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::Kokkos
30 {
31 
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 
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 
100  template <typename Derived>
102  static auto defaultInitStateful()
103  {
104  return &Material::initQpStatefulProperties<Derived>;
105  }
107 
111  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 
128 protected:
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 
163 private:
167  const QBase * const & _qrule;
169  virtual const QBase & qRule() const override { return *_qrule; }
171 };
172 
173 template <typename Derived>
174 KOKKOS_FUNCTION void
175 Material::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 
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 
189 template <typename Derived>
190 KOKKOS_FUNCTION void
191 Material::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 
203 template <typename Derived>
204 KOKKOS_FUNCTION void
205 Material::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 
217 template <typename Derived>
218 KOKKOS_FUNCTION void
219 Material::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 
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 
233 template <typename Derived>
234 KOKKOS_FUNCTION void
235 Material::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 
247 template <typename Derived>
248 KOKKOS_FUNCTION void
249 Material::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 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:23
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.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
MaterialDataType
MaterialData types.
Definition: MooseTypes.h:740
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const PropertyConstantOption _constant_option
Whether the properties declared by this material are constant over element or subdomain.
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 initQpStatefulProperties(const unsigned int, Datum &) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
KOKKOS_FUNCTION void operator()(ElementInit, const ThreadID tid, const Derived &material) const
The parallel computation entry functions called by Kokkos.
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...
MOOSE_KOKKOS_INDEX_TYPE ThreadID
Definition: KokkosThread.h:22
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:118
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.
static auto defaultInitStateful()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
Interface for objects that needs coupling capabilities.
Definition: Coupleable.h:52
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.
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.
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:775