Loading [MathJax]/extensions/tex2jax.js
PolyFEM
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
polyfem::solver::ContactForm Class Referenceabstract

Form representing the contact potential and forces. More...

#include <ContactForm.hpp>

Inheritance diagram for polyfem::solver::ContactForm:
[legend]
Collaboration diagram for polyfem::solver::ContactForm:
[legend]

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_
 

Detailed Description

Form representing the contact potential and forces.

Definition at line 34 of file ContactForm.hpp.

Constructor & Destructor Documentation

◆ ContactForm()

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.

Parameters
collision_meshReference to the collision mesh
dhatBarrier activation distance
avg_massAverage mass of the mesh
use_adaptive_barrier_stiffnessIf true, use an adaptive barrier stiffness
is_time_dependentIs the simulation time dependent?
broad_phase_methodBroad phase method to use for distance and CCD evaluations
ccd_toleranceContinuous collision detection tolerance
ccd_max_iterationsContinuous collision detection maximum iterations

Definition at line 20 of file ContactForm.cpp.

References dhat_, and prev_distance_.

◆ ~ContactForm()

virtual polyfem::solver::ContactForm::~ContactForm ( )
virtualdefault

Member Function Documentation

◆ barrier_stiffness()

double polyfem::solver::ContactForm::barrier_stiffness ( ) const
inline

◆ barrier_support_size()

virtual double polyfem::solver::ContactForm::barrier_support_size ( ) const
inlineprotectedvirtual

Reimplemented in polyfem::solver::SmoothContactForm.

Definition at line 123 of file ContactForm.hpp.

References dhat_.

Referenced by line_search_begin().

Here is the caller graph for this function:

◆ compute_displaced_surface()

Eigen::MatrixXd polyfem::solver::ContactForm::compute_displaced_surface ( const Eigen::VectorXd &  x) const

◆ dhat()

double polyfem::solver::ContactForm::dhat ( ) const
inline

Definition at line 114 of file ContactForm.hpp.

References dhat_.

Referenced by polyfem::solver::BarrierContactForm::post_step(), and polyfem::solver::SmoothContactForm::post_step().

Here is the caller graph for this function:

◆ enable_shape_derivatives()

bool polyfem::solver::ContactForm::enable_shape_derivatives ( ) const
inline

Definition at line 107 of file ContactForm.hpp.

References enable_shape_derivatives_.

Referenced by polyfem::solver::BarrierContactForm::BarrierContactForm().

Here is the caller graph for this function:

◆ get_broad_phase()

std::shared_ptr< ipc::BroadPhase > polyfem::solver::ContactForm::get_broad_phase ( ) const
inline

Definition at line 116 of file ContactForm.hpp.

References broad_phase_.

◆ init()

void polyfem::solver::ContactForm::init ( const Eigen::VectorXd &  x)
overridevirtual

Initialize the form.

Parameters
xCurrent 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_step_collision_free()

bool polyfem::solver::ContactForm::is_step_collision_free ( const Eigen::VectorXd &  x0,
const Eigen::VectorXd &  x1 
) const
overridevirtual

Checks if the step is collision free.

Returns
True if the step is collision free else false

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ line_search_begin()

void polyfem::solver::ContactForm::line_search_begin ( const Eigen::VectorXd &  x0,
const Eigen::VectorXd &  x1 
)
overridevirtual

Initialize variables used during the line search.

Parameters
x0Current solution
x1Next 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ line_search_end()

void polyfem::solver::ContactForm::line_search_end ( )
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_.

◆ max_step_size()

double polyfem::solver::ContactForm::max_step_size ( const Eigen::VectorXd &  x0,
const Eigen::VectorXd &  x1 
) const
overridevirtual

Determine the maximum step size allowable between the current and next solution.

Parameters
x0Current solution (step size = 0)
x1Next solution (step size = 1)
Returns
Maximum allowable step size

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

virtual std::string polyfem::solver::ContactForm::name ( ) const
inlineoverridevirtual

◆ set_barrier_stiffness()

void polyfem::solver::ContactForm::set_barrier_stiffness ( const double  barrier_stiffness)
inline

Get the current barrier stiffness.

Definition at line 101 of file ContactForm.hpp.

References barrier_stiffness(), and barrier_stiffness_.

Here is the call graph for this function:

◆ solution_changed()

void polyfem::solver::ContactForm::solution_changed ( const Eigen::VectorXd &  new_x)
overridevirtual

Update cached fields upon a change in the solution.

Parameters
new_xNew 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_barrier_stiffness()

virtual void polyfem::solver::ContactForm::update_barrier_stiffness ( const Eigen::VectorXd &  x,
const Eigen::MatrixXd &  grad_energy 
)
pure virtual

Update the barrier stiffness based on the current elasticity energy.

Parameters
xCurrent solution

Implemented in polyfem::solver::BarrierContactForm, polyfem::solver::PeriodicContactForm, and polyfem::solver::SmoothContactForm.

