www.mooseframework.org
ComputeIndicatorThread.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 #include "ComputeIndicatorThread.h"
15 
16 // MOOSE includes
17 #include "AuxiliarySystem.h"
18 #include "FEProblem.h"
19 #include "Indicator.h"
20 #include "InternalSideIndicator.h"
21 #include "MooseVariable.h"
22 #include "Problem.h"
23 #include "SwapBackSentinel.h"
24 
25 #include "libmesh/threads.h"
26 
28  : ThreadedElementLoop<ConstElemRange>(fe_problem),
29  _fe_problem(fe_problem),
30  _aux_sys(fe_problem.getAuxiliarySystem()),
31  _indicator_whs(_fe_problem.getIndicatorWarehouse()),
32  _internal_side_indicators(_fe_problem.getInternalSideIndicatorWarehouse()),
33  _finalize(finalize)
34 {
35 }
36 
37 // Splitting Constructor
39  : ThreadedElementLoop<ConstElemRange>(x, split),
41  _aux_sys(x._aux_sys),
45 {
46 }
47 
49 
50 void
52 {
54 
57 
58  std::set<MooseVariable *> needed_moose_vars;
59  _indicator_whs.updateVariableDependency(needed_moose_vars, _tid);
62 
63  std::set<unsigned int> needed_mat_props;
64  _indicator_whs.updateMatPropDependency(needed_mat_props, _tid);
66  _fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
67 
69 }
70 
71 void
73 {
74  for (const auto & it : _aux_sys._elem_vars[_tid])
75  {
76  MooseVariable * var = it.second;
77  var->prepareAux();
78  }
79 
80  _fe_problem.prepare(elem, _tid);
81  _fe_problem.reinitElem(elem, _tid);
82 
83  // Set up Sentinel class so that, even if reinitMaterials() throws, we
84  // still remember to swap back during stack unwinding.
86 
88 
89  // Compute
90  if (!_finalize)
91  {
93  {
94  const std::vector<std::shared_ptr<Indicator>> & indicators =
96  for (const auto & indicator : indicators)
97  indicator->computeIndicator();
98  }
99  }
100 
101  // Finalize
102  else
103  {
105  {
106  const std::vector<std::shared_ptr<Indicator>> & indicators =
108  for (const auto & indicator : indicators)
109  indicator->finalize();
110  }
111 
113  {
114  const std::vector<std::shared_ptr<InternalSideIndicator>> & internal_indicators =
116  for (const auto & internal_indicator : internal_indicators)
117  internal_indicator->finalize();
118  }
119  }
120 
121  if (!_finalize) // During finalize the Indicators should be setting values in the vectors manually
122  {
123  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
124  for (const auto & it : _aux_sys._elem_vars[_tid])
125  {
126  MooseVariable * var = it.second;
127  var->add(_aux_sys.solution());
128  }
129  }
130 }
131 
132 void
134  unsigned int /*side*/,
135  BoundaryID /*bnd_id*/)
136 {
137 }
138 
139 void
140 ComputeIndicatorThread::onInternalSide(const Elem * elem, unsigned int side)
141 {
142  if (_finalize) // If finalizing we only do something on the elements
143  return;
144 
145  // Pointer to the neighbor we are currently working on.
146  const Elem * neighbor = elem->neighbor_ptr(side);
147 
148  // Get the global id of the element and the neighbor
149  const dof_id_type elem_id = elem->id(), neighbor_id = neighbor->id();
150 
151  if ((neighbor->active() && (neighbor->level() == elem->level()) && (elem_id < neighbor_id)) ||
152  (neighbor->level() < elem->level()))
153  {
154  for (const auto & it : _aux_sys._elem_vars[_tid])
155  {
156  MooseVariable * var = it.second;
157  var->prepareAux();
158  }
159 
160  SubdomainID block_id = elem->subdomain_id();
162  {
163  _fe_problem.reinitNeighbor(elem, side, _tid);
164 
165  // Set up Sentinels so that, even if one of the reinitMaterialsXXX() calls throws, we
166  // still remember to swap back during stack unwinding.
168  _fe_problem.reinitMaterialsFace(block_id, _tid);
169 
170  SwapBackSentinel neighbor_sentinel(
172  _fe_problem.reinitMaterialsNeighbor(neighbor->subdomain_id(), _tid);
173 
174  const std::vector<std::shared_ptr<InternalSideIndicator>> & indicators =
176  for (const auto & indicator : indicators)
177  indicator->computeIndicator();
178  }
179  }
180 }
181 
182 void
184 {
185 }
186 
187 void
189 {
192 }
193 
194 void
196 {
197 }
virtual void setActiveElementalMooseVariables(const std::set< MooseVariable * > &moose_vars, THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
const MooseObjectWarehouse< InternalSideIndicator > & _internal_side_indicators
InternalSideIndicator Storage.
virtual void prepare(const Elem *elem, THREAD_ID tid) override
Base class for assembly-like calculations.
virtual void prepareMaterials(SubdomainID blk_id, THREAD_ID tid)
Add the MooseVariables that the current materials depend on to the dependency list.
Class for stuff related to variables.
Definition: MooseVariable.h:43
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
virtual void reinitMaterialsNeighbor(SubdomainID blk_id, THREAD_ID tid, bool swap_stateful=true)
virtual void subdomainSetup(THREAD_ID tid=0) const
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id) override
Called when doing boundary assembling.
static PetscErrorCode Vec x
virtual void reinitElem(const Elem *elem, THREAD_ID tid) override
virtual void reinitMaterials(SubdomainID blk_id, THREAD_ID tid, bool swap_stateful=true)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void setActiveMaterialProperties(const std::set< unsigned int > &mat_prop_ids, THREAD_ID tid) override
Record and set the material properties required by the current computing thread.
virtual void subdomainSetup(SubdomainID subdomain, THREAD_ID tid)
virtual void postElement(const Elem *) override
Called after the element assembly is done (including surface assembling)
std::vector< std::map< std::string, MooseVariable * > > _elem_vars
ComputeIndicatorThread(FEProblemBase &fe_problem, bool finalize=false)
void updateVariableDependency(std::set< MooseVariable * > &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
virtual void clearActiveMaterialProperties(THREAD_ID tid) override
Clear the active material properties.
virtual void swapBackMaterials(THREAD_ID tid)
virtual void swapBackMaterialsNeighbor(THREAD_ID tid)
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
virtual NumericVector< Number > & solution() override
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
void updateMatPropDependency(std::set< unsigned int > &needed_mat_props, THREAD_ID tid=0) const
Update material property dependency vector.
virtual void reinitMaterialsFace(SubdomainID blk_id, THREAD_ID tid, bool swap_stateful=true)
const MooseObjectWarehouse< Indicator > & _indicator_whs
Indicator Storage.
void join(const ComputeIndicatorThread &)
virtual void reinitNeighbor(const Elem *elem, unsigned int side, THREAD_ID tid) override
bool hasActiveBlockObjects(THREAD_ID tid=0) const
SubdomainID _subdomain
The subdomain for the current element.
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
void add(NumericVector< Number > &residual)
virtual void post() override
Called after the element range loop.
virtual void swapBackMaterialsFace(THREAD_ID tid)
virtual void clearActiveElementalMooseVariables(THREAD_ID tid) override
Clear the active elemental MooseVariable.
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
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}.