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 "MaterialBase.h"
14 #include "Coupleable.h"
16 #include "FEProblemBase.h"
17 
18 #include <string>
19 
20 #define usingMaterialMembers \
21  usingMaterialBaseMembers; \
22  usingCoupleableMembers; \
23  usingMaterialPropertyInterfaceMembers; \
24  using Material::_q_point; \
25  using Material::_qrule; \
26  using Material::_JxW; \
27  using Material::_current_elem; \
28  using Material::_current_subdomain_id; \
29  using Material::_current_side
30 
35 {
36 public:
38 
40 
47  virtual const dof_id_type & getElementID(const std::string & id_parameter_name,
48  unsigned int comp = 0) const override
49  {
50  return _neighbor ? ElementIDInterface::getElementIDNeighbor(id_parameter_name, comp)
51  : ElementIDInterface::getElementID(id_parameter_name, comp);
52  }
57  virtual const dof_id_type & getElementIDNeighbor(const std::string & id_parameter_name,
58  unsigned int comp = 0) const override
59  {
60  mooseError("Directly calling 'getElementIDNeighbor' is not allowed for materials. Please call "
61  "'getElementID' instead");
62  return ElementIDInterface::getElementIDNeighbor(id_parameter_name, comp);
63  }
64 
70  virtual const dof_id_type &
71  getElementIDByName(const std::string & id_parameter_name) const override
72  {
74  : ElementIDInterface::getElementIDByName(id_parameter_name);
75  }
80  virtual const dof_id_type &
81  getElementIDNeighborByName(const std::string & id_parameter_name) const override
82  {
83  mooseError("Directly calling 'getElementIDNeighborByName' is not allowed for materials. Please "
84  "call 'getElementIDByName' instead");
85  return ElementIDInterface::getElementIDNeighborByName(id_parameter_name);
86  }
87 
88  virtual void computeProperties() override;
89 
91 
95  template <typename T, bool is_ad>
97  getGenericMaterialProperty(const std::string & name, const unsigned int state = 0);
98  template <typename T>
99  const MaterialProperty<T> & getMaterialProperty(const std::string & name,
100  const unsigned int state = 0)
101  {
102  return getGenericMaterialProperty<T, false>(name, state);
103  }
104  template <typename T>
105  const ADMaterialProperty<T> & getADMaterialProperty(const std::string & name)
106  {
107  return getGenericMaterialProperty<T, true>(name, 0);
108  }
109  template <typename T>
110  const MaterialProperty<T> & getMaterialPropertyOld(const std::string & name)
111  {
112  return getGenericMaterialProperty<T, false>(name, 1);
113  }
114  template <typename T>
115  const MaterialProperty<T> & getMaterialPropertyOlder(const std::string & name)
116  {
117  return getGenericMaterialProperty<T, false>(name, 2);
118  }
120 
122 
125  template <typename T, bool is_ad>
127  getGenericMaterialPropertyByName(const std::string & name, const unsigned int state = 0);
128  template <typename T>
129  const MaterialProperty<T> & getMaterialPropertyByName(const std::string & prop_name,
130  const unsigned int state = 0)
131  {
132  return getGenericMaterialPropertyByName<T, false>(prop_name, state);
133  }
134  template <typename T>
135  const ADMaterialProperty<T> & getADMaterialPropertyByName(const std::string & prop_name)
136  {
137  return getGenericMaterialPropertyByName<T, true>(prop_name, 0);
138  }
139  template <typename T>
140  const MaterialProperty<T> & getMaterialPropertyOldByName(const std::string & prop_name)
141  {
142  return getGenericMaterialPropertyByName<T, false>(prop_name, 1);
143  }
144  template <typename T>
145  const MaterialProperty<T> & getMaterialPropertyOlderByName(const std::string & prop_name)
146  {
147  return getGenericMaterialPropertyByName<T, false>(prop_name, 2);
148  }
150 
154  MaterialBase & getMaterial(const std::string & name)
155  {
156  return getMaterialByName(parameters().get<MaterialName>(name));
157  }
158 
167  MaterialBase &
168  getMaterialByName(const std::string & name, bool no_warn = false, bool no_dep = false);
169 
171  template <typename T, bool is_ad>
173  getGenericOptionalMaterialProperty(const std::string & name, const unsigned int state = 0);
174  template <typename T>
176  const unsigned int state = 0)
177  {
178  return getGenericOptionalMaterialProperty<T, false>(name, state);
179  }
180  template <typename T>
182  {
183  return getGenericOptionalMaterialProperty<T, true>(name, 0);
184  }
185  template <typename T>
187  {
188  return getGenericOptionalMaterialProperty<T, false>(name, 1);
189  }
190  template <typename T>
192  {
193  return getGenericOptionalMaterialProperty<T, false>(name, 2);
194  }
196 
200 
201  virtual bool isBoundaryMaterial() const override { return _bnd; }
202 
203  virtual const std::unordered_set<unsigned int> & getMatPropDependencies() const override
204  {
206  }
207  virtual void subdomainSetup() override;
208 
209  enum class ConstantTypeEnum
210  {
211  NONE,
212  ELEMENT,
213  SUBDOMAIN
214  };
215 
216  bool ghostable() const override final { return _ghostable; }
217 
219  virtual void resolveOptionalProperties() override;
220 
221 protected:
222  virtual void checkMaterialProperty(const std::string & name, const unsigned int state) override;
223 
224  virtual const MaterialData & materialData() const override { return _material_data; }
225  virtual MaterialData & materialData() override { return _material_data; }
226 
227  virtual const QBase & qRule() const override { return *_qrule; }
228 
229  bool _bnd;
230  bool _neighbor;
231 
233  const QBase * const & _qrule;
234 
236 
237  const Elem * const & _current_elem;
238 
240 
242  const unsigned int & _current_side;
243 
246 
247 private:
249 
255 
257  std::vector<std::unique_ptr<OptionalMaterialPropertyProxyBase<Material>>>
259 };
260 
261 template <typename T, bool is_ad>
263 Material::getGenericMaterialProperty(const std::string & name, const unsigned int state)
264 {
265  // Check if the supplied parameter is a valid input parameter key
266  const auto prop_name = getMaterialPropertyName(name);
267 
268  // Check if it's just a constant.
269  if (const auto * default_property = defaultGenericMaterialProperty<T, is_ad>(prop_name))
270  return *default_property;
271 
272  return getGenericMaterialPropertyByName<T, is_ad>(prop_name, state);
273 }
274 
275 template <typename T, bool is_ad>
277 Material::getGenericMaterialPropertyByName(const std::string & prop_name_in,
278  const unsigned int state)
279 {
281  {
282  if (state == 1)
283  return getGenericMaterialPropertyByName<T, is_ad>(prop_name_in + _interpolated_old, 0);
284  if (state == 2)
285  return getGenericMaterialPropertyByName<T, is_ad>(prop_name_in + _interpolated_older, 0);
286  }
287 
289 
290  // The property may not exist yet, so declare it (declare/getMaterialProperty are referencing the
291  // same memory)
292  const auto prop_name =
293  _get_suffix.empty()
294  ? prop_name_in
295  : MooseUtils::join(std::vector<std::string>({prop_name_in, _get_suffix}), "_");
296 
297  if (state == 0)
298  _requested_props.insert(prop_name);
299 
300  // Do this before so that we register the ID first
301  auto & prop =
302  MaterialPropertyInterface::getGenericMaterialPropertyByName<T, is_ad>(prop_name_in, state);
303 
304  registerPropName(prop_name, true, state);
305 
306  return prop;
307 }
308 
309 template <typename T, bool is_ad>
311 Material::getGenericOptionalMaterialProperty(const std::string & name, const unsigned int state)
312 {
313  auto proxy = std::make_unique<OptionalMaterialPropertyProxy<Material, T, is_ad>>(name, state);
314  auto & optional_property = proxy->value();
315  _optional_property_proxies.push_back(std::move(proxy));
316  return optional_property;
317 }
const MooseArray< Point > & _q_point
Definition: Material.h:232
const OptionalADMaterialProperty< T > & getOptionalADMaterialProperty(const std::string &name)
Definition: Material.h:181
const OptionalMaterialProperty< T > & getOptionalMaterialPropertyOlder(const std::string &name)
Definition: Material.h:191
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name)
Definition: Material.h:110
static const std::string _interpolated_old
name suffixes for interpolated old and older properties
const QBase *const & _qrule
Definition: Material.h:233
ConstantTypeEnum computeConstantOption()
Definition: Material.C:143
const OptionalMaterialProperty< T > & getOptionalMaterialPropertyOld(const std::string &name)
Definition: Material.h:186
const MaterialProperty< T > & getMaterialProperty(const std::string &name, const unsigned int state=0)
Definition: Material.h:99
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:224
const GenericOptionalMaterialProperty< T, is_ad > & getGenericOptionalMaterialProperty(const std::string &name, const unsigned int state=0)
Optional material property getters.
Definition: Material.h:311
const GenericMaterialProperty< T, is_ad > & getGenericMaterialPropertyByName(const std::string &name, const unsigned int state=0)
Retrieve the property named "name".
Definition: Material.h:277
static const std::string _interpolated_older
const ConstantTypeEnum _constant_option
Options of the constantness level of the material.
Definition: Material.h:245
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:81
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:71
virtual void computeProperties() override
Performs the quadrature point loop, calling computeQpProperties.
Definition: Material.C:111
bool _ghostable
Whether this material can be computed in a ghosted context.
Definition: Material.h:254
const MooseArray< Real > & _JxW
Definition: Material.h:235
const MaterialProperty< T > & getMaterialPropertyByName(const std::string &prop_name, const unsigned int state=0)
Definition: Material.h:129
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:216
const ADMaterialProperty< T > & getADMaterialProperty(const std::string &name)
Definition: Material.h:105
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:86
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:201
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
MaterialData & _material_data
The material data class that stores properties.
Wrapper around a material property pointer.
bool _bnd
Definition: Material.h:229
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:57
std::set< std::string > _requested_props
Set of properties accessed via get method.
Definition: MaterialBase.h:330
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:184
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:154
void checkExecutionStage()
Check and throw an error if the execution has progressed past the construction stage.
Definition: MaterialBase.C:243
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
ConstantTypeEnum
Definition: Material.h:209
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:47
const MaterialProperty< T > & getMaterialPropertyOlderByName(const std::string &prop_name)
Definition: Material.h:145
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:230
const MaterialPropertyName _get_suffix
const MaterialProperty< T > & getMaterialPropertyOldByName(const std::string &prop_name)
Definition: Material.h:140
MaterialBase & getMaterialByName(const std::string &name, bool no_warn=false, bool no_dep=false)
Retrieve the discrete material named "name".
Definition: Material.C:157
Materials compute MaterialProperties.
Definition: Material.h:34
const ADMaterialProperty< T > & getADMaterialPropertyByName(const std::string &prop_name)
Definition: Material.h:135
Interface for objects that needs coupling capabilities.
Definition: Coupleable.h:44
An interface for accessing Materials.
const GenericMaterialProperty< T, is_ad > & getGenericZeroMaterialPropertyByName(const std::string &prop_name)
Definition: MaterialBase.h:425
const unsigned int & _current_side
current side of the current element
Definition: Material.h:242
const GenericMaterialProperty< T, is_ad > & getGenericZeroMaterialProperty()
Return a constant zero anonymous material property.
Definition: MaterialBase.h:455
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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:115
const InputParameters & parameters() const
Get the parameters of the object.
Proxy for accessing MaterialPropertyStorage.
Definition: MaterialData.h:33
const OptionalMaterialProperty< T > & getOptionalMaterialProperty(const std::string &name, const unsigned int state=0)
Definition: Material.h:175
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:155
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:258
const MaterialProperty< T > & getZeroMaterialProperty(Ts... args)
for backwards compatibility
Definition: MaterialBase.h:169
const SubdomainID & _current_subdomain_id
Definition: Material.h:239
virtual void resolveOptionalProperties() override
resolve all optional properties
Definition: Material.C:177
virtual const QBase & qRule() const override
Definition: Material.h:227
const std::unordered_set< unsigned int > & getMatPropDependencies() const
Retrieve the set of material properties that this object depends on.
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:60
std::string join(const T &strings, const std::string &delimiter)
Python like join function for strings.
Definition: MooseUtils.h:130
const Elem *const & _current_elem
Definition: Material.h:237
virtual MaterialData & materialData() override
Definition: Material.h:225
Material(const InputParameters &parameters)
Definition: Material.C:32
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:263
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const override
Retrieve the set of material properties that this object depends on.
Definition: Material.h:203