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)
 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, 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:244
bool _resize_only_if_smaller
Use non-destructive resize of material data (calling resize() will not reduce size).
Definition: MaterialData.h:340
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:250
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:336
const THREAD_ID _tid
The thread id.
Definition: MaterialData.h:247

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:244
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:244
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:247

◆ 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 
)

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
Returns
The Kokkos material property

Definition at line 495 of file MaterialData.h.

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

499 {
500  auto shell = std::make_shared<Moose::Kokkos::MaterialProperty<T, dimension>>();
501 
502  auto & prop_base = declareKokkosPropertyHelper(prop_name, typeid(T), declarer, dims, bnd, shell);
503  auto prop_cast = dynamic_cast<Moose::Kokkos::MaterialProperty<T, dimension> *>(&prop_base);
504 
505  if (!prop_cast)
506  mooseError("The declared ",
507  dimension,
508  "D Kokkos material property '",
509  prop_name,
510  "' of type '",
511  MooseUtils::prettyCppType<T>(),
512  "' was already declared or requested as a ",
513  prop_base.dim(),
514  "D property of type '",
515  prop_base.type(),
516  "'.");
517 
518  return *prop_cast;
519 }
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, std::shared_ptr< Moose::Kokkos::MaterialPropertyBase > shell)
Helper function for declaring a Kokkos material property.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
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,
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
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:244

◆ 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 455 of file MaterialData.h.

Referenced by MaterialPropertyInterface::getKokkosMaterialPropertyByName().

