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  std::vector<std::shared_ptr<MaterialData>> & material_data,
27  std::vector<std::shared_ptr<MaterialData>> & bnd_material_data,
28  std::vector<std::shared_ptr<MaterialData>> & neighbor_material_data,
29  MaterialPropertyStorage & material_props,
30  MaterialPropertyStorage & bnd_material_props,
31  MaterialPropertyStorage & neighbor_material_props,
32  std::vector<std::unique_ptr<Assembly>> & assembly)
33  : ThreadedElementLoop<ConstElemRange>(fe_problem),
34  _fe_problem(fe_problem),
35  _nl(fe_problem.getNonlinearSystemBase()),
36  _material_data(material_data),
37  _bnd_material_data(bnd_material_data),
38  _neighbor_material_data(neighbor_material_data),
39  _material_props(material_props),
40  _bnd_material_props(bnd_material_props),
41  _neighbor_material_props(neighbor_material_props),
42  _materials(_fe_problem.getResidualMaterialsWarehouse()),
43  _discrete_materials(_fe_problem.getDiscreteMaterialWarehouse()),
44  _assembly(assembly),
45  _need_internal_side_material(false),
46  _has_stateful_props(_material_props.hasStatefulProperties()),
47  _has_bnd_stateful_props(_bnd_material_props.hasStatefulProperties()),
48  _has_neighbor_stateful_props(_neighbor_material_props.hasStatefulProperties())
49 {
50 }
51 
52 // Splitting Constructor
55  : ThreadedElementLoop<ConstElemRange>(x, split),
56  _fe_problem(x._fe_problem),
57  _nl(x._nl),
58  _material_data(x._material_data),
59  _bnd_material_data(x._bnd_material_data),
60  _neighbor_material_data(x._neighbor_material_data),
61  _material_props(x._material_props),
62  _bnd_material_props(x._bnd_material_props),
63  _neighbor_material_props(x._neighbor_material_props),
64  _materials(x._materials),
65  _discrete_materials(x._discrete_materials),
66  _assembly(x._assembly),
67  _need_internal_side_material(x._need_internal_side_material),
68  _has_stateful_props(_material_props.hasStatefulProperties()),
69  _has_bnd_stateful_props(_bnd_material_props.hasStatefulProperties()),
70  _has_neighbor_stateful_props(_neighbor_material_props.hasStatefulProperties())
71 {
72 }
73 
74 void
76 {
79 
80  std::set<MooseVariableFEBase *> needed_moose_vars;
81  _materials.updateVariableDependency(needed_moose_vars, _tid);
83 }
84 
85 void
87 {
90  {
91  _fe_problem.prepare(elem, _tid);
93 
94  unsigned int n_points = _assembly[_tid]->qRule()->n_points();
95  _material_data[_tid]->resize(n_points);
96 
98  {
103  n_points,
104  *elem);
108  n_points,
109  *elem);
110  }
111  }
112 }
113 
114 void
115 ComputeMaterialsObjectThread::onBoundary(const Elem * elem, unsigned int side, BoundaryID bnd_id)
116 {
118  {
119  _assembly[_tid]->reinit(elem, side);
120  unsigned int face_n_points = _assembly[_tid]->qRuleFace()->n_points();
121 
122  _bnd_material_data[_tid]->resize(face_n_points);
123 
125  {
126  // Face Materials
127  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
131  face_n_points,
132  *elem,
133  side);
134  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
137  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
138  face_n_points,
139  *elem,
140  side);
141 
142  // Boundary Materials
146  face_n_points,
147  *elem,
148  side);
152  face_n_points,
153  *elem,
154  side);
155  }
156  }
157 }
158 
159 void
160 ComputeMaterialsObjectThread::onInternalSide(const Elem * elem, unsigned int side)
161 {
163  {
164  _assembly[_tid]->reinit(elem, side);
165  unsigned int face_n_points = _assembly[_tid]->qRuleFace()->n_points();
166  _bnd_material_data[_tid]->resize(face_n_points);
167  _neighbor_material_data[_tid]->resize(face_n_points);
168 
170  {
171  if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
175  face_n_points,
176  *elem,
177  side);
178  if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(_subdomain, _tid))
181  _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(_subdomain, _tid),
182  face_n_points,
183  *elem,
184  side);
185  }
186 
187  const Elem * neighbor = elem->neighbor_ptr(side);
188  unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[_tid]->elem());
189  const dof_id_type elem_id = elem->id(), neighbor_id = neighbor->id();
190 
192  ((neighbor->active() && (neighbor->level() == elem->level()) && (elem_id < neighbor_id)) ||
193  (neighbor->level() < elem->level())))
194  {
195  _assembly[_tid]->reinitElemAndNeighbor(elem, side, neighbor, neighbor_side);
196 
197  // Neighbor Materials
198  if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(
199  neighbor->subdomain_id(), _tid))
202  _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
203  neighbor->subdomain_id(), _tid),
204  face_n_points,
205  *elem,
206  side);
207  if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(neighbor->subdomain_id(),
208  _tid))
211  _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(
212  neighbor->subdomain_id(), _tid),
213  face_n_points,
214  *neighbor,
215  neighbor_side);
216  }
217  }
218 }
219 
220 void
222 {
223 }
224 
225 void
227 {
229 }
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
bool hasActiveBlockObjects(THREAD_ID tid=0) const
void join(const ComputeMaterialsObjectThread &)
virtual void setActiveElementalMooseVariables(const std::set< MooseVariableFEBase *> &moose_vars, THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
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.
MaterialPropertyStorage & _material_props
Stores the stateful material properties computed by materials.
bool needSubdomainMaterialOnSide(SubdomainID subdomain_id, THREAD_ID tid)
virtual void onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id) override
Called when doing boundary assembling.
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)
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
std::vector< std::string > split(const std::string &str, const std::string &delimiter)
Python like split function for strings.
Definition: MooseUtils.C:736
std::vector< std::shared_ptr< MaterialData > > & _bnd_material_data
const MaterialWarehouse & _materials
This is populated using _fe_problem.getResidualMaterialsWarehouse because it has the union of traditi...
boundary_id_type BoundaryID
void updateVariableDependency(std::set< MooseVariableFEBase *> &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
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
virtual void onElement(const Elem *elem) override
Assembly of the element (not including surface assembly)
std::vector< std::unique_ptr< Assembly > > & _assembly
SubdomainID _subdomain
The subdomain for the current element.
virtual void post() override
Called after the element range loop.
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, MaterialPropertyStorage &neighbor_material_props, std::vector< std::unique_ptr< Assembly >> &assembly)
MaterialPropertyStorage & _bnd_material_props
virtual void clearActiveElementalMooseVariables(THREAD_ID tid) override
Clear the active elemental MooseVariableFEBase.
const MaterialWarehouse & _discrete_materials
bool needBoundaryMaterialOnSide(BoundaryID bnd_id, THREAD_ID tid)
These methods are used to determine whether stateful material properties need to be stored on interna...