www.mooseframework.org
Material.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 "Material.h"
12 #include "SubProblem.h"
13 #include "MaterialData.h"
14 #include "Assembly.h"
15 #include "Executioner.h"
16 #include "Transient.h"
17 
18 #include "libmesh/quadrature.h"
19 
20 template <>
23 {
28  params += validParams<RandomInterface>();
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 Material "
42  "via MaterialPropertyInterface::getMaterial(). "
43  "Non-computed Materials are not sorted for dependencies.");
44  MooseEnum const_option("NONE=0 ELEMENT=1 SUBDOMAIN=2", "none");
45  params.addParam<MooseEnum>(
46  "constant_on",
47  const_option,
48  "When ELEMENT, MOOSE will only call computeQpProperties() for the 0th "
49  "quadrature point, and then copy that value to the other qps."
50  "When SUBDOMAIN, MOOSE will only call computeSubdomainProperties() for the 0th "
51  "quadrature point, and then copy that value to the other qps. Evaluations on element qps "
52  "will be skipped");
53 
54  params.addPrivateParam<bool>("_neighbor", false);
55 
56  // Outputs
57  params += validParams<OutputInterface>();
58  params.set<std::vector<OutputName>>("outputs") = {"none"};
59  params.addParam<std::vector<std::string>>(
60  "output_properties",
61  "List of material properties, from this material, to output (outputs "
62  "must also be defined to an output type)");
63 
64  params.addParamNamesToGroup("outputs output_properties", "Outputs");
65  params.addParamNamesToGroup("use_displaced_mesh constant_on", "Advanced");
66  params.registerBase("Material");
67 
68  return params;
69 }
70 
72  : MooseObject(parameters),
73  BlockRestrictable(this),
74  BoundaryRestrictable(this, blockIDs(), false), // false for being _not_ nodal
75  SetupInterface(this),
76  Coupleable(this, false),
78  ScalarCoupleable(this),
79  FunctionInterface(this),
81  UserObjectInterface(this),
82  TransientInterface(this),
83  MaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
87  Restartable(this, "Materials"),
88  MeshChangedInterface(parameters),
89 
90  // The false flag disables the automatic call buildOutputVariableHideList;
91  // for Material objects the hide lists are handled by MaterialOutputAction
92  OutputInterface(parameters, false),
93  RandomInterface(parameters,
94  *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
95  parameters.get<THREAD_ID>("_tid"),
96  false),
97  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
98  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
99  _tid(parameters.get<THREAD_ID>("_tid")),
100  _assembly(_subproblem.assembly(_tid)),
101  _bnd(_material_data_type != Moose::BLOCK_MATERIAL_DATA),
102  _neighbor(_material_data_type == Moose::NEIGHBOR_MATERIAL_DATA),
103  _qp(std::numeric_limits<unsigned int>::max()),
104  _qrule(_bnd ? _assembly.qRuleFace() : _assembly.qRule()),
105  _JxW(_bnd ? _assembly.JxWFace() : _assembly.JxW()),
106  _coord(_assembly.coordTransformation()),
107  _q_point(_bnd ? _assembly.qPointsFace() : _assembly.qPoints()),
108  _normals(_assembly.normals()),
109  _current_elem(_neighbor ? _assembly.neighbor() : _assembly.elem()),
110  _current_subdomain_id(_neighbor ? _assembly.currentNeighborSubdomainID()
111  : _assembly.currentSubdomainID()),
112  _current_side(_neighbor ? _assembly.neighborSide() : _assembly.side()),
113  _mesh(_subproblem.mesh()),
114  _coord_sys(_assembly.coordSystem()),
115  _compute(getParam<bool>("compute")),
116  _constant_option(getParam<MooseEnum>("constant_on").getEnum<ConstantTypeEnum>()),
117  _has_stateful_property(false)
118 {
119  // Fill in the MooseVariable dependencies
120  const std::vector<MooseVariableFEBase *> & coupled_vars = getCoupledMooseVars();
121  for (const auto & var : coupled_vars)
123 }
124 
125 void
126 Material::initStatefulProperties(unsigned int n_points)
127 {
128  for (_qp = 0; _qp < n_points; ++_qp)
130 
131  // checking for statefulness of properties via this loop is necessary
132  // because owned props might have been promoted to stateful by calls to
133  // getMaterialProperty[Old/Older] from other objects. In these cases, this
134  // object won't otherwise know that it owns stateful properties.
135  for (auto & prop : _supplied_props)
136  if (_material_data->getMaterialPropertyStorage().isStatefulProp(prop) &&
138  mooseError(std::string("Material \"") + name() +
139  "\" provides one or more stateful "
140  "properties but initQpStatefulProperties() "
141  "was not overridden in the derived class.");
142 }
143 
144 void
146 {
148 }
149 
150 void
152 {
153  for (const auto & it : _props_to_flags)
154  if (static_cast<int>(it.second) % 2 == 0) // Only Stateful properties declared!
155  mooseError("Material '", name(), "' requests undefined stateful property '", it.first, "'");
156 }
157 
158 void
159 Material::registerPropName(std::string prop_name,
160  bool is_get,
161  Material::Prop_State state,
162  bool is_declared_ad)
163 {
164  if (!is_get)
165  {
166  _supplied_props.insert(prop_name);
167  const auto & property_id = _material_data->getPropertyId(prop_name);
168  _supplied_prop_ids.insert(property_id);
169  if (is_declared_ad)
170  _supplied_ad_prop_ids.insert(property_id);
171  else
172  _supplied_regular_prop_ids.insert(property_id);
173 
174  _props_to_flags[prop_name] |= static_cast<int>(state);
175  if (static_cast<int>(state) % 2 == 0)
176  _has_stateful_property = true;
177  }
178 
179  // Store material properties for block ids
180  for (const auto & block_id : blockIDs())
181  _fe_problem.storeSubdomainMatPropName(block_id, prop_name);
182 
183  // Store material properties for the boundary ids
184  for (const auto & boundary_id : boundaryIDs())
185  _fe_problem.storeBoundaryMatPropName(boundary_id, prop_name);
186 }
187 
188 std::set<OutputName>
190 {
191  const std::vector<OutputName> & out = getParam<std::vector<OutputName>>("outputs");
192  return std::set<OutputName>(out.begin(), out.end());
193 }
194 
195 void
197 {
198  if (_constant_option == ConstantTypeEnum::SUBDOMAIN)
199  {
200  unsigned int nqp = _fe_problem.getMaxQps();
201 
202  MaterialProperties & props = _material_data->props();
203  for (const auto & prop_id : _supplied_prop_ids)
204  props[prop_id]->resize(nqp);
205 
206  _qp = 0;
208 
209  for (const auto & prop_id : _supplied_prop_ids)
210  {
211  for (decltype(nqp) qp = 1; qp < nqp; ++qp)
212  props[prop_id]->qpCopy(qp, props[prop_id], 0);
213  }
214  }
215 }
216 
217 void
219 {
220  mooseError("computeSubdomainQpProperties in Material '", name(), "' needs to be implemented");
221 }
222 
223 void
225 {
226  if (_constant_option == ConstantTypeEnum::SUBDOMAIN)
227  return;
228 
229  // Reference to *all* the MaterialProperties in the MaterialData object, not
230  // just the ones for this Material.
231  MaterialProperties & props = _material_data->props();
232 
233  // If this Material has the _constant_on_elem flag set, we take the
234  // value computed for _qp==0 and use it at all the quadrature points
235  // in the Elem.
236  if (_constant_option == ConstantTypeEnum::ELEMENT)
237  {
238  // Compute MaterialProperty values at the first qp.
239  _qp = 0;
241 
242  // Now copy the values computed at qp 0 to all the other qps.
243  for (const auto & prop_id : _supplied_regular_prop_ids)
244  {
245  auto nqp = _qrule->n_points();
246  for (decltype(nqp) qp = 1; qp < nqp; ++qp)
247  props[prop_id]->qpCopy(qp, props[prop_id], 0);
248  }
249  for (const auto & prop_id : _supplied_ad_prop_ids)
250  {
251  auto nqp = _qrule->n_points();
252  for (decltype(nqp) qp = 1; qp < nqp; ++qp)
253  props[prop_id]->qpCopy(qp, props[prop_id], 0);
254  }
256  }
257  else
258  {
259  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
262  }
263 }
264 
265 void
267 {
269  return;
270 
271  MaterialProperties & props = _material_data->props();
272  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
273  for (const auto & prop_id : _supplied_ad_prop_ids)
274  props[prop_id]->copyDualNumberToValue(_qp);
275 }
276 
277 void
279 {
280 }
281 
282 void
284 {
285  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
287 }
288 
289 void
291 {
292  if (!_compute)
293  mooseDoOnce(mooseWarning("You disabled the computation of this (",
294  name(),
295  ") material by MOOSE, but have not overridden the 'resetQpProperties' "
296  "method, this can lead to unintended values being set for material "
297  "property values."));
298 }
299 
300 void
302 {
303  _qp = qp;
305 }
306 
307 void
309 {
311  mooseError("Material properties must be retrieved during material object construction to "
312  "ensure correct dependency resolution.");
313 }
InputParameters validParams< MaterialPropertyInterface >()
std::map< std::string, int > _props_to_flags
Definition: Material.h:289
Interface for objects that need parallel consistent random numbers without patterns over the course o...
bool _has_stateful_property
Definition: Material.h:304
const QBase *const & _qrule
Definition: Material.h:224
A class for creating restricted objects.
Definition: Restartable.h:29
virtual void computeQpProperties()
Users must override this method.
Definition: Material.C:278
void mooseWarning(Args &&... args) const
Definition: MooseObject.h:155
InputParameters validParams< BlockRestrictable >()
virtual void resetQpProperties()
Resets the properties prior to calculation of traditional materials (only if &#39;compute = false&#39;)...
Definition: Material.C:290
virtual const bool & currentlyComputingJacobian() const
Returns true if the problem is in the process of computing Jacobian.
Definition: SubProblem.h:569
InputParameters validParams< OutputInterface >()
Container for storing material properties.
FEProblemBase & _fe_problem
Definition: Material.h:215
bool _overrides_init_stateful_props
Definition: Material.h:306
const ConstantTypeEnum _constant_option
Options of the constantness level of the material.
Definition: Material.h:275
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
std::set< unsigned int > _supplied_prop_ids
The ids of the supplied properties, i.e.
Definition: Material.h:256
A class to provide an common interface to objects requiring "outputs" option.
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...
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object.
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
std::set< unsigned int > _supplied_regular_prop_ids
The set of supplied regular property ids.
Definition: Material.h:259
virtual void subdomainSetup() override
Subdomain setup evaluating material properties when required.
Definition: Material.C:196
virtual void resetProperties()
Resets the properties at each quadrature point (see resetQpProperties), only called if &#39;compute = fal...
Definition: Material.C:283
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void addMooseVariableDependency(MooseVariableFEBase *var)
Call this function to add the passed in MooseVariableFEBase as a variable that this object depends on...
const bool _compute
If False MOOSE does not compute this property.
Definition: Material.h:265
unsigned int _qp
Definition: Material.h:222
Interface for objects that needs transient capabilities.
void usingADMatProps(bool using_ad_mat_props)
Set the global automatic differentiaion (AD) flag which indicates whether any consumer has requested ...
void copyDualNumbersToValues()
Copies dual number values from ADMaterials into Real property values for Material<->ADMaterial intero...
Definition: Material.C:266
virtual void computeProperties()
Performs the quadrature point loop, calling computeQpProperties.
Definition: Material.C:224
void checkStatefulSanity() const
Definition: Material.C:151
Interface for notifications that the mesh has changed.
InputParameters validParams< RandomInterface >()
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
Interface for objects that need to use distributions.
virtual void computeSubdomainProperties()
Evaluate material properties on subdomain.
Definition: Material.C:218
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:412
ConstantTypeEnum
Definition: Material.h:267
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
Interface for objects that need to use UserObjects.
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: Material.C:159
std::set< unsigned int > _supplied_ad_prop_ids
The set of supplied automatic differentiation property ids.
Definition: Material.h:262
virtual void initStatefulProperties(unsigned int n_points)
Initialize stateful properties (if material has some)
Definition: Material.C:126
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:25
std::shared_ptr< MaterialData > _material_data
Pointer to the material data class that stores properties.
std::set< OutputName > getOutputs()
Get the list of output objects that this class is restricted.
Definition: Material.C:189
Interface for objects that needs coupling capabilities.
Definition: Coupleable.h:62
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:59
void checkExecutionStage()
Check and throw an error if the execution has progerssed past the construction stage.
Definition: Material.C:308
An interface for accessing Materials.
const std::vector< MooseVariableFEBase * > & getCoupledMooseVars() const
Get the list of all coupled variables.
Definition: Coupleable.h:90
InputParameters validParams< BoundaryRestrictable >()
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
Interface for sorting dependent vectors of objects.
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
Interface for objects that needs scalar coupling capabilities.
virtual void computePropertiesAtQp(unsigned int qp)
A method for (re)computing the properties of a Material.
Definition: Material.C:301
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: Moose.h:112
std::set< std::string > _supplied_props
Set of properties declared.
Definition: Material.h:247
virtual void initQpStatefulProperties()
Initialize stateful properties at quadrature points.
Definition: Material.C:145
InputParameters validParams< Material >()
Definition: Material.C:22
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
Interface for objects that need to use functions.
InputParameters validParams< TransientInterface >()
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:406
Interface class for classes which interact with Postprocessors.
Material(const InputParameters &parameters)
Definition: Material.C:71
unsigned int THREAD_ID
Definition: MooseTypes.h:161
virtual bool startedInitialSetup()
Returns true if we are in or beyond the initialSetup stage.
unsigned int getMaxQps() const