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 #include "KokkosDispatcher.h"
15 
16 #include "MaterialBase.h"
17 
18 namespace Moose
19 {
20 namespace Kokkos
21 {
22 
27  public MeshHolder,
28  public AssemblyHolder,
29  public SystemHolder
30 {
31 public:
33 
41  MaterialBase(const MaterialBase & object);
42 
46  virtual void initialSetup() override;
47 
48  // Unused for Kokkos materials because all elements are computed in parallel
49  virtual void subdomainSetup() override final {}
50 
54  struct ElementInit
56  {
57  };
58  struct SideInit
59  {
60  };
61  struct NeighborInit
62  {
63  };
65  {
66  };
67  struct SideCompute
68  {
69  };
71  {
72  };
74 
75 protected:
84  template <typename T, unsigned int dimension = 0>
86  const std::vector<unsigned int> & dims = {})
87  {
88  std::string prop_name = name;
89  if (_pars.have_parameter<MaterialPropertyName>(name))
90  prop_name = _pars.get<MaterialPropertyName>(name);
91 
92  return declareKokkosPropertyByName<T, dimension>(prop_name, dims);
93  }
102  template <typename T, unsigned int dimension = 0>
104  declareKokkosPropertyByName(const std::string & prop_name,
105  const std::vector<unsigned int> & dims = {});
106 
111  KOKKOS_FUNCTION dof_id_type numKokkosElements() const { return _element_ids.size(); }
116  KOKKOS_FUNCTION dof_id_type numKokkosElementSides() const { return _element_side_ids.size(); }
122  KOKKOS_FUNCTION ContiguousElementID kokkosElementID(ThreadID tid) const
123  {
124  return _element_ids[tid];
125  }
131  KOKKOS_FUNCTION auto kokkosElementSideID(ThreadID tid) const { return _element_side_ids[tid]; }
132 
136  std::unique_ptr<DispatcherBase> _init_dispatcher;
138  std::unique_ptr<DispatcherBase> _compute_dispatcher;
140 
144 
166 
167 private:
168  // Unused for Kokkos materials because they are hidden by Kokkos functions
169  virtual void initQpStatefulProperties() override final {}
170  virtual void computeQpProperties() override final {}
171 
181 };
182 
183 template <typename T, unsigned int dimension>
185 MaterialBase::declareKokkosPropertyByName(const std::string & prop_name,
186  const std::vector<unsigned int> & dims)
187 {
188  static_assert(dimension <= 4, "Up to four-dimensional Kokkos material properties are allowed.");
189 
190  if (dims.size() != dimension)
191  mooseError("The declared Kokkos material property '",
192  prop_name,
193  "'\nhas a different dimension (",
194  dimension,
195  ") with the provided dimension (",
196  dims.size(),
197  ").");
198 
199  const auto prop_name_modified =
200  _declare_suffix.empty()
201  ? prop_name
202  : MooseUtils::join(std::vector<std::string>({prop_name, _declare_suffix}), "_");
203 
204  auto prop = materialData().declareKokkosProperty<T, dimension>(
205  prop_name_modified, dims, this, isBoundaryMaterial());
206 
207  registerPropName(prop_name_modified, false, 0);
208 
209  return prop;
210 }
211 
212 } // namespace Kokkos
213 } // 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
std::unique_ptr< DispatcherBase > _init_dispatcher
Kokkos functor dispatchers.
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:205
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.
std::unique_ptr< DispatcherBase > _compute_dispatcher
uint8_t dof_id_type
virtual void initQpStatefulProperties() override final
Initialize stateful properties at quadrature points.