https://mooseframework.inl.gov
Material.h
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 #pragma once
11 
12 // MOOOSE includes
13 #include "MaterialBase.h"
14 #include "Coupleable.h"
15 #include "MooseEnum.h"
17 #include "FEProblemBase.h"
18 
19 #include <string>
20 
21 #define usingMaterialMembers \
22  usingMaterialBaseMembers; \
23  usingCoupleableMembers; \
24  usingMaterialPropertyInterfaceMembers; \
25  using Material::_q_point; \
26  using Material::_qrule; \
27  using Material::_JxW; \
28  using Material::_current_elem; \
29  using Material::_current_subdomain_id; \
30  using Material::_current_side
31 
36 {
37 public:
39 
41 
48  virtual const dof_id_type & getElementID(const std::string & id_parameter_name,
49  unsigned int comp = 0) const override
50  {
51  return _neighbor ? ElementIDInterface::getElementIDNeighbor(id_parameter_name, comp)
52  : ElementIDInterface::getElementID(id_parameter_name, comp);
53  }
58  virtual const dof_id_type & getElementIDNeighbor(const std::string & id_parameter_name,
59  unsigned int comp = 0) const override
60  {
61  mooseError("Directly calling 'getElementIDNeighbor' is not allowed for materials. Please call "
62  "'getElementID' instead");
63  return ElementIDInterface::getElementIDNeighbor(id_parameter_name, comp);
64  }
65 
71  virtual const dof_id_type &
72  getElementIDByName(const std::string & id_parameter_name) const override
73  {
75  : ElementIDInterface::getElementIDByName(id_parameter_name);
76  }
81  virtual const dof_id_type &
82  getElementIDNeighborByName(const std::string & id_parameter_name) const override
83  {
84  mooseError("Directly calling 'getElementIDNeighborByName' is not allowed for materials. Please "
85  "call 'getElementIDByName' instead");
86  return ElementIDInterface::getElementIDNeighborByName(id_parameter_name);
87  }
88 
89  virtual void computeProperties() override;
90 
92 
96  template <typename T, bool is_ad>
98  getGenericMaterialProperty(const std::string & name, const unsigned int state = 0);
99  template <typename T>
100  const MaterialProperty<T> & getMaterialProperty(const std::string & name,
101  const unsigned int state = 0)
102  {
103  return getGenericMaterialProperty<T, false>(name, state);
104  }
105  template <typename T>
106  const ADMaterialProperty<T> & getADMaterialProperty(const std::string & name)
107  {
108  return getGenericMaterialProperty<T, true>(name, 0);
109  }
110  template <typename T>
111  const MaterialProperty<T> & getMaterialPropertyOld(const std::string & name)
112  {
113  return getGenericMaterialProperty<T, false>(name, 1);
114  }
115  template <typename T>
116  const MaterialProperty<T> & getMaterialPropertyOlder(const std::string & name)
117  {
118  return getGenericMaterialProperty<T, false>(name, 2);
119  }
121 
123 
126  template <typename T, bool is_ad>
128  getGenericMaterialPropertyByName(const std::string & name, const unsigned int state = 0);
129  template <typename T>
130  const MaterialProperty<T> & getMaterialPropertyByName(const std::string & prop_name,
131  const unsigned int state = 0)
132  {
133  return getGenericMaterialPropertyByName<T, false>(prop_name, state);
134  }
135  template <typename T>
136  const ADMaterialProperty<T> & getADMaterialPropertyByName(const std::string & prop_name)
137  {
138  return getGenericMaterialPropertyByName<T, true>(prop_name, 0);
139  }
140  template <typename T>
141  const MaterialProperty<T> & getMaterialPropertyOldByName(const std::string & prop_name)
142  {
143  return getGenericMaterialPropertyByName<T, false>(prop_name, 1);
144  }
145  template <typename T>
146  const MaterialProperty<T> & getMaterialPropertyOlderByName(const std::string & prop_name)
147  {
148  return getGenericMaterialPropertyByName<T, false>(prop_name, 2);
149  }
151 
155  MaterialBase & getMaterial(const std::string & name)
156  {
157  return getMaterialByName(parameters().get<MaterialName>(name));
158  }
159 
168  MaterialBase &
169  getMaterialByName(const std::string & name, bool no_warn = false, bool no_dep = false);
170 
172  template <typename T, bool is_ad>
174  getGenericOptionalMaterialProperty(const std::string & name, const unsigned int state = 0);
175  template <typename T>
177  const unsigned int state = 0)
178  {
179  return getGenericOptionalMaterialProperty<T, false>(name, state);
180  }
181  template <typename T>
183  {
184  return getGenericOptionalMaterialProperty<T, true>(name, 0);
185  }
186  template <typename T>
188  {
189  return getGenericOptionalMaterialProperty<T, false>(name, 1);
190  }
191  template <typename T>
193  {
194  return getGenericOptionalMaterialProperty<T, false>(name, 2);
195  }
197 
201 
202  virtual bool isBoundaryMaterial() const override { return _bnd; }
203 
204  virtual const std::unordered_set<unsigned int> & getMatPropDependencies() const override
205  {
207  }
208  virtual void subdomainSetup() override;
209 
210  CreateMooseEnumClass(ConstantTypeEnum, NONE, ELEMENT, SUBDOMAIN);
211 
212  bool ghostable() const override final { return _ghostable; }
213 
215  virtual void resolveOptionalProperties() override;
216 
217 protected:
218  virtual void checkMaterialProperty(const std::string & name, const unsigned int state) override;
219 
220  virtual const MaterialData & materialData() const override { return _material_data; }
221  virtual MaterialData & materialData() override { return _material_data; }
223 
224  virtual const QBase & qRule() const override { return *_qrule; }
225 
226  bool _bnd;
227  bool _neighbor;
228 
230  const QBase * const & _qrule;
231 
233 
234  const Elem * const & _current_elem;
235 
237 
239  const unsigned int & _current_side;
240 
242  const ConstantTypeEnum _constant_option;
243 
244 private:
245  ConstantTypeEnum computeConstantOption();
246 
252 
254  std::vector<std::unique_ptr<OptionalMaterialPropertyProxyBase<Material>>>
256 };
257 
258 template <typename T, bool is_ad>
260 Material::getGenericMaterialProperty(const std::string & name, const unsigned int state)
261 {
262  // Check if the supplied parameter is a valid input parameter key
263  const auto prop_name = getMaterialPropertyName(name);
264 
265  // Check if it's just a constant.
266  if (const auto * default_property = defaultGenericMaterialProperty<T, is_ad>(prop_name))
267  return *default_property;
268 
269  return getGenericMaterialPropertyByName<T, is_ad>(prop_name, state);
270 }
271 
272 template <typename T, bool is_ad>
274 Material::getGenericMaterialPropertyByName(const std::string & prop_name_in,
275  const unsigned int state)
276 {
278  {
279  if (state == 1)
280  return getGenericMaterialPropertyByName<T, is_ad>(prop_name_in + _interpolated_old, 0);
281  if (state == 2)
282  return getGenericMaterialPropertyByName<T, is_ad>(prop_name_in + _interpolated_older, 0);
283  }
284 
286 
287  // The property may not exist yet, so declare it (declare/getMaterialProperty are referencing the
288  // same memory)
289  const auto prop_name =
290  _get_suffix.empty()
291  ? prop_name_in
292  : MooseUtils::join(std::vector<std::string>({prop_name_in, _get_suffix}), "_");
293 
294  if (state == 0)
295  _requested_props.insert(prop_name);
296 
297  // Do this before so that we register the ID first
298  auto & prop =
299  MaterialPropertyInterface::getGenericMaterialPropertyByName<T, is_ad>(prop_name_in, state);
300 
301  registerPropName(prop_name, true, state);
302 
303  return prop;
304 }
305 
306 template <typename T, bool is_ad>
308 Material::getGenericOptionalMaterialProperty(const std::string & name, const unsigned int state)
309 {
310  auto proxy = std::make_unique<OptionalMaterialPropertyProxy<Material, T, is_ad>>(name, state);
311  auto & optional_property = proxy->value();
312  _optional_property_proxies.push_back(std::move(proxy));
313  return optional_property;
314 }
const MooseArray< Point > & _q_point
Definition: Material.h:229
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const
Retrieve the set of material properties that this object depends on.
const OptionalADMaterialProperty< T > & getOptionalADMaterialProperty(const std::string &name)
Definition: Material.h:182
const OptionalMaterialProperty< T > & getOptionalMaterialPropertyOlder(const std::string &name)
Definition: Material.h:192
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name)
Definition: Material.h:111
static const std::string _interpolated_old
name suffixes for interpolated old and older properties
const QBase *const & _qrule
Definition: Material.h:230
ConstantTypeEnum computeConstantOption()
Definition: Material.C:142
const OptionalMaterialProperty< T > & getOptionalMaterialPropertyOld(const std::string &name)
Definition: Material.h:187
const MaterialProperty< T > & getMaterialProperty(const std::string &name, const unsigned int state=0)
Definition: Material.h:100
virtual const dof_id_type & getElementIDNeighbor(const std::string &id_parameter_name, unsigned int comp=0) const
Gets a neighbor element integer with a parameter of the object derived from this interface.
virtual const MaterialData & materialData() const override
Definition: Material.h:220
const GenericOptionalMaterialProperty< T, is_ad > & getGenericOptionalMaterialProperty(const std::string &name, const unsigned int state=0)
Optional material property getters.
Definition: Material.h:308
const GenericMaterialProperty< T, is_ad > & getGenericMaterialPropertyByName(const std::string &name, const unsigned int state=0)
Retrieve the property named "name".
Definition: Material.h:274
static const std::string _interpolated_older
const ConstantTypeEnum _constant_option
Options of the constantness level of the material.
Definition: Material.h:242
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
virtual const dof_id_type & getElementIDNeighborByName(const std::string &id_parameter_name) const override
Directly calling this function is not needed for materials because the same material has three copies...
Definition: Material.h:82
MaterialDataType
MaterialData types.
Definition: MooseTypes.h:740
virtual const dof_id_type & getElementIDByName(const std::string &id_parameter_name) const override
Gets an element integer for the proper current element with the element integer name Note: This overr...
Definition: Material.h:72
virtual void computeProperties() override
Performs the quadrature point loop, calling computeQpProperties.
Definition: Material.C:110
bool _ghostable
Whether this material can be computed in a ghosted context.
Definition: Material.h:251
const MooseArray< Real > & _JxW
Definition: Material.h:232
const MaterialProperty< T > & getMaterialPropertyByName(const std::string &prop_name, const unsigned int state=0)
Definition: Material.h:130
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool ghostable() const override final
Whether this material supports ghosted computations.
Definition: Material.h:212
const ADMaterialProperty< T > & getADMaterialProperty(const std::string &name)
Definition: Material.h:106
virtual const dof_id_type & getElementIDNeighborByName(const std::string &id_name) const
Gets a neighbor element integer with the element integer name.
virtual void subdomainSetup() override
Subdomain setup evaluating material properties when required.
Definition: Material.C:85
MaterialPropertyName getMaterialPropertyName(const std::string &name) const
virtual bool isBoundaryMaterial() const override
Returns true of the MaterialData type is not associated with volume data.
Definition: Material.h:202
MaterialData & _material_data
The material data class that stores properties.
Wrapper around a material property pointer.
bool _bnd
Definition: Material.h:226
virtual const dof_id_type & getElementIDNeighbor(const std::string &id_parameter_name, unsigned int comp=0) const override
Directly calling this function is not needed for materials because the same material has three copies...
Definition: Material.h:58
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
std::set< std::string > _requested_props
Set of properties accessed via get method.
Definition: MaterialBase.h:348
CreateMooseEnumClass(ConstantTypeEnum, NONE, ELEMENT, SUBDOMAIN)
virtual void checkMaterialProperty(const std::string &name, const unsigned int state) override
A helper method for checking material properties This method was required to avoid a compiler problem...
Definition: Material.C:183
static InputParameters validParams()
Definition: Material.C:14
MaterialBase & getMaterial(const std::string &name)
Retrieve the discrete material with a given parameter key named "name".
Definition: Material.h:155
void checkExecutionStage()
Check and throw an error if the execution has progressed past the construction stage.
Definition: MaterialBase.C:291
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
virtual const dof_id_type & getElementID(const std::string &id_parameter_name, unsigned int comp=0) const override
Gets an element integer for the proper current element with a parameter of the object derived from th...
Definition: Material.h:48
const MaterialProperty< T > & getMaterialPropertyOlderByName(const std::string &prop_name)
Definition: Material.h:146
virtual const dof_id_type & getElementIDByName(const std::string &id_name) const
Gets an element integer with the element integer name.
bool _neighbor
Definition: Material.h:227
const MaterialPropertyName _get_suffix
const MaterialProperty< T > & getMaterialPropertyOldByName(const std::string &prop_name)
Definition: Material.h:141
MaterialBase & getMaterialByName(const std::string &name, bool no_warn=false, bool no_dep=false)
Retrieve the discrete material named "name".
Definition: Material.C:156
Materials compute MaterialProperties.
Definition: Material.h:35
const ADMaterialProperty< T > & getADMaterialPropertyByName(const std::string &prop_name)
Definition: Material.h:136
Interface for objects that needs coupling capabilities.
Definition: Coupleable.h:52
An interface for accessing Materials.
virtual Moose::MaterialDataType materialDataType() override
Definition: Material.h:222
const GenericMaterialProperty< T, is_ad > & getGenericZeroMaterialPropertyByName(const std::string &prop_name)
Definition: MaterialBase.h:476
const unsigned int & _current_side
current side of the current element
Definition: Material.h:239
const GenericMaterialProperty< T, is_ad > & getGenericZeroMaterialProperty()
Return a constant zero anonymous material property.
Definition: MaterialBase.h:506
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:281
const bool _use_interpolated_state
Use the interpolated state set up through the ProjectedStatefulMaterialStorageAction.
const MaterialProperty< T > & getMaterialPropertyOlder(const std::string &name)
Definition: Material.h:116
Proxy for accessing MaterialPropertyStorage.
Definition: MaterialData.h:37
const OptionalMaterialProperty< T > & getOptionalMaterialProperty(const std::string &name, const unsigned int state=0)
Definition: Material.h:176
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:203
virtual const dof_id_type & getElementID(const std::string &id_parameter_name, unsigned int comp=0) const
Gets an element integer with a parameter of the object derived from this interface.
std::vector< std::unique_ptr< OptionalMaterialPropertyProxyBase< Material > > > _optional_property_proxies
optional material properties
Definition: Material.h:255
const MaterialProperty< T > & getZeroMaterialProperty(Ts... args)
for backwards compatibility
Definition: MaterialBase.h:177
const SubdomainID & _current_subdomain_id
Definition: Material.h:236
virtual void resolveOptionalProperties() override
resolve all optional properties
Definition: Material.C:176
const Moose::MaterialDataType _material_data_type
The type of data.
virtual const QBase & qRule() const override
Definition: Material.h:224
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:62
const Elem *const & _current_elem
Definition: Material.h:234
virtual MaterialData & materialData() override
Definition: Material.h:221
Material(const InputParameters &parameters)
Definition: Material.C:31
uint8_t dof_id_type
const GenericMaterialProperty< T, is_ad > & getGenericMaterialProperty(const std::string &name, const unsigned int state=0)
Retrieve the property through a given input parameter key with a fallback to getting it by name...
Definition: Material.h:260
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const override
Retrieve the set of material properties that this object depends on.
Definition: Material.h:204