logo


Resources:

Part 2: The Core of PBD

In this section, we will

  • present the basic idea and the simulation algorithm of PBD
  • discuss how to solve the system of constraints that are described to be simulated
    The simulated objects:
  • a set of NN particles
  • a set of MM constraints
  • a stiffness parameter k∈[0,1]k \in [0, 1]: the strength of the constraint

🌟 Time Algorithm

Algorithm 1 Position-based dynamics: Given this data and a time step Ξ”t\Delta t
1: for all vertices ii do
2:   initialise xi=xi0,vi=vi0,wi=1/mi\bold x_i = \bold x_i^0, \bold v_i = \bold v_i^0, w_i = 1 / m_i
3: end for
4: loop
5:   for all vertices ii do vi←vi+Ξ”twifext(xi)\bold v_i \leftarrow \bold v_i + \Delta t w_i \bold f_{ext}(\bold x_i)
6:   dampVelocities(v1,…,vN)dampVelocities(\bold v_1, …, \bold v_N)
7:   for all vertices ii do pi←xi+Ξ”tvi\bold p_i \leftarrow \bold x_i + \Delta t \bold v_i
8:   for all vertices ii do genCollConstraints(xiβ†’pi)genCollConstraints(\bold x_i \rightarrow \bold p_i)
9:   loop solverIteration times
10:     projectConstraints(C1,…,CM+Mcoll,p1,…,pN)projectConstraints(C_1, …, C_{M + M_{coll}}, \bold p_1, …, \bold p_N)
11:   end loop
12:   for all vertices ii do
13:     vi←(piβˆ’xi)/Ξ”t\bold v_i \leftarrow (\bold p_i - \bold x_i) / \Delta t
14:     xi←pi\bold x_i \leftarrow \bold p_i
15:   end for
16:   velocityUpdate(v1,…,vN)velocityUpdate(\bold v_1, …, \bold v_N)
17: end loop

(1) - (3) specify the positions and the velocities of the particles
(5) - (7) perform a simple symplectic Euler integration step on the velocities and positions, the new locations pi\bold p_i are used as predictions
(8) generate non-permanent external constraints, such as collision constraints
(9) - (11) iteratively corrects the predicted positions such that they satisfy the McollM_{coll} external as well as the MM internal constraints
(12) - (15) Use the corrected positions pi\bold p_i to update the velocities and positions

🌟 Solver

The system problem: a set of MM equations for the 3N3N unknown position components, where MM is the total number of constraints.
Solving a non-symmetric, non-linear system with equalities and inequalities is a tough problem.
Let x\bold x be the concatenation x=[x1T,…,xNT]T\bold x = [\bold x_1^T, …, \bold x_N^T]^T,

C1(x)≻0...CM(x)≻0C_1(\bold x) \succ 0 \\ ... \\ C_M(\bold x) \succ 0

where the symbol ≻\succ denotes either == or β‰₯\geq.
The Newton-Raphson iteration is a method to solve non-linear symmetric systems with equalities only. It starts with a first guess of a solution. Each constraint function is then linearized in the neighborhood of the current solution using

C(x+Ξ”x)=C(x)+βˆ‡C(x)β‹…Ξ”x+O(βˆ£Ξ”x∣2)=0C(\bold x + \Delta \bold x) = C(\bold x) + \nabla C(\bold x) \cdot \Delta \bold x + O(|\Delta \bold x|^2) = 0

This yields a linear system for the global correction vector Ξ”x\Delta \bold x

βˆ‡C1(x)β‹…Ξ”x=βˆ’C1(x)...βˆ‡CM(x)β‹…Ξ”x=βˆ’CM(x)\nabla C_1(\bold x)\cdot \Delta \bold x = - C_1(\bold x) \\ ... \\ \nabla C_M(\bold x)\cdot \Delta \bold x = - C_M(\bold x)

where βˆ‡Cj(x)\nabla C_j(\bold x) is the 1Γ—N1\times N dimensional vector containing the derivatives of the function CjC_j w.r.t. all its parameters, i.e. the NN components of x\bold x. Both, the rows βˆ‡Cj(x)\nabla C_j(\bold x) and the right-hand side scalars βˆ’Cj(x)-C_j(\bold x) are constant as they are evaluated at the location x\bold x before the system is solved.

