www.mooseframework.org
ComputeElemAuxVarsThread.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 
16 
17 // MOOSE includes
18 #include "AuxiliarySystem.h"
19 #include "AuxKernel.h"
20 #include "SwapBackSentinel.h"
21 #include "FEProblem.h"
22 
23 #include "libmesh/threads.h"
24 
26  const MooseObjectWarehouse<AuxKernel> & storage,
27  bool need_materials)
28  : ThreadedElementLoop<ConstElemRange>(problem),
29  _aux_sys(problem.getAuxiliarySystem()),
30  _aux_kernels(storage),
31  _need_materials(need_materials)
32 {
33 }
34 
35 // Splitting Constructor
37  Threads::split /*split*/)
38  : ThreadedElementLoop<ConstElemRange>(x._fe_problem),
39  _aux_sys(x._aux_sys),
42 {
43 }
44 
46 
47 void
49 {
51 
52  // prepare variables
53  for (const auto & it : _aux_sys._elem_vars[_tid])
54  {
55  MooseVariable * var = it.second;
56  var->prepareAux();
57  }
58 
59  std::set<MooseVariable *> needed_moose_vars;
60  std::set<unsigned int> needed_mat_props;
61 
63  {
64  const std::vector<std::shared_ptr<AuxKernel>> & kernels =
66  for (const auto & aux : kernels)
67  {
68  aux->subdomainSetup();
69  const std::set<MooseVariable *> & mv_deps = aux->getMooseVariableDependencies();
70  const std::set<unsigned int> & mp_deps = aux->getMatPropDependencies();
71  needed_moose_vars.insert(mv_deps.begin(), mv_deps.end());
72  needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
73  }
74  }
75 
76  _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
77  _fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
79 }
80 
81 void
83 {
85  {
86  const std::vector<std::shared_ptr<AuxKernel>> & kernels =
88  _fe_problem.prepare(elem, _tid);
90 
91  // Set up the sentinel so that, even if reinitMaterials() throws, we
92  // still remember to swap back.
94 
95  if (_need_materials)
96  _fe_problem.reinitMaterials(elem->subdomain_id(), _tid);
97 
98  for (const auto & aux : kernels)
99  aux->compute();
100 
101  // update the solution vector
102  {
103  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
104  for (const auto & it : _aux_sys._elem_vars[_tid])
105  {
106  MooseVariable * var = it.second;
107  var->insert(_aux_sys.solution());
108  }
109  }
110  }
111 }
112 
113 void
115 {
118 }
119 
120 void
122 {
123 }
virtual void setActiveElementalMooseVariables(const std::set< MooseVariable * > &moose_vars, THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
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
virtual void post() override
Called after the element range loop.
const MooseObjectWarehouse< AuxKernel > & _aux_kernels
Storage object containing active AuxKernel objects.
void join(const ComputeElemAuxVarsThread &)
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::map< std::string, MooseVariable * > > _elem_vars
virtual void clearActiveMaterialProperties(THREAD_ID tid) override
Clear the active material properties.
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
virtual void swapBackMaterials(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 subdomainChanged() override
Called every time the current subdomain changes (i.e.
ComputeElemAuxVarsThread(FEProblemBase &problem, const MooseObjectWarehouse< AuxKernel > &storage, bool need_materials)
bool hasActiveBlockObjects(THREAD_ID tid=0) const
SubdomainID _subdomain
The subdomain for the current element.
void insert(NumericVector< Number > &residual)
virtual void clearActiveElementalMooseVariables(THREAD_ID tid) override
Clear the active elemental MooseVariable.
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}.