https://mooseframework.inl.gov
KokkosMaterialPropertyValueDecl.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 "KokkosArray.h"
13 
14 #define usingKokkosMaterialPropertyValueBaseMembers(T, dimension) \
15  using MaterialPropertyValueBase<T, dimension>::_idx; \
16  using MaterialPropertyValueBase<T, dimension>::_data; \
17  using MaterialPropertyValueBase<T, dimension>::_value
18 
19 namespace Moose::Kokkos
20 {
21 
22 template <typename T, unsigned int dimension>
23 class MaterialProperty;
24 
25 class Datum;
26 
32 template <typename T, unsigned int dimension>
34 class MaterialPropertyValueBase
35 {
36 public:
43  KOKKOS_FUNCTION MaterialPropertyValueBase(const MaterialProperty<T, dimension> & property,
44  const Datum & datum,
45  const unsigned int qp);
46 
52  KOKKOS_FUNCTION dof_id_type n(unsigned int dim) const { return _data->n(dim); }
53 
54 protected:
66  const T & _value;
67 };
68 
69 template <typename T, unsigned int dimension>
70 class MaterialPropertyValue : public MaterialPropertyValueBase<T, dimension>
71 {
73 
74 public:
81  KOKKOS_FUNCTION MaterialPropertyValue(const MaterialProperty<T, dimension> & property,
82  const Datum & datum,
83  const unsigned int qp);
84 
90  template <typename... index_type>
91  KOKKOS_FUNCTION T & operator()(index_type... i)
92  {
93  static_assert(sizeof...(i) == dimension,
94  "Number of arguments should match material property dimension");
95 
96  return (*_data)(i..., _idx);
97  }
103  template <typename... index_type>
104  KOKKOS_FUNCTION const T & operator()(index_type... i) const
105  {
106  static_assert(sizeof...(i) == dimension,
107  "Number of arguments should match material property dimension");
108 
109  return _data ? (*_data)(i..., _idx) : _value;
110  }
111 };
112 
113 template <typename T>
115 {
117 
118 public:
125  KOKKOS_FUNCTION
127  const Datum & datum,
128  const unsigned int qp);
129 
134  KOKKOS_FUNCTION operator const T &() const { return _data ? (*_data)(_idx) : _value; }
139  KOKKOS_FUNCTION auto & operator=(const T & value);
144  KOKKOS_FUNCTION auto & operator=(const MaterialPropertyValue<T, 0> & value);
145 };
147 
148 } // namespace Moose::Kokkos
KOKKOS_FUNCTION index_type n(unsigned int dim) const
Get the size of a dimension.
Definition: KokkosArray.h:211
KOKKOS_FUNCTION MaterialPropertyValue(const MaterialProperty< T, dimension > &property, const Datum &datum, const unsigned int qp)
Constructor.
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object...
Definition: KokkosDatum.h:23
KOKKOS_FUNCTION const T & operator()(index_type... i) const
Get the const reference of a property value.
usingKokkosMaterialPropertyValueBaseMembers(T, dimension)
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:163
KOKKOS_FUNCTION MaterialPropertyValueBase(const MaterialProperty< T, dimension > &property, const Datum &datum, const unsigned int qp)
Constructor.
The Kokkos wrapper class for accessing the material property values of a single quadrature point...
Array< T, dimension+1 > const * _data
Pointer to the property data storage.
infix_ostream_iterator< T, charT, traits > & operator=(T const &item)
Definition: InfixIterator.h:47
KOKKOS_FUNCTION dof_id_type n(unsigned int dim) const
Get the size of a dimension.
KOKKOS_FUNCTION T & operator()(index_type... i)
Get the writeable reference of a property value.
const dof_id_type _idx
Index into the property data storage.
The Kokkos material property class.
uint8_t dof_id_type