4 ms·
I just realized that I'm yet to properly introduce myself to you folks; name's Darrell (the Happy Koala - I love koalas the way other people seem to love cats!)
by the_happy_koala 8y ago
I just realized that I'm yet to properly introduce myself to you folks; name's Darrell (the Happy Koala - I love koalas the way other people seem to love cats!). I'm a self taught developer and the project this thread is concerned with is actually the reason, pretty much, I started dabbling with code. If you want more of a background, you can check out an article I wrote over at Medium about the evolution of this project and how it led to me becoming a web developer - https://medium.com/@darrell.arjuna.huffman/how-an-interest-in-physics-led-me-to-a-new-career-in-web-development-f863ea118099 https://medium.com/@darrell.arjuna.huffman/how-an-interest-i... (please bear with any spelling or grammatical mistakes as English is not my first language). I'm still very much of a junior empty stack developer, but I love coding and intend to continue doing so, so hopefully we'll have lots of interesting discussions here on Hacker News in the future! Having said that, have a nice start to the week!
- PaulHoule 8y ago(I used to simulate classical mechanics for a living, so...) It's pretty good except it runs a lot slower than it has to. The default step size is too small for most cases so you have to wait a long time for the planets to move around. When I tried increasing the step size with the slider I'd inevitably increase it too much and the planets would fly away. Personally I always use RK4 and similar algorithms with adaptive step size, mostly because it is a pain to tune the step size by hand https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods#Adaptive_Runge%E2%80%93Kutta_methods https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods#Ad... also if planets are passing close to each other you may need a shorter step when you are close and a longer step when you are far away. RK4 or RK5 with adaptive timesteps will make your demo much better with very little work. There are methods that use higher order derivatives and other tricks to take large steps, for instance I like this method https://github.com/alexrudy/bsint https://github.com/alexrudy/bsint If you were integrating the solar system for millions of years you would want a symplectic integrator. https://en.wikipedia.org/wiki/Symplectic_integrator https://en.wikipedia.org/wiki/Symplectic_integrator this might not be more accurate than another integrator but it will preserve phase space area which makes it possible that the long-term dynamics will "look like" the real long-term dynamics. (Otherwise it certainly won't!) If it were me in cases where there is a central large mass I would integrate in spherical or cylindrical coordinates, probably I would use a predictor-corrector method.
- the_happy_koala 8y agoHi Paul! Many thanks for your feedback! Implementing an integrator with an adaptive time step is on my bucket list of features that I intend to implement, as tweaking the time step manually, especially with the freaking slider, is somewhat of a pain in the neck. Another reason for why I want to implement an adaptive time step is that collisions don't really work with a fixed one as sometimes a mass will travel farther in one time step than the radius (I use a simple radius check for collisions since it doesn't require that much computing power) of the body it is smacking into, and as such the hit won't get registered, which looks kind of shoddy (implemented collisions but removed them for this reason).I've had an eye on the RK45 method, but I'm definitely going to give implementing the Bulirsch-Stoer Integrator a go as I want the user to be able to select the integrator they want to run a scenario with (right now I've just implemented Euler and RK4). As for using spherical or cylindrical coordinates, the thing is that the intention is for the user to be able to, for instance, add another sun to our solar system to marvel at all the cosmic shenanigans that would take place, so while a lot of the scenarios start out with a single large mass, that might not be the case for long if the user has a penchant for destruction.
- lilgreenland 8y agoAny thoughts on Leapfrog integration? I've got a super basic n-body simulator that I'm using for gravity and for coulomb's law. I also need to advance to adaptive time steps. https://landgreen.github.io/physics/notes/electromagnetism/potential/index.html#three-potential-sims https://landgreen.github.io/physics/notes/electromagnetism/p...
- foxes 8y agoLeapfrog is also conservative - it's a symplectic integrator. It's also stable for oscillations for a sufficiently small time step. However I think it requires a constant step size, its not adaptive.
- the_happy_koala 8y agoCan't stop myself from staring at those modulating peaks; hypnotizing stuff! Leapfrog integration, as foxes pointed out, is not symplectic if you apply an adaptive time step. I'm not that concerned about the integrator being symplectic as it's not my intention to run simulations that last for millions of years. If it's possible to add comments to a thread here on hacker news (new to this site!) indefinitely, I'll give you a heads up when I've implemented an integrator with an adaptive time step, and in case you get to it before I do, do share :D!
- dancek 8y agoThis brings memories. I wrote a planetary simulation in Java/Swing as a programming course project in 2008, back when I didn't know much about programming. That application also had sliders for control, RK4 etc. I started programming full time in 2013 and am now a senior developer. You can get far in ten years, but I'm no senior really. (I wonder where the really experienced programmers are.)