Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I Resolution of a PDE with second order Runge-Kutta

  1. Oct 3, 2017 #1
    Hi, I want to solve the p.d.e.:

    ##\frac{\partial u(x,t)}{\partial t} - \frac{\partial^2 u(x,t)}{\partial x^2}=f(x,t)##,

    with periodic boundary conditions ##u(x,t)=u(L,t)##.

    using a second order Runge-Kutta method in time. However, I am not having the proper results when I apply this method to a particular problem. I don't know if I am doing something wrong in the code, or if I am not applying the Runge-Kutta method properly.

    So, this is what I did. First I wrote:
    ##\frac{\partial u(x,t)}{\partial t}=f(x,t)+\frac{\partial^2 u(x,t)}{\partial x^2}=g(t,x,u)##,

    Then I've considered the semi discrete problem, within the Runge-Kutta scheme:

    ##u^{n+1}=u^n+\Delta t k_2##,

    With: ##k_1=g(t^n,x,u^n)=f^n(x)+\frac{\partial^2 u^n(x)}{\partial x^2}##
    and: ##k_2=g(t^n+\frac{\Delta t}{2},x,u^n+\frac{\Delta t}{2}k_1)= f^{n+\frac{1}{2}}(x)+\frac{\partial^2}{\partial x^2}\left( u^n(x)+\frac{\Delta t}{2}k_1 \right)##

    So, this is not giving the correct result, and I wanted to know if I am applying the scheme in the proper way. I am assuming all functions are periodic with period L, so I can solve this by means of Fourier methods in the spatial variable.
     
  2. jcsd
  3. Oct 7, 2017 #2
    Runge-Kutta can only solve first order differential equations. To solve a second order equation, you will need to convert it to a system of first order equations. This is done by creating a new variable
    $$v=\frac{\partial u}{\partial x}$$
    so the original ODE is rewritten as
    $$\frac{\partial v}{\partial x}=v-f(x,t)$$
    The system is now
    $$\frac{\partial}{\partial x}\begin{bmatrix} v\\ u\end{bmatrix}=\begin{bmatrix}v-f(x,t)\\ v\end{bmatrix}$$
    This can now be solved with the RK method.
     
  4. Oct 8, 2017 #3
    Hi. Thanks for your reply. The PDE I've posted is first order in time, and I am willing to use a Runge Kutta method in the time variable. However, when I do so, while treating the space variable with a spectral method, the solution is like evolving too slow in time, almost not evolving at all.
     
  5. Oct 8, 2017 #4
    Oh sorry, I misread the first derivative as being with respect to space. You are effectively solving the heat equation with a varying source term. RK is not able to solve problems of this type as far as I know. A more common approach to this problem is the Crank-Nicholson scheme which will give a solution that is second order accurate in both space and time. Are you familiar with this method?
     
  6. Oct 8, 2017 #5
    Yes, I've used Crank-Nicolson already for this problem. But anyway, I wanted to use Runge-Kutta, it can be used with what is called the method of lines, where the spatial operator is treated somehow (finite difference, spectral methods, etc.) and one obtains a set of ordinary differential equations. I've found a paper that shows this with finite differences, and a fourth order RK in time. The paper tells how to treat the runge kutta scheme in a way to get stability with no so restrictive time steps. However, I was trying a second order RK, and using other approach in the space variable (I've found the paper after trying, but I think I have done things in the correct way, at least formally, and I posted this to check that in particular).

    However, I don't obtain good results, even for a very small ##\Delta t##, and I think that if the problem were stability, the solution should blow up, but what I obtain is that the problem is evolving really really slow in time. Perhaps I should check the program, or if someone sees something in wrong in what I did, that would be great too.

    This is the paper I've found where you can see in detail how this is done for finite differences in space: http://www.sciencedirect.com/science/article/pii/0307904X77900063
     
  7. Oct 8, 2017 #6
    Okay, I'm not very familiar with this method but here is my interpretation. It looks like you should first discritize the spatial derivative such that
    $$\frac{du_{i}}{dt}=f_{i}+\frac{u_{i+1}-2u_{i}+u_{i-1}}{h_{x}^{2}}$$
    This leads to
    $$\frac{d}{dt}\mathbf{u}=\mathbf{f}$$
    where
    $$\mathbf{u}=\begin{bmatrix}u_{1}\\ \vdots\\ u_{i}\\ \vdots\\ u_{N}\end{bmatrix}$$
    $$\mathbf{f}=\begin{bmatrix}f(0,t)+u^{\prime}(0,t)\\ \vdots\\ f_{i}+\frac{u_{i+1}-2u_{i}+u_{i-1}}{h_{x}^{2}}\\ \vdots\\ f(L,t)+u^{\prime}(L,t)\end{bmatrix}$$
    Then you can apply RK to the vector equation listed above, marching the whole system forward at each time step.
     
  8. Oct 8, 2017 #7
    Ok, thanks for your reply. I haven't used finite differences in the spatial derivative, but instead of that a Fourier approach. Tomorrow I'll give you the details of what I did (because I don't have it in here). But basically, I applied a Fourier transform to get the derivatives, following the steps detailed at the beginning of the topic. However, I might have committed a mistake, because as I did it, it looks like if I had started by discretizing the time variable, and I didn't worked it with much care. But what I did is that, I just applied the Runge-Kutta formula in the way detailed above, applying the spatial derivative in Fourier space at each time step.

    So, if I remember it right, this is what I did:

    ##u^{n}=\sum u_k e^{i2 \pi k x}##,
    ##f^{n}=\sum f_k e^{i2 \pi k x}##,

    Then replacing in the equation ##u^{n+1}=f^n+\Delta t k_2## I've obtained the Fourier coefficients for the advanced time step.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Resolution of a PDE with second order Runge-Kutta
Loading...