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();
30 
31  params.addParam<bool>("use_displaced_mesh",
32  false,
33  "Whether or not this object should use the "
34  "displaced mesh for computation. Note that "
35  "in the case this is true but no "
36  "displacements are provided in the Mesh block "
37  "the undisplaced mesh will still be used.");
38  params.addParam<bool>("compute",
39  true,
40  "When false, MOOSE will not call compute methods on this material. "
41  "The user must call computeProperties() after retrieving the MaterialBase "
42  "via MaterialBasePropertyInterface::getMaterialBase(). "
43  "Non-computed MaterialBases are not sorted for dependencies.");
44 
45  params.addPrivateParam<bool>("_neighbor", false);
46  params.addPrivateParam<bool>("_interface", false);
47 
48  // Forces the calling of initStatefulProperties() even when this material
49  // does not declare any properties that are stateful. Right now,
50  // this is only used for porous_flow... pretty please keep it that way?
51  params.addPrivateParam<bool>("_force_stateful_init", false);
52 
53  // Outputs
54  params += OutputInterface::validParams();
55  params.set<std::vector<OutputName>>("outputs") = {"none"};
56  params.addParam<std::vector<std::string>>(
57  "output_properties",
58  {},
59  "List of material properties, from this material, to output (outputs "
60  "must also be defined to an output type)");
61  params.addParam<MaterialPropertyName>(
62  "declare_suffix",
63  "",
64  "An optional suffix parameter that can be appended to any declared properties. The suffix "
65  "will be prepended with a '_' character.");
66 
67  // Allow Material objects to be enabled/disabled by Control objects
68  params.declareControllable("enable");
69 
70  params.addParamNamesToGroup("outputs output_properties", "Outputs");
71  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
72  params.registerBase("MaterialBase");
73  return params;
74 }
75 
77  : MooseObject(parameters),
78  BlockRestrictable(this),
79  BoundaryRestrictable(this, blockIDs(), false), // false for being _not_ nodal
80  SetupInterface(this),
82  ScalarCoupleable(this),
83  FunctionInterface(this),
85  UserObjectInterface(this),
86  TransientInterface(this),
90  Restartable(this, "MaterialBases"),
91  MeshChangedInterface(parameters),
92  // The false flag disables the automatic call buildOutputVariableHideList;
93  // for MaterialBase objects the hide lists are handled by MaterialBaseOutputAction
94  OutputInterface(parameters, false),
95  RandomInterface(parameters,
96  *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
97  parameters.get<THREAD_ID>("_tid"),
98  false),
99  ElementIDInterface(this),
101  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 void
121 {
122  for (_qp = 0; _qp < n_points; ++_qp)
124 
125  // checking for statefulness of properties via this loop is necessary
126  // because owned props might have been promoted to stateful by calls to
127  // getMaterialProperty[Old/Older] from other objects. In these cases, this
128  // object won't otherwise know that it owns stateful properties.
129  for (const auto id : _supplied_prop_ids)
130  if (materialData().getMaterialPropertyStorage().getPropRecord(id).stateful() &&
132  mooseWarning(std::string("Material \"") + name() +
133  "\" provides one or more stateful "
134  "properties but initQpStatefulProperties() "
135  "was not overridden in the derived class.");
136 }
137 
138 void
140 {
142 }
143 
144 void
146 {
147  for (const auto & [id, min_state] : _props_to_min_states)
148  if (min_state > 0)
149  mooseError("The stateful property '",
151  "' is undefined");
152 }
153 
154 void
155 MaterialBase::registerPropName(const std::string & prop_name, bool is_get, const unsigned int state)
156 {
157  if (!is_get)
158  {
159  const auto property_id = materialData().getPropertyId(prop_name);
160 
161  _supplied_props.insert(prop_name);
162  _supplied_prop_ids.insert(property_id);
163 
164  // Store the minimum state declared
165  auto find_min_state = _props_to_min_states.find(property_id);
166  if (find_min_state == _props_to_min_states.end())
167  _props_to_min_states.emplace(property_id, state);
168  else
169  find_min_state->second = std::min(find_min_state->second, state);
170 
171  // Store material properties for block ids
172  for (const auto & block_id : blockIDs())
173  _fe_problem.storeSubdomainMatPropName(block_id, prop_name);
174 
175  // Store material properties for the boundary ids
176  for (const auto & boundary_id : boundaryIDs())
177  _fe_problem.storeBoundaryMatPropName(boundary_id, prop_name);
178  }
179 
180  if (state > 0)
181  _has_stateful_property = true;
182 }
183 
184 void
185 MaterialBase::setActiveProperties(const std::unordered_set<unsigned int> & needed_props)
186 {
187  _active_prop_ids.clear();
188  for (const auto supplied_id : _supplied_prop_ids)
189  if (needed_props.count(supplied_id))
190  _active_prop_ids.insert(supplied_id);
191 }
192 
193 std::set<OutputName>
195 {
196  const std::vector<OutputName> & out = getParam<std::vector<OutputName>>("outputs");
197  return std::set<OutputName>(out.begin(), out.end());
198 }
199 
200 void
202 {
203  mooseError("MaterialBase::subdomainSetup in Material'", name(), "' needs to be implemented");
204 }
205 
206 void
208 {
209  mooseError("MaterialBase::computeProperties in Material '", name(), "' needs to be implemented");
210 }
211 
212 void
214 {
215 }
216 
217 void
219 {
220  for (_qp = 0; _qp < qRule().n_points(); ++_qp)
222 }
223 
224 void
226 {
227  if (!_compute)
228  mooseDoOnce(mooseWarning("You disabled the computation of this (",
229  name(),
230  ") material by MOOSE, but have not overridden the 'resetQpProperties' "
231  "method, this can lead to unintended values being set for material "
232  "property values."));
233 }
234 
235 void
237 {
238  _qp = qp;
240 }
241 
242 void
244 {
246  mooseError("Material properties must be retrieved during material object construction to "
247  "ensure correct dependency resolution.");
248 }
249 
250 void
251 MaterialBase::markMatPropRequested(const std::string & name)
252 {
254 }
255 
256 void
257 MaterialBase::storeSubdomainZeroMatProp(SubdomainID block_id, const MaterialPropertyName & name)
258 {
260 }
261 
262 void
263 MaterialBase::storeBoundaryZeroMatProp(BoundaryID boundary_id, const MaterialPropertyName & name)
264 {
266 }
267 
268 unsigned int
270 {
271  return _fe_problem.getMaxQps();
272 }
Interface for objects that need parallel consistent random numbers without patterns over the course o...
FEProblemBase & _fe_problem
Definition: MaterialBase.h:316
A class for creating restricted objects.
Definition: Restartable.h:28
virtual void computeQpProperties()
Users must override this method.
Definition: MaterialBase.C:213
MaterialBase(const InputParameters &parameters)
Definition: MaterialBase.C:76
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:371
virtual void resetProperties()
Resets the properties at each quadrature point (see resetQpProperties), only called if &#39;compute = fal...
Definition: MaterialBase.C:218
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:1155
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:194
virtual void initQpStatefulProperties()
Initialize stateful properties at quadrature points.
Definition: MaterialBase.C:139
virtual void subdomainSetup() override
Subdomain setup evaluating material properties when required.
Definition: MaterialBase.C:201
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 const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
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:207
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
auto max(const L &left, const R &right)
void checkStatefulSanity() const
Definition: MaterialBase.C:145
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:361
virtual void resetQpProperties()
Resets the properties prior to calculation of traditional materials (only if &#39;compute = false&#39;)...
Definition: MaterialBase.C:225
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:263
unsigned int _qp
Definition: MaterialBase.h:320
An interface that allows the marking of invalid solutions during a solve.
Interface for objects that needs transient capabilities.
unsigned int getMaxQps() const
Definition: MaterialBase.C:269
Interface for notifications that the mesh has changed.
const bool _compute
If False MOOSE does not compute this property.
Definition: MaterialBase.h:350
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:243
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:347
std::set< unsigned int > _supplied_prop_ids
The ids of the supplied properties, i.e.
Definition: MaterialBase.h:344
Interface for objects that need to use UserObjects.
virtual void initStatefulProperties(unsigned int n_points)
Initialize stateful properties (if material has some)
Definition: MaterialBase.C:120
static InputParameters validParams()
bool _overrides_init_stateful_props
Definition: MaterialBase.h:373
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:185
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:251
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.
Interface for sorting dependent vectors of objects.
Interface for objects that needs scalar coupling capabilities.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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:155
virtual void computePropertiesAtQp(unsigned int qp)
A method for (re)computing the properties of a MaterialBase.
Definition: MaterialBase.C:236
std::set< std::string > _supplied_props
Set of properties declared.
Definition: MaterialBase.h:335
static InputParameters validParams()
Definition: MooseObject.C:25
const MaterialPropertyRegistry & getMaterialPropertyRegistry() const
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:257
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