2 SUBROUTINE DPREPJI
(NEQ
, Y
, YH
, NYH
, EWT
, RTEM
, SAVR
, S
, WM
, IWM
,
4 EXTERNAL RES
, JAC
, ADDA
6 DOUBLE PRECISION Y
, YH
, EWT
, RTEM
, SAVR
, S
, WM
7 DIMENSION NEQ
(*), Y
(*), YH
(NYH
,*), EWT
(*), RTEM
(*),
8 1 S
(*), SAVR
(*), WM
(*), IWM
(*)
10 1 ICF
, IERPJ
, IERSL
, JCUR
, JSTART
, KFLAG
, L
,
11 2 LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
, METH
, MITER
,
12 3 MAXORD
, MAXCOR
, MSBP
, MXNCF
, N
, NQ
, NST
, NFE
, NJE
, NQU
13 DOUBLE PRECISION ROWNS
,
14 1 CCMAX
, EL0
, H
, HMIN
, HMXI
, HU
, RC
, TN
, UROUND
15 COMMON /DLS001
/ ROWNS
(209),
16 1 CCMAX
, EL0
, H
, HMIN
, HMXI
, HU
, RC
, TN
, UROUND
,
18 3 ICF
, IERPJ
, IERSL
, JCUR
, JSTART
, KFLAG
, L
,
19 4 LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
, METH
, MITER
,
20 5 MAXORD
, MAXCOR
, MSBP
, MXNCF
, N
, NQ
, NST
, NFE
, NJE
, NQU
21 INTEGER I
, I1
, I2
, IER
, II
, IRES
, J
, J1
, JJ
, LENP
,
22 1 MBA
, MBAND
, MEB1
, MEBAND
, ML
, ML3
, MU
23 DOUBLE PRECISION CON
, FAC
, HL0
, R
, SRUR
, YI
, YJ
, YJJ
24 C-----------------------------------------------------------------------
25 C DPREPJI is called by DSTODI to compute and process the matrix
26 C P = A - H*EL(1)*J , where J is an approximation to the Jacobian dr/dy,
27 C where r = g(t,y) - A(t,y)*s. Here J is computed by the user-supplied
28 C routine JAC if MITER = 1 or 4, or by finite differencing if MITER =
29 C 2 or 5. J is stored in WM, rescaled, and ADDA is called to generate
30 C P. P is then subjected to LU decomposition in preparation
31 C for later solution of linear systems with P as coefficient
32 C matrix. This is done by DGEFA if MITER = 1 or 2, and by
33 C DGBFA if MITER = 4 or 5.
35 C In addition to variables described previously, communication
36 C with DPREPJI uses the following:
37 C Y = array containing predicted values on entry.
38 C RTEM = work array of length N (ACOR in DSTODI).
39 C SAVR = array used for output only. On output it contains the
40 C residual evaluated at current values of t and y.
41 C S = array containing predicted values of dy/dt (SAVF in DSTODI).
42 C WM = real work space for matrices. On output it contains the
43 C LU decomposition of P.
44 C Storage of matrix elements starts at WM(3).
45 C WM also contains the following matrix-related data:
46 C WM(1) = SQRT(UROUND), used in numerical Jacobian increments.
47 C IWM = integer work space containing pivot information, starting at
48 C IWM(21). IWM also contains the band parameters
49 C ML = IWM(1) and MU = IWM(2) if MITER is 4 or 5.
50 C EL0 = el(1) (input).
51 C IERPJ = output error flag.
52 C = 0 if no trouble occurred,
53 C = 1 if the P matrix was found to be singular,
54 C = IRES (= 2 or 3) if RES returned IRES = 2 or 3.
55 C JCUR = output flag = 1 to indicate that the Jacobian matrix
56 C (or approximation) is now current.
57 C This routine also uses the Common variables EL0, H, TN, UROUND,
58 C MITER, N, NFE, and NJE.
59 C-----------------------------------------------------------------------
64 GO TO (100, 200, 300, 400, 500), MITER
65 C If MITER = 1, call RES, then JAC, and multiply by scalar. ------------
67 CALL RES
(NEQ
, TN
, Y
, S
, SAVR
, IRES
)
69 IF (IRES
.GT
. 1) GO TO 600
73 CALL JAC
( NEQ
, TN
, Y
, S
, 0, 0, WM
(3), N
)
76 120 WM
(I
+2) = WM
(I
+2)*CON
78 C If MITER = 2, make N + 1 calls to RES to approximate J. --------------
81 CALL RES
(NEQ
, TN
, Y
, S
, SAVR
, IRES
)
83 IF (IRES
.GT
. 1) GO TO 600
88 R
= MAX
(SRUR*ABS
(YJ
),0.01D0
/EWT
(J
))
91 CALL RES
( NEQ
, TN
, Y
, S
, RTEM
, IRES
)
93 IF (IRES
.GT
. 1) GO TO 600
95 220 WM
(I
+J1
) = (RTEM
(I
) - SAVR
(I
))*FAC
100 CALL RES
(NEQ
, TN
, Y
, S
, SAVR
, IRES
)
102 IF (IRES
.GT
. 1) GO TO 600
103 C Add matrix A. --------------------------------------------------------
105 CALL ADDA
(NEQ
, TN
, Y
, 0, 0, WM
(3), N
)
106 C Do LU decomposition on P. --------------------------------------------
107 CALL DGEFA
(WM
(3), N
, N
, IWM
(21), IER
)
108 IF (IER
.NE
. 0) IERPJ
= 1
110 C Dummy section for MITER = 3
112 C If MITER = 4, call RES, then JAC, and multiply by scalar. ------------
114 CALL RES
(NEQ
, TN
, Y
, S
, SAVR
, IRES
)
116 IF (IRES
.GT
. 1) GO TO 600
125 CALL JAC
( NEQ
, TN
, Y
, S
, ML
, MU
, WM
(ML3
), MEBAND
)
128 420 WM
(I
+2) = WM
(I
+2)*CON
130 C If MITER = 5, make ML + MU + 2 calls to RES to approximate J. --------
133 CALL RES
(NEQ
, TN
, Y
, S
, SAVR
, IRES
)
135 IF (IRES
.GT
. 1) GO TO 600
147 R
= MAX
(SRUR*ABS
(YI
),0.01D0
/EWT
(I
))
149 CALL RES
( NEQ
, TN
, Y
, S
, RTEM
, IRES
)
151 IF (IRES
.GT
. 1) GO TO 600
152 DO 550 JJ
= J
,N
,MBAND
155 R
= MAX
(SRUR*ABS
(YJJ
),0.01D0
/EWT
(JJ
))
159 II
= JJ*MEB1
- ML
+ 2
161 540 WM
(II
+I
) = (RTEM
(I
) - SAVR
(I
))*FAC
165 CALL RES
(NEQ
, TN
, Y
, S
, SAVR
, IRES
)
167 IF (IRES
.GT
. 1) GO TO 600
168 C Add matrix A. --------------------------------------------------------
170 CALL ADDA
(NEQ
, TN
, Y
, ML
, MU
, WM
(ML3
), MEBAND
)
171 C Do LU decomposition of P. --------------------------------------------
172 CALL DGBFA
(WM
(3), MEBAND
, N
, ML
, MU
, IWM
(21), IER
)
173 IF (IER
.NE
. 0) IERPJ
= 1
175 C Error return for IRES = 2 or IRES = 3 return from RES. ---------------
178 C----------------------- End of Subroutine DPREPJI ---------------------