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...
 
template<unsigned int D>
 MaterialProperty (const MaterialProperty< T, D > &other)=delete
 Prevent initializing with properties of different rank. More...
 
auto & operator= (const MaterialProperty< T, dimension > &property)
 Shallow copy another property. More...
 
KOKKOS_FUNCTION operator bool () const
 Get whether this property is valid. 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 Mesh &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...
 
const std::string & name () const
 Get the property name. More...
 
const std::string & type () const
 Get the data type. More...
 
unsigned int dim () const
 Get the dimension. More...
 
unsigned int dimSize (SubdomainID subdomain, unsigned int i) const
 Get the size of a dimension. 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...
 
Array< PropertyConstantOption_constant_option
 Whether this property is constant over element or subdomain in each subdomain. 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 239 of file KokkosMaterialPropertyDecl.h.

Constructor & Destructor Documentation

◆ MaterialProperty() [1/4]

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

Default constructor.

◆ MaterialProperty() [2/4]

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

Constructor for default property.

Parameters
valueThe default value

Definition at line 32 of file KokkosMaterialProperty.h.

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

◆ MaterialProperty() [3/4]

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 39 of file KokkosMaterialProperty.h.

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

◆ MaterialProperty() [4/4]

template<typename T, unsigned int dimension = 0>
template<unsigned int D>
Moose::Kokkos::MaterialProperty< T, dimension >::MaterialProperty ( const MaterialProperty< T, D > &  other)
delete

Prevent initializing with properties of different rank.

Member Function Documentation

◆ allocate()

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

Allocate the data storage.

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

Implements Moose::Kokkos::MaterialPropertyBase.

Definition at line 111 of file KokkosMaterialProperty.h.

116 {
117  if (!_data.isAlloc())
118  _data.create(mesh.getNumSubdomains());
119 
120  if (!_constant_option.isAlloc())
121  {
122  _constant_option.create(mesh.getNumSubdomains());
124  }
125 
126  for (const auto subdomain : subdomains)
127  {
128  auto sid = mesh.getContiguousSubdomainID(subdomain);
129  auto constant_option = libmesh_map_find(_record->constant_option, subdomain);
130 
131  using index_type = typename std::remove_reference_t<decltype(_data[sid])>::unsigned_index_type;
132 
133  std::vector<index_type> n;
134 
135  for (unsigned int i = 0; i < dimension; ++i)
136  n.push_back(libmesh_map_find(_record->dims, subdomain)[i]);
137 
138  if (constant_option == PropertyConstantOption::NONE)
139  n.push_back(bnd ? assembly.getNumFaceQps(sid) : assembly.getNumQps(sid));
140  else if (constant_option == PropertyConstantOption::ELEMENT)
141  n.push_back(bnd ? assembly.getElemFacePropertySize(sid)
142  : mesh.getNumSubdomainLocalElements(subdomain));
143  else
144  n.push_back(1);
145 
146  if (!_data[sid].isAlloc())
147  _data[sid].createDevice(n);
148 
149  _constant_option[sid] = constant_option;
150  }
151 
152  _data.copyToDevice();
154 }
const PropRecord * _record
Pointer to the record of this property.
MeshBase & mesh
std::unordered_map< SubdomainID, std::vector< unsigned int > > dims
Size of each dimension of each subdomain.
KOKKOS_FUNCTION bool isAlloc() const
Get whether the array was allocated either on host or device.
Definition: KokkosArray.h:180
void create(const std::vector< index_type > &n)
Allocate array on host and device.
Definition: KokkosArray.h:303
Array< Array< T, dimension+1 > > _data
Data storage.
void copyToDevice()
Copy data from host to device.
Definition: KokkosArray.h:947
Array< PropertyConstantOption > _constant_option
Whether this property is constant over element or subdomain in each subdomain.
std::unordered_map< SubdomainID, PropertyConstantOption > constant_option
Whether this property is constant over element or subdomain in each subdomain.

◆ 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 71 of file KokkosMaterialProperty.h.

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

◆ dim()

unsigned int MaterialPropertyBase< T, is_ad >::dim ( ) const
inlineinherited

Get the dimension.

Returns
The dimension

Definition at line 205 of file KokkosMaterialPropertyDecl.h.

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

206 {
207  if (!_record || !_record->dims.size())
208  mooseError("Cannot get the dimension of an uninitialized or default material property.");
209  else
210  return _record->dims.begin()->second.size();
211 }
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:311
std::unordered_map< SubdomainID, std::vector< unsigned int > > dims
Size of each dimension of each subdomain.

◆ dimSize()

unsigned int MaterialPropertyBase< T, is_ad >::dimSize ( SubdomainID  subdomain,
unsigned int  i 
) const
inlineinherited

