https://mooseframework.inl.gov
MooseParsedFunction.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 "MooseError.h"
11 
12 // MOOSE includes
13 #include "InputParameters.h"
14 #include "MooseParsedFunction.h"
16 #include "FEProblemBase.h"
17 
18 registerMooseObjectAliased("MooseApp", MooseParsedFunction, "ParsedFunction");
19 
22 {
25  params.addRequiredCustomTypeParam<std::string>(
26  "expression", "FunctionExpression", "The user defined function.");
27  params.addClassDescription("Function created by parsing a string");
28  return params;
29 }
30 
32  : Function(parameters),
33  MooseParsedFunctionBase(parameters),
34  _value(verifyFunction(this->template getRenamedParam<std::string>("value", "expression")))
35 {
36 }
37 
38 Real
39 MooseParsedFunction::value(Real t, const Point & p) const
40 {
41  mooseAssert(_function_ptr, "ParsedFunction should have been initialized");
42  return _function_ptr->evaluate<Real>(t, p);
43 }
44 
46 MooseParsedFunction::gradient(Real t, const Point & p) const
47 {
48  mooseAssert(_function_ptr, "ParsedFunction should have been initialized");
49  return _function_ptr->evaluateGradient(t, p);
50 }
51 
52 Real
53 MooseParsedFunction::timeDerivative(Real t, const Point & p) const
54 {
55  mooseAssert(_function_ptr, "ParsedFunction should have been initialized");
56  return _function_ptr->evaluateDot(t, p);
57 }
58 
60 MooseParsedFunction::vectorValue(Real /*t*/, const Point & /*p*/) const
61 {
62  mooseError("The vectorValue method is not defined in ParsedFunction");
63 }
64 
65 void
67 {
68  // Check for non-scalar variables.
69  for (const auto i : index_range(_vars))
73  mooseError("The only variables supported by ParsedFunction are scalar variables, and var '" +
74  _vals[i] + "' is not scalar.");
75 
76  if (!_function_ptr)
77  {
78  THREAD_ID tid = this->isParamValid("_tid") ? this->template getParam<THREAD_ID>("_tid") : 0;
79 
81  std::make_unique<MooseParsedFunctionWrapper>(_pfb_feproblem, _value, _vars, _vals, tid);
82  }
83 }
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
std::unique_ptr< MooseParsedFunctionWrapper > _function_ptr
Pointer to the Parsed function wrapper object for the scalar.
Base class for function objects.
Definition: Function.h:29
virtual RealVectorValue vectorValue(Real t, const Point &p) const override
Method invalid for ParsedGradFunction.
Adds user facing parameters for parsed function.
MooseParsedFunction(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
FEProblemBase & _pfb_feproblem
Reference to the FEProblemBase class for this object.
const std::vector< std::string > _vals
Values passed by the user, they may be Reals for Postprocessors.
virtual bool hasScalarVariable(const std::string &var_name) const override
Returns a Boolean indicating whether any system contains a variable with the name provided...
This class is used to evaluate symbolic equations passed in to Moose through the input file...
virtual void initialSetup() override
Creates the parsed function.
virtual Real value(Real t, const Point &pt) const override
Evaluate the equation at the given location.
registerMooseObjectAliased("MooseApp", MooseParsedFunction, "ParsedFunction")
static InputParameters validParams()
Created from MooseSystem via the FunctionFactory.
bool hasPostprocessorValueByName(const PostprocessorName &name) const
Whether or not a Postprocessor value exists by a given name.
std::string _value
The function defined by the user.
virtual RealGradient gradient(Real t, const Point &p) const override
Evaluate the gradient of the function.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
Class constructor for the interface.
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
void addRequiredCustomTypeParam(const std::string &name, const std::string &custom_type, const std::string &doc_string)
These methods add an option parameter and with a customer type to the InputParameters object...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
virtual Real timeDerivative(Real t, const Point &p) const override
Evaluate the time derivative of the function.
const std::vector< std::string > _vars
Variables passed to libMesh::ParsedFunction.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:209
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
static InputParameters validParams()
Class constructor.
Definition: Function.C:16
auto index_range(const T &sizable)
unsigned int THREAD_ID
Definition: MooseTypes.h:237