https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
18registerMooseObjectAliased("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
38Real
39MooseParsedFunction::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
45RealGradient
46MooseParsedFunction::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
52Real
53MooseParsedFunction::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
59RealVectorValue
60MooseParsedFunction::vectorValue(Real /*t*/, const Point & /*p*/) const
61{
62 mooseError("The vectorValue method is not defined in ParsedFunction");
63}
64
65void
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}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObjectAliased("MooseApp", MooseParsedFunction, "ParsedFunction")
unsigned int THREAD_ID
Definition MooseTypes.h:237
virtual bool hasScalarVariable(const std::string &var_name) const override
Returns a Boolean indicating whether any system contains a variable with the name provided.
bool hasPostprocessorValueByName(const PostprocessorName &name) const
Whether or not a Postprocessor value exists by a given name.
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
Base class for function objects.
Definition Function.h:30
static InputParameters validParams()
Class constructor.
Definition Function.C:16
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
Adds user facing parameters for parsed function.
const std::vector< std::string > _vals
Values passed by the user, they may be Reals for Postprocessors.
FEProblemBase & _pfb_feproblem
Reference to the FEProblemBase class for this object.
std::unique_ptr< MooseParsedFunctionWrapper > _function_ptr
Pointer to the Parsed function wrapper object for the scalar.
static InputParameters validParams()
Class constructor for the interface.
const std::vector< std::string > _vars
Variables passed to libMesh::ParsedFunction.
This class is used to evaluate symbolic equations passed in to Moose through the input file.
virtual RealVectorValue vectorValue(Real t, const Point &p) const override
Method invalid for ParsedGradFunction.
static InputParameters validParams()
Created from MooseSystem via the FunctionFactory.
virtual RealGradient gradient(Real t, const Point &p) const override
Evaluate the gradient of the function.
virtual Real timeDerivative(Real t, const Point &p) const override
Evaluate the time derivative of the function.
virtual Real value(Real t, const Point &pt) const override
Evaluate the equation at the given location.
virtual void initialSetup() override
Creates the parsed function.
MooseParsedFunction(const InputParameters &parameters)
std::string _value
The function defined by the user.