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 
21 #include "libmesh/threads.h"
22 
24  : ThreadedElementLoop<ConstElemRange>(fe_problem),
25  _fe_problem(fe_problem),
26  _aux_sys(fe_problem.getAuxiliarySystem()),
27  _indicator_whs(_fe_problem.getIndicatorWarehouse()),
28  _internal_side_indicators(_fe_problem.getInternalSideIndicatorWarehouse()),
29  _finalize(finalize)
30 {
31 }
32 
33 // Splitting Constructor
35  : ThreadedElementLoop<ConstElemRange>(x, split),
36  _fe_problem(x._fe_problem),
37  _aux_sys(x._aux_sys),
38  _indicator_whs(x._indicator_whs),
39  _internal_side_indicators(x._internal_side_indicators),
40  _finalize(x._finalize)
41 {
42 }
43 
45 
46 void
48 {
50 
53 
54  std::set<MooseVariableFEBase *> needed_moose_vars;
55  _indicator_whs.updateVariableDependency(needed_moose_vars, _tid);
58 
59  std::set<unsigned int> needed_mat_props;
60  _indicator_whs.updateMatPropDependency(needed_mat_props, _tid);
62  _fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
63 
65 }
66 
67 void
69 {
70  for (auto * var : _aux_sys._elem_vars[_tid])
71  var->prepareAux();
72 
73  _fe_problem.prepare(elem, _tid);
75 
76  // Set up Sentinel class so that, even if reinitMaterials() throws, we
77  // still remember to swap back during stack unwinding.
79 
81 
82  // Compute
83  if (!_finalize)
84  {
86  {
87  const std::vector<std::shared_ptr<Indicator>> & indicators =
89  for (const auto & indicator : indicators)
90  indicator->computeIndicator();
91  }
92  }
93 
94  // Finalize
95  else
96  {
98  {
99  const std::vector<std::shared_ptr<Indicator>> & indicators =
101  for (const auto & indicator : indicators)
102  indicator->finalize();
103  }
104 
106  {
107  const std::vector<std::shared_ptr<InternalSideIndicator>> & internal_indicators =
109  for (const auto & internal_indicator : internal_indicators)
110  internal_indicator->finalize();
111  }
112  }
113 
114  if (!_finalize) // During finalize the Indicators should be setting values in the vectors manually
115  {
116  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
117  for (auto * var : _aux_sys._elem_vars[_tid])
118  var->add(_aux_sys.solution());
119  }
120 }
121 
122 void
124  unsigned int /*side*/,
125  BoundaryID /*bnd_id*/)
126 {
127 }
128 
129 void
130 ComputeIndicatorThread::onInternalSide(const Elem * elem, unsigned int side)
131 {
132  if (_finalize) // If finalizing we only do something on the elements
133  return;
134 
135  // Pointer to the neighbor we are currently working on.
136  const Elem * neighbor = elem->neighbor_ptr(side);
137 
138  // Get the global id of the element and the neighbor
139  const dof_id_type elem_id = elem->id(), neighbor_id = neighbor->id();
140 
141  if ((neighbor->active() && (neighbor->level() == elem->level()) && (elem_id < neighbor_id)) ||
142  (neighbor->level() < elem->level()))
143  {
144  for (auto * var : _aux_sys._elem_vars[_tid])
145  var->prepareAux();
146 
147  SubdomainID block_id = elem->subdomain_id();
149  {
150  _fe_problem.reinitNeighbor(elem, side, _tid);
151 
152  // Set up Sentinels so that, even if one of the reinitMaterialsXXX() calls throws, we
153  // still remember to swap back during stack unwinding.
156 
157  SwapBackSentinel neighbor_sentinel(
159  _fe_problem.reinitMaterialsNeighbor(neighbor->subdomain_id(), _tid);
160 
161  const std::vector<std::shared_ptr<InternalSideIndicator>> & indicators =
163  for (const auto & indicator : indicators)
164  indicator->computeIndicator();
165  }
166  }
167 }
168 
169 void
171 {
172 }
173 
174 void
176 {
179 }
180 
181 void
183 {
184 }
const MooseObjectWarehouse< InternalSideIndicator > & _internal_side_indicators
InternalSideIndicator Storage.
virtual void prepare(const Elem *elem, THREAD_ID tid) override
Base class for assembly-like calculations.
bool hasActiveBlockObjects(THREAD_ID tid=0) const
virtual void prepareMaterials(SubdomainID blk_id, THREAD_ID tid)
Add the MooseVariables that the current materials depend on to the dependency list.
virtual void setActiveElementalMooseVariables(const std::set< MooseVariableFEBase *> &moose_vars, THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
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 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)
std::vector< std::string > split(const std::string &str, const std::string &delimiter)
Python like split function for strings.
Definition: MooseUtils.C:784
virtual void postElement(const Elem *) override
Called after the element assembly is done (including surface assembling)
ComputeIndicatorThread(FEProblemBase &fe_problem, bool finalize=false)
boundary_id_type BoundaryID
virtual void clearActiveMaterialProperties(THREAD_ID tid) override
Clear the active material properties.
NumericVector< Number > & solution() override
void updateVariableDependency(std::set< MooseVariableFEBase *> &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
subdomain_id_type SubdomainID
virtual void swapBackMaterials(THREAD_ID tid)
virtual void swapBackMaterialsNeighbor(THREAD_ID tid)
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
std::vector< std::vector< MooseVariableFEBase * > > _elem_vars
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
SubdomainID _subdomain
The subdomain for the current element.
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
virtual void post() override
Called after the element range loop.
void updateMatPropDependency(std::set< unsigned int > &needed_mat_props, THREAD_ID tid=0) const
Update material property dependency vector.
virtual void swapBackMaterialsFace(THREAD_ID tid)
virtual void subdomainSetup(THREAD_ID tid=0) const
virtual void clearActiveElementalMooseVariables(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}.