• Advertisement
Sign in to follow this  

Spring simulation, differential solvers

This topic is 3736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The current spring simulation example using RK4: http://home.syranide.com/download/springs.zip Added a pretty picture as well, for those download shy people. ;) So I'm currently working on a little project both for the fun of it and perhaps to put it to work in some game-like setting. The simulation is as you can guess using damped harmonic oscillators (aka springs) and I've got it all up and running as well as actually understanding what most of it does (I'd like to believe so ;)). I have implemented RK4, but too small timesteps makes everything blow up as I know it also should, but I thought, since the setup I have required it to be run 10 times per frame (aka 600 times per second, I know this is dependent on stiffness/damping etc) maybe I should try a more expensive solver that gives smaller errors (thus can be iterated less times) steps so I implemented RK6. However, RK6 gave me basically identical results, meaning that the simulation would blow up at almost the same step sizes. Isn't it supposed to allow me to use larger step sizes or is there some other factor involved? I also implemented RK2 (midpoint modified I think) and tried it out and it just barely works for 40 steps * 2 iterations (whereas RK4 used 10 iterations) per frame, but it wasn't that much more costly. However, that wasn't the point, I'm implementing it for the Bulirsch-Stoer method, should I assume that the Bulirsch-Stoer method might be a better choice than RK45? (Both are adaptive step size solvers) The Bulirsch-Stoer seemed kind of praised in the Numerical Recipes-book, but to be honest their explanations was too mathematically heavy for me to actually determine if it was applicable to damped harmonic oscillators. So, my question is basically, do you think the Bulirsch-Stoer method would be a better choice than RK45 to use (or any other)? Seeing as it is really important that the simulations never explode and that I might have to do many iterations per frame anyway. Or do you have other helpful tips perhaps? I'm not interested in a very accurate method, just one that doesn't explode. EDIT: Also, by the way, what is the exact cause for it exploding? Approximating the spring equation fails and gives a very high/bad result, thus some spring gets a horribly high velocity and it causes the rest to explode as well? (But why is that? Is it when a spring (e.g.) expands and then contracts in the same step, thus the solver could interpret it as only expanding and thus gives a very high result?) Thanks! [Edited by - Syranide on October 29, 2007 8:27:19 AM]

Share this post


Link to post
Share on other sites
Advertisement
As for why it blows up, you might consider reading my GDC 2001 talk on predicting/planning the stability of rigid body physics simulation, which does go into the theoretical reasons why these types of integrators blow up. Well, it is math heavy, and looking back I would have written it differently if I could. But, it is a resource you may find helpful. The link is below.

Ultimately, the RK variants don't really behave much differently from each other in terms of numerical stability...you're only shifting things slightly, but not really making them more stable. You say you're using damped harmonic oscillators, but are you explicitly adding in the damping, as in a viscous damping force? Many explicit techniques really need this damping to improve stability when springs are involved. You could try the velocity-less Verlet integrator, which is a quite easy to implement semi-implicit solver that folks have had good success with. Or, you could consider going to a full implicit (e.g., not just semi-implicit) for maximum stability.

As for my talk, the paper and presentation are complementary:

Stable Rigid-Body Physics Paper (from GDC 2001)

Stable Rigid-Body Physics Presentation (from GDC 2001)

Share this post


Link to post
Share on other sites
Thank you so much!
I will definately look into the URLs and methods you talked about.

Share this post


Link to post
Share on other sites
Lookin at your picture I would just use simple distance constraints and a fast pairwise relaxation solver on the position level. This is unconditionally stable, fast and easy to implement.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement