www.mooseframework.org
ComputeMaterialsObjectThread.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 
15 // MOOSE includes
17 #include "NonlinearSystem.h"
18 #include "Problem.h"
19 #include "FEProblem.h"
21 #include "MaterialData.h"
22 #include "Assembly.h"
23 #include "AuxKernel.h"
24 #include "Material.h"
25 
26 #include "libmesh/threads.h"
27 #include "libmesh/quadrature.h"
28 
30  FEProblemBase & fe_problem,
31  std::vector<std::shared_ptr<MaterialData>> & material_data,
32  std::vector<std::shared_ptr<MaterialData>> & bnd_material_data,
33  std::vector<std::shared_ptr<MaterialData>> & neighbor_material_data,
34  MaterialPropertyStorage & material_props,
35  MaterialPropertyStorage & bnd_material_props,
36  std::vector<Assembly *> & assembly)
37  : ThreadedElementLoop<ConstElemRange>(fe_problem),
38  _fe_problem(fe_problem),
39  _nl(fe_problem.getNonlinearSystemBase()),
40  _material_data(material_data),
41  _bnd_material_data(bnd_material_data),
42  _neighbor_material_data(neighbor_material_data),
43  _material_props(material_props),
44  _bnd_material_props(bnd_material_props),
45  _materials(_fe_problem.getComputeMaterialWarehouse()),
46  _discrete_materials(_fe_problem.getDiscreteMaterialWarehouse()),
47  _assembly(assembly),
48  _need_internal_side_material(false),
49  _has_stateful_props(_material_props.hasStatefulProperties()),
50  _has_bnd_stateful_props(_bnd_material_props.hasStatefulProperties())
51 {
52 }
53 
54 // Splitting Constructor
56  Threads::split split)
57  : ThreadedElementLoop<ConstElemRange>(x, split),
59  _nl(x._nl),
69  _has_stateful_props(_material_props.hasStatefulProperties()),
70  _has_bnd_stateful_props(_bnd_material_props.hasStatefulProperties())
71 {
72 }
73 
75 
76 void
78 {
81 
82  std::set<MooseVariable *> needed_moose_vars;
83  _materials.updateVariableDependency(needed_moose_vars, _tid);
85 }
86 
87 void
89 {
92  {
93  _fe_problem.prepare(elem, _tid);
95 
96  unsigned int n_points = _assembly[_tid]->qRule()->n_points();
97  _material_data[_tid]->resize(n_points);
98 
100  {
105  n_points,
106  *elem);
110  n_points,
111  *elem);
112  }
113  }
114 }
115 
116 void
117 ComputeMaterialsObjectThread::onBoundary(const Elem * elem, unsigned int side, BoundaryID bnd_id)
118 {
119  if (_fe_problem.needMaterialOnSide(bnd_id, _tid))
120  {
121  _assembly[_tid]->reinit(elem, side);
122  unsigned int face_n_points = _assembly[_tid]->qRuleFace()->n_points();
123 
124  _bnd_material_data[_tid]->resize(face_n_points);
125 
127  {
128  // Face Materials
129  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
132  _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
133  face_n_points,
134  *elem,
135  side);
136  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
138  *_bnd_material_data[_tid],
139  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
140  face_n_points,
141  *elem,
142  side);
143 
144  // Boundary Materials
147  _materials.getActiveBoundaryObjects(bnd_id, _tid),
148  face_n_points,
149  *elem,
150  side);
151  if (_materials.hasActiveBoundaryObjects(bnd_id, _tid))
153  _materials.getActiveBoundaryObjects(bnd_id, _tid),
154  face_n_points,
155  *elem,
156  side);
157  }
158  }
159 }
160 
161 void
162 ComputeMaterialsObjectThread::onInternalSide(const Elem * elem, unsigned int side)
163 {
165  {
166  _assembly[_tid]->reinit(elem, side);
167  unsigned int face_n_points = _assembly[_tid]->qRuleFace()->n_points();
168  _bnd_material_data[_tid]->resize(face_n_points);
169  _neighbor_material_data[_tid]->resize(face_n_points);
170 
172  {
173  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
176  _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
177  face_n_points,
178  *elem,
179  side);
180  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
182  *_bnd_material_data[_tid],
183  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
184  face_n_points,
185  *elem,
186  side);
187  }
188 
189  const Elem * neighbor = elem->neighbor_ptr(side);
190  unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[_tid]->elem());
191  const dof_id_type elem_id = elem->id(), neighbor_id = neighbor->id();
192 
194  ((neighbor->active() && (neighbor->level() == elem->level()) && (elem_id < neighbor_id)) ||
195  (neighbor->level() < elem->level())))
196  {
197  _assembly[_tid]->reinitElemAndNeighbor(elem, side, neighbor, neighbor_side);
198 
199  // Face Materials
200  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
203  _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
204  face_n_points,
205  *elem,
206  side);
207  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
209  *_bnd_material_data[_tid],
210  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
211  face_n_points,
212  *elem,
213  side);
214 
215  // Neighbor Materials
216  if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(
217  neighbor->subdomain_id(), _tid))
219  *_bnd_material_data[_tid],
220  _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
221  neighbor->subdomain_id(), _tid),
222  face_n_points,
223  *elem,
224  side);
225  if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(neighbor->subdomain_id(),
226  _tid))
229  _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
230  neighbor->subdomain_id(), _tid),
231  face_n_points,
232  *neighbor,
233  neighbor_side);
234  }
235  }
236 }
237 
238 void
240 {
241 }
242 
243 void
245 {
247 }
virtual void setActiveElementalMooseVariables(const std::set< MooseVariable * > &moose_vars, THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
std::vector< std::shared_ptr< MaterialData > > & _neighbor_material_data
virtual void prepare(const Elem *elem, THREAD_ID tid) override
Base class for assembly-like calculations.
std::vector< std::shared_ptr< MaterialData > > & _material_data
void join(const ComputeMaterialsObjectThread &)
void initStatefulProps(MaterialData &material_data, const std::vector< std::shared_ptr< Material >> &mats, unsigned int n_qpoints, const Elem &elem, unsigned int side=0)
Initialize stateful material properties.
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
MaterialPropertyStorage & _material_props
Stores the stateful material properties computed by materials.
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id) override
Called when doing boundary assembling.
bool needMaterialOnSide(BoundaryID bnd_id, THREAD_ID tid)
These methods are used to determine whether stateful material properties need to be stored on interna...
static PetscErrorCode Vec x
virtual void reinitElem(const Elem *elem, THREAD_ID tid) override
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void subdomainSetup(SubdomainID subdomain, THREAD_ID tid)
std::vector< std::shared_ptr< MaterialData > > & _bnd_material_data
const MaterialWarehouse & _materials
Reference to the Material object warehouses.
void updateVariableDependency(std::set< MooseVariable * > &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
bool hasActiveBlockObjects(THREAD_ID tid=0) const
SubdomainID _subdomain
The subdomain for the current element.
virtual void post() override
Called after the element range loop.
MaterialPropertyStorage & _bnd_material_props
virtual void clearActiveElementalMooseVariables(THREAD_ID tid) override
Clear the active elemental MooseVariable.
const MaterialWarehouse & _discrete_materials
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
ComputeMaterialsObjectThread(FEProblemBase &fe_problem, std::vector< std::shared_ptr< MaterialData >> &material_data, std::vector< std::shared_ptr< MaterialData >> &bnd_material_data, std::vector< std::shared_ptr< MaterialData >> &neighbor_material_data, MaterialPropertyStorage &material_props, MaterialPropertyStorage &bnd_material_props, std::vector< Assembly * > &assembly)
std::vector< Assembly * > & _assembly