https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.
 
 MaterialProperty (const T &value)
 Constructor for default property.
 
 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.
 
template<unsigned int D>
 MaterialProperty (const MaterialProperty< T, D > &other)=delete
 Prevent initializing with properties of different rank.
 
auto & operator= (const MaterialProperty< T, dimension > &property)
 Shallow copy another property.
 
KOKKOS_FUNCTION operator bool () const
 Get whether this property is valid.
 
KOKKOS_FUNCTION MaterialPropertyValue< T, dimension > operator() (const Datum &datum, const unsigned int qp) const
 Get the property values of a quadrature point.
 
virtual std::type_index propertyType () override
 Get the property type index for load/store functions.
 
virtual void init (const PropRecord &record, const StorageKey &key) override
 Initialize this property.
 
virtual void allocate (const Mesh &mesh, const Assembly &assembly, const std::set< SubdomainID > &subdomains, const bool bnd, StorageKey) override
 Allocate the data storage.
 
virtual void copy (const MaterialPropertyBase &prop, StorageKey) override
 Deep copy another property.
 
virtual void swap (MaterialPropertyBase &prop, StorageKey) override
 Swap with another property.
 
unsigned int id () const
 Get the property ID.
 
const std::string & name () const
 Get the property name.
 
const std::string & type () const
 Get the data type.
 
unsigned int dim () const
 Get the dimension.
 
unsigned int dimSize (SubdomainID subdomain, unsigned int i) const
 Get the size of a dimension.
 

Protected Attributes

const PropRecord_record = nullptr
 Pointer to the record of this property.
 
unsigned int _id = libMesh::invalid_uint
 Property ID.
 
bool _default = false
 Flag whether this property has a default value.
 
Array< PropertyConstantOption_constant_option
 Whether this property is constant over element or subdomain in each subdomain.
 

Private Member Functions

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

Private Attributes

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

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}
bool _default
Flag whether this property has a default value.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ 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}
void shallowCopy(const MaterialProperty< T, dimension > &property)
Shallow copy another property.
const MaterialProperty< T, dimension > * _reference
Pointer to the reference 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
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
154}
void copyToDevice()
Copy data from host to device.
KOKKOS_FUNCTION bool isAlloc() const
Get whether the array was allocated either on host or device.
void create(const std::vector< index_type > &n)
Allocate array on host and device.
Array< PropertyConstantOption > _constant_option
Whether this property is constant over element or subdomain in each subdomain.
const PropRecord * _record
Pointer to the record of this property.
Array< Array< T, dimension+1 > > _data
Data storage.
MeshBase & mesh
std::unordered_map< SubdomainID, std::vector< unsigned int > > dims
Size of each dimension of 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}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
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.

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}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311

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

◆ 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 std::string & name() const
Get the property name.
unsigned int dim() const
Get the dimension.

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

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

188{
189 if (!_record)
190 mooseError("Cannot get the name of an uninitialized or default material property.");
191 else
192 return _record->name;
193}

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

◆ 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; }

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

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

◆ 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 return std::type_index(typeid(MaterialProperty<T, dimension>));
295 }

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

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

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

197{
198 if (!_record)
199 mooseError("Cannot get the type of an uninitialized or default material property.");
200 else
201 return _record->type;
202}
std::string type
Demangled data type name.

Friends And Related Symbol Documentation

◆ MaterialPropertyValueBase< T, dimension >

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

Definition at line 327 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)

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

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

◆ _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< T, dimension >::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 319 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 327 of file KokkosMaterialPropertyDecl.h.


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