When M=3NM=3N and only equalities are present, the system can be solved by any linear solver, e.g., a preconditioned conjugate gradient method.

Non-linear Gauss-Seidel Solver : it solves each constraint equation C(x)≻0C(\bold x) \succ 0 separately

Given x\bold x , we want to find a correction Ξ”x\Delta \bold x such that C(x+Ξ”x)≻0C(\bold x + \Delta x) \succ 0. The constraint equation is approximated by

C(x+Ξ”x)β‰ˆC(x)+βˆ‡C(x)β‹…Ξ”x≻0\begin{align}C(\bold x + \Delta \bold x) \approx C(\bold x) + \nabla C(\bold x) \cdot \Delta \bold x \succ 0\end{align}

Based on the linear and angular momentum conservation requirements, Ξ”x\Delta \bold x is restricted in the direction of βˆ‡C\nabla C .

With a scalar Lagrange multiplier Ξ»\lambda :

Ξ”x=Ξ»Mβˆ’1βˆ‡C(x)\begin{align}\Delta \bold x = \lambda \bold M^{-1} \nabla C(\bold x)\end{align}

where M=diag(m1,m2,…,mN)\bold M = diag(m_1, m_2, …, m_N) and wi=1/miw_i = 1 / m_i. The correction vector of a single particle ii

Ξ”xi=Ξ»wiβˆ‡xiC(x)\begin{align}\Delta \bold x_i = \lambda w_i \nabla_{\bold x_i} C(\bold x)\end{align} Ξ»=C(x)βˆ‘jwjβˆ£βˆ‡xjC(x)∣2\begin{align}\lambda = \frac{C(\bold x)}{\sum_j w_j|\nabla _{\bold x_j}C(\bold x)|^2}\end{align}

Formulated for the concatenated vector x\bold x of all positions, we get:

Ξ»=C(x)βˆ‡C(x)TMβˆ’1βˆ‡C(x)\begin{align}\lambda = \frac{C(\bold x)}{\nabla C(\bold x)^T\bold M^{-1}\nabla C(\bold x)}\end{align}

The Gauss-Seidel method

  • stable and easy to implement
  • converges significantly slower than global solvers. The main reason is that error corrections are propagated only locally from constraint to constraint.

Hierarchical Solver: increase the convergence rate of the Gauss-Seidel method

Figure 2: The construction of a mesh hierarchy: A fine level l is composed of all the particles shown and the dashed constraints. The next coarser level, l + 1, contains the proper subset of black particles and the solid constraints. Each fine white particle needs to be connected to at least k (=2) black particles – its parents – shown by the arrows.

Figure 2: The construction of a mesh hierarchy: A fine level l is composed of all the particles shown and the dashed constraints. The next coarser level, l + 1, contains the proper subset of black particles and the solid constraints. Each fine white particle needs to be connected to at least k (=2) black particles – its parents – shown by the arrows.

The main idea is to create a hierarchy of meshes in which the coarse meshes make sure that error corrections propagate fast across the domain.

Hierarchical Position-Based Dynamics (HPBD):

  • define the original simulation mesh to be the finest mesh of the hierarchy
  • create coarser meshes by only keeping a subset of the particles of the previous mesh.
  • The hierarchy is traversed only once from the coarsest to the finest level. Therefore, they only need to define a prolongation operator.

✨ Connection to Implicit Methods

By considering backward Euler as a constrained minimization over positions. Starting from the traditional implicit Euler time discretization of the equations of motion

xn+1=xn+Ξ”tvn+1vn+1=vn+Ξ”tMβˆ’1(Fext+kβˆ‡Cn+1)\begin{align} \bold x^{n+1} &= \bold x^n + \Delta t \bold v^{n+1} \\ \bold v^{n+1} &= \bold v^n + \Delta t \bold M^{-1}(\bold F_{ext} + k\nabla \bold C^{n+1}) \end{align}

where C\bold C is the vector of constraint potentials; kk is the stiffness. We can eliminate velocity to give:

