|
PolyFEM
|
Form representing the contact potential and forces. More...
#include <ContactForm.hpp>
Public Member Functions | |
| ContactForm (const ipc::CollisionMesh &collision_mesh, const double dhat, const double avg_mass, const bool use_adaptive_barrier_stiffness, const bool is_time_dependent, const bool enable_shape_derivatives, const ipc::BroadPhaseMethod broad_phase_method, const double ccd_tolerance, const int ccd_max_iterations) | |
| Construct a new Contact Form object. | |
| virtual | ~ContactForm ()=default |
| virtual std::string | name () const override |
| virtual void | init (const Eigen::VectorXd &x) override |
| Initialize the form. | |
| virtual void | update_quantities (const double t, const Eigen::VectorXd &x) override |
| Update time-dependent fields. | |
| virtual double | max_step_size (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const override |
| Determine the maximum step size allowable between the current and next solution. | |
| virtual void | line_search_begin (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) override |
| Initialize variables used during the line search. | |
| void | line_search_end () override |
| Clear variables used during the line search. | |
| virtual void | solution_changed (const Eigen::VectorXd &new_x) override |
| Update cached fields upon a change in the solution. | |
| virtual bool | is_step_collision_free (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const override |
| Checks if the step is collision free. | |
| virtual void | update_barrier_stiffness (const Eigen::VectorXd &x, const Eigen::MatrixXd &grad_energy)=0 |
| Update the barrier stiffness based on the current elasticity energy. | |
| Eigen::MatrixXd | compute_displaced_surface (const Eigen::VectorXd &x) const |
| Compute the displaced positions of the surface nodes. | |
| double | barrier_stiffness () const |
| Get the current barrier stiffness. | |
| void | set_barrier_stiffness (const double barrier_stiffness) |
| Get the current barrier stiffness. | |
| bool | use_adaptive_barrier_stiffness () const |
| Get use_adaptive_barrier_stiffness. | |
| virtual bool | use_convergent_formulation () const |
| Get use_convergent_formulation. | |
| bool | enable_shape_derivatives () const |
| double | weight () const override |
| Get the form's multiplicative constant weight. | |
| double | dhat () const |
| std::shared_ptr< ipc::BroadPhase > | get_broad_phase () const |
Public Member Functions inherited from polyfem::solver::Form | |
| virtual | ~Form () |
| virtual void | finish () |
| virtual double | value (const Eigen::VectorXd &x) const |
| Compute the value of the form multiplied with the weigth. | |
| Eigen::VectorXd | value_per_element (const Eigen::VectorXd &x) const |
| Compute the value of the form multiplied with the weigth. | |
| virtual void | first_derivative (const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const |
| Compute the first derivative of the value wrt x multiplied with the weigth. | |
| void | second_derivative (const Eigen::VectorXd &x, StiffnessMatrix &hessian) const |
| Compute the second derivative of the value wrt x multiplied with the weigth. | |
| virtual bool | is_step_valid (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const |
| Determine if a step from solution x0 to solution x1 is allowed. | |
| virtual void | post_step (const polysolve::nonlinear::PostStepData &data) |
| Update fields after a step in the optimization. | |
| virtual void | init_lagging (const Eigen::VectorXd &x) |
| Initialize lagged fields TODO: more than one step. | |
| virtual void | update_lagging (const Eigen::VectorXd &x, const int iter_num) |
| Update lagged fields. | |
| virtual int | max_lagging_iterations () const |
| Get the maximum number of lagging iteration allowable. | |
| virtual bool | uses_lagging () const |
| Does this form require lagging? | |
| void | set_project_to_psd (bool val) |
| Set project to psd. | |
| bool | is_project_to_psd () const |
| Get if the form's second derivative is projected to psd. | |
| void | enable () |
| Enable the form. | |
| void | disable () |
| Disable the form. | |
| void | set_enabled (const bool enabled) |
| Set if the form is enabled. | |
| bool | enabled () const |
| Determine if the form is enabled. | |
| void | set_weight (const double weight) |
| Set the form's multiplicative constant weight. | |
| void | set_output_dir (const std::string &output_dir) |
| virtual void | set_scale (const double scale) |
| sets the scale for the form | |
Public Attributes | |
| bool | save_ccd_debug_meshes = false |
| If true, output debug files. | |
Protected Member Functions | |
| virtual void | update_collision_set (const Eigen::MatrixXd &displaced_surface)=0 |
| Update the cached candidate set for the current solution. | |
| virtual double | barrier_support_size () const |
Protected Member Functions inherited from polyfem::solver::Form | |
| std::string | resolve_output_path (const std::string &path) const |
| virtual double | value_unweighted (const Eigen::VectorXd &x) const =0 |
| Compute the value of the form. | |
| virtual Eigen::VectorXd | value_per_element_unweighted (const Eigen::VectorXd &x) const |
| Compute the value of the form multiplied per element. | |
| virtual void | first_derivative_unweighted (const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const =0 |
| Compute the first derivative of the value wrt x. | |
| virtual void | second_derivative_unweighted (const Eigen::VectorXd &x, StiffnessMatrix &hessian) const =0 |
| Compute the second derivative of the value wrt x. | |
Protected Attributes | |
| const ipc::CollisionMesh & | collision_mesh_ |
| Collision mesh. | |
| const double | dhat_ |
| Barrier activation distance. | |
| const double | dmin_ = 0 |
| Minimum distance between elements. | |
| const bool | use_adaptive_barrier_stiffness_ |
| If true, use an adaptive barrier stiffness. | |
| double | barrier_stiffness_ |
| Barrier stiffness. | |
| double | max_barrier_stiffness_ |
| Maximum barrier stiffness to use when using adaptive barrier stiffness. | |
| const double | avg_mass_ |
| Average mass of the mesh (used for adaptive barrier stiffness) | |
| const bool | is_time_dependent_ |
| Is the simulation time dependent? | |
| const bool | enable_shape_derivatives_ |
| Enable shape derivatives computation. | |
| const ipc::BroadPhaseMethod | broad_phase_method_ |
| Broad phase method to use for distance and CCD evaluations. | |
| const std::shared_ptr< ipc::BroadPhase > | broad_phase_ |
| const ipc::TightInclusionCCD | tight_inclusion_ccd_ |
| Continuous collision detection specification object. | |
| double | prev_distance_ |
| Previous minimum distance between all elements. | |
| bool | use_cached_candidates_ = false |
| If true, use the cached candidate set for the current solution. | |
| ipc::Candidates | candidates_ |
| Cached candidate set for the current solution. | |
Protected Attributes inherited from polyfem::solver::Form | |
| bool | project_to_psd_ = false |
| If true, the form's second derivative is projected to be positive semidefinite. | |
| double | weight_ = 1 |
| weight of the form (e.g., AL penalty weight or Δt²) | |
| bool | enabled_ = true |
| If true, the form is enabled. | |
| std::string | output_dir_ |
Form representing the contact potential and forces.
Definition at line 35 of file ContactForm.hpp.
| polyfem::solver::ContactForm::ContactForm | ( | const ipc::CollisionMesh & | collision_mesh, |
| const double | dhat, | ||
| const double | avg_mass, | ||
| const bool | use_adaptive_barrier_stiffness, | ||
| const bool | is_time_dependent, | ||
| const bool | enable_shape_derivatives, | ||
| const ipc::BroadPhaseMethod | broad_phase_method, | ||
| const double | ccd_tolerance, | ||
| const int | ccd_max_iterations | ||
| ) |
Construct a new Contact Form object.
| collision_mesh | Reference to the collision mesh |
| dhat | Barrier activation distance |
| avg_mass | Average mass of the mesh |
| use_adaptive_barrier_stiffness | If true, use an adaptive barrier stiffness |
| is_time_dependent | Is the simulation time dependent? |
| broad_phase_method | Broad phase method to use for distance and CCD evaluations |
| ccd_tolerance | Continuous collision detection tolerance |
| ccd_max_iterations | Continuous collision detection maximum iterations |
Definition at line 20 of file ContactForm.cpp.
References dhat_, and prev_distance_.
|
virtualdefault |
|
inline |
Get the current barrier stiffness.
Definition at line 100 of file ContactForm.hpp.
References barrier_stiffness_.
Referenced by polyfem::solver::BarrierContactForm::force_shape_derivative(), polyfem::solver::SmoothContactForm::force_shape_derivative(), polyfem::solver::BarrierContactForm::post_step(), polyfem::solver::SmoothContactForm::post_step(), set_barrier_stiffness(), polyfem::solver::BarrierContactForm::update_barrier_stiffness(), and polyfem::solver::FrictionForm::update_lagging().
|
inlineprotectedvirtual |
Reimplemented in polyfem::solver::SmoothContactForm.
Definition at line 124 of file ContactForm.hpp.
References dhat_.
Referenced by line_search_begin().
| Eigen::MatrixXd polyfem::solver::ContactForm::compute_displaced_surface | ( | const Eigen::VectorXd & | x | ) | const |
Compute the displaced positions of the surface nodes.
Definition at line 55 of file ContactForm.cpp.
References collision_mesh_, polyfem::utils::unflatten(), and x.
Referenced by polyfem::solver::FrictionForm::compute_displaced_surface(), polyfem::solver::BarrierContactForm::first_derivative_unweighted(), polyfem::solver::SmoothContactForm::first_derivative_unweighted(), polyfem::solver::PeriodicContactForm::force_periodic_shape_derivative(), polyfem::solver::BarrierContactForm::force_shape_derivative(), polyfem::solver::SmoothContactForm::force_shape_derivative(), init(), is_step_collision_free(), line_search_begin(), max_step_size(), polyfem::solver::BarrierContactForm::post_step(), polyfem::solver::SmoothContactForm::post_step(), polyfem::solver::BarrierContactForm::second_derivative_unweighted(), polyfem::solver::SmoothContactForm::second_derivative_unweighted(), solution_changed(), polyfem::solver::BarrierContactForm::update_barrier_stiffness(), update_quantities(), polyfem::solver::BarrierContactForm::value_per_element_unweighted(), polyfem::solver::BarrierContactForm::value_unweighted(), and polyfem::solver::SmoothContactForm::value_unweighted().
|
inline |
Definition at line 115 of file ContactForm.hpp.
References dhat_.
Referenced by polyfem::solver::BarrierContactForm::post_step(), and polyfem::solver::SmoothContactForm::post_step().
|
inline |
Definition at line 108 of file ContactForm.hpp.
References enable_shape_derivatives_.
Referenced by polyfem::solver::BarrierContactForm::BarrierContactForm().
|
inline |
Definition at line 117 of file ContactForm.hpp.
References broad_phase_.
|
overridevirtual |
Initialize the form.
| x | Current solution |
Reimplemented from polyfem::solver::Form.
Reimplemented in polyfem::solver::PeriodicContactForm.
Definition at line 45 of file ContactForm.cpp.
References compute_displaced_surface(), update_collision_set(), and x.
Referenced by polyfem::solver::PeriodicContactForm::init().
|
overridevirtual |
Checks if the step is collision free.
Reimplemented from polyfem::solver::Form.
Reimplemented in polyfem::solver::PeriodicContactForm.
Definition at line 130 of file ContactForm.cpp.
References broad_phase_, candidates_, collision_mesh_, compute_displaced_surface(), dmin_, polyfem::utils::is_valid(), tight_inclusion_ccd_, and use_cached_candidates_.
Referenced by polyfem::solver::PeriodicContactForm::is_step_collision_free().
|
overridevirtual |
Initialize variables used during the line search.
| x0 | Current solution |
| x1 | Next solution |
Reimplemented from polyfem::solver::Form.
Reimplemented in polyfem::solver::PeriodicContactForm.
Definition at line 112 of file ContactForm.cpp.
References barrier_support_size(), broad_phase_, candidates_, collision_mesh_, compute_displaced_surface(), and use_cached_candidates_.
Referenced by polyfem::solver::PeriodicContactForm::line_search_begin().
|
overridevirtual |
Clear variables used during the line search.
Reimplemented from polyfem::solver::Form.
Definition at line 124 of file ContactForm.cpp.
References candidates_, and use_cached_candidates_.
|
overridevirtual |
Determine the maximum step size allowable between the current and next solution.
| x0 | Current solution (step size = 0) |
| x1 | Next solution (step size = 1) |
Reimplemented from polyfem::solver::Form.
Reimplemented in polyfem::solver::PeriodicContactForm.
Definition at line 65 of file ContactForm.cpp.
References broad_phase_, broad_phase_method_, candidates_, collision_mesh_, compute_displaced_surface(), dmin_, polyfem::F, polyfem::log_and_throw_error(), polyfem::logger(), polyfem::solver::Form::resolve_output_path(), save_ccd_debug_meshes, tight_inclusion_ccd_, use_cached_candidates_, polyfem::mesh::V0, and polyfem::mesh::V1.
Referenced by polyfem::solver::PeriodicContactForm::max_step_size().
|
inlineoverridevirtual |
Implements polyfem::solver::Form.
Reimplemented in polyfem::solver::BarrierContactForm, and polyfem::solver::SmoothContactForm.
Definition at line 58 of file ContactForm.hpp.
|
inline |
Get the current barrier stiffness.
Definition at line 102 of file ContactForm.hpp.
References barrier_stiffness(), and barrier_stiffness_.
|
overridevirtual |
Update cached fields upon a change in the solution.
| new_x | New solution |
Reimplemented from polyfem::solver::Form.
Reimplemented in polyfem::solver::PeriodicContactForm.
Definition at line 60 of file ContactForm.cpp.
References compute_displaced_surface(), and update_collision_set().
Referenced by polyfem::solver::PeriodicContactForm::solution_changed().
|
pure virtual |
Update the barrier stiffness based on the current elasticity energy.
| x | Current solution |
Implemented in polyfem::solver::BarrierContactForm, polyfem::solver::PeriodicContactForm, and polyfem::solver::SmoothContactForm.
|
protectedpure virtual |
Update the cached candidate set for the current solution.
| displaced_surface | Vertex positions displaced by the current solution |
Implemented in polyfem::solver::BarrierContactForm, and polyfem::solver::SmoothContactForm.
Referenced by init(), solution_changed(), and update_quantities().
|
overridevirtual |
Update time-dependent fields.
| t | Current time |
| x | Current solution at time t |
Reimplemented from polyfem::solver::Form.
Reimplemented in polyfem::solver::PeriodicContactForm.
Definition at line 50 of file ContactForm.cpp.
References compute_displaced_surface(), update_collision_set(), and x.
Referenced by polyfem::solver::PeriodicContactForm::update_quantities().
|
inline |
Get use_adaptive_barrier_stiffness.
Definition at line 104 of file ContactForm.hpp.
References use_adaptive_barrier_stiffness_.
Referenced by polyfem::solver::SmoothContactForm::SmoothContactForm(), polyfem::solver::BarrierContactForm::update_barrier_stiffness(), and polyfem::solver::SmoothContactForm::update_barrier_stiffness().
|
inlinevirtual |
Get use_convergent_formulation.
Reimplemented in polyfem::solver::BarrierContactForm.
Definition at line 106 of file ContactForm.hpp.
|
inlineoverridevirtual |
Get the form's multiplicative constant weight.
Reimplemented from polyfem::solver::Form.
Definition at line 110 of file ContactForm.hpp.
References barrier_stiffness_, and polyfem::solver::Form::weight_.
Referenced by polyfem::solver::PeriodicContactForm::force_periodic_shape_derivative().
|
protected |
Average mass of the mesh (used for adaptive barrier stiffness)
Definition at line 143 of file ContactForm.hpp.
Referenced by polyfem::solver::BarrierContactForm::update_barrier_stiffness().
|
protected |
Barrier stiffness.
Definition at line 138 of file ContactForm.hpp.
Referenced by barrier_stiffness(), polyfem::solver::BarrierContactForm::post_step(), polyfem::solver::SmoothContactForm::post_step(), set_barrier_stiffness(), polyfem::solver::BarrierContactForm::update_barrier_stiffness(), and weight().
|
protected |
Definition at line 153 of file ContactForm.hpp.
Referenced by get_broad_phase(), is_step_collision_free(), line_search_begin(), max_step_size(), polyfem::solver::SmoothContactForm::SmoothContactForm(), polyfem::solver::BarrierContactForm::update_barrier_stiffness(), polyfem::solver::BarrierContactForm::update_collision_set(), and polyfem::solver::SmoothContactForm::update_collision_set().
|
protected |
Broad phase method to use for distance and CCD evaluations.
Definition at line 152 of file ContactForm.hpp.
Referenced by max_step_size().
|
protected |
Cached candidate set for the current solution.
Definition at line 163 of file ContactForm.hpp.
Referenced by is_step_collision_free(), line_search_begin(), line_search_end(), max_step_size(), polyfem::solver::BarrierContactForm::update_collision_set(), and polyfem::solver::SmoothContactForm::update_collision_set().
|
protected |
Collision mesh.
Definition at line 127 of file ContactForm.hpp.
Referenced by compute_displaced_surface(), polyfem::solver::BarrierContactForm::first_derivative_unweighted(), polyfem::solver::SmoothContactForm::first_derivative_unweighted(), polyfem::solver::PeriodicContactForm::force_periodic_shape_derivative(), polyfem::solver::BarrierContactForm::force_shape_derivative(), polyfem::solver::SmoothContactForm::force_shape_derivative(), is_step_collision_free(), line_search_begin(), max_step_size(), polyfem::solver::PeriodicContactForm::PeriodicContactForm(), polyfem::solver::BarrierContactForm::post_step(), polyfem::solver::SmoothContactForm::post_step(), polyfem::solver::BarrierContactForm::second_derivative_unweighted(), polyfem::solver::SmoothContactForm::second_derivative_unweighted(), polyfem::solver::PeriodicContactForm::single_to_tiled(), polyfem::solver::PeriodicContactForm::tiled_to_single_grad(), polyfem::solver::BarrierContactForm::update_barrier_stiffness(), polyfem::solver::BarrierContactForm::update_collision_set(), polyfem::solver::SmoothContactForm::update_collision_set(), polyfem::solver::PeriodicContactForm::update_projection(), polyfem::solver::BarrierContactForm::value_per_element_unweighted(), polyfem::solver::BarrierContactForm::value_unweighted(), and polyfem::solver::SmoothContactForm::value_unweighted().
|
protected |
Barrier activation distance.
Definition at line 130 of file ContactForm.hpp.
Referenced by barrier_support_size(), polyfem::solver::SmoothContactForm::barrier_support_size(), ContactForm(), dhat(), polyfem::solver::BarrierContactForm::update_barrier_stiffness(), and polyfem::solver::BarrierContactForm::update_collision_set().
|
protected |
Minimum distance between elements.
Definition at line 133 of file ContactForm.hpp.
Referenced by is_step_collision_free(), max_step_size(), polyfem::solver::BarrierContactForm::update_barrier_stiffness(), and polyfem::solver::BarrierContactForm::update_collision_set().
|
protected |
Enable shape derivatives computation.
Definition at line 149 of file ContactForm.hpp.
Referenced by enable_shape_derivatives().
|
protected |
Is the simulation time dependent?
Definition at line 146 of file ContactForm.hpp.
Referenced by polyfem::solver::BarrierContactForm::post_step(), and polyfem::solver::SmoothContactForm::post_step().
|
protected |
Maximum barrier stiffness to use when using adaptive barrier stiffness.
Definition at line 140 of file ContactForm.hpp.
Referenced by polyfem::solver::BarrierContactForm::post_step(), polyfem::solver::SmoothContactForm::post_step(), and polyfem::solver::BarrierContactForm::update_barrier_stiffness().
|
protected |
Previous minimum distance between all elements.
Definition at line 158 of file ContactForm.hpp.
Referenced by ContactForm(), polyfem::solver::BarrierContactForm::post_step(), and polyfem::solver::SmoothContactForm::post_step().
| bool polyfem::solver::ContactForm::save_ccd_debug_meshes = false |
If true, output debug files.
Definition at line 113 of file ContactForm.hpp.
Referenced by max_step_size().
|
protected |
Continuous collision detection specification object.
Definition at line 155 of file ContactForm.hpp.
Referenced by is_step_collision_free(), and max_step_size().
|
protected |
If true, use an adaptive barrier stiffness.
Definition at line 136 of file ContactForm.hpp.
Referenced by polyfem::solver::BarrierContactForm::post_step(), polyfem::solver::SmoothContactForm::post_step(), and use_adaptive_barrier_stiffness().
|
protected |
If true, use the cached candidate set for the current solution.
Definition at line 161 of file ContactForm.hpp.
Referenced by is_step_collision_free(), line_search_begin(), line_search_end(), max_step_size(), polyfem::solver::BarrierContactForm::update_collision_set(), and polyfem::solver::SmoothContactForm::update_collision_set().