Efficient Computation of k2 in RK4 for Numerical RHS | PF Discussion

In summary, the conversation discusses the process of computing ##k_2## in the standard RK4 procedure for solving Navier-Stokes x-momentum using a finite-volume approach. The problem statement involves determining the time derivative ##d_t y## for an unsteady term and the advective terms. It is mentioned that ##d_xu^2## can be finite differenced as ##2ud_xu## and that the time integration can be done with explicit Euler, but the conversation focuses on using RK4. It is suggested to take one Euler step over ##1\over 2## the interval and recalculate ##\partial \vec u\over\partial t## to determine ##k_2##. The concept of ##
  • #1
member 428835
Hi PF!

I am trying to compute ##d_t y = d_x u^2##. Following standard RK4 procedure outlined by wikipedia as https://en.wikipedia.org/wiki/Runge–Kutta_methods
I am forced to compute ##k_2##. If the RHS is analytic, the fractional stepping is direct. However, the RHS gradient is finite differenced: ##(u_{i+1}^2-u_{i-1}^2)/\Delta x##. Then how would you compute ##k_2##?

Thanks!
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Hi,

Is a bit cryptic to me. I always thought ##d_xu^2 = 2u\;d_xu##
But what is ##t## doing on the LHS ? Could you be a bit clearer in the problem statement ? Are you integrating over ##t## or over ##x## ?
 
  • #3
BvU said:
Hi,

Is a bit cryptic to me. I always thought ##d_xu^2 = 2u\;d_xu##
You're right, but finite differencing ##2ud_xu## is equivalent to finite differencing ##d_xu^2##, so I left it in this form for ease.
BvU said:
But what is ##t## doing on the LHS ? Could you be a bit clearer in the problem statement ? Are you integrating over ##t## or over ##x## ?
So I'm numerically solving Navier-Stokes x-momentum using a finite-volume approach. The unsteady term is ##d_tu## and then the RHS is the advective terms. So I have ##u## for all spatial nodes along ##x## at a current time step ##n##, and I'm time-integrating to get ##u## at time ##n+1##. I can use explicit Euler no problem, but I'm confused how to time-integrate via RK4. Any ideas?
 
  • #4
Ok, so your $$d_t y = d_x u^2$$ is shorthand for $${\partial u\over\partial t} + {\partial u^2\over\partial x} = 0$$ with
$$u(x,0) = g(x) $$ in tandem with $$u(0,t)= \phi_0(t)$$ where ##g(0) = \phi_0(0)##.
(this is what I remember from the advection equation for crystal size distributions).

Right so far ?

So with RK4 you take one Euler step over ##1\over 2## the interval and recalculate ##\partial \vec u\over \partial t## there. Gives you ##k_2##
 
  • #5
BvU said:
Ok, so your $$d_t y = d_x u^2$$ is shorthand for $${\partial u\over\partial t} + {\partial u^2\over\partial x} = 0$$ with
$$u(x,0) = g(x) $$ in tandem with $$u(0,t)= \phi_0(t)$$ where ##g(0) = \phi_0(0)##.
(this is what I remember from the advection equation for crystal size distributions).

Right so far ?
Yep, that sounds right!

BvU said:
So with RK4 you take one Euler step over ##1\over 2## the interval and recalculate ##\partial \vec u\over \partial t## there. Gives you ##k_2##
Can you explain what you mean by "one Euler step"? I think this is what's getting me stuck.
 
  • #6
From the link $$ k_1 = h f(t_n,y_n) = h f(y_n)$$ since your ##f## is ##d_xu^2##, so not directly dependent on ##t##.
His ##y## is your ##\vec u## : $$ \vec k_1 = h\,{\;\vec {\partial u^2}\over \partial x} $$
In other words: determine the time derivative ##\partial \vec u\over\partial t## -- a vector -- and add ##h\over 2 ## times this vector to ##\vec u##. That way you do an Euler step ##h\over 2## to give you a new ##\vec u_n + {\vec k_1\over 2}## from which you establish ##\vec k_2 ##.

I must admit that I don't grok what is ##\vec u^2## in ##d_x \vec u^2## but I hope you can explain how to establish the time derivative :rolleyes: ?
 
Last edited:
  • Like
Likes member 428835

1. What is RK4 and why is it used in numerical computation?

RK4 (Runge-Kutta method of order 4) is a numerical method for solving ordinary differential equations. It is used because it is a higher-order method, meaning it is more accurate than simpler methods such as Euler's method, while still being relatively easy to implement.

2. What is k2 in RK4 and why is it important?

In RK4, k2 is the second slope estimation used to improve the accuracy of the solution. It is important because it takes into account the curvature of the function, which can greatly impact the accuracy of the final solution.

3. How is k2 calculated in RK4?

k2 is calculated by first computing the slope at the midpoint of the interval, using the Euler method. This slope is then used to estimate the value of the function at the midpoint, which is then used to calculate the second slope estimation, k2.

4. What are some potential sources of error when computing k2 in RK4?

Some potential sources of error when computing k2 in RK4 include rounding errors in the calculations, errors in the initial conditions or in the function being solved, and errors in the chosen step size. These errors can accumulate and affect the accuracy of the final solution.

5. How can the computation of k2 be made more efficient in RK4?

One way to make the computation of k2 more efficient in RK4 is to use adaptive step sizes. This means adjusting the step size based on the behavior of the function, so that smaller steps are taken in regions where the function is changing rapidly, and larger steps are taken in regions where it is changing slowly. This can reduce the number of calculations needed to compute k2 and improve the overall efficiency of the method.

Similar threads

  • Calculus and Beyond Homework Help
Replies
3
Views
2K
  • Special and General Relativity
Replies
8
Views
2K
Replies
1
Views
591
  • Differential Equations
Replies
1
Views
3K
  • Differential Equations
Replies
1
Views
2K
  • STEM Academic Advising
Replies
13
Views
2K
Replies
8
Views
7K
  • Differential Equations
Replies
3
Views
4K
Back
Top