www.mooseframework.org
ComputeMaterialsObjectThread.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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
48  Threads::split split)
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 
84 void
86 {
89  {
90  _fe_problem.prepare(elem, _tid);
92 
93  auto & material_data = _material_props.getMaterialData(_tid);
94 
95  unsigned int n_points = _assembly[_tid][0]->qRule()->n_points();
96  material_data.resize(n_points);
97 
99  {
105  _tid, _materials.getActiveBlockObjects(_subdomain, _tid), n_points, *elem);
106  }
107  }
108 }
109 
110 void
112  unsigned int side,
113  BoundaryID bnd_id,
114  const Elem * /*lower_d_elem = nullptr*/)
115 {
117  {
118  _fe_problem.reinitElemFace(elem, side, bnd_id, _tid);
119  unsigned int face_n_points = _assembly[_tid][0]->qRuleFace()->n_points();
120 
122 
124  {
125  // Face Materials
126  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
128  _tid,
130  face_n_points,
131  *elem,
132  side);
133  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
135  _tid,
136  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
137  face_n_points,
138  *elem,
139  side);
140 
141  // Boundary Materials
144  _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
147  _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
148  }
149  }
150 }
151 
152 void
153 ComputeMaterialsObjectThread::onInternalSide(const Elem * elem, unsigned int side)
154 {
156  {
157  const Elem * neighbor = elem->neighbor_ptr(side);
158 
160  unsigned int face_n_points = _assembly[_tid][0]->qRuleFace()->n_points();
163 
165  {
166  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
168  _tid,
170  face_n_points,
171  *elem,
172  side);
173  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
175  _tid,
176  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
177  face_n_points,
178  *elem,
179  side);
180  }
181 
182  unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[_tid][0]->elem());
183 
185  {
186  // Neighbor Materials
187  if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(
188  neighbor->subdomain_id(), _tid))
190  _tid,
191  _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
192  neighbor->subdomain_id(), _tid),
193  face_n_points,
194  *elem,
195  side);
196  if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(neighbor->subdomain_id(),
197  _tid))
199  _tid,
200  _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
201  neighbor->subdomain_id(), _tid),
202  face_n_points,
203  *neighbor,
204  neighbor_side);
205  }
206  }
207 }
208 
209 void
210 ComputeMaterialsObjectThread::onInterface(const Elem * elem, unsigned int side, BoundaryID bnd_id)
211 {
213  return;
214 
215  _fe_problem.reinitElemFace(elem, side, bnd_id, _tid);
216  unsigned int face_n_points = _assembly[_tid][0]->qRuleFace()->n_points();
217 
220 
222  {
223  // Face Materials
224  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
226  _tid,
228  face_n_points,
229  *elem,
230  side);
231 
232  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
234  _tid,
235  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
236  face_n_points,
237  *elem,
238  side);
239 
240  // Boundary Materials
243  _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
244 
247  _tid, _materials.getActiveBoundaryObjects(bnd_id, _tid), face_n_points, *elem, side);
248  }
249 
250  const Elem * neighbor = elem->neighbor_ptr(side);
251  unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[_tid][0]->elem());
252 
253  // Do we have neighbor stateful properties or do we have stateful interface material properties?
254  // If either then we need to reinit the neighbor, so at least at a minimum _neighbor_elem isn't
255  // NULL!
256  if (neighbor->active() &&
259  _fe_problem.reinitNeighbor(elem, side, _tid);
260 
261  if (_has_neighbor_stateful_props && neighbor->active())
262  {
263  // Neighbor Materials
264  if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(
265  neighbor->subdomain_id(), _tid))
267  _tid,
268  _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
269  neighbor->subdomain_id(), _tid),
270  face_n_points,
271  *elem,
272  side);
273 
274  if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(neighbor->subdomain_id(),
275  _tid))
277  _tid,
278  _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(neighbor->subdomain_id(),
279  _tid),
280  face_n_points,
281  *neighbor,
282  neighbor_side);
283  }
284 
285  // Interface Materials. Make sure we do these after neighbors
288  _tid,
290  face_n_points,
291  *elem,
292  side);
293 }
294 
295 void
297 {
298 }
299 
300 void
302 {
304 }
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
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
bool needSubdomainMaterialOnSide(SubdomainID subdomain_id, const THREAD_ID tid)
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 reinitElemFace(const Elem *elem, unsigned int side, BoundaryID bnd_id, const THREAD_ID tid) override
boundary_id_type BoundaryID
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 prepare(const Elem *elem, const THREAD_ID tid) override
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)
MaterialData & getMaterialData(const THREAD_ID tid)
bool needInterfaceMaterialOnSide(BoundaryID bnd_id, 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
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