omega_h
Reliable mesh adaptation
Omega_h_expr.hpp
1 #ifndef OMEGA_H_EXPR_HPP
2 #define OMEGA_H_EXPR_HPP
3 
4 #include <functional>
5 #include <map>
6 #include <vector>
7 
8 #include <Omega_h_any.hpp>
9 #include <Omega_h_array.hpp>
10 #include <Omega_h_matrix.hpp>
11 #include <Omega_h_reader.hpp>
12 
13 namespace Omega_h {
14 
15 struct ExprEnv {
16  ExprEnv() = default;
17  ExprEnv(LO size_in, Int dim_in);
18  using Args = std::vector<any>;
19  using Function = std::function<any(Args&)>;
20  void register_variable(std::string const& name, any const& value);
21  void register_function(std::string const& name, Function const& value);
22  void repeat(any& x);
23  std::map<std::string, any> variables;
24  std::map<std::string, Function> functions;
25  LO size;
26  Int dim;
27  std::string string(int verbose=0);
28 };
29 
30 struct ExprOp {
31  virtual ~ExprOp();
32  virtual any eval(ExprEnv& env) = 0;
33 };
34 
35 using OpPtr = std::shared_ptr<ExprOp>;
36 
37 class ExprOpsReader final : public Reader {
38  public:
39  ExprOpsReader();
40  ~ExprOpsReader() override = default;
41  OpPtr read_ops(std::string const& str);
42 
43  protected:
44  any at_shift(int token, std::string& text) override final;
45  any at_reduce(int token, std::vector<any>& rhs) override final;
46 };
47 
48 class ExprReader final : public Reader {
49  public:
50  using Args = ExprEnv::Args;
51  using Function = ExprEnv::Function;
52  ExprReader(LO size_in, Int dim_in);
53  ~ExprReader() override;
54  void register_variable(std::string const& name, any const& value);
55  void register_function(std::string const& name, Function const& value);
56  void repeat(any& x);
57 
58  protected:
59  any at_shift(int token, std::string& text) override final;
60  any at_reduce(int token, std::vector<any>& rhs) override final;
61  ExprEnv env;
62 };
63 
64 } // end namespace Omega_h
65 
66 #endif
Definition: Omega_h_expr.hpp:37
Definition: Omega_h_expr.hpp:48
Definition: Omega_h_reader.hpp:13
Definition: Omega_h_any.hpp:68
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_expr.hpp:15
Definition: Omega_h_expr.hpp:30