PolyFEM
Loading...
Searching...
No Matches
PressureAssembler.hpp
Go to the documentation of this file.
1#pragma once
2
5
9
10namespace polyfem
11{
12 namespace assembler
13 {
15 {
16 public:
19 virtual double pressure(const double start_pressure, const double v0, const double v1) const { return 0; }
20 virtual double first_derivative(const double start_pressure, const double v0, const double v1) const { return 0; }
21 virtual double second_derivative(const double start_pressure, const double v0, const double v1) const { return 0; }
22 virtual double energy(const double start_pressure, const double v0, const double v1) const { return 0; }
23
24 protected:
25 const double atmospheric = 101.3e3;
26 };
27
29 {
30 public:
31 virtual double pressure(const double start_pressure, const double v0, const double v1) const override
32 {
33 return ((start_pressure + atmospheric) * v0) / v1 - atmospheric;
34 }
35
36 virtual double first_derivative(const double start_pressure, const double v0, const double v1) const override
37 {
38 return -((start_pressure + atmospheric) * v0) / (v1 * v1);
39 }
40
41 virtual double second_derivative(const double start_pressure, const double v0, const double v1) const override
42 {
43 return 2 * ((start_pressure + atmospheric) * v0) / (v1 * v1 * v1);
44 }
45
46 virtual double energy(const double start_pressure, const double v0, const double v1) const override { return (start_pressure + atmospheric) * v0 * std::log(v1) - atmospheric * v1; }
47 };
48
50 {
51 public:
52 virtual double pressure(const double start_pressure, const double v0, const double v1) const override
53 {
54 return ((start_pressure + atmospheric) * std::pow(v0 / v1, gamma_)) - atmospheric;
55 }
56
57 virtual double first_derivative(const double start_pressure, const double v0, const double v1) const override
58 {
59 return -gamma_ * (start_pressure + atmospheric) * std::pow(v0 / v1, gamma_) / v1;
60 }
61
62 virtual double second_derivative(const double start_pressure, const double v0, const double v1) const override
63 {
64 return gamma_ * (1 + gamma_) * (start_pressure + atmospheric) * std::pow(v0 / v1, gamma_) / v1 / v1;
65 }
66
67 virtual double energy(const double start_pressure, const double v0, const double v1) const override { return (start_pressure + atmospheric) * std::pow(v0, gamma_) * (std::pow(v1, 1. - gamma_)) / (1. - gamma_) - atmospheric * v1; }
68
69 private:
70 const double gamma_ = 1.4;
71 };
72
73 // computes the rhs of a problem by \int \phi rho rhs
75 {
76 public:
77 // initialization with assembler factory mesh
78 // size of the problem, bases
79 // and solver used internally
80 PressureAssembler(const Assembler &assembler, const mesh::Mesh &mesh, const mesh::Obstacle &obstacle,
81 const std::vector<mesh::LocalBoundary> &local_pressure_boundary,
82 const std::unordered_map<int, std::vector<mesh::LocalBoundary>> &local_pressure_cavity,
83 const std::vector<int> &dirichlet_nodes,
84 const std::vector<int> &primitive_to_nodes, const std::vector<int> &node_to_primitives,
85 const int n_basis, const int size,
86 const std::vector<basis::ElementBases> &bases, const std::vector<basis::ElementBases> &gbases, const Problem &problem);
87
88 double compute_energy(
89 const Eigen::MatrixXd &displacement,
90 const std::vector<mesh::LocalBoundary> &local_pressure_boundary,
91 const int resolution,
92 const double t) const;
94 const Eigen::MatrixXd &displacement,
95 const std::vector<mesh::LocalBoundary> &local_pressure_boundary,
96 const std::vector<int> &dirichlet_nodes,
97 const int resolution,
98 const double t,
99 Eigen::VectorXd &grad) const;
101 const Eigen::MatrixXd &displacement,
102 const std::vector<mesh::LocalBoundary> &local_pressure_boundary,
103 const std::vector<int> &dirichlet_nodes,
104 const int resolution,
105 const double t,
106 const bool project_to_psd,
107 StiffnessMatrix &hess) const;
108
110 const Eigen::MatrixXd &displacement,
111 const std::unordered_map<int, std::vector<mesh::LocalBoundary>> &local_pressure_cavity,
112 const int resolution,
113 const double t) const;
115 const Eigen::MatrixXd &displacement,
116 const std::unordered_map<int, std::vector<mesh::LocalBoundary>> &local_pressure_cavity,
117 const std::vector<int> &dirichlet_nodes,
118 const int resolution,
119 const double t,
120 Eigen::VectorXd &grad) const;
122 const Eigen::MatrixXd &displacement,
123 const std::unordered_map<int, std::vector<mesh::LocalBoundary>> &local_pressure_cavity,
124 const std::vector<int> &dirichlet_nodes,
125 const int resolution,
126 const double t,
127 const bool project_to_psd,
128 StiffnessMatrix &hess) const;
129
131 const Eigen::MatrixXd &displacement,
132 const std::vector<mesh::LocalBoundary> &local_pressure_boundary,
133 const std::vector<int> &dirichlet_nodes,
134 const int resolution,
135 const double t,
136 const int n_vertices,
137 StiffnessMatrix &hess) const;
138
139 inline const Problem &problem() const { return problem_; }
140 inline const mesh::Mesh &mesh() const { return mesh_; }
141 inline const std::vector<basis::ElementBases> &bases() const { return bases_; }
142 inline const std::vector<basis::ElementBases> &gbases() const { return gbases_; }
143 inline const Assembler &assembler() const { return assembler_; }
144
145 void compute_grad_volume_id(const Eigen::MatrixXd &displacement,
146 const int boundary_id,
147 const std::vector<mesh::LocalBoundary> &local_boundary,
148 const std::vector<int> &dirichlet_nodes,
149 const int resolution,
150 Eigen::VectorXd &grad,
151 const double t = 0,
152 const bool multiply_pressure = false) const;
153
154 private:
155 double compute_volume(
156 const Eigen::MatrixXd &displacement,
157 const std::vector<mesh::LocalBoundary> &local_boundary,
158 const int resolution,
159 const double t = 0,
160 const bool multiply_pressure = false) const;
161 void compute_grad_volume(const Eigen::MatrixXd &displacement,
162 const std::vector<mesh::LocalBoundary> &local_boundary,
163 const std::vector<int> &dirichlet_nodes,
164 const int resolution,
165 Eigen::VectorXd &grad,
166 const double t = 0,
167 const bool multiply_pressure = false) const;
169 const Eigen::MatrixXd &displacement,
170 const std::vector<mesh::LocalBoundary> &local_boundary,
171 const std::vector<int> &dirichlet_nodes,
172 const int resolution,
173 StiffnessMatrix &hess,
174 const double t = 0,
175 const bool multiply_pressure = false) const;
177 const Eigen::MatrixXd &displacement,
178 const std::vector<mesh::LocalBoundary> &local_boundary,
179 const std::vector<int> &dirichlet_nodes,
180 const int resolution,
181 StiffnessMatrix &hess,
182 const double t = 0,
183 const bool multiply_pressure = false) const;
184
186 const std::vector<mesh::LocalBoundary> &local_boundary,
187 const std::vector<int> &dirichlet_nodes) const;
188
189 private:
193 const int n_basis_;
194 const int size_;
195 const std::vector<basis::ElementBases> &bases_;
196 const std::vector<basis::ElementBases> &gbases_;
198
199 std::unordered_map<int, double> starting_volumes_;
200 std::unique_ptr<ThermodynamicProcess> cavity_thermodynamics_;
201
202 const std::vector<int> primitive_to_nodes_;
203 const std::vector<int> node_to_primitives_;
205 };
206 } // namespace assembler
207} // namespace polyfem
virtual double energy(const double start_pressure, const double v0, const double v1) const override
virtual double second_derivative(const double start_pressure, const double v0, const double v1) const override
virtual double pressure(const double start_pressure, const double v0, const double v1) const override
virtual double first_derivative(const double start_pressure, const double v0, const double v1) const override
virtual double pressure(const double start_pressure, const double v0, const double v1) const override
virtual double first_derivative(const double start_pressure, const double v0, const double v1) const override
virtual double energy(const double start_pressure, const double v0, const double v1) const override
virtual double second_derivative(const double start_pressure, const double v0, const double v1) const override
double compute_energy(const Eigen::MatrixXd &displacement, const std::vector< mesh::LocalBoundary > &local_pressure_boundary, const int resolution, const double t) const
bool is_closed_or_boundary_fixed(const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &dirichlet_nodes) const
const std::vector< basis::ElementBases > & gbases_
std::unique_ptr< ThermodynamicProcess > cavity_thermodynamics_
void compute_grad_volume_id(const Eigen::MatrixXd &displacement, const int boundary_id, const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &dirichlet_nodes, const int resolution, Eigen::VectorXd &grad, const double t=0, const bool multiply_pressure=false) const
void compute_hess_volume_3d(const Eigen::MatrixXd &displacement, const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &dirichlet_nodes, const int resolution, StiffnessMatrix &hess, const double t=0, const bool multiply_pressure=false) const
void compute_hess_volume_2d(const Eigen::MatrixXd &displacement, const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &dirichlet_nodes, const int resolution, StiffnessMatrix &hess, const double t=0, const bool multiply_pressure=false) const
void compute_energy_hess(const Eigen::MatrixXd &displacement, const std::vector< mesh::LocalBoundary > &local_pressure_boundary, const std::vector< int > &dirichlet_nodes, const int resolution, const double t, const bool project_to_psd, StiffnessMatrix &hess) const
double compute_volume(const Eigen::MatrixXd &displacement, const std::vector< mesh::LocalBoundary > &local_boundary, const int resolution, const double t=0, const bool multiply_pressure=false) const
const std::vector< basis::ElementBases > & bases_
void compute_grad_volume(const Eigen::MatrixXd &displacement, const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &dirichlet_nodes, const int resolution, Eigen::VectorXd &grad, const double t=0, const bool multiply_pressure=false) const
void compute_energy_grad(const Eigen::MatrixXd &displacement, const std::vector< mesh::LocalBoundary > &local_pressure_boundary, const std::vector< int > &dirichlet_nodes, const int resolution, const double t, Eigen::VectorXd &grad) const
const std::vector< basis::ElementBases > & bases() const
void compute_force_jacobian(const Eigen::MatrixXd &displacement, const std::vector< mesh::LocalBoundary > &local_pressure_boundary, const std::vector< int > &dirichlet_nodes, const int resolution, const double t, const int n_vertices, StiffnessMatrix &hess) const
const std::vector< basis::ElementBases > & gbases() const
std::unordered_map< int, double > starting_volumes_
void compute_cavity_energy_grad(const Eigen::MatrixXd &displacement, const std::unordered_map< int, std::vector< mesh::LocalBoundary > > &local_pressure_cavity, const std::vector< int > &dirichlet_nodes, const int resolution, const double t, Eigen::VectorXd &grad) const
void compute_cavity_energy_hess(const Eigen::MatrixXd &displacement, const std::unordered_map< int, std::vector< mesh::LocalBoundary > > &local_pressure_cavity, const std::vector< int > &dirichlet_nodes, const int resolution, const double t, const bool project_to_psd, StiffnessMatrix &hess) const
double compute_cavity_energy(const Eigen::MatrixXd &displacement, const std::unordered_map< int, std::vector< mesh::LocalBoundary > > &local_pressure_cavity, const int resolution, const double t) const
virtual double pressure(const double start_pressure, const double v0, const double v1) const
virtual double second_derivative(const double start_pressure, const double v0, const double v1) const
virtual double energy(const double start_pressure, const double v0, const double v1) const
virtual double first_derivative(const double start_pressure, const double v0, const double v1) const
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:39
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:22