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 : registerMooseObjectRenamed("MooseApp", ADParsedFunction, "02/03/2024 00:00", MooseParsedFunction); 20 : 21 : InputParameters 22 106204 : MooseParsedFunction::validParams() 23 : { 24 106204 : InputParameters params = Function::validParams(); 25 106204 : params += MooseParsedFunctionBase::validParams(); 26 106204 : 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 106204 : params.addCustomTypeParam<std::string>( 30 : "expression", "FunctionExpression", "The user defined function."); 31 : 32 106204 : params.addClassDescription("Function created by parsing a string"); 33 : 34 106204 : return params; 35 0 : } 36 : 37 40278 : MooseParsedFunction::MooseParsedFunction(const InputParameters & parameters) 38 : : Function(parameters), 39 : MooseParsedFunctionBase(parameters), 40 40278 : _value(verifyFunction(this->template getRenamedParam<std::string>("value", "expression"))) 41 : { 42 40270 : } 43 : 44 : Real 45 1914200353 : MooseParsedFunction::value(Real t, const Point & p) const 46 : { 47 : mooseAssert(_function_ptr, "ParsedFunction should have been initialized"); 48 1914200353 : return _function_ptr->evaluate<Real>(t, p); 49 : } 50 : 51 : RealGradient 52 8076352 : MooseParsedFunction::gradient(Real t, const Point & p) const 53 : { 54 : mooseAssert(_function_ptr, "ParsedFunction should have been initialized"); 55 8076352 : return _function_ptr->evaluateGradient(t, p); 56 : } 57 : 58 : Real 59 4554666 : MooseParsedFunction::timeDerivative(Real t, const Point & p) const 60 : { 61 : mooseAssert(_function_ptr, "ParsedFunction should have been initialized"); 62 4554666 : return _function_ptr->evaluateDot(t, p); 63 : } 64 : 65 : RealVectorValue 66 0 : MooseParsedFunction::vectorValue(Real /*t*/, const Point & /*p*/) const 67 : { 68 0 : mooseError("The vectorValue method is not defined in ParsedFunction"); 69 : } 70 : 71 : void 72 40585 : MooseParsedFunction::initialSetup() 73 : { 74 42915 : 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 78 2334 : if (_pfb_feproblem.hasVariable(_vars[i]) && _pfb_feproblem.hasVariable(_vals[i])) 79 : { 80 : // Then see if the var has the same name as a function or postprocessor 81 8 : if (!_pfb_feproblem.hasFunction(_vars[i]) && 82 8 : !_pfb_feproblem.hasPostprocessorValueByName(_vars[i])) 83 4 : mooseError( 84 4 : "The only variables supported by ParsedFunction are scalar variables, and var '" + 85 8 : _vars[i] + "' is not scalar."); 86 : } 87 : } 88 : 89 40581 : if (!_function_ptr) 90 : { 91 39321 : THREAD_ID tid = 0; 92 39321 : if (this->isParamValid("_tid")) 93 39321 : tid = this->template getParam<THREAD_ID>("_tid"); 94 : 95 : _function_ptr = 96 39321 : std::make_unique<MooseParsedFunctionWrapper>(_pfb_feproblem, _value, _vars, _vals, tid); 97 : } 98 40577 : }