comparison +time/ExplicitRungeKuttaDiscreteData.m @ 856:ee4cfb37534d feature/poroelastic

Merge with feature/d1_staggered to get RK timestepper for discrete data.
author Martin Almquist <malmquist@stanford.edu>
date Tue, 02 Oct 2018 13:39:10 -0700
parents
children 3c916a00033f
comparison
equal deleted inserted replaced
855:5751262b323b 856:ee4cfb37534d
1 classdef ExplicitRungeKuttaDiscreteData < time.Timestepper
2 properties
3 D
4 S % Function handle for time-dependent data
5 data % Matrix of data vectors, one column per stage
6 k
7 t
8 v
9 m
10 n
11 order
12 a, b, c, s % Butcher tableau
13 K % Stage rates
14 U % Stage approximations
15 T % Stage times
16 end
17
18
19 methods
20 function obj = ExplicitRungeKuttaDiscreteData(D, S, data, k, t0, v0, order)
21 default_arg('order', 4);
22 default_arg('S', []);
23 default_arg('data', []);
24
25 obj.D = D;
26 obj.S = S;
27 obj.k = k;
28 obj.t = t0;
29 obj.v = v0;
30 obj.m = length(v0);
31 obj.n = 0;
32 obj.order = order;
33 obj.data = data;
34
35 switch order
36 case 4
37 [obj.a, obj.b, obj.c, obj.s] = time.rkparameters.rk4();
38 otherwise
39 error('That RK method is not available');
40 end
41
42 obj.K = sparse(obj.m, obj.s);
43 obj.U = sparse(obj.m, obj.s);
44
45 end
46
47 function [v,t,U,T,K] = getV(obj)
48 v = obj.v;
49 t = obj.t;
50 U = obj.U; % Stage approximations in previous time step.
51 T = obj.T; % Stage times in previous time step.
52 K = obj.K; % Stage rates in previous time step.
53 end
54
55 function [a,b,c,s] = getTableau(obj)
56 a = obj.a;
57 b = obj.b;
58 c = obj.c;
59 s = obj.s;
60 end
61
62 function obj = step(obj)
63 v = obj.v;
64 a = obj.a;
65 b = obj.b;
66 c = obj.c;
67 s = obj.s;
68 S = obj.S;
69 dt = obj.k;
70 K = obj.K;
71 U = obj.U;
72 D = obj.D;
73 data = obj.data;
74
75 for i = 1:s
76 U(:,i) = v;
77 for j = 1:i-1
78 U(:,i) = U(:,i) + dt*a(i,j)*K(:,j);
79 end
80
81 K(:,i) = D*U(:,i);
82 obj.T(i) = obj.t + c(i)*dt;
83
84 % Data from continuous function and discrete time-points.
85 if ~isempty(S)
86 K(:,i) = K(:,i) + S(obj.T(i));
87 end
88 if ~isempty(data)
89 K(:,i) = K(:,i) + data(:,obj.n*s + i);
90 end
91
92 end
93
94 obj.v = v + dt*K*b;
95 obj.t = obj.t + dt;
96 obj.n = obj.n + 1;
97 obj.U = U;
98 obj.K = K;
99 end
100 end
101
102
103 methods (Static)
104 function k = getTimeStep(lambda)
105 switch obj.order
106 case 4
107 k = rk4.get_rk4_time_step(lambda);
108 otherwise
109 error('Time-step function not available for this order');
110 end
111 end
112 end
113
114 end