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 #include "KokkosFESystem.h"
16 
17 #include "MaterialBase.h"
18 
19 namespace Moose::Kokkos
20 {
21 
26  public MeshHolder,
27  public AssemblyHolder,
28  public FESystemHolder
29 {
30 public:
32 
40  MaterialBase(const MaterialBase & object);
41 
42  // Unused for Kokkos materials because all subdomains are computed in parallel
43  virtual void subdomainSetup() override final {}
44 
48  struct ElementInit
50  {
51  };
52  struct SideInit
53  {
54  };
55  struct NeighborInit
56  {
57  };
59  {
60  };
61  struct SideCompute
62  {
63  };
65  {
66  };
68 
69 protected:
78  template <typename T, unsigned int dimension = 0>
80  const std::vector<unsigned int> & dims = {});
89  template <typename T, unsigned int dimension = 0>
91  declareKokkosOnDemandProperty(const std::string & name,
92  const std::vector<unsigned int> & dims = {});
101  template <typename T, unsigned int dimension = 0>
103  declareKokkosPropertyByName(const std::string & prop_name,
104  const std::vector<unsigned int> & dims = {})
105  {
106  return declareKokkosPropertyInternal<T, dimension>(prop_name, dims, false);
107  }
117  template <typename T, unsigned int dimension = 0>
119  declareKokkosOnDemandPropertyByName(const std::string & prop_name,
120  const std::vector<unsigned int> & dims = {})
121  {
122  return declareKokkosPropertyInternal<T, dimension>(prop_name, dims, true);
123  }
124 
129  KOKKOS_FUNCTION dof_id_type numKokkosElements() const { return _element_ids.size(); }
134  KOKKOS_FUNCTION dof_id_type numKokkosElementSides() const { return _element_side_ids.size(); }
140  KOKKOS_FUNCTION ContiguousElementID kokkosElementID(ThreadID tid) const
141  {
142  return _element_ids[tid];
143  }
149  KOKKOS_FUNCTION auto kokkosElementSideID(ThreadID tid) const { return _element_side_ids[tid]; }
150 
154  std::unique_ptr<DispatcherBase> _init_dispatcher;
156  std::unique_ptr<DispatcherBase> _compute_dispatcher;
158 
163 
167 
189 
190 private:
191  // Unused for Kokkos materials because they are hidden by Kokkos functions
192  virtual void initQpStatefulProperties() override final {}
193  virtual void computeQpProperties() override final {}
194 
199 
208  template <typename T, unsigned int dimension>
210  const std::string & prop_name, const std::vector<unsigned int> & dims, const bool on_demand);
211 
221 };
222 
223 template <typename T, unsigned int dimension>
225 MaterialBase::declareKokkosProperty(const std::string & name,
226  const std::vector<unsigned int> & dims)
227 {
228  std::string prop_name = name;
229  if (_pars.have_parameter<MaterialPropertyName>(name))
230  prop_name = _pars.get<MaterialPropertyName>(name);
231 
232  return declareKokkosPropertyByName<T, dimension>(prop_name, dims);
233 }
234 
235 template <typename T, unsigned int dimension>
238  const std::vector<unsigned int> & dims)
239 {
240  std::string prop_name = name;
241  if (_pars.have_parameter<MaterialPropertyName>(name))
242  prop_name = _pars.get<MaterialPropertyName>(name);
243 
244  return declareKokkosOnDemandPropertyByName<T, dimension>(prop_name, dims);
245 }
246 
247 template <typename T, unsigned int dimension>
249 MaterialBase::declareKokkosPropertyInternal(const std::string & prop_name,
250  const std::vector<unsigned int> & dims,
251  const bool on_demand)
252 {
253  if (dims.size() != dimension)
254  mooseError("The declared Kokkos material property '",
255  prop_name,
256  "'\nhas a different dimension (",
257  dimension,
258  ") with the provided dimension (",
259  dims.size(),
260  ").");
261 
262  const auto prop_name_modified =
263  _declare_suffix.empty()
264  ? prop_name
265  : MooseUtils::join(std::vector<std::string>({prop_name, _declare_suffix}), "_");
266 
267  auto prop = materialData().declareKokkosProperty<T, dimension>(
268  prop_name_modified, dims, this, isBoundaryMaterial(), on_demand, _constant_option);
269 
270  registerPropName(prop_name_modified, false, 0);
271 
272  return prop;
273 }
274 
275 } // namespace Moose::Kokkos
const MaterialPropertyName _declare_suffix
Suffix to append to the name of the material property/ies when declaring it/them. ...
Definition: MaterialBase.h:394
Scalar< int > _t_step
The number of the time step.
const InputParameters & _pars
The object&#39;s parameters.
Definition: MooseBase.h:384
dof_id_type ContiguousElementID
Definition: KokkosMesh.h:20
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.
MaterialProperty< T, dimension > declareKokkosPropertyByName(const std::string &prop_name, const std::vector< unsigned int > &dims={})
Declare a material property by property name.
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...
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.
The Kokkos interface that holds the host reference of the Kokkos mesh and copies it to device during ...
Definition: KokkosMesh.h:629
std::unique_ptr< DispatcherBase > _init_dispatcher
Kokkos functor dispatchers.
MaterialBase(const InputParameters &parameters)
Constructor.
Moose::Kokkos::MaterialProperty< T, dimension > declareKokkosProperty(const std::string &prop_name, const std::vector< unsigned int > &dims, const MaterialBase *declarer, const bool bnd, const bool on_demand, const Moose::Kokkos::PropertyConstantOption constant_option)
Declare a Kokkos material property.
Definition: MaterialData.h:503
MOOSE_KOKKOS_INDEX_TYPE ThreadID
Definition: KokkosThread.h:22
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
PropertyConstantOption
Property constant options.
static InputParameters validParams()
void initializeMaterialRestrictable()
Setup block and boundary restrictions for material.
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.
KOKKOS_FUNCTION index_type size() const
Get the total array size.
Definition: KokkosArray.h:294
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
MaterialProperty< T, dimension > declareKokkosProperty(const std::string &name, const std::vector< unsigned int > &dims={})
Declare a material property.
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:203
MaterialProperty< T, dimension > declareKokkosOnDemandPropertyByName(const std::string &prop_name, const std::vector< unsigned int > &dims={})
Declare an on-demand material property by property name The on-demand property is only allocated when...
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
MaterialProperty< T, dimension > declareKokkosOnDemandProperty(const std::string &name, const std::vector< unsigned int > &dims={})
Declare an on-demand material property.
MaterialProperty< T, dimension > declareKokkosPropertyInternal(const std::string &prop_name, const std::vector< unsigned int > &dims, const bool on_demand)
Internal method for declaring a material property.
uint8_t dof_id_type
virtual void initQpStatefulProperties() override final
Initialize stateful properties at quadrature points.