Line data Source code
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" 15 : #include "MooseParsedFunctionWrapper.h" 16 : #include "FEProblemBase.h" 17 : 18 : registerMooseObjectAliased("MooseApp", MooseParsedFunction, "ParsedFunction"); 19 : 20 : InputParameters 21 82528 : MooseParsedFunction::validParams() 22 : { 23 82528 : InputParameters params = Function::validParams(); 24 82528 : params += MooseParsedFunctionBase::validParams(); 25 495168 : params.addRequiredCustomTypeParam<std::string>( 26 : "expression", "FunctionExpression", "The user defined function."); 27 82528 : params.addClassDescription("Function created by parsing a string"); 28 82528 : return params; 29 0 : } 30 : 31 40319 : MooseParsedFunction::MooseParsedFunction(const InputParameters & parameters) 32 : : Function(parameters), 33 : MooseParsedFunctionBase(parameters), 34 161264 : _value(verifyFunction(this->template getRenamedParam<std::string>("value", "expression"))) 35 : { 36 40313 : } 37 : 38 : Real 39 1868581274 : MooseParsedFunction::value(Real t, const Point & p) const 40 : { 41 : mooseAssert(_function_ptr, "ParsedFunction should have been initialized"); 42 1868581274 : return _function_ptr->evaluate<Real>(t, p); 43 : } 44 : 45 : RealGradient 46 7398806 : MooseParsedFunction::gradient(Real t, const Point & p) const 47 : { 48 : mooseAssert(_function_ptr, "ParsedFunction should have been initialized"); 49 7398806 : return _function_ptr->evaluateGradient(t, p); 50 : } 51 : 52 : Real 53 3904348 : MooseParsedFunction::timeDerivative(Real t, const Point & p) const 54 : { 55 : mooseAssert(_function_ptr, "ParsedFunction should have been initialized"); 56 3904348 : return _function_ptr->evaluateDot(t, p); 57 : } 58 : 59 : RealVectorValue 60 0 : MooseParsedFunction::vectorValue(Real /*t*/, const Point & /*p*/) const 61 : { 62 0 : mooseError("The vectorValue method is not defined in ParsedFunction"); 63 : } 64 : 65 : void 66 39944 : MooseParsedFunction::initialSetup() 67 : { 68 : // Check for non-scalar variables. 69 41718 : for (const auto i : index_range(_vars)) 70 1780 : if (_pfb_feproblem.hasVariable(_vals[i]) && !_pfb_feproblem.hasScalarVariable(_vals[i]) && 71 3560 : !_pfb_feproblem.hasFunction(_vals[i]) && 72 1780 : !_pfb_feproblem.hasPostprocessorValueByName(_vals[i])) 73 6 : mooseError("The only variables supported by ParsedFunction are scalar variables, and var '" + 74 6 : _vals[i] + "' is not scalar."); 75 : 76 39941 : if (!_function_ptr) 77 : { 78 157844 : THREAD_ID tid = this->isParamValid("_tid") ? this->template getParam<THREAD_ID>("_tid") : 0; 79 : 80 : _function_ptr = 81 39461 : std::make_unique<MooseParsedFunctionWrapper>(_pfb_feproblem, _value, _vars, _vals, tid); 82 : } 83 39938 : }