www.mooseframework.org
ComputeUserObjectsThread.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 #include "Problem.h"
17 #include "SystemBase.h"
18 #include "ElementUserObject.h"
19 #include "ShapeElementUserObject.h"
20 #include "SideUserObject.h"
21 #include "ShapeSideUserObject.h"
22 #include "InternalSideUserObject.h"
23 #include "NodalUserObject.h"
24 #include "SwapBackSentinel.h"
25 #include "FEProblem.h"
26 
27 #include "libmesh/numeric_vector.h"
28 
30  FEProblemBase & problem,
31  SystemBase & sys,
32  const MooseObjectWarehouse<ElementUserObject> & elemental_user_objects,
33  const MooseObjectWarehouse<SideUserObject> & side_user_objects,
34  const MooseObjectWarehouse<InternalSideUserObject> & internal_side_user_objects)
35  : ThreadedElementLoop<ConstElemRange>(problem),
36  _soln(*sys.currentSolution()),
37  _elemental_user_objects(elemental_user_objects),
38  _side_user_objects(side_user_objects),
39  _internal_side_user_objects(internal_side_user_objects)
40 {
41 }
42 
43 // Splitting Constructor
45  : ThreadedElementLoop<ConstElemRange>(x._fe_problem),
46  _soln(x._soln),
50 {
51 }
52 
54 
55 void
57 {
59 
60  std::set<MooseVariable *> needed_moose_vars;
64 
65  std::set<unsigned int> needed_mat_props;
69 
73 
75  _fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
77 }
78 
79 void
81 {
82  _fe_problem.prepare(elem, _tid);
84 
85  // Set up Sentinel class so that, even if reinitMaterials() throws, we
86  // still remember to swap back during stack unwinding.
89 
91  {
93  for (const auto & uo : objects)
94  uo->execute();
95  }
96 
97  // UserObject Jacobians
100  {
101  // Prepare shape functions for ShapeElementUserObjects
102  std::vector<MooseVariable *> jacobian_moose_vars =
104  for (auto & jvar : jacobian_moose_vars)
105  {
106  unsigned int jvar_id = jvar->number();
107  std::vector<dof_id_type> & dof_indices = jvar->dofIndices();
108 
109  _fe_problem.prepareShapes(jvar_id, _tid);
110 
112  for (const auto & uo : e_objects)
113  {
114  auto shape_element_uo = std::dynamic_pointer_cast<ShapeElementUserObject>(uo);
115  if (shape_element_uo)
116  shape_element_uo->executeJacobianWrapper(jvar_id, dof_indices);
117  }
118  }
119  }
120 }
121 
122 void
123 ComputeUserObjectsThread::onBoundary(const Elem * elem, unsigned int side, BoundaryID bnd_id)
124 {
126  return;
127 
128  _fe_problem.reinitElemFace(elem, side, bnd_id, _tid);
129 
130  // Set up Sentinel class so that, even if reinitMaterialsFace() throws, we
131  // still remember to swap back during stack unwinding.
135 
136  const auto & objects = _side_user_objects.getActiveBoundaryObjects(bnd_id, _tid);
137  for (const auto & uo : objects)
138  uo->execute();
139 
140  // UserObject Jacobians
142  {
143  // Prepare shape functions for ShapeSideUserObjects
144  std::vector<MooseVariable *> jacobian_moose_vars =
146  for (auto & jvar : jacobian_moose_vars)
147  {
148  unsigned int jvar_id = jvar->number();
149  std::vector<dof_id_type> & dof_indices = jvar->dofIndices();
150 
152 
153  for (const auto & uo : objects)
154  {
155  auto shape_side_uo = std::dynamic_pointer_cast<ShapeSideUserObject>(uo);
156  if (shape_side_uo)
157  shape_side_uo->executeJacobianWrapper(jvar_id, dof_indices);
158  }
159  }
160  }
161 }
162 
163 void
164 ComputeUserObjectsThread::onInternalSide(const Elem * elem, unsigned int side)
165 {
166  // Pointer to the neighbor we are currently working on.
167  const Elem * neighbor = elem->neighbor_ptr(side);
168 
169  // Get the global id of the element and the neighbor
170  const dof_id_type elem_id = elem->id(), neighbor_id = neighbor->id();
171 
173  return;
174  if (!((neighbor->active() && (neighbor->level() == elem->level()) && (elem_id < neighbor_id)) ||
175  (neighbor->level() < elem->level())))
176  return;
177 
179  _fe_problem.reinitNeighbor(elem, side, _tid);
180 
181  // Set up Sentinels so that, even if one of the reinitMaterialsXXX() calls throws, we
182  // still remember to swap back during stack unwinding.
184  _fe_problem.reinitMaterialsFace(elem->subdomain_id(), _tid);
185 
187  _fe_problem.reinitMaterialsNeighbor(neighbor->subdomain_id(), _tid);
188 
190  for (const auto & uo : objects)
191  {
192  if (!uo->blockRestricted())
193  uo->execute();
194  else if (uo->hasBlocks(neighbor->subdomain_id()))
195  uo->execute();
196  }
197 }
198 
199 void
201 {
204 }
205 
206 void
208 {
209 }
void updateBlockVariableDependency(SubdomainID id, std::set< MooseVariable * > &needed_moose_vars, THREAD_ID tid=0) const
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 post() override
Called after the element range loop.
virtual void prepareFace(const Elem *elem, THREAD_ID tid) override
virtual void prepareMaterials(SubdomainID blk_id, THREAD_ID tid)
Add the MooseVariables that the current materials depend on to the dependency list.
void updateBlockMatPropDependency(SubdomainID id, std::set< unsigned int > &needed_mat_props, THREAD_ID tid=0) const
const std::vector< MooseVariable * > & getUserObjectJacobianVariables(THREAD_ID tid) const
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
const MooseObjectWarehouse< InternalSideUserObject > & _internal_side_user_objects
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.
virtual void subdomainSetup(THREAD_ID tid=0) const
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
virtual bool currentlyComputingJacobian()
Returns true if we are currently computing Jacobian.
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
static PetscErrorCode Vec x
Base class for a system (of equations)
Definition: SystemBase.h:91
virtual void reinitElem(const Elem *elem, THREAD_ID tid) override
virtual void reinitMaterials(SubdomainID blk_id, THREAD_ID tid, bool swap_stateful=true)
virtual void reinitMaterialsBoundary(BoundaryID boundary_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)
const MooseObjectWarehouse< SideUserObject > & _side_user_objects
void updateBoundaryVariableDependency(std::set< MooseVariable * > &needed_moose_vars, THREAD_ID tid=0) const
const MooseObjectWarehouse< ElementUserObject > & _elemental_user_objects
ElementUserObject class in which the _phi and _grad_phi shape function data is available and correctl...
void updateBoundaryMatPropDependency(std::set< unsigned int > &needed_mat_props, THREAD_ID tid=0) const
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
virtual void clearActiveMaterialProperties(THREAD_ID tid) override
Clear the active material properties.
void join(const ComputeUserObjectsThread &)
virtual void swapBackMaterials(THREAD_ID tid)
const NumericVector< Number > & _soln
virtual void swapBackMaterialsNeighbor(THREAD_ID tid)
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
virtual void executeJacobianWrapper(unsigned int jvar, const std::vector< dof_id_type > &dof_indices)
This function will be called with the shape functions for jvar initialized.
virtual void reinitElemFace(const Elem *elem, unsigned int side, BoundaryID bnd_id, THREAD_ID tid) override
Class for threaded computation of UserObjects.
virtual void reinitMaterialsFace(SubdomainID blk_id, THREAD_ID tid, bool swap_stateful=true)
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
virtual void prepareFaceShapes(unsigned int var, THREAD_ID tid) override
virtual void reinitNeighbor(const Elem *elem, unsigned int side, THREAD_ID tid) override
bool hasActiveBlockObjects(THREAD_ID tid=0) const
virtual void prepareShapes(unsigned int var, THREAD_ID tid) override
SubdomainID _subdomain
The subdomain for the current element.
virtual void swapBackMaterialsFace(THREAD_ID tid)
virtual void clearActiveElementalMooseVariables(THREAD_ID tid) override
Clear the active elemental MooseVariable.
SideUserObject class in which the _phi and _grad_phi shape function data is available and correctly i...
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}.
ComputeUserObjectsThread(FEProblemBase &problem, SystemBase &sys, const MooseObjectWarehouse< ElementUserObject > &elemental_user_objects, const MooseObjectWarehouse< SideUserObject > &side_user_objects, const MooseObjectWarehouse< InternalSideUserObject > &internal_side_user_objects)