comparison +time/+rk4/rungekutta_4RV.m @ 842:619561e9ec0e feature/burgers1d

Reformulate the RK4 time stages in order to easier see how the residual should be updated.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 14 Sep 2018 16:40:19 +0200
parents 008496ca38f3
children f63b99f0729d
comparison
equal deleted inserted replaced
835:008496ca38f3 842:619561e9ec0e
1 % Takes one time step of size k using the rungekutta method 1 % Takes one time step of size k using the rungekutta method
2 % starting from v_0 and where the function F(v,t) gives the 2 % starting from v_0 and where the function F(v,t) gives the
3 % time derivatives. 3 % time derivatives.
4 function v = rungekutta_4RV(v, t , k, F, RV) 4 function v = rungekutta_4RV(v, t , k, F, RV)
5 k1 = F(v, t, RV.getViscosity());
6
7 RV.update(v+0.5*k*k1, v, 0.5*k);
8 k2 = F(v+0.5*k*k1, t+0.5*k, RV.getViscosity());
9
10 RV.update(v+0.5*k*k2, v, 0.5*k);
11 k3 = F(v+0.5*k*k2, t+0.5*k, RV.getViscosity());
12 5
13 RV.update(v+k*k3, v, k); 6
14 k4 = F(v+k*k3,t+k, RV.getViscosity()); 7 v1 = v;
8 v2 = v1 + k/2*F(v1,t, RV.getViscosity());
15 9
16 RV.update(v + (1/6)*(k1+2*(k2+k3)+k4)*k, v, k); 10 RV.update(v2, v1, k/2);
17 v = v + (1/6)*(k1+2*(k2+k3)+k4)*k; 11 v3 = v1 + k/2*F(v2,t+k/2, RV.getViscosity());
12
13 RV.update(v3, v1, k/2);
14 v4 = v1 + k*F(v3,t+k/2, RV.getViscosity());
15
16 RV.update(v4,v1,k);
17 k4 = k*F(v4,t+k, RV.getViscosity());
18
19 v_next = 1/6*(-2*v1 + 2*v2 + 4*v3 + 2*v4 + k4);
20 RV.update(v_next,v,k);
21 v = v_next;
22
23
24 % k1 = F(v, t, RV.getViscosity());
25
26 % RV.update(v+0.5*k*k1, v, 0.5*k);
27 % k2 = F(v+0.5*k*k1, t+0.5*k, RV.getViscosity());
28
29 % RV.update(v+0.5*k*k2, v, 0.5*k);
30 % k3 = F(v+0.5*k*k2, t+0.5*k, RV.getViscosity());
31
32 % RV.update(v+k*k3, v, k);
33 % k4 = F(v+k*k3,t+k, RV.getViscosity());
34
35 % RV.update(v + (1/6)*(k1+2*(k2+k3)+k4)*k, v, k);
36 % v = v + (1/6)*(k1+2*(k2+k3)+k4)*k;
18 end 37 end