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 34 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 38 of file Parser.h.

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

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