21
Miles Macklin, Matthias Müller, Nuttapong Chentanez XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS

XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

Miles Macklin, Matthias Müller, Nuttapong Chentanez

XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS

Page 2: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

2

PROBLEM

• Position-Based Dynamics (PBD) stiffness depends on the number of iterations and time step size

• Converges to an infinitely stiff solution given enough iterations

• Makes setting relative stiffness difficult

• Stiffness does not have any physical basis • No concept of a constraint force magnitude

l1l2

The long standing problem of PBD is that the stiffness depends on iteration count. Regardless of how you set the stiffness coefficients in PBD, given enough iterations it will converge to an infinitely stiff solution, effectively overriding the stiffness values.

For example in a cloth model, we have bending and stretch constraints. If we need to increase iterations to reduce stretching, we inadvertently increase resistance to bending. This makes it difficult to set up relative stiffness in simulation assets, and difficult to create re-usable assets.

In addition, stiffness does not have a physical basis in PBD. It does not correspond to a traditional engineering stiffnesss. A connection to real-world physics would be nice in order to match real-world material parameters.

Finally, PBD does not have a concept of constraint force magnitude. Although constraints may be solved effectively, we have no idea how much work they have done. We need this information to drive force dependent effects such as haptic feedback, particle system spawning, motors and motor limits.

Page 3: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

3

20 ITERATIONS 160 ITERATIONS

PBD ITERATION DEPENDENT STIFFNESS

This example shows how PBD’s behavior changes with iteration count. Ideally these two pieces of cloth should behave exactly the same, but we have much stiffer cloth at high iteration counts despite having used a low stiffness coefficient.

Page 4: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

CONSTRAINED DYNAMICS

• Start with Newton’s equations of motion given an energy potential U(q)

• Define potential function U(x) in terms of constraint vector C(x)

• Compliance

Equations of motion (Newton’s 2nd Law)

Mx = �rUT (x)

U(x) =1

2C(x)T↵�1

C(x)

Elastic potential↵ = S�1

I want to start by deriving PBD from a more principled basis. We start here with our equations of motion, Newton’s second law, F=Ma. Here F is derived from an energy potential U, which we define as a quadratic form in terms of the constraint functions C.

We prefer to work in terms of compliance which is defined as inverse stiffness. Here alpha is a diagonal, or block diagonal compliance matrix.

Page 5: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

CONSTRAINED DYNAMICS

• Introduce Lagrange multiplier • Combine with our equations of

motion to obtain compliant constrained equations of motion

• [Servin et al 2006]

Mx�rC

T (x)� = 0

C(x) +↵� = 0

� = �↵�1C(x)

Compliant constrained equations of motion

Lagrange multiplier

We can further re-write the equations of motion by introducing a new variable lambda. This is our Lagrange multiplier. Plugging it into the equations of motion we obtain the familiar constrained equations of motion, with the addition of this compliant alpha*lambda term in the second equation. This can be thought of as a regularization term that makes our constraints correspond to the energy potential we defined initially.

Page 6: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

• Implicit time discretization • Introduce predicted position

• Introduce time-scaled compliance:

TIME DISCRETIZATION

M(xn+1 � x)�rC(xn+1)T�n+1 = 0

C(xn+1) + ↵�n+1 = 0

Discrete Constrained Equations of Motion

Continuous Constrained Equations of Motion

↵ =↵

�t2

x = x

n +�tvn

Mx�rC

T (x)� = 0

C(x) +↵� = 0

Now we have our equations of motion we need to solve them. This is a differential algebraic equation of order three (DAE3), a notoriously difficult problem to solve well. We take a simple approach of performing an implicit time-discretization on positions.

Here we have introduced two new variables, tilde(x) which is sometimes called the inertial, predicted, or unconstrained position. This is the state the system would obtain if we integrated it forward in time without considering the constraints.

tilde(alpha) is simply a time-step scaled version of compliance that we use to make the equations more compact.

Page 7: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

• Implicit time discretization produces a non-linear system of equations

• How do we solve such a system? • Newton’s method

NEWTON’S METHOD

