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 72922 : ComputeElemAuxVarsThread<AuxKernelType>::ComputeElemAuxVarsThread( 24 : FEProblemBase & problem, 25 : const MooseObjectWarehouse<AuxKernelType> & storage, 26 : bool need_materials) 27 : : ThreadedElementLoop<ConstElemRange>(problem), 28 145844 : _aux_sys(problem.getAuxiliarySystem()), 29 72922 : _aux_kernels(storage), 30 72922 : _need_materials(need_materials) 31 : { 32 72922 : } 33 : 34 : // Splitting Constructor 35 : template <typename AuxKernelType> 36 6726 : ComputeElemAuxVarsThread<AuxKernelType>::ComputeElemAuxVarsThread(ComputeElemAuxVarsThread & x, 37 : Threads::split /*split*/) 38 : : ThreadedElementLoop<ConstElemRange>(x._fe_problem), 39 6726 : _aux_sys(x._aux_sys), 40 6726 : _aux_kernels(x._aux_kernels), 41 6726 : _need_materials(x._need_materials) 42 : { 43 6726 : } 44 : 45 : template <typename AuxKernelType> 46 86343 : ComputeElemAuxVarsThread<AuxKernelType>::~ComputeElemAuxVarsThread() 47 : { 48 86343 : } 49 : 50 : template <typename AuxKernelType> 51 : void 52 145928 : ComputeElemAuxVarsThread<AuxKernelType>::subdomainChanged() 53 : { 54 145928 : _fe_problem.subdomainSetup(_subdomain, _tid); 55 : 56 145928 : std::set<MooseVariableFEBase *> needed_moose_vars; 57 145928 : std::unordered_set<unsigned int> needed_mat_props; 58 145928 : std::set<TagID> needed_fe_var_matrix_tags; 59 145928 : std::set<TagID> needed_fe_var_vector_tags; 60 : 61 145928 : _fe_problem.getMaterialWarehouse().updateBlockFEVariableCoupledVectorTagDependency( 62 145928 : _subdomain, needed_fe_var_vector_tags, _tid); 63 145928 : if (_aux_kernels.hasActiveBlockObjects(_subdomain, _tid)) 64 : { 65 : const std::vector<std::shared_ptr<AuxKernelType>> & kernels = 66 143775 : _aux_kernels.getActiveBlockObjects(_subdomain, _tid); 67 392433 : for (const auto & aux : kernels) 68 : { 69 248658 : aux->subdomainSetup(); 70 248658 : const auto & mv_deps = aux->getMooseVariableDependencies(); 71 248658 : const auto & mp_deps = aux->getMatPropDependencies(); 72 248658 : needed_moose_vars.insert(mv_deps.begin(), mv_deps.end()); 73 248658 : needed_mat_props.insert(mp_deps.begin(), mp_deps.end()); 74 : 75 248658 : auto & fe_var_coup_vtags = aux->getFEVariableCoupleableVectorTags(); 76 248658 : needed_fe_var_vector_tags.insert(fe_var_coup_vtags.begin(), fe_var_coup_vtags.end()); 77 : 78 248658 : auto & fe_var_coup_mtags = aux->getFEVariableCoupleableMatrixTags(); 79 248658 : needed_fe_var_matrix_tags.insert(fe_var_coup_mtags.begin(), fe_var_coup_mtags.end()); 80 : } 81 : } 82 : 83 145928 : _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid); 84 145928 : _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid); 85 145928 : _fe_problem.setActiveFEVariableCoupleableMatrixTags(needed_fe_var_matrix_tags, _tid); 86 145928 : _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_fe_var_vector_tags, _tid); 87 145928 : } 88 : 89 : template <typename AuxKernelType> 90 : void 91 9329618 : ComputeElemAuxVarsThread<AuxKernelType>::onElement(const Elem * elem) 92 : { 93 9329618 : if (_aux_kernels.hasActiveBlockObjects(_subdomain, _tid)) 94 : { 95 : const std::vector<std::shared_ptr<AuxKernelType>> & kernels = 96 9294357 : _aux_kernels.getActiveBlockObjects(_subdomain, _tid); 97 9294357 : _fe_problem.prepare(elem, _tid); 98 9294357 : _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 9294357 : SwapBackSentinel sentinel(_fe_problem, &FEProblem::swapBackMaterials, _tid, _need_materials); 103 : 104 9294357 : if (_need_materials) 105 9294357 : _fe_problem.reinitMaterials(elem->subdomain_id(), _tid); 106 : 107 24572097 : for (const auto & aux : kernels) 108 : { 109 15277768 : aux->compute(); 110 15277753 : aux->variable().insert(_aux_sys.solution()); 111 : 112 : // update the aux solution vector if writable coupled variables are used 113 15277753 : if (aux->hasWritableCoupledVariables()) 114 : { 115 1440 : for (auto * var : aux->getWritableCoupledVariables()) 116 960 : var->insert(_aux_sys.solution()); 117 : 118 480 : _fe_problem.reinitElem(elem, _tid); 119 : } 120 : } 121 9294329 : } 122 9329590 : } 123 : 124 : template <typename AuxKernelType> 125 : void 126 79620 : ComputeElemAuxVarsThread<AuxKernelType>::post() 127 : { 128 79620 : _fe_problem.clearActiveElementalMooseVariables(_tid); 129 79620 : _fe_problem.clearActiveMaterialProperties(_tid); 130 : 131 79620 : _fe_problem.clearActiveFEVariableCoupleableVectorTags(_tid); 132 79620 : _fe_problem.clearActiveFEVariableCoupleableMatrixTags(_tid); 133 79620 : } 134 : 135 : template <typename AuxKernelType> 136 : void 137 6724 : ComputeElemAuxVarsThread<AuxKernelType>::join(const ComputeElemAuxVarsThread & /*y*/) 138 : { 139 6724 : } 140 : 141 : template <typename AuxKernelType> 142 : void 143 79648 : ComputeElemAuxVarsThread<AuxKernelType>::printGeneralExecutionInformation() const 144 : { 145 79648 : if (!_fe_problem.shouldPrintExecution(_tid) || !_aux_kernels.hasActiveObjects()) 146 77358 : 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 145928 : ComputeElemAuxVarsThread<AuxKernelType>::printBlockExecutionInformation() const 156 : { 157 150032 : if (!_fe_problem.shouldPrintExecution(_tid) || _blocks_exec_printed.count(_subdomain) || 158 4104 : !_aux_kernels.hasActiveBlockObjects(_subdomain, _tid)) 159 141824 : 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 4104 : 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>;