Skip to content

Commit

Permalink
Added alternative evaluate method to FunctionParserUtils
Browse files Browse the repository at this point in the history
The class currently assumes that the deriving object has
just a single parsed expression or uses the same values,
but the new evaluate allows the symbol values to be passed in,
allowing for multiple sets of values.

Refs idaholab#28844
  • Loading branch information
joshuahansel committed Jan 21, 2025
1 parent 4ac42ea commit 35e7375
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions framework/include/utils/FunctionParserUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ class FunctionParserUtils
protected:
/// Evaluate FParser object and check EvalError
GenericReal<is_ad> evaluate(SymFunctionPtr &, const std::string & object_name = "");
/**
* Evaluate FParser object and check EvalError
*
* This version uses a supplied vector of function parameters, which is useful
* if an object uses more than one parsed function, which may have different
* function parameter values.
*/
GenericReal<is_ad> evaluate(SymFunctionPtr &,
const std::vector<GenericReal<is_ad>> &,
const std::string & object_name = "");

/// add constants (which can be complex expressions) to the parser object
void addFParserConstants(SymFunctionPtr & parser,
Expand Down
11 changes: 10 additions & 1 deletion framework/src/utils/FunctionParserUtils.C
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ FunctionParserUtils<is_ad>::setParserFeatureFlags(SymFunctionPtr & parser)
template <bool is_ad>
GenericReal<is_ad>
FunctionParserUtils<is_ad>::evaluate(SymFunctionPtr & parser, const std::string & name)
{
return evaluate(parser, _func_params, name);
}

template <bool is_ad>
GenericReal<is_ad>
FunctionParserUtils<is_ad>::evaluate(SymFunctionPtr & parser,
const std::vector<GenericReal<is_ad>> & func_params,
const std::string & name)
{
// null pointer is a shortcut for vanishing derivatives, see functionsOptimize()
if (parser == NULL)
Expand All @@ -95,7 +104,7 @@ FunctionParserUtils<is_ad>::evaluate(SymFunctionPtr & parser, const std::string
parser->setEpsilon(_epsilon);

// evaluate expression
auto result = parser->Eval(_func_params.data());
auto result = parser->Eval(func_params.data());

// restore epsilon
parser->setEpsilon(tmp_eps);
Expand Down

0 comments on commit 35e7375

Please sign in to comment.