Mercurial > repos > public > sbplib
annotate +time/Rungekutta4.m @ 1037:2d7ba44340d0 feature/burgers1d
Pass scheme specific parameters as cell array. This will enabale constructDiffOps to be more general. In addition, allow for schemes returning function handles as diffOps, which is currently how non-linear schemes such as Burgers1d are implemented.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 18 Jan 2019 09:02:02 +0100 |
parents | c6fcee3fcf1b |
children |
rev | line source |
---|---|
0 | 1 classdef Rungekutta4 < time.Timestepper |
2 properties | |
3 D | |
4 S | |
5 F | |
6 k | |
7 t | |
8 v | |
9 m | |
10 n | |
11 end | |
12 | |
13 | |
14 methods | |
15 function obj = Rungekutta4(D, S, k, t0, v0) | |
16 obj.D = D; | |
17 obj.k = k; | |
18 obj.t = t0; | |
19 obj.v = v0; | |
20 obj.m = length(v0); | |
13
b18d3d201a71
Fixed initialization of step counter in timesteppers.
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
21 obj.n = 0; |
0 | 22 |
23 if S == 0 | |
24 obj.S = zeros(obj.m,1); | |
25 else | |
26 obj.S = S; | |
27 end | |
28 | |
75
ef5c9870f386
Cleand time.Rungekutta4 a bit.
Jonatan Werpers <jonatan@werpers.com>
parents:
13
diff
changeset
|
29 if S == 0 |
ef5c9870f386
Cleand time.Rungekutta4 a bit.
Jonatan Werpers <jonatan@werpers.com>
parents:
13
diff
changeset
|
30 obj.F = @(v,t)(obj.D*v); |
ef5c9870f386
Cleand time.Rungekutta4 a bit.
Jonatan Werpers <jonatan@werpers.com>
parents:
13
diff
changeset
|
31 else |
ef5c9870f386
Cleand time.Rungekutta4 a bit.
Jonatan Werpers <jonatan@werpers.com>
parents:
13
diff
changeset
|
32 obj.F = @(v,t)(obj.D*v + obj.S); |
ef5c9870f386
Cleand time.Rungekutta4 a bit.
Jonatan Werpers <jonatan@werpers.com>
parents:
13
diff
changeset
|
33 end |
0 | 34 end |
35 | |
36 function [v,t] = getV(obj) | |
37 v = obj.v; | |
38 t = obj.t; | |
39 end | |
40 | |
41 function obj = step(obj) | |
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:
75
diff
changeset
|
42 obj.v = time.rk.rungekutta_4(obj.v, obj.t, obj.k, obj.F); |
0 | 43 obj.t = obj.t + obj.k; |
44 obj.n = obj.n + 1; | |
45 end | |
46 end | |
47 | |
48 | |
49 methods (Static) | |
50 function k = getTimeStep(lambda) | |
51 k = rk4.get_rk4_time_step(lambda); | |
52 end | |
53 end | |
54 | |
55 end |