www.mooseframework.org
MaterialBase.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
11 #include "MaterialBase.h"
12 #include "SubProblem.h"
13 #include "Assembly.h"
14 #include "Executioner.h"
15 #include "Transient.h"
16 
17 #include "libmesh/quadrature.h"
18 
20 
23 {
24 
29  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  // Outputs
49  params += OutputInterface::validParams();
50  params.set<std::vector<OutputName>>("outputs") = {"none"};
51  params.addParam<std::vector<std::string>>(
52  "output_properties",
53  "List of material properties, from this material, to output (outputs "
54  "must also be defined to an output type)");
55 
56  params.addParamNamesToGroup("outputs output_properties", "Outputs");
57  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
58  params.registerBase("MaterialBase");
59  return params;
60 }
61 
63  : MooseObject(parameters),
64  BlockRestrictable(this),
65  BoundaryRestrictable(this, blockIDs(), false), // false for being _not_ nodal
66  SetupInterface(this),
68  ScalarCoupleable(this),
69  FunctionInterface(this),
71  UserObjectInterface(this),
72  TransientInterface(this),
76  Restartable(this, "MaterialBases"),
77  MeshChangedInterface(parameters),
78 
79  // The false flag disables the automatic call buildOutputVariableHideList;
80  // for MaterialBase objects the hide lists are handled by MaterialBaseOutputAction
81  OutputInterface(parameters, false),
82  RandomInterface(parameters,
83  *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
84  parameters.get<THREAD_ID>("_tid"),
85  false),
86  ElementIDInterface(this),
87  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
88  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
89  _tid(parameters.get<THREAD_ID>("_tid")),
90  _assembly(_subproblem.assembly(_tid)),
91  _qp(std::numeric_limits<unsigned int>::max()),
92  _coord(_assembly.coordTransformation()),
93  _normals(_assembly.normals()),
94  _mesh(_subproblem.mesh()),
95  _coord_sys(_assembly.coordSystem()),
96  _compute(getParam<bool>("compute")),
97  _has_stateful_property(false)
98 {
99 }
100 
101 void
103 {
104  for (_qp = 0; _qp < n_points; ++_qp)
106 
107  // checking for statefulness of properties via this loop is necessary
108  // because owned props might have been promoted to stateful by calls to
109  // getMaterialProperty[Old/Older] from other objects. In these cases, this
110  // object won't otherwise know that it owns stateful properties.
111  for (auto & prop : _supplied_props)
112  if (materialData().getMaterialPropertyStorage().isStatefulProp(prop) &&
114  mooseError(std::string("Material \"") + name() +
115  "\" provides one or more stateful "
116  "properties but initQpStatefulProperties() "
117  "was not overridden in the derived class.");
118 }
119 
120 void
122 {
124 }
125 
126 void
128 {
129  for (const auto & it : _props_to_flags)
130  if (static_cast<int>(it.second) % 2 == 0) // Only Stateful properties declared!
131  mooseError("Material '", name(), "' requests undefined stateful property '", it.first, "'");
132 }
133 
134 void
135 MaterialBase::registerPropName(std::string prop_name,
136  bool is_get,
137  Prop_State state,
138  bool is_declared_ad)
139 {
140  if (!is_get)
141  {
142  _supplied_props.insert(prop_name);
143  const auto & property_id = materialData().getPropertyId(prop_name);
144  _supplied_prop_ids.insert(property_id);
145  if (is_declared_ad)
146  _supplied_ad_prop_ids.insert(property_id);
147  else
148  _supplied_regular_prop_ids.insert(property_id);
149 
150  _props_to_flags[prop_name] |= static_cast<int>(state);
151  if (static_cast<int>(state) % 2 == 0)
152  _has_stateful_property = true;
153  }
154 
155  // Store material properties for block ids
156  for (const auto & block_id : blockIDs())
157  _fe_problem.storeSubdomainMatPropName(block_id, prop_name);
158 
159  // Store material properties for the boundary ids
160  for (const auto & boundary_id : boundaryIDs())
161  _fe_problem.storeBoundaryMatPropName(boundary_id, prop_name);
162 }
163 
164 std::set<OutputName>
166 {
167  const std::vector<OutputName> & out = getParam<std::vector<OutputName>>("outputs");
168  return std::set<OutputName>(out.begin(), out.end());
169 }
170 
171 void
173 {
174  mooseError("MaterialBase::computeSubdomainQpProperties in Material '",
175  name(),
176  "' needs to be implemented");
177 }
178 
179 void
181 {
182  mooseError("MaterialBase::subdomainSetup in Material'", name(), "' needs to be implemented");
183 }
184 
185 void
187 {
188  mooseError("MaterialBase::computeProperties in Material '", name(), "' needs to be implemented");
189 }
190 
191 void
193 {
194 }
195 
196 void
198 {
199  for (_qp = 0; _qp < qRule().n_points(); ++_qp)
201 }
202 
203 void
205 {
206  if (!_compute)
207  mooseDoOnce(mooseWarning("You disabled the computation of this (",
208  name(),
209  ") material by MOOSE, but have not overridden the 'resetQpProperties' "
210  "method, this can lead to unintended values being set for material "
211  "property values."));
212 }
213 
214 void
216 {
217  _qp = qp;
219 }
220 
221 void
223 {
225  mooseError("Material properties must be retrieved during material object construction to "
226  "ensure correct dependency resolution.");
227 }
228 
229 void
231 {
233  return;
234 
235  MaterialProperties & props = materialData().props();
236  for (_qp = 0; _qp < qRule().n_points(); ++_qp)
237  for (const auto & prop_id : _supplied_ad_prop_ids)
238  props[prop_id]->copyDualNumberToValue(_qp);
239 }
MaterialData::getPropertyId
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
Definition: MaterialData.h:144
MooseObject::validParams
static InputParameters validParams()
Definition: MooseObject.C:35
MaterialBase.h
THREAD_ID
unsigned int THREAD_ID
Definition: MooseTypes.h:196
SetupInterface
Definition: SetupInterface.h:28
MaterialBase::checkExecutionStage
void checkExecutionStage()
Check and throw an error if the execution has progerssed past the construction stage.
Definition: MaterialBase.C:222
MaterialBase::MaterialBase
MaterialBase(const InputParameters &parameters)
Definition: MaterialBase.C:62
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
MaterialBase::initStatefulProperties
virtual void initStatefulProperties(unsigned int n_points)
Initialize stateful properties (if material has some)
Definition: MaterialBase.C:102
MaterialProperties
Container for storing material properties.
Definition: MaterialProperty.h:296
ElementIDInterface
Definition: ElementIDInterface.h:21
TransientInterface::validParams
static InputParameters validParams()
Definition: TransientInterface.C:16
SubProblem::currentlyComputingJacobian
virtual const bool & currentlyComputingJacobian() const
Returns true if the problem is in the process of computing Jacobian.
Definition: SubProblem.h:592
MaterialBase::_compute
const bool _compute
If False MOOSE does not compute this property.
Definition: MaterialBase.h:232
BlockRestrictable::blockIDs
const virtual std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object.
Definition: BlockRestrictable.C:174
FEProblemBase::usingADMatProps
void usingADMatProps(bool using_ad_mat_props)
Set the global automatic differentiaion (AD) flag which indicates whether any consumer has requested ...
Definition: FEProblemBase.h:1663
BlockRestrictable::validParams
static InputParameters validParams()
Definition: BlockRestrictable.C:23
MooseVariableDependencyInterface
Definition: MooseVariableDependencyInterface.h:17
InputParameters::addParam
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object.
Definition: InputParameters.h:1198
MaterialBase::_supplied_ad_prop_ids
std::set< unsigned int > _supplied_ad_prop_ids
Definition: MaterialBase.h:236
FunctionInterface
Interface for objects that need to use functions.
Definition: FunctionInterface.h:38
Assembly.h
UserObjectInterface
Interface for objects that need to use UserObjects.
Definition: UserObjectInterface.h:28
MaterialBase::qRule
virtual const QBase & qRule() const =0
MaterialBase::registerPropName
void registerPropName(std::string prop_name, bool is_get, Prop_State state, bool is_declared_ad=false)
Small helper function to call store{Subdomain,Boundary}MatPropName.
Definition: MaterialBase.C:135
MaterialBase::computePropertiesAtQp
virtual void computePropertiesAtQp(unsigned int qp)
A method for (re)computing the properties of a MaterialBase.
Definition: MaterialBase.C:215
MaterialBase::_overrides_init_stateful_props
bool _overrides_init_stateful_props
Definition: MaterialBase.h:266
BoundaryRestrictable
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
Definition: BoundaryRestrictable.h:30
MaterialBase::_supplied_regular_prop_ids
std::set< unsigned int > _supplied_regular_prop_ids
Definition: MaterialBase.h:234
MaterialBase::computeSubdomainProperties
virtual void computeSubdomainProperties()
Evaluate material properties on subdomain.
Definition: MaterialBase.C:172
MaterialBase::validParams
static InputParameters validParams()
Definition: MaterialBase.C:22
MaterialBase::computeProperties
virtual void computeProperties()=0
Performs the quadrature point loop, calling computeQpProperties.
Definition: MaterialBase.C:186
Executioner.h
OutputInterface
A class to provide an common interface to objects requiring "outputs" option.
Definition: OutputInterface.h:37
BoundaryRestrictable::boundaryIDs
const virtual std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
Definition: BoundaryRestrictable.C:170
MooseObject
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:50
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
MaterialBase::materialData
virtual const MaterialData & materialData() const =0
MaterialBase::computeQpProperties
virtual void computeQpProperties()
Users must override this method.
Definition: MaterialBase.C:192
MaterialBase::resetProperties
virtual void resetProperties()
Resets the properties at each quadrature point (see resetQpProperties), only called if 'compute = fal...
Definition: MaterialBase.C:197
BoundaryRestrictable::validParams
static InputParameters validParams()
Definition: BoundaryRestrictable.C:19
SubProblem
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:62
DistributionInterface
Interface for objects that need to use distributions.
Definition: DistributionInterface.h:28
MaterialBase
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:47
MaterialBase::copyDualNumbersToValues
void copyDualNumbersToValues()
Definition: MaterialBase.C:230
VectorPostprocessorInterface
Definition: VectorPostprocessorInterface.h:20
MaterialBase::_props_to_flags
std::map< std::string, int > _props_to_flags
Definition: MaterialBase.h:250
ScalarCoupleable
Interface for objects that needs scalar coupling capabilities.
Definition: ScalarCoupleable.h:34
MaterialBase::Prop_State
Prop_State
Definition: MaterialBase.h:244
PostprocessorInterface
Interface class for classes which interact with Postprocessors.
Definition: PostprocessorInterface.h:34
MaterialBase::_has_stateful_property
bool _has_stateful_property
Definition: MaterialBase.h:264
MaterialBase::getOutputs
std::set< OutputName > getOutputs()
Get the list of output objects that this class is restricted.
Definition: MaterialBase.C:165
Restartable
A class for creating restricted objects.
Definition: Restartable.h:29
TransientInterface
Interface for objects that needs transient capabilities.
Definition: TransientInterface.h:35
SubProblem::storeSubdomainMatPropName
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:410
MaterialData::props
MaterialProperties & props()
Methods for retrieving MaterialProperties object.
Definition: MaterialData.h:100
MeshChangedInterface
Interface for notifications that the mesh has changed.
Definition: MeshChangedInterface.h:28
MaterialBase::initQpStatefulProperties
virtual void initQpStatefulProperties()
Initialize stateful properties at quadrature points.
Definition: MaterialBase.C:121
SubProblem::storeBoundaryMatPropName
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:416
SubProblem.h
MaterialBase::resetQpProperties
virtual void resetQpProperties()
Resets the properties prior to calculation of traditional materials (only if 'compute = false').
Definition: MaterialBase.C:204
MaterialBase::_fe_problem
FEProblemBase & _fe_problem
Definition: MaterialBase.h:201
defineLegacyParams
defineLegacyParams(MaterialBase)
Transient.h
std
Definition: TheWarehouse.h:80
BlockRestrictable
An interface that restricts an object to subdomains via the 'blocks' input parameter.
Definition: BlockRestrictable.h:61
RandomInterface::validParams
static InputParameters validParams()
Definition: RandomInterface.C:20
MaterialBase::_supplied_props
std::set< std::string > _supplied_props
Set of properties declared.
Definition: MaterialBase.h:220
MaterialBase::checkStatefulSanity
void checkStatefulSanity() const
Definition: MaterialBase.C:127
RandomInterface
Interface for objects that need parallel consistent random numbers without patterns over the course o...
Definition: RandomInterface.h:33
OutputInterface::validParams
static InputParameters validParams()
Definition: OutputInterface.C:20
InputParameters::addPrivateParam
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...
Definition: InputParameters.h:1308
FEProblemBase
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblemBase.h:139
FEProblemBase::startedInitialSetup
virtual bool startedInitialSetup()
Returns true if we are in or beyond the initialSetup stage.
Definition: FEProblemBase.h:435
MaterialBase::_qp
unsigned int _qp
Definition: MaterialBase.h:205
DependencyResolverInterface
Interface for sorting dependent vectors of objects.
Definition: DependencyResolverInterface.h:24
MaterialBase::_supplied_prop_ids
std::set< unsigned int > _supplied_prop_ids
The ids of the supplied properties, i.e.
Definition: MaterialBase.h:229
MooseObject::mooseWarning
void mooseWarning(Args &&... args) const
Definition: MooseObject.h:150
MaterialBase::subdomainSetup
virtual void subdomainSetup() override
Subdomain setup evaluating material properties when required.
Definition: MaterialBase.C:180
MooseObject::name
virtual const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:70