M(xn+1 � x)�rC(xn+1)T�n+1 = 0

C(xn+1) + ↵�n+1 = 0

Implicit Discrete Equations of Motion

Non-Linear System

g(xn+1,�n+1) = 0

h(xn+1,�n+1) = 0

Now we have our discretized equations we need to solve them. These are non-linear equations, and the standard way to solve non-linear equations is Newton’s method. We will apply Newton’s method, but first we re-label the equations as g() and h() respectively.

Page 8: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

NEWTONS METHOD

• Linearize g,h, around current iterate x_i, lambda_i

• Update system with delta • Works well, but may need

line-search / trust-region to be robust

K �rC

T (xi)rC(xi) ↵

� �x

��

�= �

g(xi,�i)h(xi,�i)

�i+1 = �i +��

xi+1 = xi +�x

Linear Solve

System Update

Newton’s method involves first linearizing the equations to obtain a linear system that we solve for deltaX and deltaLambda. These are then applied directly to the system, and the process repeated until the deltas fall below some tolerance value.

This method works well, although it can be difficult to implement. Computing K involves the second derivatives (Hessians) of the constraint functions, and it may require a line-search or trust region method to converge. We now seek a simpler approach based on PBD, but to do that we need to make some approximations..

Page 9: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

APPROXIMATE NEWTON STEP

First approximation:

• M = K + O(dt^2) • Common Quasi-Newton

simplification

Second approximation:

• g = 0 • True for first iteration • Typically remains small

K �rC

T (xi)rC(xi) ↵

� �x

��

�= �

g(xi,�i)h(xi,�i)

M �rC

T (xi)rC(xi) ↵

� �x

��

�= �

0

h(xi,�i)

Full Newton System

Approximate System

The first approximation is to replace K with M. This drops some terms on the order of dt^2, it may affect converge rate, but it doesn’t change the solution of our Newton iteration. Sometimes this is called a quasi-Newton method.

The next approximation is to treat g(x, lambda) as zero for all iterations. We make two observations to justify this approximation. First, if we initialise the Newton iteration with x0 = tilde(x), and lambda0=0, this means g(x0, lambda0) is automatically zero, so the first Newton iteration is unchanged. In addition, g() typically remains small because it is related to the change in the constraint gradient direction. If constraints are linear, then g() is always zero. In practice g() is close to linear for small time-steps.

Page 10: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

VARIATIONAL VIEWPOINT

1

2(x� x)TM(x� x)

C(x) = 0

minimize

subject to

Implicit Euler

PBD

1

2(x� xi)

TM(x� xi)

C(x) = 0

minimize

subject to

x

x1

x2

C(x) = 0x

Some further intuition can be obtained by looking at this from a variational point of view. We can view implicit Euler as trying to find the closest point on the constraint manifold to the predicted or internal position, tilde(x). In contrast, PBD tries to find a close, but not necessarily the closest point on the manifold. Each iteration solves a slightly different minimization, starting from the current iterate, this leads to this ‘curved path’ back to the manifold. As soon as PBD finds a point on the manifold it stops, however there is no guarantee that this is the closest point. In practice the difference is small, but this is the consequence of our approximation that g() = 0.

Page 11: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

CONNECTION TO PBD

• Take Schur complement of approximate system with respect to M

• Obtain PBD or Fast Projection form

• [Goldenthal et al 2007]

M �rC

T (xi)rC(xi) ↵

� �x

��

�= �

0

h(xi,�i)

⇥rC(xi)M

�1rC(xi)T + ↵

⇤�� = �C(xi)� ↵�i

Schur complement

Approximate System

We can now make a connection back to PBD by taking the Schur complement (just plug the expression for deltaX into the second equation). This gives a familiar constrained system, with the addition of the compliance terms. This is equivalent to a compliant version of Goldenthal et al’s Fast Projection algorithm.

So far we have written things out in terms of the system as a whole, but one of the benefits of PBD is that it lets us work in terms of single constraints. So let’s see what that looks like..

Page 12: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

A GAUSS-SEIDEL UPDATE

• View PBD “scaling fator” s as incremental Lagrange multiplier

