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:
124  template <typename T, unsigned int dimension = 0, unsigned int state = 0>
125  MaterialProperty<T, dimension> getKokkosMaterialPropertyByName(const std::string & prop_name_in);
133  template <typename T, unsigned int dimension = 0>
135  {
136  return getKokkosMaterialPropertyByName<T, dimension, 1>(prop_name);
137  }
145  template <typename T, unsigned int dimension = 0>
147  {
148  return getKokkosMaterialPropertyByName<T, dimension, 2>(prop_name);
149  }
158  template <typename T, unsigned int dimension = 0, unsigned int state = 0>
160  {
161  return getKokkosMaterialPropertyByName<T, dimension, state>(getMaterialPropertyName(name));
162  }
170  template <typename T, unsigned int dimension = 0>
172  {
173  return getKokkosMaterialPropertyByName<T, dimension, 1>(getMaterialPropertyName(name));
174  }
182  template <typename T, unsigned int dimension = 0>
184  {
185  return getKokkosMaterialPropertyByName<T, dimension, 2>(getMaterialPropertyName(name));
186  }
187 
188  virtual void checkMaterialProperty(const std::string & name, const unsigned int state) override
189  {
190  // Avoid performing duplicate checks for triple block/face/neighbor materials
191  if (boundaryRestricted() || !_bnd)
193  }
194 
195  virtual bool isBoundaryMaterial() const override { return _bnd; }
196 
197  virtual const std::unordered_set<unsigned int> & getMatPropDependencies() const override
198  {
200  }
201 
202  virtual const MaterialData & materialData() const override { return _material_data; }
203  virtual MaterialData & materialData() override { return _material_data; }
205 
209  const bool _bnd;
213  const bool _neighbor;
214 
215 private:
219  const QBase * const & _qrule;
221  virtual const QBase & qRule() const override { return *_qrule; }
223 };
224 
225 template <typename Derived>
226 KOKKOS_FUNCTION void
227 Material::operator()(ElementInit, const ThreadID tid, const Derived & material) const
228 {
229  auto elem = kokkosElementID(tid);
230 
232 
233  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
234  {
235  datum.reinit();
236  material.initQpStatefulProperties(qp, datum);
237  }
238 }
239 
240 template <typename Derived>
241 KOKKOS_FUNCTION void
242 Material::operator()(SideInit, const ThreadID tid, const Derived & material) const
243 {
244  auto [elem, side] = kokkosElementSideID(tid);
245 
246  Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
247 
248  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
249  {
250  datum.reinit();
251  material.initQpStatefulProperties(qp, datum);
252  }
253 }
254 
255 template <typename Derived>
256 KOKKOS_FUNCTION void
257 Material::operator()(NeighborInit, const ThreadID tid, const Derived & material) const
258 {
259  auto [elem, side] = kokkosElementSideID(tid);
260 
261  Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
262 
263  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
264  {
265  datum.reinit();
266  material.initQpStatefulProperties(qp, datum);
267  }
268 }
269 
270 template <typename Derived>
271 KOKKOS_FUNCTION void
272 Material::operator()(ElementCompute, const ThreadID tid, const Derived & material) const
273 {
274  auto elem = kokkosElementID(tid);
275 
277 
278  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
279  {
280  datum.reinit();
281  material.computeQpProperties(qp, datum);
282  }
283 }
284 
285 template <typename Derived>
286 KOKKOS_FUNCTION void
287 Material::operator()(SideCompute, const ThreadID tid, const Derived & material) const
288 {
289  auto [elem, side] = kokkosElementSideID(tid);
290 
291  Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
292 
293  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
294  {
295  datum.reinit();
296  material.computeQpProperties(qp, datum);
297  }
298 }
299 
300 template <typename Derived>
301 KOKKOS_FUNCTION void
302 Material::operator()(NeighborCompute, const ThreadID tid, const Derived & material) const
303 {
304  auto [elem, side] = kokkosElementSideID(tid);
305 
306  Datum datum(elem, side, kokkosAssembly(), kokkosSystems());
307 
308  for (unsigned int qp = 0; qp < datum.n_qps(); qp++)
309  {
310  datum.reinit();
311  material.computeQpProperties(qp, datum);
312  }
313 }
314 
315 template <typename T, unsigned int dimension, unsigned int state>
317 Material::getKokkosMaterialPropertyByName(const std::string & prop_name_in)
318 {
320 
321  const auto prop_name =
322  _get_suffix.empty()
323  ? prop_name_in
324  : MooseUtils::join(std::vector<std::string>({prop_name_in, _get_suffix}), "_");
325 
326  if constexpr (state == 0)
327  _requested_props.insert(prop_name);
328 
329  auto prop =
330  MaterialPropertyInterface::getKokkosMaterialPropertyByName<T, dimension, state>(prop_name);
331 
332  registerPropName(prop_name, true, state);
333 
334  return prop;
335 }
336 
337 } // namespace Kokkos
338 } // namespace Moose
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const
Retrieve the set of material properties that this object depends on.
std::string join(Iterator begin, Iterator end, const std::string &delimiter)
Python-like join function for strings over an iterator range.
Definition: MooseUtils.h:142
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.
MaterialProperty< T, dimension > getKokkosMaterialPropertyOld(const std::string &name)
Get an old material property.
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.
MaterialProperty< T, dimension > getKokkosMaterialPropertyOldByName(const std::string &prop_name)
Get an old material property by property name.
static InputParameters validParams()
MaterialPropertyName getMaterialPropertyName(const std::string &name) const
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...
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
std::set< std::string > _requested_props
Set of properties accessed via get method.
Definition: MaterialBase.h:345
virtual const QBase & qRule() const override
void checkExecutionStage()
Check and throw an error if the execution has progressed past the construction stage.
Definition: MaterialBase.C:293
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.
const MaterialPropertyName _get_suffix
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.
MaterialProperty< T, dimension > getKokkosMaterialPropertyOlder(const std::string &name)
Get an older material property.
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.
void registerPropName(const std::string &prop_name, bool is_get, const unsigned int state)
Small helper function to call store{Subdomain,Boundary}MatPropName.
Definition: MaterialBase.C:205
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 Kokkos material property class.
MaterialProperty< T, dimension > getKokkosMaterialPropertyByName(const std::string &prop_name_in)
Get a material property by property name for any state.
MaterialProperty< T, dimension > getKokkosMaterialProperty(const std::string &name)
Get a material property for any state.
The base class for Kokkos materials.
MaterialProperty< T, dimension > getKokkosMaterialPropertyOlderByName(const std::string &prop_name)
Get an older material property by property name.
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:598
virtual void initQpStatefulProperties() override final
Initialize stateful properties at quadrature points.