Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "ComputeElemAuxVarsThread.h" 11 : 12 : // MOOSE includes 13 : #include "AuxiliarySystem.h" 14 : #include "AuxKernel.h" 15 : #include "SwapBackSentinel.h" 16 : #include "FEProblem.h" 17 : #include "MaterialBase.h" 18 : #include "ThreadedElementLoop.h" 19 : 20 : #include "libmesh/threads.h" 21 : 22 : template <typename AuxKernelType> 23 81145 : ComputeElemAuxVarsThread<AuxKernelType>::ComputeElemAuxVarsThread( 24 : FEProblemBase & problem, 25 : const MooseObjectWarehouse<AuxKernelType> & storage, 26 : bool need_materials) 27 : : ThreadedElementLoop<ConstElemRange>(problem), 28 162290 : _aux_sys(problem.getAuxiliarySystem()), 29 81145 : _aux_kernels(storage), 30 81145 : _need_materials(need_materials) 31 : { 32 81145 : } 33 : 34 : // Splitting Constructor 35 : template <typename AuxKernelType> 36 6897 : ComputeElemAuxVarsThread<AuxKernelType>::ComputeElemAuxVarsThread(ComputeElemAuxVarsThread & x, 37 : Threads::split /*split*/) 38 : : ThreadedElementLoop<ConstElemRange>(x._fe_problem), 39 6897 : _aux_sys(x._aux_sys), 40 6897 : _aux_kernels(x._aux_kernels), 41 6897 : _need_materials(x._need_materials) 42 : { 43 6897 : } 44 : 45 : template <typename AuxKernelType> 46 94890 : ComputeElemAuxVarsThread<AuxKernelType>::~ComputeElemAuxVarsThread() 47 : { 48 94890 : } 49 : 50 : template <typename AuxKernelType> 51 : void 52 161542 : ComputeElemAuxVarsThread<AuxKernelType>::subdomainChanged() 53 : { 54 161542 : _fe_problem.subdomainSetup(_subdomain, _tid); 55 : 56 161542 : std::set<MooseVariableFEBase *> needed_moose_vars; 57 161542 : std::unordered_set<unsigned int> needed_mat_props; 58 161542 : std::set<TagID> needed_fe_var_matrix_tags; 59 161542 : std::set<TagID> needed_fe_var_vector_tags; 60 : 61 161542 : _fe_problem.getMaterialWarehouse().updateBlockFEVariableCoupledVectorTagDependency( 62 161542 : _subdomain, needed_fe_var_vector_tags, _tid); 63 161542 : if (_aux_kernels.hasActiveBlockObjects(_subdomain, _tid)) 64 : { 65 : const std::vector<std::shared_ptr<AuxKernelType>> & kernels = 66 158519 : _aux_kernels.getActiveBlockObjects(_subdomain, _tid); 67 437536 : for (const auto & aux : kernels) 68 : { 69 279017 : aux->subdomainSetup(); 70 279017 : const auto & mv_deps = aux->getMooseVariableDependencies(); 71 279017 : const auto & mp_deps = aux->getMatPropDependencies(); 72 279017 : needed_moose_vars.insert(mv_deps.begin(), mv_deps.end()); 73 279017 : needed_mat_props.insert(mp_deps.begin(), mp_deps.end()); 74 : 75 279017 : auto & fe_var_coup_vtags = aux->getFEVariableCoupleableVectorTags(); 76 279017 : needed_fe_var_vector_tags.insert(fe_var_coup_vtags.begin(), fe_var_coup_vtags.end()); 77 : 78 279017 : auto & fe_var_coup_mtags = aux->getFEVariableCoupleableMatrixTags(); 79 279017 : needed_fe_var_matrix_tags.insert(fe_var_coup_mtags.begin(), fe_var_coup_mtags.end()); 80 : } 81 : } 82 : 83 161542 : _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid); 84 161542 : _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid); 85 161542 : _fe_problem.setActiveFEVariableCoupleableMatrixTags(needed_fe_var_matrix_tags, _tid); 86 161542 : _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_fe_var_vector_tags, _tid); 87 161542 : } 88 : 89 : template <typename AuxKernelType> 90 : void 91 10549336 : ComputeElemAuxVarsThread<AuxKernelType>::onElement(const Elem * elem) 92 : { 93 10549336 : if (_aux_kernels.hasActiveBlockObjects(_subdomain, _tid)) 94 : { 95 : const std::vector<std::shared_ptr<AuxKernelType>> & kernels = 96 10508305 : _aux_kernels.getActiveBlockObjects(_subdomain, _tid); 97 10508305 : _fe_problem.prepare(elem, _tid); 98 10508305 : _fe_problem.reinitElem(elem, _tid); 99 : 100 : // Set up the sentinel so that, even if reinitMaterials() throws, we 101 : // still remember to swap back. 102 10508305 : SwapBackSentinel sentinel(_fe_problem, &FEProblem::swapBackMaterials, _tid, _need_materials); 103 : 104 10508305 : if (_need_materials) 105 10508305 : _fe_problem.reinitMaterials(elem->subdomain_id(), _tid); 106 : 107 28131802 : for (const auto & aux : kernels) 108 : { 109 17623537 : aux->compute(); 110 17623518 : aux->variable().insert(_aux_sys.solution()); 111 : 112 : // update the aux solution vector if writable coupled variables are used 113 17623518 : if (aux->hasWritableCoupledVariables()) 114 : { 115 1620 : for (auto * var : aux->getWritableCoupledVariables()) 116 1080 : var->insert(_aux_sys.solution()); 117 : 118 540 : _fe_problem.reinitElem(elem, _tid); 119 : } 120 : } 121 10508265 : } 122 10549296 : } 123 : 124 : template <typename AuxKernelType> 125 : void 126 88002 : ComputeElemAuxVarsThread<AuxKernelType>::post() 127 : { 128 88002 : _fe_problem.clearActiveElementalMooseVariables(_tid); 129 88002 : _fe_problem.clearActiveMaterialProperties(_tid); 130 : 131 88002 : _fe_problem.clearActiveFEVariableCoupleableVectorTags(_tid); 132 88002 : _fe_problem.clearActiveFEVariableCoupleableMatrixTags(_tid); 133 88002 : } 134 : 135 : template <typename AuxKernelType> 136 : void 137 6889 : ComputeElemAuxVarsThread<AuxKernelType>::join(const ComputeElemAuxVarsThread & /*y*/) 138 : { 139 6889 : } 140 : 141 : template <typename AuxKernelType> 142 : void 143 88042 : ComputeElemAuxVarsThread<AuxKernelType>::printGeneralExecutionInformation() const 144 : { 145 88042 : if (!_fe_problem.shouldPrintExecution(_tid) || !_aux_kernels.hasActiveObjects()) 146 85752 : return; 147 : 148 2290 : const auto & console = _fe_problem.console(); 149 2290 : const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag(); 150 2290 : console << "[DBG] Executing auxiliary kernels on elements on " << execute_on << std::endl; 151 : } 152 : 153 : template <typename AuxKernelType> 154 : void 155 161542 : ComputeElemAuxVarsThread<AuxKernelType>::printBlockExecutionInformation() const 156 : { 157 165646 : if (!_fe_problem.shouldPrintExecution(_tid) || _blocks_exec_printed.count(_subdomain) || 158 4104 : !_aux_kernels.hasActiveBlockObjects(_subdomain, _tid)) 159 157438 : return; 160 : 161 4104 : const auto & console = _fe_problem.console(); 162 4104 : const auto & kernels = _aux_kernels.getActiveBlockObjects(_subdomain, _tid); 163 4104 : console << "[DBG] Ordering of AuxKernels on block " << _subdomain << std::endl; 164 8208 : printExecutionOrdering<AuxKernelType>(kernels, false); 165 4104 : _blocks_exec_printed.insert(_subdomain); 166 : } 167 : 168 : template class ComputeElemAuxVarsThread<AuxKernel>; 169 : template class ComputeElemAuxVarsThread<VectorAuxKernel>; 170 : template class ComputeElemAuxVarsThread<ArrayAuxKernel>;