PolyFEM
Loading...
Searching...
No Matches
ExpressionValue.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
4#include <map>
5
6#include <units/units.hpp>
7
8namespace polyfem
9{
10 namespace utils
11 {
13 {
14 public:
16
17 void set_unit_type(const std::string &unit_type)
18 {
19 unit_type_ = units::unit_from_string(unit_type);
20 unit_type_set_ = true;
21 for (auto &expr : mat_expr_)
22 expr.set_unit_type(unit_type);
23 }
24
25 void init(const json &vals, const std::string &root_path);
26 void init(const double val);
27 void init(const Eigen::MatrixXd &val);
28 void init(const std::string &expr, const std::string &root_path);
29#ifdef POLYFEM_WITH_PYTHON
30 void init_python(const std::string &path, const std::string &function_name);
31#endif
32
33 void init(const std::function<double(double x, double y, double z)> &func);
34 void init(const std::function<double(double x, double y, double z, double t)> &func);
35 void init(const std::function<double(double x, double y, double z, double t, int index)> &func);
36
37 void init(const std::function<Eigen::MatrixXd(double x, double y, double z)> &func, const int coo);
38 void init(const std::function<Eigen::MatrixXd(double x, double y, double z, double t)> &func, const int coo);
39
40 void set_t(const json &t);
41
42 double operator()(double x, double y, double z = 0, double t = 0, int index = -1) const;
43
44 void clear();
45
46 bool is_zero() const
47 {
48 return expr_.empty() && mat_.size() == 0 && mat_expr_.empty() && !sfunc_ && !tfunc_ && fabs(value_) < 1e-10;
49 }
50 bool is_mat() const
51 {
52 if (expr_.empty() && mat_.size() > 0)
53 return true;
54 return false;
55 }
56
57 const Eigen::MatrixXd &get_mat() const
58 {
59 assert(is_mat());
60 return mat_;
61 }
62
63 void set_mat(const Eigen::MatrixXd &mat)
64 {
65 assert(is_mat());
66 assert(mat_.rows() == mat.rows());
67 assert(mat_.cols() == mat.cols());
68 mat_ = mat;
69 }
70
71 double get_val() const
72 {
73 return value_;
74 }
75
76 private:
77 std::function<double(double x, double y, double z, double t, int index)> sfunc_;
78 std::function<Eigen::MatrixXd(double x, double y, double z, double t)> tfunc_;
80
81 std::string expr_;
82 double value_;
83 Eigen::MatrixXd mat_;
84 std::vector<ExpressionValue> mat_expr_;
85 std::map<double, int> t_index_;
86
87 units::precise_unit unit_type_;
88 units::precise_unit unit_;
89 bool unit_type_set_ = false;
90 };
91 } // namespace utils
92} // namespace polyfem
double val
Definition Assembler.cpp:86
ElementAssemblyValues vals
Definition Assembler.cpp:22
int y
int z
int x
void init(const json &vals, const std::string &root_path)
std::vector< ExpressionValue > mat_expr_
std::function< double(double x, double y, double z, double t, int index)> sfunc_
std::function< Eigen::MatrixXd(double x, double y, double z, double t)> tfunc_
std::map< double, int > t_index_
void set_unit_type(const std::string &unit_type)
double operator()(double x, double y, double z=0, double t=0, int index=-1) const
const Eigen::MatrixXd & get_mat() const
void set_mat(const Eigen::MatrixXd &mat)
nlohmann::json json
Definition Common.hpp:9