https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosMaterialProperty.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
13
14#ifdef MOOSE_KOKKOS_SCOPE
16#endif
17
18#include "KokkosAssembly.h"
19#include "KokkosMesh.h"
20
21namespace Moose::Kokkos
22{
23
24inline void
26{
27 _record = &record;
28 _id = record.id;
29}
30
31template <typename T, unsigned int dimension>
33{
34 _default = true;
35 _value = value;
36}
37
38template <typename T, unsigned int dimension>
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}
49
50template <typename T, unsigned int dimension>
51auto &
53{
54 shallowCopy(property);
55
56 return *this;
57}
58
59template <typename T, unsigned int dimension>
60void
62{
63 MaterialPropertyBase::init(record, key);
64
65 _reference = this;
66}
67
68#ifdef MOOSE_KOKKOS_SCOPE
69template <typename T, unsigned int dimension>
70void
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}
83
84template <typename T, unsigned int dimension>
85void
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}
94
95template <typename T, unsigned int dimension>
96void
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}
108
109template <typename T, unsigned int dimension>
110void
112 const Assembly & assembly,
113 const std::set<SubdomainID> & subdomains,
114 const bool bnd,
116{
117 if (!_data.isAlloc())
118 _data.create(mesh.getNumSubdomains());
119
120 if (!_constant_option.isAlloc())
121 {
122 _constant_option.create(mesh.getNumSubdomains());
123 _constant_option = PropertyConstantOption::NONE;
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();
153 _constant_option.copyToDevice();
154}
155
156template <typename T, unsigned int dimension>
158MaterialProperty<T, dimension>::operator()(const Datum & datum, const unsigned int qp) const
159{
160 return MaterialPropertyValue<T, dimension>(*this, datum, qp);
161}
162#endif
163
164template <typename T, unsigned int dimension>
165void
166propertyStore(std::ostream & stream, void * prop)
167{
168 auto property = static_cast<MaterialProperty<T, dimension> *>(prop);
169
170 dataStore(stream, property->_data, nullptr);
171}
172template <typename T, unsigned int dimension>
173void
174propertyLoad(std::istream & stream, void * prop)
175{
176 auto property = static_cast<MaterialProperty<T, dimension> *>(prop);
177
178 dataLoad(stream, property->_data, nullptr);
179}
180
181} // namespace Moose::Kokkos
The Kokkos assembly class.
KOKKOS_FUNCTION dof_id_type getNumFaceQps(ContiguousSubdomainID subdomain) const
Get the total number of facial quadrature points in a subdomain NOTE: This number does not represent ...
KOKKOS_FUNCTION dof_id_type getElemFacePropertySize(ContiguousSubdomainID subdomain) const
Get the size of element-constant face material property data storage of a subdomain.
KOKKOS_FUNCTION dof_id_type getNumQps(ContiguousSubdomainID subdomain) const
Get the total number of elemental quadrature points in a subdomain.
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object.
The base class for Kokkos material properties.
const PropRecord * _record
Pointer to the record of this property.
virtual void init(const PropRecord &record, const StorageKey &)
Initialize this property.
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.
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.
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
MeshBase & mesh
void dataLoad(std::istream &stream, Array< T, dimension, index_type, layout > &array, void *context)
void propertyLoad(std::istream &stream, void *prop)
void propertyStore(std::ostream &stream, void *prop)
void dataStore(std::ostream &stream, Array< T, dimension, index_type, layout > &array, void *context)
A structure storing the metadata of Kokkos material properties.