<p>Time integration with implicit Euler is unconditionally stable. This means you can choose arbitrary large time steps without worrying that your solution &quot;explodes&quot;. In contrast to explicit Euler, it requires you to solve a linear equation system at least once, which is generally much slower than simple matrix-vector multiplication. If the problem is non-linear, you also need to iterate until your error is minimized. This obviously takes even longer.</p>
<p>However, stability issues can be a pain to deal with and all explicit methods have limitations regarding their stability. Solving stability problems might force you to reduce your time step size drastically and to calculate so many intermediate steps that the implicit version gets more effective. An additional factor is the size of the system you want to simulate. If I remember correctly, the finer your mesh (smaller cells), the smaller are the timesteps you need to maintain stability.</p>
<blockquote>
<p>I'd like to know which algorithm uses the least amount of operations per frame / vertex.</p>
</blockquote>
<p>I think there is no general answer to the question because it depends on many factors like the mesh size, target FPS and the maximum local velocity that might occur. You need to evaluate all relevant factors and pick a method based on your exact problem.</p>
<p>In case you want raw speed and do not encounter any stability problems, the explicit Euler method should be one of the fastest methods but it usually blows up rather quickly.</p>
<p><strong>Additional info</strong></p>
<p>A time-integration method that is quite popular in real-time engines is Runge-Kutta 4. It is also an explicit method and doesn't require you to solve a linear system. It has a good balance of stability and speed, so you might have a look at it. I have never simulated cloth myself, nor have I programmed an RK4, so I can't tell if it is a good choice here.</p>

CC BY-SA 4.0
2021-04-13T13:06:23.790Z
Thanks for the answer!  I also found [this](https://www.cs.utah.edu/~ladislav/liu13fast/liu13fast.pdf) paper, which seems to strike some compromise between speed and exactness.  I work in design, so I don't want to solve a specific problem but first and foremost want to get something to look cool and behave fluently, so if my parameters lead to numerical instability, I can tweak them a bit.  I think I'll try to implement explicit Euler on the GPU, even if it doesn't work, it seems like a useful practice to work with GPU.js once.
fweth
CC BY-SA 4.0
2021-04-12T17:52:42.533Z
2021-04-12T17:52:42.533Z
wychmaster
<p>I'd like to simulate a 4-dimensional cloth in the web browser, since browsers don't offer great ressources for numerical computation, I'd like to know which algorithm uses the least amount of operations per frame / vertex.</p>
<p><a href="https://codepen.io/fweth/pen/poRjMKg?editors=0010" rel="nofollow noreferrer">Here</a> is some naive first draft using explicit Euler.  I found <a href="https://www.cs.utah.edu/%7Eladislav/liu13fast/liu13fast.pdf" rel="nofollow noreferrer">this</a> paper discussing a fast method for finding approximate solutions of the implicit Euler method.  What I gathered from the discussion is that implicit Euler is numerically more stable in certain scenarios, but it looks like it uses more operations than explicit Euler since it is built around iterations.  Is that correct?</p>
<p>Also, are there any libraries using WebGL to accelerate numerical computations which might be useful for this project?  I thought about looking into TensorFlow.js.</p>

CC BY-SA 4.0
2023-10-23T01:41:28.863Z
I actually implemented that paper not long ago. It was in a compute shader however in Unity. It boiled down for the case of non tearing cloth of a matrix vector multiplication mainly.
user8469759
<webgl><real-time><physics><javascript>
Fastest Simulation Of Mass Spring Systems
fweth
# Fastest Simulation Of Mass Spring Systems

(Asked by: username_0 on 2021-04-10)

I'd like to simulate a 4-dimensional cloth in the web browser, since browsers don't offer great ressources for numerical computation, I'd like to know which algorithm uses the least amount of operations per frame / vertex.

[Here](https://codepen.io/username_0/pen/poRjMKg?editors=0010) is some naive first draft using explicit Euler. I found [this](https://www.cs.utah.edu/%7Eladislav/liu13fast/liu13fast.pdf) paper discussing a fast method for finding approximate solutions of the implicit Euler method. What I gathered from the discussion is that implicit Euler is numerically more stable in certain scenarios, but it looks like it uses more operations than explicit Euler since it is built around iterations. Is that correct?

Also, are there any libraries using WebGL to accelerate numerical computations which might be useful for this project? I thought about looking into TensorFlow.js.

**Tags:** webgl, real-time, physics, javascript

> **Comments:**
> **username_1**: I actually implemented that paper not long ago. It was in a compute shader however in Unity. It boiled down for the case of non tearing cloth of a matrix vector multiplication mainly.  

---

## 1 answers

### Answer by username_2 on 2021-04-12. Score: 1 | Accepted answer

Time integration with implicit Euler is unconditionally stable. This means you can choose arbitrary large time steps without worrying that your solution "explodes". In contrast to explicit Euler, it requires you to solve a linear equation system at least once, which is generally much slower than simple matrix-vector multiplication. If the problem is non-linear, you also need to iterate until your error is minimized. This obviously takes even longer.

However, stability issues can be a pain to deal with and all explicit methods have limitations regarding their stability. Solving stability problems might force you to reduce your time step size drastically and to calculate so many intermediate steps that the implicit version gets more effective. An additional factor is the size of the system you want to simulate. If I remember correctly, the finer your mesh (smaller cells), the smaller are the timesteps you need to maintain stability.

> I'd like to know which algorithm uses the least amount of operations per frame / vertex.

I think there is no general answer to the question because it depends on many factors like the mesh size, target FPS and the maximum local velocity that might occur. You need to evaluate all relevant factors and pick a method based on your exact problem.

In case you want raw speed and do not encounter any stability problems, the explicit Euler method should be one of the fastest methods but it usually blows up rather quickly.

**Additional info**

A time-integration method that is quite popular in real-time engines is Runge-Kutta 4. It is also an explicit method and doesn't require you to solve a linear system. It has a good balance of stability and speed, so you might have a look at it. I have never simulated cloth myself, nor have I programmed an RK4, so I can't tell if it is a good choice here.

> **Comments:**
> **username_0**: Thanks for the answer!  I also found [this](https://www.cs.utah.edu/~ladislav/liu13fast/liu13fast.pdf) paper, which seems to strike some compromise between speed and exactness.  I work in design, so I don't want to solve a specific problem but first and foremost want to get something to look cool and behave fluently, so if my parameters lead to numerical instability, I can tweak them a bit.  I think I'll try to implement explicit Euler on the GPU, even if it doesn't work, it seems like a useful practice to work with GPU.js once.  

---

