PolyFEM
Loading...
Searching...
No Matches
ESPContactForm.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "ContactForm.hpp"
4#include <ipc/esp/esp_collisions.hpp>
5#include <ipc/esp/esp_potential.hpp>
6#include <cmath>
7
8namespace polyfem::solver
9{
10
12 {
13 public:
14 ESPContactForm(const ipc::CollisionMesh &collision_mesh,
15 const double dhat,
16 const double avg_mass,
17 const json esp_params,
18 const bool skip_obstacles,
19 std::shared_ptr<ipc::Barrier> barrier,
20 const bool use_adaptive_dhat,
22 const bool is_time_dependent,
23 const bool enable_shape_derivatives,
24 const ipc::BroadPhaseMethod broad_phase_method,
25 const double ccd_tolerance,
26 const int ccd_max_iterations,
27 const double dhat_epsilon_scale);
28
29 virtual std::string name() const override { return "ESP"; }
30
31 void update_barrier_stiffness(const Eigen::VectorXd &x, const Eigen::MatrixXd &grad_energy) override;
32
36 void post_step(const polysolve::nonlinear::PostStepData &data) override;
37
38 const ipc::ESPParameters &get_params() const { return params; }
39
40 const ipc::ESPCollisions &collision_set() const { return collision_set_; }
41
42 const ipc::ESPPotential &barrier_potential() const { return barrier_potential_; }
43
44 protected:
48 double value_unweighted(const Eigen::VectorXd &x) const override;
49
53 Eigen::VectorXd value_per_element_unweighted(const Eigen::VectorXd &x) const override;
54
58 void first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override;
59
63 void second_derivative_unweighted(const Eigen::VectorXd &x, StiffnessMatrix &hessian) const override;
64
65 double barrier_support_size() const override { return dhat_; }
66
67 void update_collision_set(const Eigen::MatrixXd &displaced_surface) override;
68
69 private:
70 ipc::ESPParameters params;
71
73 ipc::ESPCollisions collision_set_;
74
76 ipc::ESPPotential barrier_potential_;
77
78 Eigen::MatrixXd cached_displaced_surface;
79 };
80} // namespace polyfem::solver
int x
Form representing the contact potential and forces.
bool use_adaptive_barrier_stiffness() const
Get use_adaptive_barrier_stiffness.
const double dhat_
Barrier activation distance.
double dhat_epsilon_scale() const
Get the dhat_epsilon_scale passed to ipc::update_barrier_stiffness.
double value_unweighted(const Eigen::VectorXd &x) const override
Compute the contact barrier potential value.
void update_collision_set(const Eigen::MatrixXd &displaced_surface) override
Update the cached candidate set for the current solution.
void post_step(const polysolve::nonlinear::PostStepData &data) override
Update fields after a step in the optimization.
void update_barrier_stiffness(const Eigen::VectorXd &x, const Eigen::MatrixXd &grad_energy) override
Update the barrier stiffness based on the current elasticity energy.
ipc::ESPCollisions collision_set_
Cached constraint set for the current solution.
const ipc::ESPParameters & get_params() const
ipc::ESPPotential barrier_potential_
Contact potential.
const ipc::ESPCollisions & collision_set() const
virtual std::string name() const override
void first_derivative_unweighted(const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override
Compute the first derivative of the value wrt x.
double barrier_support_size() const override
const ipc::ESPPotential & barrier_potential() const
void second_derivative_unweighted(const Eigen::VectorXd &x, StiffnessMatrix &hessian) const override
Compute the second derivative of the value wrt x.
Eigen::VectorXd value_per_element_unweighted(const Eigen::VectorXd &x) const override
Compute the value of the form multiplied per element.
nlohmann::json json
Definition Common.hpp:9
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:24