https://mooseframework.inl.gov
MaterialBase.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
11 #include "MaterialBase.h"
13 #include "FEProblemBase.h"
14 #include "Assembly.h"
15 #include "Executioner.h"
16 #include "Transient.h"
17 
18 #include "libmesh/quadrature.h"
19 
22 {
23 
28  params += RandomInterface::validParams();
31 
32  params.addParam<bool>("use_displaced_mesh",
33  false,
34  "Whether or not this object should use the "
35  "displaced mesh for computation. Note that "
36  "in the case this is true but no "
37  "displacements are provided in the Mesh block "
38  "the undisplaced mesh will still be used.");
39  params.addParam<bool>("compute",
40  true,
41  "When false, MOOSE will not call compute methods on this material. "
42  "The user must call computeProperties() after retrieving the MaterialBase "
43  "via MaterialBasePropertyInterface::getMaterialBase(). "
44  "Non-computed MaterialBases are not sorted for dependencies.");
45 
46  params.addPrivateParam<bool>("_neighbor", false);
47  params.addPrivateParam<bool>("_interface", false);
48 
49  // Forces the calling of initStatefulProperties() even when this material
50  // does not declare any properties that are stateful. Right now,
51  // this is only used for porous_flow... pretty please keep it that way?
52  params.addPrivateParam<bool>("_force_stateful_init", false);
53 
54  // Outputs
55  params += OutputInterface::validParams();
56  params.set<std::vector<OutputName>>("outputs") = {"none"};
57  params.addParam<std::vector<std::string>>(
58  "output_properties",
59  {},
60  "List of material properties, from this material, to output (outputs "
61  "must also be defined to an output type)");
62  params.addParam<MaterialPropertyName>(
63  "declare_suffix",
64  "",
65  "An optional suffix parameter that can be appended to any declared properties. The suffix "
66  "will be prepended with a '_' character.");
67 
68  // Allow Material objects to be enabled/disabled by Control objects
69  params.declareControllable("enable");
70 
71  params.addParamNamesToGroup("outputs output_properties", "Outputs");
72  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
73  params.registerBase("MaterialBase");
74  return params;
75 }
76 
78  : MooseObject(parameters),
79  BlockRestrictable(this),
80  BoundaryRestrictable(this, blockIDs(), false), // false for being _not_ nodal
81  SetupInterface(this),
83  ScalarCoupleable(this),
84  FunctionInterface(this),
86  UserObjectInterface(this),
87  TransientInterface(this),
91  Restartable(this, "MaterialBases"),
92  MeshChangedInterface(parameters),
93  // The false flag disables the automatic call buildOutputVariableHideList;
94  // for MaterialBase objects the hide lists are handled by MaterialBaseOutputAction
95  OutputInterface(parameters, false),
96  RandomInterface(parameters,
97  *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
98  parameters.get<THREAD_ID>("_tid"),
99  false),
100  ElementIDInterface(this),
102  ADFunctorInterface(this),
103  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
104  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
105  _tid(parameters.get<THREAD_ID>("_tid")),
106  _assembly(_subproblem.assembly(_tid, 0)),
107  _qp(std::numeric_limits<unsigned int>::max()),
108  _coord(_assembly.coordTransformation()),
109  _normals(_assembly.normals()),
110  _mesh(_subproblem.mesh()),
111  _coord_sys(_assembly.coordSystem()),
112  _compute(getParam<bool>("compute")),
113  _has_stateful_property(false),
114  _declare_suffix(getParam<MaterialPropertyName>("declare_suffix")),
115  _force_stateful_init(getParam<bool>("_force_stateful_init"))
116 {
117 }
118 
119 #ifdef MOOSE_KOKKOS_ENABLED
121  : MooseObject(object, key),
122  BlockRestrictable(object, key),
123  BoundaryRestrictable(object, key),
124  SetupInterface(object, key),
126  ScalarCoupleable(object, key),
127  FunctionInterface(object, key),
128  DistributionInterface(object, key),
129  UserObjectInterface(object, key),
130  TransientInterface(object, key),
131  PostprocessorInterface(object, key),
132  VectorPostprocessorInterface(object, key),
133  DependencyResolverInterface(object, key),
134  Restartable(object, key),
135  MeshChangedInterface(object, key),
136  OutputInterface(object, key),
137  RandomInterface(object, key),
138  ElementIDInterface(object, key),
139  GeometricSearchInterface(object, key),
140  ADFunctorInterface(object, key),
141  _subproblem(object._subproblem),
142  _fe_problem(object._fe_problem),
143  _tid(object._tid),
144  _assembly(object._assembly),
145  _coord(object._coord),
146  _normals(object._normals),
147  _mesh(object._mesh),
148  _coord_sys(object._coord_sys),
149  _compute(object._compute),
150  _has_stateful_property(object._has_stateful_property),
151  _declare_suffix(object._declare_suffix),
152  _force_stateful_init(object._force_stateful_init)
153 {
154 }
155 #endif
156 
157 void
158 MaterialBase::initStatefulProperties(const unsigned int n_points)
159 {
160  for (_qp = 0; _qp < n_points; ++_qp)
162 
163  // checking for statefulness of properties via this loop is necessary
164  // because owned props might have been promoted to stateful by calls to
165  // getMaterialProperty[Old/Older] from other objects. In these cases, this
166  // object won't otherwise know that it owns stateful properties.
167  for (const auto id : _supplied_prop_ids)
168  if (materialData().getMaterialPropertyStorage().getPropRecord(id).stateful() &&
170  mooseWarning(std::string("Material \"") + name() +
171  "\" provides one or more stateful "
172  "properties but initQpStatefulProperties() "
173  "was not overridden in the derived class.");
174 }
175 
176 void
178 {
180 }
181 
182 void
184 {
185  for (const auto & [id, min_state] : _props_to_min_states)
186  if (min_state > 0)
187  mooseError("The stateful property '",
189  "' is undefined");
190 }
191 
192 bool
194 {
195  for (auto & prop : _supplied_props)
196  if (materialData().getMaterialPropertyStorage().isRestoredProperty(prop))
197  return true;
198 
199  return false;
200 }
201 
202 void
203 MaterialBase::registerPropName(const std::string & prop_name, bool is_get, const unsigned int state)
204 {
205  if (!is_get)
206  {
207  const auto property_id = materialData().getPropertyId(prop_name);
208 
209  _supplied_props.insert(prop_name);
210  _supplied_prop_ids.insert(property_id);
211 
212  // Store the minimum state declared
213  auto find_min_state = _props_to_min_states.find(property_id);
214  if (find_min_state == _props_to_min_states.end())
215  _props_to_min_states.emplace(property_id, state);
216  else
217  find_min_state->second = std::min(find_min_state->second, state);
218 
219  // Store material properties for block ids
220  for (const auto & block_id : blockIDs())
221  _fe_problem.storeSubdomainMatPropName(block_id, prop_name);
222 
223  // Store material properties for the boundary ids
224  for (const auto & boundary_id : boundaryIDs())
225  _fe_problem.storeBoundaryMatPropName(boundary_id, prop_name);
226  }
227 
228  if (state > 0)
229  _has_stateful_property = true;
230 }
231 
232 void
233 MaterialBase::setActiveProperties(const std::unordered_set<unsigned int> & needed_props)
234 {
235  _active_prop_ids.clear();
236  for (const auto supplied_id : _supplied_prop_ids)
237  if (needed_props.count(supplied_id))
238  _active_prop_ids.insert(supplied_id);
239 }
240 
241 std::set<OutputName>
243 {
244  const std::vector<OutputName> & out = getParam<std::vector<OutputName>>("outputs");
245  return std::set<OutputName>(out.begin(), out.end());
246 }
247 
248 void
250 {
251  mooseError("MaterialBase::subdomainSetup in Material'", name(), "' needs to be implemented");
252 }
253 
254 void
256 {
257  mooseError("MaterialBase::computeProperties in Material '", name(), "' needs to be implemented");
258 }
259 
260 void
262 {
263 }
264 
265 void
267 {
268  for (_qp = 0; _qp < qRule().n_points(); ++_qp)
270 }
271 
272 void
274 {
275  if (!_compute)
276  mooseDoOnce(mooseWarning("You disabled the computation of this (",
277  name(),
278  ") material by MOOSE, but have not overridden the 'resetQpProperties' "
279  "method, this can lead to unintended values being set for material "
280  "property values."));
281 }
282 
283 void
285 {
286  _qp = qp;
288 }
289 
290 void
292 {
294  mooseError("Material properties must be retrieved during material object construction to "
295  "ensure correct dependency resolution.");
296 }
297 
298 void
299 MaterialBase::markMatPropRequested(const std::string & name)
300 {
302 }
303 
304 void
305 MaterialBase::storeSubdomainZeroMatProp(SubdomainID block_id, const MaterialPropertyName & name)
306 {
308 }
309 
310 void
311 MaterialBase::storeBoundaryZeroMatProp(BoundaryID boundary_id, const MaterialPropertyName & name)
312 {
314 }
315 
316 unsigned int
318 {
319  return _fe_problem.getMaxQps();
320 }
virtual void initStatefulProperties(const unsigned int n_points)
Initialize stateful properties (if material has some)
Definition: MaterialBase.C:158
Interface for objects that need parallel consistent random numbers without patterns over the course o...
FEProblemBase & _fe_problem
Definition: MaterialBase.h:328
A class for creating restricted objects.
Definition: Restartable.h:28
virtual void computeQpProperties()
Users must override this method.
Definition: MaterialBase.C:261
MaterialBase(const InputParameters &parameters)
Definition: MaterialBase.C:77
virtual void storeSubdomainZeroMatProp(SubdomainID block_id, const MaterialPropertyName &name)
Adds to a map based on block ids of material properties for which a zero value can be returned...
Definition: SubProblem.C:596
static InputParameters validParams()
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
static InputParameters validParams()
Definition: MaterialBase.C:21
bool _has_stateful_property
Definition: MaterialBase.h:383
virtual void resetProperties()
Resets the properties at each quadrature point (see resetQpProperties), only called if &#39;compute = fal...
Definition: MaterialBase.C:266
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1135
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
Definition: MaterialData.C:80
virtual void storeBoundaryZeroMatProp(BoundaryID boundary_id, const MaterialPropertyName &name)
Adds to a map based on boundary ids of material properties for which a zero value can be returned...
Definition: SubProblem.C:602
static InputParameters validParams()
A class to provide an common interface to objects requiring "outputs" option.
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
std::set< OutputName > getOutputs()
Get the list of output objects that this class is restricted.
Definition: MaterialBase.C:242
virtual void initQpStatefulProperties()
Initialize stateful properties at quadrature points.
Definition: MaterialBase.C:177
virtual void subdomainSetup() override
Subdomain setup evaluating material properties when required.
Definition: MaterialBase.C:249
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted, this function returns all mesh subdomain ids.
static InputParameters validParams()
virtual const QBase & qRule() const =0
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void markMatPropRequested(const std::string &)
Helper method for adding a material property name to the _material_property_requested set...
Definition: SubProblem.C:725
virtual void computeProperties()=0
Performs the quadrature point loop, calling computeQpProperties.
Definition: MaterialBase.C:255
auto max(const L &left, const R &right)
void checkStatefulSanity() const
Definition: MaterialBase.C:183
static InputParameters validParams()
An interface for accessing Moose::Functors for systems that care about automatic differentiation, e.g.
std::unordered_map< unsigned int, unsigned int > _props_to_min_states
The minimum states requested (0 = current, 1 = old, 2 = older) This is sparse and is used to keep tra...
Definition: MaterialBase.h:373
virtual void resetQpProperties()
Resets the properties prior to calculation of traditional materials (only if &#39;compute = false&#39;)...
Definition: MaterialBase.C:273
void storeBoundaryZeroMatProp(BoundaryID boundary_id, const MaterialPropertyName &name)
Adds to a map based on boundary ids of material properties for which a zero value can be returned...
Definition: MaterialBase.C:311
unsigned int _qp
Definition: MaterialBase.h:332
Interface for objects that needs transient capabilities.
void mooseWarning(Args &&... args) const
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
unsigned int getMaxQps() const
Definition: MaterialBase.C:317
Interface for notifications that the mesh has changed.
const bool _compute
If False MOOSE does not compute this property.
Definition: MaterialBase.h:362
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
void checkExecutionStage()
Check and throw an error if the execution has progressed past the construction stage.
Definition: MaterialBase.C:291
boundary_id_type BoundaryID
static InputParameters validParams()
Interface for objects that need to use distributions.
virtual void storeBoundaryMatPropName(BoundaryID boundary_id, const std::string &name)
Adds the given material property to a storage map based on boundary ids.
Definition: SubProblem.C:590
std::unordered_set< unsigned int > _active_prop_ids
The ids of the current active supplied properties.
Definition: MaterialBase.h:359
std::set< unsigned int > _supplied_prop_ids
The ids of the supplied properties, i.e.
Definition: MaterialBase.h:356
Interface for objects that need to use UserObjects.
static InputParameters validParams()
bool _overrides_init_stateful_props
Definition: MaterialBase.h:385
void setActiveProperties(const std::unordered_set< unsigned int > &needed_props)
Set active properties of this material Note: This function is called by FEProblemBase::setActiveMater...
Definition: MaterialBase.C:233
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
void markMatPropRequested(const std::string &name)
Helper method for adding a material property name to the material property requested set...
Definition: MaterialBase.C:299
const std::string & getName(const unsigned int id) const
OStreamProxy out
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271
Interface for sorting dependent vectors of objects.
Interface for objects that needs scalar coupling capabilities.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
void registerPropName(const std::string &prop_name, bool is_get, const unsigned int state)
Small helper function to call store{Subdomain,Boundary}MatPropName.
Definition: MaterialBase.C:203
virtual void computePropertiesAtQp(unsigned int qp)
A method for (re)computing the properties of a MaterialBase.
Definition: MaterialBase.C:284
std::set< std::string > _supplied_props
Set of properties declared.
Definition: MaterialBase.h:347
static InputParameters validParams()
Definition: MooseObject.C:25
const MaterialPropertyRegistry & getMaterialPropertyRegistry() const
static InputParameters validParams()
auto min(const L &left, const R &right)
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
virtual const MaterialData & materialData() const =0
void storeSubdomainZeroMatProp(SubdomainID block_id, const MaterialPropertyName &name)
Adds to a map based on block ids of material properties for which a zero value can be returned...
Definition: MaterialBase.C:305
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:62
Interface for objects that need to use functions.
void ErrorVector unsigned int
virtual void storeSubdomainMatPropName(SubdomainID block_id, const std::string &name)
Adds the given material property to a storage map based on block ids.
Definition: SubProblem.C:584
Interface class for classes which interact with Postprocessors.
unsigned int THREAD_ID
Definition: MooseTypes.h:209
virtual bool startedInitialSetup()
Returns true if we are in or beyond the initialSetup stage.
unsigned int getMaxQps() const
bool hasRestoredProperties() const
Definition: MaterialBase.C:193