◆ update_collision_set()

virtual void polyfem::solver::ContactForm::update_collision_set ( const Eigen::MatrixXd &  displaced_surface)
protectedpure virtual

Update the cached candidate set for the current solution.

Parameters
displaced_surfaceVertex positions displaced by the current solution

Implemented in polyfem::solver::BarrierContactForm, and polyfem::solver::SmoothContactForm.

Referenced by init(), solution_changed(), and update_quantities().

Here is the caller graph for this function:

◆ update_quantities()

void polyfem::solver::ContactForm::update_quantities ( const double  t,
const Eigen::VectorXd &  x 
)
overridevirtual

Update time-dependent fields.

Parameters
tCurrent time
xCurrent 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ use_adaptive_barrier_stiffness()

bool polyfem::solver::ContactForm::use_adaptive_barrier_stiffness ( ) const
inline

Get use_adaptive_barrier_stiffness.

Definition at line 103 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().

Here is the caller graph for this function:

◆ use_convergent_formulation()

virtual bool polyfem::solver::ContactForm::use_convergent_formulation ( ) const
inlinevirtual

Get use_convergent_formulation.

Reimplemented in polyfem::solver::BarrierContactForm.

Definition at line 105 of file ContactForm.hpp.

◆ weight()

double polyfem::solver::ContactForm::weight ( ) const
inlineoverridevirtual

Get the form's multiplicative constant weight.

Reimplemented from polyfem::solver::Form.

Definition at line 109 of file ContactForm.hpp.

References barrier_stiffness_, and polyfem::solver::Form::weight_.

Referenced by polyfem::solver::PeriodicContactForm::force_periodic_shape_derivative().

Here is the caller graph for this function:

Member Data Documentation

◆ avg_mass_

const double polyfem::solver::ContactForm::avg_mass_
protected

Average mass of the mesh (used for adaptive barrier stiffness)

Definition at line 142 of file ContactForm.hpp.

Referenced by polyfem::solver::BarrierContactForm::update_barrier_stiffness().

◆ barrier_stiffness_

◆ broad_phase_

◆ broad_phase_method_

const ipc::BroadPhaseMethod polyfem::solver::ContactForm::broad_phase_method_
protected

Broad phase method to use for distance and CCD evaluations.

Definition at line 151 of file ContactForm.hpp.

Referenced by max_step_size().

◆ candidates_

ipc::Candidates polyfem::solver::ContactForm::candidates_
protected

◆ collision_mesh_

◆ dhat_

◆ dmin_

const double polyfem::solver::ContactForm::dmin_ = 0
protected

◆ enable_shape_derivatives_

const bool polyfem::solver::ContactForm::enable_shape_derivatives_
protected

Enable shape derivatives computation.

Definition at line 148 of file ContactForm.hpp.

Referenced by enable_shape_derivatives().

◆ is_time_dependent_

const bool polyfem::solver::ContactForm::is_time_dependent_
protected

Is the simulation time dependent?

Definition at line 145 of file ContactForm.hpp.

Referenced by polyfem::solver::BarrierContactForm::post_step(), and polyfem::solver::SmoothContactForm::post_step().

◆ max_barrier_stiffness_

double polyfem::solver::ContactForm::max_barrier_stiffness_
protected

Maximum barrier stiffness to use when using adaptive barrier stiffness.

Definition at line 139 of file ContactForm.hpp.

Referenced by polyfem::solver::BarrierContactForm::post_step(), polyfem::solver::SmoothContactForm::post_step(), and polyfem::solver::BarrierContactForm::update_barrier_stiffness().

◆ prev_distance_

double polyfem::solver::ContactForm::prev_distance_
protected

Previous minimum distance between all elements.

Definition at line 157 of file ContactForm.hpp.

Referenced by ContactForm(), polyfem::solver::BarrierContactForm::post_step(), and polyfem::solver::SmoothContactForm::post_step().

◆ save_ccd_debug_meshes

bool polyfem::solver::ContactForm::save_ccd_debug_meshes = false

If true, output debug files.

Definition at line 112 of file ContactForm.hpp.

Referenced by max_step_size().

◆ tight_inclusion_ccd_

const ipc::TightInclusionCCD polyfem::solver::ContactForm::tight_inclusion_ccd_
protected

Continuous collision detection specification object.

Definition at line 154 of file ContactForm.hpp.

Referenced by is_step_collision_free(), and max_step_size().

◆ use_adaptive_barrier_stiffness_

const bool polyfem::solver::ContactForm::use_adaptive_barrier_stiffness_
protected

If true, use an adaptive barrier stiffness.

Definition at line 135 of file ContactForm.hpp.

Referenced by polyfem::solver::BarrierContactForm::post_step(), polyfem::solver::SmoothContactForm::post_step(), and use_adaptive_barrier_stiffness().

◆ use_cached_candidates_

bool polyfem::solver::ContactForm::use_cached_candidates_ = false
protected

The documentation for this class was generated from the following files: