Line data Source code
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
19 : {
20 : namespace Kokkos
21 : {
22 :
23 : /**
24 : * The base class for a user to derive their own Kokkos functions.
25 : *
26 : * The user should define the hook methods in their derived class as inlined public methods (not
27 : * virtual override) with the same signature. If they are defined in the derived class, they will
28 : * hide the default definitions in the base class. However, the default definitions are not to be
29 : * actually called. If a hook method was not defined in the derived class, it should not be called.
30 : */
31 : class FunctionBase : public Moose::FunctionBase
32 : {
33 : public:
34 : static InputParameters validParams();
35 :
36 : /**
37 : * Constructor
38 : */
39 : FunctionBase(const InputParameters & parameters);
40 : /**
41 : * Copy constructor for parallel dispatch
42 : */
43 : FunctionBase(const FunctionBase & object);
44 :
45 : /**
46 : * Evaluate a scalar value at point (t,x,y,z)
47 : * @param t The time
48 : * @param p The location in space (x,y,z)
49 : * @returns The scalar value evaluated at the time and location
50 : */
51 : KOKKOS_FUNCTION Real value(Real /* t */, Real3 /* p */) const
52 : {
53 : KOKKOS_ASSERT(false);
54 : return 0;
55 : }
56 : /**
57 : * Evaluate a vector value at point (t,x,y,z)
58 : * @param t The time
59 : * @param p The location in space (x,y,z)
60 : * @returns The vector value evaluated at the time and location
61 : */
62 0 : KOKKOS_FUNCTION Real3 vectorValue(Real /* t */, Real3 /* p */) const
63 : {
64 : KOKKOS_ASSERT(false);
65 0 : return Real3(0);
66 : }
67 : /**
68 : * Evaluate a gradient at point (t,x,y,z)
69 : * @param t The time
70 : * @param p The location in space (x,y,z)
71 : * @returns The gradient evaluated at the time and location
72 : */
73 0 : KOKKOS_FUNCTION Real3 gradient(Real /* t */, Real3 /* p */) const
74 : {
75 : KOKKOS_ASSERT(false);
76 0 : return Real3(0);
77 : }
78 : /**
79 : * Evaluate a curl at point (t,x,y,z)
80 : * @param t The time
81 : * @param p The location in space (x,y,z)
82 : * @returns The curl evaluated at the time and location
83 : */
84 0 : KOKKOS_FUNCTION Real3 curl(Real /* t */, Real3 /* p */) const
85 : {
86 : KOKKOS_ASSERT(false);
87 0 : return Real3(0);
88 : }
89 : /**
90 : * Evaluate a divergence at point (t,x,y,z)
91 : * @param t The time
92 : * @param p The location in space (x,y,z)
93 : * @returns The divergence evaluated at the time and location
94 : */
95 0 : KOKKOS_FUNCTION Real div(Real /* t */, Real3 /* p */) const
96 : {
97 : KOKKOS_ASSERT(false);
98 0 : return 0;
99 : }
100 : /**
101 : * Evaluate a time derivative at point (t,x,y,z)
102 : * @param t The time
103 : * @param p The location in space (x,y,z)
104 : * @returns The time derivative evaluated at the time and location
105 : */
106 0 : KOKKOS_FUNCTION Real timeDerivative(Real /* t */, Real3 /* p */) const
107 : {
108 : KOKKOS_ASSERT(false);
109 0 : return 0;
110 : }
111 : /**
112 : * Evaluate a time integral at point (x,y,z) between time \p t1 and \p t2
113 : * @param t1 The beginning time
114 : * @param t2 The end time
115 : * @param p The location in space (x,y,z)
116 : * @returns The time integral evaluated at the location between the times
117 : */
118 0 : KOKKOS_FUNCTION Real timeIntegral(Real /* t1 */, Real /* t2 */, Real3 /* p */) const
119 : {
120 : KOKKOS_ASSERT(false);
121 0 : return 0;
122 : }
123 : /**
124 : * Evaluate the integral over the domain
125 : * @returns The integral over the domain
126 : */
127 0 : KOKKOS_FUNCTION Real integral() const
128 : {
129 : KOKKOS_ASSERT(false);
130 0 : return 0;
131 : }
132 : /**
133 : * Evaluate the average over the domain
134 : * @returns The average over the domain
135 : */
136 0 : KOKKOS_FUNCTION Real average() const
137 : {
138 : KOKKOS_ASSERT(false);
139 0 : return 0;
140 : }
141 : };
142 :
143 : /**
144 : * The abstract class that provides polymorphic interfaces for a function.
145 : *
146 : * NOTE: This class is not the base class for a Kokkos function derivation. The user should derive
147 : * their own function from Moose::Kokkos::FunctionBase.
148 : */
149 : class Function final
150 : {
151 : public:
152 : /**
153 : * Constructor
154 : * @param wrapper The host function wrapper
155 : */
156 : Function(std::shared_ptr<FunctionWrapperHostBase> wrapper);
157 : /**
158 : * Copy constructor for parallel dispatch
159 : */
160 : Function(const Function & function);
161 : /**
162 : * Destructor
163 : */
164 : ~Function();
165 :
166 12656539 : KOKKOS_FUNCTION Real value(Real t, Real3 p) const { return _wrapper_device->value(t, p); }
167 : KOKKOS_FUNCTION Real3 vectorValue(Real t, Real3 p) const
168 : {
169 : return _wrapper_device->vectorValue(t, p);
170 : }
171 : KOKKOS_FUNCTION Real3 gradient(Real t, Real3 p) const { return _wrapper_device->gradient(t, p); }
172 : KOKKOS_FUNCTION Real3 curl(Real t, Real3 p) const { return _wrapper_device->curl(t, p); }
173 : KOKKOS_FUNCTION Real div(Real t, Real3 p) const { return _wrapper_device->div(t, p); }
174 : KOKKOS_FUNCTION Real timeDerivative(Real t, Real3 p) const
175 : {
176 : return _wrapper_device->timeDerivative(t, p);
177 : }
178 : KOKKOS_FUNCTION Real timeIntegral(Real t1, Real t2, Real3 p) const
179 : {
180 : return _wrapper_device->timeIntegral(t1, t2, p);
181 : }
182 : KOKKOS_FUNCTION Real integral() const { return _wrapper_device->integral(); }
183 : KOKKOS_FUNCTION Real average() const { return _wrapper_device->average(); }
184 :
185 : private:
186 : /**
187 : * Pointer to the host function wrapper
188 : */
189 : std::shared_ptr<FunctionWrapperHostBase> _wrapper_host;
190 : /**
191 : * Pointer to the device function wrapper
192 : */
193 : FunctionWrapperDeviceBase * _wrapper_device = nullptr;
194 : };
195 :
196 : }
197 : }
|