456 {
457  // Reserve the storages for the property up to the requested state
458  // If the storages were already reserved, it will do nothing
459  for (unsigned int s = 0; s <= state; ++s)
460  {
461  auto shell = std::make_shared<Moose::Kokkos::MaterialProperty<T, dimension>>();
462 
463  addKokkosPropertyHelper(prop_name, typeid(T), state, shell);
464 
465  // Only instantiate load and store functions for stateful properties to avoid requiring users
466  // to provide custom dataLoad and dataStore for non-trivially-copyable types that are never
467  // used as stateful properties
468  if constexpr (state > 0)
469  kokkosRegisterLoadStoreHelper(shell->propertyType(),
470  Moose::Kokkos::propertyStore<T, dimension>,
471  Moose::Kokkos::propertyLoad<T, dimension>);
472  }
473 
474  auto & prop_base = getKokkosPropertyHelper(prop_name, state, nullptr);
475  auto prop_cast = dynamic_cast<Moose::Kokkos::MaterialProperty<T, dimension> *>(&prop_base);
476 
477  if (!prop_cast)
478  mooseError("The requested ",
479  dimension,
480  "D Kokkos material property '",
481  prop_name,
482  "' of type '",
484  "' was already declared or requested as a ",
485  prop_base.dim(),
486  "D property of type '",
487  prop_base.type(),
488  "'.");
489 
490  return *prop_cast;
491 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
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:159
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:1147
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 186 of file MaterialData.h.

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

◆ 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 207 of file MaterialData.h.

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

◆ 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:244
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 378 of file MaterialData.h.

381 {
382  if constexpr (is_ad)
383  mooseAssert(state == 0, "Cannot request/declare AD properties for states other than zero");
384  if constexpr (declare)
385  mooseAssert(state == 0, "Cannot declare properties for states other than zero");
386 
387  // Register/get the ID of the property
388  const auto prop_id = addPropertyHelper(
389  prop_name, typeid(T), state, declare ? &castRequestorToDeclarer(requestor) : nullptr);
390  const auto size = prop_id + 1;
391 
392  // Initialize the states that we need
393  for (const auto state_i : make_range(getMaxStateRequested(prop_id) + 1))
394  {
395  auto & entry = props(state_i);
396  if (entry.size() < size)
397  entry.resize(size, {});
398  // if we are not declaring the property we initialize only what we need (the requested state)
399  if (!entry.hasValue(prop_id) && (declare || state_i == state))
400  {
401  if (state_i == 0)
402  entry.setPointer(
403  prop_id, std::move(std::make_unique<GenericMaterialProperty<T, is_ad>>(prop_id)), {});
404  else
405  entry.setPointer(prop_id, std::move(std::make_unique<MaterialProperty<T>>(prop_id)), {});
406  }
407  }
408 
409  // Should be available now
410  auto & base_prop = props(state)[prop_id];
411 
412  // In the event that this property was already declared/requested, make sure
413  // that the types are consistent
414  auto prop = dynamic_cast<GenericMaterialProperty<T, is_ad> *>(&base_prop);
415  if (!prop)
416  {
417  constexpr std::string_view action = declare ? "declared" : "requested";
418  constexpr auto is_ad_to_str = [](const bool is_ad_bool)
419  { return std::string_view(is_ad_bool ? "AD" : "non-AD"); };
420  constexpr std::string_view ad_type = is_ad_to_str(is_ad);
421 
422  std::stringstream error;
423  error << "The " << action << " " << ad_type << " "
424  << "material property '" + prop_name + "' of type '" << MooseUtils::prettyCppType<T>()
425  << "'\nis already retrieved or declared as a " << is_ad_to_str(base_prop.isAD())
426  << " property of type '" << base_prop.type() << "'.";
427  mooseErrorHelper(requestor, error.str());
428  }
429 
430  return *prop;
431 }
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:347
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::getKokkosMaterialPropertyByName(), haveGenericProperty(), and MaterialBase::registerPropName().

81 {
82  return _storage.getMaterialPropertyRegistry().getID(prop_name);
83 }
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:244
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:244
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 362 of file MaterialData.h.

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

363 {
364  if (!hasProperty(prop_name))
365  return false;
366 
367  const auto prop_id = getPropertyId(prop_name);
368  // the property id exists, but the property was not created in this instance of the material type
369  if (prop_id >= props(0).size())
370  return false;
371 
372  const PropertyValue * const base_prop = props(0).queryValue(prop_id);
373  return dynamic_cast<const GenericMaterialProperty<T, is_ad> *>(base_prop) != nullptr;
374 }
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:347

◆ 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 444 of file MaterialData.h.

Referenced by MaterialPropertyInterface::hasKokkosMaterialPropertyByName().

445 {
446  if (!haveKokkosPropertyHelper(prop_name))
447  return false;
448 
449  auto & prop = getKokkosPropertyHelper(prop_name);
450  return dynamic_cast<Moose::Kokkos::MaterialProperty<T, dimension> *>(&prop) != nullptr;
451 }
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 233 of file MaterialData.h.

233 { 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:340

◆ isSwapped()

bool MaterialData::isSwapped ( ) const
inline

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

Definition at line 181 of file MaterialData.h.

Referenced by swap(), and swapBack().

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

◆ 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:250

◆ 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 228 of file MaterialData.h.

228 { _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:340

◆ 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 347 of file MaterialData.h.

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

348 {
349  mooseAssert(_props.size() > state, "Invalid state");
350  return _props[state];
351 }
std::array< MaterialProperties, max_state+1 > _props
The underlying property data.
Definition: MaterialData.h:253

◆ props() [2/2]

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

Definition at line 354 of file MaterialData.h.

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

◆ 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 435 of file MaterialData.h.

436 {
437  for (const auto & mat : mats)
438  mat->computeProperties();
439 }

◆ 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:244
bool _resize_only_if_smaller
Use non-destructive resize of material data (calling resize() will not reduce size).
Definition: MaterialData.h:340
unsigned int _n_qpoints
Number of quadrature points.
Definition: MaterialData.h:250
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:347
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:181
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:244
bool _swapped
Status of storage swapping (calling swap sets this to true; swapBack sets it to false) ...
Definition: MaterialData.h:336
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:247

◆ 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:181
MaterialPropertyStorage & _storage
Reference to the MaterialStorage class.
Definition: MaterialData.h:244
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:336
const THREAD_ID _tid
The thread id.
Definition: MaterialData.h:247

Member Data Documentation

◆ _n_qpoints

unsigned int MaterialData::_n_qpoints
private

Number of quadrature points.

Definition at line 250 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 253 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 340 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 336 of file MaterialData.h.

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

◆ _tid

const THREAD_ID MaterialData::_tid
private

The thread id.

Definition at line 247 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: