https://mooseframework.inl.gov
Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
MaterialData Class Reference

Proxy for accessing MaterialPropertyStorage. More...

#include <MaterialData.h>

Classes

class  XFEMKey
 Key that provides access to only the XFEM class. More...
 

Public Member Functions

 MaterialData (MaterialPropertyStorage &storage, const THREAD_ID tid)
 
void resize (unsigned int n_qpoints)
 Resize the data to hold properties for n_qpoints quadrature points. More...
 
unsigned int nQPoints () const
 Returns the number of quadrature points the material properties support/hold. More...
 
void copy (const Elem &elem_to, const Elem &elem_from, unsigned int side)
 copy material properties from one element to another More...
 
void swap (const Elem &elem, unsigned int side=0)
 material properties for given element (and possible side) More...
 
template<typename MatContainer >
void reinit (const MatContainer &mats)
 Reinit material properties for given element (and possible side) More...
 
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. More...
 
void swapBack (const Elem &elem, unsigned int side=0)
 material properties for given element (and possible side) More...
 
const MaterialPropertiesprops (const unsigned int state=0) const
 
MaterialPropertiesprops (const unsigned int state=0)
 
template<typename T , bool is_ad>
bool haveGenericProperty (const std::string &prop_name) const
 
template<typename T >
bool haveProperty (const std::string &prop_name) const
 Returns true if the regular material property exists - defined by any material. More...
 
template<typename T >
bool haveADProperty (const std::string &prop_name) const
 Returns true if the AD material property exists - defined by any material. More...
 
template<typename T , unsigned int dimension>
bool haveKokkosProperty (const std::string &prop_name) const
 Get whether a Kokkos material property exists. More...
 
template<typename T , bool is_ad = false>
GenericMaterialProperty< T, is_ad > & getProperty (const std::string &prop_name, const unsigned int state, const MooseObject &requestor)
 Retrieves a material property. More...
 
template<typename T , bool is_ad>
GenericMaterialProperty< T, is_ad > & declareProperty (const std::string &prop_name, const MooseObject &requestor)
 Declares a material property. More...
 
template<typename T , unsigned int dimension, unsigned int state>
Moose::Kokkos::MaterialProperty< T, dimension > getKokkosProperty (const std::string &prop_name)
 Get a Kokkos material property. More...
 
template<typename T , unsigned int dimension>
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. More...
 
bool isSwapped () const
 Returns true if the stateful material is in a swapped state. More...
 
const MaterialPropertyStoragegetMaterialPropertyStorage () const
 Provide read-only access to the underlying MaterialPropertyStorage object. More...
 
MaterialPropertyStoragegetMaterialPropertyStorageForXFEM (const XFEMKey)
 Provide write-only access to the underlying MaterialPropertyStorage object JUST FOR XFEM. More...
 
bool hasProperty (const std::string &prop_name) const
 
unsigned int getPropertyId (const std::string &prop_name) const
 Wrapper for MaterialStorage::getPropertyId. More...
 
void onlyResizeIfSmaller (bool flag)
 Set _resize_only_if_smaller to perform a non-destructive resize. More...
 
bool isOnlyResizeIfSmaller () const
 Check value of _resize_only_if_smaller. More...
 
void eraseProperty (const Elem *elem)
 Remove the property storage and element pointer from MaterialPropertyStorage data structures Use this when elements are deleted so we don't end up with invalid elem pointers (for e.g. More...
 

Static Public Attributes

static constexpr unsigned int max_state = 2
 The max time state supported (2 = older) More...
 

Private Member Functions

unsigned int addPropertyHelper (const std::string &prop_name, const std::type_info &type, const unsigned int state, const MaterialBase *const declarer)
 
template<typename T , bool is_ad, bool declare>
GenericMaterialProperty< T, is_ad > & getPropertyHelper (const std::string &prop_name, const unsigned int state, const MooseObject &requestor)
 
