PolyFEM
Loading...
Searching...
No Matches
PressureForm.cpp
Go to the documentation of this file.
1#include "PressureForm.hpp"
2
6
10
12
14
16
17namespace polyfem::solver
18{
20 const std::vector<mesh::LocalBoundary> &local_pressure_boundary,
21 const std::unordered_map<int, std::vector<mesh::LocalBoundary>> &local_pressure_cavity,
22 const std::vector<int> &dirichlet_nodes,
23 const int n_boundary_samples,
24 const assembler::PressureAssembler &pressure_assembler,
25 const bool is_time_dependent)
26 : ndof_(ndof),
27 local_pressure_boundary_(local_pressure_boundary),
28 local_pressure_cavity_(local_pressure_cavity),
29 dirichlet_nodes_(dirichlet_nodes),
30 n_boundary_samples_(n_boundary_samples),
31 pressure_assembler_(pressure_assembler)
32 {
33 t_ = 0;
34 }
35
36 double PressureForm::value_unweighted(const Eigen::VectorXd &x) const
37 {
40 return -1 * (pressure_energy + pressure_cavity_energy);
41 }
42
43 void PressureForm::first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const
44 {
45 // REMEMBER -!!!!!
46 Eigen::VectorXd pressure_gradv, pressure_cavity_gradv;
49 gradv = pressure_gradv + pressure_cavity_gradv;
50 gradv *= -1;
51 }
52
53 void PressureForm::second_derivative_unweighted(const Eigen::VectorXd &x, StiffnessMatrix &hessian) const
54 {
55 StiffnessMatrix pressure_hessian, pressure_cavity_hessian;
58 hessian = pressure_hessian + pressure_cavity_hessian;
59 hessian *= -1;
60 }
61
62 void PressureForm::update_quantities(const double t, const Eigen::VectorXd &x)
63 {
64 this->t_ = t;
65 }
66
67 void PressureForm::force_shape_derivative(const int n_verts, const double t, const Eigen::MatrixXd &x, const Eigen::MatrixXd &adjoint, Eigen::VectorXd &term)
68 {
69 Eigen::MatrixXd adjoint_zeroed = adjoint;
70 adjoint_zeroed(dirichlet_nodes_, Eigen::all).setZero();
71
72 StiffnessMatrix hessian;
74
75 term = -hessian.transpose() * adjoint_zeroed;
76 }
77
79 const int n_verts,
80 const double t,
81 const int pressure_boundary_id,
82 const Eigen::MatrixXd &x,
83 const Eigen::MatrixXd &adjoint)
84 {
85 Eigen::MatrixXd adjoint_zeroed = adjoint;
86 adjoint_zeroed(dirichlet_nodes_, Eigen::all).setZero();
87
88 Eigen::VectorXd pressure_gradv;
90 pressure_gradv *= -1;
91
92 Eigen::MatrixXd term;
93 term = pressure_gradv.transpose() * adjoint_zeroed;
94 term *= -1;
95
96 assert(term.size() == 1);
97 return term(0);
98 }
99
100} // namespace polyfem::solver
int x
double compute_energy(const Eigen::MatrixXd &displacement, const std::vector< mesh::LocalBoundary > &local_pressure_boundary, const int resolution, const double t) const
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_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
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
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
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
bool project_to_psd_
If true, the form's second derivative is projected to be positive semidefinite.
Definition Form.hpp:146
void second_derivative_unweighted(const Eigen::VectorXd &x, StiffnessMatrix &hessian) const override
Compute the second derivative of the value wrt x.
void update_quantities(const double t, const Eigen::VectorXd &x) override
Update time dependent quantities.
double value_unweighted(const Eigen::VectorXd &x) const override
Compute the value of the body force form.
const assembler::PressureAssembler & pressure_assembler_
Reference to the pressure assembler.
double force_pressure_derivative(const int n_verts, const double t, const int pressure_boundary_id, const Eigen::MatrixXd &x, const Eigen::MatrixXd &adjoint)
Compute the derivative of the force wrt vertex positions, then multiply the resulting matrix with adj...
const std::vector< mesh::LocalBoundary > & local_pressure_boundary_
PressureForm(const int ndof, const std::vector< mesh::LocalBoundary > &local_pressure_boundary, const std::unordered_map< int, std::vector< mesh::LocalBoundary > > &local_pressure_cavity, const std::vector< int > &dirichlet_nodes, const int n_boundary_samples, const assembler::PressureAssembler &pressure_assembler, const bool is_time_dependent)
Construct a new Body Form object.
const std::vector< int > & dirichlet_nodes_
void force_shape_derivative(const int n_verts, const double t, const Eigen::MatrixXd &x, const Eigen::MatrixXd &adjoint, Eigen::VectorXd &term)
Compute the derivative of the force wrt vertex positions, then multiply the resulting matrix with adj...
void first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override
Compute the first derivative of the value wrt x.
const std::unordered_map< int, std::vector< mesh::LocalBoundary > > & local_pressure_cavity_
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:22