1#ifndef HH_MUPARSERXINTERFACE_HH
2#define HH_MUPARSERXINTERFACE_HH
29template <
int N,
class ArgumentType = std::array<
double, N> >
40 M_parser(mup::pckALL_NON_COMPLEX | mup::pckMATRIX), M_value{N, 0.0}
42 M_parser.DefineVar(
"x", mup::Variable(&M_value));
48 M_parser.SetExpr(My_e.c_str());
65 M_parser(mup::pckALL_NON_COMPLEX | mup::pckMATRIX), M_value{N, 0.0}
67 M_parser.DefineVar(
"x", mup::Variable(&M_value));
68 M_parser.SetExpr(My_e.c_str());
83 this->My_e = mpi.My_e;
84 this->M_parser.ClearVar();
85 this->M_value = mpi.M_value;
86 M_parser.DefineVar(
"x", mup::Variable(&M_value));
87 M_parser.SetExpr(My_e.c_str());
102 std::ifstream file(filename);
105 throw std::runtime_error(
"Cannot open function file: " + filename);
108 std::string expression;
111 while(std::getline(file, expression)) {
112 if(!expression.empty())
break;
117 if(expression.empty()) {
118 throw std::runtime_error(
"File is empty or contains no expression: " + filename);
121 std::cout <<
"Read expression from file: " << expression << std::endl;
137 M_parser.SetExpr(e.c_str());
143 for(
int i = 0; i < N; ++i)
145 M_value.At(i) = x[i];
150 ans = M_parser.Eval();
152 catch(mup::ParserError &error)
154 std::cerr <<
"Muparsex error with code:" << error.GetCode()
157 std::cerr <<
"While processing expression: " << error.GetExpr()
159 std::cerr <<
"Error Message: " << error.GetMsg() << std::endl;
162 return ans.GetFloat();
169 mup::ParserX M_parser;
171 mutable mup::Value M_value;
muParserXInterface()
Default constructor.
muParserXInterface(muParserXInterface const &mpi)
muParserXInterface operator=(muParserXInterface const &mpi)
void set_expression(const std::string &e)
Sets the muparserX expression.
static muParserXInterface fromFile(const std::string &filename)
auto operator()(ArgumentType const &x) const
muParserXInterface(const std::string expression)
Constructor that takes a string containing muParserX expression.