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),
104  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
105  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
106  _tid(parameters.get<THREAD_ID>("_tid")),
107  _assembly(_subproblem.assembly(_tid, 0)),
108  _qp(std::numeric_limits<unsigned int>::max()),
109  _coord(_assembly.coordTransformation()),
110  _normals(_assembly.normals()),
111  _mesh(_subproblem.mesh()),
112  _coord_sys(_assembly.coordSystem()),
113  _compute(getParam<bool>("compute")),
114  _has_stateful_property(false),
115  _declare_suffix(getParam<MaterialPropertyName>("declare_suffix")),
116  _force_stateful_init(getParam<bool>("_force_stateful_init"))
117 {
118 }
119 
120 #ifdef MOOSE_KOKKOS_ENABLED
122  : MooseObject(object, key),
123  BlockRestrictable(object, key),
124  BoundaryRestrictable(object, key),
125  SetupInterface(object, key),
127  ScalarCoupleable(object, key),
128  FunctionInterface(object, key),
129  DistributionInterface(object, key),
130  UserObjectInterface(object, key),
131  TransientInterface(object, key),
132  PostprocessorInterface(object, key),
133  VectorPostprocessorInterface(object, key),
134  DependencyResolverInterface(object, key),
135  Restartable(object, key),
136  MeshChangedInterface(object, key),
137  OutputInterface(object, key),
138  RandomInterface(object, key),
139  ElementIDInterface(object, key),
140  GeometricSearchInterface(object, key),
141  ADFunctorInterface(object, key),
142  SolutionInvalidInterface(object, key),
143  _subproblem(object._subproblem),
144  _fe_problem(object._fe_problem),
145  _tid(object._tid),
146  _assembly(object._assembly),
147  _coord(object._coord),
148  _normals(object._normals),
149  _mesh(object._mesh),
150  _coord_sys(object._coord_sys),
151  _compute(object._compute),
152  _has_stateful_property(object._has_stateful_property),
153  _declare_suffix(object._declare_suffix),
154  _force_stateful_init(object._force_stateful_init)
155 {
156 }
157 #endif
158 
159 void
160 MaterialBase::initStatefulProperties(const unsigned int n_points)
161 {
162  for (_qp = 0; _qp < n_points; ++_qp)
164 
165  // checking for statefulness of properties via this loop is necessary
166  // because owned props might have been promoted to stateful by calls to
167  // getMaterialProperty[Old/Older] from other objects. In these cases, this
168  // object won't otherwise know that it owns stateful properties.
169  for (const auto id : _supplied_prop_ids)
170  if (materialData().getMaterialPropertyStorage().getPropRecord(id).stateful() &&
172  mooseWarning(std::string("Material \"") + name() +
173  "\" provides one or more stateful "
174  "properties but initQpStatefulProperties() "
175  "was not overridden in the derived class.");
176 }
177 
178 void
180 {
182 }
183 
184 void
186 {
187  for (const auto & [id, min_state] : _props_to_min_states)
188  if (min_state > 0)
189  mooseError("The stateful property '",
191  "' is undefined");
192 }
193 
194 bool
196 {
197  for (auto & prop : _supplied_props)
198  if (materialData().getMaterialPropertyStorage().isRestoredProperty(prop))
199  return true;
200 
201  return false;
202 }
203 
204 void
205 MaterialBase::registerPropName(const std::string & prop_name, bool is_get, const unsigned int state)
206 {
207  if (!is_get)
208  {
209  const auto property_id = materialData().getPropertyId(prop_name);
210 
211  _supplied_props.insert(prop_name);
212  _supplied_prop_ids.insert(property_id);
213 
214  // Store the minimum state declared
215  auto find_min_state = _props_to_min_states.find(property_id);
216  if (find_min_state == _props_to_min_states.end())
217  _props_to_min_states.emplace(property_id, state);
218  else
219  find_min_state->second = std::min(find_min_state->second, state);
220 
221  // Store material properties for block ids
222  for (const auto & block_id : blockIDs())
223  _fe_problem.storeSubdomainMatPropName(block_id, prop_name);
224 
225  // Store material properties for the boundary ids
226  for (const auto & boundary_id : boundaryIDs())
227  _fe_problem.storeBoundaryMatPropName(boundary_id, prop_name);
228  }
229 
230  if (state > 0)
231  _has_stateful_property = true;
232 }
233 
234 void
235 MaterialBase::setActiveProperties(const std::unordered_set<unsigned int> & needed_props)
236 {
237  _active_prop_ids.clear();
238  for (const auto supplied_id : _supplied_prop_ids)
239  if (needed_props.count(supplied_id))
240  _active_prop_ids.insert(supplied_id);
241 }
242 
243 std::set<OutputName>
245 {
246  const std::vector<OutputName> & out = getParam<std::vector<OutputName>>("outputs");
247  return std::set<OutputName>(out.begin(), out.end());
248 }
249 
250 void
252 {
253  mooseError("MaterialBase::subdomainSetup in Material'", name(), "' needs to be implemented");
254 }
255 
256 void
258 {
259  mooseError("MaterialBase::computeProperties in Material '", name(), "' needs to be implemented");
260 }
261 
262 void
264 {
265 }
266 
267 void
269 {
270  for (_qp = 0; _qp < qRule().n_points(); ++_qp)
272 }
273 
274 void
276 {
277  if (!_compute)
278  mooseDoOnce(mooseWarning("You disabled the computation of this (",
279  name(),
280  ") material by MOOSE, but have not overridden the 'resetQpProperties' "
281  "method, this can lead to unintended values being set for material "
282  "property values."));
283 }
284 
285 void
287 {
288  _qp = qp;
290 }
291 
292 void
294 {
296  mooseError("Material properties must be retrieved during material object construction to "
297  "ensure correct dependency resolution.");
298 }
299 
300 void
301 MaterialBase::markMatPropRequested(const std::string & name)
302 {
304 }
305 
306 void
307 MaterialBase::storeSubdomainZeroMatProp(SubdomainID block_id, const MaterialPropertyName & name)
308 {
310 }
311 
312 void
313 MaterialBase::storeBoundaryZeroMatProp(BoundaryID boundary_id, const MaterialPropertyName & name)
314 {
316 }
317 
318 unsigned int
320 {
321  return _fe_problem.getMaxQps();
322 }
virtual void initStatefulProperties(const unsigned int n_points)
Initialize stateful properties (if material has some)
Definition: MaterialBase.C:160
Interface for objects that need parallel consistent random numbers without patterns over the course o...
FEProblemBase & _fe_problem
Definition: MaterialBase.h:329
A class for creating restricted objects.
Definition: Restartable.h:28
virtual void computeQpProperties()
Users must override this method.
Definition: MaterialBase.C:263
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:595
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:384
virtual void resetProperties()
Resets the properties at each quadrature point (see resetQpProperties), only called if &#39;compute = fal...
Definition: MaterialBase.C:268
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:1133
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:601
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:244
virtual void initQpStatefulProperties()
Initialize stateful properties at quadrature points.
Definition: MaterialBase.C:179
virtual void subdomainSetup() override
Subdomain setup evaluating material properties when required.
Definition: MaterialBase.C:251
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:724
virtual void computeProperties()=0
Performs the quadrature point loop, calling computeQpProperties.
Definition: MaterialBase.C:257
auto max(const L &left, const R &right)
void checkStatefulSanity() const
Definition: MaterialBase.C:185
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:374
virtual void resetQpProperties()
Resets the properties prior to calculation of traditional materials (only if &#39;compute = false&#39;)...
Definition: MaterialBase.C:275
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:313
unsigned int _qp
Definition: MaterialBase.h:333
An interface that allows the marking of invalid solutions during a solve.
Interface for objects that needs transient capabilities.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
unsigned int getMaxQps() const
Definition: MaterialBase.C:319
Interface for notifications that the mesh has changed.
const bool _compute
If False MOOSE does not compute this property.
Definition: MaterialBase.h:363
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:27
void checkExecutionStage()
Check and throw an error if the execution has progressed past the construction stage.
Definition: MaterialBase.C:293
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:589
std::unordered_set< unsigned int > _active_prop_ids
The ids of the current active supplied properties.
Definition: MaterialBase.h:360
std::set< unsigned int > _supplied_prop_ids
The ids of the supplied properties, i.e.
Definition: MaterialBase.h:357
Interface for objects that need to use UserObjects.
static InputParameters validParams()
bool _overrides_init_stateful_props
Definition: MaterialBase.h:386
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:235
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:301
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 mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
Definition: MooseBase.h:299
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:205
virtual void computePropertiesAtQp(unsigned int qp)
A method for (re)computing the properties of a MaterialBase.
Definition: MaterialBase.C:286
std::set< std::string > _supplied_props
Set of properties declared.
Definition: MaterialBase.h:348
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:307
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:583
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:195