https://mooseframework.inl.gov
KokkosFunction.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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"
13 #include "KokkosFunctionWrapper.h"
14 #include "KokkosFunctorRegistry.h"
15 
16 #include "FunctionBase.h"
17 
18 namespace Moose::Kokkos
19 {
20 
30 {
31 public:
33 
41  FunctionBase(const FunctionBase & object);
42 
49  KOKKOS_FUNCTION Real value(Real /* t */, Real3 /* p */) const
50  {
51  KOKKOS_ASSERT(false);
52  return 0;
53  }
60  KOKKOS_FUNCTION Real3 vectorValue(Real /* t */, Real3 /* p */) const
61  {
62  KOKKOS_ASSERT(false);
63  return Real3(0);
64  }
71  KOKKOS_FUNCTION Real3 gradient(Real /* t */, Real3 /* p */) const
72  {
73  KOKKOS_ASSERT(false);
74  return Real3(0);
75  }
82  KOKKOS_FUNCTION Real3 curl(Real /* t */, Real3 /* p */) const
83  {
84  KOKKOS_ASSERT(false);
85  return Real3(0);
86  }
93  KOKKOS_FUNCTION Real div(Real /* t */, Real3 /* p */) const
94  {
95  KOKKOS_ASSERT(false);
96  return 0;
97  }
104  KOKKOS_FUNCTION Real timeDerivative(Real /* t */, Real3 /* p */) const
105  {
106  KOKKOS_ASSERT(false);
107  return 0;
108  }
116  KOKKOS_FUNCTION Real timeIntegral(Real /* t1 */, Real /* t2 */, Real3 /* p */) const
117  {
118  KOKKOS_ASSERT(false);
119  return 0;
120  }
125  KOKKOS_FUNCTION Real integral() const
126  {
127  KOKKOS_ASSERT(false);
128  return 0;
129  }
134  KOKKOS_FUNCTION Real average() const
135  {
136  KOKKOS_ASSERT(false);
137  return 0;
138  }
139 };
140 
147 class Function final
148 {
149 public:
154  Function(std::shared_ptr<FunctionWrapperHostBase> wrapper);
158  Function(const Function & function);
162  ~Function();
163 
164  KOKKOS_FUNCTION Real value(Real t, Real3 p) const { return _wrapper_device->value(t, p); }
165  KOKKOS_FUNCTION Real3 vectorValue(Real t, Real3 p) const
166  {
167  return _wrapper_device->vectorValue(t, p);
168  }
169  KOKKOS_FUNCTION Real3 gradient(Real t, Real3 p) const { return _wrapper_device->gradient(t, p); }
170  KOKKOS_FUNCTION Real3 curl(Real t, Real3 p) const { return _wrapper_device->curl(t, p); }
171  KOKKOS_FUNCTION Real div(Real t, Real3 p) const { return _wrapper_device->div(t, p); }
172  KOKKOS_FUNCTION Real timeDerivative(Real t, Real3 p) const
173  {
174  return _wrapper_device->timeDerivative(t, p);
175  }
176  KOKKOS_FUNCTION Real timeIntegral(Real t1, Real t2, Real3 p) const
177  {
178  return _wrapper_device->timeIntegral(t1, t2, p);
179  }
180  KOKKOS_FUNCTION Real integral() const { return _wrapper_device->integral(); }
181  KOKKOS_FUNCTION Real average() const { return _wrapper_device->average(); }
182 
183 private:
187  std::shared_ptr<FunctionWrapperHostBase> _wrapper_host;
192 };
193 
194 } // namespace Moose::Kokkos
Vector3< Real > Real3
Definition: KokkosTypes.h:31
Base class for device function wrapper.
KOKKOS_FUNCTION Real3 vectorValue(Real t, Real3 p) const
static InputParameters validParams()
virtual KOKKOS_FUNCTION Real timeIntegral(Real t1, Real t2, Real3 p) const =0
virtual KOKKOS_FUNCTION Real3 gradient(Real t, Real3 p) const =0
KOKKOS_FUNCTION Real timeIntegral(Real, Real, Real3) const
Evaluate a time integral at point (x,y,z) between time t1 and t2.
KOKKOS_FUNCTION Real integral() const
Evaluate the integral over the domain.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
KOKKOS_FUNCTION Real3 gradient(Real t, Real3 p) const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
KOKKOS_FUNCTION Real3 gradient(Real, Real3) const
Evaluate a gradient at point (t,x,y,z)
The base class for a user to derive their own Kokkos functions.
KOKKOS_FUNCTION Real div(Real, Real3) const
Evaluate a divergence at point (t,x,y,z)
Function(std::shared_ptr< FunctionWrapperHostBase > wrapper)
Constructor.
virtual KOKKOS_FUNCTION Real3 vectorValue(Real t, Real3 p) const =0
KOKKOS_FUNCTION Real3 curl(Real, Real3) const
Evaluate a curl at point (t,x,y,z)
The abstract class that provides polymorphic interfaces for a function.
virtual KOKKOS_FUNCTION Real integral() const =0
FunctionWrapperDeviceBase * _wrapper_device
Pointer to the device function wrapper.
virtual KOKKOS_FUNCTION Real average() const =0
~Function()
Destructor.
KOKKOS_FUNCTION Real timeDerivative(Real t, Real3 p) const
std::shared_ptr< FunctionWrapperHostBase > _wrapper_host
Pointer to the host function wrapper.
KOKKOS_FUNCTION Real timeIntegral(Real t1, Real t2, Real3 p) const
KOKKOS_FUNCTION Real3 curl(Real t, Real3 p) const
KOKKOS_FUNCTION Real average() const
Evaluate the average over the domain.
KOKKOS_FUNCTION Real3 vectorValue(Real, Real3) const
Evaluate a vector value at point (t,x,y,z)
virtual KOKKOS_FUNCTION Real timeDerivative(Real t, Real3 p) const =0
KOKKOS_FUNCTION Real integral() const
FunctionBase(const InputParameters &parameters)
Constructor.
virtual KOKKOS_FUNCTION Real div(Real t, Real3 p) const =0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
KOKKOS_FUNCTION Real average() const
KOKKOS_FUNCTION Real div(Real t, Real3 p) const
virtual KOKKOS_FUNCTION Real value(Real t, Real3 p) const =0
Virtual shims that calls the corresponding methods of the actual stored function. ...
virtual KOKKOS_FUNCTION Real3 curl(Real t, Real3 p) const =0
KOKKOS_FUNCTION Real value(Real, Real3) const
Evaluate a scalar value at point (t,x,y,z)
KOKKOS_FUNCTION Real timeDerivative(Real, Real3) const
Evaluate a time derivative at point (t,x,y,z)
KOKKOS_FUNCTION Real value(Real t, Real3 p) const