https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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
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),
80 BoundaryRestrictable(this, blockIDs(), false), // false for being _not_ nodal
81 SetupInterface(this),
83 ScalarCoupleable(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
157void
158MaterialBase::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)
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
176void
181
182void
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
192bool
194{
195 for (auto & prop : _supplied_props)
197 return true;
198
199 return false;
200}
201
202void
203MaterialBase::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)
230}
231
232void
233MaterialBase::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
241std::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
248void
250{
251 mooseError("MaterialBase::subdomainSetup in Material'", name(), "' needs to be implemented");
252}
253
254void
256{
257 mooseError("MaterialBase::computeProperties in Material '", name(), "' needs to be implemented");
258}
259
260void
264
265void
267{
268 for (_qp = 0; _qp < qRule().n_points(); ++_qp)
270}
271
272void
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
283void
285{
286 _qp = qp;
288}
289
290void
292{
294 mooseError("Material properties must be retrieved during material object construction to "
295 "ensure correct dependency resolution.");
296}
297
298void
303
304void
305MaterialBase::storeSubdomainZeroMatProp(SubdomainID block_id, const MaterialPropertyName & name)
306{
308}
309
310void
311MaterialBase::storeBoundaryZeroMatProp(BoundaryID boundary_id, const MaterialPropertyName & name)
312{
314}
315
316unsigned int
318{
319 return _fe_problem.getMaxQps();
320}
boundary_id_type BoundaryID
unsigned int THREAD_ID
Definition MooseTypes.h:237
void ErrorVector unsigned int
An interface for accessing Moose::Functors for systems that care about automatic differentiation,...
static InputParameters validParams()
An interface that restricts an object to subdomains via the 'blocks' input parameter.
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted,...
static InputParameters validParams()
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
static InputParameters validParams()
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
Interface for sorting dependent vectors of objects.
Interface for objects that need to use distributions.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
unsigned int getMaxQps() const
const MaterialPropertyRegistry & getMaterialPropertyRegistry() const
virtual bool startedInitialSetup()
Returns true if we are in or beyond the initialSetup stage.
Interface for objects that need to use functions.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
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 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...
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
MaterialBases compute MaterialProperties.
virtual void computeProperties()=0
Performs the quadrature point loop, calling computeQpProperties.
unsigned int getMaxQps() const
virtual void computeQpProperties()
Users must override this method.
MaterialBase(const InputParameters &parameters)
virtual void initStatefulProperties(const unsigned int n_points)
Initialize stateful properties (if material has some)
unsigned int _qp
void markMatPropRequested(const std::string &name)
Helper method for adding a material property name to the material property requested set.
void checkStatefulSanity() const
std::set< unsigned int > _supplied_prop_ids
The ids of the supplied properties, i.e.
void checkExecutionStage()
Check and throw an error if the execution has progressed past the construction stage.
virtual void initQpStatefulProperties()
Initialize stateful properties at quadrature points.
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.
FEProblemBase & _fe_problem
virtual const MaterialData & materialData() const =0
virtual void resetProperties()
Resets the properties at each quadrature point (see resetQpProperties), only called if 'compute = fal...
void setActiveProperties(const std::unordered_set< unsigned int > &needed_props)
Set active properties of this material Note: This function is called by FEProblemBase::setActiveMater...
bool hasRestoredProperties() const
std::set< OutputName > getOutputs()
Get the list of output objects that this class is restricted.
virtual const QBase & qRule() const =0
virtual void computePropertiesAtQp(unsigned int qp)
A method for (re)computing the properties of a MaterialBase.
const bool _compute
If False MOOSE does not compute this property.
void registerPropName(const std::string &prop_name, bool is_get, const unsigned int state)
Small helper function to call store{Subdomain,Boundary}MatPropName.
static InputParameters validParams()
virtual void resetQpProperties()
Resets the properties prior to calculation of traditional materials (only if 'compute = false').
bool _overrides_init_stateful_props
bool _has_stateful_property
std::unordered_set< unsigned int > _active_prop_ids
The ids of the current active supplied properties.
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...
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.
std::set< std::string > _supplied_props
Set of properties declared.
virtual void subdomainSetup() override
Subdomain setup evaluating material properties when required.
const MaterialPropertyStorage & getMaterialPropertyStorage() const
Provide read-only access to the underlying MaterialPropertyStorage object.
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
const std::string & getName(const unsigned int id) const
bool isRestoredProperty(const std::string &name) const
const PropRecord & getPropRecord(const unsigned int id) const
Get the property record associated with the material with id id.
Interface for notifications that the mesh has changed.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
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
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
static InputParameters validParams()
Definition MooseObject.C:25
A class to provide an common interface to objects requiring "outputs" option.
static InputParameters validParams()
Interface class for classes which interact with Postprocessors.
Interface for objects that need parallel consistent random numbers without patterns over the course o...
static InputParameters validParams()
A class for creating restricted objects.
Definition Restartable.h:29
Interface for objects that needs scalar coupling capabilities.
void mooseWarning(Args &&... args) const
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
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
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 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
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
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
Interface for objects that needs transient capabilities.
static InputParameters validParams()
Interface for objects that need to use UserObjects.
MeshBase & mesh
bool stateful() const
Whether or not this property is stateful.