Mercurial > repos > public > sbplib
annotate +time/+rk/General.m @ 995:10c5eda235b7 feature/timesteppers
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 09 Jan 2019 22:57:13 +0100 |
parents | 44e7e497c3b7 |
children |
rev | line source |
---|---|
992
bbd165cc585c
Move time.Rungekutta to time.rk.General
Jonatan Werpers <jonatan@werpers.com>
parents:
986
diff
changeset
|
1 classdef General < time.Timestepper |
888
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
2 properties |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
3 F % RHS of the ODE |
918
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
4 dt % Time step |
888
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
5 t % Time point |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
6 v % Solution vector |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
7 n % Time level |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
8 scheme % The scheme used for the time stepping, e.g rk4, rk6 etc. |
995
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
9 bt |
918
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
10 V % All stage approximations in most recent time step |
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
11 K % All stage rates in most recent time step |
888
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
12 end |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
13 |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
14 |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
15 methods |
995
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
16 % Timesteps v_t = F(t,v), using the specified ButcherTableau |
993
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
17 % from t = t0 with timestep dt and initial conditions v(0) = v0 |
995
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
18 function obj = General(F, dt, t0, v0, bt) |
993
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
19 assertType(bt, 'time.rk.ButcherTableau') |
888
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
20 obj.F = F; |
918
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
21 obj.dt = dt; |
888
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
22 obj.t = t0; |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
23 obj.v = v0; |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
24 obj.n = 0; |
918
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
25 |
993
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
26 assert(bt.isExplicit()) |
995
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
27 obj.bt = bt; |
888
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
28 end |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
29 |
918
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
30 % v: Current solution |
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
31 % t: Current time |
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
32 % V: All stage approximations in most recent time step |
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
33 % K: All stage rates in most recent time step |
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
34 % T: Time points (corresponding to V and K) in most recent time step |
995
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
35 function [v,t] = getV(obj) |
888
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
36 v = obj.v; |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
37 t = obj.t; |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
38 end |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
39 |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
40 function obj = step(obj) |
995
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
41 s = obj.bt.nStages(); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
42 a = obj.bt.a; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
43 b = obj.bt.b; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
44 c = obj.bt.c; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
45 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
46 % Compute rates K |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
47 K = zeros(length(v), s); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
48 for i = 1:s |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
49 V_i = obj.v; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
50 for j = 1:i-1 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
51 V_i = V_i + dt*a(i,j)*K(:,j); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
52 end |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
53 K(:,i) = F(t+dt*c(i), V_i); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
54 end |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
55 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
56 % Compute updated solution |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
57 v_next = v; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
58 for i = 1:s |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
59 v_next = v_next + dt*b(i)*K(:,i); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
60 end |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
61 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
62 obj.v = v_next; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
63 obj.t = obj.t + obj.dt; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
64 obj.n = obj.n + 1; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
65 end |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
66 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
67 % TBD: Method name |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
68 % TBD: Parameter name |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
69 % |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
70 % Takes a regular step but with discreteRates(:,i) added to RHS for stage i. |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
71 % v_t = F(t,v) + discreteRates(:, ...) |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
72 % |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
73 % Also returns the stage approximations (V) and stage rates (K). |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
74 function [v,t, V, K] = stepWithDiscreteData(obj, discreteRates) |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
75 s = obj.bt.nStages(); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
76 a = obj.bt.a; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
77 b = obj.bt.b; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
78 c = obj.bt.c; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
79 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
80 % Compute rates K and stage approximations V |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
81 K = zeros(length(v), s); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
82 V = zeros(length(v), s); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
83 for i = 1:s |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
84 V_i = obj.v; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
85 for j = 1:i-1 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
86 V_i = V_i + dt*a(i,j)*K(:,j); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
87 end |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
88 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
89 K_i = F(t+dt*c(i), V_i); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
90 K_i = K_i + discreteRates(:,i); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
91 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
92 V(:,i) = V_i; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
93 K(:,i) = K_i; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
94 end |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
95 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
96 % Compute updated updated solution |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
97 v_next = v; |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
98 for i = 1:s |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
99 v_next = v_next + dt*b(i)*K(:,i); |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
100 end |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
101 |
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
102 obj.v = v_next; |
918
679f4ddd982f
Add properties for stage approximations and stage rates in the Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
888
diff
changeset
|
103 obj.t = obj.t + obj.dt; |
888
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
104 obj.n = obj.n + 1; |
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
105 end |
933
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
106 |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
107 % Returns a vector of time points, including substage points, |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
108 % in the time interval [t0, tEnd]. |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
109 % The time-step obj.dt is assumed to be aligned with [t0, tEnd] already. |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
110 function tvec = timePoints(obj, t0, tEnd) |
995
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
111 % TBD: Should this be implemented here or somewhere else? |
933
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
112 N = round( (tEnd-t0)/obj.dt ); |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
113 tvec = zeros(N*obj.s, 1); |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
114 s = obj.coeffs.s; |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
115 c = obj.coeffs.c; |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
116 for i = 1:N |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
117 ind = (i-1)*s+1 : i*s; |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
118 tvec(ind) = ((i-1) + c')*obj.dt; |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
119 end |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
120 end |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
121 |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
122 % Returns a vector of quadrature weights corresponding to grid points |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
123 % in time interval [t0, tEnd], substage points included. |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
124 % The time-step obj.dt is assumed to be aligned with [t0, tEnd] already. |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
125 function weights = quadWeights(obj, t0, tEnd) |
995
10c5eda235b7
Full use of butcher tableau in time.rk.General. Inline rungekutta step methods
Jonatan Werpers <jonatan@werpers.com>
parents:
993
diff
changeset
|
126 % TBD: Should this be implemented here or somewhere else? |
933
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
127 N = round( (tEnd-t0)/obj.dt ); |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
128 b = obj.coeffs.b; |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
129 weights = repmat(b', N, 1); |
34b3d092a4d0
Add methods timePoints and quadWeights to Rungekutta class.
Martin Almquist <malmquist@stanford.edu>
parents:
932
diff
changeset
|
130 end |
888
8732d6bd9890
Add general Runge-Kutta class
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
131 end |
993
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
132 |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
133 methods(Static) |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
134 % TBD: Function name |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
135 function ts = methodFromStr(F, dt, t0, v0, methodStr, discreteData) |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
136 default_arg('discreteData', []); |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
137 |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
138 try |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
139 bt = time.rk.ButcherTableau.(method); |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
140 catch |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
141 error('Runge-Kutta method ''%s'' is not implemented', methodStr) |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
142 end |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
143 |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
144 ts = time.rk.General(F, dt, t0, v0, bt, discreteData); |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
145 end |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
146 end |
44e7e497c3b7
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
Jonatan Werpers <jonatan@werpers.com>
parents:
992
diff
changeset
|
147 end |