comparison +time/Rungekutta.m @ 888:8732d6bd9890 feature/timesteppers

Add general Runge-Kutta class - Add a general Runge-Kutta class which time integrates the solution based on coefficients obtained from a Butcher tableau - Add butcher tableau which returns coefficents for the specified Runge-Kutta method - Remove RungKutta4proper, since obsolete
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 15 Nov 2018 17:10:01 -0800
parents
children 679f4ddd982f
comparison
equal deleted inserted replaced
887:50d5a3843099 888:8732d6bd9890
1 classdef Rungekutta < time.Timestepper
2 properties
3 F % RHS of the ODE
4 k % Time step
5 t % Time point
6 v % Solution vector
7 n % Time level
8 scheme % The scheme used for the time stepping, e.g rk4, rk6 etc.
9 end
10
11
12 methods
13 % Timesteps v_t = F(v,t), using the specified RK method from t = t0 with
14 % timestep k and initial conditions v = v0
15 function obj = Rungekutta(F, k, t0, v0, method)
16 default_arg('method',"rk4");
17 obj.F = F;
18 obj.k = k;
19 obj.t = t0;
20 obj.v = v0;
21 obj.n = 0;
22 % TODO: method "rk4" is also implemented in the butcher tableau, but the rungekutta_4.m implementation
23 % might be slightly more efficient. Need to do some profiling before deciding whether or not to keep it.
24 if (method == "rk4")
25 obj.scheme = @time.rk.rungekutta_4;
26 else
27 % Extract the coefficients for the specified method
28 % used for the RK updates from the Butcher tableua.
29 [s,a,b,c] = time.rk.butcherTableau(method);
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
33 end
34
35 function [v,t] = getV(obj)
36 v = obj.v;
37 t = obj.t;
38 end
39
40 function obj = step(obj)
41 obj.v = obj.scheme(obj.v, obj.t, obj.k, obj.F);
42 obj.t = obj.t + obj.k;
43 obj.n = obj.n + 1;
44 end
45 end
46 end