https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosMaterialPropertyDecl.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://www.mooseframework.org
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "KokkosArray.h"
13
14#include "MoosePassKey.h"
15
16#include <typeindex>
17
18class MaterialBase;
19
20namespace Moose::Kokkos
21{
22
24
26
27template <typename T, unsigned int dimension>
29
30template <typename T, unsigned int dimension>
32
33class Datum;
34class Assembly;
35class Mesh;
36
41{
42 NONE,
43 ELEMENT,
45};
46
51{
55 std::set<const ::MaterialBase *> declarers;
59 std::string name;
63 std::string type;
67 unsigned int id = libMesh::invalid_uint;
71 std::unordered_map<SubdomainID, std::vector<unsigned int>> dims;
75 bool bnd = false;
79 bool on_demand = false;
83 std::unordered_map<SubdomainID, PropertyConstantOption> constant_option;
84};
85
86using PropertyStore = std::function<void(std::ostream &, void *)>;
87using PropertyLoad = std::function<void(std::istream &, void *)>;
88
93{
94public:
103
108 unsigned int id() const { return _id; }
113 const std::string & name() const;
118 const std::string & type() const;
123 unsigned int dim() const;
130 unsigned int dimSize(SubdomainID subdomain, unsigned int i) const;
131
136 virtual std::type_index propertyType() = 0;
137
142 virtual void init(const PropRecord & record, const StorageKey &);
143
151 virtual void allocate(const Mesh & mesh,
152 const Assembly & assembly,
153 const std::set<SubdomainID> & subdomains,
154 const bool bnd,
155 StorageKey) = 0;
160 virtual void copy(const MaterialPropertyBase & prop, StorageKey) = 0;
165 virtual void swap(MaterialPropertyBase & prop, StorageKey) = 0;
166
167protected:
171 const PropRecord * _record = nullptr;
179 bool _default = false;
184};
185
186inline const std::string &
188{
189 if (!_record)
190 mooseError("Cannot get the name of an uninitialized or default material property.");
191 else
192 return _record->name;
193}
194
195inline const std::string &
197{
198 if (!_record)
199 mooseError("Cannot get the type of an uninitialized or default material property.");
200 else
201 return _record->type;
202}
203
204inline unsigned int
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}
212
213inline unsigned int
214MaterialPropertyBase::dimSize(SubdomainID subdomain, unsigned int i) const
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}
229
230template <typename T, unsigned int dimension>
231void propertyStore(std::ostream & stream, void * prop);
232template <typename T, unsigned int dimension>
233void propertyLoad(std::istream & stream, void * prop);
234
238template <typename T, unsigned int dimension = 0>
240{
241public:
245 MaterialProperty() = default;
250 MaterialProperty(const T & value);
266 template <unsigned int D>
268
273 auto & operator=(const MaterialProperty<T, dimension> & property);
274
275#ifdef MOOSE_KOKKOS_SCOPE
280 KOKKOS_FUNCTION operator bool() const { return _data.isAlloc() || _default; }
281
288 KOKKOS_FUNCTION MaterialPropertyValue<T, dimension> operator()(const Datum & datum,
289 const unsigned int qp) const;
290#endif
291
292 virtual std::type_index propertyType() override
293 {
294 return std::type_index(typeid(MaterialProperty<T, dimension>));
295 }
296
297 virtual void init(const PropRecord & record, const StorageKey & key) override;
298
299#ifdef MOOSE_KOKKOS_SCOPE
300 virtual void allocate(const Mesh & mesh,
301 const Assembly & assembly,
302 const std::set<SubdomainID> & subdomains,
303 const bool bnd,
304 StorageKey) override;
305 virtual void copy(const MaterialPropertyBase & prop, StorageKey) override;
306 virtual void swap(MaterialPropertyBase & prop, StorageKey) override;
307#endif
308
309private:
314 void shallowCopy(const MaterialProperty<T, dimension> & property);
315
328
329 friend class MaterialPropertyValueBase<T, dimension>;
330
331 friend void propertyStore<T, dimension>(std::ostream &, void *);
332 friend void propertyLoad<T, dimension>(std::istream &, void *);
333};
334
335// The Kokkos array containing Kokkos material properties requires a deep copy because the copy
336// constructor of each Kokkos material property should be invoked
337template <typename T, unsigned int dimension>
338struct ArrayDeepCopy<MaterialProperty<T, dimension>>
339{
340 static constexpr bool value = true;
341};
342
343} // namespace Moose::Kokkos
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
MaterialBases compute MaterialProperties.
Stores the stateful material properties computed by materials.
The Kokkos array class.
The Kokkos assembly class.
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object.
The base class for Kokkos material properties.
const std::string & name() const
Get the property name.
virtual std::type_index propertyType()=0
Get the property type index for load/store functions.
virtual void allocate(const Mesh &mesh, const Assembly &assembly, const std::set< SubdomainID > &subdomains, const bool bnd, StorageKey)=0
Allocate the data storage.
unsigned int dim() const
Get the dimension.
Array< PropertyConstantOption > _constant_option
Whether this property is constant over element or subdomain in each subdomain.
const std::string & type() const
Get the data type.
bool _default
Flag whether this property has a default value.
virtual void swap(MaterialPropertyBase &prop, StorageKey)=0
Swap with another property.
unsigned int dimSize(SubdomainID subdomain, unsigned int i) const
Get the size of a dimension.
const PropRecord * _record
Pointer to the record of this property.
MaterialPropertyBase()=default
Default constructor.
virtual void copy(const MaterialPropertyBase &prop, StorageKey)=0
Deep copy another property.
unsigned int id() const
Get the property ID.
virtual void init(const PropRecord &record, const StorageKey &)
Initialize this property.
The Kokkos wrapper class for accessing the material property values of a single quadrature point.
The Kokkos material property class.
virtual void swap(MaterialPropertyBase &prop, StorageKey) override
Swap with another property.
auto & operator=(const MaterialProperty< T, dimension > &property)
Shallow copy another property.
virtual std::type_index propertyType() override
Get the property type index for load/store functions.
MaterialProperty()=default
Default constructor.
void shallowCopy(const MaterialProperty< T, dimension > &property)
Shallow copy another 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.
const MaterialProperty< T, dimension > * _reference
Pointer to the reference property.
Array< Array< T, dimension+1 > > _data
Data storage.
MaterialProperty(const MaterialProperty< T, D > &other)=delete
Prevent initializing with properties of different rank.
KOKKOS_FUNCTION MaterialPropertyValue< T, dimension > operator()(const Datum &datum, const unsigned int qp) const
Get the property values of a quadrature point.
virtual void init(const PropRecord &record, const StorageKey &key) override
Initialize this property.
The Kokkos mesh object.
Definition KokkosMesh.h:53
std::function< void(std::istream &, void *)> PropertyLoad
void propertyLoad(std::istream &stream, void *prop)
std::function< void(std::ostream &, void *)> PropertyStore
PropertyConstantOption
Property constant options.
void propertyStore(std::ostream &stream, void *prop)
const unsigned int invalid_uint
The type trait that determines the default behavior of copy constructor and deepCopy() If this type t...
Definition KokkosArray.h:92
static constexpr bool value
Definition KokkosArray.h:93
A structure storing the metadata of Kokkos material properties.
std::set< const ::MaterialBase * > declarers
List of declaring materials.
bool bnd
Flag whether this property is a face property.
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.
bool on_demand
Flag whether this property is an on-demand property.
std::string type
Demangled data type name.