ode 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/MIT-License.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +12 -0
- data/SciPy-License.txt +30 -0
- data/ext/ode/extconf.rb +25 -0
- data/ext/ode/ode.c +124 -0
- data/ext/ode/odepack.h +6 -0
- data/ext/ode/odepack/blkdta000.f +26 -0
- data/ext/ode/odepack/bnorm.f +30 -0
- data/ext/ode/odepack/cfode.f +112 -0
- data/ext/ode/odepack/ewset.f +32 -0
- data/ext/ode/odepack/fnorm.f +22 -0
- data/ext/ode/odepack/intdy.f +84 -0
- data/ext/ode/odepack/lsoda.f +1654 -0
- data/ext/ode/odepack/prja.f +177 -0
- data/ext/ode/odepack/readme +84 -0
- data/ext/ode/odepack/solsy.f +72 -0
- data/ext/ode/odepack/srcma.f +55 -0
- data/ext/ode/odepack/stoda.f +637 -0
- data/ext/ode/odepack/vmnorm.f +18 -0
- data/ext/ode/odepack/vode.f +3667 -0
- data/ext/ode/odepack/xerrwv.f +114 -0
- data/ext/ode/odepack/zvode.f +3658 -0
- data/lib/ode.rb +9 -0
- data/lib/ode/methods.rb +15 -0
- data/lib/ode/solver.rb +42 -0
- data/lib/ode/version.rb +3 -0
- data/ode.gemspec +23 -0
- metadata +105 -0
@@ -0,0 +1,177 @@
|
|
1
|
+
subroutine prja (neq, y, yh, nyh, ewt, ftem, savf, wm, iwm,
|
2
|
+
1 f, jac)
|
3
|
+
clll. optimize
|
4
|
+
external f, jac
|
5
|
+
integer neq, nyh, iwm
|
6
|
+
integer iownd, iowns,
|
7
|
+
1 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
|
8
|
+
2 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
|
9
|
+
integer iownd2, iowns2, jtyp, mused, mxordn, mxords, isav
|
10
|
+
integer i, i1, i2, ier, ii, j, j1, jj, lenp,
|
11
|
+
1 mba, mband, meb1, meband, ml, ml3, mu, np1
|
12
|
+
double precision y, yh, ewt, ftem, savf, wm, rsav
|
13
|
+
double precision rowns,
|
14
|
+
1 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround
|
15
|
+
double precision rownd2, rowns2, pdnorm
|
16
|
+
double precision con, fac, hl0, r, r0, srur, yi, yj, yjj,
|
17
|
+
1 vmnorm, fnorm, bnorm
|
18
|
+
dimension neq(1), y(1), yh(nyh,*), ewt(1), ftem(1), savf(1),
|
19
|
+
1 wm(*), iwm(*), rsav(240), isav(50)
|
20
|
+
common /ls0001/ rowns(209),
|
21
|
+
2 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround,
|
22
|
+
3 iownd(14), iowns(6),
|
23
|
+
4 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
|
24
|
+
5 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
|
25
|
+
common /lsa001/ rownd2, rowns2(20), pdnorm,
|
26
|
+
1 iownd2(3), iowns2(2), jtyp, mused, mxordn, mxords
|
27
|
+
c-----------------------------------------------------------------------
|
28
|
+
c prja is called by stoda to compute and process the matrix
|
29
|
+
c p = i - h*el(1)*j , where j is an approximation to the jacobian.
|
30
|
+
c here j is computed by the user-supplied routine jac if
|
31
|
+
c miter = 1 or 4 or by finite differencing if miter = 2 or 5.
|
32
|
+
c j, scaled by -h*el(1), is stored in wm. then the norm of j (the
|
33
|
+
c matrix norm consistent with the weighted max-norm on vectors given
|
34
|
+
c by vmnorm) is computed, and j is overwritten by p. p is then
|
35
|
+
c subjected to lu decomposition in preparation for later solution
|
36
|
+
c of linear systems with p as coefficient matrix. this is done
|
37
|
+
c by dgetrf if miter = 1 or 2, and by dgbtrf if miter = 4 or 5.
|
38
|
+
c
|
39
|
+
c in addition to variables described previously, communication
|
40
|
+
c with prja uses the following..
|
41
|
+
c y = array containing predicted values on entry.
|
42
|
+
c ftem = work array of length n (acor in stoda).
|
43
|
+
c savf = array containing f evaluated at predicted y.
|
44
|
+
c wm = real work space for matrices. on output it contains the
|
45
|
+
c lu decomposition of p.
|
46
|
+
c storage of matrix elements starts at wm(3).
|
47
|
+
c wm also contains the following matrix-related data..
|
48
|
+
c wm(1) = sqrt(uround), used in numerical jacobian increments.
|
49
|
+
c iwm = integer work space containing pivot information, starting at
|
50
|
+
c iwm(21). iwm also contains the band parameters
|
51
|
+
c ml = iwm(1) and mu = iwm(2) if miter is 4 or 5.
|
52
|
+
c el0 = el(1) (input).
|
53
|
+
c pdnorm= norm of jacobian matrix. (output).
|
54
|
+
c ierpj = output error flag, = 0 if no trouble, .gt. 0 if
|
55
|
+
c p matrix found to be singular.
|
56
|
+
c jcur = output flag = 1 to indicate that the jacobian matrix
|
57
|
+
c (or approximation) is now current.
|
58
|
+
c this routine also uses the common variables el0, h, tn, uround,
|
59
|
+
c miter, n, nfe, and nje.
|
60
|
+
c-----------------------------------------------------------------------
|
61
|
+
nje = nje + 1
|
62
|
+
ierpj = 0
|
63
|
+
jcur = 1
|
64
|
+
hl0 = h*el0
|
65
|
+
go to (100, 200, 300, 400, 500), miter
|
66
|
+
c if miter = 1, call jac and multiply by scalar. -----------------------
|
67
|
+
100 lenp = n*n
|
68
|
+
do 110 i = 1,lenp
|
69
|
+
110 wm(i+2) = 0.0d0
|
70
|
+
call srcma (rsav, isav, 1)
|
71
|
+
call jac (neq, tn, y, 0, 0, wm(3), n)
|
72
|
+
call srcma (rsav, isav, 2)
|
73
|
+
con = -hl0
|
74
|
+
do 120 i = 1,lenp
|
75
|
+
120 wm(i+2) = wm(i+2)*con
|
76
|
+
go to 240
|
77
|
+
c if miter = 2, make n calls to f to approximate j. --------------------
|
78
|
+
200 fac = vmnorm (n, savf, ewt)
|
79
|
+
r0 = 1000.0d0*dabs(h)*uround*dfloat(n)*fac
|
80
|
+
if (r0 .eq. 0.0d0) r0 = 1.0d0
|
81
|
+
srur = wm(1)
|
82
|
+
j1 = 2
|
83
|
+
do 230 j = 1,n
|
84
|
+
yj = y(j)
|
85
|
+
r = dmax1(srur*dabs(yj),r0/ewt(j))
|
86
|
+
y(j) = y(j) + r
|
87
|
+
fac = -hl0/r
|
88
|
+
call srcma (rsav, isav, 1)
|
89
|
+
call f (neq, tn, y, ftem)
|
90
|
+
call srcma (rsav, isav, 2)
|
91
|
+
do 220 i = 1,n
|
92
|
+
220 wm(i+j1) = (ftem(i) - savf(i))*fac
|
93
|
+
y(j) = yj
|
94
|
+
j1 = j1 + n
|
95
|
+
230 continue
|
96
|
+
nfe = nfe + n
|
97
|
+
240 continue
|
98
|
+
c compute norm of jacobian. --------------------------------------------
|
99
|
+
pdnorm = fnorm (n, wm(3), ewt)/dabs(hl0)
|
100
|
+
c add identity matrix. -------------------------------------------------
|
101
|
+
np1 = n + 1
|
102
|
+
j = 3
|
103
|
+
do 250 i = 1,n
|
104
|
+
wm(j) = wm(j) + 1.0d0
|
105
|
+
250 j = j + np1
|
106
|
+
c do lu decomposition on p. --------------------------------------------
|
107
|
+
c Replaced LINPACK dgefa with LAPACK dgetrf
|
108
|
+
c call dgefa (wm(3), n, n, iwm(21), ier)
|
109
|
+
call dgetrf (n, n, wm(3), n, iwm(21), ier)
|
110
|
+
if (ier .ne. 0) ierpj = 1
|
111
|
+
return
|
112
|
+
c dummy block only, since miter is never 3 in this routine. ------------
|
113
|
+
300 return
|
114
|
+
c if miter = 4, call jac and multiply by scalar. -----------------------
|
115
|
+
400 ml = iwm(1)
|
116
|
+
mu = iwm(2)
|
117
|
+
ml3 = ml + 3
|
118
|
+
mband = ml + mu + 1
|
119
|
+
meband = mband + ml
|
120
|
+
lenp = meband*n
|
121
|
+
do 410 i = 1,lenp
|
122
|
+
410 wm(i+2) = 0.0d0
|
123
|
+
call srcma (rsav, isav, 1)
|
124
|
+
call jac (neq, tn, y, ml, mu, wm(ml3), meband)
|
125
|
+
call srcma (rsav, isav, 2)
|
126
|
+
con = -hl0
|
127
|
+
do 420 i = 1,lenp
|
128
|
+
420 wm(i+2) = wm(i+2)*con
|
129
|
+
go to 570
|
130
|
+
c if miter = 5, make mband calls to f to approximate j. ----------------
|
131
|
+
500 ml = iwm(1)
|
132
|
+
mu = iwm(2)
|
133
|
+
mband = ml + mu + 1
|
134
|
+
mba = min0(mband,n)
|
135
|
+
meband = mband + ml
|
136
|
+
meb1 = meband - 1
|
137
|
+
srur = wm(1)
|
138
|
+
fac = vmnorm (n, savf, ewt)
|
139
|
+
r0 = 1000.0d0*dabs(h)*uround*dfloat(n)*fac
|
140
|
+
if (r0 .eq. 0.0d0) r0 = 1.0d0
|
141
|
+
do 560 j = 1,mba
|
142
|
+
do 530 i = j,n,mband
|
143
|
+
yi = y(i)
|
144
|
+
r = dmax1(srur*dabs(yi),r0/ewt(i))
|
145
|
+
530 y(i) = y(i) + r
|
146
|
+
call srcma (rsav, isav, 1)
|
147
|
+
call f (neq, tn, y, ftem)
|
148
|
+
call srcma (rsav, isav, 2)
|
149
|
+
do 550 jj = j,n,mband
|
150
|
+
y(jj) = yh(jj,1)
|
151
|
+
yjj = y(jj)
|
152
|
+
r = dmax1(srur*dabs(yjj),r0/ewt(jj))
|
153
|
+
fac = -hl0/r
|
154
|
+
i1 = max0(jj-mu,1)
|
155
|
+
i2 = min0(jj+ml,n)
|
156
|
+
ii = jj*meb1 - ml + 2
|
157
|
+
do 540 i = i1,i2
|
158
|
+
540 wm(ii+i) = (ftem(i) - savf(i))*fac
|
159
|
+
550 continue
|
160
|
+
560 continue
|
161
|
+
nfe = nfe + mba
|
162
|
+
570 continue
|
163
|
+
c compute norm of jacobian. --------------------------------------------
|
164
|
+
pdnorm = bnorm (n, wm(3), meband, ml, mu, ewt)/dabs(hl0)
|
165
|
+
c add identity matrix. -------------------------------------------------
|
166
|
+
ii = mband + 2
|
167
|
+
do 580 i = 1,n
|
168
|
+
wm(ii) = wm(ii) + 1.0d0
|
169
|
+
580 ii = ii + meband
|
170
|
+
c do lu decomposition of p. --------------------------------------------
|
171
|
+
c Replaced LINPACK dgefa with LAPACK dgetrf
|
172
|
+
c call dgbfa (wm(3), meband, n, ml, mu, iwm(21), ier)
|
173
|
+
call dgbtrf (n, n, ml, mu, wm(3), meband, iwm(21), ier)
|
174
|
+
if (ier .ne. 0) ierpj = 1
|
175
|
+
return
|
176
|
+
c----------------------- end of subroutine prja ------------------------
|
177
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
|
2
|
+
Here's what is available (all in double precision):
|
3
|
+
LSODE
|
4
|
+
LSODES
|
5
|
+
LSODA
|
6
|
+
LSODAR
|
7
|
+
LSODI
|
8
|
+
LSOIBT
|
9
|
+
|
10
|
+
To receive the document try:
|
11
|
+
send only DOC from odepack
|
12
|
+
|
13
|
+
To receive the demo program try:
|
14
|
+
send only DEMO from odepack
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
I. Summary of the ODEPACK Solvers
|
19
|
+
|
20
|
+
|
21
|
+
A. Solvers for explicitly given systems.
|
22
|
+
|
23
|
+
In the solvers below, it is assumed that the ODE's are given
|
24
|
+
explicitly, so that the system can be written in the form
|
25
|
+
dy/dt = f(t,y) ,
|
26
|
+
where y is the vector of dependent variables, and t is the independent
|
27
|
+
variable.
|
28
|
+
|
29
|
+
|
30
|
+
1. LSODE (Livermore Solver for Ordinary Differential Equations) is the
|
31
|
+
basic solver of the collection. It solves stiff and nonstiff systems
|
32
|
+
of the form dy/dt = f. In the stiff case, it treats the Jacobian matrix
|
33
|
+
df/dy as either a full or a banded matrix, and as either user-supplied
|
34
|
+
or internally approximated by difference quotients. It uses Adams methods
|
35
|
+
(predictor-corrector) in the nonstiff case, and Backward Differentiation
|
36
|
+
Formula (BDF) methods in the stiff case. The linear systems that arise
|
37
|
+
are solved by direct methods (LU factor/solve). LSODE supersedes the older
|
38
|
+
GEAR and GEARB packages, and reflects a complete redesign of the user
|
39
|
+
interface and internal organization, with some algorithmic improvements.
|
40
|
+
|
41
|
+
|
42
|
+
2. LSODES, written jointly with A. H. Sherman, solves systems dy/dt = f
|
43
|
+
and in the stiff case treats the Jacobian matrix in general sparse
|
44
|
+
form. It determines the sparsity structure on its own (or optionally
|
45
|
+
accepts this information from the user), and uses parts of the Yale Sparse
|
46
|
+
Matrix Package (YSMP) to solve the linear systems that arise.
|
47
|
+
LSODES supersedes, and improves upon, the older GEARS package.
|
48
|
+
|
49
|
+
|
50
|
+
3. LSODA, written jointly with L. R. Petzold, solves systems dy/dt = f
|
51
|
+
with a full or banded Jacobian when the problem is stiff, but it
|
52
|
+
automatically selects between nonstiff (Adams) and stiff (BDF) methods.
|
53
|
+
It uses the nonstiff method initially, and dynamically monitors data
|
54
|
+
in order to decide which method to use.
|
55
|
+
|
56
|
+
|
57
|
+
4. LSODAR, also written jointly with L. R. Petzold, is a variant of LSODA
|
58
|
+
with a rootfinding capability added. Thus it solves problems dy/dt = f
|
59
|
+
with full or banded Jacobian and automatic method selection, and at
|
60
|
+
the same time, it finds the roots of any of a set of given functions
|
61
|
+
of the form g(t,y). This is often useful for finding stop conditions
|
62
|
+
or points at which switches are to be made in the function f.
|
63
|
+
|
64
|
+
|
65
|
+
B. Solvers for linearly implicit systems.
|
66
|
+
|
67
|
+
In the solvers below, it is assumed that the derivative dy/dt is
|
68
|
+
implicit, but occurs linearly, so that the system can be written
|
69
|
+
A(t,y) dy/dt = g(t,y) ,
|
70
|
+
where A is a square matrix. These solvers allow A to be singular,
|
71
|
+
in which case the system is a differential-algebraic system, but in that
|
72
|
+
case users must be very careful to supply a well-posed problem with
|
73
|
+
consistent initial conditions.
|
74
|
+
|
75
|
+
|
76
|
+
5. LSODI, written jointly with J. F. Painter, solves linearly implicit
|
77
|
+
systems in which the matrices involved (A, dg/dy, and d(A dy/dt)/dy) are
|
78
|
+
all assumed to be either full or banded. LSODI supersedes the older
|
79
|
+
GEARIB solver and improves upon it in numerous ways.
|
80
|
+
|
81
|
+
|
82
|
+
6. LSOIBT, written jointly with C. S. Kenney, solves linearly implicit
|
83
|
+
systems in which the matrices involved are all assumed to be
|
84
|
+
block-tridiagonal. Linear systems are solved by the LU method.
|
@@ -0,0 +1,72 @@
|
|
1
|
+
subroutine solsy (wm, iwm, x, tem)
|
2
|
+
clll. optimize
|
3
|
+
integer iwm
|
4
|
+
integer iownd, iowns,
|
5
|
+
1 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
|
6
|
+
2 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
|
7
|
+
integer i, meband, ml, mu
|
8
|
+
double precision wm, x, tem
|
9
|
+
double precision rowns,
|
10
|
+
1 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround
|
11
|
+
double precision di, hl0, phl0, r
|
12
|
+
dimension wm(*), iwm(*), x(1), tem(1)
|
13
|
+
common /ls0001/ rowns(209),
|
14
|
+
2 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround,
|
15
|
+
3 iownd(14), iowns(6),
|
16
|
+
4 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
|
17
|
+
5 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
|
18
|
+
c-----------------------------------------------------------------------
|
19
|
+
c this routine manages the solution of the linear system arising from
|
20
|
+
c a chord iteration. it is called if miter .ne. 0.
|
21
|
+
c if miter is 1 or 2, it calls dgetrs to accomplish this.
|
22
|
+
c if miter = 3 it updates the coefficient h*el0 in the diagonal
|
23
|
+
c matrix, and then computes the solution.
|
24
|
+
c if miter is 4 or 5, it calls dgbtrs.
|
25
|
+
c communication with solsy uses the following variables..
|
26
|
+
c wm = real work space containing the inverse diagonal matrix if
|
27
|
+
c miter = 3 and the lu decomposition of the matrix otherwise.
|
28
|
+
c storage of matrix elements starts at wm(3).
|
29
|
+
c wm also contains the following matrix-related data..
|
30
|
+
c wm(1) = sqrt(uround) (not used here),
|
31
|
+
c wm(2) = hl0, the previous value of h*el0, used if miter = 3.
|
32
|
+
c iwm = integer work space containing pivot information, starting at
|
33
|
+
c iwm(21), if miter is 1, 2, 4, or 5. iwm also contains band
|
34
|
+
c parameters ml = iwm(1) and mu = iwm(2) if miter is 4 or 5.
|
35
|
+
c x = the right-hand side vector on input, and the solution vector
|
36
|
+
c on output, of length n.
|
37
|
+
c tem = vector of work space of length n, not used in this version.
|
38
|
+
c iersl = output flag (in common). iersl = 0 if no trouble occurred.
|
39
|
+
c iersl = 1 if a singular matrix arose with miter = 3.
|
40
|
+
c this routine also uses the common variables el0, h, miter, and n.
|
41
|
+
c-----------------------------------------------------------------------
|
42
|
+
iersl = 0
|
43
|
+
go to (100, 100, 300, 400, 400), miter
|
44
|
+
c Replaced LINPACK dgesl with LAPACK dgetrs
|
45
|
+
c 100 call dgesl (wm(3), n, n, iwm(21), x, 0)
|
46
|
+
100 call dgetrs ('N', n, 1, wm(3), n, iwm(21), x, n, ier)
|
47
|
+
return
|
48
|
+
c
|
49
|
+
300 phl0 = wm(2)
|
50
|
+
hl0 = h*el0
|
51
|
+
wm(2) = hl0
|
52
|
+
if (hl0 .eq. phl0) go to 330
|
53
|
+
r = hl0/phl0
|
54
|
+
do 320 i = 1,n
|
55
|
+
di = 1.0d0 - r*(1.0d0 - 1.0d0/wm(i+2))
|
56
|
+
if (dabs(di) .eq. 0.0d0) go to 390
|
57
|
+
320 wm(i+2) = 1.0d0/di
|
58
|
+
330 do 340 i = 1,n
|
59
|
+
340 x(i) = wm(i+2)*x(i)
|
60
|
+
return
|
61
|
+
390 iersl = 1
|
62
|
+
return
|
63
|
+
c
|
64
|
+
400 ml = iwm(1)
|
65
|
+
mu = iwm(2)
|
66
|
+
meband = 2*ml + mu + 1
|
67
|
+
c Replaced LINPACK dgbsl with LAPACK dgbtrs
|
68
|
+
c call dgbsl (wm(3), meband, n, ml, mu, iwm(21), x, 0)
|
69
|
+
call dgbtrs ('N', n, ml, mu, 1, wm(3), meband, iwm(21), x, n, ier)
|
70
|
+
return
|
71
|
+
c----------------------- end of subroutine solsy -----------------------
|
72
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
subroutine srcma (rsav, isav, job)
|
2
|
+
c-----------------------------------------------------------------------
|
3
|
+
c this routine saves or restores (depending on job) the contents of
|
4
|
+
c the common blocks ls0001, lsa001, and eh0001, which are used
|
5
|
+
c internally by one or more odepack solvers.
|
6
|
+
c
|
7
|
+
c rsav = real array of length 240 or more.
|
8
|
+
c isav = integer array of length 50 or more.
|
9
|
+
c job = flag indicating to save or restore the common blocks..
|
10
|
+
c job = 1 if common is to be saved (written to rsav/isav)
|
11
|
+
c job = 2 if common is to be restored (read from rsav/isav)
|
12
|
+
c a call with job = 2 presumes a prior call with job = 1.
|
13
|
+
c-----------------------------------------------------------------------
|
14
|
+
integer isav, job
|
15
|
+
integer ieh, ils, ilsa
|
16
|
+
integer i, lenrls, lenils, lenrla, lenila
|
17
|
+
double precision rsav
|
18
|
+
double precision rls, rlsa
|
19
|
+
dimension rsav(1), isav(1)
|
20
|
+
common /ls0001/ rls(218), ils(39)
|
21
|
+
common /lsa001/ rlsa(22), ilsa(9)
|
22
|
+
common /eh0001/ ieh(2)
|
23
|
+
data lenrls/218/, lenils/39/, lenrla/22/, lenila/9/
|
24
|
+
c
|
25
|
+
if (job .eq. 2) go to 100
|
26
|
+
do 10 i = 1,lenrls
|
27
|
+
10 rsav(i) = rls(i)
|
28
|
+
do 15 i = 1,lenrla
|
29
|
+
15 rsav(lenrls+i) = rlsa(i)
|
30
|
+
c
|
31
|
+
do 20 i = 1,lenils
|
32
|
+
20 isav(i) = ils(i)
|
33
|
+
do 25 i = 1,lenila
|
34
|
+
25 isav(lenils+i) = ilsa(i)
|
35
|
+
c
|
36
|
+
isav(lenils+lenila+1) = ieh(1)
|
37
|
+
isav(lenils+lenila+2) = ieh(2)
|
38
|
+
return
|
39
|
+
c
|
40
|
+
100 continue
|
41
|
+
do 110 i = 1,lenrls
|
42
|
+
110 rls(i) = rsav(i)
|
43
|
+
do 115 i = 1,lenrla
|
44
|
+
115 rlsa(i) = rsav(lenrls+i)
|
45
|
+
c
|
46
|
+
do 120 i = 1,lenils
|
47
|
+
120 ils(i) = isav(i)
|
48
|
+
do 125 i = 1,lenila
|
49
|
+
125 ilsa(i) = isav(lenils+i)
|
50
|
+
c
|
51
|
+
ieh(1) = isav(lenils+lenila+1)
|
52
|
+
ieh(2) = isav(lenils+lenila+2)
|
53
|
+
return
|
54
|
+
c----------------------- end of subroutine srcma -----------------------
|
55
|
+
end
|
@@ -0,0 +1,637 @@
|
|
1
|
+
subroutine stoda (neq, y, yh, nyh, yh1, ewt, savf, acor,
|
2
|
+
1 wm, iwm, f, jac, pjac, slvs)
|
3
|
+
clll. optimize
|
4
|
+
external f, jac, pjac, slvs
|
5
|
+
integer neq, nyh, iwm
|
6
|
+
integer iownd, ialth, ipup, lmax, meo, nqnyh, nslp,
|
7
|
+
1 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
|
8
|
+
2 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
|
9
|
+
integer iownd2, icount, irflag, jtyp, mused, mxordn, mxords
|
10
|
+
integer i, i1, iredo, iret, j, jb, m, ncf, newq
|
11
|
+
integer lm1, lm1p1, lm2, lm2p1, nqm1, nqm2, isav
|
12
|
+
double precision y, yh, yh1, ewt, savf, acor, wm, rsav
|
13
|
+
double precision conit, crate, el, elco, hold, rmax, tesco,
|
14
|
+
2 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround
|
15
|
+
double precision rownd2, pdest, pdlast, ratio, cm1, cm2,
|
16
|
+
1 pdnorm
|
17
|
+
double precision dcon, ddn, del, delp, dsm, dup, exdn, exsm, exup,
|
18
|
+
1 r, rh, rhdn, rhsm, rhup, told, vmnorm
|
19
|
+
double precision alpha, dm1, dm2, exm1, exm2, pdh, pnorm, rate,
|
20
|
+
1 rh1, rh1it, rh2, rm, sm1
|
21
|
+
dimension neq(1), y(1), yh(nyh,*), yh1(1), ewt(1), savf(1),
|
22
|
+
1 acor(1), wm(*), iwm(*), rsav(240), isav(50)
|
23
|
+
dimension sm1(12)
|
24
|
+
common /ls0001/ conit, crate, el(13), elco(13,12),
|
25
|
+
1 hold, rmax, tesco(3,12),
|
26
|
+
2 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround, iownd(14),
|
27
|
+
3 ialth, ipup, lmax, meo, nqnyh, nslp,
|
28
|
+
4 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
|
29
|
+
5 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
|
30
|
+
common /lsa001/ rownd2, pdest, pdlast, ratio, cm1(12), cm2(5),
|
31
|
+
1 pdnorm,
|
32
|
+
2 iownd2(3), icount, irflag, jtyp, mused, mxordn, mxords
|
33
|
+
data sm1/0.5d0, 0.575d0, 0.55d0, 0.45d0, 0.35d0, 0.25d0,
|
34
|
+
1 0.20d0, 0.15d0, 0.10d0, 0.075d0, 0.050d0, 0.025d0/
|
35
|
+
c-----------------------------------------------------------------------
|
36
|
+
c stoda performs one step of the integration of an initial value
|
37
|
+
c problem for a system of ordinary differential equations.
|
38
|
+
c note.. stoda is independent of the value of the iteration method
|
39
|
+
c indicator miter, when this is .ne. 0, and hence is independent
|
40
|
+
c of the type of chord method used, or the jacobian structure.
|
41
|
+
c communication with stoda is done with the following variables..
|
42
|
+
c
|
43
|
+
c y = an array of length .ge. n used as the y argument in
|
44
|
+
c all calls to f and jac.
|
45
|
+
c neq = integer array containing problem size in neq(1), and
|
46
|
+
c passed as the neq argument in all calls to f and jac.
|
47
|
+
c yh = an nyh by lmax array containing the dependent variables
|
48
|
+
c and their approximate scaled derivatives, where
|
49
|
+
c lmax = maxord + 1. yh(i,j+1) contains the approximate
|
50
|
+
c j-th derivative of y(i), scaled by h**j/factorial(j)
|
51
|
+
c (j = 0,1,...,nq). on entry for the first step, the first
|
52
|
+
c two columns of yh must be set from the initial values.
|
53
|
+
c nyh = a constant integer .ge. n, the first dimension of yh.
|
54
|
+
c yh1 = a one-dimensional array occupying the same space as yh.
|
55
|
+
c ewt = an array of length n containing multiplicative weights
|
56
|
+
c for local error measurements. local errors in y(i) are
|
57
|
+
c compared to 1.0/ewt(i) in various error tests.
|
58
|
+
c savf = an array of working storage, of length n.
|
59
|
+
c acor = a work array of length n, used for the accumulated
|
60
|
+
c corrections. on a successful return, acor(i) contains
|
61
|
+
c the estimated one-step local error in y(i).
|
62
|
+
c wm,iwm = real and integer work arrays associated with matrix
|
63
|
+
c operations in chord iteration (miter .ne. 0).
|
64
|
+
c pjac = name of routine to evaluate and preprocess jacobian matrix
|
65
|
+
c and p = i - h*el0*jac, if a chord method is being used.
|
66
|
+
c it also returns an estimate of norm(jac) in pdnorm.
|
67
|
+
c slvs = name of routine to solve linear system in chord iteration.
|
68
|
+
c ccmax = maximum relative change in h*el0 before pjac is called.
|
69
|
+
c h = the step size to be attempted on the next step.
|
70
|
+
c h is altered by the error control algorithm during the
|
71
|
+
c problem. h can be either positive or negative, but its
|
72
|
+
c sign must remain constant throughout the problem.
|
73
|
+
c hmin = the minimum absolute value of the step size h to be used.
|
74
|
+
c hmxi = inverse of the maximum absolute value of h to be used.
|
75
|
+
c hmxi = 0.0 is allowed and corresponds to an infinite hmax.
|
76
|
+
c hmin and hmxi may be changed at any time, but will not
|
77
|
+
c take effect until the next change of h is considered.
|
78
|
+
c tn = the independent variable. tn is updated on each step taken.
|
79
|
+
c jstart = an integer used for input only, with the following
|
80
|
+
c values and meanings..
|
81
|
+
c 0 perform the first step.
|
82
|
+
c .gt.0 take a new step continuing from the last.
|
83
|
+
c -1 take the next step with a new value of h,
|
84
|
+
c n, meth, miter, and/or matrix parameters.
|
85
|
+
c -2 take the next step with a new value of h,
|
86
|
+
c but with other inputs unchanged.
|
87
|
+
c on return, jstart is set to 1 to facilitate continuation.
|
88
|
+
c kflag = a completion code with the following meanings..
|
89
|
+
c 0 the step was succesful.
|
90
|
+
c -1 the requested error could not be achieved.
|
91
|
+
c -2 corrector convergence could not be achieved.
|
92
|
+
c -3 fatal error in pjac or slvs.
|
93
|
+
c a return with kflag = -1 or -2 means either
|
94
|
+
c abs(h) = hmin or 10 consecutive failures occurred.
|
95
|
+
c on a return with kflag negative, the values of tn and
|
96
|
+
c the yh array are as of the beginning of the last
|
97
|
+
c step, and h is the last step size attempted.
|
98
|
+
c maxord = the maximum order of integration method to be allowed.
|
99
|
+
c maxcor = the maximum number of corrector iterations allowed.
|
100
|
+
c msbp = maximum number of steps between pjac calls (miter .gt. 0).
|
101
|
+
c mxncf = maximum number of convergence failures allowed.
|
102
|
+
c meth = current method.
|
103
|
+
c meth = 1 means adams method (nonstiff)
|
104
|
+
c meth = 2 means bdf method (stiff)
|
105
|
+
c meth may be reset by stoda.
|
106
|
+
c miter = corrector iteration method.
|
107
|
+
c miter = 0 means functional iteration.
|
108
|
+
c miter = jt .gt. 0 means a chord iteration corresponding
|
109
|
+
c to jacobian type jt. (the lsoda argument jt is
|
110
|
+
c communicated here as jtyp, but is not used in stoda
|
111
|
+
c except to load miter following a method switch.)
|
112
|
+
c miter may be reset by stoda.
|
113
|
+
c n = the number of first-order differential equations.
|
114
|
+
c-----------------------------------------------------------------------
|
115
|
+
kflag = 0
|
116
|
+
told = tn
|
117
|
+
ncf = 0
|
118
|
+
ierpj = 0
|
119
|
+
iersl = 0
|
120
|
+
jcur = 0
|
121
|
+
icf = 0
|
122
|
+
delp = 0.0d0
|
123
|
+
if (jstart .gt. 0) go to 200
|
124
|
+
if (jstart .eq. -1) go to 100
|
125
|
+
if (jstart .eq. -2) go to 160
|
126
|
+
c-----------------------------------------------------------------------
|
127
|
+
c on the first call, the order is set to 1, and other variables are
|
128
|
+
c initialized. rmax is the maximum ratio by which h can be increased
|
129
|
+
c in a single step. it is initially 1.e4 to compensate for the small
|
130
|
+
c initial h, but then is normally equal to 10. if a failure
|
131
|
+
c occurs (in corrector convergence or error test), rmax is set at 2
|
132
|
+
c for the next increase.
|
133
|
+
c cfode is called to get the needed coefficients for both methods.
|
134
|
+
c-----------------------------------------------------------------------
|
135
|
+
lmax = maxord + 1
|
136
|
+
nq = 1
|
137
|
+
l = 2
|
138
|
+
ialth = 2
|
139
|
+
rmax = 10000.0d0
|
140
|
+
rc = 0.0d0
|
141
|
+
el0 = 1.0d0
|
142
|
+
crate = 0.7d0
|
143
|
+
hold = h
|
144
|
+
nslp = 0
|
145
|
+
ipup = miter
|
146
|
+
iret = 3
|
147
|
+
c initialize switching parameters. meth = 1 is assumed initially. -----
|
148
|
+
icount = 20
|
149
|
+
irflag = 0
|
150
|
+
pdest = 0.0d0
|
151
|
+
pdlast = 0.0d0
|
152
|
+
ratio = 5.0d0
|
153
|
+
call cfode (2, elco, tesco)
|
154
|
+
do 10 i = 1,5
|
155
|
+
10 cm2(i) = tesco(2,i)*elco(i+1,i)
|
156
|
+
call cfode (1, elco, tesco)
|
157
|
+
do 20 i = 1,12
|
158
|
+
20 cm1(i) = tesco(2,i)*elco(i+1,i)
|
159
|
+
go to 150
|
160
|
+
c-----------------------------------------------------------------------
|
161
|
+
c the following block handles preliminaries needed when jstart = -1.
|
162
|
+
c ipup is set to miter to force a matrix update.
|
163
|
+
c if an order increase is about to be considered (ialth = 1),
|
164
|
+
c ialth is reset to 2 to postpone consideration one more step.
|
165
|
+
c if the caller has changed meth, cfode is called to reset
|
166
|
+
c the coefficients of the method.
|
167
|
+
c if h is to be changed, yh must be rescaled.
|
168
|
+
c if h or meth is being changed, ialth is reset to l = nq + 1
|
169
|
+
c to prevent further changes in h for that many steps.
|
170
|
+
c-----------------------------------------------------------------------
|
171
|
+
100 ipup = miter
|
172
|
+
lmax = maxord + 1
|
173
|
+
if (ialth .eq. 1) ialth = 2
|
174
|
+
if (meth .eq. mused) go to 160
|
175
|
+
call cfode (meth, elco, tesco)
|
176
|
+
ialth = l
|
177
|
+
iret = 1
|
178
|
+
c-----------------------------------------------------------------------
|
179
|
+
c the el vector and related constants are reset
|
180
|
+
c whenever the order nq is changed, or at the start of the problem.
|
181
|
+
c-----------------------------------------------------------------------
|
182
|
+
150 do 155 i = 1,l
|
183
|
+
155 el(i) = elco(i,nq)
|
184
|
+
nqnyh = nq*nyh
|
185
|
+
rc = rc*el(1)/el0
|
186
|
+
el0 = el(1)
|
187
|
+
conit = 0.5d0/dfloat(nq+2)
|
188
|
+
go to (160, 170, 200), iret
|
189
|
+
c-----------------------------------------------------------------------
|
190
|
+
c if h is being changed, the h ratio rh is checked against
|
191
|
+
c rmax, hmin, and hmxi, and the yh array rescaled. ialth is set to
|
192
|
+
c l = nq + 1 to prevent a change of h for that many steps, unless
|
193
|
+
c forced by a convergence or error test failure.
|
194
|
+
c-----------------------------------------------------------------------
|
195
|
+
160 if (h .eq. hold) go to 200
|
196
|
+
rh = h/hold
|
197
|
+
h = hold
|
198
|
+
iredo = 3
|
199
|
+
go to 175
|
200
|
+
170 rh = dmax1(rh,hmin/dabs(h))
|
201
|
+
175 rh = dmin1(rh,rmax)
|
202
|
+
rh = rh/dmax1(1.0d0,dabs(h)*hmxi*rh)
|
203
|
+
c-----------------------------------------------------------------------
|
204
|
+
c if meth = 1, also restrict the new step size by the stability region.
|
205
|
+
c if this reduces h, set irflag to 1 so that if there are roundoff
|
206
|
+
c problems later, we can assume that is the cause of the trouble.
|
207
|
+
c-----------------------------------------------------------------------
|
208
|
+
if (meth .eq. 2) go to 178
|
209
|
+
irflag = 0
|
210
|
+
pdh = dmax1(dabs(h)*pdlast,0.000001d0)
|
211
|
+
if (rh*pdh*1.00001d0 .lt. sm1(nq)) go to 178
|
212
|
+
rh = sm1(nq)/pdh
|
213
|
+
irflag = 1
|
214
|
+
178 continue
|
215
|
+
r = 1.0d0
|
216
|
+
do 180 j = 2,l
|
217
|
+
r = r*rh
|
218
|
+
do 180 i = 1,n
|
219
|
+
180 yh(i,j) = yh(i,j)*r
|
220
|
+
h = h*rh
|
221
|
+
rc = rc*rh
|
222
|
+
ialth = l
|
223
|
+
if (iredo .eq. 0) go to 690
|
224
|
+
c-----------------------------------------------------------------------
|
225
|
+
c this section computes the predicted values by effectively
|
226
|
+
c multiplying the yh array by the pascal triangle matrix.
|
227
|
+
c rc is the ratio of new to old values of the coefficient h*el(1).
|
228
|
+
c when rc differs from 1 by more than ccmax, ipup is set to miter
|
229
|
+
c to force pjac to be called, if a jacobian is involved.
|
230
|
+
c in any case, pjac is called at least every msbp steps.
|
231
|
+
c-----------------------------------------------------------------------
|
232
|
+
200 if (dabs(rc-1.0d0) .gt. ccmax) ipup = miter
|
233
|
+
if (nst .ge. nslp+msbp) ipup = miter
|
234
|
+
tn = tn + h
|
235
|
+
i1 = nqnyh + 1
|
236
|
+
do 215 jb = 1,nq
|
237
|
+
i1 = i1 - nyh
|
238
|
+
cdir$ ivdep
|
239
|
+
do 210 i = i1,nqnyh
|
240
|
+
210 yh1(i) = yh1(i) + yh1(i+nyh)
|
241
|
+
215 continue
|
242
|
+
pnorm = vmnorm (n, yh1, ewt)
|
243
|
+
c-----------------------------------------------------------------------
|
244
|
+
c up to maxcor corrector iterations are taken. a convergence test is
|
245
|
+
c made on the r.m.s. norm of each correction, weighted by the error
|
246
|
+
c weight vector ewt. the sum of the corrections is accumulated in the
|
247
|
+
c vector acor(i). the yh array is not altered in the corrector loop.
|
248
|
+
c-----------------------------------------------------------------------
|
249
|
+
220 m = 0
|
250
|
+
rate = 0.0d0
|
251
|
+
del = 0.0d0
|
252
|
+
do 230 i = 1,n
|
253
|
+
230 y(i) = yh(i,1)
|
254
|
+
call srcma (rsav, isav, 1)
|
255
|
+
call f (neq, tn, y, savf)
|
256
|
+
call srcma (rsav, isav, 2)
|
257
|
+
nfe = nfe + 1
|
258
|
+
if (ipup .le. 0) go to 250
|
259
|
+
c-----------------------------------------------------------------------
|
260
|
+
c if indicated, the matrix p = i - h*el(1)*j is reevaluated and
|
261
|
+
c preprocessed before starting the corrector iteration. ipup is set
|
262
|
+
c to 0 as an indicator that this has been done.
|
263
|
+
c-----------------------------------------------------------------------
|
264
|
+
call pjac (neq, y, yh, nyh, ewt, acor, savf, wm, iwm, f, jac)
|
265
|
+
ipup = 0
|
266
|
+
rc = 1.0d0
|
267
|
+
nslp = nst
|
268
|
+
crate = 0.7d0
|
269
|
+
if (ierpj .ne. 0) go to 430
|
270
|
+
250 do 260 i = 1,n
|
271
|
+
260 acor(i) = 0.0d0
|
272
|
+
270 if (miter .ne. 0) go to 350
|
273
|
+
c-----------------------------------------------------------------------
|
274
|
+
c in the case of functional iteration, update y directly from
|
275
|
+
c the result of the last function evaluation.
|
276
|
+
c-----------------------------------------------------------------------
|
277
|
+
do 290 i = 1,n
|
278
|
+
savf(i) = h*savf(i) - yh(i,2)
|
279
|
+
290 y(i) = savf(i) - acor(i)
|
280
|
+
del = vmnorm (n, y, ewt)
|
281
|
+
do 300 i = 1,n
|
282
|
+
y(i) = yh(i,1) + el(1)*savf(i)
|
283
|
+
300 acor(i) = savf(i)
|
284
|
+
go to 400
|
285
|
+
c-----------------------------------------------------------------------
|
286
|
+
c in the case of the chord method, compute the corrector error,
|
287
|
+
c and solve the linear system with that as right-hand side and
|
288
|
+
c p as coefficient matrix.
|
289
|
+
c-----------------------------------------------------------------------
|
290
|
+
350 do 360 i = 1,n
|
291
|
+
360 y(i) = h*savf(i) - (yh(i,2) + acor(i))
|
292
|
+
call slvs (wm, iwm, y, savf)
|
293
|
+
if (iersl .lt. 0) go to 430
|
294
|
+
if (iersl .gt. 0) go to 410
|
295
|
+
del = vmnorm (n, y, ewt)
|
296
|
+
do 380 i = 1,n
|
297
|
+
acor(i) = acor(i) + y(i)
|
298
|
+
380 y(i) = yh(i,1) + el(1)*acor(i)
|
299
|
+
c-----------------------------------------------------------------------
|
300
|
+
c test for convergence. if m.gt.0, an estimate of the convergence
|
301
|
+
c rate constant is stored in crate, and this is used in the test.
|
302
|
+
c
|
303
|
+
c we first check for a change of iterates that is the size of
|
304
|
+
c roundoff error. if this occurs, the iteration has converged, and a
|
305
|
+
c new rate estimate is not formed.
|
306
|
+
c in all other cases, force at least two iterations to estimate a
|
307
|
+
c local lipschitz constant estimate for adams methods.
|
308
|
+
c on convergence, form pdest = local maximum lipschitz constant
|
309
|
+
c estimate. pdlast is the most recent nonzero estimate.
|
310
|
+
c-----------------------------------------------------------------------
|
311
|
+
400 continue
|
312
|
+
if (del .le. 100.0d0*pnorm*uround) go to 450
|
313
|
+
if (m .eq. 0 .and. meth .eq. 1) go to 405
|
314
|
+
if (m .eq. 0) go to 402
|
315
|
+
rm = 1024.0d0
|
316
|
+
if (del .le. 1024.0d0*delp) rm = del/delp
|
317
|
+
rate = dmax1(rate,rm)
|
318
|
+
crate = dmax1(0.2d0*crate,rm)
|
319
|
+
402 dcon = del*dmin1(1.0d0,1.5d0*crate)/(tesco(2,nq)*conit)
|
320
|
+
if (dcon .gt. 1.0d0) go to 405
|
321
|
+
pdest = dmax1(pdest,rate/dabs(h*el(1)))
|
322
|
+
if (pdest .ne. 0.0d0) pdlast = pdest
|
323
|
+
go to 450
|
324
|
+
405 continue
|
325
|
+
m = m + 1
|
326
|
+
if (m .eq. maxcor) go to 410
|
327
|
+
if (m .ge. 2 .and. del .gt. 2.0d0*delp) go to 410
|
328
|
+
delp = del
|
329
|
+
call srcma (rsav, isav, 1)
|
330
|
+
call f (neq, tn, y, savf)
|
331
|
+
call srcma (rsav, isav, 2)
|
332
|
+
nfe = nfe + 1
|
333
|
+
go to 270
|
334
|
+
c-----------------------------------------------------------------------
|
335
|
+
c the corrector iteration failed to converge.
|
336
|
+
c if miter .ne. 0 and the jacobian is out of date, pjac is called for
|
337
|
+
c the next try. otherwise the yh array is retracted to its values
|
338
|
+
c before prediction, and h is reduced, if possible. if h cannot be
|
339
|
+
c reduced or mxncf failures have occurred, exit with kflag = -2.
|
340
|
+
c-----------------------------------------------------------------------
|
341
|
+
410 if (miter .eq. 0 .or. jcur .eq. 1) go to 430
|
342
|
+
icf = 1
|
343
|
+
ipup = miter
|
344
|
+
go to 220
|
345
|
+
430 icf = 2
|
346
|
+
ncf = ncf + 1
|
347
|
+
rmax = 2.0d0
|
348
|
+
tn = told
|
349
|
+
i1 = nqnyh + 1
|
350
|
+
do 445 jb = 1,nq
|
351
|
+
i1 = i1 - nyh
|
352
|
+
cdir$ ivdep
|
353
|
+
do 440 i = i1,nqnyh
|
354
|
+
440 yh1(i) = yh1(i) - yh1(i+nyh)
|
355
|
+
445 continue
|
356
|
+
if (ierpj .lt. 0 .or. iersl .lt. 0) go to 680
|
357
|
+
if (dabs(h) .le. hmin*1.00001d0) go to 670
|
358
|
+
if (ncf .eq. mxncf) go to 670
|
359
|
+
rh = 0.25d0
|
360
|
+
ipup = miter
|
361
|
+
iredo = 1
|
362
|
+
go to 170
|
363
|
+
c-----------------------------------------------------------------------
|
364
|
+
c the corrector has converged. jcur is set to 0
|
365
|
+
c to signal that the jacobian involved may need updating later.
|
366
|
+
c the local error test is made and control passes to statement 500
|
367
|
+
c if it fails.
|
368
|
+
c-----------------------------------------------------------------------
|
369
|
+
450 jcur = 0
|
370
|
+
if (m .eq. 0) dsm = del/tesco(2,nq)
|
371
|
+
if (m .gt. 0) dsm = vmnorm (n, acor, ewt)/tesco(2,nq)
|
372
|
+
if (dsm .gt. 1.0d0) go to 500
|
373
|
+
c-----------------------------------------------------------------------
|
374
|
+
c after a successful step, update the yh array.
|
375
|
+
c decrease icount by 1, and if it is -1, consider switching methods.
|
376
|
+
c if a method switch is made, reset various parameters,
|
377
|
+
c rescale the yh array, and exit. if there is no switch,
|
378
|
+
c consider changing h if ialth = 1. otherwise decrease ialth by 1.
|
379
|
+
c if ialth is then 1 and nq .lt. maxord, then acor is saved for
|
380
|
+
c use in a possible order increase on the next step.
|
381
|
+
c if a change in h is considered, an increase or decrease in order
|
382
|
+
c by one is considered also. a change in h is made only if it is by a
|
383
|
+
c factor of at least 1.1. if not, ialth is set to 3 to prevent
|
384
|
+
c testing for that many steps.
|
385
|
+
c-----------------------------------------------------------------------
|
386
|
+
kflag = 0
|
387
|
+
iredo = 0
|
388
|
+
nst = nst + 1
|
389
|
+
hu = h
|
390
|
+
nqu = nq
|
391
|
+
mused = meth
|
392
|
+
do 460 j = 1,l
|
393
|
+
do 460 i = 1,n
|
394
|
+
460 yh(i,j) = yh(i,j) + el(j)*acor(i)
|
395
|
+
icount = icount - 1
|
396
|
+
if (icount .ge. 0) go to 488
|
397
|
+
if (meth .eq. 2) go to 480
|
398
|
+
c-----------------------------------------------------------------------
|
399
|
+
c we are currently using an adams method. consider switching to bdf.
|
400
|
+
c if the current order is greater than 5, assume the problem is
|
401
|
+
c not stiff, and skip this section.
|
402
|
+
c if the lipschitz constant and error estimate are not polluted
|
403
|
+
c by roundoff, go to 470 and perform the usual test.
|
404
|
+
c otherwise, switch to the bdf methods if the last step was
|
405
|
+
c restricted to insure stability (irflag = 1), and stay with adams
|
406
|
+
c method if not. when switching to bdf with polluted error estimates,
|
407
|
+
c in the absence of other information, double the step size.
|
408
|
+
c
|
409
|
+
c when the estimates are ok, we make the usual test by computing
|
410
|
+
c the step size we could have (ideally) used on this step,
|
411
|
+
c with the current (adams) method, and also that for the bdf.
|
412
|
+
c if nq .gt. mxords, we consider changing to order mxords on switching.
|
413
|
+
c compare the two step sizes to decide whether to switch.
|
414
|
+
c the step size advantage must be at least ratio = 5 to switch.
|
415
|
+
c-----------------------------------------------------------------------
|
416
|
+
if (nq .gt. 5) go to 488
|
417
|
+
if (dsm .gt. 100.0d0*pnorm*uround .and. pdest .ne. 0.0d0)
|
418
|
+
1 go to 470
|
419
|
+
if (irflag .eq. 0) go to 488
|
420
|
+
rh2 = 2.0d0
|
421
|
+
nqm2 = min0(nq,mxords)
|
422
|
+
go to 478
|
423
|
+
470 continue
|
424
|
+
exsm = 1.0d0/dfloat(l)
|
425
|
+
rh1 = 1.0d0/(1.2d0*dsm**exsm + 0.0000012d0)
|
426
|
+
rh1it = 2.0d0*rh1
|
427
|
+
pdh = pdlast*dabs(h)
|
428
|
+
if (pdh*rh1 .gt. 0.00001d0) rh1it = sm1(nq)/pdh
|
429
|
+
rh1 = dmin1(rh1,rh1it)
|
430
|
+
if (nq .le. mxords) go to 474
|
431
|
+
nqm2 = mxords
|
432
|
+
lm2 = mxords + 1
|
433
|
+
exm2 = 1.0d0/dfloat(lm2)
|
434
|
+
lm2p1 = lm2 + 1
|
435
|
+
dm2 = vmnorm (n, yh(1,lm2p1), ewt)/cm2(mxords)
|
436
|
+
rh2 = 1.0d0/(1.2d0*dm2**exm2 + 0.0000012d0)
|
437
|
+
go to 476
|
438
|
+
474 dm2 = dsm*(cm1(nq)/cm2(nq))
|
439
|
+
rh2 = 1.0d0/(1.2d0*dm2**exsm + 0.0000012d0)
|
440
|
+
nqm2 = nq
|
441
|
+
476 continue
|
442
|
+
if (rh2 .lt. ratio*rh1) go to 488
|
443
|
+
c the switch test passed. reset relevant quantities for bdf. ----------
|
444
|
+
478 rh = rh2
|
445
|
+
icount = 20
|
446
|
+
meth = 2
|
447
|
+
miter = jtyp
|
448
|
+
pdlast = 0.0d0
|
449
|
+
nq = nqm2
|
450
|
+
l = nq + 1
|
451
|
+
go to 170
|
452
|
+
c-----------------------------------------------------------------------
|
453
|
+
c we are currently using a bdf method. consider switching to adams.
|
454
|
+
c compute the step size we could have (ideally) used on this step,
|
455
|
+
c with the current (bdf) method, and also that for the adams.
|
456
|
+
c if nq .gt. mxordn, we consider changing to order mxordn on switching.
|
457
|
+
c compare the two step sizes to decide whether to switch.
|
458
|
+
c the step size advantage must be at least 5/ratio = 1 to switch.
|
459
|
+
c if the step size for adams would be so small as to cause
|
460
|
+
c roundoff pollution, we stay with bdf.
|
461
|
+
c-----------------------------------------------------------------------
|
462
|
+
480 continue
|
463
|
+
exsm = 1.0d0/dfloat(l)
|
464
|
+
if (mxordn .ge. nq) go to 484
|
465
|
+
nqm1 = mxordn
|
466
|
+
lm1 = mxordn + 1
|
467
|
+
exm1 = 1.0d0/dfloat(lm1)
|
468
|
+
lm1p1 = lm1 + 1
|
469
|
+
dm1 = vmnorm (n, yh(1,lm1p1), ewt)/cm1(mxordn)
|
470
|
+
rh1 = 1.0d0/(1.2d0*dm1**exm1 + 0.0000012d0)
|
471
|
+
go to 486
|
472
|
+
484 dm1 = dsm*(cm2(nq)/cm1(nq))
|
473
|
+
rh1 = 1.0d0/(1.2d0*dm1**exsm + 0.0000012d0)
|
474
|
+
nqm1 = nq
|
475
|
+
exm1 = exsm
|
476
|
+
486 rh1it = 2.0d0*rh1
|
477
|
+
pdh = pdnorm*dabs(h)
|
478
|
+
if (pdh*rh1 .gt. 0.00001d0) rh1it = sm1(nqm1)/pdh
|
479
|
+
rh1 = dmin1(rh1,rh1it)
|
480
|
+
rh2 = 1.0d0/(1.2d0*dsm**exsm + 0.0000012d0)
|
481
|
+
if (rh1*ratio .lt. 5.0d0*rh2) go to 488
|
482
|
+
alpha = dmax1(0.001d0,rh1)
|
483
|
+
dm1 = (alpha**exm1)*dm1
|
484
|
+
if (dm1 .le. 1000.0d0*uround*pnorm) go to 488
|
485
|
+
c the switch test passed. reset relevant quantities for adams. --------
|
486
|
+
rh = rh1
|
487
|
+
icount = 20
|
488
|
+
meth = 1
|
489
|
+
miter = 0
|
490
|
+
pdlast = 0.0d0
|
491
|
+
nq = nqm1
|
492
|
+
l = nq + 1
|
493
|
+
go to 170
|
494
|
+
c
|
495
|
+
c no method switch is being made. do the usual step/order selection. --
|
496
|
+
488 continue
|
497
|
+
ialth = ialth - 1
|
498
|
+
if (ialth .eq. 0) go to 520
|
499
|
+
if (ialth .gt. 1) go to 700
|
500
|
+
if (l .eq. lmax) go to 700
|
501
|
+
do 490 i = 1,n
|
502
|
+
490 yh(i,lmax) = acor(i)
|
503
|
+
go to 700
|
504
|
+
c-----------------------------------------------------------------------
|
505
|
+
c the error test failed. kflag keeps track of multiple failures.
|
506
|
+
c restore tn and the yh array to their previous values, and prepare
|
507
|
+
c to try the step again. compute the optimum step size for this or
|
508
|
+
c one lower order. after 2 or more failures, h is forced to decrease
|
509
|
+
c by a factor of 0.2 or less.
|
510
|
+
c-----------------------------------------------------------------------
|
511
|
+
500 kflag = kflag - 1
|
512
|
+
tn = told
|
513
|
+
i1 = nqnyh + 1
|
514
|
+
do 515 jb = 1,nq
|
515
|
+
i1 = i1 - nyh
|
516
|
+
cdir$ ivdep
|
517
|
+
do 510 i = i1,nqnyh
|
518
|
+
510 yh1(i) = yh1(i) - yh1(i+nyh)
|
519
|
+
515 continue
|
520
|
+
rmax = 2.0d0
|
521
|
+
if (dabs(h) .le. hmin*1.00001d0) go to 660
|
522
|
+
if (kflag .le. -3) go to 640
|
523
|
+
iredo = 2
|
524
|
+
rhup = 0.0d0
|
525
|
+
go to 540
|
526
|
+
c-----------------------------------------------------------------------
|
527
|
+
c regardless of the success or failure of the step, factors
|
528
|
+
c rhdn, rhsm, and rhup are computed, by which h could be multiplied
|
529
|
+
c at order nq - 1, order nq, or order nq + 1, respectively.
|
530
|
+
c in the case of failure, rhup = 0.0 to avoid an order increase.
|
531
|
+
c the largest of these is determined and the new order chosen
|
532
|
+
c accordingly. if the order is to be increased, we compute one
|
533
|
+
c additional scaled derivative.
|
534
|
+
c-----------------------------------------------------------------------
|
535
|
+
520 rhup = 0.0d0
|
536
|
+
if (l .eq. lmax) go to 540
|
537
|
+
do 530 i = 1,n
|
538
|
+
530 savf(i) = acor(i) - yh(i,lmax)
|
539
|
+
dup = vmnorm (n, savf, ewt)/tesco(3,nq)
|
540
|
+
exup = 1.0d0/dfloat(l+1)
|
541
|
+
rhup = 1.0d0/(1.4d0*dup**exup + 0.0000014d0)
|
542
|
+
540 exsm = 1.0d0/dfloat(l)
|
543
|
+
rhsm = 1.0d0/(1.2d0*dsm**exsm + 0.0000012d0)
|
544
|
+
rhdn = 0.0d0
|
545
|
+
if (nq .eq. 1) go to 550
|
546
|
+
ddn = vmnorm (n, yh(1,l), ewt)/tesco(1,nq)
|
547
|
+
exdn = 1.0d0/dfloat(nq)
|
548
|
+
rhdn = 1.0d0/(1.3d0*ddn**exdn + 0.0000013d0)
|
549
|
+
c if meth = 1, limit rh according to the stability region also. --------
|
550
|
+
550 if (meth .eq. 2) go to 560
|
551
|
+
pdh = dmax1(dabs(h)*pdlast,0.000001d0)
|
552
|
+
if (l .lt. lmax) rhup = dmin1(rhup,sm1(l)/pdh)
|
553
|
+
rhsm = dmin1(rhsm,sm1(nq)/pdh)
|
554
|
+
if (nq .gt. 1) rhdn = dmin1(rhdn,sm1(nq-1)/pdh)
|
555
|
+
pdest = 0.0d0
|
556
|
+
560 if (rhsm .ge. rhup) go to 570
|
557
|
+
if (rhup .gt. rhdn) go to 590
|
558
|
+
go to 580
|
559
|
+
570 if (rhsm .lt. rhdn) go to 580
|
560
|
+
newq = nq
|
561
|
+
rh = rhsm
|
562
|
+
go to 620
|
563
|
+
580 newq = nq - 1
|
564
|
+
rh = rhdn
|
565
|
+
if (kflag .lt. 0 .and. rh .gt. 1.0d0) rh = 1.0d0
|
566
|
+
go to 620
|
567
|
+
590 newq = l
|
568
|
+
rh = rhup
|
569
|
+
if (rh .lt. 1.1d0) go to 610
|
570
|
+
r = el(l)/dfloat(l)
|
571
|
+
do 600 i = 1,n
|
572
|
+
600 yh(i,newq+1) = acor(i)*r
|
573
|
+
go to 630
|
574
|
+
610 ialth = 3
|
575
|
+
go to 700
|
576
|
+
c if meth = 1 and h is restricted by stability, bypass 10 percent test.
|
577
|
+
620 if (meth .eq. 2) go to 622
|
578
|
+
if (rh*pdh*1.00001d0 .ge. sm1(newq)) go to 625
|
579
|
+
622 if (kflag .eq. 0 .and. rh .lt. 1.1d0) go to 610
|
580
|
+
625 if (kflag .le. -2) rh = dmin1(rh,0.2d0)
|
581
|
+
c-----------------------------------------------------------------------
|
582
|
+
c if there is a change of order, reset nq, l, and the coefficients.
|
583
|
+
c in any case h is reset according to rh and the yh array is rescaled.
|
584
|
+
c then exit from 690 if the step was ok, or redo the step otherwise.
|
585
|
+
c-----------------------------------------------------------------------
|
586
|
+
if (newq .eq. nq) go to 170
|
587
|
+
630 nq = newq
|
588
|
+
l = nq + 1
|
589
|
+
iret = 2
|
590
|
+
go to 150
|
591
|
+
c-----------------------------------------------------------------------
|
592
|
+
c control reaches this section if 3 or more failures have occured.
|
593
|
+
c if 10 failures have occurred, exit with kflag = -1.
|
594
|
+
c it is assumed that the derivatives that have accumulated in the
|
595
|
+
c yh array have errors of the wrong order. hence the first
|
596
|
+
c derivative is recomputed, and the order is set to 1. then
|
597
|
+
c h is reduced by a factor of 10, and the step is retried,
|
598
|
+
c until it succeeds or h reaches hmin.
|
599
|
+
c-----------------------------------------------------------------------
|
600
|
+
640 if (kflag .eq. -10) go to 660
|
601
|
+
rh = 0.1d0
|
602
|
+
rh = dmax1(hmin/dabs(h),rh)
|
603
|
+
h = h*rh
|
604
|
+
do 645 i = 1,n
|
605
|
+
645 y(i) = yh(i,1)
|
606
|
+
call srcma (rsav, isav, 1)
|
607
|
+
call f (neq, tn, y, savf)
|
608
|
+
call srcma (rsav, isav, 2)
|
609
|
+
nfe = nfe + 1
|
610
|
+
do 650 i = 1,n
|
611
|
+
650 yh(i,2) = h*savf(i)
|
612
|
+
ipup = miter
|
613
|
+
ialth = 5
|
614
|
+
if (nq .eq. 1) go to 200
|
615
|
+
nq = 1
|
616
|
+
l = 2
|
617
|
+
iret = 3
|
618
|
+
go to 150
|
619
|
+
c-----------------------------------------------------------------------
|
620
|
+
c all returns are made through this section. h is saved in hold
|
621
|
+
c to allow the caller to change h on the next step.
|
622
|
+
c-----------------------------------------------------------------------
|
623
|
+
660 kflag = -1
|
624
|
+
go to 720
|
625
|
+
670 kflag = -2
|
626
|
+
go to 720
|
627
|
+
680 kflag = -3
|
628
|
+
go to 720
|
629
|
+
690 rmax = 10.0d0
|
630
|
+
700 r = 1.0d0/tesco(2,nqu)
|
631
|
+
do 710 i = 1,n
|
632
|
+
710 acor(i) = acor(i)*r
|
633
|
+
720 hold = h
|
634
|
+
jstart = 1
|
635
|
+
return
|
636
|
+
c----------------------- end of subroutine stoda -----------------------
|
637
|
+
end
|