Get the size of a dimension.

Parameters
subdomainThe MOOSE subdomain ID
iThe dimension index
Returns
The size of the dimension

Definition at line 214 of file KokkosMaterialPropertyDecl.h.

215 {
216  const unsigned int D = dim();
217 
218  if (i >= D)
219  mooseError("Cannot get the size of ",
220  i,
221  "-th dimension for the ",
222  D,
223  "D material property '",
224  name(),
225  "'.");
226 
227  return libmesh_map_find(_record->dims, subdomain)[i];
228 }
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:311
std::unordered_map< SubdomainID, std::vector< unsigned int > > dims
Size of each dimension of each subdomain.
unsigned int dim() const
Get the dimension.
const 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 108 of file KokkosMaterialPropertyDecl.h.

108 { 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 61 of file KokkosMaterialProperty.h.

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

◆ name()

const std::string & MaterialPropertyBase< T, is_ad >::name ( ) const
inlineinherited

Get the property name.

Returns
The property name

Definition at line 187 of file KokkosMaterialPropertyDecl.h.

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

188 {
189  if (!_record)
190  mooseError("Cannot get the name of an uninitialized or default material property.");
191  else
192  return _record->name;
193 }
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:311
std::string name
Property name.

◆ operator bool()

template<typename T, unsigned int dimension = 0>
KOKKOS_FUNCTION Moose::Kokkos::MaterialProperty< T, dimension >::operator bool ( ) const
inline

Get whether this property is valid.

Returns
Whether this property is valid

Definition at line 280 of file KokkosMaterialPropertyDecl.h.

280 { return _data.isAlloc() || _default; }
Array< Array< T, dimension+1 > > _data
Data storage.
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 158 of file KokkosMaterialProperty.h.

159 {
160  return MaterialPropertyValue<T, dimension>(*this, datum, qp);
161 }

◆ 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 52 of file KokkosMaterialProperty.h.

53 {
54  shallowCopy(property);
55 
56  return *this;
57 }
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 292 of file KokkosMaterialPropertyDecl.h.

293  {
294  static const std::type_index type = typeid(*this);
295 
296  return type;
297  }
const 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 97 of file KokkosMaterialProperty.h.

98 {
99  _record = property._record;
100  _id = property._id;
101  _default = property._default;
102  _constant_option = property._constant_option;
103 
104  _reference = property._reference;
105  _data = property._data;
106  _value = property._value;
107 }
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.
Array< PropertyConstantOption > _constant_option
Whether this property is constant over element or subdomain in each subdomain.

◆ 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 86 of file KokkosMaterialProperty.h.

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

◆ type()

const std::string & MaterialPropertyBase< T, is_ad >::type ( ) const
inlineinherited

Get the data type.

Returns
The demangled data type name

Definition at line 196 of file KokkosMaterialPropertyDecl.h.

Referenced by Moose::Kokkos::MaterialProperty< Real >::propertyType().

197 {
198  if (!_record)
199  mooseError("Cannot get the type of an uninitialized or default material property.");
200  else
201  return _record->type;
202 }
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:311
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 331 of file KokkosMaterialPropertyDecl.h.

◆ propertyLoad

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

Definition at line 174 of file KokkosMaterialProperty.h.

175 {
176  auto property = static_cast<MaterialProperty<T, dimension> *>(prop);
177 
178  dataLoad(stream, property->_data, nullptr);
179 }
void dataLoad(std::istream &stream, Array< T, dimension, index_type, layout > &array, void *context)
Definition: KokkosArray.h:1269

◆ propertyStore

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

Definition at line 166 of file KokkosMaterialProperty.h.

167 {
168  auto property = static_cast<MaterialProperty<T, dimension> *>(prop);
169 
170  dataStore(stream, property->_data, nullptr);
171 }
void dataStore(std::ostream &stream, Array< T, dimension, index_type, layout > &array, void *context)
Definition: KokkosArray.h:1225

Member Data Documentation

◆ _constant_option

Array<PropertyConstantOption> Moose::Kokkos::MaterialPropertyBase::_constant_option
protectedinherited

Whether this property is constant over element or subdomain in each subdomain.

Definition at line 183 of file KokkosMaterialPropertyDecl.h.

◆ _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 325 of file KokkosMaterialPropertyDecl.h.

Referenced by Moose::Kokkos::MaterialProperty< Real >::operator bool().

◆ _default

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

Flag whether this property has a default value.

Definition at line 179 of file KokkosMaterialPropertyDecl.h.

Referenced by Moose::Kokkos::MaterialProperty< Real >::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 321 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 329 of file KokkosMaterialPropertyDecl.h.


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