Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to switch to using RK4 instead of forward-Euler #128

Open
timhutton opened this issue Jan 14, 2021 · 0 comments
Open

Option to switch to using RK4 instead of forward-Euler #128

timhutton opened this issue Jan 14, 2021 · 0 comments

Comments

@timhutton
Copy link
Member

timhutton commented Jan 14, 2021

See discussion in #118

RK4 is:

  • The derivative k1 is computed from the current state, a.
  • A half-step forward in time is taken, using k1: a2 = a + (timestep/2)*k1
  • The derivative k2 is computed from state a2.
  • A half-step forward in time from the start is taken again, using k2 this time: a3 = a + (timestep/2)*k2
  • The derivative k3 is computed from state a3.
  • A full step forward in time from the start is taken, using k3: a4 = a + timestep*k3
  • The derivative k4 is computed from state a4.
  • The new state is given by a' = a + timestep * (k1 + 2*k2 + 2*k3 + k4) / 6

One approach is to store a2, a3 and a4 in new images. This would quadruple the amount of GPU memory needed, which is not desirable.

Alternatively we can use a larger neighborhood so that we can find the intermediate values we need. This is the approach we use in advection_RungeKutta4.vti

One optimisation opportunity in that implementation is that many of the intermediate values are computed more than once. For example, the value at state a4 for the central cell is computed three times - once for this cell, once for the cell to the left and once for the cell to the right. Fortunately OpenCL has a mechanism for reusing such computation - local memory. See #122 for a discussion of how to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant