17 #include "libmesh/elem.h" 44 void resize(
unsigned int n_qpoints);
53 void copy(
const Elem & elem_to,
const Elem & elem_from,
unsigned int side);
56 void swap(
const Elem & elem,
unsigned int side = 0);
65 template <
typename MatContainer>
66 void reinit(
const MatContainer & mats);
69 void reset(
const std::vector<std::shared_ptr<MaterialBase>> & mats);
72 void swapBack(
const Elem & elem,
unsigned int side = 0);
84 template <
typename T,
bool is_ad>
91 return haveGenericProperty<T, false>(prop_name);
98 return haveGenericProperty<T, true>(prop_name);
110 template <
typename T,
bool is_ad = false>
112 const unsigned int state,
115 return getPropertyHelper<T, is_ad, false>(prop_name, state, requestor);
125 template <
typename T,
bool is_ad>
129 return getPropertyHelper<T, is_ad, true>(prop_name, 0, requestor);
166 bool hasProperty(
const std::string & prop_name)
const;
175 unsigned int getPropertyId(
const std::string & prop_name)
const;
207 std::array<MaterialProperties, max_state + 1>
_props;
210 const std::type_info & type,
211 const unsigned int state,
214 template <
typename T,
bool is_ad,
bool declare>
216 const unsigned int state,
240 mooseAssert(
_props.size() > state,
"Invalid state");
247 mooseAssert(
_props.size() > state,
"Invalid state");
251 template <
typename T,
bool is_ad>
260 if (prop_id >=
props(0).size())
267 template <
typename T,
bool is_ad,
bool declare>
270 const unsigned int state,
274 mooseAssert(state == 0,
"Cannot request/declare AD properties for states other than zero");
275 if constexpr (declare)
276 mooseAssert(state == 0,
"Cannot declare properties for states other than zero");
281 const auto size = prop_id + 1;
286 auto & entry =
props(state_i);
287 if (entry.size() < size)
288 entry.resize(size, {});
290 if (!entry.hasValue(prop_id) && (declare || state_i == state))
301 auto & base_prop =
props(state)[prop_id];
308 constexpr std::string_view action = declare ?
"declared" :
"requested";
309 constexpr
auto is_ad_to_str = [](
const bool is_ad_bool)
310 {
return std::string_view(is_ad_bool ?
"AD" :
"non-AD"); };
311 constexpr std::string_view ad_type = is_ad_to_str(is_ad);
313 std::stringstream error;
314 error <<
"The " << action <<
" " << ad_type <<
" " 315 <<
"material property '" + prop_name +
"' of type '" << MooseUtils::prettyCppType<T>()
316 <<
"'\nis already retrieved or declared as a " << is_ad_to_str(base_prop.isAD())
317 <<
" property of type '" << base_prop.type() <<
"'.";
324 template <
typename MatContainer>
328 for (
const auto & mat : mats)
329 mat->computeProperties();
const MaterialPropertyStorage & getMaterialPropertyStorage() const
Provide read-only access to the underlying MaterialPropertyStorage object.
bool isSwapped() const
Returns true if the stateful material is in a swapped state.
bool hasProperty(const std::string &prop_name) const
bool haveGenericProperty(const std::string &prop_name) const
void onlyResizeIfSmaller(bool flag)
Set _resize_only_if_smaller to perform a non-destructive resize.
const MaterialBase & castRequestorToDeclarer(const MooseObject &requestor) const
Helper for casting requestor to a MaterialBase in addPropertyHelper() (templated) ...
bool haveProperty(const std::string &prop_name) const
Returns true if the regular material property exists - defined by any material.
void swapBack(const Elem &elem, unsigned int side=0)
material properties for given element (and possible side)
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
void reinit(const MatContainer &mats)
Reinit material properties for given element (and possible side)
bool _resize_only_if_smaller
Use non-destructive resize of material data (calling resize() will not reduce size).
std::array< MaterialProperties, max_state+1 > _props
The underlying property data.
Stores the stateful material properties computed by materials.
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
bool isOnlyResizeIfSmaller() const
Check value of _resize_only_if_smaller.
void eraseProperty(const Elem *elem)
Remove the property storage and element pointer from MaterialPropertyStorage data structures Use this...
MaterialData(MaterialPropertyStorage &storage, const THREAD_ID tid)
unsigned int _n_qpoints
Number of quadrature points.
unsigned int addPropertyHelper(const std::string &prop_name, const std::type_info &type, const unsigned int state, const MaterialBase *const declarer)
const T * queryValue(const std::size_t i) const
Every object that can be built by the factory should be derived from this class.
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
void copy(const Elem &elem_to, const Elem &elem_from, unsigned int side)
copy material properties from one element to another
Abstract definition of a property value.
const MaterialProperties & props(const unsigned int state=0) const
static constexpr unsigned int max_state
The max time state supported (2 = older)
Materials compute MaterialProperties.
unsigned int getMaxStateRequested(const unsigned int prop_id) const
maximum state id requested for a property
MaterialPropertyStorage & getMaterialPropertyStorageForXFEM(const XFEMKey)
Provide write-only access to the underlying MaterialPropertyStorage object JUST FOR XFEM...
bool haveADProperty(const std::string &prop_name) const
Returns true if the AD material property exists - defined by any material.
void reset(const std::vector< std::shared_ptr< MaterialBase >> &mats)
Calls the reset method of Materials to ensure that they are in a proper state.
void swap(const Elem &elem, unsigned int side=0)
material properties for given element (and possible side)
GenericMaterialProperty< T, is_ad > & getProperty(const std::string &prop_name, const unsigned int state, const MooseObject &requestor)
Retrieves a material property.
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
IntRange< T > make_range(T beg, T end)
static void mooseErrorHelper(const MooseObject &object, const std::string_view &error)
unsigned int nQPoints() const
Returns the number of quadrature points the material properties support/hold.
Proxy for accessing MaterialPropertyStorage.
Key that provides access to only the XFEM class.
MaterialBases compute MaterialProperties.
GenericMaterialProperty< T, is_ad > & declareProperty(const std::string &prop_name, const MooseObject &requestor)
Declares a material property.
void resize(unsigned int n_qpoints)
Resize the data to hold properties for n_qpoints quadrature points.
GenericMaterialProperty< T, is_ad > & getPropertyHelper(const std::string &prop_name, const unsigned int state, const MooseObject &requestor)
const THREAD_ID _tid
The thread id.