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 }
22
23 void init(const json &vals);
24 void init(const double val);
25 void init(const Eigen::MatrixXd &val);
26 void init(const std::string &expr);
27
28 void init(const std::function<double(double x, double y, double z)> &func);
29 void init(const std::function<double(double x, double y, double z, double t)> &func);
30 void init(const std::function<double(double x, double y, double z, double t, int index)> &func);
31
32 void init(const std::function<Eigen::MatrixXd(double x, double y, double z)> &func, const int coo);
33 void init(const std::function<Eigen::MatrixXd(double x, double y, double z, double t)> &func, const int coo);
34
35 void set_t(const json &t);
36
37 double operator()(double x, double y, double z = 0, double t = 0, int index = -1) const;
38
39 void clear();
40
41 bool is_zero() const { return expr_.empty() && fabs(value_) < 1e-10; }
42 bool is_mat() const
43 {
44 if (expr_.empty() && mat_.size() > 0)
45 return true;
46 return false;
47 }
48
49 const Eigen::MatrixXd &get_mat() const
50 {
51 assert(is_mat());
52 return mat_;
53 }
54
55 void set_mat(const Eigen::MatrixXd &mat)
56 {
57 assert(is_mat());
58 assert(mat_.rows() == mat.rows());
59 assert(mat_.cols() == mat.cols());
60 mat_ = mat;
61 }
62
63 double get_val() const
64 {
65 return value_;
66 }
67
68 private:
69 std::function<double(double x, double y, double z, double t, int index)> sfunc_;
70 std::function<Eigen::MatrixXd(double x, double y, double z, double t)> tfunc_;
72
73 std::string expr_;
74 double value_;
75 Eigen::MatrixXd mat_;
76 std::vector<ExpressionValue> mat_expr_;
77 std::map<double, int> t_index_;
78
79 units::precise_unit unit_type_;
80 units::precise_unit unit_;
81 bool unit_type_set_ = false;
82 };
83 } // namespace utils
84} // namespace polyfem
double val
Definition Assembler.cpp:86
ElementAssemblyValues vals
Definition Assembler.cpp:22
int y
int z
int x
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