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::Kokkos
19 {
20 
25  public MeshHolder,
26  public AssemblyHolder,
27  public SystemHolder
28 {
29 public:
31 
39  MaterialBase(const MaterialBase & object);
40 
41  // Unused for Kokkos materials because all subdomains are computed in parallel
42  virtual void subdomainSetup() override final {}
43 
47  struct ElementInit
49  {
50  };
51  struct SideInit
52  {
53  };
54  struct NeighborInit
55  {
56  };
58  {
59  };
60  struct SideCompute
61  {
62  };
64  {
65  };
67 
68 protected:
77  template <typename T, unsigned int dimension = 0>
79  const std::vector<unsigned int> & dims = {});
88  template <typename T, unsigned int dimension = 0>
90  declareKokkosOnDemandProperty(const std::string & name,
91  const std::vector<unsigned int> & dims = {});
100  template <typename T, unsigned int dimension = 0>
102  declareKokkosPropertyByName(const std::string & prop_name,
103  const std::vector<unsigned int> & dims = {})
104  {
105  return declareKokkosPropertyInternal<T, dimension>(prop_name, dims, false);
106  }
116  template <typename T, unsigned int dimension = 0>
118  declareKokkosOnDemandPropertyByName(const std::string & prop_name,
119  const std::vector<unsigned int> & dims = {})
120  {
121  return declareKokkosPropertyInternal<T, dimension>(prop_name, dims, true);
122  }
123 
128  KOKKOS_FUNCTION dof_id_type numKokkosElements() const { return _element_ids.size(); }
133  KOKKOS_FUNCTION dof_id_type numKokkosElementSides() const { return _element_side_ids.size(); }
139  KOKKOS_FUNCTION ContiguousElementID kokkosElementID(ThreadID tid) const
140  {
141  return _element_ids[tid];
142  }
148  KOKKOS_FUNCTION auto kokkosElementSideID(ThreadID tid) const { return _element_side_ids[tid]; }
149 
153  std::unique_ptr<DispatcherBase> _init_dispatcher;
155  std::unique_ptr<DispatcherBase> _compute_dispatcher;
157 
162 
166 
188 
189 private:
190  // Unused for Kokkos materials because they are hidden by Kokkos functions
191  virtual void initQpStatefulProperties() override final {}
192  virtual void computeQpProperties() override final {}
193 
198 
207  template <typename T, unsigned int dimension>
209  const std::string & prop_name, const std::vector<unsigned int> & dims, const bool on_demand);
210 
220 };
221 
222 template <typename T, unsigned int dimension>
224 MaterialBase::declareKokkosProperty(const std::string & name,
225  const std::vector<unsigned int> & dims)
226 {
227  std::string prop_name = name;
228  if (_pars.have_parameter<MaterialPropertyName>(name))
229  prop_name = _pars.get<MaterialPropertyName>(name);
230 
231  return declareKokkosPropertyByName<T, dimension>(prop_name, dims);
232 }
233 
234 template <typename T, unsigned int dimension>
237  const std::vector<unsigned int> & dims)
238 {
239  std::string prop_name = name;
240  if (_pars.have_parameter<MaterialPropertyName>(name))
241  prop_name = _pars.get<MaterialPropertyName>(name);
242 
243  return declareKokkosOnDemandPropertyByName<T, dimension>(prop_name, dims);
244 }
245 
246 template <typename T, unsigned int dimension>
248 MaterialBase::declareKokkosPropertyInternal(const std::string & prop_name,
249  const std::vector<unsigned int> & dims,
250  const bool on_demand)
251 {
252  if (dims.size() != dimension)
253  mooseError("The declared Kokkos material property '",
254  prop_name,
255  "'\nhas a different dimension (",
256  dimension,
257  ") with the provided dimension (",
258  dims.size(),
259  ").");
260 
261  const auto prop_name_modified =
262  _declare_suffix.empty()
263  ? prop_name
264  : MooseUtils::join(std::vector<std::string>({prop_name, _declare_suffix}), "_");
265 
266  auto prop = materialData().declareKokkosProperty<T, dimension>(
267  prop_name_modified, dims, this, isBoundaryMaterial(), on_demand, _constant_option);
268 
269  registerPropName(prop_name_modified, false, 0);
270 
271  return prop;
272 }
273 
274 } // 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:394
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 systems and copies it to device duri...
Definition: KokkosSystem.h:753
The Kokkos interface that holds the host reference of the Kokkos mesh and copies it to device during ...
Definition: KokkosMesh.h:430
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:205
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:281
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.