https://mooseframework.inl.gov
Function.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 "MooseObject.h"
13 #include "SetupInterface.h"
14 #include "TransientInterface.h"
15 #include "PostprocessorInterface.h"
16 #include "UserObjectInterface.h"
17 #include "Restartable.h"
18 #include "MeshChangedInterface.h"
19 #include "ScalarCoupleable.h"
20 #include "MooseFunctor.h"
21 #include "ChainedReal.h"
22 
23 // libMesh
24 #include "libmesh/vector_value.h"
25 
26 // libMesh forward declarations
27 namespace libMesh
28 {
29 class Point;
30 }
31 
36 class Function : public MooseObject,
37  public SetupInterface,
38  public TransientInterface,
40  public UserObjectInterface,
41  public Restartable,
42  public MeshChangedInterface,
43  public ScalarCoupleable,
44  public Moose::FunctorBase<Real>
45 {
46 public:
52 
54 
58  virtual ~Function();
59 
67  virtual Real value(Real t, const Point & p) const;
68 
77  virtual ADReal value(const ADReal & t, const ADPoint & p) const;
78 
80  ChainedReal value(const ChainedReal & t) const;
81  template <typename U>
82  auto value(const U & t) const;
83  template <typename U>
84  auto value(const U & t, const U & x, const U & y = 0, const U & z = 0) const;
86 
94  virtual RealVectorValue vectorValue(Real t, const Point & p) const;
95 
103  virtual RealVectorValue curl(Real t, const Point & p) const;
104 
112  virtual Real div(Real t, const Point & p) const;
113 
122  virtual RealGradient gradient(Real t, const Point & p) const;
123 
130  virtual Real timeDerivative(Real t, const Point & p) const;
131 
133  template <typename U>
134  auto timeDerivative(const U & t) const;
135  template <typename U>
136  auto timeDerivative(const U & t, const U & x, const U & y = 0, const U & z = 0) const;
138 
140  virtual Real integral() const;
141 
143  virtual Real average() const;
144 
152  virtual Real timeIntegral(Real t1, Real t2, const Point & p) const;
153 
154  void timestepSetup() override;
155  // We will only allow initialSetup() and timestepSetup() to be overriden
156  void residualSetup() override final;
157  void jacobianSetup() override final;
158  void customSetup(const ExecFlagType & exec_type) override final;
159 
160  bool hasBlocks(SubdomainID) const override { return true; }
161 
162  bool supportsFaceArg() const override final { return true; }
163  bool supportsElemSideQpArg() const override final { return true; }
164 
165 private:
168  using typename Moose::FunctorBase<Real>::DotType;
169 
176 
177  template <typename R>
178  ValueType evaluateHelper(const R & r, const Moose::StateArg & state) const;
179 
180  ValueType evaluate(const ElemArg & elem, const Moose::StateArg & state) const override final;
181  ValueType evaluate(const FaceArg & face, const Moose::StateArg & state) const override final;
182  ValueType evaluate(const ElemQpArg & qp, const Moose::StateArg & state) const override final;
183  ValueType evaluate(const ElemSideQpArg & elem_side_qp,
184  const Moose::StateArg & state) const override final;
185  ValueType evaluate(const ElemPointArg & elem_point,
186  const Moose::StateArg & state) const override final;
187  ValueType evaluate(const NodeArg & node, const Moose::StateArg & state) const override final;
188 
189  template <typename R>
190  GradientType evaluateGradientHelper(const R & r, const Moose::StateArg & state) const;
191 
193  const Moose::StateArg & state) const override final;
195  const Moose::StateArg & state) const override final;
197  const Moose::StateArg & state) const override final;
198  GradientType evaluateGradient(const ElemSideQpArg & elem_side_qp,
199  const Moose::StateArg & state) const override final;
200  GradientType evaluateGradient(const ElemPointArg & elem_point,
201  const Moose::StateArg & state) const override final;
203  const Moose::StateArg & state) const override final;
204 
205  template <typename R>
206  DotType evaluateDotHelper(const R & r, const Moose::StateArg & state) const;
207  DotType evaluateDot(const ElemArg & elem, const Moose::StateArg & state) const override final;
208  DotType evaluateDot(const FaceArg & face, const Moose::StateArg & state) const override final;
209  DotType evaluateDot(const ElemQpArg & qp, const Moose::StateArg & state) const override final;
210  DotType evaluateDot(const ElemSideQpArg & elem_side_qp,
211  const Moose::StateArg & state) const override final;
212  DotType evaluateDot(const ElemPointArg & elem_point,
213  const Moose::StateArg & state) const override final;
214  DotType evaluateDot(const NodeArg & node, const Moose::StateArg & state) const override final;
215 };
216 
217 template <typename U>
218 auto
219 Function::value(const U & t) const
220 {
222  return value(t, p);
223 }
224 
225 template <typename U>
226 auto
227 Function::value(const U & t, const U & x, const U & y, const U & z) const
228 {
230  return value(t, p);
231 }
232 
233 template <typename U>
234 auto
235 Function::timeDerivative(const U & t) const
236 {
238  return timeDerivative(t, p);
239 }
240 
241 template <typename U>
242 auto
243 Function::timeDerivative(const U & t, const U & x, const U & y, const U & z) const
244 {
246  return timeDerivative(t, p);
247 }
Base class for function objects.
Definition: Function.h:36
A class for creating restricted objects.
Definition: Restartable.h:28
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:90
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:110
DotType evaluateDotHelper(const R &r, const Moose::StateArg &state) const
Definition: Function.C:236
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:103
virtual Real timeDerivative(Real t, const Point &p) const
Get the time derivative of the function.
Definition: Function.C:83
DualNumber< Real, Real > ChainedReal
Definition: ChainedReal.h:30
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...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
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:284
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:47
bool supportsElemSideQpArg() const override final
Whether this functor supports evaluation with ElemSideQpArg.
Definition: Function.h:163
typename FunctorReturnType< T, FunctorEvaluationKind::Gradient >::type GradientType
This rigmarole makes it so that a user can create functors that return containers (std::vector...
Definition: MooseFunctor.h:149
typename std::conditional< is_ad, typename ADType< T >::type, T >::type GenericType
Definition: MooseTypes.h:644
Function(const InputParameters &parameters)
Definition: Function.C:28
virtual Real average() const
Returns the average of the function over its domain.
Definition: Function.C:124
Interface for objects that needs transient capabilities.
Interface for notifications that the mesh has changed.
A structure defining a "face" evaluation calling argument for Moose functors.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
bool supportsFaceArg() const override final
Whether this functor supports evaluation with FaceArg.
Definition: Function.h:162
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.
Interface for objects that need to use UserObjects.
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:290
void customSetup(const ExecFlagType &exec_type) override final
Gets called in FEProblemBase::execute() for execute flags other than initial, timestep_begin, nonlinear, linear and subdomain.
Definition: Function.C:296
void timestepSetup() override
Gets called at the beginning of the timestep before this object is asked to do its job...
Definition: Function.C:278
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
GradientType evaluateGradientHelper(const R &r, const Moose::StateArg &state) const
Definition: Function.C:193
ValueType evaluate(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor with a given element.
Definition: Function.C:138
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:76
DotType evaluateDot(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor time derivative with a given element.
Definition: Function.C:242
Interface for objects that needs scalar coupling capabilities.
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:96
virtual Real integral() const
Returns the integral of the function over its domain.
Definition: Function.C:117
const InputParameters & parameters() const
Get the parameters of the object.
State argument for evaluating functors.
virtual ~Function()
Function destructor.
Definition: Function.C:41
bool hasBlocks(SubdomainID) const override
Returns whether the functor is defined on this block.
Definition: Function.h:160
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:44
GradientType evaluateGradient(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor gradient with a given element.
Definition: Function.C:199
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:132
Interface class for classes which interact with Postprocessors.