https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
37public:
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>
107 {
108 return getGenericMaterialProperty<T, true>(name, 0);
109 }
110 template <typename T>
112 {
113 return getGenericMaterialProperty<T, false>(name, 1);
114 }
115 template <typename T>
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
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
217protected:
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;
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
244private:
245 ConstantTypeEnum computeConstantOption();
246
252
254 std::vector<std::unique_ptr<OptionalMaterialPropertyProxyBase<Material>>>
256};
257
258template <typename T, bool is_ad>
260Material::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
272template <typename T, bool is_ad>
274Material::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
306template <typename T, bool is_ad>
308Material::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}
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
Interface for objects that needs coupling capabilities.
Definition Coupleable.h:53
virtual const dof_id_type & getElementIDByName(const std::string &id_name) const
Gets an element integer with the element integer name.
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 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.
virtual const dof_id_type & getElementIDNeighborByName(const std::string &id_name) const
Gets a neighbor element integer with the element integer name.
Wrapper around a material property pointer.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
MaterialBases compute MaterialProperties.
const MaterialProperty< T > & getZeroMaterialProperty(Ts... args)
for backwards compatibility
void checkExecutionStage()
Check and throw an error if the execution has progressed past the construction stage.
const GenericMaterialProperty< T, is_ad > & getGenericZeroMaterialProperty()
Return a constant zero anonymous material property.
std::set< std::string > _requested_props
Set of properties accessed via get method.
void registerPropName(const std::string &prop_name, bool is_get, const unsigned int state)
Small helper function to call store{Subdomain,Boundary}MatPropName.
const GenericMaterialProperty< T, is_ad > & getGenericZeroMaterialPropertyByName(const std::string &prop_name)
Proxy for accessing MaterialPropertyStorage.
An interface for accessing Materials.
MaterialPropertyName getMaterialPropertyName(const std::string &name) const
static const std::string _interpolated_old
name suffixes for interpolated old and older properties
const Moose::MaterialDataType _material_data_type
The type of data.
static const std::string _interpolated_older
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const
Retrieve the set of material properties that this object depends on.
MaterialData & _material_data
The material data class that stores properties.
const bool _use_interpolated_state
Use the interpolated state set up through the ProjectedStatefulMaterialStorageAction.
const MaterialPropertyName _get_suffix
Materials compute MaterialProperties.
Definition Material.h:36
const OptionalMaterialProperty< T > & getOptionalMaterialProperty(const std::string &name, const unsigned int state=0)
Definition Material.h:176
MaterialBase & getMaterialByName(const std::string &name, bool no_warn=false, bool no_dep=false)
Retrieve the discrete material named "name".
Definition Material.C:156
virtual void computeProperties() override
Performs the quadrature point loop, calling computeQpProperties.
Definition Material.C:110
static InputParameters validParams()
Definition Material.C:14
const unsigned int & _current_side
current side of the current element
Definition Material.h:239
const ADMaterialProperty< T > & getADMaterialPropertyByName(const std::string &prop_name)
Definition Material.h:136
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
virtual Moose::MaterialDataType materialDataType() override
Definition Material.h:222
const Elem *const & _current_elem
Definition Material.h:234
CreateMooseEnumClass(ConstantTypeEnum, NONE, ELEMENT, SUBDOMAIN)
const MaterialProperty< T > & getMaterialPropertyOlder(const std::string &name)
Definition Material.h:116
virtual void resolveOptionalProperties() override
resolve all optional properties
Definition Material.C:176
const OptionalMaterialProperty< T > & getOptionalMaterialPropertyOlder(const std::string &name)
Definition Material.h:192
bool _neighbor
Definition Material.h:227
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
MaterialBase & getMaterial(const std::string &name)
Retrieve the discrete material with a given parameter key named "name".
Definition Material.h:155
const ConstantTypeEnum _constant_option
Options of the constantness level of the material.
Definition Material.h:242
const SubdomainID & _current_subdomain_id
Definition Material.h:236
const GenericOptionalMaterialProperty< T, is_ad > & getGenericOptionalMaterialProperty(const std::string &name, const unsigned int state=0)
Optional material property getters.
Definition Material.h:308
ConstantTypeEnum computeConstantOption()
Definition Material.C:142
virtual const MaterialData & materialData() const override
Definition Material.h:220
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
std::vector< std::unique_ptr< OptionalMaterialPropertyProxyBase< Material > > > _optional_property_proxies
optional material properties
Definition Material.h:255
const MaterialProperty< T > & getMaterialProperty(const std::string &name, const unsigned int state=0)
Definition Material.h:100
const MaterialProperty< T > & getMaterialPropertyByName(const std::string &prop_name, const unsigned int state=0)
Definition Material.h:130
const QBase *const & _qrule
Definition Material.h:230
virtual MaterialData & materialData() override
Definition Material.h:221
bool ghostable() const override final
Whether this material supports ghosted computations.
Definition Material.h:212
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name)
Definition Material.h:111
const ADMaterialProperty< T > & getADMaterialProperty(const std::string &name)
Definition Material.h:106
const OptionalMaterialProperty< T > & getOptionalMaterialPropertyOld(const std::string &name)
Definition Material.h:187
const OptionalADMaterialProperty< T > & getOptionalADMaterialProperty(const std::string &name)
Definition Material.h:182
const MaterialProperty< T > & getMaterialPropertyOldByName(const std::string &prop_name)
Definition Material.h:141
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 subdomainSetup() override
Subdomain setup evaluating material properties when required.
Definition Material.C:85
const GenericMaterialProperty< T, is_ad > & getGenericMaterialPropertyByName(const std::string &name, const unsigned int state=0)
Retrieve the property named "name".
Definition Material.h:274
const MooseArray< Real > & _JxW
Definition Material.h:232
bool _bnd
Definition Material.h:226
virtual bool isBoundaryMaterial() const override
Returns true of the MaterialData type is not associated with volume data.
Definition Material.h:202
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
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
virtual const QBase & qRule() const override
Definition Material.h:224
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
const MooseArray< Point > & _q_point
Definition Material.h:229
bool _ghostable
Whether this material can be computed in a ghosted context.
Definition Material.h:251
const MaterialProperty< T > & getMaterialPropertyOlderByName(const std::string &prop_name)
Definition Material.h:146
forward declarations
Definition MooseArray.h:18
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
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:271
MaterialDataType
MaterialData types.
Definition MooseTypes.h:746