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 "ComputeMarkerThread.h" 12 : #include "AuxiliarySystem.h" 13 : #include "Problem.h" 14 : #include "FEProblem.h" 15 : #include "Marker.h" 16 : #include "MooseVariableFE.h" 17 : #include "SwapBackSentinel.h" 18 : 19 : #include "libmesh/threads.h" 20 : 21 6513 : ComputeMarkerThread::ComputeMarkerThread(FEProblemBase & fe_problem) 22 : : ThreadedElementLoop<ConstElemRange>(fe_problem), 23 6513 : _fe_problem(fe_problem), 24 13026 : _aux_sys(fe_problem.getAuxiliarySystem()), 25 6513 : _marker_whs(_fe_problem.getMarkerWarehouse()) 26 : { 27 6513 : } 28 : 29 : // Splitting Constructor 30 7 : ComputeMarkerThread::ComputeMarkerThread(ComputeMarkerThread & x, Threads::split split) 31 : : ThreadedElementLoop<ConstElemRange>(x, split), 32 7 : _fe_problem(x._fe_problem), 33 7 : _aux_sys(x._aux_sys), 34 7 : _marker_whs(x._marker_whs) 35 : { 36 7 : } 37 : 38 6527 : ComputeMarkerThread::~ComputeMarkerThread() {} 39 : 40 : void 41 22112 : ComputeMarkerThread::subdomainChanged() 42 : { 43 22112 : _fe_problem.subdomainSetup(_subdomain, _tid); 44 22112 : _marker_whs.subdomainSetup(_tid); 45 : 46 22112 : std::set<MooseVariableFEBase *> needed_moose_vars; 47 22112 : _marker_whs.updateVariableDependency(needed_moose_vars, _tid); 48 : 49 69427 : for (auto * var : _aux_sys._elem_vars[_tid]) 50 47315 : var->prepareAux(); 51 : 52 22112 : std::unordered_set<unsigned int> needed_mat_props; 53 22112 : _marker_whs.updateMatPropDependency(needed_mat_props, _tid); 54 : 55 22112 : _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid); 56 : 57 : // Only prepare (and therefore reinit) materials if a marker actually consumes a material 58 : // property. Otherwise skip the material system entirely to avoid recomputing the whole stack. 59 22112 : if (!needed_mat_props.empty()) 60 0 : _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid); 61 : else 62 22112 : _fe_problem.clearActiveMaterialProperties(_tid); 63 22112 : } 64 : 65 : void 66 1662376 : ComputeMarkerThread::onElement(const Elem * elem) 67 : { 68 1662376 : _fe_problem.prepare(elem, _tid); 69 1662376 : _fe_problem.reinitElem(elem, _tid); 70 : 71 : // Set up Sentinel class so that, even if reinitMaterials() throws, we 72 : // still remember to swap back during stack unwinding. 73 : SwapBackSentinel sentinel(_fe_problem, 74 : &FEProblem::swapBackMaterials, 75 : _tid, 76 1662376 : _fe_problem.hasActiveMaterialProperties(_tid)); 77 : 78 1662376 : _fe_problem.reinitMaterials(_subdomain, _tid); 79 : 80 1662376 : if (_marker_whs.hasActiveBlockObjects(_subdomain, _tid)) 81 : { 82 : const std::vector<std::shared_ptr<Marker>> & markers = 83 1658632 : _marker_whs.getActiveBlockObjects(_subdomain, _tid); 84 3544768 : for (const auto & marker : markers) 85 1886136 : marker->computeMarker(); 86 : } 87 : 88 4651576 : for (auto * var : _aux_sys._elem_vars[_tid]) 89 2989200 : var->insert(_aux_sys.solution()); 90 1662376 : } 91 : 92 : void 93 303439 : ComputeMarkerThread::onBoundary(const Elem * /*elem*/, 94 : unsigned int /*side*/, 95 : BoundaryID /*bnd_id*/, 96 : const Elem * /*lower_d_elem = nullptr*/) 97 : { 98 303439 : } 99 : 100 : void 101 3333803 : ComputeMarkerThread::onInternalSide(const Elem * /*elem*/, unsigned int /*side*/) 102 : { 103 3333803 : } 104 : 105 : void 106 1662376 : ComputeMarkerThread::postElement(const Elem * /*elem*/) 107 : { 108 1662376 : } 109 : 110 : void 111 6520 : ComputeMarkerThread::post() 112 : { 113 6520 : _fe_problem.clearActiveElementalMooseVariables(_tid); 114 6520 : } 115 : 116 : void 117 7 : ComputeMarkerThread::join(const ComputeMarkerThread & /*y*/) 118 : { 119 7 : } 120 : 121 : void 122 6520 : ComputeMarkerThread::printGeneralExecutionInformation() const 123 : { 124 6520 : if (!_fe_problem.shouldPrintExecution(_tid)) 125 6457 : return; 126 63 : const auto & console = _fe_problem.console(); 127 63 : const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag(); 128 63 : console << "[DBG] Beginning elemental loop to compute Markers on " << execute_on << std::endl; 129 : } 130 : 131 : void 132 22112 : ComputeMarkerThread::printBlockExecutionInformation() const 133 : { 134 22175 : if (!_fe_problem.shouldPrintExecution(_tid) || _blocks_exec_printed.count(_subdomain) || 135 63 : !_marker_whs.hasActiveBlockObjects(_subdomain, _tid)) 136 22049 : return; 137 : 138 63 : const auto & console = _fe_problem.console(); 139 63 : const auto & markers = _marker_whs.getActiveBlockObjects(_subdomain, _tid); 140 63 : console << "[DBG] Execution order on block: " << _subdomain << std::endl; 141 126 : printExecutionOrdering<Marker>(markers, false); 142 63 : _blocks_exec_printed.insert(_subdomain); 143 : }