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 : // MOOSE includes 11 : #include "ComputeElemAuxBcsThread.h" 12 : #include "AuxiliarySystem.h" 13 : #include "FEProblem.h" 14 : #include "DisplacedProblem.h" 15 : #include "Assembly.h" 16 : #include "AuxKernel.h" 17 : #include "SwapBackSentinel.h" 18 : 19 : #include "libmesh/threads.h" 20 : 21 : template <typename AuxKernelType> 22 24876 : ComputeElemAuxBcsThread<AuxKernelType>::ComputeElemAuxBcsThread( 23 : FEProblemBase & fe_problem, 24 : const MooseObjectWarehouse<AuxKernelType> & storage, 25 : bool need_materials) 26 24876 : : _fe_problem(fe_problem), 27 24876 : _aux_sys(fe_problem.getAuxiliarySystem()), 28 24876 : _storage(storage), 29 24876 : _need_materials(need_materials) 30 : { 31 24876 : } 32 : 33 : // Splitting Constructor 34 : template <typename AuxKernelType> 35 0 : ComputeElemAuxBcsThread<AuxKernelType>::ComputeElemAuxBcsThread(ComputeElemAuxBcsThread & x, 36 : Threads::split /*split*/) 37 0 : : _fe_problem(x._fe_problem), 38 0 : _aux_sys(x._aux_sys), 39 0 : _storage(x._storage), 40 0 : _need_materials(x._need_materials) 41 : { 42 0 : } 43 : 44 : template <typename AuxKernelType> 45 : void 46 24876 : ComputeElemAuxBcsThread<AuxKernelType>::operator()(const ConstBndElemRange & range) 47 : { 48 24876 : ParallelUniqueId puid; 49 24876 : _tid = puid.id; 50 : 51 : // Reference to all boundary restricted AuxKernels for the current thread 52 24876 : const auto & boundary_kernels = _storage.getActiveBoundaryObjects(_tid); 53 : 54 24876 : printGeneralExecutionInformation(); 55 : 56 3828615 : for (const auto & belem : range) 57 : { 58 3803745 : const Elem * elem = belem->_elem; 59 3803745 : unsigned short int side = belem->_side; 60 3803745 : BoundaryID boundary_id = belem->_bnd_id; 61 3803745 : SubdomainID last_sub_id = Elem::invalid_subdomain_id; 62 : 63 : // need to update the boundary ID in assembly 64 3803745 : _fe_problem.setCurrentBoundaryID(boundary_id, _tid); 65 : 66 3803745 : if (elem->processor_id() == _fe_problem.processor_id()) 67 : { 68 : // Locate the AuxKernel objects for the current BoundaryID 69 2947403 : const auto iter = boundary_kernels.find(boundary_id); 70 : 71 2947403 : if (iter != boundary_kernels.end() && !(iter->second.empty())) 72 : { 73 111832 : printBoundaryExecutionInformation(boundary_id, iter->second); 74 111832 : const auto sub_id = elem->subdomain_id(); 75 111832 : if (sub_id != last_sub_id) 76 : { 77 111832 : _fe_problem.subdomainSetup(sub_id, _tid); 78 111832 : last_sub_id = sub_id; 79 : } 80 111832 : _fe_problem.setCurrentSubdomainID(elem, _tid); 81 111832 : _fe_problem.prepare(elem, _tid); 82 111832 : _fe_problem.reinitElemFace(elem, side, _tid); 83 : 84 111832 : const Elem * lower_d_elem = _fe_problem.mesh().getLowerDElem(elem, side); 85 111832 : _fe_problem.setCurrentLowerDElem(lower_d_elem, _tid); 86 111832 : if (lower_d_elem) 87 825 : _fe_problem.reinitLowerDElem(lower_d_elem, _tid); 88 : 89 111832 : const Elem * neighbor = elem->neighbor_ptr(side); 90 : 91 : // The last check here is absolutely necessary otherwise we will attempt to evaluate 92 : // neighbor materials on neighbor elements that aren't evaluable, e.g. don't have algebraic 93 : // ghosting 94 111832 : bool compute_interface = 95 113434 : neighbor && neighbor->active() && 96 1602 : _fe_problem.getInterfaceMaterialsWarehouse().hasActiveBoundaryObjects(boundary_id, 97 : _tid); 98 : 99 : // Set up Sentinel class so that, even if reinitMaterialsFace() throws, we 100 : // still remember to swap back during stack unwinding. 101 111832 : SwapBackSentinel sentinel(_fe_problem, &FEProblem::swapBackMaterialsFace, _tid); 102 111832 : SwapBackSentinel neighbor_sentinel( 103 : _fe_problem, &FEProblem::swapBackMaterialsNeighbor, _tid, compute_interface); 104 : 105 111832 : if (_need_materials) 106 : { 107 111832 : std::unordered_set<unsigned int> needed_mat_props; 108 234360 : for (const auto & aux : iter->second) 109 : { 110 122528 : const auto & mp_deps = aux->getMatPropDependencies(); 111 122528 : needed_mat_props.insert(mp_deps.begin(), mp_deps.end()); 112 : } 113 111832 : _fe_problem.setActiveMaterialProperties(needed_mat_props, _tid); 114 : 115 111832 : _fe_problem.reinitMaterialsFaceOnBoundary(boundary_id, sub_id, _tid); 116 : 117 111832 : _fe_problem.reinitMaterialsBoundary(boundary_id, _tid); 118 : 119 111832 : if (compute_interface) 120 : { 121 416 : _fe_problem.reinitNeighbor(elem, side, _tid); 122 416 : _fe_problem.reinitMaterialsNeighbor(neighbor->subdomain_id(), _tid); 123 416 : _fe_problem.reinitMaterialsInterface(boundary_id, _tid); 124 : } 125 111832 : } 126 : 127 234348 : for (const auto & aux : iter->second) 128 : { 129 122522 : aux->determineWhetherCoincidentLowerDCalc(); 130 122516 : aux->compute(); 131 122516 : aux->insert(); 132 : } 133 : 134 111826 : if (_need_materials) 135 111826 : _fe_problem.clearActiveMaterialProperties(_tid); 136 111826 : } 137 : } 138 : } 139 24870 : } 140 : 141 : template <typename AuxKernelType> 142 : void 143 0 : ComputeElemAuxBcsThread<AuxKernelType>::join(const ComputeElemAuxBcsThread & /*y*/) 144 : { 145 0 : } 146 : 147 : template <typename AuxKernelType> 148 : void 149 24876 : ComputeElemAuxBcsThread<AuxKernelType>::printGeneralExecutionInformation() const 150 : { 151 24876 : if (_fe_problem.shouldPrintExecution(_tid) && _storage.hasActiveObjects()) 152 : { 153 420 : const auto & console = _fe_problem.console(); 154 420 : const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag(); 155 420 : console << "[DBG] Executing boundary restricted auxkernels on boundary elements on " 156 420 : << execute_on << std::endl; 157 : } 158 24876 : } 159 : 160 : template <typename AuxKernelType> 161 : void 162 111832 : ComputeElemAuxBcsThread<AuxKernelType>::printBoundaryExecutionInformation( 163 : unsigned int boundary_id, const std::vector<std::shared_ptr<AuxKernelType>> & kernels) const 164 : { 165 117112 : if (!_fe_problem.shouldPrintExecution(_tid) || !_storage.hasActiveObjects() || 166 117112 : _boundaries_exec_printed.count(boundary_id)) 167 110992 : return; 168 : 169 840 : const auto & console = _fe_problem.console(); 170 840 : console << "[DBG] Ordering on boundary " << boundary_id << std::endl; 171 840 : std::vector<MooseObject *> objs_ptrs; 172 1680 : for (auto & kernel_ptr : kernels) 173 840 : if (kernel_ptr->hasBoundary(boundary_id)) 174 840 : objs_ptrs.push_back(dynamic_cast<MooseObject *>(kernel_ptr.get())); 175 1680 : std::string list_kernels = ConsoleUtils::mooseObjectVectorToString(objs_ptrs); 176 840 : console << ConsoleUtils::formatString(list_kernels, "[DBG]") << std::endl; 177 840 : _boundaries_exec_printed.insert(boundary_id); 178 840 : } 179 : 180 : template class ComputeElemAuxBcsThread<AuxKernel>; 181 : template class ComputeElemAuxBcsThread<VectorAuxKernel>; 182 : template class ComputeElemAuxBcsThread<ArrayAuxKernel>;