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
171 Function & operator=(const Function & function) = default;
172
177 KOKKOS_FUNCTION operator bool() const
178 {
179 KOKKOS_IF_ON_HOST(return static_cast<bool>(_wrapper_host);)
180
181 return _wrapper_device != nullptr;
182 }
183
184 KOKKOS_FUNCTION Real value(Real t, Real3 p) const
185 {
186 KOKKOS_ASSERT(_wrapper_device);
187
188 return _wrapper_device->value(t, p);
189 }
190 KOKKOS_FUNCTION Real3 vectorValue(Real t, Real3 p) const
191 {
192 KOKKOS_ASSERT(_wrapper_device);
193
194 return _wrapper_device->vectorValue(t, p);
195 }
196 KOKKOS_FUNCTION Real3 gradient(Real t, Real3 p) const
197 {
198 KOKKOS_ASSERT(_wrapper_device);
199
200 return _wrapper_device->gradient(t, p);
201 }
202 KOKKOS_FUNCTION Real3 curl(Real t, Real3 p) const
203 {
204 KOKKOS_ASSERT(_wrapper_device);
205
206 return _wrapper_device->curl(t, p);
207 }
208 KOKKOS_FUNCTION Real div(Real t, Real3 p) const
209 {
210 KOKKOS_ASSERT(_wrapper_device);
211
212 return _wrapper_device->div(t, p);
213 }
214 KOKKOS_FUNCTION Real timeDerivative(Real t, Real3 p) const
215 {
216 KOKKOS_ASSERT(_wrapper_device);
217
218 return _wrapper_device->timeDerivative(t, p);
219 }
220 KOKKOS_FUNCTION Real timeIntegral(Real t1, Real t2, Real3 p) const
221 {
222 KOKKOS_ASSERT(_wrapper_device);
223
224 return _wrapper_device->timeIntegral(t1, t2, p);
225 }
226 KOKKOS_FUNCTION Real integral() const
227 {
228 KOKKOS_ASSERT(_wrapper_device);
229
230 return _wrapper_device->integral();
231 }
232 KOKKOS_FUNCTION Real average() const
233 {
234 KOKKOS_ASSERT(_wrapper_device);
235
236 return _wrapper_device->average();
237 }
238
239private:
243 std::shared_ptr<FunctionWrapperHostBase> _wrapper_host;
248};
249
250template <>
252{
253 static constexpr bool value = true;
254};
255
256} // 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.
Function & operator=(const Function &function)=default
Copy assignment operator.
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
The type trait that determines the default behavior of copy constructor and deepCopy() If this type t...
Definition KokkosArray.h:92
static constexpr bool value
Definition KokkosArray.h:93