12#ifdef MOOSE_KOKKOS_ENABLED
24#include <unordered_map>
26#define usingMaterialPropertyInterfaceMembers \
27 using MaterialPropertyInterface::_material_data_type; \
28 using MaterialPropertyInterface::_material_data
73 const std::set<SubdomainID> & block_ids,
74 const std::set<BoundaryID> & boundary_ids);
76#ifdef MOOSE_KOKKOS_ENABLED
102 template <
typename T,
bool is_ad>
104 const unsigned int state = 0)
106 return getGenericMaterialProperty<T, is_ad>(name,
_material_data, state);
108 template <
typename T>
110 const unsigned int state = 0)
112 return getGenericMaterialProperty<T, false>(name, state);
114 template <
typename T>
117 return getGenericMaterialProperty<T, true>(name, 0);
119 template <
typename T>
122 return getMaterialProperty<T>(name, 1);
124 template <
typename T>
127 return getMaterialProperty<T>(name, 2);
139 template <
typename T,
bool is_ad>
143 return getGenericMaterialPropertyByName<T, is_ad>(name,
_material_data, state);
145 template <
typename T>
147 const unsigned int state = 0)
149 return getGenericMaterialPropertyByName<T, false>(name, state);
151 template <
typename T>
154 return getGenericMaterialPropertyByName<T, true>(name, 0);
156 template <
typename T>
159 return getMaterialPropertyByName<T>(name, 1);
161 template <
typename T>
164 return getMaterialPropertyByName<T>(name, 2);
168#ifdef MOOSE_KOKKOS_SCOPE
177 template <
typename T,
unsigned int dimension = 0,
unsigned int state = 0>
187 template <
typename T,
unsigned int dimension = 0>
191 return getKokkosMaterialPropertyByName<T, dimension, 1>(prop_name);
200 template <
typename T,
unsigned int dimension = 0>
204 return getKokkosMaterialPropertyByName<T, dimension, 2>(prop_name);
214 template <
typename T,
unsigned int dimension = 0,
unsigned int state = 0>
226 template <
typename T,
unsigned int dimension = 0>
239 template <
typename T,
unsigned int dimension = 0>
249 template <
typename T,
bool is_ad>
253 template <
typename T>
255 const unsigned int state = 0)
257 return getGenericOptionalMaterialProperty<T, false>(name, state);
259 template <
typename T>
262 return getGenericOptionalMaterialProperty<T, true>(name);
265 template <
typename T>
268 return getOptionalMaterialProperty<T>(name, 1);
270 template <
typename T>
273 return getOptionalMaterialProperty<T>(name, 2);
287 template <
typename T>
288 std::pair<const MaterialProperty<T> *, std::set<SubdomainID>>
291#ifdef MOOSE_KOKKOS_SCOPE
303 template <
typename T,
unsigned int dimension = 0,
unsigned int state = 0>
304 std::pair<Moose::Kokkos::MaterialProperty<T, dimension>, std::set<SubdomainID>>
312 template <
typename T,
bool is_ad>
315 template <
typename T,
bool is_ad>
322 template <
typename T,
bool is_ad>
326 template <
typename T,
typename... Ts>
329 return getGenericZeroMaterialProperty<T, false>(args...);
380 std::unordered_map<SubdomainID, std::vector<MaterialBase *>>
389 template <
typename T>
391 template <
typename T>
393 template <
typename T>
395 template <
typename T>
397#ifdef MOOSE_KOKKOS_SCOPE
398 template <
typename T,
unsigned int dimension = 0>
400 template <
typename T,
unsigned int dimension = 0>
406 template <
typename T,
bool is_ad>
410 return hasADMaterialProperty<T>(name);
412 return hasMaterialProperty<T>(name);
414 template <
typename T,
bool is_ad>
418 return hasADMaterialPropertyByName<T>(name);
420 return hasMaterialPropertyByName<T>(name);
453 template <
typename T,
bool is_ad>
455 const std::string & name,
MaterialData & material_data,
const unsigned int state = 0);
462 template <
typename T>
465 const unsigned int state = 0)
467 return getGenericMaterialProperty<T, false>(name, material_data, state);
475 template <
typename T>
479 return getGenericMaterialProperty<T, true>(name, material_data, 0);
486 template <
typename T,
bool is_ad>
488 const MaterialPropertyName & name,
MaterialData & material_data,
const unsigned int state);
495 template <
typename T,
bool is_ad>
499 const unsigned int state);
506 template <
typename T>
509 const unsigned int state = 0)
511 return getGenericMaterialPropertyByName<T, false>(name, material_data, state);
518 template <
typename T>
522 return getGenericMaterialPropertyByName<T, true>(name, material_data, 0);
528 template <
typename T>
532 return getMaterialProperty<T>(name, material_data, 1);
539 template <
typename T>
543 return getMaterialProperty<T>(name, material_data, 2);
550 template <
typename T>
554 return getMaterialPropertyByName<T>(name, material_data, 1);
561 template <
typename T>
565 return getMaterialPropertyByName<T>(name, material_data, 2);
591#ifdef MOOSE_KOKKOS_ENABLED
609#ifdef MOOSE_KOKKOS_ENABLED
644 template <
typename T,
bool is_ad>
647 template <
typename T>
650 return defaultGenericMaterialProperty<T, false>(name);
652 template <
typename T>
655 return defaultGenericMaterialProperty<T, true>(name);
719 std::vector<std::unique_ptr<OptionalMaterialPropertyProxyBase<MaterialPropertyInterface>>>
723template <
class M,
typename T,
bool is_ad>
734 if (mpi.template hasGenericMaterialProperty<T, is_ad>(this->_name))
738 mooseError(
"Non-current (state > 0) material properties are not available as AD");
740 _value.set(&mpi.template getGenericMaterialProperty<T, is_ad>(this->_name, this->_state));
748template <
typename T,
bool is_ad>
752 if constexpr (std::is_same_v<T, Real> || std::is_same_v<T, RealVectorValue>)
754 std::istringstream ss(name);
758 if (ss >> real_value && ss.eof())
765 auto & T_property =
static_cast<prop_type &
>(*property);
767 T_property.resize(nqp);
768 for (
const auto qp : make_range(nqp))
769 T_property[qp] = real_value;
779std::pair<const MaterialProperty<T> *, std::set<SubdomainID>>
783 mooseError(
"getBlockMaterialProperty must be called by a block restrictable object");
786 ?
static_cast<const std::string &
>(name_in)
787 : MooseUtils::join(std::vector<std::string>({name_in,
_get_suffix}),
"_");
789 using pair_type = std::pair<const MaterialProperty<T> *, std::set<SubdomainID>>;
791 if (!hasMaterialPropertyByName<T>(name))
792 return pair_type(
nullptr, {});
797 auto prop_blocks_pair = pair_type(&prop, std::move(
blocks));
804 return prop_blocks_pair;
813 return hasMaterialPropertyByName<T>(prop_name);
822 : MooseUtils::join(std::vector<std::string>({name_in,
_get_suffix}),
"_");
826template <
typename T,
bool is_ad>
831 return getGenericZeroMaterialPropertyByName<T, is_ad>(prop_name);
834template <
typename T,
bool is_ad>
839 if (hasGenericMaterialPropertyByName<T, is_ad>(prop_name))
840 return getGenericMaterialPropertyByName<T, is_ad>(prop_name);
842 return getGenericZeroMaterialProperty<T, is_ad>();
845template <
typename T,
bool is_ad>
855 if (nqp > zero.size())
859 for (
unsigned int qp = 0; qp < nqp; ++qp)
871 return hasADMaterialPropertyByName<T>(prop_name);
880 : MooseUtils::join(std::vector<std::string>({name_in,
_get_suffix}),
"_");
884template <
typename T,
bool is_ad>
887 const unsigned int state)
889 auto proxy = std::make_unique<OptionalMaterialPropertyProxy<MaterialPropertyInterface, T, is_ad>>(
891 auto & optional_property = proxy->value();
893 return optional_property;
896template <
typename T,
bool is_ad>
899 const MaterialPropertyName & prop_name,
MaterialData & material_data,
const unsigned int state)
902 if (
const auto * default_property = defaultGenericMaterialProperty<T, is_ad>(prop_name))
905 return *default_property;
909 mooseError(
"Stateful material properties not allowed for this object."
914 "\" was requested.");
916 return this->getGenericMaterialPropertyByName<T, is_ad>(prop_name, material_data, state);
919template <
typename T,
bool is_ad>
923 const unsigned int state)
928 return getPossiblyConstantGenericMaterialPropertyByName<T, is_ad>(
929 prop_name, material_data, state);
932template <
typename T,
bool is_ad>
936 const unsigned int state)
938#ifdef MOOSE_KOKKOS_ENABLED
941 "Attempted to retrieve a standard MOOSE material property from a Kokkos object.");
947 return getGenericMaterialPropertyByName<T, is_ad>(
950 return getGenericMaterialPropertyByName<T, is_ad>(
955 ?
static_cast<const std::string &
>(name_in)
956 : MooseUtils::join(std::vector<std::string>({name_in,
_get_suffix}),
"_");
979#ifdef MOOSE_KOKKOS_SCOPE
980template <
typename T,
unsigned int dimension>
986 return hasKokkosMaterialPropertyByName<T, dimension>(prop_name);
989template <
typename T,
unsigned int dimension>
995 : MooseUtils::join(std::vector<std::string>({name_in,
_get_suffix}),
"_");
999template <
typename T,
unsigned int dimension,
unsigned int state>
1005 "Attempted to retrieve a Kokkos material property from a standard MOOSE object.");
1007 if constexpr (std::is_same_v<T, Real>)
1009 std::istringstream ss(prop_name_in);
1013 if (ss >> value && ss.eof())
1017 const auto prop_name =
1019 ?
static_cast<const std::string &
>(prop_name_in)
1020 : MooseUtils::join(std::vector<std::string>({prop_name_in,
_get_suffix}),
"_");
1037 if constexpr (state == 0)
1045template <
typename T,
unsigned int dimension,
unsigned int state>
1046std::pair<Moose::Kokkos::MaterialProperty<T, dimension>, std::set<SubdomainID>>
1051 "Attempted to retrieve a Kokkos material property from a standard MOOSE object.");
1054 mooseError(
"getKokkosBlockMaterialProperty must be called by a block restrictable object");
1057 ?
static_cast<const std::string &
>(name_in)
1058 : MooseUtils::join(std::vector<std::string>({name_in,
_get_suffix}),
"_");
1060 using pair_type = std::pair<Moose::Kokkos::MaterialProperty<T, dimension>, std::set<SubdomainID>>;
1062 if (!hasKokkosMaterialPropertyByName<T, dimension>(name))
1073 auto prop_blocks_pair = pair_type(prop, std::move(
blocks));
1078 if constexpr (state == 0)
1083 return prop_blocks_pair;
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Wrapper around a material property pointer.
MaterialBases compute MaterialProperties.
Proxy for accessing MaterialPropertyStorage.
bool haveProperty(const std::string &prop_name) const
Returns true if the regular material property exists - defined by any material.
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
bool haveKokkosProperty(const std::string &prop_name) const
Get whether a Kokkos material property exists.
bool haveADProperty(const std::string &prop_name) const
Returns true if the AD material property exists - defined by any material.
Moose::Kokkos::MaterialProperty< T, dimension > getKokkosProperty(const std::string &prop_name)
Get a Kokkos material property.
GenericMaterialProperty< T, is_ad > & getProperty(const std::string &prop_name, const unsigned int state, const MooseObject &requestor)
Retrieves a material property.
An interface for accessing Materials.
const MaterialProperty< T > & getMaterialPropertyOlder(const std::string &name)
const MaterialProperty< T > & getMaterialProperty(const std::string &name, MaterialData &material_data, const unsigned int state=0)
Retrieve the property named "name" for the specified material_data.
const ADMaterialProperty< T > * defaultADMaterialProperty(const std::string &name)
const std::set< BoundaryID > & _mi_boundary_ids
Storage for the boundary ids created by BoundaryRestrictable.
bool hasMaterialPropertyByName(const std::string &name)
bool hasADMaterialProperty(const std::string &name)
bool _get_material_property_called
Initialized to false.
void statefulPropertiesAllowed(bool)
Derived classes can declare whether or not they work with stateful material properties.
const MaterialProperty< T > & getMaterialPropertyByName(const MaterialPropertyName &name, const unsigned int state=0)
bool hasGenericMaterialProperty(const std::string &name)
generic hasMaterialProperty helper
const OptionalMaterialProperty< T > & getOptionalMaterialPropertyOld(const std::string &name)
const bool _mi_boundary_restricted
BoundaryRestricted flag.
const THREAD_ID _mi_tid
Current threaded it.
bool _stateful_allowed
True by default.
const MaterialProperty< T > & getMaterialPropertyOlderByName(const MaterialPropertyName &name)
Moose::Kokkos::MaterialProperty< T, dimension > getKokkosMaterialPropertyByName(const std::string &prop_name_in)
Get a Kokkos material property by property name for any state.
std::vector< BoundaryName > getMaterialPropertyBoundaryNames(const std::string &name)
Retrieve the boundary namess that the material property is defined.
const MaterialProperty< T > & getMaterialPropertyOldByName(const MaterialPropertyName &name)
Moose::Kokkos::MaterialProperty< T, dimension > getKokkosMaterialPropertyOlderByName(const std::string &prop_name)
Get an older Kokkos material property by property name.
bool hasADMaterialPropertyByName(const std::string &name)
std::vector< std::unique_ptr< OptionalMaterialPropertyProxyBase< MaterialPropertyInterface > > > _optional_property_proxies
optional material properties
const MaterialProperty< T > & getMaterialProperty(const std::string &name, const unsigned int state=0)
std::vector< SubdomainName > getMaterialPropertyBlockNames(const std::string &name)
Retrieve the block names that the material property is defined.
MaterialPropertyName getMaterialPropertyName(const std::string &name) const
MaterialBase & getMaterial(const std::string &name)
Return a MaterialBase reference - usable for computing directly.
const ADMaterialProperty< T > & getADMaterialPropertyByName(const MaterialPropertyName &name, MaterialData &material_data)
Retrieve the AD property named "name" without any deduction for the specified \q material_data.
MaterialBase & getMaterialByName(const std::string &name, bool no_warn=false)
const GenericMaterialProperty< T, is_ad > * defaultGenericMaterialProperty(const std::string &name)
static const std::string _interpolated_old
name suffixes for interpolated old and older properties
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name, MaterialData &material_data)
Retrieve the old property deduced from the name name for the specified material_data.
virtual void checkMaterialProperty(const std::string &name, const unsigned int state)
A helper method for checking material properties This method was required to avoid a compiler problem...
Moose::Kokkos::MaterialProperty< T, dimension > getKokkosMaterialPropertyOldByName(const std::string &prop_name)
Get an old Kokkos material property by property name.
const Moose::MaterialDataType _material_data_type
The type of data.
std::set< SubdomainID > getMaterialPropertyBlocks(const std::string &name)
Retrieve the block ids that the material property is defined.
static const std::string _interpolated_older
const std::set< SubdomainID > & _mi_block_ids
Storage for the block ids created by BlockRestrictable.
const bool _is_kokkos_object
Whether the MOOSE object is a Kokkos object.
const ADMaterialProperty< T > & getADMaterialPropertyByName(const MaterialPropertyName &name)
void markMatPropRequested(const std::string &)
A proxy method for _mi_feproblem.markMatPropRequested(name)
const GenericMaterialProperty< T, is_ad > & getGenericZeroMaterialPropertyByName(const std::string &prop_name)
const GenericMaterialProperty< T, is_ad > & getPossiblyConstantGenericMaterialPropertyByName(const MaterialPropertyName &prop_name, MaterialData &material_data, const unsigned int state)
Retrieve the generic property named "prop_name" without any deduction for the specified material_data...
FEProblemBase & _mi_feproblem
Reference to the FEProblemBase class.
const GenericMaterialProperty< T, is_ad > & getGenericMaterialPropertyByName(const MaterialPropertyName &name, const unsigned int state=0)
Retrieve reference to material property or its old or older value The name required by this method is...
std::unordered_set< unsigned int > _material_property_dependencies
The set of material properties (as given by their IDs) that this object depends on.
std::vector< std::unique_ptr< PropertyValue > > _default_properties
Storage vector for default properties.
std::unordered_map< SubdomainID, std::vector< MaterialBase * > > buildRequiredMaterials(bool allow_stateful=true)
get a map of MaterialBase pointers for all material objects that this object depends on for each bloc...
void checkBlockAndBoundaryCompatibility(std::shared_ptr< MaterialBase > discrete)
Check if block and boundary restrictions of a given material are compatible with the current material...
const OptionalADMaterialProperty< T > & getOptionalADMaterialProperty(const std::string &name)
const OptionalMaterialProperty< T > & getOptionalMaterialPropertyOlder(const std::string &name)
static constexpr PropertyValue::id_type zero_property_id
The material property ID for a zero property.
std::pair< Moose::Kokkos::MaterialProperty< T, dimension >, std::set< SubdomainID > > getKokkosBlockMaterialProperty(const MaterialPropertyName &name)
Retrieve a Kokkos material property with the mesh blocks where it is defined NOTE: This is not a drop...
unsigned int getMaxQps() const
bool hasKokkosMaterialProperty(const std::string &name)
const ADMaterialProperty< T > & getADMaterialProperty(const std::string &name)
virtual bool getMaterialPropertyCalled() const
Returns true if getMaterialProperty() has been called, false otherwise.
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const
Retrieve the set of material properties that this object depends on.
bool hasMaterialProperty(const std::string &name)
Check if the material property exists.
const InputParameters & _mi_params
Parameters of the object with this interface.
SubProblem & _mi_subproblem
Reference to the subproblem.
const MooseObjectName _mi_moose_object_name
The "complete" name of the object that this interface belongs for material property output.
const GenericMaterialProperty< T, is_ad > & getGenericZeroMaterialProperty()
Return a constant zero anonymous material property.
MaterialData & _material_data
The material data class that stores properties.
bool hasGenericMaterialPropertyByName(const std::string &name)
Moose::MaterialDataType getMaterialDataType(const std::set< BoundaryID > &boundary_ids) const
const ADMaterialProperty< T > & getADMaterialProperty(const std::string &name, MaterialData &material_data)
Retrieve the AD property named "name" for the specified material_data.
const MaterialProperty< T > & getMaterialPropertyOldByName(const MaterialPropertyName &name, MaterialData &material_data)
Retrieve the old property named name without any deduction for the specified material_data.
static InputParameters validParams()
const MaterialProperty< T > & getMaterialPropertyOld(const std::string &name)
Moose::Kokkos::MaterialProperty< T, dimension > getKokkosMaterialPropertyOlder(const std::string &name)
Get an older Kokkos material property.
const MaterialProperty< T > & getMaterialPropertyByName(const MaterialPropertyName &name, MaterialData &material_data, const unsigned int state=0)
Retrieve the property named "name" without any deduction for the specified material_data.
const MooseObject & _mi_moose_object
The MooseObject creating the MaterialPropertyInterface.
const bool _use_interpolated_state
Use the interpolated state set up through the ProjectedStatefulMaterialStorageAction.
void addConsumedPropertyName(const MooseObjectName &obj_name, const std::string &prop_name)
const MaterialPropertyName _get_suffix
const GenericMaterialProperty< T, is_ad > & getGenericMaterialProperty(const std::string &name, const unsigned int state=0)
Retrieve reference to material property or one of it's old or older values.
const MaterialProperty< T > & getMaterialPropertyOlder(const std::string &name, MaterialData &material_data)
Retrieve the older property deduced from the name name for the specified material_data.
std::set< BoundaryID > getMaterialPropertyBoundaryIDs(const std::string &name)
Retrieve the boundary ids that the material property is defined.
Moose::Kokkos::MaterialProperty< T, dimension > getKokkosMaterialPropertyOld(const std::string &name)
Get an old Kokkos material property.
bool hasKokkosMaterialPropertyByName(const std::string &name)
const OptionalMaterialProperty< T > & getOptionalMaterialProperty(const std::string &name, const unsigned int state=0)
std::pair< const MaterialProperty< T > *, std::set< SubdomainID > > getBlockMaterialProperty(const MaterialPropertyName &name)
Retrieve pointer to a material property with the mesh blocks where it is defined The name required by...
virtual void resolveOptionalProperties()
resolve all optional properties
const std::string _mi_name
The name of the object that this interface belongs to.
void checkExecutionStage()
Check and throw an error if the execution has progressed past the construction stage.
const MaterialProperty< T > * defaultMaterialProperty(const std::string &name)
const MaterialProperty< T > & getMaterialPropertyOlderByName(const MaterialPropertyName &name, MaterialData &material_data)
Retrieve the older property named name without any deduction for the specified material_data.
const GenericOptionalMaterialProperty< T, is_ad > & getGenericOptionalMaterialProperty(const std::string &name, const unsigned int state=0)
Moose::Kokkos::MaterialProperty< T, dimension > getKokkosMaterialProperty(const std::string &name)
Get a Kokkos material property for any state.
static constexpr PropertyValue::id_type default_property_id
The material property ID for a default (parsed from input) property.
virtual void getKokkosMaterialPropertyHook(const std::string &, const unsigned int)
A virtual method that can be overriden by Kokkos objects to insert additional operations in getKokkos...
const MaterialProperty< T > & getZeroMaterialProperty(Ts... args)
for backwards compatibility
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...
A class for storing the names of MooseObject by tag and object name.
Every object that can be built by the factory should be derived from this class.
The Kokkos material property class.
Helper class for deferred getting of material properties after the construction phase for materials.
virtual ~OptionalMaterialPropertyProxyBase()
const unsigned int _state
OptionalMaterialPropertyProxyBase(const std::string &name, const unsigned int state)
virtual void resolve(M &material)=0
OptionalMaterialPropertyProxy(const std::string &name, const unsigned int state)
void resolve(M &mpi) override
GenericOptionalMaterialProperty< T, is_ad > _value
const GenericOptionalMaterialProperty< T, is_ad > & value() const
static constexpr id_type invalid_property_id
The material property ID for an invalid property We only have this because there are a few cases wher...
unsigned int id_type
The type for a material property ID.
Generic class for solving transient nonlinear problems.
void mooseSetToZero(T &v)
Helper function templates to set a variable to zero.
constexpr std::size_t constMaxQpsPerElem
This is used for places where we initialize some qp-sized data structures that would end up being siz...
MaterialDataType
MaterialData types.