https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeIndicatorThread.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
11
12// MOOSE includes
13#include "AuxiliarySystem.h"
14#include "FEProblem.h"
15#include "Indicator.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
38 : ThreadedElementLoop<ConstElemRange>(x, split),
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
49void
51{
53
56
57 std::set<MooseVariableFEBase *> needed_moose_vars;
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;
75
76 // Only prepare (and therefore reinit) materials if an indicator actually consumes a material
77 // property. Otherwise skip the material system entirely to avoid recomputing the whole stack.
78 if (!needed_mat_props.empty())
79 _fe_problem.prepareMaterials(needed_mat_props, _subdomain, _tid);
80 else
82}
83
84void
86{
87 for (auto * var : _aux_sys._elem_vars[_tid])
88 var->prepareAux();
89
92
93 // Set up Sentinel class so that, even if reinitMaterials() throws, we
94 // still remember to swap back during stack unwinding.
96
98
99 // Compute
100 if (!_finalize)
101 {
103 {
104 const std::vector<std::shared_ptr<Indicator>> & indicators =
106 for (const auto & indicator : indicators)
107 indicator->computeIndicator();
108 }
109 }
110
111 // Finalize
112 else
113 {
115 {
116 const std::vector<std::shared_ptr<Indicator>> & indicators =
118 for (const auto & indicator : indicators)
119 indicator->finalize();
120 }
121
123 {
124 const std::vector<std::shared_ptr<InternalSideIndicatorBase>> & internal_indicators =
126 for (const auto & internal_indicator : internal_indicators)
127 internal_indicator->finalize();
128 }
129 }
130
131 if (!_finalize) // During finalize the Indicators should be setting values in the vectors manually
132 for (auto * var : _aux_sys._elem_vars[_tid])
133 var->add(_aux_sys.solution());
134}
135
136void
138 unsigned int /*side*/,
139 BoundaryID /*bnd_id*/,
140 const Elem * /*lower_d_elem = nullptr*/)
141{
142}
143
144void
145ComputeIndicatorThread::onInternalSide(const Elem * elem, unsigned int side)
146{
147 if (_finalize) // If finalizing we only do something on the elements
148 return;
149
150 // Pointer to the neighbor we are currently working on.
151 const Elem * neighbor = elem->neighbor_ptr(side);
152
153 for (auto * var : _aux_sys._elem_vars[_tid])
154 var->prepareAux();
155
156 SubdomainID block_id = elem->subdomain_id();
158 {
159 _fe_problem.reinitNeighbor(elem, side, _tid);
160
161 // Set up Sentinels so that, even if one of the reinitMaterialsXXX() calls throws, we
162 // still remember to swap back during stack unwinding.
165
166 SwapBackSentinel neighbor_sentinel(
168 _fe_problem.reinitMaterialsNeighbor(neighbor->subdomain_id(), _tid);
169
170 const std::vector<std::shared_ptr<InternalSideIndicatorBase>> & indicators =
172 for (const auto & indicator : indicators)
173 indicator->computeIndicator();
174 }
175}
176
177void
179{
180}
181
182void
188
189void
193
194void
196{
198 return;
199
200 const auto & console = _fe_problem.console();
201 const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
202 if (!_finalize)
203 console << "[DBG] Executing indicators on elements then on internal sides on " << execute_on
204 << std::endl;
205 else
206 console << "[DBG] Finalizing indicator loop" << std::endl;
207}
208
209void
211{
213 return;
214
215 const auto & console = _fe_problem.console();
217 {
218 const auto & indicators = _indicator_whs.getActiveBlockObjects(_subdomain, _tid);
219 console << "[DBG] Ordering of element indicators on block " << _subdomain << std::endl;
220 printExecutionOrdering<Indicator>(indicators, false);
221 }
223 {
225 console << "[DBG] Ordering of element internal sides indicators on block " << _subdomain
226 << std::endl;
227 printExecutionOrdering<InternalSideIndicatorBase>(indicators, false);
228 }
230}
boundary_id_type BoundaryID
std::vector< std::vector< MooseVariableFieldBase * > > _elem_vars
Elemental variables.
void printBlockExecutionInformation() const override
Print list of specific objects executed and in which order.
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
virtual void postElement(const Elem *) override
Called after the element assembly is done (including surface assembling)
ComputeIndicatorThread(FEProblemBase &fe_problem, bool finalize=false)
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
const MooseObjectWarehouse< InternalSideIndicatorBase > & _internal_side_indicators
InternalSideIndicator Storage.
virtual void post() override
Called after the element range loop.
void join(const ComputeIndicatorThread &)
void printGeneralExecutionInformation() const override
Print general information about the loop when it executes.
const MooseObjectWarehouse< Indicator > & _indicator_whs
Indicator Storage.
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr) override
Called when doing boundary assembling.
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
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 reinitElem(const Elem *elem, const THREAD_ID tid) override
virtual void swapBackMaterialsFace(const THREAD_ID tid)
const MaterialWarehouse & getMaterialWarehouse() const
void reinitMaterials(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true)
virtual void prepare(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
virtual void swapBackMaterialsNeighbor(const THREAD_ID tid)
void clearActiveMaterialProperties(const THREAD_ID tid)
Clear the active material properties.
virtual void clearActiveElementalMooseVariables(const THREAD_ID tid) override
Clear the active elemental MooseVariableFEBase.
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...
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
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 swapBackMaterials(const THREAD_ID tid)
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
virtual void subdomainSetup(SubdomainID subdomain, const THREAD_ID tid)
virtual void reinitNeighbor(const Elem *elem, unsigned int side, const THREAD_ID tid) override
void updateVariableDependency(std::set< MooseVariableFieldBase * > &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
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.
void updateBlockFEVariableCoupledVectorTagDependency(SubdomainID id, std::set< TagID > &needed_fe_var_vector_tags, THREAD_ID tid=0) const
bool hasActiveBlockObjects(THREAD_ID tid=0) const
virtual void subdomainSetup(THREAD_ID tid=0) const
const ConsoleStream & console() const
Return console handle.
Definition Problem.h:48
The "SwapBackSentinel" class's destructor guarantees that FEProblemBase::swapBackMaterials{Face,...
NumericVector< Number > & solution()
Definition SystemBase.h:203
SubdomainID _subdomain
The subdomain for the current element.
std::set< SubdomainID > _blocks_exec_printed
Keep track of which blocks were visited.
Base class for assembly-like calculations.