https://mooseframework.inl.gov
ComputeMaterialsObjectThread.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 
10 // MOOSE includes
12 #include "NonlinearSystem.h"
13 #include "Problem.h"
14 #include "FEProblem.h"
16 #include "MaterialData.h"
17 #include "Assembly.h"
18 #include "AuxKernel.h"
19 #include "Material.h"
20 
21 #include "libmesh/threads.h"
22 #include "libmesh/quadrature.h"
23 
25  FEProblemBase & fe_problem,
26  MaterialPropertyStorage & material_props,
27  MaterialPropertyStorage & bnd_material_props,
28  MaterialPropertyStorage & neighbor_material_props,
29  std::vector<std::vector<std::unique_ptr<Assembly>>> & assembly)
30  : ThreadedElementLoop<ConstElemRange>(fe_problem),
31  _fe_problem(fe_problem),
32  _material_props(material_props),
33  _bnd_material_props(bnd_material_props),
34  _neighbor_material_props(neighbor_material_props),
35  _materials(_fe_problem.getRegularMaterialsWarehouse()),
36  _interface_materials(_fe_problem.getInterfaceMaterialsWarehouse()),
37  _discrete_materials(_fe_problem.getDiscreteMaterialWarehouse()),
38  _assembly(assembly),
39  _need_internal_side_material(false),
40  _has_stateful_props(_material_props.hasStatefulProperties()),
41  _has_bnd_stateful_props(_bnd_material_props.hasStatefulProperties()),
42  _has_neighbor_stateful_props(_neighbor_material_props.hasStatefulProperties())
43 {
44 }
45 
46 // Splitting Constructor
50  _fe_problem(x._fe_problem),
51  _material_props(x._material_props),
52  _bnd_material_props(x._bnd_material_props),
53  _neighbor_material_props(x._neighbor_material_props),
54  _materials(x._materials),
55  _interface_materials(x._interface_materials),
56  _discrete_materials(x._discrete_materials),
57  _assembly(x._assembly),
58  _need_internal_side_material(x._need_internal_side_material),
59  _has_stateful_props(_material_props.hasStatefulProperties()),
60  _has_bnd_stateful_props(_bnd_material_props.hasStatefulProperties()),
61  _has_neighbor_stateful_props(_neighbor_material_props.hasStatefulProperties())
62 {
63 }
64 
65 void
67 {
70 
71  std::set<MooseVariableFEBase *> needed_moose_vars;
72  _materials.updateVariableDependency(needed_moose_vars, _tid);
75 
76  std::set<TagID> needed_fe_var_vector_tags;
78  _subdomain, needed_fe_var_vector_tags, _tid);
80  _subdomain, needed_fe_var_vector_tags, _tid);
81  _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_fe_var_vector_tags, _tid);
82 
83  // Note that we do not know here which materials will be active on this subdomain because we don't
84  // have the various warehouses (kernels, ...) to gather the needed material properties like in
85  // NonlinearThread
86 }
87 
88 void
90 {
93  {
94  _fe_problem.prepare(elem, _tid);
96 
97  auto & material_data = _material_props.getMaterialData(_tid);
98 
99  unsigned int n_points = _assembly[_tid][0]->qRule()->n_points();
100  material_data.resize(n_points);
101 
103  {
109  _tid, _materials.getActiveBlockObjects(_subdomain, _tid), n_points, *elem);
110  }
111  }
112 }
113 
114 void
116  unsigned int side,
117  BoundaryID bnd_id,
118  const Elem * /*lower_d_elem = nullptr*/)
119 {
121  {
122  _fe_problem.reinitElemFace(elem, side, _tid);
123  const auto face_n_points = _assembly[_tid][/*system_index*/ 0]->qRuleFace()->n_points();
124 
126 
128  {
129  // Face Materials
130  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
132  _tid,
134  face_n_points,
135  *elem,
136  side);
137  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
139  _tid,
140  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
141  face_n_points,
142  *elem,
143  side);
144 
145  // Boundary Materials
148  _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
151  _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
152  }
153  }
154 }
155 
156 void
157 ComputeMaterialsObjectThread::onInternalSide(const Elem * elem, unsigned int side)
158 {
160  {
161  const Elem * neighbor = elem->neighbor_ptr(side);
162 
164  unsigned int face_n_points = _assembly[_tid][0]->qRuleFace()->n_points();
167 
169  {
170  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
172  _tid,
174  face_n_points,
175  *elem,
176  side);
177  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
179  _tid,
180  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
181  face_n_points,
182  *elem,
183  side);
184  }
185 
186  unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[_tid][0]->elem());
187 
189  {
190  // Neighbor Materials
191  if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(
192  neighbor->subdomain_id(), _tid))
194  _tid,
195  _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
196  neighbor->subdomain_id(), _tid),
197  face_n_points,
198  *elem,
199  side);
200  if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(neighbor->subdomain_id(),
201  _tid))
203  _tid,
204  _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
205  neighbor->subdomain_id(), _tid),
206  face_n_points,
207  *neighbor,
208  neighbor_side);
209  }
210  }
211 }
212 
213 void
214 ComputeMaterialsObjectThread::onInterface(const Elem * elem, unsigned int side, BoundaryID bnd_id)
215 {
217  return;
218 
219  _fe_problem.reinitElemFace(elem, side, _tid);
220  unsigned int face_n_points = _assembly[_tid][0]->qRuleFace()->n_points();
221 
224 
226  {
227  // Face Materials
228  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
230  _tid,
232  face_n_points,
233  *elem,
234  side);
235 
236  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
238  _tid,
239  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
240  face_n_points,
241  *elem,
242  side);
243 
244  // Boundary Materials
247  _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
248 
251  _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
252  }
253 
254  const Elem * neighbor = elem->neighbor_ptr(side);
255  unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[_tid][0]->elem());
256 
257  // Do we have neighbor stateful properties or do we have stateful interface material properties?
258  // If either then we need to reinit the neighbor, so at least at a minimum _neighbor_elem isn't
259  // NULL!
260  if (neighbor->active() &&
263  _fe_problem.reinitNeighbor(elem, side, _tid);
264 
265  if (_has_neighbor_stateful_props && neighbor->active())
266  {
267  // Neighbor Materials
268  if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(
269  neighbor->subdomain_id(), _tid))
271  _tid,
272  _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
273  neighbor->subdomain_id(), _tid),
274  face_n_points,
275  *elem,
276  side);
277 
278  if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(neighbor->subdomain_id(),
279  _tid))
281  _tid,
282  _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(neighbor->subdomain_id(),
283  _tid),
284  face_n_points,
285  *neighbor,
286  neighbor_side);
287  }
288 
289  // Interface Materials. Make sure we do these after neighbors
292  _tid,
294  face_n_points,
295  *elem,
296  side);
297 }
298 
299 void
301 {
302 }
303 
304 void
306 {
308 }
void updateVariableDependency(std::set< MooseVariableFieldBase *> &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
Base class for assembly-like calculations.
bool hasActiveBlockObjects(THREAD_ID tid=0) const
void join(const ComputeMaterialsObjectThread &)
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
virtual void prepare(const Elem *elem, const THREAD_ID tid) override
MaterialPropertyStorage & _material_props
Stores the stateful material properties computed by materials.
bool needBoundaryMaterialOnSide(BoundaryID bnd_id, const THREAD_ID tid)
These methods are used to determine whether stateful material properties need to be stored on interna...
const MaterialWarehouse & _interface_materials
This is populated using _fe_problem.getResidualInterfaceMaterialsWarehouse because it has the union o...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void reinitElemNeighborAndLowerD(const Elem *elem, unsigned int side, const THREAD_ID tid) override
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
virtual void setActiveElementalMooseVariables(const std::set< MooseVariableFEBase *> &moose_vars, const THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
const MaterialWarehouse & _materials
This is populated using _fe_problem.getResidualMaterialsWarehouse because it has the union of traditi...
virtual void reinitElem(const Elem *elem, const THREAD_ID tid) override
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id, const Elem *lower_d_elem=nullptr) override
Called when doing boundary assembling.
boundary_id_type BoundaryID
bool needInternalNeighborSideMaterial(SubdomainID subdomain_id, const THREAD_ID tid)
virtual void onInternalSide(const Elem *elem, unsigned int side) override
Called when doing internal edge assembling.
MaterialPropertyStorage & _neighbor_material_props
virtual void subdomainChanged() override
Called every time the current subdomain changes (i.e.
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
tbb::split split
void updateBlockFEVariableCoupledVectorTagDependency(SubdomainID id, std::set< TagID > &needed_fe_var_vector_tags, THREAD_ID tid=0) const
Update FE variable coupleable vector tag vector.
std::vector< std::vector< std::unique_ptr< Assembly > > > & _assembly
virtual void subdomainSetup(SubdomainID subdomain, const THREAD_ID tid)
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
ComputeMaterialsObjectThread(FEProblemBase &fe_problem, MaterialPropertyStorage &material_props, MaterialPropertyStorage &bnd_material_props, MaterialPropertyStorage &neighbor_material_props, std::vector< std::vector< std::unique_ptr< Assembly >>> &assembly)
bool needInterfaceMaterialOnSide(BoundaryID bnd_id, const THREAD_ID tid)
void reinitElemFace(const Elem *elem, unsigned int side, BoundaryID, const THREAD_ID tid)
SubdomainID _subdomain
The subdomain for the current element.
virtual void post() override
Called after the element range loop.
virtual void reinitNeighbor(const Elem *elem, unsigned int side, const THREAD_ID tid) override
const MaterialData & getMaterialData(const THREAD_ID tid) const
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
void initStatefulProps(const THREAD_ID tid, const std::vector< std::shared_ptr< MaterialBase >> &mats, const unsigned int n_qpoints, const Elem &elem, const unsigned int side=0)
Initialize stateful material properties.
virtual void onInterface(const Elem *elem, unsigned int side, BoundaryID bnd_id) override
Called when doing interface assembling.
MaterialPropertyStorage & _bnd_material_props
virtual void clearActiveElementalMooseVariables(const THREAD_ID tid) override
Clear the active elemental MooseVariableFEBase.
const MaterialWarehouse & _discrete_materials
void resize(unsigned int n_qpoints)
Resize the data to hold properties for n_qpoints quadrature points.
Definition: MaterialData.C:21