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 6424 : ComputeMarkerThread::ComputeMarkerThread(FEProblemBase & fe_problem) 22 : : ThreadedElementLoop<ConstElemRange>(fe_problem), 23 6424 : _fe_problem(fe_problem), 24 12848 : _aux_sys(fe_problem.getAuxiliarySystem()), 25 6424 : _marker_whs(_fe_problem.getMarkerWarehouse()) 26 : { 27 6424 : } 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 7654 : ComputeMarkerThread::~ComputeMarkerThread() {} 39 : 40 : void 41 23088 : ComputeMarkerThread::subdomainChanged() 42 : { 43 23088 : _fe_problem.subdomainSetup(_subdomain, _tid); 44 23088 : _marker_whs.subdomainSetup(_tid); 45 : 46 23088 : std::set<MooseVariableFEBase *> needed_moose_vars; 47 23088 : _marker_whs.updateVariableDependency(needed_moose_vars, _tid); 48 : 49 72534 : for (auto * var : _aux_sys._elem_vars[_tid]) 50 49446 : var->prepareAux(); 51 : 52 23088 : std::unordered_set<unsigned int> needed_mat_props; 53 23088 : _marker_whs.updateMatPropDependency(needed_mat_props, _tid); 54 : 55 23088 : _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid); 56 23088 : _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid); 57 23088 : } 58 : 59 : void 60 1694242 : ComputeMarkerThread::onElement(const Elem * elem) 61 : { 62 1694242 : _fe_problem.prepare(elem, _tid); 63 1694242 : _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 1694242 : _fe_problem.hasActiveMaterialProperties(_tid)); 71 : 72 1694242 : _fe_problem.reinitMaterials(_subdomain, _tid); 73 : 74 1694242 : if (_marker_whs.hasActiveBlockObjects(_subdomain, _tid)) 75 : { 76 : const std::vector<std::shared_ptr<Marker>> & markers = 77 1690498 : _marker_whs.getActiveBlockObjects(_subdomain, _tid); 78 3606316 : for (const auto & marker : markers) 79 1915818 : marker->computeMarker(); 80 : } 81 : 82 : { 83 1694242 : Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx); 84 4766342 : for (auto * var : _aux_sys._elem_vars[_tid]) 85 3072100 : var->insert(_aux_sys.solution()); 86 1694242 : } 87 1694242 : } 88 : 89 : void 90 305130 : ComputeMarkerThread::onBoundary(const Elem * /*elem*/, 91 : unsigned int /*side*/, 92 : BoundaryID /*bnd_id*/, 93 : const Elem * /*lower_d_elem = nullptr*/) 94 : { 95 305130 : } 96 : 97 : void 98 3397189 : ComputeMarkerThread::onInternalSide(const Elem * /*elem*/, unsigned int /*side*/) 99 : { 100 3397189 : } 101 : 102 : void 103 1694242 : ComputeMarkerThread::postElement(const Elem * /*elem*/) 104 : { 105 1694242 : } 106 : 107 : void 108 7039 : ComputeMarkerThread::post() 109 : { 110 7039 : _fe_problem.clearActiveElementalMooseVariables(_tid); 111 7039 : } 112 : 113 : void 114 615 : ComputeMarkerThread::join(const ComputeMarkerThread & /*y*/) 115 : { 116 615 : } 117 : 118 : void 119 7039 : ComputeMarkerThread::printGeneralExecutionInformation() const 120 : { 121 7039 : if (!_fe_problem.shouldPrintExecution(_tid)) 122 6969 : 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 23088 : ComputeMarkerThread::printBlockExecutionInformation() const 130 : { 131 23158 : if (!_fe_problem.shouldPrintExecution(_tid) || _blocks_exec_printed.count(_subdomain) || 132 70 : !_marker_whs.hasActiveBlockObjects(_subdomain, _tid)) 133 23018 : 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 70 : printExecutionOrdering<Marker>(markers, false); 139 70 : _blocks_exec_printed.insert(_subdomain); 140 : }