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 7056 : ComputeMarkerThread::ComputeMarkerThread(FEProblemBase & fe_problem) 22 : : ThreadedElementLoop<ConstElemRange>(fe_problem), 23 7056 : _fe_problem(fe_problem), 24 14112 : _aux_sys(fe_problem.getAuxiliarySystem()), 25 7056 : _marker_whs(_fe_problem.getMarkerWarehouse()) 26 : { 27 7056 : } 28 : 29 : // Splitting Constructor 30 615 : ComputeMarkerThread::ComputeMarkerThread(ComputeMarkerThread & x, Threads::split split) 31 : : ThreadedElementLoop<ConstElemRange>(x, split), 32 615 : _fe_problem(x._fe_problem), 33 615 : _aux_sys(x._aux_sys), 34 615 : _marker_whs(x._marker_whs) 35 : { 36 615 : } 37 : 38 8286 : ComputeMarkerThread::~ComputeMarkerThread() {} 39 : 40 : void 41 25476 : ComputeMarkerThread::subdomainChanged() 42 : { 43 25476 : _fe_problem.subdomainSetup(_subdomain, _tid); 44 25476 : _marker_whs.subdomainSetup(_tid); 45 : 46 25476 : std::set<MooseVariableFEBase *> needed_moose_vars; 47 25476 : _marker_whs.updateVariableDependency(needed_moose_vars, _tid); 48 : 49 80121 : for (auto * var : _aux_sys._elem_vars[_tid]) 50 54645 : var->prepareAux(); 51 : 52 25476 : std::unordered_set<unsigned int> needed_mat_props; 53 25476 : _marker_whs.updateMatPropDependency(needed_mat_props, _tid); 54 : 55 25476 : _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid); 56 25476 : _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid); 57 25476 : } 58 : 59 : void 60 1878634 : ComputeMarkerThread::onElement(const Elem * elem) 61 : { 62 1878634 : _fe_problem.prepare(elem, _tid); 63 1878634 : _fe_problem.reinitElem(elem, _tid); 64 : 65 : // Set up Sentinel class so that, even if reinitMaterials() throws, we 66 : // still remember to swap back during stack unwinding. 67 : SwapBackSentinel sentinel(_fe_problem, 68 : &FEProblem::swapBackMaterials, 69 : _tid, 70 1878634 : _fe_problem.hasActiveMaterialProperties(_tid)); 71 : 72 1878634 : _fe_problem.reinitMaterials(_subdomain, _tid); 73 : 74 1878634 : if (_marker_whs.hasActiveBlockObjects(_subdomain, _tid)) 75 : { 76 : const std::vector<std::shared_ptr<Marker>> & markers = 77 1874422 : _marker_whs.getActiveBlockObjects(_subdomain, _tid); 78 4000354 : for (const auto & marker : markers) 79 2125932 : marker->computeMarker(); 80 : } 81 : 82 : { 83 1878634 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 84 5254707 : for (auto * var : _aux_sys._elem_vars[_tid]) 85 3376073 : var->insert(_aux_sys.solution()); 86 1878634 : } 87 1878634 : } 88 : 89 : void 90 340676 : ComputeMarkerThread::onBoundary(const Elem * /*elem*/, 91 : unsigned int /*side*/, 92 : BoundaryID /*bnd_id*/, 93 : const Elem * /*lower_d_elem = nullptr*/) 94 : { 95 340676 : } 96 : 97 : void 98 3768995 : ComputeMarkerThread::onInternalSide(const Elem * /*elem*/, unsigned int /*side*/) 99 : { 100 3768995 : } 101 : 102 : void 103 1878634 : ComputeMarkerThread::postElement(const Elem * /*elem*/) 104 : { 105 1878634 : } 106 : 107 : void 108 7671 : ComputeMarkerThread::post() 109 : { 110 7671 : _fe_problem.clearActiveElementalMooseVariables(_tid); 111 7671 : } 112 : 113 : void 114 615 : ComputeMarkerThread::join(const ComputeMarkerThread & /*y*/) 115 : { 116 615 : } 117 : 118 : void 119 7671 : ComputeMarkerThread::printGeneralExecutionInformation() const 120 : { 121 7671 : if (!_fe_problem.shouldPrintExecution(_tid)) 122 7601 : return; 123 70 : const auto & console = _fe_problem.console(); 124 70 : const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag(); 125 70 : console << "[DBG] Beginning elemental loop to compute Markers on " << execute_on << std::endl; 126 : } 127 : 128 : void 129 25476 : ComputeMarkerThread::printBlockExecutionInformation() const 130 : { 131 25546 : if (!_fe_problem.shouldPrintExecution(_tid) || _blocks_exec_printed.count(_subdomain) || 132 70 : !_marker_whs.hasActiveBlockObjects(_subdomain, _tid)) 133 25406 : return; 134 : 135 70 : const auto & console = _fe_problem.console(); 136 70 : const auto & markers = _marker_whs.getActiveBlockObjects(_subdomain, _tid); 137 70 : console << "[DBG] Execution order on block: " << _subdomain << std::endl; 138 140 : printExecutionOrdering<Marker>(markers, false); 139 70 : _blocks_exec_printed.insert(_subdomain); 140 : }