POV-Ray : Newsgroups : povray.off-topic : I think I did something wrong with RK4... : I think I did something wrong with RK4... Server Time
4 Nov 2024 13:14:24 EST (-0500)
  I think I did something wrong with RK4...  
From: Chambers
Date: 6 Apr 2008 20:55:28
Message: <47f97100$1@news.povray.org>
Here's a test app for Windows:

http://www.pacificwebguy.com/downloads/TestingRK4.zip
(Note that, although the app itself is named "Threaded_Physics.exe", I 
haven't gotten around to implementing the "threaded" part yet.  Right 
now, I'm just trying to make it work *correctly*).

Click anywhere on the screen to shoot particles in that direction.
Press F1 to switch between Newtonian integration and Rk4 integration.

The main thing to notice, other than the fact that RK4 is *much* slower 
than Newtonian, is that using RK4 seems to amplify the forces somehow. 
The result is that everything seems rather... well, crazy.  In contrast, 
I've reached a point where the Newtonian doesn't look quite so bad 
(although I'd still like to work on the speed factor a bit).

Here's the inside of the RK4 integrator, as I implemented it:

{
  collide(particles_now, forces_now, gravity);
  step(particles_now, particles_stepped, forces_now, dt/2);
  collide(particles_stepped, forces_A, gravity);
  step(particles_now, particles_stepped, forces_A, dt/2);
  collide(particles_stepped, forces_B, gravity);
  step(particles_now, particles_stepped, forces_B, dt);
  collide(particles_stepped, forces_C, gravity);
  for (int i=0; i<size; i++) {
   forces_final[i] =
    (forces_now[i]+2*forces_A[i]+2*forces_B[i]+forces_C[i])/6.0f;
  }
  step(particles_now, particles_now, forces_final, dt);
}

And stubbed headers for the functions:

collide(data, result, gravity)
This calculates the collisions between particles, and the resultant 
forces (gravity is used as the initial, or base, force to start with)

step(data, result, forces, dt)
Applies forces to data with a timestep of dt

PS I just got a collection of all of Chopin's piano music (something 
like 15 CDs), and it's great "productivity" music (ie, have on in the 
background while I'm working on something else) :)

-- 
...Ben Chambers
www.pacificwebguy.com


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.