You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/time_integration.html
+64-19Lines changed: 64 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -76,45 +76,90 @@ <h3>Controls</h3>
76
76
<!-- Theory section -->
77
77
<divclass="card theory">
78
78
<h2>Time integration methods:</h2>
79
-
This example shows the motion of a particle with an initial velocity. Moreover, a constant gravitational acceleration is acting on the particle. In this special case an analytic solution can be computed as:
79
+
Simulating the motion of a physical system means solving its equations of motion, a system of ordinary differential equations (ODEs) that relate positions, velocities and accelerations. Since these equations can generally not be solved analytically, we approximate the solution step by step: given the state (position and velocity) at time $t$, a <b>time integration method</b> computes an approximation of the state at time $t + \Delta t$ using the currently acting forces. Repeating this update for a sequence of small time steps $\Delta t$ advances the simulation over time.
80
+
<p>
81
+
This example shows the motion of a single particle that has an initial velocity and is subject to a constant gravitational acceleration. Because the acceleration is constant here, this special case is one of the rare ones that admits a closed-form solution:
The motion determined using this analytic solution is plotted in green and can be compared with different numerical solutions that are introduced in the following.
85
-
86
+
This exact trajectory is plotted in green and serves as ground truth against which the numerical solutions (blue), computed with the methods introduced below, can be compared. As soon as forces depend on the state itself in a more complex way — e.g. spring, contact or SPH pressure forces — no analytic solution is available anymore and numerical time integration becomes essential.
87
+
</p>
88
+
<p>
89
+
Three properties are commonly used to characterize and compare time integration methods:
90
+
<ul>
91
+
<li><b>Order of accuracy:</b> A method of order $p$ has a local error (introduced in a single step) of $O(\Delta t^{p+1})$ and, consequently, a global error (accumulated over a fixed time interval) of $O(\Delta t^{p})$. Halving $\Delta t$ for a method of order $p$ roughly reduces the global error by a factor of $2^p$.</li>
92
+
<li><b>Computational cost:</b> given by the number of evaluations of the acceleration/force function required per time step. This is important in practice since evaluating the forces (e.g. for cloth, deformable solids or SPH fluids) is usually the most expensive part of a simulation step.</li>
93
+
<li><b>Stability and energy behavior:</b> describes how the numerical solution behaves over long simulation times, in particular whether it stays close to the true trajectory or whether energy is spuriously gained, lost, or oscillates around the correct value.</li>
94
+
</ul>
95
+
Try the different methods in the simulation with a large time step (e.g. $\Delta t = 0.1$) and compare how far the blue (numerical) trajectory deviates from the green (exact) one.
96
+
</p>
97
+
86
98
<h3>Explicit Euler</h3>
87
-
88
-
The explicit Euler method is a first-order accurate method for solving ordinary differential equations (ODEs):
99
+
100
+
The explicit Euler method (also called forward Euler) is the simplest time integration scheme for ODEs. It uses only quantities known at the current time $t$ to extrapolate the state to $t + \Delta t$:
<li>First-order accurate ($O(\Delta t)$ global error); requires only a single force evaluation per step, so it is the cheapest of the three methods.</li>
108
+
<li><b>Not symplectic:</b> it systematically injects energy into the system because the position update uses the <em>old</em> velocity $\mathbf v(t)$ instead of the newly computed one. For an oscillating system (e.g. a mass on a spring) this causes the amplitude to grow over time, even though the exact solution conserves energy.</li>
109
+
<li>Only conditionally stable: for stiff forces (e.g. stiff springs) $\Delta t$ must be chosen small enough, otherwise the simulation diverges numerically. For this reason explicit Euler is rarely used in practice and mainly serves as a baseline for comparison.</li>
110
+
</ul>
111
+
94
112
<h3>Symplectic Euler</h3>
95
-
96
-
The symplectic Euler method is also known as semi-implicit Euler since first the new velocity is determined and then the new position is computed using the new velocity value:
113
+
114
+
The symplectic Euler method is also known as semi-implicit Euler: it first updates the velocity using the current acceleration, and then uses this <em>already updated</em> velocity to advance the position:
The method is also first-order accurate but yields better results than the explicit Euler since it is a symplectic method.
102
-
119
+
<p><b>Properties:</b></p>
120
+
<ul>
121
+
<li>Still only first-order accurate, just like explicit Euler, and has the same cost of a single force evaluation per step — switching from explicit to symplectic Euler is essentially "free" in terms of performance.</li>
122
+
<li><b>Symplectic:</b> the method (approximately) preserves phase-space volume, which implies that the energy error stays bounded and oscillates around the true value instead of drifting away over time. This yields qualitatively much better long-term behavior than explicit Euler, even though the two methods have the same order and the same error at any single instant.</li>
123
+
<li>Because it is cheap, simple to implement and behaves well over long simulations, symplectic Euler is the de-facto standard in real-time physics: it is used for particle systems, cloth, rigid bodies, SPH fluids and position-based dynamics alike.</li>
124
+
</ul>
125
+
103
126
<h3>Runge-Kutta 2</h3>
104
-
105
-
Typically numerical integration methods are defined for a differential equation determined by a function $\mathbf f(t, \mathbf s(t))$, where $\mathbf s$ defines the state of the system at time $t$. In our example the state is defined by the current position and velocity of the particle and the function is defined as:
127
+
128
+
Higher-order integration methods are usually formulated for a general first-order ODE $\dot{\mathbf s}(t) = \mathbf f(t, \mathbf s(t))$, where $\mathbf s$ is the state of the system at time $t$. In our example the state consists of the particle's position and velocity, and the ODE is defined by:
Note that the Runge-Kutta method has multiple stages (in our case 2) to achieve a higher-order accuracy. However, this approach is more expensive than the Euler methods since the function has to be evaluated once per stage.
117
-
</div>
139
+
Intuitively, $\mathbf k_1$ is a trial (explicit Euler) step used only to estimate the state at the midpoint $t + \frac12 \Delta t$; the actual step $\mathbf k_2$ is then taken using the derivative evaluated at that midpoint, which cancels out the leading-order error term of the Euler methods.
140
+
<p><b>Properties:</b></p>
141
+
<ul>
142
+
<li>Second-order accurate ($O(\Delta t^2)$ global error): halving $\Delta t$ roughly quarters the error, so for smooth, non-stiff problems RK2 reaches a given accuracy with a much larger time step than either Euler method.</li>
143
+
<li>Has two stages, i.e. the function $\mathbf f$ must be evaluated twice per time step — roughly twice the cost of an Euler step. In general, an order-$p$ Runge-Kutta method typically needs at least $p$ stages, so higher accuracy is traded against more force evaluations per step.</li>
144
+
<li><b>Not symplectic:</b> despite its higher accuracy, RK2 can still exhibit long-term energy drift on oscillatory problems; the higher order just makes the drift smaller and less visible over short simulation times.</li>
145
+
</ul>
146
+
147
+
<h3>Summary</h3>
148
+
<p>The following table summarizes the properties discussed above:</p>
<tr><td>Runge-Kutta 2</td><td>2</td><td>2</td><td>No</td><td>Higher short-term accuracy for smooth, non-stiff problems</td></tr>
154
+
</table>
155
+
There is no single "best" method: the right choice depends on whether short-term accuracy, long-term (energy) stability, or per-step cost matters most for the application at hand. Higher-order methods such as Runge-Kutta 4, or implicit methods for stiff problems, extend these same trade-offs further and are covered in later examples.
156
+
157
+
<h3>References</h3>
158
+
<ul>
159
+
<li>[HLW06] Ernst Hairer, Christian Lubich, Gerhard Wanner. Geometric Numerical Integration: Structure-Preserving Algorithms for Ordinary Differential Equations, 2nd edition. Springer, 2006.</li>
160
+
<li>[BW98] David Baraff, Andrew Witkin. Large Steps in Cloth Simulation. In Proceedings of SIGGRAPH, 1998.</li>
0 commit comments