M(xn+1βˆ’2xn+xn+1βˆ’Ξ”t2Mβˆ’1Fext)=Ξ”t2kβˆ‡Cn+1\begin{align} \bold M(\bold x^{n+1} - 2\bold x^n + \bold x^{n+1} - \Delta t^2 \bold M^{-1}\bold F_{ext}) = \Delta t^2 k \nabla \bold C^{n+1} \end{align}

Equation (12) can be seen as the first-order optimality condition for the following minimization:

minx12(xn+1βˆ’x~)TM(xn+1βˆ’x~)βˆ’Ξ”t2kCn+1\begin{align} \underset{\bold x}{min} \frac{1}{2}(\bold x^{n+1} - \tilde {\bold x})^T\bold M(\bold x^{n+1} - \tilde {\bold x}) - \Delta t^2 k \bold C^{n+1} \end{align}

where x~\tilde {\bold x} is the predicted position, given by:

x~=2xnβˆ’xnβˆ’1+Ξ”t2Mβˆ’1Fext=xn+Ξ”tvn+Ξ”t2Mβˆ’1Fext\begin{align} \tilde {\bold x} &= 2\bold x^n - \bold x^{n-1} + \Delta t^2 \bold M^{-1}\bold F_{ext} \\ &= \bold x^n + \Delta t \bold v^n + \Delta t^2 \bold M^{-1} \bold F_{ext} \end{align}

Taking the limit as kβ†’βˆžk \rightarrow \infty we obtain the constrained minimization:

minx12(xn+1βˆ’x~)TM(xn+1βˆ’x~)s.t.Ci(xn+1)=0,i=1,...,n.\begin{equation}\begin{aligned} \underset{\bold x}{min} \frac{1}{2}(\bold x^{n+1} - \tilde {\bold x})^T\bold M(\bold x^{n+1} - \tilde {\bold x}) \\ s.t. C_i(\bold x^{n+1}) = 0, i = 1, ..., n. \end{aligned}\end{equation}

We can interpret this minimization problem as finding the closest point on the constraint manifold to the predicted position.

To solve this minimization, PBD employs a variant of the fast projection algorithm but modifies the projection step by linearizing constraints one at a time using a Gauss-Seidel approach.

✨ Second Order Methods

the second-order accurate BDF update equations

xn+1=43xnβˆ’13xnβˆ’1+23Ξ”tvn+1vn+1=43vnβˆ’13vnβˆ’1+23Ξ”tMβˆ’1(Fext+kβˆ‡Cn+1)\begin{align} \bold x^{n+1} &= \frac{4}{3}\bold x^n - \frac{1}{3}\bold x^{n-1} + \frac{2}{3} \Delta t\bold v^{n+1} \\ \bold v^{n+1} &= \frac{4}{3}\bold v^n - \frac{1}{3}\bold v^{n-1} + \frac{2}{3} \Delta t\bold M^{-1}(\bold F_{ext} + k\nabla \bold C^{n+1}) \end{align}

Eliminating velocity and re-arranging gives

M(xn+1βˆ’x~)=49Ξ”t2kβˆ‡Cn+1\begin{align} \bold M(\bold x^{n+1} - \tilde {\bold x}) = \frac{4}{9}\Delta t^2 k \nabla \bold C^{n+1} \end{align}

where the inertial position x~\tilde {\bold x} is given by:

x~=43xnβˆ’13xnβˆ’1+89Ξ”tvnβˆ’29Ξ”tvnβˆ’1+49Ξ”t2Mβˆ’1Fext\begin{align} \tilde {\bold x} &= \frac{4}{3}\bold x^n - \frac{1}{3}\bold x^{n-1} + \frac{8}{9}\Delta t \bold v^n - \frac{2}{9} \Delta t\bold v^{n-1} +\frac{4}{9}\Delta t^2 \bold M^{-1} \bold F_{ext} \end{align}

Equation (19) can again be considered as the optimality condition for a minimization of the same form as (16).

Once the constraints have been solved, the updated velocity is obtained according to (17)

vn+1=1Ξ”t[32xn+1βˆ’2xn+12xnβˆ’1]\begin{align} \bold v^{n+1} = \frac{1}{\Delta t}\left [ \frac{3}{2}\bold x^{n+1} - 2\bold x^n + \frac{1}{2}\bold x^{n-1} \right] \end{align}
PreBack to BlogNext