comparison +time/Rungekutta.m @ 849:5b180c76578e feature/burgers1d

Use the old implementation for RK4 until the different methods are profiled.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 21 Sep 2018 09:13:03 +0200
parents 1c6f1595bb94
children 4e5e53d6336c
comparison
equal deleted inserted replaced
848:c8ea9bbdc62c 849:5b180c76578e
3 F % RHS of the ODE 3 F % RHS of the ODE
4 k % Time step 4 k % Time step
5 t % Time point 5 t % Time point
6 v % Solution vector 6 v % Solution vector
7 n % Time level 7 n % Time level
8 coeffs % The coefficents used for the RK time integration 8 scheme % The coefficents used for the RK time integration
9 end 9 end
10 10
11 11
12 methods 12 methods
13 % Timesteps v_t = F(v,t), using RK with specfied order from t = t0 with 13 % Timesteps v_t = F(v,t), using RK with specfied order from t = t0 with
17 obj.F = F; 17 obj.F = F;
18 obj.k = k; 18 obj.k = k;
19 obj.t = t0; 19 obj.t = t0;
20 obj.v = v0; 20 obj.v = v0;
21 obj.n = 0; 21 obj.n = 0;
22 % Extract the coefficients for the specified order 22 % TBD: Order 4 is also implemented in the butcher tableau, but the rungekutta_4.m implementation
23 % used for the RK updates from the Butcher tableua. 23 % might be slightly more efficient. Need to do some profiling before deciding whether or not to keep it.
24 [s,a,b,c] = butcherTableau(order); 24 if (order == 4)
25 obj.coeffs = struct('s',s,'a',a,'b',b,'c',c); 25 obj.scheme = @time.rk.rungekutta_4;
26 else
27 % Extract the coefficients for the specified order
28 % used for the RK updates from the Butcher tableua.
29 [s,a,b,c] = time.rk.butcherTableau(order);
30 coeffs = struct('s',s,'a',a,'b',b,'c',c);
31 obj.scheme = @(v,t,dt,F) time.rk.rungekutta(v, t , dt, F, coeffs);
32 end
26 end 33 end
27 34
28 function [v,t] = getV(obj) 35 function [v,t] = getV(obj)
29 v = obj.v; 36 v = obj.v;
30 t = obj.t; 37 t = obj.t;
31 end 38 end
32 39
33 function obj = step(obj) 40 function obj = step(obj)
34 obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, obj.F, obj.coeffs); 41 obj.v = obj.scheme(obj.v, obj.t, obj.k, obj.F);
35 obj.t = obj.t + obj.k; 42 obj.t = obj.t + obj.k;
36 obj.n = obj.n + 1; 43 obj.n = obj.n + 1;
37 end 44 end
38 end 45 end
39 end 46 end