forked from idaholab/moose
/
Function.h
226 lines (196 loc) · 7.96 KB
/
Function.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
#pragma once
#include "MooseObject.h"
#include "SetupInterface.h"
#include "TransientInterface.h"
#include "PostprocessorInterface.h"
#include "UserObjectInterface.h"
#include "Restartable.h"
#include "MeshChangedInterface.h"
#include "ScalarCoupleable.h"
#include "MooseFunctor.h"
#include "MooseADWrapper.h"
#include "ChainedReal.h"
// libMesh
#include "libmesh/vector_value.h"
// libMesh forward declarations
namespace libMesh
{
class Point;
}
/**
* Base class for function objects. Functions override value to supply a
* value at a point.
*/
class Function : public MooseObject,
public SetupInterface,
public TransientInterface,
public PostprocessorInterface,
public UserObjectInterface,
public Restartable,
public MeshChangedInterface,
public ScalarCoupleable,
public Moose::FunctorBase<Real>
{
public:
/**
* Class constructor
* \param parameters The input parameters for the function
*/
static InputParameters validParams();
Function(const InputParameters & parameters);
/**
* Function destructor
*/
virtual ~Function();
/**
* Override this to evaluate the scalar function at point (t,x,y,z), by default
* this returns zero, you must override it.
* \param t The time
* \param p The Point in space (x,y,z)
* \return A scalar of the function evaluated at the time and location
*/
virtual Real value(Real t, const Point & p) const;
/**
* Override this to evaluate the scalar function at point (t,x,y,z), using dual numbers by default
* this uses value, gradient, and timeDerivative to assemble a dual number, although the function
* can be overridden with a custom computation using dual numbers.
* \param t The time
* \param p The Point in space (x,y,z)
* \return A scalar of the function evaluated at the time and location
*/
virtual ADReal value(const ADReal & t, const ADPoint & p) const;
///@{ Helpers to call value(t,x,y,z)
ChainedReal value(const ChainedReal & t) const;
template <typename U>
auto value(const U & t) const;
template <typename U>
auto value(const U & t, const U & x, const U & y = 0, const U & z = 0) const;
///@}
/**
* Override this to evaluate the vector function at a point (t,x,y,z), by default
* this returns a zero vector, you must override it.
* \param t The time
* \param p The Point in space (x,y,z)
* \return A vector of the function evaluated at the time and location
*/
virtual RealVectorValue vectorValue(Real t, const Point & p) const;
/**
* Override this to evaluate the curl of the vector function at a point (t,x,y,z),
* by default this returns a zero vector, you must override it.
* \param t The time
* \param p The Point in space (x,y,z)
* \return A vector of the curl of the function evaluated at the time and location
*/
virtual RealVectorValue vectorCurl(Real t, const Point & p) const;
using Moose::FunctorBase<Real>::gradient;
/**
* Function objects can optionally provide a gradient at a point. By default
* this returns 0, you must override it.
* \param t The time
* \param p The Point in space (x,y,z)
* \return A gradient of the function evaluated at the time and location
*/
virtual RealGradient gradient(Real t, const Point & p) const;
/**
* Get the time derivative of the function
* \param t The time
* \param p The point in space (x,y,z)
* \return The time derivative of the function at the specified time and location
*/
virtual Real timeDerivative(Real t, const Point & p) const;
///@{ Helpers to call timeDerivative(t,x,y,z)
template <typename U>
auto timeDerivative(const U & t) const;
template <typename U>
auto timeDerivative(const U & t, const U & x, const U & y = 0, const U & z = 0) const;
///@}
// Not defined
virtual Real integral() const;
// Not defined
virtual Real average() const;
void timestepSetup() override;
void residualSetup() override;
void jacobianSetup() override;
void customSetup(const ExecFlagType & exec_type) override;
bool hasBlocks(SubdomainID) const override { return true; }
private:
using typename Moose::FunctorBase<Real>::ValueType;
using typename Moose::FunctorBase<Real>::GradientType;
using typename Moose::FunctorBase<Real>::DotType;
using ElemArg = Moose::ElemArg;
using ElemQpArg = Moose::ElemQpArg;
using ElemSideQpArg = Moose::ElemSideQpArg;
using FaceArg = Moose::FaceArg;
using ElemPointArg = Moose::ElemPointArg;
using NodeArg = Moose::NodeArg;
template <typename R>
ValueType evaluateHelper(const R & r, const Moose::StateArg & state) const;
ValueType evaluate(const ElemArg & elem, const Moose::StateArg & state) const override final;
ValueType evaluate(const FaceArg & face, const Moose::StateArg & state) const override final;
ValueType evaluate(const ElemQpArg & qp, const Moose::StateArg & state) const override final;
ValueType evaluate(const ElemSideQpArg & elem_side_qp,
const Moose::StateArg & state) const override final;
ValueType evaluate(const ElemPointArg & elem_point,
const Moose::StateArg & state) const override final;
ValueType evaluate(const NodeArg & node, const Moose::StateArg & state) const override final;
template <typename R>
GradientType evaluateGradientHelper(const R & r, const Moose::StateArg & state) const;
GradientType evaluateGradient(const ElemArg & elem,
const Moose::StateArg & state) const override final;
GradientType evaluateGradient(const FaceArg & face,
const Moose::StateArg & state) const override final;
GradientType evaluateGradient(const ElemQpArg & qp,
const Moose::StateArg & state) const override final;
GradientType evaluateGradient(const ElemSideQpArg & elem_side_qp,
const Moose::StateArg & state) const override final;
GradientType evaluateGradient(const ElemPointArg & elem_point,
const Moose::StateArg & state) const override final;
GradientType evaluateGradient(const NodeArg & node,
const Moose::StateArg & state) const override final;
template <typename R>
DotType evaluateDotHelper(const R & r, const Moose::StateArg & state) const;
DotType evaluateDot(const ElemArg & elem, const Moose::StateArg & state) const override final;
DotType evaluateDot(const FaceArg & face, const Moose::StateArg & state) const override final;
DotType evaluateDot(const ElemQpArg & qp, const Moose::StateArg & state) const override final;
DotType evaluateDot(const ElemSideQpArg & elem_side_qp,
const Moose::StateArg & state) const override final;
DotType evaluateDot(const ElemPointArg & elem_point,
const Moose::StateArg & state) const override final;
DotType evaluateDot(const NodeArg & node, const Moose::StateArg & state) const override final;
};
template <typename U>
auto
Function::value(const U & t) const
{
static const MooseADWrapper<Point, MooseIsADType<U>::value> p;
return value(t, p);
}
template <typename U>
auto
Function::value(const U & t, const U & x, const U & y, const U & z) const
{
MooseADWrapper<Point, MooseIsADType<U>::value> p(x, y, z);
return value(t, p);
}
template <typename U>
auto
Function::timeDerivative(const U & t) const
{
static const MooseADWrapper<Point, MooseIsADType<U>::value> p;
return timeDerivative(t, p);
}
template <typename U>
auto
Function::timeDerivative(const U & t, const U & x, const U & y, const U & z) const
{
MooseADWrapper<Point, MooseIsADType<U>::value> p(x, y, z);
return timeDerivative(t, p);
}