www.mooseframework.org
Public Member Functions | List of all members
FuncParseEvaler Class Reference

#include <Parser.h>

Inheritance diagram for FuncParseEvaler:
[legend]

Public Member Functions

virtual std::string eval (hit::Field *n, const std::list< std::string > &args, hit::BraceExpander &exp)
 

Detailed Description

Definition at line 33 of file Parser.h.

Member Function Documentation

◆ eval()

virtual std::string FuncParseEvaler::eval ( hit::Field *  n,
const std::list< std::string > &  args,
hit::BraceExpander &  exp 
)
inlinevirtual

Definition at line 37 of file Parser.h.

38  {
39  std::string func_text;
40  for (auto & s : args)
41  func_text += s;
42  auto n_errs = exp.errors.size();
43 
44  FunctionParser fp;
45  std::vector<std::string> var_names;
46  auto ret = fp.ParseAndDeduceVariables(func_text, var_names);
47  if (ret != -1)
48  {
49  exp.errors.push_back(hit::errormsg(exp.fname, n, "fparse error: ", fp.ErrorMsg()));
50  return n->val();
51  }
52 
53  std::string errors;
54  std::vector<double> var_vals;
55  for (auto & var : var_names)
56  {
57  // recursively check all parent scopes for the needed variables
58  hit::Node * curr = n;
59  while ((curr = curr->parent()))
60  {
61  auto src = curr->find(var);
62  if (src && src != n && src->type() == hit::NodeType::Field)
63  {
64  exp.used.push_back(hit::pathJoin({curr->fullpath(), var}));
65  var_vals.push_back(curr->param<double>(var));
66  break;
67  }
68  }
69 
70  if (curr == nullptr)
71  exp.errors.push_back(hit::errormsg(exp.fname,
72  n,
73  "\n no variable '",
74  var,
75  "' found for use in function parser expression"));
76  }
77 
78  if (exp.errors.size() != n_errs)
79  return n->val();
80 
81  std::stringstream ss;
82  ss << std::setprecision(17) << fp.Eval(var_vals.data());
83 
84  // change kind only (not val)
85  n->setVal(n->val(), hit::Field::Kind::Float);
86  return ss.str();
87  }
PetscInt n

The documentation for this class was generated from the following file: