https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Function.C
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#include "Function.h"
11#include "FEProblemBase.h"
12
13using namespace Moose;
14
17{
19 return params;
20}
21
23 : FunctionBase(parameters), Moose::FunctorBase<Real>(name())
24{
25}
26
28
29Real
30Function::value(Real /*t*/, const Point & /*p*/) const
31{
32 mooseError("value method not implemented");
33 return 0.0;
34}
35
37Function::value(const ADReal & t, const ADPoint & p) const
38{
39 const auto rt = MetaPhysicL::raw_value(t);
40 const auto rp = MetaPhysicL::raw_value(p);
41 const auto grad = gradient(rt, rp);
42 ADReal ret = value(rt, rp);
43 ret.derivatives() = grad(0) * p(0).derivatives()
44#if LIBMESH_DIM > 1
45 + grad(1) * p(1).derivatives()
46#endif
47#if LIBMESH_DIM > 2
48 + grad(2) * p(2).derivatives()
49#endif
50 + timeDerivative(rt, rp) * t.derivatives();
51 return ret;
53
56{
57 static const Point p;
58 return {value(t.value(), p), timeDerivative(t.value(), p) * t.derivatives()};
59}
60
61RealGradient
62Function::gradient(Real /*t*/, const Point & /*p*/) const
63{
64 mooseError("gradient method not implemented");
65 return RealGradient(0, 0, 0);
66}
67
68Real
69Function::timeDerivative(Real /*t*/, const Point & /*p*/) const
70{
71 mooseError("timeDerivative method not implemented");
72 return 0;
73}
74
75Real
76Function::timeIntegral(Real /*t1*/, Real /*t2*/, const Point & /*p*/) const
77{
78 mooseError("timeIntegral() not implemented.");
79}
80
81RealVectorValue
82Function::vectorValue(Real /*t*/, const Point & /*p*/) const
83{
84 mooseError("vectorValue method not implemented");
85 return RealVectorValue(0, 0, 0);
86}
87
88RealVectorValue
89Function::curl(Real /*t*/, const Point & /*p*/) const
90{
91 mooseError("curl method not implemented");
92 return RealVectorValue(0, 0, 0);
93}
94
95Real
96Function::div(Real /*t*/, const Point & /*p*/) const
97{
98 mooseError("div method not implemented");
99 return 0;
100}
101
102Real
104{
105 mooseError("Integral method not implemented for function ", name());
106 return 0;
108
109Real
111{
112 mooseError("Average method not implemented for function ", name());
113 return 0;
114}
115
116template <typename R>
117typename Function::ValueType
118Function::evaluateHelper(const R & r, const Moose::StateArg & state) const
119{
120 return value(_ti_feproblem.getTimeFromStateArg(state), r.getPoint());
121}
122
123typename Function::ValueType
124Function::evaluate(const ElemArg & elem_arg, const Moose::StateArg & state) const
125{
126 return evaluateHelper(elem_arg, state);
127}
128
129typename Function::ValueType
130Function::evaluate(const FaceArg & face, const Moose::StateArg & state) const
131{
132 if (face.face_side && face.fi->neighborPtr() &&
133 (face.fi->elem().subdomain_id() != face.fi->neighbor().subdomain_id()))
134 {
135 // Some users like to put discontinuities in their functions at subdomain changes in which case
136 // in order to always get the proper discontinuous effect we should evaluate ever so slightly
137 // off the face. Consider evaluation of: if(x < 0, -1, 1) if the face centroid is right at x ==
138 // 0 for example. The user likely doesn't want you to return 1 if they've asked for a 0-
139 // evaluation
140 //
141 // I can't quite tell but I think the tolerance for comparing coordinates (x, y, z, t) in
142 // fparser is ~1e-9 so we need to use something larger than that. The comparison is absolute
143 static constexpr Real offset_tolerance = 1e-8;
144 auto offset = offset_tolerance * face.fi->normal();
145 if (face.face_side == face.fi->elemPtr())
146 offset *= -1;
147 return value(_ti_feproblem.getTimeFromStateArg(state), face.getPoint() + offset);
148 }
149 else
150 return value(_ti_feproblem.getTimeFromStateArg(state), face.getPoint());
151}
152
153typename Function::ValueType
154Function::evaluate(const ElemQpArg & elem_qp, const Moose::StateArg & state) const
155{
156 return evaluateHelper(elem_qp, state);
157}
158
159typename Function::ValueType
160Function::evaluate(const ElemSideQpArg & elem_side_qp, const Moose::StateArg & state) const
161{
162 return evaluateHelper(elem_side_qp, state);
163}
164
165typename Function::ValueType
166Function::evaluate(const ElemPointArg & elem_point_arg, const Moose::StateArg & state) const
167{
168 return evaluateHelper(elem_point_arg, state);
169}
170
171typename Function::ValueType
172Function::evaluate(const NodeArg & node_arg, const Moose::StateArg & state) const
173{
174 return evaluateHelper(node_arg, state);
175}
176
177template <typename R>
179Function::evaluateGradientHelper(const R & r, const Moose::StateArg & state) const
180{
181 return gradient(_ti_feproblem.getTimeFromStateArg(state), r.getPoint());
182}
183
185Function::evaluateGradient(const ElemArg & elem_arg, const Moose::StateArg & state) const
186{
187 return evaluateGradientHelper(elem_arg, state);
188}
189
191Function::evaluateGradient(const FaceArg & face, const Moose::StateArg & state) const
192{
193 return evaluateGradientHelper(face, state);
194}
195
197Function::evaluateGradient(const ElemQpArg & elem_qp, const Moose::StateArg & state) const
198{
199 return evaluateGradientHelper(elem_qp, state);
200}
201
203Function::evaluateGradient(const ElemSideQpArg & elem_side_qp, const Moose::StateArg & state) const
204{
205 return evaluateGradientHelper(elem_side_qp, state);
206}
207
209Function::evaluateGradient(const ElemPointArg & elem_point_arg, const Moose::StateArg & state) const
210{
211 return evaluateGradientHelper(elem_point_arg, state);
212}
213
215Function::evaluateGradient(const NodeArg & node_arg, const Moose::StateArg & state) const
216{
217 return evaluateGradientHelper(node_arg, state);
218}
219
220template <typename R>
221typename Function::DotType
222Function::evaluateDotHelper(const R & r, const Moose::StateArg & state) const
223{
224 return timeDerivative(_ti_feproblem.getTimeFromStateArg(state), r.getPoint());
225}
226
227typename Function::DotType
228Function::evaluateDot(const ElemArg & elem_arg, const Moose::StateArg & state) const
229{
230 return evaluateDotHelper(elem_arg, state);
231}
232
233typename Function::DotType
234Function::evaluateDot(const FaceArg & face, const Moose::StateArg & state) const
235{
236 return evaluateDotHelper(face, state);
237}
238
239typename Function::DotType
240Function::evaluateDot(const ElemQpArg & elem_qp, const Moose::StateArg & state) const
241{
242 return evaluateDotHelper(elem_qp, state);
243}
244
245typename Function::DotType
246Function::evaluateDot(const ElemSideQpArg & elem_side_qp, const Moose::StateArg & state) const
247{
248 return evaluateDotHelper(elem_side_qp, state);
249}
250
251typename Function::DotType
252Function::evaluateDot(const ElemPointArg & elem_point_arg, const Moose::StateArg & state) const
253{
254 return evaluateDotHelper(elem_point_arg, state);
255}
256
257typename Function::DotType
258Function::evaluateDot(const NodeArg & node_arg, const Moose::StateArg & state) const
259{
260 return evaluateDotHelper(node_arg, state);
261}
262
263void
268
269void
274
275void
280
281void
283{
285}
DualNumber< Real, DNDerivativeType, true > ADReal
DualNumber< Real, Real > ChainedReal
Definition ChainedReal.h:30
Real getTimeFromStateArg(const Moose::StateArg &state) const
Returns the time associated with the requested state.
const Point & normal() const
Returns the unit normal vector for the face oriented outward from the face's elem element.
Definition FaceInfo.h:72
const Elem & elem() const
Definition FaceInfo.h:85
const Elem * neighborPtr() const
Definition FaceInfo.h:88
const Elem * elemPtr() const
Definition FaceInfo.h:86
const Elem & neighbor() const
Definition FaceInfo.h:220
virtual Real integral() const
Returns the integral of the function over its domain.
Definition Function.C:103
DotType evaluateDot(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor time derivative with a given element.
Definition Function.C:228
static InputParameters validParams()
Class constructor.
Definition Function.C:16
virtual RealGradient gradient(Real t, const Point &p) const
Function objects can optionally provide a gradient at a point.
Definition Function.C:62
virtual Real timeIntegral(Real t1, Real t2, const Point &p) const
Computes the time integral at a spatial point between two time values.
Definition Function.C:76
void residualSetup() override final
Gets called just before the residual is computed and before this object is asked to do its job.
Definition Function.C:270
void customSetup(const ExecFlagType &exec_type) override final
Gets called in FEProblemBase::execute() for execute flags other than initial, timestep_begin,...
Definition Function.C:282
virtual ~Function()
Function destructor.
Definition Function.C:27
DotType evaluateDotHelper(const R &r, const Moose::StateArg &state) const
Definition Function.C:222
ValueType evaluateHelper(const R &r, const Moose::StateArg &state) const
Definition Function.C:118
virtual RealVectorValue curl(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 retur...
Definition Function.C:89
virtual Real value(Real t, const Point &p) const
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero,...
Definition Function.C:30
ValueType evaluate(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor with a given element.
Definition Function.C:124
virtual Real timeDerivative(Real t, const Point &p) const
Get the time derivative of the function.
Definition Function.C:69
Function(const InputParameters &parameters)
Definition Function.C:22
GradientType evaluateGradient(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor gradient with a given element.
Definition Function.C:185
GradientType evaluateGradientHelper(const R &r, const Moose::StateArg &state) const
Definition Function.C:179
virtual Real div(Real t, const Point &p) const
Override this to evaluate the divergence of the vector function at a point (t,x,y,...
Definition Function.C:96
void timestepSetup() override
Gets called at the beginning of the timestep before this object is asked to do its job.
Definition Function.C:264
virtual Real average() const
Returns the average of the function over its domain.
Definition Function.C:110
virtual RealVectorValue vectorValue(Real t, const Point &p) const
Override this to evaluate the vector function at a point (t,x,y,z), by default this returns a zero ve...
Definition Function.C:82
void jacobianSetup() override final
Gets called just before the Jacobian is computed and before this object is asked to do its job.
Definition Function.C:276
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
Class for containing MooseEnum item information.
static InputParameters validParams()
Base class template for functor objects.
typename FunctorReturnType< Real, FunctorEvaluationKind::Gradient >::type GradientType
This rigmarole makes it so that a user can create functors that return containers (std::vector,...
virtual void residualSetup() override
virtual void timestepSetup() override
virtual void customSetup(const ExecFlagType &exec_type) override
virtual void jacobianSetup() override
FEProblemBase & _ti_feproblem
auto raw_value(const Eigen::Map< T > &in)
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
A structure that is used to evaluate Moose functors logically at an element/cell center.
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
Argument for requesting functor evaluation at a quadrature point location in an element.
Argument for requesting functor evaluation at quadrature point locations on an element side.
A structure defining a "face" evaluation calling argument for Moose functors.
const libMesh::Elem * face_side
A member that can be used to indicate whether there is a sidedness to this face.
const FaceInfo * fi
a face information object which defines our location in space
libMesh::Point getPoint() const
State argument for evaluating functors.