https://mooseframework.inl.gov
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 
13 using namespace Moose;
14 
17 {
19  return params;
20 }
21 
23  : FunctionBase(parameters), Moose::FunctorBase<Real>(name())
24 {
25 }
26 
28 
29 Real
30 Function::value(Real /*t*/, const Point & /*p*/) const
31 {
32  mooseError("value method not implemented");
33  return 0.0;
34 }
35 
36 ADReal
37 Function::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;
52 }
53 
55 Function::value(const ChainedReal & t) const
56 {
57  static const Point p;
58  return {value(t.value(), p), timeDerivative(t.value(), p) * t.derivatives()};
59 }
60 
62 Function::gradient(Real /*t*/, const Point & /*p*/) const
63 {
64  mooseError("gradient method not implemented");
65  return RealGradient(0, 0, 0);
66 }
67 
68 Real
69 Function::timeDerivative(Real /*t*/, const Point & /*p*/) const
70 {
71  mooseError("timeDerivative method not implemented");
72  return 0;
73 }
74 
75 Real
76 Function::timeIntegral(Real /*t1*/, Real /*t2*/, const Point & /*p*/) const
77 {
78  mooseError("timeIntegral() not implemented.");
79 }
80 
82 Function::vectorValue(Real /*t*/, const Point & /*p*/) const
83 {
84  mooseError("vectorValue method not implemented");
85  return RealVectorValue(0, 0, 0);
86 }
87 
89 Function::curl(Real /*t*/, const Point & /*p*/) const
90 {
91  mooseError("curl method not implemented");
92  return RealVectorValue(0, 0, 0);
93 }
94 
95 Real
96 Function::div(Real /*t*/, const Point & /*p*/) const
97 {
98  mooseError("div method not implemented");
99  return 0;
100 }
101 
102 Real
104 {
105  mooseError("Integral method not implemented for function ", name());
106  return 0;
107 }
108 
109 Real
111 {
112  mooseError("Average method not implemented for function ", name());
113  return 0;
114 }
115 
116 template <typename R>
117 typename Function::ValueType
118 Function::evaluateHelper(const R & r, const Moose::StateArg & state) const
119 {
120  return value(_ti_feproblem.getTimeFromStateArg(state), r.getPoint());
121 }
122 
123 typename Function::ValueType
124 Function::evaluate(const ElemArg & elem_arg, const Moose::StateArg & state) const
125 {
126  return evaluateHelper(elem_arg, state);
127 }
128 
129 typename Function::ValueType
130 Function::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 
153 typename Function::ValueType
154 Function::evaluate(const ElemQpArg & elem_qp, const Moose::StateArg & state) const
155 {
156  return evaluateHelper(elem_qp, state);
157 }
158 
159 typename Function::ValueType
160 Function::evaluate(const ElemSideQpArg & elem_side_qp, const Moose::StateArg & state) const
161 {
162  return evaluateHelper(elem_side_qp, state);
163 }
164 
165 typename Function::ValueType
166 Function::evaluate(const ElemPointArg & elem_point_arg, const Moose::StateArg & state) const
167 {
168  return evaluateHelper(elem_point_arg, state);
169 }
170 
171 typename Function::ValueType
172 Function::evaluate(const NodeArg & node_arg, const Moose::StateArg & state) const
173 {
174  return evaluateHelper(node_arg, state);
175 }
176 
177 template <typename R>
178 typename Function::GradientType
179 Function::evaluateGradientHelper(const R & r, const Moose::StateArg & state) const
180 {
181  return gradient(_ti_feproblem.getTimeFromStateArg(state), r.getPoint());
182 }
183 
184 typename Function::GradientType
185 Function::evaluateGradient(const ElemArg & elem_arg, const Moose::StateArg & state) const
186 {
187  return evaluateGradientHelper(elem_arg, state);
188 }
189 
190 typename Function::GradientType
191 Function::evaluateGradient(const FaceArg & face, const Moose::StateArg & state) const
192 {
193  return evaluateGradientHelper(face, state);
194 }
195 
196 typename Function::GradientType
197 Function::evaluateGradient(const ElemQpArg & elem_qp, const Moose::StateArg & state) const
198 {
199  return evaluateGradientHelper(elem_qp, state);
200 }
201 
202 typename Function::GradientType
203 Function::evaluateGradient(const ElemSideQpArg & elem_side_qp, const Moose::StateArg & state) const
204 {
205  return evaluateGradientHelper(elem_side_qp, state);
206 }
207 
208 typename Function::GradientType
209 Function::evaluateGradient(const ElemPointArg & elem_point_arg, const Moose::StateArg & state) const
210 {
211  return evaluateGradientHelper(elem_point_arg, state);
212 }
213 
214 typename Function::GradientType
215 Function::evaluateGradient(const NodeArg & node_arg, const Moose::StateArg & state) const
216 {
217  return evaluateGradientHelper(node_arg, state);
218 }
219 
220 template <typename R>
221 typename Function::DotType
222 Function::evaluateDotHelper(const R & r, const Moose::StateArg & state) const
223 {
224  return timeDerivative(_ti_feproblem.getTimeFromStateArg(state), r.getPoint());
225 }
226 
227 typename Function::DotType
228 Function::evaluateDot(const ElemArg & elem_arg, const Moose::StateArg & state) const
229 {
230  return evaluateDotHelper(elem_arg, state);
231 }
232 
233 typename Function::DotType
234 Function::evaluateDot(const FaceArg & face, const Moose::StateArg & state) const
235 {
236  return evaluateDotHelper(face, state);
237 }
238 
239 typename Function::DotType
240 Function::evaluateDot(const ElemQpArg & elem_qp, const Moose::StateArg & state) const
241 {
242  return evaluateDotHelper(elem_qp, state);
243 }
244 
245 typename Function::DotType
246 Function::evaluateDot(const ElemSideQpArg & elem_side_qp, const Moose::StateArg & state) const
247 {
248  return evaluateDotHelper(elem_side_qp, state);
249 }
250 
251 typename Function::DotType
252 Function::evaluateDot(const ElemPointArg & elem_point_arg, const Moose::StateArg & state) const
253 {
254  return evaluateDotHelper(elem_point_arg, state);
255 }
256 
257 typename Function::DotType
258 Function::evaluateDot(const NodeArg & node_arg, const Moose::StateArg & state) const
259 {
260  return evaluateDotHelper(node_arg, state);
261 }
262 
263 void
265 {
267 }
268 
269 void
271 {
273 }
274 
275 void
277 {
279 }
280 
281 void
283 {
285 }
std::string name(const ElemQuality q)
FEProblemBase & _ti_feproblem
Base class template for functor objects.
Definition: MooseFunctor.h:137
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
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,z), by default this returns zero, you must override it.
Definition: Function.C:96
const libMesh::Elem * face_side
A member that can be used to indicate whether there is a sidedness to this face.
DotType evaluateDotHelper(const R &r, const Moose::StateArg &state) const
Definition: Function.C:222
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 timeDerivative(Real t, const Point &p) const
Get the time derivative of the function.
Definition: Function.C:69
const Elem & elem() const
Definition: FaceInfo.h:85
DualNumber< Real, Real > ChainedReal
Definition: ChainedReal.h:30
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:100
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
void residualSetup() override final
Definition: Function.C:270
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:42
typename FunctorReturnType< Real, FunctorEvaluationKind::Gradient >::type GradientType
This rigmarole makes it so that a user can create functors that return containers (std::vector...
Definition: MooseFunctor.h:149
Function(const InputParameters &parameters)
Definition: Function.C:22
virtual Real average() const
Returns the average of the function over its domain.
Definition: Function.C:110
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
const Elem * neighborPtr() const
Definition: FaceInfo.h:88
A structure defining a "face" evaluation calling argument for Moose functors.
Real getTimeFromStateArg(const Moose::StateArg &state) const
Returns the time associated with the requested state.
const FaceInfo * fi
a face information object which defines our location in space
libMesh::Point getPoint() const
const Elem & neighbor() const
Definition: FaceInfo.h:220
A structure that is used to evaluate Moose functors logically at an element/cell center.
Argument for requesting functor evaluation at a quadrature point location in an element.
const Point & normal() const
Returns the unit normal vector for the face oriented outward from the face&#39;s elem element...
Definition: FaceInfo.h:72
void jacobianSetup() override final
Definition: Function.C:276
void customSetup(const ExecFlagType &exec_type) override final
Definition: Function.C:282
void timestepSetup() override
Definition: Function.C:264
const Elem * elemPtr() const
Definition: FaceInfo.h:86
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
GradientType evaluateGradientHelper(const R &r, const Moose::StateArg &state) const
Definition: Function.C:179
ValueType evaluate(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor with a given element.
Definition: Function.C:124
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
virtual RealGradient gradient(Real t, const Point &p) const
Function objects can optionally provide a gradient at a point.
Definition: Function.C:62
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
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:281
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
virtual Real integral() const
Returns the integral of the function over its domain.
Definition: Function.C:103
State argument for evaluating functors.
virtual ~Function()
Function destructor.
Definition: Function.C:27
static InputParameters validParams()
Definition: FunctionBase.C:16
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
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
GradientType evaluateGradient(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor gradient with a given element.
Definition: Function.C:185
static InputParameters validParams()
Class constructor.
Definition: Function.C:16
Argument for requesting functor evaluation at quadrature point locations on an element side...
ValueType evaluateHelper(const R &r, const Moose::StateArg &state) const
Definition: Function.C:118