www.mooseframework.org
Function.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "MooseADWrapper.h"
22 #include "ChainedReal.h"
23 
24 // libMesh
25 #include "libmesh/vector_value.h"
26 
27 // libMesh forward declarations
28 namespace libMesh
29 {
30 class Point;
31 }
32 
37 class Function : public MooseObject,
38  public SetupInterface,
39  public TransientInterface,
41  public UserObjectInterface,
42  public Restartable,
43  public MeshChangedInterface,
44  public ScalarCoupleable,
45  public Moose::FunctorBase<Real>
46 {
47 public:
53 
55 
59  virtual ~Function();
60 
68  virtual Real value(Real t, const Point & p) const;
69 
78  virtual ADReal value(const ADReal & t, const ADPoint & p) const;
79 
81  ChainedReal value(const ChainedReal & t) const;
82  template <typename U>
83  auto value(const U & t) const;
84  template <typename U>
85  auto value(const U & t, const U & x, const U & y = 0, const U & z = 0) const;
87 
95  virtual RealVectorValue vectorValue(Real t, const Point & p) const;
96 
104  virtual RealVectorValue curl(Real t, const Point & p) const;
105 
113  virtual Real div(Real t, const Point & p) const;
114 
123  virtual RealGradient gradient(Real t, const Point & p) const;
124 
131  virtual Real timeDerivative(Real t, const Point & p) const;
132 
134  template <typename U>
135  auto timeDerivative(const U & t) const;
136  template <typename U>
137  auto timeDerivative(const U & t, const U & x, const U & y = 0, const U & z = 0) const;
139 
140  // Not defined
141  virtual Real integral() const;
142 
143  // Not defined
144  virtual Real average() const;
145 
146  void timestepSetup() override;
147  void residualSetup() override;
148  void jacobianSetup() override;
149  void customSetup(const ExecFlagType & exec_type) override;
150 
151  bool hasBlocks(SubdomainID) const override { return true; }
152 
153  bool supportsFaceArg() const override final { return true; }
154  bool supportsElemSideQpArg() const override final { return true; }
155 
156 private:
159  using typename Moose::FunctorBase<Real>::DotType;
160 
167 
168  template <typename R>
169  ValueType evaluateHelper(const R & r, const Moose::StateArg & state) const;
170 
171  ValueType evaluate(const ElemArg & elem, const Moose::StateArg & state) const override final;
172  ValueType evaluate(const FaceArg & face, const Moose::StateArg & state) const override final;
173  ValueType evaluate(const ElemQpArg & qp, const Moose::StateArg & state) const override final;
174  ValueType evaluate(const ElemSideQpArg & elem_side_qp,
175  const Moose::StateArg & state) const override final;
176  ValueType evaluate(const ElemPointArg & elem_point,
177  const Moose::StateArg & state) const override final;
178  ValueType evaluate(const NodeArg & node, const Moose::StateArg & state) const override final;
179 
180  template <typename R>
181  GradientType evaluateGradientHelper(const R & r, const Moose::StateArg & state) const;
182 
184  const Moose::StateArg & state) const override final;
186  const Moose::StateArg & state) const override final;
188  const Moose::StateArg & state) const override final;
189  GradientType evaluateGradient(const ElemSideQpArg & elem_side_qp,
190  const Moose::StateArg & state) const override final;
191  GradientType evaluateGradient(const ElemPointArg & elem_point,
192  const Moose::StateArg & state) const override final;
194  const Moose::StateArg & state) const override final;
195 
196  template <typename R>
197  DotType evaluateDotHelper(const R & r, const Moose::StateArg & state) const;
198  DotType evaluateDot(const ElemArg & elem, const Moose::StateArg & state) const override final;
199  DotType evaluateDot(const FaceArg & face, const Moose::StateArg & state) const override final;
200  DotType evaluateDot(const ElemQpArg & qp, const Moose::StateArg & state) const override final;
201  DotType evaluateDot(const ElemSideQpArg & elem_side_qp,
202  const Moose::StateArg & state) const override final;
203  DotType evaluateDot(const ElemPointArg & elem_point,
204  const Moose::StateArg & state) const override final;
205  DotType evaluateDot(const NodeArg & node, const Moose::StateArg & state) const override final;
206 };
207 
208 template <typename U>
209 auto
210 Function::value(const U & t) const
211 {
213  return value(t, p);
214 }
215 
216 template <typename U>
217 auto
218 Function::value(const U & t, const U & x, const U & y, const U & z) const
219 {
221  return value(t, p);
222 }
223 
224 template <typename U>
225 auto
226 Function::timeDerivative(const U & t) const
227 {
229  return timeDerivative(t, p);
230 }
231 
232 template <typename U>
233 auto
234 Function::timeDerivative(const U & t, const U & x, const U & y, const U & z) const
235 {
237  return timeDerivative(t, p);
238 }
Base class for function objects.
Definition: Function.h:37
A class for creating restricted objects.
Definition: Restartable.h:28
Base class template for functor objects.
Definition: MooseFunctor.h:137
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:101
DotType evaluateDotHelper(const R &r, const Moose::StateArg &state) const
Definition: Function.C:227
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:94
virtual Real timeDerivative(Real t, const Point &p) const
Get the time derivative of the function.
Definition: Function.C:80
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...
bool supportsElemSideQpArg() const override final
Whether this functor supports evaluation with ElemSideQpArg.
Definition: Function.h:154
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
Function(const InputParameters &parameters)
Definition: Function.C:25
virtual Real average() const
Definition: Function.C:115
void residualSetup() override
Gets called just before the residual is computed and before this object is asked to do its job...
Definition: Function.C:275
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:33
bool supportsFaceArg() const override final
Whether this functor supports evaluation with FaceArg.
Definition: Function.h:153
A structure that is used to evaluate Moose functors logically at an element/cell center.
DualReal ADReal
Definition: ADRealForward.h:14
Argument for requesting functor evaluation at a quadrature point location in an element.
Interface for objects that need to use UserObjects.
void timestepSetup() override
Gets called at the beginning of the timestep before this object is asked to do its job...
Definition: Function.C:269
typename MooseADWrapperStruct< T, is_ad >::type MooseADWrapper
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
GradientType evaluateGradientHelper(const R &r, const Moose::StateArg &state) const
Definition: Function.C:184
ValueType evaluate(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor with a given element.
Definition: Function.C:129
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
void customSetup(const ExecFlagType &exec_type) override
Gets called in FEProblemBase::execute() for execute flags other than initial, timestep_begin, nonlinear, linear and subdomain.
Definition: Function.C:287
virtual RealGradient gradient(Real t, const Point &p) const
Function objects can optionally provide a gradient at a point.
Definition: Function.C:73
DotType evaluateDot(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor time derivative with a given element.
Definition: Function.C:233
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:87
virtual Real integral() const
Definition: Function.C:108
const InputParameters & parameters() const
Get the parameters of the object.
State argument for evaluating functors.
virtual ~Function()
Function destructor.
Definition: Function.C:38
bool hasBlocks(SubdomainID) const override
Returns whether the functor is defined on this block.
Definition: Function.h:151
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:41
GradientType evaluateGradient(const ElemArg &elem, const Moose::StateArg &state) const override final
Evaluate the functor gradient with a given element.
Definition: Function.C:190
static InputParameters validParams()
Class constructor.
Definition: Function.C:15
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:123
Interface class for classes which interact with Postprocessors.
void jacobianSetup() override
Gets called just before the Jacobian is computed and before this object is asked to do its job...
Definition: Function.C:281