https://mooseframework.inl.gov
ComputeMarkerThread.C
Go to the documentation of this file.
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 
22  : ThreadedElementLoop<ConstElemRange>(fe_problem),
23  _fe_problem(fe_problem),
24  _aux_sys(fe_problem.getAuxiliarySystem()),
25  _marker_whs(_fe_problem.getMarkerWarehouse())
26 {
27 }
28 
29 // Splitting Constructor
32  _fe_problem(x._fe_problem),
33  _aux_sys(x._aux_sys),
34  _marker_whs(x._marker_whs)
35 {
36 }
37 
39 
40 void
42 {
45 
46  std::set<MooseVariableFEBase *> needed_moose_vars;
47  _marker_whs.updateVariableDependency(needed_moose_vars, _tid);
48 
49  for (auto * var : _aux_sys._elem_vars[_tid])
50  var->prepareAux();
51 
52  std::unordered_set<unsigned int> needed_mat_props;
53  _marker_whs.updateMatPropDependency(needed_mat_props, _tid);
54 
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  if (!needed_mat_props.empty())
60  _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid);
61  else
63 }
64 
65 void
67 {
68  _fe_problem.prepare(elem, _tid);
70 
71  // Set up Sentinel class so that, even if reinitMaterials() throws, we
72  // still remember to swap back during stack unwinding.
75  _tid,
77 
79 
81  {
82  const std::vector<std::shared_ptr<Marker>> & markers =
84  for (const auto & marker : markers)
85  marker->computeMarker();
86  }
87 
88  for (auto * var : _aux_sys._elem_vars[_tid])
89  var->insert(_aux_sys.solution());
90 }
91 
92 void
93 ComputeMarkerThread::onBoundary(const Elem * /*elem*/,
94  unsigned int /*side*/,
95  BoundaryID /*bnd_id*/,
96  const Elem * /*lower_d_elem = nullptr*/)
97 {
98 }
99 
100 void
101 ComputeMarkerThread::onInternalSide(const Elem * /*elem*/, unsigned int /*side*/)
102 {
103 }
104 
105 void
106 ComputeMarkerThread::postElement(const Elem * /*elem*/)
107 {
108 }
109 
110 void
112 {
114 }
115 
116 void
118 {
119 }
120 
121 void
123 {
125  return;
126  const auto & console = _fe_problem.console();
127  const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
128  console << "[DBG] Beginning elemental loop to compute Markers on " << execute_on << std::endl;
129 }
130 
131 void
133 {
136  return;
137 
138  const auto & console = _fe_problem.console();
139  const auto & markers = _marker_whs.getActiveBlockObjects(_subdomain, _tid);
140  console << "[DBG] Execution order on block: " << _subdomain << std::endl;
141  printExecutionOrdering<Marker>(markers, false);
143 }
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr) override
Called when doing boundary assembling.
void updateVariableDependency(std::set< MooseVariableFieldBase *> &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
FEProblemBase & _fe_problem
Base class for assembly-like calculations.
bool hasActiveBlockObjects(THREAD_ID tid=0) const
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
virtual void prepare(const Elem *elem, const THREAD_ID tid) override
NumericVector< Number > & solution()
Definition: SystemBase.h:197
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
const MooseObjectWarehouse< Marker > & _marker_whs
Reference to the Marker warhouse in FEProblemBase.
void printGeneralExecutionInformation() const override
Print information about the loop.
void clearActiveMaterialProperties(const THREAD_ID tid)
Clear the active material properties.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void postElement(const Elem *) override
Called after the element assembly is done (including surface assembling)
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
virtual void setActiveElementalMooseVariables(const std::set< MooseVariableFEBase *> &moose_vars, const THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
virtual void post() override
Called after the element range loop.
virtual void reinitElem(const Elem *elem, const THREAD_ID tid) override
AuxiliarySystem & _aux_sys
boundary_id_type BoundaryID
void printBlockExecutionInformation() const override
Print information about ordering of objects on each block.
ComputeMarkerThread(FEProblemBase &fe_problem)
void join(const ComputeMarkerThread &)
std::set< SubdomainID > _blocks_exec_printed
Keep track of which blocks were visited.
std::vector< std::vector< MooseVariableFieldBase * > > _elem_vars
Elemental variables.
tbb::split split
const ConsoleStream & console() const
Return console handle.
Definition: Problem.h:48
virtual void swapBackMaterials(const THREAD_ID tid)
virtual void subdomainSetup(SubdomainID subdomain, const THREAD_ID tid)
void reinitMaterials(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true)
void updateMatPropDependency(std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0, const bool producer_only=false) const
Update material property dependency vector.
SubdomainID _subdomain
The subdomain for the current element.
void prepareMaterials(const std::unordered_set< unsigned int > &consumer_needed_mat_props, const SubdomainID blk_id, const THREAD_ID tid)
Add the MooseVariables and the material properties that the current materials depend on to the depend...
bool hasActiveMaterialProperties(const THREAD_ID tid) const
Method to check whether or not a list of active material roperties has been set.
virtual void subdomainSetup(THREAD_ID tid=0) const
virtual void clearActiveElementalMooseVariables(const THREAD_ID tid) override
Clear the active elemental MooseVariableFEBase.
The "SwapBackSentinel" class&#39;s destructor guarantees that FEProblemBase::swapBackMaterials{Face,Neighbor}() is called even when an exception is thrown from FEProblemBase::reinitMaterials{Face,Neighbor}.