• Additional compliance terms • Must store Lagrange

multiplier for each constraint

• PBD solves the infinite stiffness case ��j =

�Cj(xi)� ↵j�ij

rCjM�1rCT

j + ↵j

PBD

XPBD

sj =�Cj(xi)

rCjM�1rCT

j

Here we have the original “scaling factor” from PBD, and the new deltaLambda term from XPBD. We can see that when alpha == 0 (infinite stiffness, or zero compliance) that the two equations are the same. From this we can see that s in PBD is actually an incremental Lagrange multiplier change for the infinitely stiff case. This makes sense, as it’s the behavior we observe in PBD as we increase iteration count.

When alpha > 0 we have some additional terms in the numerator and denominator which act to regularise the constraint.

Page 13: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

XPBD ALGORITHM

• Only two differences from PBD:

• Lagrange multiplier calculation (include compliance terms)

• Lagrange multiplier update (store instead of discard)

Algorithm 1 PBD simulation loop

1: predict position

˜

x ( x

n

+�tv

n

+�t

2M

�1f

ext

(x

n

)

2:

3: initialize solve x0 ( ˜

x

4: initialize multipliers �0 ( 0

5: while i < solverIterations do

6: for all constraints do

7: compute ��

8: compute �x

9: update �

i+1 ( �

i

+��

10: update x

i+1 ( x

i

+�x

11: end for

12: i ( i+ 1

13: end while

14:

15: update positions x

n+1 ( x

i

16: update velocities v

n+1 ( 1�t

�x

n+1 � x

n

So here is the final XPBD algorithm. It is identical to the original PBD method with the addition of these two changes to the deltaLamba update, and then rather than throw away that value, we accumulate it in a per-constraint auxiliary variable.

Page 14: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

RESULTS

• Compare solver output to a non-linear Newton method

• Close agreement for primal and dual variables

• Extend PBD to handle non-linear FEM

75 80 85 90 95 100350

400

450

500

550

600

Frame

Fo

rce

(N

)

Newton

XPBD 50

XPBD 100

XPBD 1000

We compare our method to a non-linear Newton method applied directly to the implicit equations of motion and find that it produces very close results. This graph shows the restoring force at the attachment for a chain swinging under gravity. XPBD approachs the reference solution given enough iterations. Here our Newton solver has used an LDLT decomposition as its linear solver backend.

Page 15: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

RESULTS

• Contact / friction

Page 16: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

RESULTS

• Contact / friction

Page 17: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

RESULTS

• Contact / friction

Page 18: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

SUMMARY

• Extend PBD to simulate well defined elastic and dissipative potentials • Maintains simplicity and robustness of original method

• Requires storing a a single scalar auxiliary variable representing a Lagrange multiplier

• Can be used to compute total constraint force magnitude for e.g.: motor limits, haptic devices, etc

• Reduces to PBD when alpha=0, too few iterations means artificial compliance • Contact, assume zero compliance

Page 19: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

THANK YOU

Page 20: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

REFERENCES

• Servin, Martin, Claude Lacoursiere, and Niklas Melin. "Interactive simulation of elastic deformable materials." SIGRAD 2006. The Annual SIGRAD Conference; Special Theme: Computer Games. No. 019. Linköping University Electronic Press, 2006.

• Goldenthal, Rony, et al. "Efficient simulation of inextensible cloth." ACM Transactions on Graphics (TOG) 26.3 (2007): 49.

• Müller, Matthias, et al. "Position based dynamics." Journal of Visual Communication and Image Representation 18.2 (2007): 109-118.

Page 21: XPBD: POSITION-BASED SIMULATION OF COMPLIANT … · 2021. 7. 19. · XPBD: POSITION-BASED SIMULATION OF COMPLIANT CONSTRAINED DYNAMICS. 2 PROBLEM •Position-Based Dynamics (PBD)

DAMPING

• Extend the same method to handle implicit damping

• Define a Rayleigh dissipation potential D(x,v)

• Implicit damping just a few additional terms in Lagrange multiplier update

D(x,v) =1

2C(x)T�C(x)

=1

2v

TrC

T�rCv,