https://mooseframework.inl.gov
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 
29 namespace Moose
30 {
31 namespace Kokkos
32 {
33 
51 {
52 public:
54 
59 
63  Material(const Material & object);
64 
68  virtual void initStatefulProperties(unsigned int) override;
72  virtual void computeProperties() override;
73 
78 
84  KOKKOS_FUNCTION void initQpStatefulProperties(const unsigned int /* qp */,
85  Datum & /* datum */) const
86  {
87  }
94 
98  template <typename Derived>
100  KOKKOS_FUNCTION void operator()(ElementInit, const ThreadID tid, const Derived & material) const;
101  template <typename Derived>
102  KOKKOS_FUNCTION void operator()(SideInit, const ThreadID tid, const Derived & material) const;
103  template <typename Derived>
104  KOKKOS_FUNCTION void operator()(NeighborInit, const ThreadID tid, const Derived & material) const;
105  template <typename Derived>
106  KOKKOS_FUNCTION void
107  operator()(ElementCompute, const ThreadID tid, const Derived & material) const;
108  template <typename Derived>
109  KOKKOS_FUNCTION void operator()(SideCompute, const ThreadID tid, const Derived & material) const;
110  template <typename Derived>
111  KOKKOS_FUNCTION void
112  operator()(NeighborCompute, const ThreadID tid, const Derived & material) const;
114 
115 protected:
120  void getKokkosMaterialPropertyHook(const std::string & prop_name_in,
121  const unsigned int state) override final;
122 
123  virtual void checkMaterialProperty(const std::string & name, const unsigned int state) override
124  {
125  // Avoid performing duplicate checks for triple block/face/neighbor materials
126  if (boundaryRestricted() || !_bnd)
128  }
129 
130  virtual bool isBoundaryMaterial() const override { return _bnd; }
131 
132  virtual const std::unordered_set<unsigned int> & getMatPropDependencies() const override
133  {
135  }
136 
137  virtual const MaterialData & materialData() const override { return _material_data; }
138  virtual MaterialData & materialData() override { return _material_data; }
140 
144  const bool _bnd;
148  const bool _neighbor;
149 
150 private:
154  const QBase * const & _qrule;
156  virtual const QBase & qRule() const override { return *_qrule; }
158 };
159 
160 template <typename Derived>
161 KOKKOS_FUNCTION void
162 Material::operator()(ElementInit, const ThreadID tid, const Derived & material) const
163 {
164  auto elem = kokkosElementID(tid);
165 
167 
168  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
169  {
170  datum.reinit();
171  material.initQpStatefulProperties(qp, datum);
172  }
173 }
174 
175 template <typename Derived>
176 KOKKOS_FUNCTION void
177 Material::operator()(SideInit, const ThreadID tid, const Derived & material) const
178 {
179  auto [elem, side] = kokkosElementSideID(tid);
180 
181  Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
182 
183  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
184  {
185  datum.reinit();
186  material.initQpStatefulProperties(qp, datum);
187  }
188 }
189 
190 template <typename Derived>
191 KOKKOS_FUNCTION void
192 Material::operator()(NeighborInit, const ThreadID tid, const Derived & material) const
193 {
194  auto [elem, side] = kokkosElementSideID(tid);
195 
196  Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
197 
198  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
199  {
200  datum.reinit();
201  material.initQpStatefulProperties(qp, datum);
202  }
203 }
204 
205 template <typename Derived>
206 KOKKOS_FUNCTION void
207 Material::operator()(ElementCompute, const ThreadID tid, const Derived & material) const
208 {
209  auto elem = kokkosElementID(tid);
210 
212 
213  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
214  {
215  datum.reinit();
216  material.computeQpProperties(qp, datum);
217  }
218 }
219 
220 template <typename Derived>
221 KOKKOS_FUNCTION void
222 Material::operator()(SideCompute, const ThreadID tid, const Derived & material) const
223 {
224  auto [elem, side] = kokkosElementSideID(tid);
225 
226  Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
227 
228  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
229  {
230  datum.reinit();
231  material.computeQpProperties(qp, datum);
232  }
233 }
234 
235 template <typename Derived>
236 KOKKOS_FUNCTION void
237 Material::operator()(NeighborCompute, const ThreadID tid, const Derived & material) const
238 {
239  auto [elem, side] = kokkosElementSideID(tid);
240 
241  Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
242 
243  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
244  {
245  datum.reinit();
246  material.computeQpProperties(qp, datum);
247  }
248 }
249 
250 } // namespace Kokkos
251 } // namespace Moose
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const
Retrieve the set of material properties that this object depends on.
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...
virtual void initStatefulProperties(unsigned int) override
Dispatch stateful material property initialization.
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object...
Definition: KokkosDatum.h:25
virtual MaterialDataType materialDataType() override
const unsigned int invalid_uint
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
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...
virtual bool boundaryRestricted() const
Returns true if this object has been restricted to a boundary.
dof_id_type ThreadID
Definition: KokkosThread.h:18
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
MaterialDataType
MaterialData types.
Definition: MooseTypes.h:692
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static auto defaultInitStateful()
Get the function pointer of the default initQpStatefulProperties()
KOKKOS_FUNCTION ContiguousElementID kokkosElementID(ThreadID tid) const
Get the contiguous element ID for a thread.
static InputParameters validParams()
MaterialData & _material_data
The material data class that stores properties.
KOKKOS_FUNCTION void operator()(ElementInit, const ThreadID tid, const Derived &material) const
The parallel computation entry functions called by Kokkos.
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...
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...
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
virtual const QBase & qRule() const override
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
Definition: KokkosDatum.h:100
KOKKOS_FUNCTION auto kokkosElementSideID(ThreadID tid) const
Get the contiguous element ID - side index pair for a thread.
virtual void computeProperties() override
Dispatch material property evaluation.
Material(const InputParameters &parameters)
Constructor.
Interface for objects that needs coupling capabilities.
Definition: Coupleable.h:49
The base class for a user to derive their own Kokkos materials.
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const override
Retrieve the set of material properties that this object depends on.
An interface for accessing Materials.
const QBase *const & _qrule
Dummy members unused for Kokkos materials.
virtual MaterialData & materialData() override
Proxy for accessing MaterialPropertyStorage.
Definition: MaterialData.h:37
virtual bool isBoundaryMaterial() const override
Returns true of the MaterialData type is not associated with volume data.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const bool _neighbor
Flag whether the material is on neighbor faces.
virtual const MaterialData & materialData() const override
const Moose::MaterialDataType _material_data_type
The type of data.
The base class for Kokkos materials.
KOKKOS_FUNCTION void reinit()
Reset the reinit flag.
Definition: KokkosDatum.h:166
const bool _bnd
Flag whether the material is on faces.
KOKKOS_FUNCTION const Array< System > & kokkosSystems() const
Get the const reference of the Kokkos systems.
Definition: KokkosSystem.h:608
virtual void initQpStatefulProperties() override final
Initialize stateful properties at quadrature points.