www.mooseframework.org
MooseParsedFunction.C
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 #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 registerMooseObjectRenamed("MooseApp", ADParsedFunction, "02/03/2024 00:00", MooseParsedFunction);
20 
23 {
26  params.addDeprecatedCustomTypeParam<std::string>(
27  "value", "FunctionExpression", "The user defined function.", "Use 'expression' instead.");
28  // TODO Make required once deprecation is handled, see #19119
29  params.addCustomTypeParam<std::string>(
30  "expression", "FunctionExpression", "The user defined function.");
31 
32  params.addClassDescription("Function created by parsing a string");
33 
34  return params;
35 }
36 
38  : Function(parameters),
39  MooseParsedFunctionBase(parameters),
40  _value(verifyFunction(this->template getRenamedParam<std::string>("value", "expression")))
41 {
42 }
43 
44 Real
45 MooseParsedFunction::value(Real t, const Point & p) const
46 {
47  mooseAssert(_function_ptr, "ParsedFunction should have been initialized");
48  return _function_ptr->evaluate<Real>(t, p);
49 }
50 
52 MooseParsedFunction::gradient(Real t, const Point & p) const
53 {
54  mooseAssert(_function_ptr, "ParsedFunction should have been initialized");
55  return _function_ptr->evaluateGradient(t, p);
56 }
57 
58 Real
59 MooseParsedFunction::timeDerivative(Real t, const Point & p) const
60 {
61  mooseAssert(_function_ptr, "ParsedFunction should have been initialized");
62  return _function_ptr->evaluateDot(t, p);
63 }
64 
66 MooseParsedFunction::vectorValue(Real /*t*/, const Point & /*p*/) const
67 {
68  mooseError("The vectorValue method is not defined in ParsedFunction");
69 }
70 
71 void
73 {
74  for (const auto i : index_range(_vars))
75  {
76  // Check for non-scalar variables.
77  // First, see if the var is actually assigned to a proper scalar value
79  {
80  // Then see if the var has the same name as a function or postprocessor
81  if (!_pfb_feproblem.hasFunction(_vars[i]) &&
83  mooseError(
84  "The only variables supported by ParsedFunction are scalar variables, and var '" +
85  _vars[i] + "' is not scalar.");
86  }
87  }
88 
89  if (!_function_ptr)
90  {
91  THREAD_ID tid = 0;
92  if (this->isParamValid("_tid"))
93  tid = this->template getParam<THREAD_ID>("_tid");
94 
96  std::make_unique<MooseParsedFunctionWrapper>(_pfb_feproblem, _value, _vars, _vals, tid);
97  }
98 }
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:37
virtual RealVectorValue vectorValue(Real t, const Point &p) const override
Method invalid for ParsedGradFunction.
Creates the &#39;vars&#39; and &#39;vals&#39; parameters used by all ParsedFunctions, the parameters provided from th...
MooseParsedFunction(const InputParameters &parameters)
registerMooseObjectRenamed("MooseApp", ADParsedFunction, "02/03/2024 00:00", MooseParsedFunction)
void addCustomTypeParam(const std::string &name, const T &value, const std::string &custom_type, const std::string &doc_string)
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.
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.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
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.
void addDeprecatedCustomTypeParam(const std::string &name, const std::string &custom_type, const std::string &doc_string, const std::string &deprecation_msg)
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.
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.
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
static InputParameters validParams()
Class constructor.
Definition: Function.C:15
auto index_range(const T &sizable)
unsigned int THREAD_ID
Definition: MooseTypes.h:198