Potential

template <class TCollisionsclass Potential;

Base class for potentials.

Template Parameters:
class TCollisions

The type of the collisions.

Public Functions

Potential() = default;
virtual ~Potential() = default;
virtual std::string name() const = 0;

The name of this potential (used for profiling).

double operator()(const TCollisionscollisions,
    
const CollisionMeshmesh,
    
Eigen::ConstRef<Eigen::MatrixXd> X) const;

Compute the potential for a set of collisions.

Parameters:
const TCollisions &collisions

The set of collisions.

const CollisionMesh &mesh

The collision mesh.

Eigen::ConstRef<Eigen::MatrixXd> X

Degrees of freedom of the collision mesh (e.g., vertices or velocities).

Returns:

The potential for a set of collisions.

Eigen::VectorXd gradient(const TCollisionscollisions,
    
const CollisionMeshmeshEigen::ConstRef<Eigen::MatrixXd> X,
    
const bool in_full_dof = false) const;

Compute the gradient of the potential.

Parameters:
const TCollisions &collisions

The set of collisions.

const CollisionMesh &mesh

The collision mesh.

Eigen::ConstRef<Eigen::MatrixXd> X

Degrees of freedom of the collision mesh (e.g., vertices or velocities).

const bool in_full_dof = false

If true, return the gradient in full-mesh DOF (equivalent to mesh.to_full_dof(gradient), but assembled directly in full DOF when possible, avoiding the extra map).

Returns:

The gradient of the potential w.r.t. X. This will have a size of X.size() (or mesh.full_ndof() if in_full_dof).

Eigen::SparseMatrix<double> hessian(const TCollisionscollisions,
    
const CollisionMeshmeshEigen::ConstRef<Eigen::MatrixXd> X,
    
const PSDProjectionMethod project_hessian_to_psd
    
= PSDProjectionMethod::NONE
,
    
const bool in_full_dof = false) const;

Compute the hessian of the potential.

Parameters:
const TCollisions &collisions

The set of collisions.

const CollisionMesh &mesh

The collision mesh.

Eigen::ConstRef<Eigen::MatrixXd> X

Degrees of freedom of the collision mesh (e.g., vertices or velocities).

const PSDProjectionMethod project_hessian_to_psd = PSDProjectionMethod::NONE

Make sure the hessian is positive semi-definite.

const bool in_full_dof = false

If true, return the Hessian in full-mesh DOF (equivalent to mesh.to_full_dof(hessian), but assembled directly in full DOF when possible, avoiding the two sparse-matrix products).

Returns:

The Hessian of the potential w.r.t. X. This will have a size of X.size() by X.size() (or mesh.full_ndof() square if in_full_dof).

void assemble_hessian(const TCollisionscollisions,
    
const CollisionMeshmeshEigen::ConstRef<Eigen::MatrixXd> X,
    
HessianAssemblerassembler,
    
const PSDProjectionMethod project_hessian_to_psd
    
= PSDProjectionMethod::NONE
,
    
const bool in_full_dof = false) const;

Assemble the Hessian of the potential using a custom assembler.

Evaluates the local Hessian of every collision (in parallel) and feeds each to assembler (see HessianAssembler). This decouples the local derivative evaluation from the global matrix construction; hessian() is a thin wrapper around this using a TripletHessianAssembler.

Parameters:
const TCollisions &collisions

The set of collisions.

const CollisionMesh &mesh

The collision mesh.

Eigen::ConstRef<Eigen::MatrixXd> X

Degrees of freedom of the collision mesh (e.g., vertices or velocities).

HessianAssembler &assembler

The assembler that accumulates the local Hessians.

const PSDProjectionMethod project_hessian_to_psd = PSDProjectionMethod::NONE

Make sure the hessian is positive semi-definite.

const bool in_full_dof = false

If true, stencil vertex IDs are remapped to full-mesh vertex IDs (requires mesh.is_selection_dof_map(); throws otherwise).

virtual double operator()(const TCollisioncollision,
    
Eigen::ConstRef<VectorMaxNd> x) const
   
 = 0;

Compute the potential for a single collision.

Parameters:
const TCollision &collision

The collision.

Eigen::ConstRef<VectorMaxNd> x

The collision stencil’s degrees of freedom.

Returns:

The potential.

virtual VectorMaxNd gradient(const TCollisioncollision,
    
Eigen::ConstRef<VectorMaxNd> x) const
   
 = 0;

Compute the gradient of the potential for a single collision.

Parameters:
const TCollision &collision

The collision.

Eigen::ConstRef<VectorMaxNd> x

The collision stencil’s degrees of freedom.

Returns:

The gradient of the potential.

virtual MatrixMaxNd hessian(const TCollisioncollision,
    
Eigen::ConstRef<VectorMaxNd> x,
    
const PSDProjectionMethod project_hessian_to_psd
    
= PSDProjectionMethod::NONE
) const
   
 = 0;

Compute the hessian of the potential for a single collision.

Parameters:
const TCollision &collision

The collision.

Eigen::ConstRef<VectorMaxNd> x

The collision stencil’s degrees of freedom.

const PSDProjectionMethod project_hessian_to_psd = PSDProjectionMethod::NONE

Whether to project the hessian to the positive semi-definite cone.

Returns:

The hessian of the potential.

Protected Types

using TCollision = typename TCollisions::value_type;
using VectorMaxNd = VectorMax<double, STENCIL_NDOF>;
using MatrixMaxNd = MatrixMax<double, STENCIL_NDOF, STENCIL_NDOF>;

Protected Static Attributes

static constexpr int STENCIL_NDOF = 3 * TCollision::STENCIL_SIZE;

Maximum degrees of freedom per collision.