www.mooseframework.org
Material.h
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 #pragma once
11 
12 // MOOOSE includes
13 #include "MaterialProperty.h"
14 #include "MooseObject.h"
15 #include "BlockRestrictable.h"
16 #include "BoundaryRestrictable.h"
17 #include "SetupInterface.h"
18 #include "Coupleable.h"
20 #include "ScalarCoupleable.h"
21 #include "FunctionInterface.h"
22 #include "DistributionInterface.h"
23 #include "UserObjectInterface.h"
24 #include "TransientInterface.h"
26 #include "PostprocessorInterface.h"
29 #include "Restartable.h"
30 #include "MeshChangedInterface.h"
31 #include "OutputInterface.h"
32 #include "RandomInterface.h"
33 
34 // forward declarations
35 class Material;
36 class MooseMesh;
37 class MaterialData;
38 class SubProblem;
39 
40 template <>
42 
46 class Material : public MooseObject,
47  public BlockRestrictable,
48  public BoundaryRestrictable,
49  public SetupInterface,
50  public Coupleable,
52  public ScalarCoupleable,
53  public FunctionInterface,
54  public DistributionInterface,
55  public UserObjectInterface,
56  public TransientInterface,
61  public Restartable,
62  public MeshChangedInterface,
63  public OutputInterface,
64  public RandomInterface
65 {
66 public:
68 
72  virtual void initStatefulProperties(unsigned int n_points);
73 
77  virtual void computeProperties();
78 
85  virtual void resetProperties();
86 
94  virtual void computePropertiesAtQp(unsigned int qp);
95 
97 
101  template <typename T>
102  const MaterialProperty<T> & getMaterialProperty(const std::string & name);
103  template <typename T>
104  const ADMaterialPropertyObject<T> & getADMaterialProperty(const std::string & name);
105  template <typename T>
106  const MaterialProperty<T> & getMaterialPropertyOld(const std::string & name);
107  template <typename T>
108  const MaterialProperty<T> & getMaterialPropertyOlder(const std::string & name);
110 
112 
115  template <typename T>
116  const MaterialProperty<T> & getMaterialPropertyByName(const std::string & prop_name);
117  template <typename T>
118  const ADMaterialPropertyObject<T> & getADMaterialPropertyByName(const std::string & prop_name);
119  template <typename T>
120  const MaterialProperty<T> & getMaterialPropertyOldByName(const std::string & prop_name);
121  template <typename T>
122  const MaterialProperty<T> & getMaterialPropertyOlderByName(const std::string & prop_name);
124 
126 
129  template <typename T>
130  MaterialProperty<T> & declareProperty(const std::string & prop_name);
131  template <typename T>
132  MaterialProperty<T> & declarePropertyOld(const std::string & prop_name);
133  template <typename T>
134  MaterialProperty<T> & declarePropertyOlder(const std::string & prop_name);
136 
141  template <typename T>
142  const MaterialProperty<T> & getZeroMaterialProperty(const std::string & prop_name);
143 
148  virtual const std::set<std::string> & getRequestedItems() override { return _requested_props; }
149 
154  virtual const std::set<std::string> & getSuppliedItems() override { return _supplied_props; }
155 
156  void checkStatefulSanity() const;
157 
162  std::set<OutputName> getOutputs();
163 
167  bool isBoundaryMaterial() const { return _bnd; }
168 
172  virtual void subdomainSetup() override;
173 
174 protected:
178  virtual void computeSubdomainProperties();
179 
183  virtual void computeQpProperties();
184 
194  virtual void resetQpProperties();
195 
205  virtual void initQpStatefulProperties();
206 
212 
214 
218 
219  bool _bnd;
220  bool _neighbor;
221 
222  unsigned int _qp;
223 
224  const QBase * const & _qrule;
230 
231  const Elem * const & _current_elem;
232 
234 
236  const unsigned int & _current_side;
237 
239 
242 
244  std::set<std::string> _requested_props;
245 
247  std::set<std::string> _supplied_props;
248 
256  std::set<unsigned int> _supplied_prop_ids;
257 
259  std::set<unsigned int> _supplied_regular_prop_ids;
260 
262  std::set<unsigned int> _supplied_ad_prop_ids;
263 
265  const bool _compute;
266 
268  {
272  };
273 
276 
278  {
281  };
282 
284  {
285  CURRENT = 0x1,
286  OLD = 0x2,
287  OLDER = 0x4
288  };
289  std::map<std::string, int> _props_to_flags;
290 
292  void registerPropName(std::string prop_name,
293  bool is_get,
294  Prop_State state,
295  bool is_declared_ad = false);
296 
298  std::vector<unsigned int> _displacements;
299 
300 private:
302  void checkExecutionStage();
303 
305 
307 };
308 
309 template <typename T>
310 const MaterialProperty<T> &
311 Material::getMaterialProperty(const std::string & name)
312 {
313  // Check if the supplied parameter is a valid imput parameter key
314  std::string prop_name = deducePropertyName(name);
315 
316  // Check if it's just a constant.
317  const MaterialProperty<T> * default_property = defaultMaterialProperty<T>(prop_name);
318  if (default_property)
319  return *default_property;
320 
321  return getMaterialPropertyByName<T>(prop_name);
322 }
323 
324 template <typename T>
326 Material::getADMaterialProperty(const std::string & name)
327 {
328  // Check if the supplied parameter is a valid imput parameter key
329  std::string prop_name = deducePropertyName(name);
330 
331  // Check if it's just a constant.
332  const ADMaterialPropertyObject<T> * default_property = defaultADMaterialProperty<T>(prop_name);
333  if (default_property)
334  return *default_property;
335 
336  return getADMaterialPropertyByName<T>(prop_name);
337 }
338 
339 template <typename T>
340 const MaterialProperty<T> &
341 Material::getMaterialPropertyOld(const std::string & name)
342 {
343  // Check if the supplied parameter is a valid imput parameter key
344  std::string prop_name = deducePropertyName(name);
345 
346  // Check if it's just a constant.
347  const MaterialProperty<T> * default_property = defaultMaterialProperty<T>(prop_name);
348  if (default_property)
349  return *default_property;
350 
351  return getMaterialPropertyOldByName<T>(prop_name);
352 }
353 
354 template <typename T>
355 const MaterialProperty<T> &
356 Material::getMaterialPropertyOlder(const std::string & name)
357 {
358  // Check if the supplied parameter is a valid imput parameter key
359  std::string prop_name = deducePropertyName(name);
360 
361  // Check if it's just a constant.
362  const MaterialProperty<T> * default_property = defaultMaterialProperty<T>(prop_name);
363  if (default_property)
364  return *default_property;
365 
366  return getMaterialPropertyOlderByName<T>(prop_name);
367 }
368 
369 template <typename T>
370 const MaterialProperty<T> &
371 Material::getMaterialPropertyByName(const std::string & prop_name)
372 {
374  // The property may not exist yet, so declare it (declare/getMaterialProperty are referencing the
375  // same memory)
376  _requested_props.insert(prop_name);
377  registerPropName(prop_name, true, Material::CURRENT);
378  return MaterialPropertyInterface::getMaterialPropertyByName<T>(prop_name);
379 }
380 
381 template <typename T>
383 Material::getADMaterialPropertyByName(const std::string & prop_name)
384 {
386  // The property may not exist yet, so declare it (declare/getADMaterialProperty are referencing
387  // the same memory)
388  _requested_props.insert(prop_name);
389  registerPropName(prop_name, true, Material::CURRENT);
390  return MaterialPropertyInterface::getADMaterialPropertyByName<T>(prop_name);
391 }
392 
393 template <typename T>
394 const MaterialProperty<T> &
395 Material::getMaterialPropertyOldByName(const std::string & prop_name)
396 {
397  registerPropName(prop_name, true, Material::OLD);
398  return MaterialPropertyInterface::getMaterialPropertyOldByName<T>(prop_name);
399 }
400 
401 template <typename T>
402 const MaterialProperty<T> &
403 Material::getMaterialPropertyOlderByName(const std::string & prop_name)
404 {
405  registerPropName(prop_name, true, Material::OLDER);
406  return MaterialPropertyInterface::getMaterialPropertyOlderByName<T>(prop_name);
407 }
408 
409 template <typename T>
411 Material::declareProperty(const std::string & prop_name)
412 {
413  registerPropName(prop_name, false, Material::CURRENT);
414  return _material_data->declareProperty<T>(prop_name);
415 }
416 
417 template <typename T>
419 Material::declarePropertyOld(const std::string & prop_name)
420 {
421  mooseDoOnce(
422  mooseDeprecated("declarePropertyOld is deprecated and not needed anymore.\nUse "
423  "getMaterialPropertyOld (only) if a reference is required in this class."));
424  registerPropName(prop_name, false, Material::OLD);
425  return _material_data->declarePropertyOld<T>(prop_name);
426 }
427 
428 template <typename T>
430 Material::declarePropertyOlder(const std::string & prop_name)
431 {
432  mooseDoOnce(
433  mooseDeprecated("declarePropertyOlder is deprecated and not needed anymore. Use "
434  "getMaterialPropertyOlder (only) if a reference is required in this class."));
435  registerPropName(prop_name, false, Material::OLDER);
436  return _material_data->declarePropertyOlder<T>(prop_name);
437 }
438 
439 template <typename T>
440 const MaterialProperty<T> &
441 Material::getZeroMaterialProperty(const std::string & prop_name)
442 {
444  MaterialProperty<T> & preload_with_zero = _material_data->getProperty<T>(prop_name);
445 
446  _requested_props.insert(prop_name);
447  registerPropName(prop_name, true, Material::CURRENT);
449 
450  // Register this material on these blocks and boundaries as a zero property with relaxed
451  // consistency checking
452  for (std::set<SubdomainID>::const_iterator it = blockIDs().begin(); it != blockIDs().end(); ++it)
453  _fe_problem.storeSubdomainZeroMatProp(*it, prop_name);
454  for (std::set<BoundaryID>::const_iterator it = boundaryIDs().begin(); it != boundaryIDs().end();
455  ++it)
456  _fe_problem.storeBoundaryZeroMatProp(*it, prop_name);
457 
458  // set values for all qpoints to zero
459  // (in multiapp scenarios getMaxQps can return different values in each app; we need the max)
460  unsigned int nqp = _mi_feproblem.getMaxQps();
461  if (nqp > preload_with_zero.size())
462  preload_with_zero.resize(nqp);
463  for (unsigned int qp = 0; qp < nqp; ++qp)
464  mooseSetToZero<T>(preload_with_zero[qp]);
465 
466  return preload_with_zero;
467 }
468 
const MooseArray< Point > & _q_point
Definition: Material.h:227
std::map< std::string, int > _props_to_flags
Definition: Material.h:289
SubProblem & _subproblem
Definition: Material.h:213
Interface for objects that need parallel consistent random numbers without patterns over the course o...
const MaterialProperty< T > & getZeroMaterialProperty(const std::string &prop_name)
Return a material property that is initialized to zero by default and does not need to (but can) be d...
Definition: Material.h:441
bool _has_stateful_property
Definition: Material.h:304
FEProblemBase & _mi_feproblem
Reference to the FEProblemBase class.
const QBase *const & _qrule
Definition: Material.h:224
A class for creating restricted objects.
Definition: Restartable.h:29
const MaterialProperty< T > & getMaterialPropertyOlderByName(const std::string &prop_name)
Definition: Material.h:403
Keeps track of stuff related to assembling.
Definition: Assembly.h:62
std::vector< unsigned int > _displacements
Displacement ids.
Definition: Material.h:298
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:418
virtual void computeQpProperties()
Users must override this method.
Definition: Material.C:278
virtual void resetQpProperties()
Resets the properties prior to calculation of traditional materials (only if &#39;compute = false&#39;)...
Definition: Material.C:290
FEProblemBase & _fe_problem
Definition: Material.h:215
bool _overrides_init_stateful_props
Definition: Material.h:306
const MaterialProperty< T > & getMaterialPropertyOldByName(const std::string &prop_name)
Definition: Material.h:395
const ConstantTypeEnum _constant_option
Options of the constantness level of the material.
Definition: Material.h:275
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:424
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.
const MooseArray< Real > & _JxW
Definition: Material.h:225
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< std::string > _requested_props
Set of properties accessed via get method.
Definition: Material.h:244
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object.
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.
virtual void markMatPropRequested(const std::string &)
Helper method for adding a material property name to the _material_property_requested set...
Definition: SubProblem.C:546
MaterialProperty< T > & declarePropertyOlder(const std::string &prop_name)
Definition: Material.h:430
const bool _compute
If False MOOSE does not compute this property.
Definition: Material.h:265
unsigned int _qp
Definition: Material.h:222
std::string deducePropertyName(const std::string &name)
Small helper to look up a material property name through the input parameter keys.
Interface for objects that needs transient capabilities.
bool _bnd
Definition: Material.h:219
THREAD_ID _tid
Definition: Material.h:216
void copyDualNumbersToValues()
Copies dual number values from ADMaterials into Real property values for Material<->ADMaterial intero...
Definition: Material.C:266
bool isBoundaryMaterial() const
Returns true of the MaterialData type is not associated with volume data.
Definition: Material.h:167
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.
virtual const std::set< std::string > & getSuppliedItems() override
Return a set of properties accessed with declareProperty.
Definition: Material.h:154
MaterialProperty< T > & declarePropertyOld(const std::string &prop_name)
Definition: Material.h:419
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:65
Interface for objects that need to use distributions.
virtual void computeSubdomainProperties()
Evaluate material properties on subdomain.
Definition: Material.C:218
ConstantTypeEnum
Definition: Material.h:267
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
Interface for objects that need to use UserObjects.
subdomain_id_type SubdomainID
bool _neighbor
Definition: Material.h:220
const MaterialProperty< T > & getMaterialPropertyOlder(const std::string &name)
Definition: Material.h:356
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
CoordinateSystemType
Definition: MooseTypes.h:556
std::shared_ptr< MaterialData > _material_data
Pointer to the material data class that stores properties.
Materials compute MaterialProperties.
Definition: Material.h:46
virtual void resize(int n) override
Resizes the property to the size n.
virtual const std::set< std::string > & getRequestedItems() override
Return a set of properties accessed with getMaterialProperty.
Definition: Material.h:148
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.
void mooseDeprecated(Args &&... args) const
Definition: MooseObject.h:161
const unsigned int & _current_side
current side of the current element
Definition: Material.h:236
Concrete definition of a parameter value for a specified type.
const ADMaterialPropertyObject< T > & getADMaterialPropertyByName(const std::string &prop_name)
Definition: Material.h:383
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.
MooseMesh & _mesh
Definition: Material.h:238
MaterialProperty< T > & declareProperty(const std::string &prop_name)
Declare the property named "name".
Definition: Material.h:411
virtual void computePropertiesAtQp(unsigned int qp)
A method for (re)computing the properties of a Material.
Definition: Material.C:301
Proxy for accessing MaterialPropertyStorage.
Definition: MaterialData.h:27
const MooseArray< Real > & _coord
Definition: Material.h:226
Assembly & _assembly
Definition: Material.h:217
const ADMaterialPropertyObject< T > & getADMaterialProperty(const std::string &name)
Definition: Material.h:326
const Moose::CoordinateSystemType & _coord_sys
Coordinate system.
Definition: Material.h:241
const SubdomainID & _current_subdomain_id
Definition: Material.h:233
InputParameters validParams< Material >()
Definition: Material.C:22
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
const MooseArray< Point > & _normals
normals at quadrature points (valid only in boundary materials)
Definition: Material.h:229
const MaterialProperty< T > & getMaterialProperty(const std::string &name)
Retrieve the property through a given input parameter key with a fallback to getting it by name...
Definition: Material.h:311
virtual unsigned int size() const override
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name)
Definition: Material.h:341
QP_Data_Type
Definition: Material.h:277
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
Interface for objects that need to use functions.
const Elem *const & _current_elem
Definition: Material.h:231
Interface class for classes which interact with Postprocessors.
Material(const InputParameters &parameters)
Definition: Material.C:71
unsigned int THREAD_ID
Definition: MooseTypes.h:161
const MaterialProperty< T > & getMaterialPropertyByName(const std::string &prop_name)
Retrieve the property named "name".
Definition: Material.h:371
unsigned int getMaxQps() const