-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsode15.f
More file actions
165 lines (121 loc) · 4.51 KB
/
sode15.f
File metadata and controls
165 lines (121 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
subroutine sode15(NEQ, NCTR, T0, Y0, u, atol,
1 rtol, Fcn, Jcn)
implicit none
c mkl function
double precision dlange
c Uebergabeparameter
external Fcn, Jcn
integer NEQ, NCTR
double precision T0, Y0, u, atol, rtol
c Zaehlervariable
integer Iter, m, k, j, klast, kopt, inc
integer nfevals, nsolves, nfailed, npds,
1 ndecomps, nsteps
logical Jcurrent
c helper Variablen integer
integer E, maxIt, maxk, nconhk, difU, tdir
c helper Variable double precision
double precision y, yp, t, dfdy, threshold, anaPD, hmin,
1 wt, rh, htspan, tfinal, hmax, absh, h, DfDt, ml, mu,
2 abshlast, dif
c parameter double precision
c Gamma_k, alpha, invGa
double precision G, alpha, invGa, erconst, eps
c parameter declartion integer
parameter(maxIt = 4, maxk = 5, inc = 1)
c Uebergabeparameter dimension
dimension T0(2), Y0(NEQ), u(NCTR)
c helper dimension integer
dimension E(NEQ, NEQ)
c helper dimension double precision
dimension Y(NEQ), dfdy(NEQ, NEQ), yp(NEQ), wt(NEQ),
1 DfDt(NEQ), dif(NEQ, maxk+2)
c parameter dimension
dimension G(5), alpha(5), invGa(5), erconst(5), difU(5, 5)
c parameter declartion double precision
c ToDo: eps bestimmen
parameter(eps = 2.2204D-16, ml = 1.0, mu= 0.0)
c parameter declartion array
parameter(G = (/ 1.0, 3.0/2.0, 11.0/6.0, 25.0/12.0,
1 137.0/60.0 /), alpha = (/-37.0/200.0, -1.0/9.0,
2 -0.0823, -0.0415, 0.0/),
3 invGa = 1.0 / (G * (1.0 - alpha)))
parameter (difU =(/
$ -1, 0, 0, 0, 0,
$ -2, 1, 0, 0, 0,
$ -3, 3, -1, 0, 0,
$ -4, 6, -4, 1, 0,
$ -5, 10,-10, 5, -1/))
parameter (erconst = (/ alpha(1) * G(1) + 1.0 / 2,
1 alpha(2) * G(2) + 1.0 / 3, alpha(3) * G(3) + 1.0 / 4,
2 alpha(4) * G(4) + 1.0 / 5, alpha(5) * G(5) + 1.0 / 6/))
data k/1/, m/1/, klast/1/
E = 0
do Iter = 1, NEQ
E(Iter, Iter) = 1
enddo
threshold = atol / rtol
htspan = abs(T0(2) - T0(1))
tfinal = T0(2)
c By default, hmax = 1/10 of the interval
hmax = 0.1 * htspan
tdir = sign(1.0, (T0(2) - T0(1)))
c Stats
nsteps = 0
nfailed = 0
nfevals = 0
npds = 0
ndecomps = 0
nsolves = 0
dif = 0
t = T0(1)
y = Y0
c yp = 0
c dfdy = 0
call Fcn (NEQ, T0(1), Y0, u, yp)
nfevals = nfevals + 1
call Jcn(NEQ, T0(1), Y0, u, dfdy, NEQ)
npds = npds + 1
Jcurrent = .true.
hmin = 16 * eps * abs(t)
wt = max(abs(y),threshold)
c rh = 1.25 * maxval(abs(yp/wt), NEQ) / sqrt(rtol)
c ToDo: spaeter absh durch hmax ersetzen
c absh = min(hmax, htspan)
c if (absh * rh > 1) then
c absh = 1 / rh
c end if
c absh = max(absh, hmin)
c tdel = (t + tdir*min(sqrt(eps)*max(abs(t),abs(t+h)),absh))-t
c ToDo timeinvariant deshalb kein dfdt nötig
c f1 = feval(odeFcn,t+tdel,y,odeArgs{:});
c call Fcn (NEQ, t+tdel, Y0, u, f1)
c nfevals = nfevals + 1;
c dfdt = (f1 - yp) / tdel;
DfDt = 0
call dgemv('N', NEQ, NEQ, ml, dfdy, NEQ, yp, inc,
1 mu, DfDt,inc)
c
rh = 1.25 * sqrt(0.5 * maxval(abs( DfDt / wt)) / rtol)
absh = min(hmax, htspan)
if (absh * rh .GT. 1) then
absh = 1 / rh
end if
absh = max(absh, hmin)
c Matlab 417
h = tdir * absh
abshlast = absh
dif(:,1) = h * yp
hinvGak = h * invGa(k)
c Matlab 425
c % Initialize.
ck = 1; % start at order 1 with BDF1
cK = 1; % K = 1:k
cklast = k;
cabshlast = absh;
cdif = zeros(neq,maxk+2);
cdif(:,1) = h * yp;
chinvGak = h * invGa(k);
cnconhk = 0; % steps taken with current h and k
cMiter = Mt - hinvGak * dfdy;
end subroutine