PolyFEM
Loading...
Searching...
No Matches
OperatorSplittingSolver.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
7
8#include <polysolve/linear/Solver.hpp>
9
11#include <memory>
12
13#ifdef POLYFEM_WITH_TBB
14#include <tbb/tbb.h>
15#endif
16
17namespace polyfem
18{
19 namespace solver
20 {
22 {
23 public:
24 void initialize_grid(const mesh::Mesh &mesh,
25 const std::vector<basis::ElementBases> &gbases,
26 const std::vector<basis::ElementBases> &bases,
27 const double &density_dx);
28
29 void initialize_mesh(const mesh::Mesh &mesh,
30 const int shape, const int n_el,
31 const std::vector<mesh::LocalBoundary> &local_boundary);
32
33 void initialize_hashtable(const mesh::Mesh &mesh);
34
36
37 void initialize_solver(const mesh::Mesh &mesh,
38 const int shape_, const int n_el_,
39 const std::vector<mesh::LocalBoundary> &local_boundary,
40 const std::vector<int> &bnd_nodes);
41
43 const int shape, const int n_el,
44 const std::vector<mesh::LocalBoundary> &local_boundary,
45 const std::vector<int> &bnd_nodes);
46
48 const int shape, const int n_el,
49 const std::vector<mesh::LocalBoundary> &local_boundary,
50 const std::vector<int> &boundary_nodes_,
51 const std::vector<int> &pressure_boundary_nodes,
52 const std::vector<int> &bnd_nodes,
53 const StiffnessMatrix &mass,
54 const StiffnessMatrix &stiffness_viscosity,
55 const StiffnessMatrix &stiffness_velocity,
56 const StiffnessMatrix &mass_velocity,
57 const double &dt,
58 const double &viscosity_,
59 const json &params);
60
62
63 int trace_back(const std::vector<basis::ElementBases> &gbases,
64 const std::vector<basis::ElementBases> &bases,
65 const RowVectorNd &pos_1,
66 const RowVectorNd &vel_1,
67 RowVectorNd &pos_2,
68 RowVectorNd &vel_2,
69 Eigen::MatrixXd &local_pos,
70 const Eigen::MatrixXd &sol,
71 const double dt);
72
73 int interpolator(const std::vector<basis::ElementBases> &gbases,
74 const std::vector<basis::ElementBases> &bases,
75 const RowVectorNd &pos,
76 RowVectorNd &vel,
77 Eigen::MatrixXd &local_pos,
78 const Eigen::MatrixXd &sol);
79
80 void interpolator(const RowVectorNd &pos, double &val);
81
82 public:
83 void advection(const mesh::Mesh &mesh,
84 const std::vector<basis::ElementBases> &gbases,
85 const std::vector<basis::ElementBases> &bases,
86 Eigen::MatrixXd &sol,
87 const double dt,
88 const Eigen::MatrixXd &local_pts,
89 const int order = 1,
90 const int RK = 1);
91
92 void advect_density_exact(const std::vector<basis::ElementBases> &gbases,
93 const std::vector<basis::ElementBases> &bases,
94 const std::shared_ptr<assembler::Problem> problem,
95 const double t,
96 const double dt,
97 const int RK = 3);
98
99 void advect_density(const std::vector<basis::ElementBases> &gbases,
100 const std::vector<basis::ElementBases> &bases,
101 const Eigen::MatrixXd &sol,
102 const double dt,
103 const int RK = 3);
104
105 void advection_FLIP(const mesh::Mesh &mesh, const std::vector<basis::ElementBases> &gbases, const std::vector<basis::ElementBases> &bases, Eigen::MatrixXd &sol, const double dt, const Eigen::MatrixXd &local_pts, const int order = 1);
106
107 void advection_PIC(const mesh::Mesh &mesh, const std::vector<basis::ElementBases> &gbases, const std::vector<basis::ElementBases> &bases, Eigen::MatrixXd &sol, const double dt, const Eigen::MatrixXd &local_pts, const int order = 1);
108
109 void solve_diffusion_1st(const StiffnessMatrix &mass, const std::vector<int> &bnd_nodes, Eigen::MatrixXd &sol);
110
111 void external_force(const mesh::Mesh &mesh,
112 const assembler::Assembler &assembler,
113 const std::vector<basis::ElementBases> &gbases,
114 const std::vector<basis::ElementBases> &bases,
115 const double dt,
116 Eigen::MatrixXd &sol,
117 const Eigen::MatrixXd &local_pts,
118 const std::shared_ptr<assembler::Problem> problem,
119 const double time);
120
121 void solve_pressure(const StiffnessMatrix &mixed_stiffness, const std::vector<int> &pressure_boundary_nodes, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure);
122
123 void projection(const StiffnessMatrix &velocity_mass, const StiffnessMatrix &mixed_stiffness, const std::vector<int> &boundary_nodes_, Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure);
124
125 void projection(int n_bases,
126 const std::vector<basis::ElementBases> &gbases,
127 const std::vector<basis::ElementBases> &bases,
128 const std::vector<basis::ElementBases> &pressure_bases,
129 const Eigen::MatrixXd &local_pts,
130 Eigen::MatrixXd &pressure,
131 Eigen::MatrixXd &sol);
132
133 void initialize_density(const std::shared_ptr<assembler::Problem> &problem);
134
135 long search_cell(const std::vector<basis::ElementBases> &gbases, const RowVectorNd &pos, Eigen::MatrixXd &local_pts);
136
137 bool outside_quad(const std::vector<RowVectorNd> &vert, const RowVectorNd &pos);
138
139 void compute_gbase_val(const int elem_idx, const Eigen::MatrixXd &local_pos, Eigen::MatrixXd &pos);
140
141 void compute_gbase_jacobi(const int elem_idx, const Eigen::MatrixXd &local_pos, Eigen::MatrixXd &jacobi);
142
144 const int elem_idx,
145 const RowVectorNd &pos,
146 Eigen::MatrixXd &local_pos);
147
148 void save_density();
149
150 int dim;
151 int n_el;
152 int shape;
153
156
157 Eigen::MatrixXd V;
158 Eigen::MatrixXi T;
159
160 std::vector<std::vector<long>> hash_table;
161 Eigen::Matrix<long, Eigen::Dynamic, 1, Eigen::ColMajor, 3, 1> hash_table_cell_num;
162
163 std::vector<Eigen::Matrix<double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3>> position_particle;
164 std::vector<Eigen::Matrix<double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3>> velocity_particle;
165 std::vector<int> cellI_particle;
166 Eigen::MatrixXd new_sol;
167 Eigen::MatrixXd new_sol_w;
168
169 std::vector<int> boundary_elem_id;
170 std::vector<int> boundary_nodes;
171
172 std::unique_ptr<polysolve::linear::Solver> solver_diffusion;
173 std::unique_ptr<polysolve::linear::Solver> solver_projection;
174 std::unique_ptr<polysolve::linear::Solver> solver_mass;
175
178
179 Eigen::VectorXd density;
180 // Eigen::VectorXi density_cell_no;
181 // std::vector<ElementAssemblyValues> density_local_weights;
182 Eigen::Matrix<double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3> grid_cell_num;
184 };
185 } // namespace solver
186} // namespace polyfem
double val
Definition Assembler.cpp:86
Stores the basis functions for a given element in a mesh (facet in 2d, cell in 3d).
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:39
void initialize_mesh(const mesh::Mesh &mesh, const int shape, const int n_el, const std::vector< mesh::LocalBoundary > &local_boundary)
void solve_pressure(const StiffnessMatrix &mixed_stiffness, const std::vector< int > &pressure_boundary_nodes, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
void projection(const StiffnessMatrix &velocity_mass, const StiffnessMatrix &mixed_stiffness, const std::vector< int > &boundary_nodes_, Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure)
int interpolator(const std::vector< basis::ElementBases > &gbases, const std::vector< basis::ElementBases > &bases, const RowVectorNd &pos, RowVectorNd &vel, Eigen::MatrixXd &local_pos, const Eigen::MatrixXd &sol)
void compute_gbase_val(const int elem_idx, const Eigen::MatrixXd &local_pos, Eigen::MatrixXd &pos)
void external_force(const mesh::Mesh &mesh, const assembler::Assembler &assembler, const std::vector< basis::ElementBases > &gbases, const std::vector< basis::ElementBases > &bases, const double dt, Eigen::MatrixXd &sol, const Eigen::MatrixXd &local_pts, const std::shared_ptr< assembler::Problem > problem, const double time)
std::unique_ptr< polysolve::linear::Solver > solver_diffusion
void advection(const mesh::Mesh &mesh, const std::vector< basis::ElementBases > &gbases, const std::vector< basis::ElementBases > &bases, Eigen::MatrixXd &sol, const double dt, const Eigen::MatrixXd &local_pts, const int order=1, const int RK=1)
void initialize_density(const std::shared_ptr< assembler::Problem > &problem)
void advection_PIC(const mesh::Mesh &mesh, const std::vector< basis::ElementBases > &gbases, const std::vector< basis::ElementBases > &bases, Eigen::MatrixXd &sol, const double dt, const Eigen::MatrixXd &local_pts, const int order=1)
std::vector< Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > > position_particle
long search_cell(const std::vector< basis::ElementBases > &gbases, const RowVectorNd &pos, Eigen::MatrixXd &local_pts)
std::vector< std::vector< long > > hash_table
int trace_back(const std::vector< basis::ElementBases > &gbases, const std::vector< basis::ElementBases > &bases, const RowVectorNd &pos_1, const RowVectorNd &vel_1, RowVectorNd &pos_2, RowVectorNd &vel_2, Eigen::MatrixXd &local_pos, const Eigen::MatrixXd &sol, const double dt)
void advect_density(const std::vector< basis::ElementBases > &gbases, const std::vector< basis::ElementBases > &bases, const Eigen::MatrixXd &sol, const double dt, const int RK=3)
void advection_FLIP(const mesh::Mesh &mesh, const std::vector< basis::ElementBases > &gbases, const std::vector< basis::ElementBases > &bases, Eigen::MatrixXd &sol, const double dt, const Eigen::MatrixXd &local_pts, const int order=1)
bool outside_quad(const std::vector< RowVectorNd > &vert, const RowVectorNd &pos)
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > grid_cell_num
Eigen::Matrix< long, Eigen::Dynamic, 1, Eigen::ColMajor, 3, 1 > hash_table_cell_num
std::unique_ptr< polysolve::linear::Solver > solver_projection
std::vector< Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > > velocity_particle
void calculate_local_pts(const basis::ElementBases &gbase, const int elem_idx, const RowVectorNd &pos, Eigen::MatrixXd &local_pos)
std::unique_ptr< polysolve::linear::Solver > solver_mass
void compute_gbase_jacobi(const int elem_idx, const Eigen::MatrixXd &local_pos, Eigen::MatrixXd &jacobi)
void advect_density_exact(const std::vector< basis::ElementBases > &gbases, const std::vector< basis::ElementBases > &bases, const std::shared_ptr< assembler::Problem > problem, const double t, const double dt, const int RK=3)
void initialize_solver(const mesh::Mesh &mesh, const int shape_, const int n_el_, const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &bnd_nodes)
void solve_diffusion_1st(const StiffnessMatrix &mass, const std::vector< int > &bnd_nodes, Eigen::MatrixXd &sol)
void initialize_grid(const mesh::Mesh &mesh, const std::vector< basis::ElementBases > &gbases, const std::vector< basis::ElementBases > &bases, const double &density_dx)
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:22