https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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"
15
16#include "FunctionBase.h"
17
18namespace Moose::Kokkos
19{
20
30{
31public:
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
147class Function final
148{
149public:
153 Function() = default;
158 Function(std::shared_ptr<FunctionWrapperHostBase> wrapper);
162 Function(const Function & function);
167
172 KOKKOS_FUNCTION operator bool() const
173 {
174 KOKKOS_IF_ON_HOST(return static_cast<bool>(_wrapper_host);)
175
176 return _wrapper_device != nullptr;
177 }
178
179 KOKKOS_FUNCTION Real value(Real t, Real3 p) const
180 {
181 KOKKOS_ASSERT(_wrapper_device);
182
183 return _wrapper_device->value(t, p);
184 }
185 KOKKOS_FUNCTION Real3 vectorValue(Real t, Real3 p) const
186 {
187 KOKKOS_ASSERT(_wrapper_device);
188
189 return _wrapper_device->vectorValue(t, p);
190 }
191 KOKKOS_FUNCTION Real3 gradient(Real t, Real3 p) const
192 {
193 KOKKOS_ASSERT(_wrapper_device);
194
195 return _wrapper_device->gradient(t, p);
196 }
197 KOKKOS_FUNCTION Real3 curl(Real t, Real3 p) const
198 {
199 KOKKOS_ASSERT(_wrapper_device);
200
201 return _wrapper_device->curl(t, p);
202 }
203 KOKKOS_FUNCTION Real div(Real t, Real3 p) const
204 {
205 KOKKOS_ASSERT(_wrapper_device);
206
207 return _wrapper_device->div(t, p);
208 }
209 KOKKOS_FUNCTION Real timeDerivative(Real t, Real3 p) const
210 {
211 KOKKOS_ASSERT(_wrapper_device);
212
213 return _wrapper_device->timeDerivative(t, p);
214 }
215 KOKKOS_FUNCTION Real timeIntegral(Real t1, Real t2, Real3 p) const
216 {
217 KOKKOS_ASSERT(_wrapper_device);
218
219 return _wrapper_device->timeIntegral(t1, t2, p);
220 }
221 KOKKOS_FUNCTION Real integral() const
222 {
223 KOKKOS_ASSERT(_wrapper_device);
224
225 return _wrapper_device->integral();
226 }
227 KOKKOS_FUNCTION Real average() const
228 {
229 KOKKOS_ASSERT(_wrapper_device);
230
231 return _wrapper_device->average();
232 }
233
234private:
238 std::shared_ptr<FunctionWrapperHostBase> _wrapper_host;
243};
244
245} // namespace Moose::Kokkos
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
The base class for a user to derive their own Kokkos functions.
KOKKOS_FUNCTION Real3 curl(Real, Real3) const
Evaluate a curl at point (t,x,y,z)
KOKKOS_FUNCTION Real average() const
Evaluate the average over the domain.
FunctionBase(const FunctionBase &object)
Copy constructor for parallel dispatch.
KOKKOS_FUNCTION Real3 gradient(Real, Real3) const
Evaluate a gradient at point (t,x,y,z)
KOKKOS_FUNCTION Real integral() const
Evaluate the integral over the domain.
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 timeDerivative(Real, Real3) const
Evaluate a time derivative at point (t,x,y,z)
KOKKOS_FUNCTION Real value(Real, Real3) const
Evaluate a scalar value at point (t,x,y,z)
KOKKOS_FUNCTION Real div(Real, Real3) const
Evaluate a divergence at point (t,x,y,z)
static InputParameters validParams()
FunctionBase(const InputParameters &parameters)
Constructor.
KOKKOS_FUNCTION Real3 vectorValue(Real, Real3) const
Evaluate a vector value at point (t,x,y,z)
Base class for device function wrapper.
KOKKOS_FUNCTION KOKKOS_VIRTUAL Real3 gradient(Real, Real3) const
KOKKOS_FUNCTION KOKKOS_VIRTUAL Real value(Real, Real3) const
Virtual shims that calls the corresponding methods of the actual stored function.
KOKKOS_FUNCTION KOKKOS_VIRTUAL Real average() const
KOKKOS_FUNCTION KOKKOS_VIRTUAL Real timeIntegral(Real, Real, Real3) const
KOKKOS_FUNCTION KOKKOS_VIRTUAL Real3 vectorValue(Real, Real3) const
KOKKOS_FUNCTION KOKKOS_VIRTUAL Real timeDerivative(Real, Real3) const
KOKKOS_FUNCTION KOKKOS_VIRTUAL Real div(Real, Real3) const
KOKKOS_FUNCTION KOKKOS_VIRTUAL Real3 curl(Real, Real3) const
KOKKOS_FUNCTION KOKKOS_VIRTUAL Real integral() const
The abstract class that provides polymorphic interfaces for a function.
KOKKOS_FUNCTION Real timeDerivative(Real t, Real3 p) const
Function()=default
Default constructor.
KOKKOS_FUNCTION Real3 curl(Real t, Real3 p) const
KOKKOS_FUNCTION Real average() const
std::shared_ptr< FunctionWrapperHostBase > _wrapper_host
Pointer to the host function wrapper.
KOKKOS_FUNCTION Real value(Real t, Real3 p) const
FunctionWrapperDeviceBase * _wrapper_device
Pointer to the device function wrapper.
Function(const Function &function)
Copy constructor for parallel dispatch.
KOKKOS_FUNCTION Real integral() const
Function(std::shared_ptr< FunctionWrapperHostBase > wrapper)
Constructor.
KOKKOS_FUNCTION Real div(Real t, Real3 p) const
KOKKOS_FUNCTION Real timeIntegral(Real t1, Real t2, Real3 p) const
KOKKOS_FUNCTION Real3 gradient(Real t, Real3 p) const
KOKKOS_FUNCTION Real3 vectorValue(Real t, Real3 p) const
Vector3< Real > Real3
Definition KokkosTypes.h:32