2 SUBROUTINE DPREPJ
(NEQ
, Y
, YH
, NYH
, EWT
, FTEM
, SAVF
, WM
, IWM
,
4 C***BEGIN PROLOGUE DPREPJ
6 C***PURPOSE Compute and process Newton iteration matrix.
7 C***TYPE DOUBLE PRECISION (SPREPJ-S, DPREPJ-D)
8 C***AUTHOR Hindmarsh, Alan C., (LLNL)
11 C DPREPJ is called by DSTODE to compute and process the matrix
12 C P = I - h*el(1)*J , where J is an approximation to the Jacobian.
13 C Here J is computed by the user-supplied routine JAC if
14 C MITER = 1 or 4, or by finite differencing if MITER = 2, 3, or 5.
15 C If MITER = 3, a diagonal approximation to J is used.
16 C J is stored in WM and replaced by P. If MITER .ne. 3, P is then
17 C subjected to LU decomposition in preparation for later solution
18 C of linear systems with P as coefficient matrix. This is done
19 C by DGEFA if MITER = 1 or 2, and by DGBFA if MITER = 4 or 5.
21 C In addition to variables described in DSTODE and DLSODE prologues,
22 C communication with DPREPJ uses the following:
23 C Y = array containing predicted values on entry.
24 C FTEM = work array of length N (ACOR in DSTODE).
25 C SAVF = array containing f evaluated at predicted y.
26 C WM = real work space for matrices. On output it contains the
27 C inverse diagonal matrix if MITER = 3 and the LU decomposition
28 C of P if MITER is 1, 2 , 4, or 5.
29 C Storage of matrix elements starts at WM(3).
30 C WM also contains the following matrix-related data:
31 C WM(1) = SQRT(UROUND), used in numerical Jacobian increments.
32 C WM(2) = H*EL0, saved for later use if MITER = 3.
33 C IWM = integer work space containing pivot information, starting at
34 C IWM(21), if MITER is 1, 2, 4, or 5. IWM also contains band
35 C parameters ML = IWM(1) and MU = IWM(2) if MITER is 4 or 5.
36 C EL0 = EL(1) (input).
37 C IERPJ = output error flag, = 0 if no trouble, .gt. 0 if
38 C P matrix found to be singular.
39 C JCUR = output flag = 1 to indicate that the Jacobian matrix
40 C (or approximation) is now current.
41 C This routine also uses the COMMON variables EL0, H, TN, UROUND,
42 C MITER, N, NFE, and NJE.
45 C***ROUTINES CALLED DGBFA, DGEFA, DVNORM
46 C***COMMON BLOCKS DLS001
47 C***REVISION HISTORY (YYMMDD)
49 C 890501 Modified prologue to SLATEC/LDOC format. (FNF)
50 C 890504 Minor cosmetic changes. (FNF)
51 C 930809 Renamed to allow single/double precision versions. (ACH)
52 C 010418 Reduced size of Common block /DLS001/. (ACH)
53 C 031105 Restored 'own' variables to Common block /DLS001/, to
54 C enable interrupt/restart feature. (ACH)
55 C***END PROLOGUE DPREPJ
59 DOUBLE PRECISION Y
, YH
, EWT
, FTEM
, SAVF
, WM
60 DIMENSION NEQ
(*), Y
(*), YH
(NYH
,*), EWT
(*), FTEM
(*), SAVF
(*),
63 1 ICF
, IERPJ
, IERSL
, JCUR
, JSTART
, KFLAG
, L
,
64 2 LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
, METH
, MITER
,
65 3 MAXORD
, MAXCOR
, MSBP
, MXNCF
, N
, NQ
, NST
, NFE
, NJE
, NQU
66 DOUBLE PRECISION ROWNS
,
67 1 CCMAX
, EL0
, H
, HMIN
, HMXI
, HU
, RC
, TN
, UROUND
68 COMMON /DLS001
/ ROWNS
(209),
69 1 CCMAX
, EL0
, H
, HMIN
, HMXI
, HU
, RC
, TN
, UROUND
,
71 3 ICF
, IERPJ
, IERSL
, JCUR
, JSTART
, KFLAG
, L
,
72 4 LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
, METH
, MITER
,
73 5 MAXORD
, MAXCOR
, MSBP
, MXNCF
, N
, NQ
, NST
, NFE
, NJE
, NQU
74 INTEGER I
, I1
, I2
, IER
, II
, J
, J1
, JJ
, LENP
,
75 1 MBA
, MBAND
, MEB1
, MEBAND
, ML
, ML3
, MU
, NP1
76 DOUBLE PRECISION CON
, DI
, FAC
, HL0
, R
, R0
, SRUR
, YI
, YJ
, YJJ
,
79 C***FIRST EXECUTABLE STATEMENT DPREPJ
84 GO TO (100, 200, 300, 400, 500), MITER
85 C If MITER = 1, call JAC and multiply by scalar. -----------------------
89 CALL JAC
(NEQ
, TN
, Y
, 0, 0, WM
(3), N
)
92 120 WM
(I
+2) = WM
(I
+2)*CON
94 C If MITER = 2, make N calls to F to approximate J. --------------------
95 200 FAC
= DVNORM
(N
, SAVF
, EWT
)
96 R0
= 1000.0D0*ABS
(H
)*UROUND*N*FAC
97 IF (R0
.EQ
. 0.0D0
) R0
= 1.0D0
102 R
= MAX
(SRUR*ABS
(YJ
),R0
/EWT
(J
))
105 CALL F
(NEQ
, TN
, Y
, FTEM
)
107 220 WM
(I
+J1
) = (FTEM
(I
) - SAVF
(I
))*FAC
112 C Add identity matrix. -------------------------------------------------
116 WM
(J
) = WM
(J
) + 1.0D0
118 C Do LU decomposition on P. --------------------------------------------
119 CALL DGEFA
(WM
(3), N
, N
, IWM
(21), IER
)
120 IF (IER
.NE
. 0) IERPJ
= 1
122 C If MITER = 3, construct a diagonal approximation to J and P. ---------
126 310 Y
(I
) = Y
(I
) + R*
(H*SAVF
(I
) - YH
(I
,2))
127 CALL F
(NEQ
, TN
, Y
, WM
(3))
130 R0
= H*SAVF
(I
) - YH
(I
,2)
131 DI
= 0.1D0*R0
- H*
(WM
(I
+2) - SAVF
(I
))
133 IF (ABS
(R0
) .LT
. UROUND
/EWT
(I
)) GO TO 320
134 IF (ABS
(DI
) .EQ
. 0.0D0
) GO TO 330
135 WM
(I
+2) = 0.1D0*R0
/DI
140 C If MITER = 4, call JAC and multiply by scalar. -----------------------
149 CALL JAC
(NEQ
, TN
, Y
, ML
, MU
, WM
(ML3
), MEBAND
)
152 420 WM
(I
+2) = WM
(I
+2)*CON
154 C If MITER = 5, make MBAND calls to F to approximate J. ----------------
162 FAC
= DVNORM
(N
, SAVF
, EWT
)
163 R0
= 1000.0D0*ABS
(H
)*UROUND*N*FAC
164 IF (R0
.EQ
. 0.0D0
) R0
= 1.0D0
168 R
= MAX
(SRUR*ABS
(YI
),R0
/EWT
(I
))
170 CALL F
(NEQ
, TN
, Y
, FTEM
)
171 DO 550 JJ
= J
,N
,MBAND
174 R
= MAX
(SRUR*ABS
(YJJ
),R0
/EWT
(JJ
))
178 II
= JJ*MEB1
- ML
+ 2
180 540 WM
(II
+I
) = (FTEM
(I
) - SAVF
(I
))*FAC
184 C Add identity matrix. -------------------------------------------------
187 WM
(II
) = WM
(II
) + 1.0D0
189 C Do LU decomposition of P. --------------------------------------------
190 CALL DGBFA
(WM
(3), MEBAND
, N
, ML
, MU
, IWM
(21), IER
)
191 IF (IER
.NE
. 0) IERPJ
= 1
193 C----------------------- END OF SUBROUTINE DPREPJ ----------------------