https://mooseframework.inl.gov
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 
18 class MooseMesh;
19 class MaterialBase;
20 
21 namespace Moose
22 {
23 namespace Kokkos
24 {
25 
27 
29 
30 template <typename T, unsigned int dimension>
32 
33 template <typename T, unsigned int dimension>
35 
36 class Datum;
37 class Assembly;
38 
42 struct PropRecord
43 {
47  std::set<const ::MaterialBase *> declarers;
51  std::string name;
55  std::string type;
59  unsigned int id = libMesh::invalid_uint;
63  std::vector<unsigned int> dims;
67  bool bnd = false;
68 };
69 
70 using PropertyStore = std::function<void(std::ostream &, void *)>;
71 using PropertyLoad = std::function<void(std::istream &, void *)>;
72 
77 {
78 public:
82  MaterialPropertyBase() = default;
86  virtual ~MaterialPropertyBase() {}
87 
92  unsigned int id() const { return _id; }
97  std::string name() const { return _record->name; }
102  std::string type() const { return _record->type; }
107  unsigned int dim() const { return _record->dims.size(); }
113  unsigned int dim(unsigned int i) const
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  }
126 
131  virtual std::type_index propertyType() = 0;
132 
137  virtual void init(const PropRecord & record, const StorageKey &);
138 
146  virtual void allocate(const MooseMesh & mesh,
147  const Assembly & assembly,
148  const std::set<SubdomainID> & subdomains,
149  const bool bnd,
150  StorageKey) = 0;
155  virtual void copy(const MaterialPropertyBase & prop, StorageKey) = 0;
160  virtual void swap(MaterialPropertyBase & prop, StorageKey) = 0;
161 
162 #ifdef MOOSE_KOKKOS_SCOPE
163 
167  KOKKOS_FUNCTION operator bool() const { return _id != libMesh::invalid_uint || _default; }
168 #endif
169 
170 protected:
174  const PropRecord * _record = nullptr;
178  unsigned int _id = libMesh::invalid_uint;
182  bool _default = false;
183 };
184 
185 template <typename T, unsigned int dimension>
186 void propertyStore(std::ostream & stream, void * prop);
187 template <typename T, unsigned int dimension>
188 void propertyLoad(std::istream & stream, void * prop);
189 
193 template <typename T, unsigned int dimension = 0>
195 {
196 public:
200  MaterialProperty() = default;
205  MaterialProperty(const T & value);
218 
223  auto & operator=(const MaterialProperty<T, dimension> & property);
224 
225 #ifdef MOOSE_KOKKOS_SCOPE
226 
232  KOKKOS_FUNCTION MaterialPropertyValue<T, dimension> operator()(const Datum & datum,
233  const unsigned int qp) const;
234 #endif
235 
236  virtual std::type_index propertyType() override
237  {
238  static const std::type_index type = typeid(*this);
239 
240  return type;
241  }
242 
243  virtual void init(const PropRecord & record, const StorageKey & key) override;
244 
245 #ifdef MOOSE_KOKKOS_SCOPE
246  virtual void allocate(const MooseMesh & mesh,
247  const Assembly & assembly,
248  const std::set<SubdomainID> & subdomains,
249  const bool bnd,
250  StorageKey) override;
251  virtual void copy(const MaterialPropertyBase & prop, StorageKey) override;
252  virtual void swap(MaterialPropertyBase & prop, StorageKey) override;
253 #endif
254 
255 private:
260  void shallowCopy(const MaterialProperty<T, dimension> & property);
261 
274 
275  friend class MaterialPropertyValueBase<T, dimension>;
276 
277  friend void propertyStore<T, dimension>(std::ostream &, void *);
278  friend void propertyLoad<T, dimension>(std::istream &, void *);
279 };
280 
281 // The Kokkos array containing Kokkos material properties requires a deep copy because the copy
282 // constructor of each Kokkos material property should be invoked
283 template <typename T, unsigned int dimension>
284 struct ArrayDeepCopy<MaterialProperty<T, dimension>>
285 {
286  static const bool value = true;
287 };
288 
289 } // namespace Kokkos
290 } // namespace Moose
virtual void init(const PropRecord &record, const StorageKey &)
Initialize this property.
The Kokkos array class.
Definition: KokkosArray.h:56
The Kokkos assembly class.
A structure storing the metadata of Kokkos material properties.
The base class for Kokkos material properties.
KOKKOS_FUNCTION MaterialPropertyValue< T, dimension > operator()(const Datum &datum, const unsigned int qp) const
Get the property values of a quadrature point.
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object...
Definition: KokkosDatum.h:25
const PropRecord * _record
Pointer to the record of this property.
const unsigned int invalid_uint
virtual std::type_index propertyType()=0
Get the property type index for load/store functions.
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)
Stores the stateful material properties computed by materials.
virtual void init(const PropRecord &record, const StorageKey &key) override
Initialize this property.
std::function< void(std::istream &, void *)> PropertyLoad
virtual void swap(MaterialPropertyBase &prop, StorageKey) override
Swap with another property.
virtual std::type_index propertyType() override
Get the property type index for load/store functions.
virtual void allocate(const MooseMesh &mesh, const Assembly &assembly, const std::set< SubdomainID > &subdomains, const bool bnd, StorageKey) override
Allocate the data storage.
std::string name
Property name.
unsigned int dim(unsigned int i) const
Get the size of a dimension.
virtual void swap(MaterialPropertyBase &prop, StorageKey)=0
Swap with another property.
virtual void copy(const MaterialPropertyBase &prop, StorageKey)=0
Deep copy another property.
std::string type
Demangled data type name.
auto & operator=(const MaterialProperty< T, dimension > &property)
Shallow copy another property.
std::vector< unsigned int > dims
Size of each dimension.
The Kokkos wrapper class for accessing the material property values of a single quadrature point...
static const bool value
Definition: KokkosArray.h:69
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::set< const ::MaterialBase * > declarers
List of declaring materials.
MaterialProperty()=default
Default constructor.
const MaterialProperty< T, dimension > * _reference
Pointer to the reference property.
unsigned int dim() const
Get the dimension.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:92
std::function< void(std::ostream &, void *)> PropertyStore
Array< Array< T, dimension+1 > > _data
Data storage.
virtual void copy(const MaterialPropertyBase &prop, StorageKey) override
Deep copy another property.
bool _default
Flag whether this property has a default value.
The type trait that determines the default behavior of copy constructor and deepCopy() If this type t...
Definition: KokkosArray.h:67
void shallowCopy(const MaterialProperty< T, dimension > &property)
Shallow copy another property.
std::string type() const
Get the data type.
std::string name() const
Get the property name.
virtual void allocate(const MooseMesh &mesh, const Assembly &assembly, const std::set< SubdomainID > &subdomains, const bool bnd, StorageKey)=0
Allocate the data storage.
MaterialPropertyBase()=default
Default constructor.
bool bnd
Flag whether this property is a face property.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
The Kokkos material property class.
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:62
unsigned int id() const
Get the property ID.
void propertyStore(std::ostream &stream, void *prop)