Barrier

Barrier functions and functionals.

Types

Name

Description

ipc::Barrier

Base class for barrier functions.

ipc::ClampedLogBarrier

Smoothly clamped log barrier functions from [Li et al.].

ipc::ClampedLogSqBarrier

Clamped log barrier with a quadratic log term from [Huang et al.].

ipc::CubicBarrier

Cubic barrier function from [Ando 2024].

ipc::NormalizedBarrier

Normalized barrier function from [Li et al.].

ipc::TwoStageBarrier

Two-stage barrier function from [Chen et al. 2025].

ipc::InversePowerBarrier

Inverse-power barrier \(h(d,\hat{d})/d^p\) with a C² cubic B-spline window.

ipc::NearFarBarrier

Splits a base barrier into near and far parts (used by the ESP potential).

Functions

Name

Description

ipc::barrier()

Evaluate the barrier function.

ipc::barrier_first_derivative()

Derivative of the barrier function.

ipc::barrier_second_derivative()

Second derivative of the barrier function.

ipc::barrier_force_magnitude()

Compute the barrier force magnitude.

ipc::barrier_force_magnitude_gradient()

Compute the gradient of the barrier force magnitude.

ipc::initial_barrier_stiffness()

Compute the initial barrier stiffness.

ipc::update_barrier_stiffness()

Update the barrier stiffness based on the current state.

ipc::semi_implicit_stiffness()

Compute the semi-implicit stiffness for all collisions.

Function Details

template <typename T> T ipc::barrier(const T d, const T dhat);

Function that grows to infinity as d approaches 0 from the right.

\[ b(d) = -(d-\hat{d})^2\ln\left(\frac{d}{\hat{d}}\right) \]

Parameters:
const T d

The distance.

const T dhat

Activation distance of the barrier.

Returns:

The value of the barrier function at d.

template <typename T>
T ipc::barrier_first_derivative(const T d, const T dhat);

Derivative of the barrier function.

\[ b'(d) = (\hat{d}-d) \left( 2\ln\left( \frac{d}{\hat{d}} \right) - \frac{\hat{d}}{d} + 1\right) \]

Parameters:
const T d

The distance.

const T dhat

Activation distance of the barrier.

Returns:

The derivative of the barrier wrt d.

template <typename T>
T ipc::barrier_second_derivative(const T d, const T dhat);

Second derivative of the barrier function.

\[ b''(d) = \left( \frac{\hat{d}}{d} + 2 \right) \frac{\hat{d}}{d} - 2\ln\left( \frac{d}{\hat{d}} \right) - 3 \]

Parameters:
const T d

The distance.

const T dhat

Activation distance of the barrier.

Returns:

The second derivative of the barrier wrt d.

Barrier Force Magnitude

double ipc::barrier_force_magnitude(const double distance_squared,
    
const Barrier& barrier, const double dhat,
    
const double barrier_stiffness, const double dmin = 0);

Compute the magnitude of the force due to a barrier.

Parameters:
const double distance_squared

The squared distance between elements.

const Barrier &barrier

The barrier function.

const double dhat

The activation distance of the barrier.

const double barrier_stiffness

The stiffness of the barrier.

const double dmin = 0

The minimum distance offset to the barrier.

Returns:

The magnitude of the force.

VectorMax12d ipc::barrier_force_magnitude_gradient(
    
const double distance_squared,
    
Eigen::ConstRef<VectorMax12d> distance_squared_gradient,
    
const Barrier& barrier, const double dhat,
    
const double barrier_stiffness, const double dmin = 0);

Compute the gradient of the magnitude of the force due to a barrier.

Parameters:
const double distance_squared

The squared distance between elements.

Eigen::ConstRef<VectorMax12d> distance_squared_gradient

The gradient of the squared distance.

const Barrier &barrier

The barrier function.

const double dhat

The activation distance of the barrier.

const double barrier_stiffness

The stiffness of the barrier.

const double dmin = 0

The minimum distance offset to the barrier.

Returns:

The gradient of the force.

Adaptive Barrier Stiffness

double ipc::initial_barrier_stiffness(const double bbox_diagonal,
    
const Barrier& barrier, const double dhat,
    
const double average_mass,
    
Eigen::ConstRef<Eigen::VectorXd> grad_energy,
    
Eigen::ConstRef<Eigen::VectorXd> grad_barrier,
    
double& max_barrier_stiffness,
    
const double min_barrier_stiffness_scale = 1e11,
    
const double dmin = 0);

Compute an inital barrier stiffness using the barrier potential gradient.

Note

This heuristic was designed for unweighted collisions. With area weighting and a physical barrier, the stiffness is a material parameter in the same units as Young’s modulus, so choosing it directly relative to the elastic stiffness is usually more appropriate than adapting it. If you still use this function with weighted collisions, pass average_mass / mean(weight) as average_mass so the adaptive range accounts for the weights.

Parameters:
const double bbox_diagonal

[in] Length of the diagonal of the bounding box of the scene.

const Barrier &barrier

[in] Barrier function.

const double dhat

[in] Activation distance of the barrier.

const double average_mass

[in] Average mass of all bodies.

Eigen::ConstRef<Eigen::VectorXd> grad_energy

[in] Gradient of the elasticity energy function.

Eigen::ConstRef<Eigen::VectorXd> grad_barrier

[in] Gradient of the barrier potential.

double &max_barrier_stiffness

[out] Maximum stiffness of the barrier.

const double min_barrier_stiffness_scale = 1e11

[in] Scale used to premultiply the minimum barrier stiffness.

const double dmin = 0

[in] Minimum distance between elements.

Returns:

The initial barrier stiffness.

double ipc::update_barrier_stiffness(const double prev_min_distance,
    
const double min_distance, const double max_barrier_stiffness,
    
const double barrier_stiffness, const double bbox_diagonal,
    
const double dhat_epsilon_scale = 1e-9, const double dmin = 0);

Update the barrier stiffness if the distance is decreasing and less than dhat_epsilon_scale * diag.

Parameters:
const double prev_min_distance

[in] Previous minimum distance between elements.

const double min_distance

[in] Current minimum distance between elements.

const double max_barrier_stiffness

[in] Maximum stiffness of the barrier.

const double barrier_stiffness

[in] Current barrier stiffness.

const double bbox_diagonal

[in] Length of the diagonal of the bounding box of the scene.

const double dhat_epsilon_scale = 1e-9

[in] Update if distance is less than this fraction of the diagonal.

const double dmin = 0

[in] Minimum distance between elements.

Returns:

The updated barrier stiffness.

Semi-Implicit Stiffness

template <typename StencilsT>
Eigen::VectorXd ipc::semi_implicit_stiffness(
    
const CollisionMesh& mesh,
    
Eigen::ConstRef<Eigen::MatrixXd> vertices,
    
const StencilsT& collisions,
    
Eigen::ConstRef<Eigen::VectorXd> vertex_masses,
    
const Eigen::SparseMatrix<double>& hess, const double dmin);

Compute the semi-implicit stiffness’s for all collisions.

Note

See [Ando 2024] for details.

Parameters:
const CollisionMesh &mesh

Collision mesh.

Eigen::ConstRef<Eigen::MatrixXd> vertices

Vertex positions.

const StencilsT &collisions

Normal collisions or collision candidates.

Eigen::ConstRef<Eigen::VectorXd> vertex_masses

Lumped vertex masses.

const Eigen::SparseMatrix<double> &hess

Hessian of the elasticity energy function.

const double dmin

Minimum distance between elements.

Returns:

The semi-implicit stiffness’s.