Feellgood
expression_parser.h
1 /*
2  * Parser/evaluator for the analytic expressions given by the user:
3  * the initial magnetization M(x, y, z), the applied field (B(t) or B(x, y, z))
4  * and a time-dependent scalar field amplitude.
5  */
6 
7 #ifndef expression_parser_h
8 #define expression_parser_h
9 
10 #include <duktape.h>
11 #include <string>
12 
13 #include <eigen3/Eigen/Dense>
14 
20  {
21 public:
23  ExpressionParser(const ExpressionParser &) = delete;
24  ExpressionParser &operator=(const ExpressionParser &) = delete;
26 
32  void set_function(const std::string &js_function) const;
33 
39  void set_expressions(const std::string &parameters, const std::string &expr_x,
40  const std::string &expr_y, const std::string &expr_z);
41 
45  double get_scalar(double arg) const;
46 
50  Eigen::Vector3d get_vector(double arg) const;
51 
55  Eigen::Vector3d get_vector(const Eigen::Ref<Eigen::Vector3d> arg) const;
56 
57 private:
62  void die_if_error(duk_int_t err) const;
63 
67  double get_vector_component(int idx) const;
68 
73  Eigen::Vector3d compute_vector(int argument_count) const;
74 
78  duk_context *ctx;
79  };
80 
81 #endif /* expression_parser_h */
Definition: expression_parser.h:20
void set_expressions(const std::string &parameters, const std::string &expr_x, const std::string &expr_y, const std::string &expr_z)
Definition: expression_parser.cpp:60
Eigen::Vector3d compute_vector(int argument_count) const
Definition: expression_parser.cpp:92
double get_vector_component(int idx) const
Definition: expression_parser.cpp:78
double get_scalar(double arg) const
Definition: expression_parser.cpp:67
Eigen::Vector3d get_vector(double arg) const
Definition: expression_parser.cpp:103
duk_context * ctx
Definition: expression_parser.h:78
void die_if_error(duk_int_t err) const
Definition: expression_parser.cpp:40
void set_function(const std::string &js_function) const
Definition: expression_parser.cpp:48