comparison +time/Rungekutta.m @ 846:c6fcee3fcf1b feature/burgers1d

Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 20 Sep 2018 17:51:19 +0200
parents
children 1c6f1595bb94
comparison
equal deleted inserted replaced
845:1e057b0f2fed 846:c6fcee3fcf1b
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 coeffs % The coefficents used for the RK time integration
9 end
10
11
12 methods
13 % Timesteps v_t = F(v,t), using RK with specfied order from t = t0 with
14 % timestep k and initial conditions v = v0
15 function obj = Rungekutta(F, k, t0, v0, order)
16 default_arg('order','4');
17 obj.F = F;
18 obj.k = k;
19 obj.t = t0;
20 obj.v = v0;
21 obj.n = 0;
22 % Extract the coefficients for the specified order
23 % used for the RK updates from the Butcher tableua.
24 [s,a,b,c] = butcherTableau(order);
25 obj.coeffs = struct('s',s,'a',a,'b',b,'c',c);
26 end
27
28 function [v,t] = getV(obj)
29 v = obj.v;
30 t = obj.t;
31 end
32
33 function obj = step(obj)
34 obj.v = time.rk.rungekutta(obj.v, obj.t, obj.k, obj.F, obj.coeffs);
35 obj.t = obj.t + obj.k;
36 obj.n = obj.n + 1;
37 end
38 end
39 end