PolyFEM
Loading...
Searching...
No Matches
polyfem::solver::PeriodicContactForm Class Reference

Form representing the contact potential and forces on a periodic mesh This form has a different input format of [fluctuation, affine], only can be used in NLHomoProblem. More...

#include <PeriodicContactForm.hpp>

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

Public Member Functions

 PeriodicContactForm (const ipc::CollisionMesh &periodic_collision_mesh, const Eigen::VectorXi &tiled_to_single, const double dhat, const double avg_mass, const bool use_convergent_formulation, 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.
 
void init (const Eigen::VectorXd &x) override
 Initialize the form.
 
void force_periodic_shape_derivative (const State &state, const PeriodicMeshToMesh &periodic_mesh_map, const Eigen::VectorXd &periodic_mesh_representation, const ipc::Collisions &contact_set, const Eigen::VectorXd &solution, const Eigen::VectorXd &adjoint_sol, Eigen::VectorXd &term)
 
Eigen::VectorXd single_to_tiled (const Eigen::VectorXd &x) const
 
Eigen::VectorXd tiled_to_single_grad (const Eigen::VectorXd &grad) const
 
void update_quantities (const double t, const Eigen::VectorXd &x) override
 Update time-dependent fields.
 
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.
 
void line_search_begin (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) override
 Initialize variables used during the line search.
 
void solution_changed (const Eigen::VectorXd &new_x) override
 Update cached fields upon a change in the solution.
 
void post_step (const polysolve::nonlinear::PostStepData &data) override
 Update fields after a step in the optimization.
 
bool is_step_collision_free (const Eigen::VectorXd &x0, const Eigen::VectorXd &x1) const override
 Checks if the step is collision free.
 
void update_barrier_stiffness (const Eigen::VectorXd &x, const Eigen::MatrixXd &grad_energy) override
 Update the barrier stiffness based on the current elasticity energy.
 
- Public Member Functions inherited from polyfem::solver::ContactForm
 ContactForm (const ipc::CollisionMesh &collision_mesh, const double dhat, const double avg_mass, const bool use_convergent_formulation, 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
 
std::string name () const override
 
virtual void force_shape_derivative (const ipc::Collisions &collision_set, const Eigen::MatrixXd &solution, const Eigen::VectorXd &adjoint_sol, Eigen::VectorXd &term)
 
void line_search_end () override
 Clear variables used during the line search.
 
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.
 
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
 
const ipc::Collisions & collision_set () const
 
const ipc::BarrierPotential & barrier_potential () const
 
- Public Member Functions inherited from polyfem::solver::Form
virtual ~Form ()
 
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 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.
 
virtual void set_apply_DBC (const Eigen::VectorXd &x, bool apply_DBC)
 Set if the Dirichlet boundary conditions should be enforced.
 
void set_output_dir (const std::string &output_dir)
 

Protected Member Functions

double value_unweighted (const Eigen::VectorXd &x) const override
 Compute the contact barrier potential value.
 
void first_derivative_unweighted (const Eigen::VectorXd &x, Eigen::VectorXd &gradv) const override
 Compute the first derivative of the value wrt x.
 
void second_derivative_unweighted (const Eigen::VectorXd &x, StiffnessMatrix &hessian) const override
 Compute the second derivative of the value wrt x.
 
- Protected Member Functions inherited from polyfem::solver::ContactForm
Eigen::VectorXd value_per_element_unweighted (const Eigen::VectorXd &x) const override
 Compute the value of the form multiplied per element.
 
void update_collision_set (const Eigen::MatrixXd &displaced_surface)
 Update the cached candidate set for the current solution.
 
- Protected Member Functions inherited from polyfem::solver::Form
std::string resolve_output_path (const std::string &path) const
 

Private Member Functions

void update_projection () const
 

Private Attributes

const Eigen::VectorXi tiled_to_single_
 
const int n_single_dof_
 
StiffnessMatrix proj
 

Additional Inherited Members

- Public Attributes inherited from polyfem::solver::ContactForm
bool save_ccd_debug_meshes = false
 If true, output debug files.
 
- Protected Attributes inherited from polyfem::solver::ContactForm
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 double ccd_tolerance_
 Continuous collision detection tolerance.
 
const int ccd_max_iterations_
 Continuous collision detection maximum iterations.
 
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::Collisions collision_set_
 Cached constraint set for the current solution.
 
ipc::Candidates candidates_
 Cached candidate set for the current solution.
 
const ipc::BarrierPotential barrier_potential_
 
- 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 on a periodic mesh This form has a different input format of [fluctuation, affine], only can be used in NLHomoProblem.

Definition at line 18 of file PeriodicContactForm.hpp.

Constructor & Destructor Documentation

◆ PeriodicContactForm()

polyfem::solver::PeriodicContactForm::PeriodicContactForm ( const ipc::CollisionMesh &  periodic_collision_mesh,
const Eigen::VectorXi &  tiled_to_single,
const double  dhat,
const double  avg_mass,
const bool  use_convergent_formulation,
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
periodic_collision_mesh3x3 tiling of a periodic mesh
tiled_to_singleIndex mapping from the tiled mesh to the original periodic mesh

Definition at line 12 of file PeriodicContactForm.cpp.

References polyfem::solver::ContactForm::collision_mesh_, tiled_to_single_, and update_projection().

Here is the call graph for this function:

Member Function Documentation

◆ first_derivative_unweighted()

void polyfem::solver::PeriodicContactForm::first_derivative_unweighted ( const Eigen::VectorXd &  x,
Eigen::VectorXd &  gradv 
) const
overrideprotectedvirtual

Compute the first derivative of the value wrt x.

Parameters
[in]xCurrent solution
[out]gradvOutput gradient of the value wrt x

Reimplemented from polyfem::solver::ContactForm.

Definition at line 111 of file PeriodicContactForm.cpp.

References polyfem::solver::ContactForm::first_derivative_unweighted(), single_to_tiled(), tiled_to_single_grad(), and x.

Here is the call graph for this function:

◆ force_periodic_shape_derivative()

void polyfem::solver::PeriodicContactForm::force_periodic_shape_derivative ( const State state,
const PeriodicMeshToMesh periodic_mesh_map,
const Eigen::VectorXd &  periodic_mesh_representation,
const ipc::Collisions &  contact_set,
const Eigen::VectorXd &  solution,
const Eigen::VectorXd &  adjoint_sol,
Eigen::VectorXd &  term 
)

◆ init()

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

Initialize the form.

Parameters
xCurrent solution

Reimplemented from polyfem::solver::ContactForm.

Definition at line 101 of file PeriodicContactForm.cpp.

References polyfem::solver::ContactForm::init(), single_to_tiled(), and x.

Here is the call graph for this function:

◆ is_step_collision_free()

bool polyfem::solver::PeriodicContactForm::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::ContactForm.

Definition at line 159 of file PeriodicContactForm.cpp.

References polyfem::solver::ContactForm::is_step_collision_free(), and single_to_tiled().

Here is the call graph for this function:

◆ line_search_begin()

void polyfem::solver::PeriodicContactForm::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::ContactForm.

Definition at line 142 of file PeriodicContactForm.cpp.

References polyfem::solver::ContactForm::line_search_begin(), and single_to_tiled().

Here is the call graph for this function:

◆ max_step_size()

double polyfem::solver::PeriodicContactForm::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::ContactForm.

Definition at line 137 of file PeriodicContactForm.cpp.

References polyfem::solver::ContactForm::max_step_size(), and single_to_tiled().

Here is the call graph for this function:

◆ post_step()

void polyfem::solver::PeriodicContactForm::post_step ( const polysolve::nonlinear::PostStepData &  data)
overridevirtual

Update fields after a step in the optimization.

Parameters
iter_numOptimization iteration number
xCurrent solution

Reimplemented from polyfem::solver::ContactForm.

Definition at line 152 of file PeriodicContactForm.cpp.

References polyfem::solver::ContactForm::post_step(), and single_to_tiled().

Here is the call graph for this function:

◆ second_derivative_unweighted()

void polyfem::solver::PeriodicContactForm::second_derivative_unweighted ( const Eigen::VectorXd &  x,
StiffnessMatrix hessian 
) const
overrideprotectedvirtual

Compute the second derivative of the value wrt x.

Parameters
xCurrent solution
hessianOutput Hessian of the value wrt x

Reimplemented from polyfem::solver::ContactForm.

Definition at line 117 of file PeriodicContactForm.cpp.

References proj, polyfem::solver::ContactForm::second_derivative_unweighted(), single_to_tiled(), update_projection(), and x.

Here is the call graph for this function:

◆ single_to_tiled()

Eigen::VectorXd polyfem::solver::PeriodicContactForm::single_to_tiled ( const Eigen::VectorXd &  x) const

Definition at line 58 of file PeriodicContactForm.cpp.

References polyfem::solver::ContactForm::collision_mesh_, n_single_dof_, tiled_to_single_, and x.

Referenced by first_derivative_unweighted(), force_periodic_shape_derivative(), init(), is_step_collision_free(), line_search_begin(), max_step_size(), post_step(), second_derivative_unweighted(), solution_changed(), update_barrier_stiffness(), update_quantities(), and value_unweighted().

Here is the caller graph for this function:

◆ solution_changed()

void polyfem::solver::PeriodicContactForm::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::ContactForm.

Definition at line 147 of file PeriodicContactForm.cpp.

References single_to_tiled(), and polyfem::solver::ContactForm::solution_changed().

Here is the call graph for this function:

◆ tiled_to_single_grad()

Eigen::VectorXd polyfem::solver::PeriodicContactForm::tiled_to_single_grad ( const Eigen::VectorXd &  grad) const

Definition at line 79 of file PeriodicContactForm.cpp.

References polyfem::solver::ContactForm::collision_mesh_, n_single_dof_, and tiled_to_single_.

Referenced by first_derivative_unweighted().

Here is the caller graph for this function:

◆ update_barrier_stiffness()

void polyfem::solver::PeriodicContactForm::update_barrier_stiffness ( const Eigen::VectorXd &  x,
const Eigen::MatrixXd &  grad_energy 
)
overridevirtual

Update the barrier stiffness based on the current elasticity energy.

Parameters
xCurrent solution

Reimplemented from polyfem::solver::ContactForm.

Definition at line 164 of file PeriodicContactForm.cpp.

References single_to_tiled(), polyfem::solver::ContactForm::update_barrier_stiffness(), and x.

Here is the call graph for this function:

◆ update_projection()

void polyfem::solver::PeriodicContactForm::update_projection ( ) const
private

Definition at line 36 of file PeriodicContactForm.cpp.

References polyfem::solver::ContactForm::collision_mesh_, entries, n_single_dof_, proj, and tiled_to_single_.

Referenced by PeriodicContactForm(), and second_derivative_unweighted().

Here is the caller graph for this function:

◆ update_quantities()

void polyfem::solver::PeriodicContactForm::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::ContactForm.

Definition at line 132 of file PeriodicContactForm.cpp.

References single_to_tiled(), polyfem::solver::ContactForm::update_quantities(), and x.

Here is the call graph for this function:

◆ value_unweighted()

double polyfem::solver::PeriodicContactForm::value_unweighted ( const Eigen::VectorXd &  x) const
overrideprotectedvirtual

Compute the contact barrier potential value.

Parameters
xCurrent solution
Returns
Value of the contact barrier potential

Reimplemented from polyfem::solver::ContactForm.

Definition at line 106 of file PeriodicContactForm.cpp.

References single_to_tiled(), polyfem::solver::ContactForm::value_unweighted(), and x.

Here is the call graph for this function:

Member Data Documentation

◆ n_single_dof_

const int polyfem::solver::PeriodicContactForm::n_single_dof_
private

◆ proj

StiffnessMatrix polyfem::solver::PeriodicContactForm::proj
mutableprivate

◆ tiled_to_single_

const Eigen::VectorXi polyfem::solver::PeriodicContactForm::tiled_to_single_
private

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