changeset 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
files +time/+rk4/rungekutta_4RV.m
diffstat 1 files changed, 30 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/+time/+rk4/rungekutta_4RV.m	Thu Sep 13 18:14:54 2018 +0200
+++ b/+time/+rk4/rungekutta_4RV.m	Fri Sep 14 16:40:19 2018 +0200
@@ -2,17 +2,36 @@
 % starting from v_0 and where the function F(v,t) gives the
 % time derivatives.
 function v = rungekutta_4RV(v, t , k, F, RV)
-    k1 = F(v, t, RV.getViscosity());
-	
-    RV.update(v+0.5*k*k1, v, 0.5*k);
-	k2 = F(v+0.5*k*k1, t+0.5*k, RV.getViscosity());
-	
-	RV.update(v+0.5*k*k2, v, 0.5*k);
-    k3 = F(v+0.5*k*k2, t+0.5*k, RV.getViscosity());
+    
+
+    v1 = v;
+    v2 = v1 + k/2*F(v1,t, RV.getViscosity());
+    
+    RV.update(v2, v1, k/2);
+    v3 = v1 + k/2*F(v2,t+k/2, RV.getViscosity());
+    
+    RV.update(v3, v1, k/2);
+    v4 = v1 + k*F(v3,t+k/2, RV.getViscosity());
     
-    RV.update(v+k*k3, v, k);
-    k4 = F(v+k*k3,t+k, RV.getViscosity());
+    RV.update(v4,v1,k);
+    k4 = k*F(v4,t+k, RV.getViscosity());
+
+    v_next = 1/6*(-2*v1 + 2*v2 + 4*v3 + 2*v4 + k4);
+    RV.update(v_next,v,k);
+    v = v_next;
+    
+
+    % k1 = F(v, t, RV.getViscosity());
     
-    RV.update(v + (1/6)*(k1+2*(k2+k3)+k4)*k, v, k);
-    v = v + (1/6)*(k1+2*(k2+k3)+k4)*k;
+    % RV.update(v+0.5*k*k1, v, 0.5*k);
+    % k2 = F(v+0.5*k*k1, t+0.5*k, RV.getViscosity());
+    
+    % RV.update(v+0.5*k*k2, v, 0.5*k);
+    % k3 = F(v+0.5*k*k2, t+0.5*k, RV.getViscosity());
+    
+    % RV.update(v+k*k3, v, k);
+    % k4 = F(v+k*k3,t+k, RV.getViscosity());
+    
+    % RV.update(v + (1/6)*(k1+2*(k2+k3)+k4)*k, v, k);
+    % v = v + (1/6)*(k1+2*(k2+k3)+k4)*k;
 end
\ No newline at end of file