www.mooseframework.org
ComputeIndicatorThread.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #include "ComputeIndicatorThread.h"
11 
12 // MOOSE includes
13 #include "AuxiliarySystem.h"
14 #include "FEProblem.h"
15 #include "Indicator.h"
16 #include "InternalSideIndicator.h"
17 #include "MooseVariableFE.h"
18 #include "Problem.h"
19 #include "SwapBackSentinel.h"
20 // For dynamic casting to Coupleable
21 #include "Material.h"
22 #include "InterfaceMaterial.h"
23 
24 #include "libmesh/threads.h"
25 
27  : ThreadedElementLoop<ConstElemRange>(fe_problem),
28  _fe_problem(fe_problem),
29  _aux_sys(fe_problem.getAuxiliarySystem()),
30  _indicator_whs(_fe_problem.getIndicatorWarehouse()),
31  _internal_side_indicators(_fe_problem.getInternalSideIndicatorWarehouse()),
32  _finalize(finalize)
33 {
34 }
35 
36 // Splitting Constructor
39  _fe_problem(x._fe_problem),
40  _aux_sys(x._aux_sys),
41  _indicator_whs(x._indicator_whs),
42  _internal_side_indicators(x._internal_side_indicators),
43  _finalize(x._finalize)
44 {
45 }
46 
48 
49 void
51 {
53 
56 
57  std::set<MooseVariableFEBase *> needed_moose_vars;
58  _indicator_whs.updateVariableDependency(needed_moose_vars, _tid);
61 
62  // Update variable coupleable vector tags
63  std::set<TagID> needed_var_vector_tags;
65  _subdomain, needed_var_vector_tags, _tid);
67  _subdomain, needed_var_vector_tags, _tid);
69  _subdomain, needed_var_vector_tags, _tid);
71 
72  std::unordered_set<unsigned int> needed_mat_props;
73  _indicator_whs.updateMatPropDependency(needed_mat_props, _tid);
75 
76  _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid);
77 }
78 
79 void
81 {
82  for (auto * var : _aux_sys._elem_vars[_tid])
83  var->prepareAux();
84 
85  _fe_problem.prepare(elem, _tid);
87 
88  // Set up Sentinel class so that, even if reinitMaterials() throws, we
89  // still remember to swap back during stack unwinding.
91 
93 
94  // Compute
95  if (!_finalize)
96  {
98  {
99  const std::vector<std::shared_ptr<Indicator>> & indicators =
101  for (const auto & indicator : indicators)
102  indicator->computeIndicator();
103  }
104  }
105 
106  // Finalize
107  else
108  {
110  {
111  const std::vector<std::shared_ptr<Indicator>> & indicators =
113  for (const auto & indicator : indicators)
114  indicator->finalize();
115  }
116 
118  {
119  const std::vector<std::shared_ptr<InternalSideIndicator>> & internal_indicators =
121  for (const auto & internal_indicator : internal_indicators)
122  internal_indicator->finalize();
123  }
124  }
125 
126  if (!_finalize) // During finalize the Indicators should be setting values in the vectors manually
127  {
128  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
129  for (auto * var : _aux_sys._elem_vars[_tid])
130  var->add(_aux_sys.solution());
131  }
132 }
133 
134 void
136  unsigned int /*side*/,
137  BoundaryID /*bnd_id*/,
138  const Elem * /*lower_d_elem = nullptr*/)
139 {
140 }
141 
142 void
143 ComputeIndicatorThread::onInternalSide(const Elem * elem, unsigned int side)
144 {
145  if (_finalize) // If finalizing we only do something on the elements
146  return;
147 
148  // Pointer to the neighbor we are currently working on.
149  const Elem * neighbor = elem->neighbor_ptr(side);
150 
151  for (auto * var : _aux_sys._elem_vars[_tid])
152  var->prepareAux();
153 
154  SubdomainID block_id = elem->subdomain_id();
156  {
157  _fe_problem.reinitNeighbor(elem, side, _tid);
158 
159  // Set up Sentinels so that, even if one of the reinitMaterialsXXX() calls throws, we
160  // still remember to swap back during stack unwinding.
163 
164  SwapBackSentinel neighbor_sentinel(
166  _fe_problem.reinitMaterialsNeighbor(neighbor->subdomain_id(), _tid);
167 
168  const std::vector<std::shared_ptr<InternalSideIndicator>> & indicators =
170  for (const auto & indicator : indicators)
171  indicator->computeIndicator();
172  }
173 }
174 
175 void
177 {
178 }
179 
180 void
182 {
185 }
186 
187 void
189 {
190 }
191 
192 void
194 {
196  return;
197 
198  const auto & console = _fe_problem.console();
199  const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
200  if (!_finalize)
201  console << "[DBG] Executing indicators on elements then on internal sides on " << execute_on
202  << std::endl;
203  else
204  console << "[DBG] Finalizing indicator loop" << std::endl;
205 }
206 
207 void
209 {
211  return;
212 
213  const auto & console = _fe_problem.console();
215  {
216  const auto & indicators = _indicator_whs.getActiveBlockObjects(_subdomain, _tid);
217  console << "[DBG] Ordering of element indicators on block " << _subdomain << std::endl;
218  printExecutionOrdering<Indicator>(indicators, false);
219  }
221  {
223  console << "[DBG] Ordering of element internal sides indicators on block " << _subdomain
224  << std::endl;
225  printExecutionOrdering<InternalSideIndicator>(indicators, false);
226  }
228 }
void updateVariableDependency(std::set< MooseVariableFieldBase *> &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr) override
Called when doing boundary assembling.
const MooseObjectWarehouse< InternalSideIndicator > & _internal_side_indicators
InternalSideIndicator Storage.
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
NumericVector< Number > & solution()
Definition: SystemBase.h:176
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
void clearActiveMaterialProperties(const THREAD_ID tid)
Clear the active material properties.
const MaterialWarehouse & getMaterialWarehouse() const
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void reinitMaterialsFace(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true, const std::deque< MaterialBase *> *reinit_mats=nullptr)
reinit materials on element faces
virtual void swapBackMaterialsFace(const THREAD_ID tid)
virtual void setActiveElementalMooseVariables(const std::set< MooseVariableFEBase *> &moose_vars, const THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
void printGeneralExecutionInformation() const override
Print general information about the loop when it executes.
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
virtual void postElement(const Elem *) override
Called after the element assembly is done (including surface assembling)
virtual void reinitElem(const Elem *elem, const THREAD_ID tid) override
void reinitMaterialsNeighbor(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true, const std::deque< MaterialBase *> *reinit_mats=nullptr)
reinit materials on the neighboring element face
ComputeIndicatorThread(FEProblemBase &fe_problem, bool finalize=false)
boundary_id_type BoundaryID
void updateMatPropDependency(std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0) const
Update material property dependency vector.
virtual void swapBackMaterialsNeighbor(const THREAD_ID tid)
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
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)
void updateBlockFEVariableCoupledVectorTagDependency(SubdomainID id, std::set< TagID > &needed_fe_var_vector_tags, THREAD_ID tid=0) const
Update FE variable coupleable vector tag vector.
virtual void subdomainSetup(SubdomainID subdomain, const THREAD_ID tid)
void reinitMaterials(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true)
const MooseObjectWarehouse< Indicator > & _indicator_whs
Indicator Storage.
virtual void prepare(const Elem *elem, const THREAD_ID tid) override
void printBlockExecutionInformation() const override
Print list of specific objects executed and in which order.
void join(const ComputeIndicatorThread &)
SubdomainID _subdomain
The subdomain for the current element.
virtual void reinitNeighbor(const Elem *elem, unsigned int side, const THREAD_ID tid) override
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
virtual void post() override
Called after the element range loop.
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...
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}.