12 #ifdef MOOSE_KOKKOS_ENABLED 21 #include "libmesh/elem.h" 48 void resize(
unsigned int n_qpoints);
57 void copy(
const Elem & elem_to,
const Elem & elem_from,
unsigned int side);
60 void swap(
const Elem & elem,
unsigned int side = 0);
69 template <
typename MatContainer>
70 void reinit(
const MatContainer & mats);
73 void reset(
const std::vector<std::shared_ptr<MaterialBase>> & mats);
76 void swapBack(
const Elem & elem,
unsigned int side = 0);
88 template <
typename T,
bool is_ad>
95 return haveGenericProperty<T, false>(prop_name);
102 return haveGenericProperty<T, true>(prop_name);
105 #ifdef MOOSE_KOKKOS_SCOPE 113 template <
typename T,
unsigned int dimension>
126 template <
typename T,
bool is_ad = false>
128 const unsigned int state,
131 return getPropertyHelper<T, is_ad, false>(prop_name, state, requestor);
141 template <
typename T,
bool is_ad>
145 return getPropertyHelper<T, is_ad, true>(prop_name, 0, requestor);
148 #ifdef MOOSE_KOKKOS_SCOPE 157 template <
typename T,
unsigned int dimension,
unsigned int state>
172 template <
typename T,
unsigned int dimension>
175 const std::vector<unsigned int> & dims,
178 const bool on_demand,
216 bool hasProperty(
const std::string & prop_name)
const;
225 unsigned int getPropertyId(
const std::string & prop_name)
const;
257 std::array<MaterialProperties, max_state + 1>
_props;
260 const std::type_info & type,
261 const unsigned int state,
264 template <
typename T,
bool is_ad,
bool declare>
266 const unsigned int state,
269 #ifdef MOOSE_KOKKOS_ENABLED 280 const std::type_info & type,
281 const unsigned int state,
282 std::shared_ptr<Moose::Kokkos::MaterialPropertyBase> shell);
298 const std::type_info & type,
300 const std::vector<unsigned int> & dims,
302 const bool on_demand,
304 std::shared_ptr<Moose::Kokkos::MaterialPropertyBase> shell);
314 const std::string & prop_name,
315 const unsigned int state = 0,
316 std::shared_ptr<Moose::Kokkos::MaterialPropertyBase> shell =
nullptr)
const;
357 mooseAssert(
_props.size() > state,
"Invalid state");
364 mooseAssert(
_props.size() > state,
"Invalid state");
368 template <
typename T,
bool is_ad>
377 if (prop_id >=
props(0).size())
384 template <
typename T,
bool is_ad,
bool declare>
387 const unsigned int state,
391 mooseAssert(state == 0,
"Cannot request/declare AD properties for states other than zero");
392 if constexpr (declare)
393 mooseAssert(state == 0,
"Cannot declare properties for states other than zero");
398 const auto size = prop_id + 1;
403 auto & entry =
props(state_i);
404 if (entry.size() < size)
405 entry.resize(size, {});
407 if (!entry.hasValue(prop_id) && (declare || state_i == state))
418 auto & base_prop =
props(state)[prop_id];
425 constexpr std::string_view action = declare ?
"declared" :
"requested";
426 constexpr
auto is_ad_to_str = [](
const bool is_ad_bool)
427 {
return std::string_view(is_ad_bool ?
"AD" :
"non-AD"); };
428 constexpr std::string_view ad_type = is_ad_to_str(is_ad);
430 std::stringstream error;
431 error <<
"The " << action <<
" " << ad_type <<
" " 432 <<
"material property '" + prop_name +
"' of type '" << MooseUtils::prettyCppType<T>()
433 <<
"'\nis already retrieved or declared as a " << is_ad_to_str(base_prop.isAD())
434 <<
" property of type '" << base_prop.type() <<
"'.";
441 template <
typename MatContainer>
445 for (
const auto & mat : mats)
446 mat->computeProperties();
449 #ifdef MOOSE_KOKKOS_SCOPE 450 template <
typename T,
unsigned int dimension>
461 template <
typename T,
unsigned int dimension,
unsigned int state>
467 for (
unsigned int s = 0; s <= state; ++s)
469 auto shell = std::make_shared<Moose::Kokkos::MaterialProperty<T, dimension>>();
476 if constexpr (state > 0)
478 Moose::Kokkos::propertyStore<T, dimension>,
479 Moose::Kokkos::propertyLoad<T, dimension>);
488 "D Kokkos material property '",
491 MooseUtils::prettyCppType<T>(),
492 "' was already declared or requested as a ",
494 "D property of type '",
501 template <
typename T,
unsigned int dimension>
504 const std::vector<unsigned int> & dims,
507 const bool on_demand,
510 auto shell = std::make_shared<Moose::Kokkos::MaterialProperty<T, dimension>>();
513 prop_name,
typeid(T), declarer, dims, bnd, on_demand, constant_option, shell);
519 "D Kokkos material property '",
522 MooseUtils::prettyCppType<T>(),
523 "' was already declared or requested as a ",
525 "D property of type '",
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.
Moose::Kokkos::MaterialProperty< T, dimension > getKokkosProperty(const std::string &prop_name)
Get a Kokkos material property.
bool hasProperty(const std::string &prop_name) const
bool haveGenericProperty(const std::string &prop_name) const
The base class for Kokkos material properties.
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)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
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.
std::function< void(std::istream &, void *)> PropertyLoad
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.
Moose::Kokkos::MaterialProperty< T, dimension > declareKokkosProperty(const std::string &prop_name, const std::vector< unsigned int > &dims, const MaterialBase *declarer, const bool bnd, const bool on_demand, const Moose::Kokkos::PropertyConstantOption constant_option)
Declare a Kokkos material property.
unsigned int addPropertyHelper(const std::string &prop_name, const std::type_info &type, const unsigned int state, const MaterialBase *const declarer)
Moose::Kokkos::MaterialPropertyBase & addKokkosPropertyHelper(const std::string &prop_name, const std::type_info &type, const unsigned int state, std::shared_ptr< Moose::Kokkos::MaterialPropertyBase > shell)
Helper function for adding a Kokkos material property.
const T * queryValue(const std::size_t i) const
PropertyConstantOption
Property constant options.
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
std::function< void(std::ostream &, void *)> PropertyStore
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.
Moose::Kokkos::MaterialPropertyBase & getKokkosPropertyHelper(const std::string &prop_name, const unsigned int state=0, std::shared_ptr< Moose::Kokkos::MaterialPropertyBase > shell=nullptr) const
Helper function for getting a Kokkos material property.
Moose::Kokkos::MaterialPropertyBase & declareKokkosPropertyHelper(const std::string &prop_name, const std::type_info &type, const MaterialBase *declarer, const std::vector< unsigned int > &dims, const bool bnd, const bool on_demand, const Moose::Kokkos::PropertyConstantOption constant_option, std::shared_ptr< Moose::Kokkos::MaterialPropertyBase > shell)
Helper function for declaring a Kokkos material property.
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) ...
bool haveKokkosProperty(const std::string &prop_name) const
Get whether a Kokkos material property exists.
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.
The Kokkos material property class.
void kokkosRegisterLoadStoreHelper(std::type_index type, Moose::Kokkos::PropertyStore store, Moose::Kokkos::PropertyLoad load)
Helper function to register load/store functions of a Kokkos material property to the Kokkos material...
bool haveKokkosPropertyHelper(const std::string &prop_name) const
Helper function for checking whether a Kokkos material property exists.
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.