Moose::Kokkos::MaterialPropertyBaseaddKokkosPropertyHelper (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. More...
 
Moose::Kokkos::MaterialPropertyBasedeclareKokkosPropertyHelper (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. More...
 
Moose::Kokkos::MaterialPropertyBasegetKokkosPropertyHelper (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. More...
 
bool haveKokkosPropertyHelper (const std::string &prop_name) const
 Helper function for checking whether a Kokkos material property exists. More...
 
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 property storage. More...
 
const MaterialBasecastRequestorToDeclarer (const MooseObject &requestor) const
 Helper for casting requestor to a MaterialBase in addPropertyHelper() (templated) More...
 
unsigned int getMaxStateRequested (const unsigned int prop_id) const
 maximum state id requested for a property More...
 

Static Private Member Functions

static void mooseErrorHelper (const MooseObject &object, const std::string_view &error)
 

Private Attributes

MaterialPropertyStorage_storage
 Reference to the MaterialStorage class. More...
 
const THREAD_ID _tid
 The thread id. More...
 
unsigned int _n_qpoints
 Number of quadrature points. More...
 
std::array< MaterialProperties, max_state+1 > _props
 The underlying property data. More...
 
bool _swapped
 Status of storage swapping (calling swap sets this to true; swapBack sets it to false) More...
 
bool _resize_only_if_smaller
 Use non-destructive resize of material data (calling resize() will not reduce size). More...
 

Detailed Description

Proxy for accessing MaterialPropertyStorage.

MaterialData stores the values associated with a particular material object

Definition at line 37 of file MaterialData.h.

Constructor & Destructor Documentation

◆ MaterialData()

MaterialData::MaterialData ( MaterialPropertyStorage storage,
const THREAD_ID  tid 
)

Definition at line 15 of file MaterialData.C.

16  : _storage(storage), _tid(tid), _n_qpoints(0), _swapped(false), _resize_only_if_smaller(false)
17 {
18 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248
bool _resize_only_if_smaller
Use non-destructive resize of material data (calling resize() will not reduce size).
Definition: MaterialData.h:348
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:254
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:344
const THREAD_ID _tid
The thread id.
Definition: MaterialData.h:251

Member Function Documentation

◆ addKokkosPropertyHelper()

Moose::Kokkos::MaterialPropertyBase& MaterialData::addKokkosPropertyHelper ( const std::string &  prop_name,
const std::type_info &  type,
const unsigned int  state,
std::shared_ptr< Moose::Kokkos::MaterialPropertyBase shell 
)
private

Helper function for adding a Kokkos material property.

Parameters
prop_nameThe property name
typeThe property data type
stateThe property state
shellThe managed pointer containing the instance of the property
Returns
The Kokkos material property

Referenced by getKokkosProperty().

◆ addPropertyHelper()

unsigned int MaterialData::addPropertyHelper ( const std::string &  prop_name,
const std::type_info &  type,
const unsigned int  state,
const MaterialBase *const  declarer 
)
private

Definition at line 92 of file MaterialData.C.

Referenced by getPropertyHelper().

96 {
97  return _storage.addProperty(prop_name, type, state, declarer);
98 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248
unsigned int addProperty(const std::string &prop_name, const std::type_info &type, const unsigned int state, const MaterialBase *const declarer)
Adds a property with the name prop_name, type type, and state state (0 = current, 1 = old...

◆ castRequestorToDeclarer()

const MaterialBase & MaterialData::castRequestorToDeclarer ( const MooseObject requestor) const
private

Helper for casting requestor to a MaterialBase in addPropertyHelper() (templated)

Definition at line 101 of file MaterialData.C.

Referenced by getPropertyHelper().

102 {
103  const auto declarer = dynamic_cast<const MaterialBase *>(&requestor);
104  mooseAssert(declarer, "Not a MaterialBase");
105  return *declarer;
106 }
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:62

◆ copy()

void MaterialData::copy ( const Elem &  elem_to,
const Elem &  elem_from,
unsigned int  side 
)

copy material properties from one element to another

Definition at line 35 of file MaterialData.C.

36 {
37  _storage.copy(_tid, &elem_to, &elem_from, side, nQPoints());
38 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248
unsigned int nQPoints() const
Returns the number of quadrature points the material properties support/hold.
Definition: MaterialData.h:54
void copy(const THREAD_ID tid, const Elem &elem_to, const Elem &elem_from, unsigned int side, unsigned int n_qpoints)
Copy material properties from elem_from to elem_to.
const THREAD_ID _tid
The thread id.
Definition: MaterialData.h:251

◆ declareKokkosProperty()

template<typename T , unsigned int dimension>
Moose::Kokkos::MaterialProperty< T, dimension > MaterialData::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.

Template Parameters
TThe property data type
dimensionThe property dimension
Parameters
prop_nameThe property name
dimsThe vector containing the size of each dimension
declarerThe Kokkos material declaring the property
bndWhether the property is a face property
on_demandWhether the property is an on-demand property
constant_optionWhether the property is constant on element or subdomain
Returns
The Kokkos material property

Definition at line 503 of file MaterialData.h.

Referenced by Moose::Kokkos::MaterialBase::declareKokkosPropertyInternal().

509 {
510  auto shell = std::make_shared<Moose::Kokkos::MaterialProperty<T, dimension>>();
511 
512  auto & prop_base = declareKokkosPropertyHelper(
513  prop_name, typeid(T), declarer, dims, bnd, on_demand, constant_option, shell);
514  auto prop_cast = dynamic_cast<Moose::Kokkos::MaterialProperty<T, dimension> *>(&prop_base);
515 
516  if (!prop_cast)
517  mooseError("The declared ",
518  dimension,
519  "D Kokkos material property '",
520  prop_name,
521  "' of type '",
522  MooseUtils::prettyCppType<T>(),
523  "' was already declared or requested as a ",
524  prop_base.dim(),
525  "D property of type '",
526  prop_base.type(),
527  "'.");
528 
529  return *prop_cast;
530 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
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.
The Kokkos material property class.

◆ declareKokkosPropertyHelper()

Moose::Kokkos::MaterialPropertyBase& MaterialData::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 
)
private

Helper function for declaring a Kokkos material property.

Parameters
prop_nameThe property name
typeThe property data type
declarerThe Kokkos material declaring the property
dimsThe vector containing the size of each dimension
bndWhether the property is a face property
on_demandWhether the property is an on-demand property
constant_optionWhether the property is constant on element or subdomain
shellThe managed pointer containing the instance of the property
Returns
The Kokkos material property

Referenced by declareKokkosProperty().

◆ declareProperty()

template<typename T , bool is_ad>
GenericMaterialProperty<T, is_ad>& MaterialData::declareProperty ( const std::string &  prop_name,
const MooseObject requestor 
)
inline

Declares a material property.

Template Parameters
TThe type of the property
is_adWhether or not the property is AD
Parameters
prop_nameThe name of the property
requestorThe MooseObject declaring the property
Returns
The property for the supplied type and name

Definition at line 142 of file MaterialData.h.

Referenced by MaterialBase::declareGenericPropertyByName().

144  {
145  return getPropertyHelper<T, is_ad, true>(prop_name, 0, requestor);
146  }

◆ eraseProperty()

void MaterialData::eraseProperty ( const Elem *  elem)

Remove the property storage and element pointer from MaterialPropertyStorage data structures Use this when elements are deleted so we don't end up with invalid elem pointers (for e.g.

stateful properties) hanging around in our data structures

Definition at line 86 of file MaterialData.C.

87 {
88  _storage.eraseProperty(elem);
89 }
void eraseProperty(const Elem *elem)
Remove the property storage and element pointer from internal data structures Use this when elements ...
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248

◆ getKokkosProperty()

template<typename T , unsigned int dimension, unsigned int state>
Moose::Kokkos::MaterialProperty< T, dimension > MaterialData::getKokkosProperty ( const std::string &  prop_name)

Get a Kokkos material property.

Template Parameters
TThe property data type
dimensionThe property dimension
stateThe property state
Parameters
prop_nameThe property name
Returns
The Kokkos material property

Definition at line 463 of file MaterialData.h.

Referenced by MaterialPropertyInterface::getKokkosBlockMaterialProperty(), and MaterialPropertyInterface::getKokkosMaterialPropertyByName().

464 {
465  // Reserve the storages for the property up to the requested state
466  // If the storages were already reserved, it will do nothing
467  for (unsigned int s = 0; s <= state; ++s)
468  {
469  auto shell = std::make_shared<Moose::Kokkos::MaterialProperty<T, dimension>>();
470 
471  addKokkosPropertyHelper(prop_name, typeid(T), state, shell);
472 
473  // Only instantiate load and store functions for stateful properties to avoid requiring users
474  // to provide custom dataLoad and dataStore for non-trivially-copyable types that are never
475  // used as stateful properties
476  if constexpr (state > 0)
477  kokkosRegisterLoadStoreHelper(shell->propertyType(),
478  Moose::Kokkos::propertyStore<T, dimension>,
479  Moose::Kokkos::propertyLoad<T, dimension>);
480  }
481 
482  auto & prop_base = getKokkosPropertyHelper(prop_name, state, nullptr);
483  auto prop_cast = dynamic_cast<Moose::Kokkos::MaterialProperty<T, dimension> *>(&prop_base);
484 
485  if (!prop_cast)
486  mooseError("The requested ",
487  dimension,
488  "D Kokkos material property '",
489  prop_name,
490  "' of type '",
492  "' was already declared or requested as a ",
493  prop_base.dim(),
494  "D property of type '",
495  prop_base.type(),
496  "'.");
497 
498  return *prop_cast;
499 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
void propertyLoad(std::istream &stream, void *prop)
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:163
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.
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.
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
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...
std::string prettyCppType(const std::string &cpp_type)
Definition: MooseUtils.C:1140
void propertyStore(std::ostream &stream, void *prop)

◆ getKokkosPropertyHelper()

Moose::Kokkos::MaterialPropertyBase& MaterialData::getKokkosPropertyHelper ( const std::string &  prop_name,
const unsigned int  state = 0,
std::shared_ptr< Moose::Kokkos::MaterialPropertyBase shell = nullptr 
) const
private

Helper function for getting a Kokkos material property.

Parameters
prop_nameThe property name
stateThe property state
shellThe managed pointer containing the instance of the property
Returns
The Kokkos material property

Referenced by getKokkosProperty(), and haveKokkosProperty().

◆ getMaterialPropertyStorage()

const MaterialPropertyStorage& MaterialData::getMaterialPropertyStorage ( ) const
inline

Provide read-only access to the underlying MaterialPropertyStorage object.

Definition at line 190 of file MaterialData.h.

190 { return _storage; }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248

◆ getMaterialPropertyStorageForXFEM()

MaterialPropertyStorage& MaterialData::getMaterialPropertyStorageForXFEM ( const XFEMKey  )
inline

Provide write-only access to the underlying MaterialPropertyStorage object JUST FOR XFEM.

This should be removed. To be clear - you should not ever expect to have write access to this data. It just turned out that XFEM got away with it when we were storing things as pointers instead of smart pointers...

These dirty reasons are why this method is named so egregiously.

Definition at line 211 of file MaterialData.h.

211 { return _storage; }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248

◆ getMaxStateRequested()

unsigned int MaterialData::getMaxStateRequested ( const unsigned int  prop_id) const
private

maximum state id requested for a property

Definition at line 109 of file MaterialData.C.

Referenced by getPropertyHelper().

110 {
111  return _storage.getPropRecord(prop_id).state;
112 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248
unsigned int state
The max state requrested for this property (0 = current, 1 = old, ...)
const PropRecord & getPropRecord(const unsigned int id) const
Get the property record associated with the material with id id.

◆ getProperty()

template<typename T , bool is_ad = false>
GenericMaterialProperty<T, is_ad>& MaterialData::getProperty ( const std::string &  prop_name,
const unsigned int  state,
const MooseObject requestor 
)
inline

Retrieves a material property.

Template Parameters
TThe type of the property
is_adWhether or not the property is AD
Parameters
prop_nameThe name of the property
stateThe time state (0 = current, 1 = old, etc; defaults to 0)
requestorThe MooseObject requesting the property
Returns
The property for the supplied type and name

Definition at line 127 of file MaterialData.h.

Referenced by MaterialPropertyInterface::getBlockMaterialProperty(), MaterialPropertyInterface::getGenericMaterialPropertyByName(), and MaterialBase::getGenericZeroMaterialPropertyByName().

130  {
131  return getPropertyHelper<T, is_ad, false>(prop_name, state, requestor);
132  }

◆ getPropertyHelper()

template<typename T , bool is_ad, bool declare>
GenericMaterialProperty< T, is_ad > & MaterialData::getPropertyHelper ( const std::string &  prop_name,
const unsigned int  state,
const MooseObject requestor 
)
private

Definition at line 386 of file MaterialData.h.

389 {
390  if constexpr (is_ad)
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");
394 
395  // Register/get the ID of the property
396  const auto prop_id = addPropertyHelper(
397  prop_name, typeid(T), state, declare ? &castRequestorToDeclarer(requestor) : nullptr);
398  const auto size = prop_id + 1;
399 
400  // Initialize the states that we need
401  for (const auto state_i : make_range(getMaxStateRequested(prop_id) + 1))
402  {
403  auto & entry = props(state_i);
404  if (entry.size() < size)
405  entry.resize(size, {});
406  // if we are not declaring the property we initialize only what we need (the requested state)
407  if (!entry.hasValue(prop_id) && (declare || state_i == state))
408  {
409  if (state_i == 0)
410  entry.setPointer(
411  prop_id, std::move(std::make_unique<GenericMaterialProperty<T, is_ad>>(prop_id)), {});
412  else
413  entry.setPointer(prop_id, std::move(std::make_unique<MaterialProperty<T>>(prop_id)), {});
414  }
415  }
416 
417  // Should be available now
418  auto & base_prop = props(state)[prop_id];
419 
420  // In the event that this property was already declared/requested, make sure
421  // that the types are consistent
422  auto prop = dynamic_cast<GenericMaterialProperty<T, is_ad> *>(&base_prop);
423  if (!prop)
424  {
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);
429 
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() << "'.";
435  mooseErrorHelper(requestor, error.str());
436  }
437 
438  return *prop;
439 }
const MaterialBase & castRequestorToDeclarer(const MooseObject &requestor) const
Helper for casting requestor to a MaterialBase in addPropertyHelper() (templated) ...
Definition: MaterialData.C:101
unsigned int addPropertyHelper(const std::string &prop_name, const std::type_info &type, const unsigned int state, const MaterialBase *const declarer)
Definition: MaterialData.C:92
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
const MaterialProperties & props(const unsigned int state=0) const
Definition: MaterialData.h:355
unsigned int getMaxStateRequested(const unsigned int prop_id) const
maximum state id requested for a property
Definition: MaterialData.C:109
IntRange< T > make_range(T beg, T end)
static void mooseErrorHelper(const MooseObject &object, const std::string_view &error)
Definition: MaterialData.C:68

◆ getPropertyId()

unsigned int MaterialData::getPropertyId ( const std::string &  prop_name) const

Wrapper for MaterialStorage::getPropertyId.

Allows classes with a MaterialData object (i.e. MaterialPropertyInterface) to access material property IDs.

Parameters
prop_nameThe name of the material property
Returns
An unsigned int corresponding to the property ID of the passed in prop_name

Definition at line 80 of file MaterialData.C.

Referenced by MaterialPropertyInterface::getBlockMaterialProperty(), MaterialPropertyInterface::getGenericMaterialPropertyByName(), MaterialPropertyInterface::getKokkosBlockMaterialProperty(), MaterialPropertyInterface::getKokkosMaterialPropertyByName(), haveGenericProperty(), and MaterialBase::registerPropName().

81 {
82  return _storage.getMaterialPropertyRegistry().getID(prop_name);
83 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248
const MaterialPropertyRegistry & getMaterialPropertyRegistry() const
unsigned int getID(const std::string &name) const

◆ hasProperty()

bool MaterialData::hasProperty ( const std::string &  prop_name) const
Returns
Whether or not a property exists with the name name

Definition at line 74 of file MaterialData.C.

Referenced by haveGenericProperty().

75 {
76  return _storage.hasProperty(prop_name);
77 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248
bool hasProperty(const std::string &prop_name) const

◆ haveADProperty()

template<typename T >
bool MaterialData::haveADProperty ( const std::string &  prop_name) const
inline

Returns true if the AD material property exists - defined by any material.

Definition at line 100 of file MaterialData.h.

Referenced by MaterialPropertyInterface::hasADMaterialPropertyByName(), and MaterialOutputAction::hasADProperty().

101  {
102  return haveGenericProperty<T, true>(prop_name);
103  }

◆ haveGenericProperty()

template<typename T , bool is_ad>
bool MaterialData::haveGenericProperty ( const std::string &  prop_name) const
inline

Definition at line 370 of file MaterialData.h.

Referenced by BlockRestrictable::hasBlockMaterialProperty(), and BoundaryRestrictable::hasBoundaryMaterialProperty().

371 {
372  if (!hasProperty(prop_name))
373  return false;
374 
375  const auto prop_id = getPropertyId(prop_name);
376  // the property id exists, but the property was not created in this instance of the material type
377  if (prop_id >= props(0).size())
378  return false;
379 
380  const PropertyValue * const base_prop = props(0).queryValue(prop_id);
381  return dynamic_cast<const GenericMaterialProperty<T, is_ad> *>(base_prop) != nullptr;
382 }
bool hasProperty(const std::string &prop_name) const
Definition: MaterialData.C:74
unsigned int getPropertyId(const std::string &prop_name) const
Wrapper for MaterialStorage::getPropertyId.
Definition: MaterialData.C:80
const T * queryValue(const std::size_t i) const
typename GenericMaterialPropertyStruct< T, is_ad >::type GenericMaterialProperty
Abstract definition of a property value.
const MaterialProperties & props(const unsigned int state=0) const
Definition: MaterialData.h:355

◆ haveKokkosProperty()

template<typename T , unsigned int dimension>
bool MaterialData::haveKokkosProperty ( const std::string &  prop_name) const

Get whether a Kokkos material property exists.

Template Parameters
TThe property data type
dimensionThe property dimension
Parameters
prop_nameThe property name
Returns
Whether the Kokkos material property exists

Definition at line 452 of file MaterialData.h.

Referenced by MaterialPropertyInterface::hasKokkosMaterialPropertyByName().

453 {
454  if (!haveKokkosPropertyHelper(prop_name))
455  return false;
456 
457  auto & prop = getKokkosPropertyHelper(prop_name);
458  return dynamic_cast<Moose::Kokkos::MaterialProperty<T, dimension> *>(&prop) != nullptr;
459 }
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.
The Kokkos material property class.
bool haveKokkosPropertyHelper(const std::string &prop_name) const
Helper function for checking whether a Kokkos material property exists.

◆ haveKokkosPropertyHelper()

bool MaterialData::haveKokkosPropertyHelper ( const std::string &  prop_name) const
private

Helper function for checking whether a Kokkos material property exists.

Parameters
prop_nameThe property name
Returns
Whether the Kokkos material property exists

Referenced by haveKokkosProperty().

◆ haveProperty()

template<typename T >
bool MaterialData::haveProperty ( const std::string &  prop_name) const
inline

Returns true if the regular material property exists - defined by any material.

Definition at line 93 of file MaterialData.h.

Referenced by MaterialPropertyInterface::hasMaterialPropertyByName(), and MaterialOutputAction::hasProperty().

94  {
95  return haveGenericProperty<T, false>(prop_name);
96  }

◆ isOnlyResizeIfSmaller()

bool MaterialData::isOnlyResizeIfSmaller ( ) const
inline

Check value of _resize_only_if_smaller.

Definition at line 237 of file MaterialData.h.

237 { return _resize_only_if_smaller; };
bool _resize_only_if_smaller
Use non-destructive resize of material data (calling resize() will not reduce size).
Definition: MaterialData.h:348

◆ isSwapped()

bool MaterialData::isSwapped ( ) const
inline

Returns true if the stateful material is in a swapped state.

Definition at line 185 of file MaterialData.h.

Referenced by swap(), and swapBack().

185 { return _swapped; }
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:344

◆ kokkosRegisterLoadStoreHelper()

void MaterialData::kokkosRegisterLoadStoreHelper ( std::type_index  type,
Moose::Kokkos::PropertyStore  store,
Moose::Kokkos::PropertyLoad  load 
)
private

Helper function to register load/store functions of a Kokkos material property to the Kokkos material property storage.

Parameters
typeThe property type index
storeThe store function pointer
loadThe load function pointer

Referenced by getKokkosProperty().

◆ mooseErrorHelper()

void MaterialData::mooseErrorHelper ( const MooseObject object,
const std::string_view &  error 
)
staticprivate

Definition at line 68 of file MaterialData.C.

Referenced by getPropertyHelper().

69 {
70  object.mooseError(error);
71 }

◆ nQPoints()

unsigned int MaterialData::nQPoints ( ) const
inline

Returns the number of quadrature points the material properties support/hold.

Definition at line 54 of file MaterialData.h.

Referenced by copy(), and resize().

54 { return _n_qpoints; }
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:254

◆ onlyResizeIfSmaller()

void MaterialData::onlyResizeIfSmaller ( bool  flag)
inline

Set _resize_only_if_smaller to perform a non-destructive resize.

Setting this flag to true means that resize(n) will not decrease the size of _props if n is smaller than the size of the material data object.

Definition at line 232 of file MaterialData.h.

232 { _resize_only_if_smaller = flag; };
bool _resize_only_if_smaller
Use non-destructive resize of material data (calling resize() will not reduce size).
Definition: MaterialData.h:348

◆ props() [1/2]

const MaterialProperties & MaterialData::props ( const unsigned int  state = 0) const
inline
Returns
The properties for the state state (defaults to zero).

This should NEVER be used to modify the size of these objects.{

Definition at line 355 of file MaterialData.h.

Referenced by Material::computeProperties(), getPropertyHelper(), haveGenericProperty(), resize(), and Material::subdomainSetup().

356 {
357  mooseAssert(_props.size() > state, "Invalid state");
358  return _props[state];
359 }
std::array< MaterialProperties, max_state+1 > _props
The underlying property data.
Definition: MaterialData.h:257

◆ props() [2/2]

MaterialProperties & MaterialData::props ( const unsigned int  state = 0)
inline

Definition at line 362 of file MaterialData.h.

363 {
364  mooseAssert(_props.size() > state, "Invalid state");
365  return _props[state];
366 }
std::array< MaterialProperties, max_state+1 > _props
The underlying property data.
Definition: MaterialData.h:257

◆ reinit()

template<typename MatContainer >
void MaterialData::reinit ( const MatContainer &  mats)

Reinit material properties for given element (and possible side)

Parameters
matsThe material objects for which to compute properties
execute_statefulWhether to execute material objects that have stateful properties. This should be false when for example executing material objects for mortar contexts in which stateful properties don't make sense

Definition at line 443 of file MaterialData.h.

444 {
445  for (const auto & mat : mats)
446  mat->computeProperties();
447 }

◆ reset()

void MaterialData::reset ( const std::vector< std::shared_ptr< MaterialBase >> &  mats)

Calls the reset method of Materials to ensure that they are in a proper state.

Definition at line 51 of file MaterialData.C.

52 {
53  for (const auto & mat : mats)
54  mat->resetProperties();
55 }

◆ resize()

void MaterialData::resize ( unsigned int  n_qpoints)

Resize the data to hold properties for n_qpoints quadrature points.

Definition at line 21 of file MaterialData.C.

Referenced by ComputeMaterialsObjectThread::onBoundary(), ComputeMaterialsObjectThread::onInterface(), ComputeMaterialsObjectThread::onInternalSide(), FEProblemBase::reinitMaterials(), FEProblemBase::reinitMaterialsBoundary(), FEProblemBase::reinitMaterialsFace(), FEProblemBase::reinitMaterialsFaceOnBoundary(), FEProblemBase::reinitMaterialsInterface(), FEProblemBase::reinitMaterialsNeighbor(), and FEProblemBase::resizeMaterialData().

22 {
23  if (n_qpoints == nQPoints())
24  return;
25 
26  if (_resize_only_if_smaller && n_qpoints < nQPoints())
27  return;
28 
29  for (const auto state : _storage.stateIndexRange())
30  props(state).resizeItems(n_qpoints, {});
31  _n_qpoints = n_qpoints;
32 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248
bool _resize_only_if_smaller
Use non-destructive resize of material data (calling resize() will not reduce size).
Definition: MaterialData.h:348
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:254
void resizeItems(const std::size_t n_qpoints, const WriteKey)
Resize items in this array, i.e.
libMesh::IntRange< unsigned int > stateIndexRange() const
const MaterialProperties & props(const unsigned int state=0) const
Definition: MaterialData.h:355
unsigned int nQPoints() const
Returns the number of quadrature points the material properties support/hold.
Definition: MaterialData.h:54

◆ swap()

void MaterialData::swap ( const Elem &  elem,
unsigned int  side = 0 
)

material properties for given element (and possible side)

Definition at line 41 of file MaterialData.C.

42 {
44  return;
45 
46  _storage.swap(_tid, elem, side);
47  _swapped = true;
48 }
bool isSwapped() const
Returns true if the stateful material is in a swapped state.
Definition: MaterialData.h:185
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:344
void swap(const THREAD_ID tid, const Elem &elem, unsigned int side)
Swap (shallow copy) material properties in MaterialData and MaterialPropertyStorage Thread safe...
const THREAD_ID _tid
The thread id.
Definition: MaterialData.h:251

◆ swapBack()

void MaterialData::swapBack ( const Elem &  elem,
unsigned int  side = 0 
)

material properties for given element (and possible side)

Definition at line 58 of file MaterialData.C.

Referenced by FEProblemBase::swapBackMaterials(), FEProblemBase::swapBackMaterialsFace(), and FEProblemBase::swapBackMaterialsNeighbor().

59 {
61  {
62  _storage.swapBack(_tid, elem, side);
63  _swapped = false;
64  }
65 }
bool isSwapped() const
Returns true if the stateful material is in a swapped state.
Definition: MaterialData.h:185
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:248
void swapBack(const THREAD_ID tid, const Elem &elem, unsigned int side)
Swap (shallow copy) material properties in MaterialPropertyStorage and MaterialDat Thread safe...
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:344
const THREAD_ID _tid
The thread id.
Definition: MaterialData.h:251

Member Data Documentation

◆ _n_qpoints

unsigned int MaterialData::_n_qpoints
private

Number of quadrature points.

Definition at line 254 of file MaterialData.h.

Referenced by nQPoints(), and resize().

◆ _props

std::array<MaterialProperties, max_state + 1> MaterialData::_props
private

The underlying property data.

Definition at line 257 of file MaterialData.h.

Referenced by props().

◆ _resize_only_if_smaller

bool MaterialData::_resize_only_if_smaller
private

Use non-destructive resize of material data (calling resize() will not reduce size).

Default is false (normal resize behaviour)

Definition at line 348 of file MaterialData.h.

Referenced by isOnlyResizeIfSmaller(), onlyResizeIfSmaller(), and resize().

◆ _storage

MaterialPropertyStorage& MaterialData::_storage
private

◆ _swapped

bool MaterialData::_swapped
private

Status of storage swapping (calling swap sets this to true; swapBack sets it to false)

Definition at line 344 of file MaterialData.h.

Referenced by isSwapped(), swap(), and swapBack().

◆ _tid

const THREAD_ID MaterialData::_tid
private

The thread id.

Definition at line 251 of file MaterialData.h.

Referenced by copy(), swap(), and swapBack().

◆ max_state

constexpr unsigned int MaterialData::max_state = 2
static

The max time state supported (2 = older)

Definition at line 43 of file MaterialData.h.

Referenced by MaterialPropertyStorage::addProperty().


The documentation for this class was generated from the following files: