https://mooseframework.inl.gov
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Moose::Kokkos::MaterialProperty< T, dimension > Class Template Referencefinal

The Kokkos material property class. More...

#include <KokkosMaterialPropertyDecl.h>

Inheritance diagram for Moose::Kokkos::MaterialProperty< T, dimension >:
[legend]

Public Member Functions

 MaterialProperty ()=default
 Default constructor. More...
 
 MaterialProperty (const T &value)
 Constructor for default property. More...
 
 MaterialProperty (const MaterialProperty< T, dimension > &property)
 Copy constructor The reference material properties are held by the material property storage, and the user deals with the clones of them. More...
 
auto & operator= (const MaterialProperty< T, dimension > &property)
 Shallow copy another property. More...
 
KOKKOS_FUNCTION MaterialPropertyValue< T, dimension > operator() (const Datum &datum, const unsigned int qp) const
 Get the property values of a quadrature point. More...
 
virtual std::type_index propertyType () override
 Get the property type index for load/store functions. More...
 
virtual void init (const PropRecord &record, const StorageKey &key) override
 Initialize this property. More...
 
virtual void allocate (const MooseMesh &mesh, const Assembly &assembly, const std::set< SubdomainID > &subdomains, const bool bnd, StorageKey) override
 Allocate the data storage. More...
 
virtual void copy (const MaterialPropertyBase &prop, StorageKey) override
 Deep copy another property. More...
 
virtual void swap (MaterialPropertyBase &prop, StorageKey) override
 Swap with another property. More...
 
unsigned int id () const
 Get the property ID. More...
 
std::string name () const
 Get the property name. More...
 
std::string type () const
 Get the data type. More...
 
unsigned int dim () const
 Get the dimension. More...
 
unsigned int dim (unsigned int i) const
 Get the size of a dimension. More...
 
KOKKOS_FUNCTION operator bool () const
 Get whether this property is valid. More...
 

Protected Attributes

const PropRecord_record = nullptr
 Pointer to the record of this property. More...
 
unsigned int _id = libMesh::invalid_uint
 Property ID. More...
 
bool _default = false
 Flag whether this property has a default value. More...
 

Private Member Functions

void shallowCopy (const MaterialProperty< T, dimension > &property)
 Shallow copy another property. More...
 

Private Attributes

const MaterialProperty< T, dimension > * _reference = nullptr
 Pointer to the reference property. More...
 
Array< Array< T, dimension+1 > > _data
 Data storage. More...
 
_value
 Default value. More...
 

Friends

class MaterialPropertyValueBase< T, dimension >
 
void propertyStore (std::ostream &, void *)
 
void propertyLoad (std::istream &, void *)
 

Detailed Description

template<typename T, unsigned int dimension = 0>
class Moose::Kokkos::MaterialProperty< T, dimension >

The Kokkos material property class.

Definition at line 194 of file KokkosMaterialPropertyDecl.h.

Constructor & Destructor Documentation

◆ MaterialProperty() [1/3]

template<typename T, unsigned int dimension = 0>
Moose::Kokkos::MaterialProperty< T, dimension >::MaterialProperty ( )
default

Default constructor.

◆ MaterialProperty() [2/3]

template<typename T , unsigned int dimension>
MaterialProperty< T, dimension >::MaterialProperty ( const T &  value)

Constructor for default property.

Parameters
valueThe default value

Definition at line 35 of file KokkosMaterialProperty.h.

36 {
37  _default = true;
38  _value = value;
39 }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
bool _default
Flag whether this property has a default value.

◆ MaterialProperty() [3/3]

template<typename T , unsigned int dimension>
MaterialProperty< T, dimension >::MaterialProperty ( const MaterialProperty< T, dimension > &  property)

Copy constructor The reference material properties are held by the material property storage, and the user deals with the clones of them.

The reference material properties also hold the arrays for storing the property values (_data), and the user accesses the arrays through their shallow copies in the clones. As a result, if the reference material properties reallocate their arrays, the shallow copies of arrays in the clones will lose synchronization. Thus, the clones also hold the pointers to their reference material properties and shallow copy them in the copy constructor, so that the arrays are always synchronized with those in the reference material properties during parallel dispatch.

Definition at line 42 of file KokkosMaterialProperty.h.

43 {
44  // If reference exists, copy the reference property
45  // Reference can be nullptr if the property is a default or optional property
46  const auto & prop = property._reference ? *property._reference : property;
47 
48  shallowCopy(prop);
49 
50  _reference = property._reference;
51 }
const MaterialProperty< T, dimension > * _reference
Pointer to the reference property.
void shallowCopy(const MaterialProperty< T, dimension > &property)
Shallow copy another property.

Member Function Documentation

◆ allocate()

template<typename T , unsigned int dimension>
void MaterialProperty< T, dimension >::allocate ( const MooseMesh mesh,
const Assembly assembly,
const std::set< SubdomainID > &  subdomains,
const bool  bnd,
StorageKey   
)
overridevirtual

Allocate the data storage.

Parameters
meshThe MOOSE mesh
assemblyThe Kokkos assembly
subdomainsThe MOOSE subdomain IDs
bndWhether this property is a face property

Implements Moose::Kokkos::MaterialPropertyBase.

Definition at line 113 of file KokkosMaterialProperty.h.

118 {
119  if (!_data.isAlloc())
120  _data.create(mesh.meshSubdomains().size());
121 
122  for (const auto subdomain : subdomains)
123  {
124  auto sid = mesh.getKokkosMesh()->getContiguousSubdomainID(subdomain);
125 
126  std::vector<dof_id_type> n;
127 
128  for (unsigned int i = 0; i < dimension; ++i)
129  n.push_back(_record->dims[i]);
130 
131  n.push_back(bnd ? assembly.getNumFaceQps(sid) : assembly.getNumQps(sid));
132 
133  if (!_data[sid].isAlloc())
134  _data[sid].createDevice(n);
135  }
136 
137  _data.copyToDevice();
138 }
const PropRecord * _record
Pointer to the record of this property.
MeshBase & mesh
std::vector< unsigned int > dims
Size of each dimension.
Array< Array< T, dimension+1 > > _data
Data storage.

◆ copy()

template<typename T , unsigned int dimension>
void MaterialProperty< T, dimension >::copy ( const MaterialPropertyBase prop,
StorageKey   
)
overridevirtual

Deep copy another property.

Parameters
propThe property to copy

Implements Moose::Kokkos::MaterialPropertyBase.

Definition at line 74 of file KokkosMaterialProperty.h.

75 {
76  auto prop_cast = dynamic_cast<const MaterialProperty<T, dimension> *>(&prop);
77 
78  mooseAssert(prop_cast, "The property to copy should be of the same type and dimension.");
79 
80  for (const auto i : index_range(prop_cast->_data))
81  if (prop_cast->_data[i].isAlloc())
82  _data[i].deepCopy(prop_cast->_data[i]);
83 
84  _data.copyToDevice();
85 }
Array< Array< T, dimension+1 > > _data
Data storage.
auto index_range(const T &sizable)

◆ dim() [1/2]

unsigned int Moose::Kokkos::MaterialPropertyBase::dim ( ) const
inlineinherited

Get the dimension.

Returns
The dimension

Definition at line 107 of file KokkosMaterialPropertyDecl.h.

Referenced by Moose::Kokkos::MaterialPropertyBase::dim().

107 { return _record->dims.size(); }
const PropRecord * _record
Pointer to the record of this property.
std::vector< unsigned int > dims
Size of each dimension.

◆ dim() [2/2]

unsigned int Moose::Kokkos::MaterialPropertyBase::dim ( unsigned int  i) const
inlineinherited

Get the size of a dimension.

Parameters
iThe dimension index
Returns
The size of the dimension

Definition at line 113 of file KokkosMaterialPropertyDecl.h.

114  {
115  if (i >= dim())
116  mooseError("Cannot query the size of ",
117  i,
118  "-th dimension for the ",
119  dim(),
120  "D material property '",
121  name(),
122  "'.");
123 
124  return _record->dims.at(i);
125  }
const PropRecord * _record
Pointer to the record of this property.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
std::vector< unsigned int > dims
Size of each dimension.
unsigned int dim() const
Get the dimension.
std::string name() const
Get the property name.

◆ id()

unsigned int Moose::Kokkos::MaterialPropertyBase::id ( ) const
inlineinherited

Get the property ID.

Returns
The property ID assigned by the MOOSE registry

Definition at line 92 of file KokkosMaterialPropertyDecl.h.

92 { return _id; }

◆ init()

template<typename T , unsigned int dimension>
void MaterialProperty< T, dimension >::init ( const PropRecord record,
const StorageKey  
)
overridevirtual

Initialize this property.

Parameters
recordThe record of this property

Reimplemented from Moose::Kokkos::MaterialPropertyBase.

Definition at line 64 of file KokkosMaterialProperty.h.

65 {
66  MaterialPropertyBase::init(record, key);
67 
68  _reference = this;
69 }
virtual void init(const PropRecord &record, const StorageKey &)
Initialize this property.
const MaterialProperty< T, dimension > * _reference
Pointer to the reference property.

◆ name()

std::string Moose::Kokkos::MaterialPropertyBase::name ( ) const
inlineinherited

Get the property name.

Returns
The property name

Definition at line 97 of file KokkosMaterialPropertyDecl.h.

Referenced by Moose::Kokkos::MaterialPropertyBase::dim().

97 { return _record->name; }
const PropRecord * _record
Pointer to the record of this property.
std::string name
Property name.

◆ operator bool()

KOKKOS_FUNCTION Moose::Kokkos::MaterialPropertyBase::operator bool ( ) const
inlineinherited

Get whether this property is valid.

Returns
Whether this property is valid

Definition at line 167 of file KokkosMaterialPropertyDecl.h.

167 { return _id != libMesh::invalid_uint || _default; }
const unsigned int invalid_uint
bool _default
Flag whether this property has a default value.

◆ operator()()

template<typename T , unsigned int dimension>
KOKKOS_FUNCTION MaterialPropertyValue< T, dimension > MaterialProperty< T, dimension >::operator() ( const Datum datum,
const unsigned int  qp 
) const

Get the property values of a quadrature point.

Parameters
datumThe Datum object of the current thread
qpThe local quadrature point index
Returns
The MaterialPropertyValue object that provides access to the property values

Definition at line 142 of file KokkosMaterialProperty.h.

143 {
144  return MaterialPropertyValue<T, dimension>(*this, datum, qp);
145 }

◆ operator=()

template<typename T , unsigned int dimension>
auto & MaterialProperty< T, dimension >::operator= ( const MaterialProperty< T, dimension > &  property)

Shallow copy another property.

Parameters
propertyThe property to be shallow copied

Definition at line 55 of file KokkosMaterialProperty.h.

56 {
57  shallowCopy(property);
58 
59  return *this;
60 }
void shallowCopy(const MaterialProperty< T, dimension > &property)
Shallow copy another property.

◆ propertyType()

template<typename T, unsigned int dimension = 0>
virtual std::type_index Moose::Kokkos::MaterialProperty< T, dimension >::propertyType ( )
inlineoverridevirtual

Get the property type index for load/store functions.

Returns
The property type index for the load/store function pointer map lookup

Implements Moose::Kokkos::MaterialPropertyBase.

Definition at line 236 of file KokkosMaterialPropertyDecl.h.

237  {
238  static const std::type_index type = typeid(*this);
239 
240  return type;
241  }
std::string type() const
Get the data type.

◆ shallowCopy()

template<typename T , unsigned int dimension>
void MaterialProperty< T, dimension >::shallowCopy ( const MaterialProperty< T, dimension > &  property)
private

Shallow copy another property.

Parameters
propertyThe property to be shallow copied

Definition at line 100 of file KokkosMaterialProperty.h.

