https://mooseframework.inl.gov
KokkosMaterialBase.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 #include "KokkosTypes.h"
14 
15 #include "MaterialBase.h"
16 
17 namespace Moose
18 {
19 namespace Kokkos
20 {
21 
26  public MeshHolder,
27  public AssemblyHolder,
28  public SystemHolder
29 {
30 public:
32 
40  MaterialBase(const MaterialBase & object);
41 
45  virtual void initialSetup() override;
46 
47  // Unused for Kokkos materials because all elements are computed in parallel
48  virtual void subdomainSetup() override final {}
49 
53  struct ElementInit
55  {
56  };
57  struct SideInit
58  {
59  };
60  struct NeighborInit
61  {
62  };
64  {
65  };
66  struct SideCompute
67  {
68  };
70  {
71  };
73 
74 protected:
83  template <typename T, unsigned int dimension = 0>
85  const std::vector<unsigned int> & dims = {})
86  {
87  std::string prop_name = name;
88  if (_pars.have_parameter<MaterialPropertyName>(name))
89  prop_name = _pars.get<MaterialPropertyName>(name);
90 
91  return declareKokkosPropertyByName<T, dimension>(prop_name, dims);
92  }
101  template <typename T, unsigned int dimension = 0>
103  declareKokkosPropertyByName(const std::string & prop_name,
104  const std::vector<unsigned int> & dims = {});
105 
110  KOKKOS_FUNCTION dof_id_type numKokkosElements() const { return _element_ids.size(); }
115  KOKKOS_FUNCTION dof_id_type numKokkosElementSides() const { return _element_side_ids.size(); }
121  KOKKOS_FUNCTION ContiguousElementID kokkosElementID(ThreadID tid) const
122  {
123  return _element_ids[tid];
124  }
130  KOKKOS_FUNCTION auto kokkosElementSideID(ThreadID tid) const { return _element_side_ids[tid]; }
131 
135 
157 
158 private:
159  // Unused for Kokkos materials because they are hidden by Kokkos functions
160  virtual void initQpStatefulProperties() override final {}
161  virtual void computeQpProperties() override final {}
162 
172 };
173 
174 template <typename T, unsigned int dimension>
176 MaterialBase::declareKokkosPropertyByName(const std::string & prop_name,
177  const std::vector<unsigned int> & dims)
178 {
179  static_assert(dimension <= 4, "Up to four-dimensional Kokkos material properties are allowed.");
180 
181  if (dims.size() != dimension)
182  mooseError("The declared Kokkos material property '",
183  prop_name,
184  "'\nhas a different dimension (",
185  dimension,
186  ") with the provided dimension (",
187  dims.size(),
188  ").");
189 
190  const auto prop_name_modified =
191  _declare_suffix.empty()
192  ? prop_name
193  : MooseUtils::join(std::vector<std::string>({prop_name, _declare_suffix}), "_");
194 
195  auto prop = materialData().declareKokkosProperty<T, dimension>(
196  prop_name_modified, dims, this, isBoundaryMaterial());
197 
198  registerPropName(prop_name_modified, false, 0);
199 
200  return prop;
201 }
202 
203 } // namespace Kokkos
204 } // namespace Moose
const MaterialPropertyName _declare_suffix
Suffix to append to the name of the material property/ies when declaring it/them. ...
Definition: MaterialBase.h:391
Scalar< int > _t_step
The number of the time step.
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
const InputParameters & _pars
The object&#39;s parameters.
Definition: MooseBase.h:366
MaterialProperty< T, dimension > declareKokkosPropertyByName(const std::string &prop_name, const std::vector< unsigned int > &dims={})
Declare a material property by property name.
dof_id_type ThreadID
Definition: KokkosThread.h:18
dof_id_type ContiguousElementID
Definition: KokkosMesh.h:20
virtual void initialSetup() override
Setup block and boundary restrictions.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
virtual void computeQpProperties() override final
Users must override this method.
KOKKOS_FUNCTION dof_id_type numKokkosElementSides() const
Get the number of sides this material is operating on for face material property evaluation.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MaterialProperty< T, dimension > declareKokkosProperty(const std::string &name, const std::vector< unsigned int > &dims={})
Declare a material property.
KOKKOS_FUNCTION ContiguousElementID kokkosElementID(ThreadID tid) const
Get the contiguous element ID for a thread.
The Kokkos interface that holds the host reference of the Kokkos systems and copies it to device duri...
Definition: KokkosSystem.h:576
The Kokkos interface that holds the host reference of the Kokkos mesh and copies it to device during ...
Definition: KokkosMesh.h:338
Moose::Kokkos::MaterialProperty< T, dimension > declareKokkosProperty(const std::string &prop_name, const std::vector< unsigned int > &dims, const MaterialBase *declarer, const bool bnd)
Declare a Kokkos material property.
Definition: MaterialData.h:495
MaterialBase(const InputParameters &parameters)
Constructor.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
static InputParameters validParams()
KOKKOS_FUNCTION auto kokkosElementSideID(ThreadID tid) const
Get the contiguous element ID - side index pair for a thread.
The Kokkos interface that holds the host reference of the Kokkos assembly and copies it to device dur...
Array< ContiguousElementID > _element_ids
Contiguous element IDs this material operates on for element material property evaluation.
Scalar< Real > _t
TODO: Move to TransientInterface.
Scalar< Real > _dt_old
Size of the old time step.
virtual void subdomainSetup() override final
Subdomain setup evaluating material properties when required.
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
Scalar< Real > _dt
Time step size.
KOKKOS_FUNCTION dof_id_type numKokkosElements() const
Get the number of elements this material operates on for element material property evaluation...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271
Array< Pair< ContiguousElementID, unsigned int > > _element_side_ids
Contiguous element ID - side index pairs this material operates on for face material property evaluat...
Scalar< const Real > _t_old
Old time.
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:204
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
The Kokkos material property class.
The base class for Kokkos materials.
virtual const MaterialData & materialData() const =0
virtual bool isBoundaryMaterial() const =0
Returns true of the MaterialData type is not associated with volume data.
uint8_t dof_id_type
virtual void initQpStatefulProperties() override final
Initialize stateful properties at quadrature points.