https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosMaterial.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// initQpStatefulProperties() and computeQpProperties() are intentionally hidden
13// but some compilers generate ugly warnings
14
15#if defined(__clang__)
16#pragma clang diagnostic push
17#pragma clang diagnostic ignored "-Woverloaded-virtual"
18#elif defined(__GNUC__) || defined(__GNUG__)
19#pragma GCC diagnostic push
20#pragma GCC diagnostic ignored "-Woverloaded-virtual"
21#endif
22
23#include "KokkosMaterialBase.h"
24#include "KokkosDatum.h"
25
26#include "Coupleable.h"
28
29namespace Moose::Kokkos
30{
31
51{
52public:
54
59
63 Material(const Material & object);
64
68 virtual void initStatefulProperties(unsigned int) override;
72 virtual void computeProperties() override;
73
79
85 template <typename Derived>
86 KOKKOS_FUNCTION void initQpStatefulProperties(const unsigned int /* qp */,
87 Datum & /* datum */) const
88 {
89 ::Kokkos::abort(
90 "Default initQpStatefulProperties() should never be called. Make sure you properly "
91 "redefined this method in your class without typos.");
92 }
94
101 template <typename Derived>
103 {
104 return &Material::initQpStatefulProperties<Derived>;
105 }
107
112 template <typename Derived>
113 KOKKOS_FUNCTION void operator()(ElementInit, const ThreadID tid, const Derived & material) const;
114 template <typename Derived>
115 KOKKOS_FUNCTION void operator()(SideInit, const ThreadID tid, const Derived & material) const;
116 template <typename Derived>
117 KOKKOS_FUNCTION void operator()(NeighborInit, const ThreadID tid, const Derived & material) const;
118 template <typename Derived>
119 KOKKOS_FUNCTION void
120 operator()(ElementCompute, const ThreadID tid, const Derived & material) const;
121 template <typename Derived>
122 KOKKOS_FUNCTION void operator()(SideCompute, const ThreadID tid, const Derived & material) const;
123 template <typename Derived>
124 KOKKOS_FUNCTION void
125 operator()(NeighborCompute, const ThreadID tid, const Derived & material) const;
127
128protected:
133 void getKokkosMaterialPropertyHook(const std::string & prop_name_in,
134 const unsigned int state) override final;
135
136 virtual void checkMaterialProperty(const std::string & name, const unsigned int state) override
137 {
138 // Avoid performing duplicate checks for triple block/face/neighbor materials
139 if (boundaryRestricted() || !_bnd)
141 }
142
143 virtual bool isBoundaryMaterial() const override { return _bnd; }
144
145 virtual const std::unordered_set<unsigned int> & getMatPropDependencies() const override
146 {
148 }
149
150 virtual const MaterialData & materialData() const override { return _material_data; }
151 virtual MaterialData & materialData() override { return _material_data; }
153
157 const bool _bnd;
161 const bool _neighbor;
162
163private:
168 const QBase * const & _qrule;
169 virtual const QBase & qRule() const override { return *_qrule; }
171};
172
173template <typename Derived>
174KOKKOS_FUNCTION void
175Material::operator()(ElementInit, const ThreadID tid, const Derived & material) const
176{
177 // When constant option is subdomain, elem is an arbitrary element in each subdomain, and thus
178 // datum is invalid
179 auto elem = kokkosElementID(tid);
180
181 Datum datum(elem, libMesh::invalid_uint, kokkosAssembly(), kokkosSystems());
182
183 const unsigned int num_qps = _constant_option == PropertyConstantOption::NONE ? datum.n_qps() : 1;
184
185 for (unsigned int qp = 0; qp < num_qps; ++qp)
186 material.template initQpStatefulProperties<Derived>(qp, datum);
187}
188
189template <typename Derived>
190KOKKOS_FUNCTION void
191Material::operator()(SideInit, const ThreadID tid, const Derived & material) const
192{
193 auto [elem, side] = kokkosElementSideID(tid);
194
195 Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
196
197 const unsigned int num_qps = _constant_option == PropertyConstantOption::NONE ? datum.n_qps() : 1;
198
199 for (unsigned int qp = 0; qp < num_qps; ++qp)
200 material.template initQpStatefulProperties<Derived>(qp, datum);
201}
202
203template <typename Derived>
204KOKKOS_FUNCTION void
205Material::operator()(NeighborInit, const ThreadID tid, const Derived & material) const
206{
207 auto [elem, side] = kokkosElementSideID(tid);
208
209 Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
210
211 const unsigned int num_qps = _constant_option == PropertyConstantOption::NONE ? datum.n_qps() : 1;
212
213 for (unsigned int qp = 0; qp < num_qps; ++qp)
214 material.template initQpStatefulProperties<Derived>(qp, datum);
215}
216
217template <typename Derived>
218KOKKOS_FUNCTION void
219Material::operator()(ElementCompute, const ThreadID tid, const Derived & material) const
220{
221 // When constant option is subdomain, elem is an arbitrary element in each subdomain, and thus
222 // datum is invalid
223 auto elem = kokkosElementID(tid);
224
225 Datum datum(elem, libMesh::invalid_uint, kokkosAssembly(), kokkosSystems());
226
227 const unsigned int num_qps = _constant_option == PropertyConstantOption::NONE ? datum.n_qps() : 1;
228
229 for (unsigned int qp = 0; qp < num_qps; ++qp)
230 material.template computeQpProperties<Derived>(qp, datum);
231}
232
233template <typename Derived>
234KOKKOS_FUNCTION void
235Material::operator()(SideCompute, const ThreadID tid, const Derived & material) const
236{
237 auto [elem, side] = kokkosElementSideID(tid);
238
239 Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
240
241 const unsigned int num_qps = _constant_option == PropertyConstantOption::NONE ? datum.n_qps() : 1;
242
243 for (unsigned int qp = 0; qp < num_qps; ++qp)
244 material.template computeQpProperties<Derived>(qp, datum);
245}
246
247template <typename Derived>
248KOKKOS_FUNCTION void
249Material::operator()(NeighborCompute, const ThreadID tid, const Derived & material) const
250{
251 auto [elem, side] = kokkosElementSideID(tid);
252
253 Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
254
255 const unsigned int num_qps = _constant_option == PropertyConstantOption::NONE ? datum.n_qps() : 1;
256
257 for (unsigned int qp = 0; qp < num_qps; ++qp)
258 material.template computeQpProperties<Derived>(qp, datum);
259}
260
261} // namespace Moose::Kokkos
virtual bool boundaryRestricted() const
Returns true if this object has been restricted to a boundary.
Interface for objects that needs coupling capabilities.
Definition Coupleable.h:53
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Proxy for accessing MaterialPropertyStorage.
An interface for accessing Materials.
virtual void checkMaterialProperty(const std::string &name, const unsigned int state)
A helper method for checking material properties This method was required to avoid a compiler problem...
const Moose::MaterialDataType _material_data_type
The type of data.
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const
Retrieve the set of material properties that this object depends on.
MaterialData & _material_data
The material data class that stores properties.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object.
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
The base class for Kokkos materials.
KOKKOS_FUNCTION auto kokkosElementSideID(ThreadID tid) const
Get the contiguous element ID - side index pair for a thread.
KOKKOS_FUNCTION ContiguousElementID kokkosElementID(ThreadID tid) const
Get the contiguous element ID for a thread.
const PropertyConstantOption _constant_option
Whether the properties declared by this material are constant over element or subdomain.
The base class for a user to derive their own Kokkos materials.
KOKKOS_FUNCTION void initQpStatefulProperties(const unsigned int, Datum &) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
const QBase *const & _qrule
Dummy members unused for Kokkos materials.
virtual MaterialDataType materialDataType() override
virtual void initStatefulProperties(unsigned int) override
Dispatch stateful material property initialization.
virtual bool isBoundaryMaterial() const override
Returns true of the MaterialData type is not associated with volume data.
Material(const InputParameters &parameters)
Constructor.
virtual const QBase & qRule() const override
virtual MaterialData & materialData() override
static InputParameters validParams()
static auto defaultInitStateful()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
virtual void checkMaterialProperty(const std::string &name, const unsigned int state) override
A helper method for checking material properties This method was required to avoid a compiler problem...
const bool _bnd
Flag whether the material is on faces.
KOKKOS_FUNCTION void operator()(ElementInit, const ThreadID tid, const Derived &material) const
The parallel computation entry functions called by Kokkos.
virtual void computeProperties() override
Dispatch material property evaluation.
Material(const Material &object)
Copy constructor for parallel dispatch.
void getKokkosMaterialPropertyHook(const std::string &prop_name_in, const unsigned int state) override final
Override of the MaterialPropertyInterface function to perform additional checks and add dependencies.
virtual const MaterialData & materialData() const override
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const override
Retrieve the set of material properties that this object depends on.
const bool _neighbor
Flag whether the material is on neighbor faces.
MOOSE_KOKKOS_INDEX_TYPE ThreadID
MaterialDataType
MaterialData types.
Definition MooseTypes.h:746
const unsigned int invalid_uint