PolyFEM
Loading...
Searching...
No Matches
GenericProblem.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace polyfem
8{
9 namespace assembler
10 {
12 {
13 int fe_space_id = -1;
14 int size = 0;
15 std::array<utils::ExpressionValue, 3> value;
16 std::vector<std::shared_ptr<utils::Interpolation>> interpolation;
17 Eigen::Matrix<bool, 1, 3> dirichlet_dimension;
18
19 void set_unit_type(const std::string &unit_type)
20 {
21 for (auto &v : value)
22 v.set_unit_type(unit_type);
23 }
24
25 double eval(const RowVectorNd &pts, const int dim, const double t, const int el_id = -1) const;
26 };
27
29 {
30 int fe_space_id = -1;
32 std::shared_ptr<utils::Interpolation> interpolation;
33
34 void set_unit_type(const std::string &unit_type)
35 {
36 value.set_unit_type(unit_type);
37 }
38
39 double eval(const RowVectorNd &pts, const double t) const;
40 };
41
43 {
44 int body_id = -1;
45 int fe_space_id = -1;
46 int size = 0;
47 std::array<utils::ExpressionValue, 3> value;
48 };
49
56
58 {
59 public:
60 GenericTensorProblem(const std::string &name);
61 void set_units(const assembler::Assembler &assembler, const Units &units) override;
62
63 void rhs(const assembler::Assembler &assembler, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
64 void rhs(const assembler::Assembler &assembler, const mesh::Mesh &mesh, const int element_id, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
65 bool is_rhs_zero(const int fe_space_id = -1) const override;
66
67 void dirichlet_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
68 void neumann_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &normals, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
69 void pressure_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &normals, const double t, Eigen::MatrixXd &val) const override;
70 double pressure_cavity_bc(const int boundary_id, const double t) const override;
71
72 void dirichlet_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
73 void neumann_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const Eigen::MatrixXd &normal, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
74 bool is_nodal_dirichlet_boundary(const int n_id, const int tag, const int fe_space_id = -1) override;
75 bool is_nodal_neumann_boundary(const int n_id, const int tag, const int fe_space_id = -1) override;
76 bool has_nodal_dirichlet(const int fe_space_id = -1) override;
77 bool has_nodal_neumann(const int fe_space_id = -1) override;
78 bool is_nodal_dimension_dirichlet(const int n_id, const int tag, const int dim, const int fe_space_id = -1) const override;
79 void update_nodes(const Eigen::VectorXi &in_node_to_node) override;
80
81 bool has_exact_sol() const override { return has_exact_; }
82 bool is_scalar() const override { return false; }
83 bool is_time_dependent() const override { return is_time_dept_; }
84 void set_time_dependent(const bool val) { is_time_dept_ = val; }
85 bool is_constant_in_time() const override { return !is_time_dept_; }
86 bool might_have_no_dirichlet() override { return !is_all_; }
87
88 void initial_solution(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
89 void initial_velocity(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
90 void initial_acceleration(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
91
92 void set_parameters(const json &params, const std::string &root_path) override;
93
94 bool is_dimension_dirichet(const int tag, const int dim, const int fe_space_id = -1) const override;
95 bool all_dimensions_dirichlet(const int fe_space_id) const override;
96
97 void exact(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const override;
98 void exact_grad(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const override;
99
100 void clear() override;
101
102 void update_dirichlet_boundary(const int id, const int time_step, const Eigen::VectorXd &val);
103 void update_dirichlet_nodes(const Eigen::VectorXi &in_node_to_node, const Eigen::VectorXi &node_ids, const Eigen::MatrixXd &nodal_dirichlet);
104 void update_pressure_boundary(const int id, const int time_step, const double val);
105
106 private:
107 bool has_exact_ = false;
108 bool has_exact_grad_ = false;
109 bool is_time_dept_ = false;
110 // bool is_mixed_ = false;
111
112 std::vector<TensorBCValue> forces_;
113 std::vector<TensorBCValue> displacements_;
114 std::vector<ScalarBCValue> normal_aligned_forces_;
115 std::vector<ScalarBCValue> pressures_;
116 std::unordered_map<int, ScalarBCValue> cavity_pressures_;
117
118 std::vector<TensorInitialValue> initial_position_;
119 std::vector<TensorInitialValue> initial_velocity_;
120 std::vector<TensorInitialValue> initial_acceleration_;
121
122 std::map<int, std::array<utils::ExpressionValue, 3>> rhs_;
123 std::map<int, int> rhs_size_;
124 std::vector<TensorInitialValue> body_rhs_;
125 std::array<utils::ExpressionValue, 3> exact_;
126 std::array<utils::ExpressionValue, 9> exact_grad_;
127
128 std::map<int, TensorBCValue> nodal_dirichlet_;
129 std::map<int, TensorBCValue> nodal_neumann_;
130 std::vector<Eigen::MatrixXd> nodal_dirichlet_mat_;
131 std::vector<Eigen::MatrixXd> nodal_neumann_mat_;
132
134
135 protected:
136 bool has_boundary(const BoundaryKind kind, const int tag, const int fe_space_id) override;
137 };
138
140 {
141 public:
142 GenericScalarProblem(const std::string &name);
143 void set_units(const assembler::Assembler &assembler, const Units &units) override;
144
145 void rhs(const assembler::Assembler &assembler, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
146 void rhs(const assembler::Assembler &assembler, const mesh::Mesh &mesh, const int element_id, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
147 bool is_rhs_zero(const int fe_space_id = -1) const override;
148
149 void dirichlet_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
150 void neumann_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &normals, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
151 void initial_solution(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
152
153 void dirichlet_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
154 void neumann_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const Eigen::MatrixXd &normal, const double t, Eigen::MatrixXd &val, const int fe_space_id = -1) const override;
155 bool is_nodal_dirichlet_boundary(const int n_id, const int tag, const int fe_space_id = -1) override;
156 bool is_nodal_neumann_boundary(const int n_id, const int tag, const int fe_space_id = -1) override;
157 bool has_nodal_dirichlet(const int fe_space_id = -1) override;
158 bool has_nodal_neumann(const int fe_space_id = -1) override;
159 void update_nodes(const Eigen::VectorXi &in_node_to_node) override;
160
161 bool has_exact_sol() const override { return has_exact_; }
162 bool is_scalar() const override { return true; }
163 bool is_time_dependent() const override { return is_time_dept_; }
164 void set_time_dependent(const bool val) { is_time_dept_ = val; }
165 bool is_constant_in_time() const override { return !is_time_dept_; }
166 bool might_have_no_dirichlet() override { return !is_all_; }
167
168 void set_parameters(const json &params, const std::string &root_path) override;
169
170 void exact(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const override;
171 void exact_grad(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const override;
172
173 void clear() override;
174
175 private:
176 std::vector<ScalarBCValue> neumann_;
177 std::vector<ScalarBCValue> dirichlet_;
178 std::vector<ScalarInitialValue> initial_solution_;
179
180 std::map<int, ScalarBCValue> nodal_dirichlet_;
181 std::map<int, ScalarBCValue> nodal_neumann_;
182 std::vector<Eigen::MatrixXd> nodal_dirichlet_mat_;
183 std::vector<Eigen::MatrixXd> nodal_neumann_mat_;
184
185 std::map<int, utils::ExpressionValue> rhs_;
186 std::vector<ScalarInitialValue> body_rhs_;
188 std::array<utils::ExpressionValue, 3> exact_grad_;
190 bool has_exact_ = false;
191 bool has_exact_grad_ = false;
192 bool is_time_dept_ = false;
193
194 protected:
195 bool has_boundary(const BoundaryKind kind, const int tag, const int fe_space_id) override;
196 };
197 } // namespace assembler
198} // namespace polyfem
double val
Definition Assembler.cpp:89
void neumann_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &normals, const double t, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
bool is_nodal_neumann_boundary(const int n_id, const int tag, const int fe_space_id=-1) override
std::vector< ScalarBCValue > neumann_
void initial_solution(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
std::vector< Eigen::MatrixXd > nodal_neumann_mat_
void update_nodes(const Eigen::VectorXi &in_node_to_node) override
void dirichlet_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const double t, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
bool is_nodal_dirichlet_boundary(const int n_id, const int tag, const int fe_space_id=-1) override
std::vector< ScalarInitialValue > body_rhs_
std::array< utils::ExpressionValue, 3 > exact_grad_
bool has_nodal_dirichlet(const int fe_space_id=-1) override
void exact_grad(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const override
bool has_nodal_neumann(const int fe_space_id=-1) override
std::map< int, utils::ExpressionValue > rhs_
void neumann_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const Eigen::MatrixXd &normal, const double t, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
std::map< int, ScalarBCValue > nodal_dirichlet_
void rhs(const assembler::Assembler &assembler, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
std::vector< ScalarInitialValue > initial_solution_
bool is_rhs_zero(const int fe_space_id=-1) const override
void set_units(const assembler::Assembler &assembler, const Units &units) override
std::map< int, ScalarBCValue > nodal_neumann_
std::vector< ScalarBCValue > dirichlet_
void set_parameters(const json &params, const std::string &root_path) override
bool has_boundary(const BoundaryKind kind, const int tag, const int fe_space_id) override
void exact(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const override
void dirichlet_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
std::vector< Eigen::MatrixXd > nodal_dirichlet_mat_
void update_pressure_boundary(const int id, const int time_step, const double val)
bool has_boundary(const BoundaryKind kind, const int tag, const int fe_space_id) override
std::map< int, TensorBCValue > nodal_neumann_
std::vector< TensorInitialValue > initial_acceleration_
void set_parameters(const json &params, const std::string &root_path) override
void initial_acceleration(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
void initial_solution(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
std::unordered_map< int, ScalarBCValue > cavity_pressures_
std::vector< TensorInitialValue > initial_position_
void rhs(const assembler::Assembler &assembler, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
void update_nodes(const Eigen::VectorXi &in_node_to_node) override
std::vector< TensorInitialValue > body_rhs_
std::vector< TensorInitialValue > initial_velocity_
bool all_dimensions_dirichlet(const int fe_space_id) const override
void update_dirichlet_nodes(const Eigen::VectorXi &in_node_to_node, const Eigen::VectorXi &node_ids, const Eigen::MatrixXd &nodal_dirichlet)
std::vector< TensorBCValue > displacements_
void neumann_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &normals, const double t, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
std::vector< ScalarBCValue > normal_aligned_forces_
std::map< int, std::array< utils::ExpressionValue, 3 > > rhs_
bool is_nodal_dimension_dirichlet(const int n_id, const int tag, const int dim, const int fe_space_id=-1) const override
void dirichlet_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
std::vector< Eigen::MatrixXd > nodal_neumann_mat_
bool is_nodal_neumann_boundary(const int n_id, const int tag, const int fe_space_id=-1) override
bool is_dimension_dirichet(const int tag, const int dim, const int fe_space_id=-1) const override
void pressure_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &normals, const double t, Eigen::MatrixXd &val) const override
void exact(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const override
std::map< int, TensorBCValue > nodal_dirichlet_
bool has_nodal_neumann(const int fe_space_id=-1) override
std::array< utils::ExpressionValue, 9 > exact_grad_
bool is_rhs_zero(const int fe_space_id=-1) const override
void dirichlet_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const double t, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
void update_dirichlet_boundary(const int id, const int time_step, const Eigen::VectorXd &val)
double pressure_cavity_bc(const int boundary_id, const double t) const override
std::vector< ScalarBCValue > pressures_
bool is_nodal_dirichlet_boundary(const int n_id, const int tag, const int fe_space_id=-1) override
void neumann_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const Eigen::MatrixXd &normal, const double t, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
void exact_grad(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const override
bool has_nodal_dirichlet(const int fe_space_id=-1) override
void set_units(const assembler::Assembler &assembler, const Units &units) override
std::array< utils::ExpressionValue, 3 > exact_
std::vector< Eigen::MatrixXd > nodal_dirichlet_mat_
void initial_velocity(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val, const int fe_space_id=-1) const override
const std::string & name() const
Definition Problem.hpp:29
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:41
void set_unit_type(const std::string &unit_type)
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13
std::shared_ptr< utils::Interpolation > interpolation
void set_unit_type(const std::string &unit_type)
double eval(const RowVectorNd &pts, const double t) const
Eigen::Matrix< bool, 1, 3 > dirichlet_dimension
std::vector< std::shared_ptr< utils::Interpolation > > interpolation
void set_unit_type(const std::string &unit_type)
std::array< utils::ExpressionValue, 3 > value
double eval(const RowVectorNd &pts, const int dim, const double t, const int el_id=-1) const
std::array< utils::ExpressionValue, 3 > value