101 {
102  _record = property._record;
103  _id = property._id;
104  _default = property._default;
105 
106  _reference = property._reference;
107  _data = property._data;
108  _value = property._value;
109 }
const PropRecord * _record
Pointer to the record of this property.
const MaterialProperty< T, dimension > * _reference
Pointer to the reference property.
Array< Array< T, dimension+1 > > _data
Data storage.
bool _default
Flag whether this property has a default value.

◆ swap()

template<typename T , unsigned int dimension>
void MaterialProperty< T, dimension >::swap ( MaterialPropertyBase prop,
StorageKey   
)
overridevirtual

Swap with another property.

Parameters
propThe property to swap

Implements Moose::Kokkos::MaterialPropertyBase.

Definition at line 89 of file KokkosMaterialProperty.h.

90 {
91  auto prop_cast = dynamic_cast<MaterialProperty<T, dimension> *>(&prop);
92 
93  mooseAssert(prop_cast, "The property to swap should be of the same type and dimension.");
94 
95  _data.swap(prop_cast->_data);
96 }
Array< Array< T, dimension+1 > > _data
Data storage.

◆ type()

std::string Moose::Kokkos::MaterialPropertyBase::type ( ) const
inlineinherited

Get the data type.

Returns
The demangled data type name

Definition at line 102 of file KokkosMaterialPropertyDecl.h.

Referenced by Moose::Kokkos::MaterialProperty< T, dimension >::propertyType().

102 { return _record->type; }
const PropRecord * _record
Pointer to the record of this property.
std::string type
Demangled data type name.

Friends And Related Function Documentation

◆ MaterialPropertyValueBase< T, dimension >

template<typename T, unsigned int dimension = 0>
friend class MaterialPropertyValueBase< T, dimension >
friend

Definition at line 275 of file KokkosMaterialPropertyDecl.h.

◆ propertyLoad

template<typename T, unsigned int dimension = 0>
void propertyLoad ( std::istream &  ,
void  
)
friend

Definition at line 158 of file KokkosMaterialProperty.h.

159 {
160  auto property = static_cast<MaterialProperty<T, dimension> *>(prop);
161 
162  dataLoad(stream, property->_data, nullptr);
163 }
void dataLoad(std::istream &stream, Array< T, dimension > &array, void *context)
Definition: KokkosArray.h:931

◆ propertyStore

template<typename T, unsigned int dimension = 0>
void propertyStore ( std::ostream &  ,
void  
)
friend

Definition at line 150 of file KokkosMaterialProperty.h.

151 {
152  auto property = static_cast<MaterialProperty<T, dimension> *>(prop);
153 
154  dataStore(stream, property->_data, nullptr);
155 }
void dataStore(std::ostream &stream, Array< T, dimension > &array, void *context)
Definition: KokkosArray.h:887

Member Data Documentation

◆ _data

template<typename T, unsigned int dimension = 0>
Array<Array<T, dimension + 1> > Moose::Kokkos::MaterialProperty< T, dimension >::_data
private

Data storage.

Definition at line 269 of file KokkosMaterialPropertyDecl.h.

◆ _default

bool Moose::Kokkos::MaterialPropertyBase::_default = false
protectedinherited

Flag whether this property has a default value.

Definition at line 182 of file KokkosMaterialPropertyDecl.h.

Referenced by Moose::Kokkos::MaterialPropertyBase::operator bool().

◆ _id

unsigned int Moose::Kokkos::MaterialPropertyBase::_id = libMesh::invalid_uint
protectedinherited

◆ _record

const PropRecord* Moose::Kokkos::MaterialPropertyBase::_record = nullptr
protectedinherited

◆ _reference

template<typename T, unsigned int dimension = 0>
const MaterialProperty<T, dimension>* Moose::Kokkos::MaterialProperty< T, dimension >::_reference = nullptr
private

Pointer to the reference property.

Definition at line 265 of file KokkosMaterialPropertyDecl.h.

◆ _value

template<typename T, unsigned int dimension = 0>
T Moose::Kokkos::MaterialProperty< T, dimension >::_value
private

Default value.

Definition at line 273 of file KokkosMaterialPropertyDecl.h.


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