annotate +time/Rungekutta.m @ 1025:ac80bedc8df7 feature/advectionRV

Clean up of Utux2d
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Mon, 07 Jan 2019 16:26:05 +0100
parents 4e5e53d6336c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
846
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
1 classdef Rungekutta < time.Timestepper
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
2 properties
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
3 F % RHS of the ODE
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
4 k % Time step
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
5 t % Time point
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
6 v % Solution vector
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
7 n % Time level
850
4e5e53d6336c Correct documentation of Rungekutta
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 849
diff changeset
8 scheme % The scheme used for the time stepping, e.g rk4, rk6 etc.
846
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
9 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
10
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
11
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
12 methods
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
13 % Timesteps v_t = F(v,t), using RK with specfied order from t = t0 with
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
14 % timestep k and initial conditions v = v0
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
15 function obj = Rungekutta(F, k, t0, v0, order)
847
1c6f1595bb94 Clean up in RK time stepper schemes
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 846
diff changeset
16 default_arg('order',4);
846
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
17 obj.F = F;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
18 obj.k = k;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
19 obj.t = t0;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
20 obj.v = v0;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
21 obj.n = 0;
849
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
22 % TBD: Order 4 is also implemented in the butcher tableau, but the rungekutta_4.m implementation
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
23 % might be slightly more efficient. Need to do some profiling before deciding whether or not to keep it.
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
24 if (order == 4)
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
25 obj.scheme = @time.rk.rungekutta_4;
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
26 else
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
27 % Extract the coefficients for the specified order
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
28 % used for the RK updates from the Butcher tableua.
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
29 [s,a,b,c] = time.rk.butcherTableau(order);
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
30 coeffs = struct('s',s,'a',a,'b',b,'c',c);
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
31 obj.scheme = @(v,t,dt,F) time.rk.rungekutta(v, t , dt, F, coeffs);
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
32 end
846
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
33 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
34
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
35 function [v,t] = getV(obj)
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
36 v = obj.v;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
37 t = obj.t;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
38 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
39
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
40 function obj = step(obj)
849
5b180c76578e Use the old implementation for RK4 until the different methods are profiled.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 847
diff changeset
41 obj.v = obj.scheme(obj.v, obj.t, obj.k, obj.F);
846
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
42 obj.t = obj.t + obj.k;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
43 obj.n = obj.n + 1;
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
44 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
45 end
c6fcee3fcf1b Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
46 end