1 SUBROUTINE INTEGRATE
( TIN
, TOUT
)
3 IMPLICIT KPP_REAL
(A
-H
,O
-Z
)
4 INCLUDE
'KPP_ROOT_Parameters.h'
5 INCLUDE
'KPP_ROOT_Global.h'
12 PARAMETER (LRW
=2*NVAR*NVAR
+9*NVAR
+25,LIW
=NVAR
+35)
13 PARAMETER (LRCONT
=4*NVAR
+4+10)
14 COMMON /CONT
/ICONT
(4),RCONT
(LRCONT
)
15 COMMON/STAT
/NFCN
,NJAC
,NSTEP
,NACCPT
,NREJCT
,NDEC
,NSOL
16 COMMON /VERWER
/ IVERWER
, IBEGIN
, STEPCUT
17 EXTERNAL VODE_FSPLIT_VAR
, VODE_Jac_SP
27 C ---- NORMAL COMPUTATION ---
30 C ---- USE OPTIONAL INPUT ---
32 IWORK
(5) = MAXORD
! MAX ORD
35 RWORK
(6) = STEPMAX
! STEP MAX
36 RWORK
(7) = STEPMIN
! STEP MIN
37 RWORK
(5) = STEPMIN
! INITIAL STEP
39 C ----- SIGNAL FOR STIFF CASE, FULL JACOBIAN, INTERN (22) or SUPPLIED (21)
42 CALL DVODE
(VODE_FSPLIT_VAR
, NVAR
, VAR
, TIN
, TOUT
, ITOL
,
44 * ISTATE
, IOPT
, RWORK
, LRW
, IWORK
, LIW
,
45 * VODE_Jac_SP
, MF
, RPAR
, IPAR
)
48 print
*,'ATMDVODE: Unsucessfull exit at T=',
49 & TIN
,' (ISTATE=',ISTATE
,')'
56 C -- This version has JAC sparse, FCN aggregate --
58 SUBROUTINE DVODE
(F
, NEQ
, Y
, T
, TOUT
, ITOL
, RelTol
, AbsTol
, ITASK
,
59 1 ISTATE
, IOPT
, RWORK
, LRW
, IWORK
, LIW
, JAC
, MF
,
62 KPP_REAL Y
, T
, TOUT
, RelTol
, AbsTol
, RWORK
, RPAR
63 INTEGER NEQ
, ITOL
, ITASK
, ISTATE
, IOPT
, LRW
, IWORK
, LIW
,
65 DIMENSION Y
(*), RelTol
(*), AbsTol
(*), RWORK
(LRW
), IWORK
(LIW
),
67 C-----------------------------------------------------------------------
68 C DVODE.. Variable-coefficient Ordinary Differential Equation solver,
69 C with fixed-leading coefficient implementation.
70 C This version is in KPP_REAL.
72 C DVODE solves the initial value problem for stiff or nonstiff
73 C systems of first order ODEs,
74 C dy/dt = f(t,y) , or, in component form,
75 C dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(NEQ)) (i = 1,...,NEQ).
76 C DVODE is a package based on the EPISODE and EPISODEB packages, and
77 C on the ODEPACK user interface standard, with minor modifications.
78 C-----------------------------------------------------------------------
79 C Revision History (YYMMDD)
81 C 890922 Added interrupt/restart ability, minor changes throughout.
82 C 910228 Minor revisions in line format, prologue, etc.
83 C 920227 Modifications by D. Pang:
84 C (1) Applied subgennam to get generic intrinsic names.
85 C (2) Changed intrinsic names to generic in comments.
86 C (3) Added *DECK lines before each routine.
87 C 920721 Names of routines and labeled Common blocks changed, so as
88 C to be unique in combined single/KPP_REAL code (ACH).
89 C 920722 Minor revisions to prologue (ACH).
90 C 920831 Conversion to KPP_REAL done (ACH).
91 C-----------------------------------------------------------------------
94 C 1. P. N. Brown, G. D. Byrne, and A. C. Hindmarsh, "VODE: A Variable
95 C Coefficient ODE Solver," SIAM J. Sci. Stat. Comput., 10 (1989),
96 C pp. 1038-1051. Also, LLNL Report UCRL-98412, June 1988.
97 C 2. G. D. Byrne and A. C. Hindmarsh, "A Polyalgorithm for the
98 C Numerical Solution of Ordinary Differential Equations,"
99 C ACM Trans. Math. Software, 1 (1975), pp. 71-96.
100 C 3. A. C. Hindmarsh and G. D. Byrne, "EPISODE: An Effective Package
101 C for the Integration of Systems of Ordinary Differential
102 C Equations," LLNL Report UCID-30112, Rev. 1, April 1977.
103 C 4. G. D. Byrne and A. C. Hindmarsh, "EPISODEB: An Experimental
104 C Package for the Integration of Systems of Ordinary Differential
105 C Equations with Banded Jacobians," LLNL Report UCID-30132, April
107 C 5. A. C. Hindmarsh, "ODEPACK, a Systematized Collection of ODE
108 C Solvers," in Scientific Computing, R. S. Stepleman et al., eds.,
109 C North-Holland, Amsterdam, 1983, pp. 55-64.
110 C 6. K. R. Jackson and R. Sacks-Davis, "An Alternative Implementation
111 C of Variable Step-Size Multistep Formulas for Stiff ODEs," ACM
112 C Trans. Math. Software, 6 (1980), pp. 295-318.
113 C-----------------------------------------------------------------------
116 C Peter N. Brown and Alan C. Hindmarsh
117 C Computing and Mathematics Research Division, L-316
118 C Lawrence Livermore National Laboratory
119 C Livermore, CA 94550
122 C Exxon Research and Engineering Co.
125 C Annandale, NJ 08801
126 C-----------------------------------------------------------------------
129 C Communication between the user and the DVODE package, for normal
130 C situations, is summarized here. This summary describes only a subset
131 C of the full set of options available. See the full description for
132 C details, including optional communication, nonstandard options,
133 C and instructions for special situations. See also the example
134 C problem (with program and output) following this summary.
136 C A. First provide a subroutine of the form..
138 C SUBROUTINE F (NEQ, T, Y, YDOT, RPAR, IPAR)
139 C KPP_REAL T, Y, YDOT, RPAR
140 C DIMENSION Y(NEQ), YDOT(NEQ)
142 C which supplies the vector function f by loading YDOT(i) with f(i).
144 C B. Next determine (or guess) whether or not the problem is stiff.
145 C Stiffness occurs when the Jacobian matrix df/dy has an eigenvalue
146 C whose real part is negative and large in magnitude, compared to the
147 C reciprocal of the t span of interest. If the problem is nonstiff,
148 C use a method flag MF = 10. If it is stiff, there are four standard
149 C choices for MF (21, 22, 24, 25), and DVODE requires the Jacobian
150 C matrix in some form. In these cases (MF .gt. 0), DVODE will use a
151 C saved copy of the Jacobian matrix. If this is undesirable because of
152 C storage limitations, set MF to the corresponding negative value
153 C (-21, -22, -24, -25). (See full description of MF below.)
154 C The Jacobian matrix is regarded either as full (MF = 21 or 22),
155 C or banded (MF = 24 or 25). In the banded case, DVODE requires two
156 C half-bandwidth parameters ML and MU. These are, respectively, the
157 C widths of the lower and upper parts of the band, excluding the main
158 C diagonal. Thus the band consists of the locations (i,j) with
159 C i-ML .le. j .le. i+MU, and the full bandwidth is ML+MU+1.
161 C C. If the problem is stiff, you are encouraged to supply the Jacobian
162 C directly (MF = 21 or 24), but if this is not feasible, DVODE will
163 C compute it internally by difference quotients (MF = 22 or 25).
164 C If you are supplying the Jacobian, provide a subroutine of the form..
166 C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD, RPAR, IPAR)
167 C KPP_REAL T, Y, PD, RPAR
168 C DIMENSION Y(NEQ), PD(NROWPD,NEQ)
170 C which supplies df/dy by loading PD as follows..
171 C For a full Jacobian (MF = 21), load PD(i,j) with df(i)/dy(j),
172 C the partial derivative of f(i) with respect to y(j). (Ignore the
173 C ML and MU arguments in this case.)
174 C For a banded Jacobian (MF = 24), load PD(i-j+MU+1,j) with
175 C df(i)/dy(j), i.e. load the diagonal lines of df/dy into the rows of
176 C PD from the top down.
177 C In either case, only nonzero elements need be loaded.
179 C D. Write a main program which calls subroutine DVODE once for
180 C each point at which answers are desired. This should also provide
181 C for possible use of logical unit 6 for output of error messages
182 C by DVODE. On the first CALL to DVODE, supply arguments as follows..
183 C F = Name of subroutine for right-hand side vector f.
184 C This name must be declared external in calling program.
185 C NEQ = Number of first order ODE-s.
186 C Y = Array of initial values, of length NEQ.
187 C T = The initial value of the independent variable.
188 C TOUT = First point where output is desired (.ne. T).
189 C ITOL = 1 or 2 according as AbsTol (below) is a scalar or array.
190 C RelTol = Relative tolerance parameter (scalar).
191 C AbsTol = Absolute tolerance parameter (scalar or array).
192 C The estimated local error in Y(i) will be controlled so as
193 C to be roughly less (in magnitude) than
194 C EWT(i) = RelTol*abs(Y(i)) + AbsTol if ITOL = 1, or
195 C EWT(i) = RelTol*abs(Y(i)) + AbsTol(i) if ITOL = 2.
196 C Thus the local error test passes if, in each component,
197 C either the absolute error is less than AbsTol (or AbsTol(i)),
198 C or the relative error is less than RelTol.
199 C Use RelTol = 0.0 for pure absolute error control, and
200 C use AbsTol = 0.0 (or AbsTol(i) = 0.0) for pure relative error
201 C control. Caution.. Actual (global) errors may exceed these
202 C local tolerances, so choose them conservatively.
203 C ITASK = 1 for normal computation of output values of Y at t = TOUT.
204 C ISTATE = Integer flag (input and output). Set ISTATE = 1.
205 C IOPT = 0 to indicate no optional input used.
206 C RWORK = Real work array of length at least..
207 C 20 + 16*NEQ for MF = 10,
208 C 22 + 9*NEQ + 2*NEQ**2 for MF = 21 or 22,
209 C 22 + 11*NEQ + (3*ML + 2*MU)*NEQ for MF = 24 or 25.
210 C LRW = Declared length of RWORK (in user's DIMENSION statement).
211 C IWORK = Integer work array of length at least..
213 C 30 + NEQ for MF = 21, 22, 24, or 25.
214 C If MF = 24 or 25, input in IWORK(1),IWORK(2) the lower
215 C and upper half-bandwidths ML,MU.
216 C LIW = Declared length of IWORK (in user's DIMENSION).
217 C JAC = Name of subroutine for Jacobian matrix (MF = 21 or 24).
218 C If used, this name must be declared external in calling
219 C program. If not used, pass a dummy name.
220 C MF = Method flag. Standard values are..
221 C 10 for nonstiff (Adams) method, no Jacobian used.
222 C 21 for stiff (BDF) method, user-supplied full Jacobian.
223 C 22 for stiff method, internally generated full Jacobian.
224 C 24 for stiff method, user-supplied banded Jacobian.
225 C 25 for stiff method, internally generated banded Jacobian.
226 C RPAR,IPAR = user-defined real and integer arrays passed to F and JAC.
227 C Note that the main program must declare arrays Y, RWORK, IWORK,
228 C and possibly AbsTol, RPAR, and IPAR.
230 C E. The output from the first CALL (or any call) is..
231 C Y = Array of computed values of y(t) vector.
232 C T = Corresponding value of independent variable (normally TOUT).
233 C ISTATE = 2 if DVODE was successful, negative otherwise.
234 C -1 means excess work done on this call. (Perhaps wrong MF.)
235 C -2 means excess accuracy requested. (Tolerances too small.)
236 C -3 means illegal input detected. (See printed message.)
237 C -4 means repeated error test failures. (Check all input.)
238 C -5 means repeated convergence failures. (Perhaps bad
239 C Jacobian supplied or wrong choice of MF or tolerances.)
240 C -6 means error weight became zero during problem. (Solution
241 C component i vanished, and AbsTol or AbsTol(i) = 0.)
243 C F. To continue the integration after a successful return, simply
244 C reset TOUT and CALL DVODE again. No other parameters need be reset.
246 C-----------------------------------------------------------------------
249 C The following is a simple example problem, with the coding
250 C needed for its solution by DVODE. The problem is from chemical
251 C kinetics, and consists of the following three rate equations..
252 C dy1/dt = -.04*y1 + 1.e4*y2*y3
253 C dy2/dt = .04*y1 - 1.e4*y2*y3 - 3.e7*y2**2
254 C dy3/dt = 3.e7*y2**2
255 C on the interval from t = 0.0 to t = 4.e10, with initial conditions
256 C y1 = 1.0, y2 = y3 = 0. The problem is stiff.
258 C The following coding solves this problem with DVODE, using MF = 21
259 C and printing results at t = .4, 4., ..., 4.e10. It uses
260 C ITOL = 2 and AbsTol much smaller for y2 than y1 or y3 because
261 C y2 has much smaller values.
262 C At the end of the run, statistical quantities of interest are
263 C printed. (See optional output in the full description below.)
264 C To generate Fortran source code, replace C in column 1 with a blank
265 C in the coding below.
268 C KPP_REAL AbsTol, RPAR, RelTol, RWORK, T, TOUT, Y
269 C DIMENSION Y(3), AbsTol(3), RWORK(67), IWORK(33)
288 C CALL DVODE(FEX,NEQ,Y,T,TOUT,ITOL,RelTol,AbsTol,ITASK,ISTATE,
289 C 1 IOPT,RWORK,LRW,IWORK,LIW,JEX,MF,RPAR,IPAR)
290 C WRITE(6,20)T,Y(1),Y(2),Y(3)
291 C 20 FORMAT(' At t =',D12.4,' y =',3D14.6)
292 C IF (ISTATE .LT. 0) GO TO 80
294 C WRITE(6,60) IWORK(11),IWORK(12),IWORK(13),IWORK(19),
295 C 1 IWORK(20),IWORK(21),IWORK(22)
296 C 60 FORMAT(/' No. steps =',I4,' No. f-s =',I4,
297 C 1 ' No. J-s =',I4,' No. LU-s =',I4/
298 C 2 ' No. nonlinear iterations =',I4/
299 C 3 ' No. nonlinear convergence failures =',I4/
300 C 4 ' No. error test failures =',I4/)
302 C 80 WRITE(6,90)ISTATE
303 C 90 FORMAT(///' Error halt.. ISTATE =',I3)
307 C SUBROUTINE FEX (NEQ, T, Y, YDOT, RPAR, IPAR)
308 C KPP_REAL RPAR, T, Y, YDOT
309 C DIMENSION Y(NEQ), YDOT(NEQ)
310 C YDOT(1) = -.04D0*Y(1) + 1.D4*Y(2)*Y(3)
311 C YDOT(3) = 3.D7*Y(2)*Y(2)
312 C YDOT(2) = -YDOT(1) - YDOT(3)
316 C SUBROUTINE JEX (NEQ, T, Y, ML, MU, PD, NRPD, RPAR, IPAR)
317 C KPP_REAL PD, RPAR, T, Y
318 C DIMENSION Y(NEQ), PD(NRPD,NEQ)
320 C PD(1,2) = 1.D4*Y(3)
321 C PD(1,3) = 1.D4*Y(2)
324 C PD(3,2) = 6.D7*Y(2)
325 C PD(2,2) = -PD(1,2) - PD(3,2)
329 C The following output was obtained from the above program on a
330 C Cray-1 computer with the CFT compiler.
332 C At t = 4.0000e-01 y = 9.851680e-01 3.386314e-05 1.479817e-02
333 C At t = 4.0000e+00 y = 9.055255e-01 2.240539e-05 9.445214e-02
334 C At t = 4.0000e+01 y = 7.158108e-01 9.184883e-06 2.841800e-01
335 C At t = 4.0000e+02 y = 4.505032e-01 3.222940e-06 5.494936e-01
336 C At t = 4.0000e+03 y = 1.832053e-01 8.942690e-07 8.167938e-01
337 C At t = 4.0000e+04 y = 3.898560e-02 1.621875e-07 9.610142e-01
338 C At t = 4.0000e+05 y = 4.935882e-03 1.984013e-08 9.950641e-01
339 C At t = 4.0000e+06 y = 5.166183e-04 2.067528e-09 9.994834e-01
340 C At t = 4.0000e+07 y = 5.201214e-05 2.080593e-10 9.999480e-01
341 C At t = 4.0000e+08 y = 5.213149e-06 2.085271e-11 9.999948e-01
342 C At t = 4.0000e+09 y = 5.183495e-07 2.073399e-12 9.999995e-01
343 C At t = 4.0000e+10 y = 5.450996e-08 2.180399e-13 9.999999e-01
345 C No. steps = 595 No. f-s = 832 No. J-s = 13 No. LU-s = 112
346 C No. nonlinear iterations = 831
347 C No. nonlinear convergence failures = 0
348 C No. error test failures = 22
349 C-----------------------------------------------------------------------
350 C Full description of user interface to DVODE.
352 C The user interface to DVODE consists of the following parts.
354 C i. The CALL sequence to subroutine DVODE, which is a driver
355 C routine for the solver. This includes descriptions of both
356 C the CALL sequence arguments and of user-supplied routines.
357 C Following these descriptions is
358 C * a description of optional input available through the
360 C * a description of optional output (in the work arrays), and
361 C * instructions for interrupting and restarting a solution.
363 C ii. Descriptions of other routines in the DVODE package that may be
364 C (optionally) called by the user. These provide the ability to
365 C alter error message handling, save and restore the internal
366 C COMMON, and obtain specified derivatives of the solution y(t).
368 C iii. Descriptions of COMMON blocks to be declared in overlay
369 C or similar environments.
371 C iv. Description of two routines in the DVODE package, either of
372 C which the user may replace with his own version, if desired.
373 C these relate to the measurement of errors.
375 C-----------------------------------------------------------------------
376 C Part i. Call Sequence.
378 C The CALL sequence parameters used for input only are
379 C F, NEQ, TOUT, ITOL, RelTol, AbsTol, ITASK, IOPT, LRW, LIW, JAC, MF,
380 C and those used for both input and output are
382 C The work arrays RWORK and IWORK are also used for conditional and
383 C optional input and optional output. (The term output here refers
384 C to the return from subroutine DVODE to the user's calling program.)
386 C The legality of input parameters will be thoroughly checked on the
387 C initial CALL for the problem, but not checked thereafter unless a
388 C change in input parameters is flagged by ISTATE = 3 in the input.
390 C The descriptions of the CALL arguments are as follows.
392 C F = The name of the user-supplied subroutine defining the
393 C ODE system. The system must be put in the first-order
394 C form dy/dt = f(t,y), where f is a vector-valued function
395 C of the scalar t and the vector y. Subroutine F is to
396 C compute the function f. It is to have the form
397 C SUBROUTINE F (NEQ, T, Y, YDOT, RPAR, IPAR)
398 C KPP_REAL T, Y, YDOT, RPAR
399 C DIMENSION Y(NEQ), YDOT(NEQ)
400 C where NEQ, T, and Y are input, and the array YDOT = f(t,y)
401 C is output. Y and YDOT are arrays of length NEQ.
402 C (In the DIMENSION statement above, NEQ can be replaced by
403 C * to make Y and YDOT assumed size arrays.)
404 C Subroutine F should not alter Y(1),...,Y(NEQ).
405 C F must be declared EXTERNAL in the calling program.
407 C Subroutine F may access user-defined real and integer
408 C work arrays RPAR and IPAR, which are to be dimensioned
409 C in the main program.
411 C If quantities computed in the F routine are needed
412 C externally to DVODE, an extra CALL to F should be made
413 C for this purpose, for consistent and accurate results.
414 C If only the derivative dy/dt is needed, use DVINDY instead.
416 C NEQ = The size of the ODE system (number of first order
417 C ordinary differential equations). Used only for input.
418 C NEQ may not be increased during the problem, but
419 C can be decreased (with ISTATE = 3 in the input).
421 C Y = A real array for the vector of dependent variables, of
422 C length NEQ or more. Used for both input and output on the
423 C first CALL (ISTATE = 1), and only for output on other calls.
424 C On the first call, Y must contain the vector of initial
425 C values. In the output, Y contains the computed solution
426 C evaluated at T. If desired, the Y array may be used
427 C for other purposes between calls to the solver.
429 C This array is passed as the Y argument in all calls to
432 C T = The independent variable. In the input, T is used only on
433 C the first call, as the initial point of the integration.
434 C In the output, after each call, T is the value at which a
435 C computed solution Y is evaluated (usually the same as TOUT).
436 C On an error return, T is the farthest point reached.
438 C TOUT = The next value of t at which a computed solution is desired.
439 C Used only for input.
441 C When starting the problem (ISTATE = 1), TOUT may be equal
442 C to T for one call, then should .ne. T for the next call.
443 C For the initial T, an input value of TOUT .ne. T is used
444 C in order to determine the direction of the integration
445 C (i.e. the algebraic sign of the step sizes) and the rough
446 C scale of the problem. Integration in either direction
447 C (forward or backward in t) is permitted.
449 C If ITASK = 2 or 5 (one-step modes), TOUT is ignored after
450 C the first CALL (i.e. the first CALL with TOUT .ne. T).
451 C Otherwise, TOUT is required on every call.
453 C If ITASK = 1, 3, or 4, the values of TOUT need not be
454 C monotone, but a value of TOUT which backs up is limited
455 C to the current internal t interval, whose endpoints are
456 C TCUR - HU and TCUR. (See optional output, below, for
459 C ITOL = An indicator for the type of error control. See
460 C description below under AbsTol. Used only for input.
462 C RelTol = A relative error tolerance parameter, either a scalar or
463 C an array of length NEQ. See description below under AbsTol.
466 C AbsTol = An absolute error tolerance parameter, either a scalar or
467 C an array of length NEQ. Input only.
469 C The input parameters ITOL, RelTol, and AbsTol determine
470 C the error control performed by the solver. The solver will
471 C control the vector e = (e(i)) of estimated local errors
472 C in Y, according to an inequality of the form
473 C rms-norm of ( e(i)/EWT(i) ) .le. 1,
474 C where EWT(i) = RelTol(i)*abs(Y(i)) + AbsTol(i),
475 C and the rms-norm (root-mean-square norm) here is
476 C rms-norm(v) = sqrt(sum v(i)**2 / NEQ). Here EWT = (EWT(i))
477 C is a vector of weights which must always be positive, and
478 C the values of RelTol and AbsTol should all be non-negative.
479 C The following table gives the types (scalar/array) of
480 C RelTol and AbsTol, and the corresponding form of EWT(i).
482 C ITOL RelTol AbsTol EWT(i)
483 C 1 scalar scalar RelTol*ABS(Y(i)) + AbsTol
484 C 2 scalar array RelTol*ABS(Y(i)) + AbsTol(i)
485 C 3 array scalar RelTol(i)*ABS(Y(i)) + AbsTol
486 C 4 array array RelTol(i)*ABS(Y(i)) + AbsTol(i)
488 C When either of these parameters is a scalar, it need not
489 C be dimensioned in the user's calling program.
491 C If none of the above choices (with ITOL, RelTol, and AbsTol
492 C fixed throughout the problem) is suitable, more general
493 C error controls can be obtained by substituting
494 C user-supplied routines for the setting of EWT and/or for
495 C the norm calculation. See Part iv below.
497 C If global errors are to be estimated by making a repeated
498 C run on the same problem with smaller tolerances, then all
499 C components of RelTol and AbsTol (i.e. of EWT) should be scaled
502 C ITASK = An index specifying the task to be performed.
503 C Input only. ITASK has the following values and meanings.
504 C 1 means normal computation of output values of y(t) at
505 C t = TOUT (by overshooting and interpolating).
506 C 2 means take one step only and return.
507 C 3 means stop at the first internal mesh point at or
508 C beyond t = TOUT and return.
509 C 4 means normal computation of output values of y(t) at
510 C t = TOUT but without overshooting t = TCRIT.
511 C TCRIT must be input as RWORK(1). TCRIT may be equal to
512 C or beyond TOUT, but not behind it in the direction of
513 C integration. This option is useful if the problem
514 C has a singularity at or beyond t = TCRIT.
515 C 5 means take one step, without passing TCRIT, and return.
516 C TCRIT must be input as RWORK(1).
518 C Note.. If ITASK = 4 or 5 and the solver reaches TCRIT
519 C (within roundoff), it will return T = TCRIT (exactly) to
520 C indicate this (unless ITASK = 4 and TOUT comes before TCRIT,
521 C in which case answers at T = TOUT are returned first).
523 C ISTATE = an index used for input and output to specify the
524 C the state of the calculation.
526 C In the input, the values of ISTATE are as follows.
527 C 1 means this is the first CALL for the problem
528 C (initializations will be done). See note below.
529 C 2 means this is not the first call, and the calculation
530 C is to continue normally, with no change in any input
531 C parameters except possibly TOUT and ITASK.
532 C (If ITOL, RelTol, and/or AbsTol are changed between calls
533 C with ISTATE = 2, the new values will be used but not
534 C tested for legality.)
535 C 3 means this is not the first call, and the
536 C calculation is to continue normally, but with
537 C a change in input parameters other than
538 C TOUT and ITASK. Changes are allowed in
539 C NEQ, ITOL, RelTol, AbsTol, IOPT, LRW, LIW, MF, ML, MU,
540 C and any of the optional input except H0.
541 C (See IWORK description for ML and MU.)
542 C Note.. A preliminary CALL with TOUT = T is not counted
543 C as a first CALL here, as no initialization or checking of
544 C input is done. (Such a CALL is sometimes useful to include
545 C the initial conditions in the output.)
546 C Thus the first CALL for which TOUT .ne. T requires
547 C ISTATE = 1 in the input.
549 C In the output, ISTATE has the following values and meanings.
550 C 1 means nothing was done, as TOUT was equal to T with
551 C ISTATE = 1 in the input.
552 C 2 means the integration was performed successfully.
553 C -1 means an excessive amount of work (more than MXSTEP
554 C steps) was done on this call, before completing the
555 C requested task, but the integration was otherwise
556 C successful as far as T. (MXSTEP is an optional input
557 C and is normally 500.) To continue, the user may
558 C simply reset ISTATE to a value .gt. 1 and CALL again.
559 C (The excess work step counter will be reset to 0.)
560 C In addition, the user may increase MXSTEP to avoid
561 C this error return. (See optional input below.)
562 C -2 means too much accuracy was requested for the precision
563 C of the machine being used. This was detected before
564 C completing the requested task, but the integration
565 C was successful as far as T. To continue, the tolerance
566 C parameters must be reset, and ISTATE must be set
567 C to 3. The optional output TOLSF may be used for this
568 C purpose. (Note.. If this condition is detected before
569 C taking any steps, then an illegal input return
570 C (ISTATE = -3) occurs instead.)
571 C -3 means illegal input was detected, before taking any
572 C integration steps. See written message for details.
573 C Note.. If the solver detects an infinite loop of calls
574 C to the solver with illegal input, it will cause
576 C -4 means there were repeated error test failures on
577 C one attempted step, before completing the requested
578 C task, but the integration was successful as far as T.
579 C The problem may have a singularity, or the input
580 C may be inappropriate.
581 C -5 means there were repeated convergence test failures on
582 C one attempted step, before completing the requested
583 C task, but the integration was successful as far as T.
584 C This may be caused by an inaccurate Jacobian matrix,
585 C if one is being used.
586 C -6 means EWT(i) became zero for some i during the
587 C integration. Pure relative error control (AbsTol(i)=0.0)
588 C was requested on a variable which has now vanished.
589 C The integration was successful as far as T.
591 C Note.. Since the normal output value of ISTATE is 2,
592 C it does not need to be reset for normal continuation.
593 C Also, since a negative input value of ISTATE will be
594 C regarded as illegal, a negative output value requires the
595 C user to change it, and possibly other input, before
596 C calling the solver again.
598 C IOPT = An integer flag to specify whether or not any optional
599 C input is being used on this call. Input only.
600 C The optional input is listed separately below.
601 C IOPT = 0 means no optional input is being used.
602 C Default values will be used in all cases.
603 C IOPT = 1 means optional input is being used.
605 C RWORK = A real working array (KPP_REAL).
606 C The length of RWORK must be at least
607 C 20 + NYH*(MAXORD + 1) + 3*NEQ + LWM where
608 C NYH = the initial value of NEQ,
609 C MAXORD = 12 (if METH = 1) or 5 (if METH = 2) (unless a
610 C smaller value is given as an optional input),
611 C LWM = length of work space for matrix-related data..
612 C LWM = 0 if MITER = 0,
613 C LWM = 2*NEQ**2 + 2 if MITER = 1 or 2, and MF.gt.0,
614 C LWM = NEQ**2 + 2 if MITER = 1 or 2, and MF.lt.0,
615 C LWM = NEQ + 2 if MITER = 3,
616 C LWM = (3*ML+2*MU+2)*NEQ + 2 if MITER = 4 or 5, and MF.gt.0,
617 C LWM = (2*ML+MU+1)*NEQ + 2 if MITER = 4 or 5, and MF.lt.0.
618 C (See the MF description for METH and MITER.)
619 C Thus if MAXORD has its default value and NEQ is constant,
621 C 20 + 16*NEQ for MF = 10,
622 C 22 + 16*NEQ + 2*NEQ**2 for MF = 11 or 12,
623 C 22 + 16*NEQ + NEQ**2 for MF = -11 or -12,
624 C 22 + 17*NEQ for MF = 13,
625 C 22 + 18*NEQ + (3*ML+2*MU)*NEQ for MF = 14 or 15,
626 C 22 + 17*NEQ + (2*ML+MU)*NEQ for MF = -14 or -15,
627 C 20 + 9*NEQ for MF = 20,
628 C 22 + 9*NEQ + 2*NEQ**2 for MF = 21 or 22,
629 C 22 + 9*NEQ + NEQ**2 for MF = -21 or -22,
630 C 22 + 10*NEQ for MF = 23,
631 C 22 + 11*NEQ + (3*ML+2*MU)*NEQ for MF = 24 or 25.
632 C 22 + 10*NEQ + (2*ML+MU)*NEQ for MF = -24 or -25.
633 C The first 20 words of RWORK are reserved for conditional
634 C and optional input and optional output.
636 C The following word in RWORK is a conditional input..
637 C RWORK(1) = TCRIT = critical value of t which the solver
638 C is not to overshoot. Required if ITASK is
639 C 4 or 5, and ignored otherwise. (See ITASK.)
641 C LRW = The length of the array RWORK, as declared by the user.
642 C (This will be checked by the solver.)
644 C IWORK = An integer work array. The length of IWORK must be at least
645 C 30 if MITER = 0 or 3 (MF = 10, 13, 20, 23), or
646 C 30 + NEQ otherwise (abs(MF) = 11,12,14,15,21,22,24,25).
647 C The first 30 words of IWORK are reserved for conditional and
648 C optional input and optional output.
650 C The following 2 words in IWORK are conditional input..
651 C IWORK(1) = ML These are the lower and upper
652 C IWORK(2) = MU half-bandwidths, respectively, of the
653 C banded Jacobian, excluding the main diagonal.
654 C The band is defined by the matrix locations
655 C (i,j) with i-ML .le. j .le. i+MU. ML and MU
656 C must satisfy 0 .le. ML,MU .le. NEQ-1.
657 C These are required if MITER is 4 or 5, and
658 C ignored otherwise. ML and MU may in fact be
659 C the band parameters for a matrix to which
660 C df/dy is only approximately equal.
662 C LIW = the length of the array IWORK, as declared by the user.
663 C (This will be checked by the solver.)
665 C Note.. The work arrays must not be altered between calls to DVODE
666 C for the same problem, except possibly for the conditional and
667 C optional input, and except for the last 3*NEQ words of RWORK.
668 C The latter space is used for internal scratch space, and so is
669 C available for use by the user outside DVODE between calls, if
670 C desired (but not for use by F or JAC).
672 C JAC = The name of the user-supplied routine (MITER = 1 or 4) to
673 C compute the Jacobian matrix, df/dy, as a function of
674 C the scalar t and the vector y. It is to have the form
675 C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD,
677 C KPP_REAL T, Y, PD, RPAR
678 C DIMENSION Y(NEQ), PD(NROWPD, NEQ)
679 C where NEQ, T, Y, ML, MU, and NROWPD are input and the array
680 C PD is to be loaded with partial derivatives (elements of the
681 C Jacobian matrix) in the output. PD must be given a first
682 C dimension of NROWPD. T and Y have the same meaning as in
683 C Subroutine F. (In the DIMENSION statement above, NEQ can
684 C be replaced by * to make Y and PD assumed size arrays.)
685 C In the full matrix case (MITER = 1), ML and MU are
686 C ignored, and the Jacobian is to be loaded into PD in
687 C columnwise manner, with df(i)/dy(j) loaded into PD(i,j).
688 C In the band matrix case (MITER = 4), the elements
689 C within the band are to be loaded into PD in columnwise
690 C manner, with diagonal lines of df/dy loaded into the rows
691 C of PD. Thus df(i)/dy(j) is to be loaded into PD(i-j+MU+1,j).
692 C ML and MU are the half-bandwidth parameters. (See IWORK).
693 C The locations in PD in the two triangular areas which
694 C correspond to nonexistent matrix elements can be ignored
695 C or loaded arbitrarily, as they are overwritten by DVODE.
696 C JAC need not provide df/dy exactly. A crude
697 C approximation (possibly with a smaller bandwidth) will do.
698 C In either case, PD is preset to zero by the solver,
699 C so that only the nonzero elements need be loaded by JAC.
700 C Each CALL to JAC is preceded by a CALL to F with the same
701 C arguments NEQ, T, and Y. Thus to gain some efficiency,
702 C intermediate quantities shared by both calculations may be
703 C saved in a user COMMON block by F and not recomputed by JAC,
704 C if desired. Also, JAC may alter the Y array, if desired.
705 C JAC must be declared external in the calling program.
706 C Subroutine JAC may access user-defined real and integer
707 C work arrays, RPAR and IPAR, whose dimensions are set by the
708 C user in the main program.
710 C MF = The method flag. Used only for input. The legal values of
711 C MF are 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25,
712 C -11, -12, -14, -15, -21, -22, -24, -25.
713 C MF is a signed two-digit integer, MF = JSV*(10*METH + MITER).
714 C JSV = SIGN(MF) indicates the Jacobian-saving strategy..
715 C JSV = 1 means a copy of the Jacobian is saved for reuse
716 C in the corrector iteration algorithm.
717 C JSV = -1 means a copy of the Jacobian is not saved
718 C (valid only for MITER = 1, 2, 4, or 5).
719 C METH indicates the basic linear multistep method..
720 C METH = 1 means the implicit Adams method.
721 C METH = 2 means the method based on backward
722 C differentiation formulas (BDF-s).
723 C MITER indicates the corrector iteration method..
724 C MITER = 0 means functional iteration (no Jacobian matrix
726 C MITER = 1 means chord iteration with a user-supplied
727 C full (NEQ by NEQ) Jacobian.
728 C MITER = 2 means chord iteration with an internally
729 C generated (difference quotient) full Jacobian
730 C (using NEQ extra calls to F per df/dy value).
731 C MITER = 3 means chord iteration with an internally
732 C generated diagonal Jacobian approximation
733 C (using 1 extra CALL to F per df/dy evaluation).
734 C MITER = 4 means chord iteration with a user-supplied
736 C MITER = 5 means chord iteration with an internally
737 C generated banded Jacobian (using ML+MU+1 extra
738 C calls to F per df/dy evaluation).
739 C If MITER = 1 or 4, the user must supply a subroutine JAC
740 C (the name is arbitrary) as described above under JAC.
741 C For other values of MITER, a dummy argument can be used.
743 C RPAR User-specified array used to communicate real parameters
744 C to user-supplied subroutines. If RPAR is a vector, then
745 C it must be dimensioned in the user's main program. If it
746 C is unused or it is a scalar, then it need not be
749 C IPAR User-specified array used to communicate integer parameter
750 C to user-supplied subroutines. The comments on dimensioning
751 C RPAR apply to IPAR.
752 C-----------------------------------------------------------------------
755 C The following is a list of the optional input provided for in the
756 C CALL sequence. (See also Part ii.) For each such input variable,
757 C this table lists its name as used in this documentation, its
758 C location in the CALL sequence, its meaning, and the default value.
759 C The use of any of this input requires IOPT = 1, and in that
760 C case all of this input is examined. A value of zero for any
761 C of these optional input variables will cause the default value to be
762 C used. Thus to use a subset of the optional input, simply preload
763 C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively, and
764 C then set those of interest to nonzero values.
766 C NAME LOCATION MEANING AND DEFAULT VALUE
768 C H0 RWORK(5) The step size to be attempted on the first step.
769 C The default value is determined by the solver.
771 C HMAX RWORK(6) The maximum absolute step size allowed.
772 C The default value is infinite.
774 C HMIN RWORK(7) The minimum absolute step size allowed.
775 C The default value is 0. (This lower bound is not
776 C enforced on the final step before reaching TCRIT
777 C when ITASK = 4 or 5.)
779 C MAXORD IWORK(5) The maximum order to be allowed. The default
780 C value is 12 if METH = 1, and 5 if METH = 2.
781 C If MAXORD exceeds the default value, it will
782 C be reduced to the default value.
783 C If MAXORD is changed during the problem, it may
784 C cause the current order to be reduced.
786 C MXSTEP IWORK(6) Maximum number of (internally defined) steps
787 C allowed during one CALL to the solver.
788 C The default value is 500.
790 C MXHNIL IWORK(7) Maximum number of messages printed (per problem)
791 C warning that T + H = T on a step (H = step size).
792 C This must be positive to result in a non-default
793 C value. The default value is 10.
795 C-----------------------------------------------------------------------
798 C As optional additional output from DVODE, the variables listed
799 C below are quantities related to the performance of DVODE
800 C which are available to the user. These are communicated by way of
801 C the work arrays, but also have internal mnemonic names as shown.
802 C Except where stated otherwise, all of this output is defined
803 C on any successful return from DVODE, and on any return with
804 C ISTATE = -1, -2, -4, -5, or -6. On an illegal input return
805 C (ISTATE = -3), they will be unchanged from their existing values
806 C (if any), except possibly for TOLSF, LENRW, and LENIW.
807 C On any error return, output relevant to the error will be defined,
810 C NAME LOCATION MEANING
812 C HU RWORK(11) The step size in t last used (successfully).
814 C HCUR RWORK(12) The step size to be attempted on the next step.
816 C TCUR RWORK(13) The current value of the independent variable
817 C which the solver has actually reached, i.e. the
818 C current internal mesh point in t. In the output,
819 C TCUR will always be at least as far from the
820 C initial value of t as the current argument T,
821 C but may be farther (if interpolation was done).
823 C TOLSF RWORK(14) A tolerance scale factor, greater than 1.0,
824 C computed when a request for too much accuracy was
825 C detected (ISTATE = -3 if detected at the start of
826 C the problem, ISTATE = -2 otherwise). If ITOL is
827 C left unaltered but RelTol and AbsTol are uniformly
828 C scaled up by a factor of TOLSF for the next call,
829 C then the solver is deemed likely to succeed.
830 C (The user may also ignore TOLSF and alter the
831 C tolerance parameters in any other way appropriate.)
833 C NST IWORK(11) The number of steps taken for the problem so far.
835 C NFE IWORK(12) The number of f evaluations for the problem so far.
837 C NJE IWORK(13) The number of Jacobian evaluations so far.
839 C NQU IWORK(14) The method order last used (successfully).
841 C NQCUR IWORK(15) The order to be attempted on the next step.
843 C IMXER IWORK(16) The index of the component of largest magnitude in
844 C the weighted local error vector ( e(i)/EWT(i) ),
845 C on an error return with ISTATE = -4 or -5.
847 C LENRW IWORK(17) The length of RWORK actually required.
848 C This is defined on normal returns and on an illegal
849 C input return for insufficient storage.
851 C LENIW IWORK(18) The length of IWORK actually required.
852 C This is defined on normal returns and on an illegal
853 C input return for insufficient storage.
855 C NLU IWORK(19) The number of matrix LU decompositions so far.
857 C NNI IWORK(20) The number of nonlinear (Newton) iterations so far.
859 C NCFN IWORK(21) The number of convergence failures of the nonlinear
862 C NETF IWORK(22) The number of error test failures of the integrator
865 C The following two arrays are segments of the RWORK array which
866 C may also be of interest to the user as optional output.
867 C For each array, the table below gives its internal name,
868 C its base address in RWORK, and its description.
870 C NAME BASE ADDRESS DESCRIPTION
872 C YH 21 The Nordsieck history array, of size NYH by
873 C (NQCUR + 1), where NYH is the initial value
874 C of NEQ. For j = 0,1,...,NQCUR, column j+1
875 C of YH contains HCUR**j/factorial(j) times
876 C the j-th derivative of the interpolating
877 C polynomial currently representing the
878 C solution, evaluated at t = TCUR.
880 C ACOR LENRW-NEQ+1 Array of size NEQ used for the accumulated
881 C corrections on each step, scaled in the output
882 C to represent the estimated local error in Y
883 C on the last step. This is the vector e in
884 C the description of the error control. It is
885 C defined only on a successful return from DVODE.
887 C-----------------------------------------------------------------------
888 C Interrupting and Restarting
890 C If the integration of a given problem by DVODE is to be
891 C interrupted and then later continued, such as when restarting
892 C an interrupted run or alternating between two or more ODE problems,
893 C the user should save, following the return from the last DVODE call
894 C prior to the interruption, the contents of the CALL sequence
895 C variables and internal COMMON blocks, and later restore these
896 C values before the next DVODE CALL for that problem. To save
897 C and restore the COMMON blocks, use subroutine DVSRCO, as
898 C described below in part ii.
900 C In addition, if non-default values for either LUN or MFLAG are
901 C desired, an extra CALL to XSETUN and/or XSETF should be made just
902 C before continuing the integration. See Part ii below for details.
904 C-----------------------------------------------------------------------
905 C Part ii. Other Routines Callable.
907 C The following are optional calls which the user may make to
908 C gain additional capabilities in conjunction with DVODE.
909 C (The routines XSETUN and XSETF are designed to conform to the
910 C SLATEC error handling package.)
912 C FORM OF CALL FUNCTION
913 C CALL XSETUN(LUN) Set the logical unit number, LUN, for
914 C output of messages from DVODE, if
915 C the default is not desired.
916 C The default value of LUN is 6.
918 C CALL XSETF(MFLAG) Set a flag to control the printing of
920 C MFLAG = 0 means do not print. (Danger..
921 C This risks losing valuable information.)
922 C MFLAG = 1 means print (the default).
924 C Either of the above calls may be made at
925 C any time and will take effect immediately.
927 C CALL DVSRCO(RSAV,ISAV,JOB) Saves and restores the contents of
928 C the internal COMMON blocks used by
929 C DVODE. (See Part iii below.)
930 C RSAV must be a real array of length 49
931 C or more, and ISAV must be an integer
932 C array of length 40 or more.
933 C JOB=1 means save COMMON into RSAV/ISAV.
934 C JOB=2 means restore COMMON from RSAV/ISAV.
935 C DVSRCO is useful if one is
936 C interrupting a run and restarting
937 C later, or alternating between two or
938 C more problems solved with DVODE.
940 C CALL DVINDY(,,,,,) Provide derivatives of y, of various
941 C (See below.) orders, at a specified point T, if
942 C desired. It may be called only after
943 C a successful return from DVODE.
945 C The detailed instructions for using DVINDY are as follows.
946 C The form of the CALL is..
948 C CALL DVINDY (T, K, RWORK(21), NYH, DKY, IFLAG)
950 C The input parameters are..
952 C T = Value of independent variable where answers are desired
953 C (normally the same as the T last returned by DVODE).
954 C For valid results, T must lie between TCUR - HU and TCUR.
955 C (See optional output for TCUR and HU.)
956 C K = Integer order of the derivative desired. K must satisfy
957 C 0 .le. K .le. NQCUR, where NQCUR is the current order
958 C (see optional output). The capability corresponding
959 C to K = 0, i.e. computing y(T), is already provided
960 C by DVODE directly. Since NQCUR .ge. 1, the first
961 C derivative dy/dt is always available with DVINDY.
962 C RWORK(21) = The base address of the history array YH.
963 C NYH = Column length of YH, equal to the initial value of NEQ.
965 C The output parameters are..
967 C DKY = A real array of length NEQ containing the computed value
968 C of the K-th derivative of y(t).
969 C IFLAG = Integer flag, returned as 0 if K and T were legal,
970 C -1 if K was illegal, and -2 if T was illegal.
971 C On an error return, a message is also written.
972 C-----------------------------------------------------------------------
973 C Part iii. COMMON Blocks.
974 C If DVODE is to be used in an overlay situation, the user
975 C must declare, in the primary overlay, the variables in..
976 C (1) the CALL sequence to DVODE,
977 C (2) the two internal COMMON blocks
978 C /DVOD01/ of length 81 (48 KPP_REAL words
979 C followed by 33 integer words),
980 C /DVOD02/ of length 9 (1 KPP_REAL word
981 C followed by 8 integer words),
983 C If DVODE is used on a system in which the contents of internal
984 C COMMON blocks are not preserved between calls, the user should
985 C declare the above two COMMON blocks in his main program to insure
986 C that their contents are preserved.
988 C-----------------------------------------------------------------------
989 C Part iv. Optionally Replaceable Solver Routines.
991 C Below are descriptions of two routines in the DVODE package which
992 C relate to the measurement of errors. Either routine can be
993 C replaced by a user-supplied version, if desired. However, since such
994 C a replacement may have a major impact on performance, it should be
995 C done only when absolutely necessary, and only with great caution.
996 C (Note.. The means by which the package version of a routine is
997 C superseded by the user's version may be system-dependent.)
1000 C The following subroutine is called just before each internal
1001 C integration step, and sets the array of error weights, EWT, as
1002 C described under ITOL/RelTol/AbsTol above..
1003 C SUBROUTINE DEWSET (NEQ, ITOL, RelTol, AbsTol, YCUR, EWT)
1004 C where NEQ, ITOL, RelTol, and AbsTol are as in the DVODE CALL sequence,
1005 C YCUR contains the current dependent variable vector, and
1006 C EWT is the array of weights set by DEWSET.
1008 C If the user supplies this subroutine, it must return in EWT(i)
1009 C (i = 1,...,NEQ) a positive quantity suitable for comparison with
1010 C errors in Y(i). The EWT array returned by DEWSET is passed to the
1011 C DVNORM routine (See below.), and also used by DVODE in the computation
1012 C of the optional output IMXER, the diagonal Jacobian approximation,
1013 C and the increments for difference quotient Jacobians.
1015 C In the user-supplied version of DEWSET, it may be desirable to use
1016 C the current values of derivatives of y. Derivatives up to order NQ
1017 C are available from the history array YH, described above under
1018 C Optional Output. In DEWSET, YH is identical to the YCUR array,
1019 C extended to NQ + 1 columns with a column length of NYH and scale
1020 C factors of h**j/factorial(j). On the first CALL for the problem,
1021 C given by NST = 0, NQ is 1 and H is temporarily set to 1.0.
1022 C NYH is the initial value of NEQ. The quantities NQ, H, and NST
1023 C can be obtained by including in DEWSET the statements..
1024 C KPP_REAL RVOD, H, HU
1025 C COMMON /DVOD01/ RVOD(48), IVOD(33)
1026 C COMMON /DVOD02/ HU, NCFN, NETF, NFE, NJE, NLU, NNI, NQU, NST
1029 C Thus, for example, the current value of dy/dt can be obtained as
1030 C YCUR(NYH+i)/H (i=1,...,NEQ) (and the division by H is
1031 C unnecessary when NST = 0).
1034 C The following is a real function routine which computes the weighted
1035 C root-mean-square norm of a vector v..
1036 C D = DVNORM (N, V, W)
1038 C N = the length of the vector,
1039 C V = real array of length N containing the vector,
1040 C W = real array of length N containing weights,
1041 C D = sqrt( (1/N) * sum(V(i)*W(i))**2 ).
1042 C DVNORM is called with N = NEQ and with W(i) = 1.0/EWT(i), where
1043 C EWT is as set by subroutine DEWSET.
1045 C If the user supplies this function, it should return a non-negative
1046 C value of DVNORM suitable for use in the error control in DVODE.
1047 C None of the arguments should be altered by DVNORM.
1048 C For example, a user-supplied DVNORM routine might..
1049 C -substitute a max-norm of (V(i)*W(i)) for the rms-norm, or
1050 C -ignore some components of V in the norm, with the effect of
1051 C suppressing the error control on those components of Y.
1052 C-----------------------------------------------------------------------
1053 C Other Routines in the DVODE Package.
1055 C In addition to subroutine DVODE, the DVODE package includes the
1056 C following subroutines and function routines..
1057 C DVHIN computes an approximate step size for the initial step.
1058 C DVINDY computes an interpolated value of the y vector at t = TOUT.
1059 C DVSTEP is the core integrator, which does one step of the
1060 C integration and the associated error control.
1061 C DVSET sets all method coefficients and test constants.
1062 C DVNLSD solves the underlying nonlinear system -- the corrector.
1063 C DVJAC computes and preprocesses the Jacobian matrix J = df/dy
1064 C and the Newton iteration matrix P = I - (h/l1)*J.
1065 C DVSOL manages solution of linear system in chord iteration.
1066 C DVJUST adjusts the history array on a change of order.
1067 C DEWSET sets the error weight vector EWT before each step.
1068 C DVNORM computes the weighted r.m.s. norm of a vector.
1069 C DVSRCO is a user-callable routines to save and restore
1070 C the contents of the internal COMMON blocks.
1071 C DACOPY is a routine to copy one two-dimensional array to another.
1072 C DGEFA and DGESL are routines from LINPACK for solving full
1073 C systems of linear algebraic equations.
1074 C DGBFA and DGBSL are routines from LINPACK for solving banded
1076 C DAXPY, DSCAL, and DCOPY are basic linear algebra modules (BLAS).
1077 C D1MACH sets the unit roundoff of the machine.
1078 C XERRWD, XSETUN, XSETF, LUNSAV, and MFLGSV handle the printing of all
1079 C error messages and warnings. XERRWD is machine-dependent.
1080 C Note.. DVNORM, D1MACH, LUNSAV, and MFLGSV are function routines.
1081 C All the others are subroutines.
1083 C The intrinsic and external routines used by the DVODE package are..
1084 C ABS, MAX, MIN, REAL, SIGN, SQRT, and WRITE.
1086 C-----------------------------------------------------------------------
1088 C Type declarations for labeled COMMON block DVOD01 --------------------
1090 KPP_REAL ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
,
1091 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
1092 2 RC
, RL1
, TAU
, TQ
, TN
, UROUND
1093 INTEGER ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
1094 1 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
1095 2 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
1096 3 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
1099 C Type declarations for labeled COMMON block DVOD02 --------------------
1102 INTEGER NCFN
, NETF
, NFE
, NJE
, NLU
, NNI
, NQU
, NST
1104 C Type declarations for local variables --------------------------------
1106 EXTERNAL DVNLSD
, F
, JAC
1108 KPP_REAL AbsTolI
, BIG
, EWTI
, FOUR
, H0
, HMAX
, HMX
, HUN
, ONE
,
1109 1 PT2
, RH
, RelTolI
, SIZE
, TCRIT
, TNEXT
, TOLSF
, TP
, TWO
, ZERO
1110 INTEGER I
, IER
, IFLAG
, IMXER
, JCO
, KGO
, LENIW
, LENJ
, LENP
, LENRW
,
1111 1 LENWM
, LF0
, MBAND
, ML
, MORD
, MU
, MXHNL0
, MXSTP0
, NITER
, NSLAST
1114 C Type declaration for function subroutines called ---------------------
1116 KPP_REAL D1MACH
, DVNORM
1119 C-----------------------------------------------------------------------
1120 C The following Fortran-77 declaration is to cause the values of the
1121 C listed (local) variables to be saved between calls to DVODE.
1122 C-----------------------------------------------------------------------
1123 SAVE MORD
, MXHNL0
, MXSTP0
1124 SAVE ZERO
, ONE
, TWO
, FOUR
, PT2
, HUN
1125 C-----------------------------------------------------------------------
1126 C The following internal COMMON blocks contain variables which are
1127 C communicated between subroutines in the DVODE package, or which are
1128 C to be saved between calls to DVODE.
1129 C In each block, real variables precede integers.
1130 C The block /DVOD01/ appears in subroutines DVODE, DVINDY, DVSTEP,
1131 C DVSET, DVNLSD, DVJAC, DVSOL, DVJUST and DVSRCO.
1132 C The block /DVOD02/ appears in subroutines DVODE, DVINDY, DVSTEP,
1133 C DVNLSD, DVJAC, and DVSRCO.
1135 C The variables stored in the internal COMMON blocks are as follows..
1137 C ACNRM = Weighted r.m.s. norm of accumulated correction vectors.
1138 C CCMXJ = Threshhold on DRC for updating the Jacobian. (See DRC.)
1139 C CONP = The saved value of TQ(5).
1140 C CRATE = Estimated corrector convergence rate constant.
1141 C DRC = Relative change in H*RL1 since last DVJAC call.
1142 C EL = Real array of integration coefficients. See DVSET.
1143 C ETA = Saved tentative ratio of new to old H.
1144 C ETAMAX = Saved maximum value of ETA to be allowed.
1145 C H = The step size.
1146 C HMIN = The minimum absolute value of the step size H to be used.
1147 C HMXI = Inverse of the maximum absolute value of H to be used.
1148 C HMXI = 0.0 is allowed and corresponds to an infinite HMAX.
1149 C HNEW = The step size to be attempted on the next step.
1150 C HSCAL = Stepsize in scaling of YH array.
1151 C PRL1 = The saved value of RL1.
1152 C RC = Ratio of current H*RL1 to value on last DVJAC call.
1153 C RL1 = The reciprocal of the coefficient EL(1).
1154 C TAU = Real vector of past NQ step sizes, length 13.
1155 C TQ = A real vector of length 5 in which DVSET stores constants
1156 C used for the convergence test, the error test, and the
1157 C selection of H at a new order.
1158 C TN = The independent variable, updated on each step taken.
1159 C UROUND = The machine unit roundoff. The smallest positive real number
1160 C such that 1.0 + UROUND .ne. 1.0
1161 C ICF = Integer flag for convergence failure in DVNLSD..
1162 C 0 means no failures.
1163 C 1 means convergence failure with out of date Jacobian
1164 C (recoverable error).
1165 C 2 means convergence failure with current Jacobian or
1166 C singular matrix (unrecoverable error).
1167 C INIT = Saved integer flag indicating whether initialization of the
1168 C problem has been done (INIT = 1) or not.
1169 C IPUP = Saved flag to signal updating of Newton matrix.
1170 C JCUR = Output flag from DVJAC showing Jacobian status..
1171 C JCUR = 0 means J is not current.
1172 C JCUR = 1 means J is current.
1173 C JSTART = Integer flag used as input to DVSTEP..
1174 C 0 means perform the first step.
1175 C 1 means take a new step continuing from the last.
1176 C -1 means take the next step with a new value of MAXORD,
1177 C HMIN, HMXI, N, METH, MITER, and/or matrix parameters.
1178 C On return, DVSTEP sets JSTART = 1.
1179 C JSV = Integer flag for Jacobian saving, = sign(MF).
1180 C KFLAG = A completion code from DVSTEP with the following meanings..
1181 C 0 the step was succesful.
1182 C -1 the requested error could not be achieved.
1183 C -2 corrector convergence could not be achieved.
1184 C -3, -4 fatal error in VNLS (can not occur here).
1185 C KUTH = Input flag to DVSTEP showing whether H was reduced by the
1186 C driver. KUTH = 1 if H was reduced, = 0 otherwise.
1187 C L = Integer variable, NQ + 1, current order plus one.
1188 C LMAX = MAXORD + 1 (used for dimensioning).
1189 C LOCJS = A pointer to the saved Jacobian, whose storage starts at
1190 C WM(LOCJS), if JSV = 1.
1191 C LYH, LEWT, LACOR, LSAVF, LWM, LIWM = Saved integer pointers
1192 C to segments of RWORK and IWORK.
1193 C MAXORD = The maximum order of integration method to be allowed.
1194 C METH/MITER = The method flags. See MF.
1195 C MSBJ = The maximum number of steps between J evaluations, = 50.
1196 C MXHNIL = Saved value of optional input MXHNIL.
1197 C MXSTEP = Saved value of optional input MXSTEP.
1198 C N = The number of first-order ODEs, = NEQ.
1199 C NEWH = Saved integer to flag change of H.
1200 C NEWQ = The method order to be used on the next step.
1201 C NHNIL = Saved counter for occurrences of T + H = T.
1202 C NQ = Integer variable, the current integration method order.
1203 C NQNYH = Saved value of NQ*NYH.
1204 C NQWAIT = A counter controlling the frequency of order changes.
1205 C An order change is about to be considered if NQWAIT = 1.
1206 C NSLJ = The number of steps taken as of the last Jacobian update.
1207 C NSLP = Saved value of NST as of last Newton matrix update.
1208 C NYH = Saved value of the initial value of NEQ.
1209 C HU = The step size in t last used.
1210 C NCFN = Number of nonlinear convergence failures so far.
1211 C NETF = The number of error test failures of the integrator so far.
1212 C NFE = The number of f evaluations for the problem so far.
1213 C NJE = The number of Jacobian evaluations so far.
1214 C NLU = The number of matrix LU decompositions so far.
1215 C NNI = Number of nonlinear iterations so far.
1216 C NQU = The method order last used.
1217 C NST = The number of steps taken for the problem so far.
1218 C-----------------------------------------------------------------------
1219 COMMON /DVOD01
/ ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
(13),
1220 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
1221 2 RC
, RL1
, TAU
(13), TQ
(5), TN
, UROUND
,
1222 3 ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
1223 4 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
1224 5 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
1225 6 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
1227 COMMON /DVOD02
/ HU
, NCFN
, NETF
, NFE
, NJE
, NLU
, NNI
, NQU
, NST
1230 DATA MORD
(1) /12/, MORD
(2) /5/, MXSTP0
/500/, MXHNL0
/10/
1231 DATA ZERO
/0.0D0
/, ONE
/1.0D0
/, TWO
/2.0D0
/, FOUR
/4.0D0
/,
1232 1 PT2
/0.2D0
/, HUN
/100.0D0
/
1233 C-----------------------------------------------------------------------
1235 C This code block is executed on every call.
1236 C It tests ISTATE and ITASK for legality and branches appropriately.
1237 C If ISTATE .gt. 1 but the flag INIT shows that initialization has
1238 C not yet been done, an error return occurs.
1239 C If ISTATE = 1 and TOUT = T, return immediately.
1240 C-----------------------------------------------------------------------
1241 IF (ISTATE
.LT
. 1 .OR
. ISTATE
.GT
. 3) GO TO 601
1242 IF (ITASK
.LT
. 1 .OR
. ITASK
.GT
. 5) GO TO 602
1243 IF (ISTATE
.EQ
. 1) GO TO 10
1244 IF (INIT
.NE
. 1) GO TO 603
1245 IF (ISTATE
.EQ
. 2) GO TO 200
1248 IF (TOUT
.EQ
. T
) RETURN
1249 C-----------------------------------------------------------------------
1251 C The next code block is executed for the initial CALL (ISTATE = 1),
1252 C or for a continuation CALL with parameter changes (ISTATE = 3).
1253 C It contains checking of all input and various initializations.
1255 C First check legality of the non-optional input NEQ, ITOL, IOPT,
1257 C-----------------------------------------------------------------------
1258 20 IF (NEQ
.LE
. 0) GO TO 604
1259 IF (ISTATE
.EQ
. 1) GO TO 25
1260 IF (NEQ
.GT
. N
) GO TO 605
1262 IF (ITOL
.LT
. 1 .OR
. ITOL
.GT
. 4) GO TO 606
1263 IF (IOPT
.LT
. 0 .OR
. IOPT
.GT
. 1) GO TO 607
1267 MITER
= MF
- 10*METH
1268 IF (METH
.LT
. 1 .OR
. METH
.GT
. 2) GO TO 608
1269 IF (MITER
.LT
. 0 .OR
. MITER
.GT
. 5) GO TO 608
1270 IF (MITER
.LE
. 3) GO TO 30
1273 IF (ML
.LT
. 0 .OR
. ML
.GE
. N
) GO TO 609
1274 IF (MU
.LT
. 0 .OR
. MU
.GE
. N
) GO TO 610
1276 C Next process and check the optional input. ---------------------------
1277 IF (IOPT
.EQ
. 1) GO TO 40
1281 IF (ISTATE
.EQ
. 1) H0
= ZERO
1285 40 MAXORD
= IWORK
(5)
1286 IF (MAXORD
.LT
. 0) GO TO 611
1287 IF (MAXORD
.EQ
. 0) MAXORD
= 100
1288 MAXORD
= MIN
(MAXORD
,MORD
(METH
))
1290 IF (MXSTEP
.LT
. 0) GO TO 612
1291 IF (MXSTEP
.EQ
. 0) MXSTEP
= MXSTP0
1293 IF (MXHNIL
.LT
. 0) GO TO 613
1294 IF (MXHNIL
.EQ
. 0) MXHNIL
= MXHNL0
1295 IF (ISTATE
.NE
. 1) GO TO 50
1297 IF ((TOUT
- T
)*H0
.LT
. ZERO
) GO TO 614
1299 IF (HMAX
.LT
. ZERO
) GO TO 615
1301 IF (HMAX
.GT
. ZERO
) HMXI
= ONE
/HMAX
1303 IF (HMIN
.LT
. ZERO
) GO TO 616
1304 C-----------------------------------------------------------------------
1305 C Set work array pointers and check lengths LRW and LIW.
1306 C Pointers to segments of RWORK and IWORK are named by prefixing L to
1307 C the name of the segment. E.g., the segment YH starts at RWORK(LYH).
1308 C Segments of RWORK (in order) are denoted YH, WM, EWT, SAVF, ACOR.
1309 C Within WM, LOCJS is the location of the saved Jacobian (JSV .gt. 0).
1310 C-----------------------------------------------------------------------
1312 IF (ISTATE
.EQ
. 1) NYH
= N
1313 LWM
= LYH
+ (MAXORD
+ 1)*NYH
1315 IF (MITER
.EQ
. 0) LENWM
= 0
1316 IF (MITER
.EQ
. 1 .OR
. MITER
.EQ
. 2) THEN
1317 LENWM
= 2 + (1 + JCO
)*N*N
1320 IF (MITER
.EQ
. 3) LENWM
= 2 + N
1321 IF (MITER
.EQ
. 4 .OR
. MITER
.EQ
. 5) THEN
1323 LENP
= (MBAND
+ ML
)*N
1325 LENWM
= 2 + LENP
+ JCO*LENJ
1331 LENRW
= LACOR
+ N
- 1
1335 IF (MITER
.EQ
. 0 .OR
. MITER
.EQ
. 3) LENIW
= 30
1337 IF (LENRW
.GT
. LRW
) GO TO 617
1338 IF (LENIW
.GT
. LIW
) GO TO 618
1339 C Check RelTol and AbsTol for legality. ------------------------------------
1343 IF (ITOL
.GE
. 3) RelTolI
= RelTol
(I
)
1344 IF (ITOL
.EQ
. 2 .OR
. ITOL
.EQ
. 4) AbsTolI
= AbsTol
(I
)
1345 IF (RelTolI
.LT
. ZERO
) GO TO 619
1346 IF (AbsTolI
.LT
. ZERO
) GO TO 620
1348 IF (ISTATE
.EQ
. 1) GO TO 100
1349 C If ISTATE = 3, set flag to signal parameter changes to DVSTEP. -------
1351 IF (NQ
.LE
. MAXORD
) GO TO 90
1352 C MAXORD was reduced below NQ. Copy YH(*,MAXORD+2) into SAVF. ---------
1353 CALL DCOPY
(N
, RWORK
(LWM
), 1, RWORK
(LSAVF
), 1)
1354 C Reload WM(1) = RWORK(LWM), since LWM may have changed. ---------------
1355 90 IF (MITER
.GT
. 0) RWORK
(LWM
) = SQRT
(UROUND
)
1356 C-----------------------------------------------------------------------
1358 C The next block is for the initial CALL only (ISTATE = 1).
1359 C It contains all remaining initializations, the initial CALL to F,
1360 C and the calculation of the initial step size.
1361 C The error weights in EWT are inverted after being loaded.
1362 C-----------------------------------------------------------------------
1363 100 UROUND
= D1MACH
(4)
1365 IF (ITASK
.NE
. 4 .AND
. ITASK
.NE
. 5) GO TO 110
1367 IF ((TCRIT
- TOUT
)*(TOUT
- T
) .LT
. ZERO
) GO TO 625
1368 IF (H0
.NE
. ZERO
.AND
. (T
+ H0
- TCRIT
)*H0
.GT
. ZERO
)
1371 IF (MITER
.GT
. 0) RWORK
(LWM
) = SQRT
(UROUND
)
1385 C Initial CALL to F. (LF0 points to YH(*,2).) -------------------------
1387 CALL F
(N
, T
, Y
, RWORK
(LF0
))
1389 C Load the initial value vector in YH. ---------------------------------
1390 CALL DCOPY
(N
, Y
, 1, RWORK
(LYH
), 1)
1391 C Load and invert the EWT array. (H is temporarily set to 1.0.) -------
1394 CALL DEWSET
(N
, ITOL
, RelTol
, AbsTol
, RWORK
(LYH
), RWORK
(LEWT
))
1396 IF (RWORK
(I
+LEWT
-1) .LE
. ZERO
) GO TO 621
1397 120 RWORK
(I
+LEWT
-1) = ONE
/RWORK
(I
+LEWT
-1)
1398 IF (H0
.NE
. ZERO
) GO TO 180
1399 C Call DVHIN to set initial step size H0 to be attempted. --------------
1400 CALL DVHIN
(N
, T
, RWORK
(LYH
), RWORK
(LF0
), F
, RPAR
, IPAR
, TOUT
,
1401 1 UROUND
, RWORK
(LEWT
), ITOL
, AbsTol
, Y
, RWORK
(LACOR
), H0
,
1404 IF (IER
.NE
. 0) GO TO 622
1405 C Adjust H0 if necessary to meet HMAX bound. ---------------------------
1406 180 RH
= ABS
(H0
)*HMXI
1407 IF (RH
.GT
. ONE
) H0
= H0
/RH
1408 C Load H with H0 and scale YH(*,2) by H0. ------------------------------
1410 CALL DSCAL
(N
, H0
, RWORK
(LF0
), 1)
1412 C-----------------------------------------------------------------------
1414 C The next code block is for continuation calls only (ISTATE = 2 or 3)
1415 C and is to check stop conditions before taking a step.
1416 C-----------------------------------------------------------------------
1419 GO TO (210, 250, 220, 230, 240), ITASK
1420 210 IF ((TN
- TOUT
)*H
.LT
. ZERO
) GO TO 250
1421 CALL DVINDY
(TOUT
, 0, RWORK
(LYH
), NYH
, Y
, IFLAG
)
1422 IF (IFLAG
.NE
. 0) GO TO 627
1425 220 TP
= TN
- HU*
(ONE
+ HUN*UROUND
)
1426 IF ((TP
- TOUT
)*H
.GT
. ZERO
) GO TO 623
1427 IF ((TN
- TOUT
)*H
.LT
. ZERO
) GO TO 250
1429 230 TCRIT
= RWORK
(1)
1430 IF ((TN
- TCRIT
)*H
.GT
. ZERO
) GO TO 624
1431 IF ((TCRIT
- TOUT
)*H
.LT
. ZERO
) GO TO 625
1432 IF ((TN
- TOUT
)*H
.LT
. ZERO
) GO TO 245
1433 CALL DVINDY
(TOUT
, 0, RWORK
(LYH
), NYH
, Y
, IFLAG
)
1434 IF (IFLAG
.NE
. 0) GO TO 627
1437 240 TCRIT
= RWORK
(1)
1438 IF ((TN
- TCRIT
)*H
.GT
. ZERO
) GO TO 624
1439 245 HMX
= ABS
(TN
) + ABS
(H
)
1440 IHIT
= ABS
(TN
- TCRIT
) .LE
. HUN*UROUND*HMX
1442 TNEXT
= TN
+ HNEW*
(ONE
+ FOUR*UROUND
)
1443 IF ((TNEXT
- TCRIT
)*H
.LE
. ZERO
) GO TO 250
1444 H
= (TCRIT
- TN
)*(ONE
- FOUR*UROUND
)
1446 C-----------------------------------------------------------------------
1448 C The next block is normally executed for all calls and contains
1449 C the CALL to the one-step core integrator DVSTEP.
1451 C This is a looping point for the integration steps.
1453 C First check for too many steps being taken, update EWT (if not at
1454 C start of problem), check for too much accuracy being requested, and
1455 C check for H below the roundoff level in T.
1456 C-----------------------------------------------------------------------
1458 IF ((NST
-NSLAST
) .GE
. MXSTEP
) GO TO 500
1459 CALL DEWSET
(N
, ITOL
, RelTol
, AbsTol
, RWORK
(LYH
), RWORK
(LEWT
))
1461 IF (RWORK
(I
+LEWT
-1) .LE
. ZERO
) GO TO 510
1462 260 RWORK
(I
+LEWT
-1) = ONE
/RWORK
(I
+LEWT
-1)
1463 270 TOLSF
= UROUND*DVNORM
(N
, RWORK
(LYH
), RWORK
(LEWT
))
1464 IF (TOLSF
.LE
. ONE
) GO TO 280
1466 IF (NST
.EQ
. 0) GO TO 626
1468 280 IF ((TN
+ H
) .NE
. TN
) GO TO 290
1470 IF (NHNIL
.GT
. MXHNIL
) GO TO 290
1471 MSG
= 'DVODE-- Warning..internal T (=R1) and H (=R2) are'
1472 CALL XERRWD
(MSG
, 50, 101, 1, 0, 0, 0, 0, ZERO
, ZERO
)
1473 MSG
=' such that in the machine, T + H = T on the next step '
1474 CALL XERRWD
(MSG
, 60, 101, 1, 0, 0, 0, 0, ZERO
, ZERO
)
1475 MSG
= ' (H = step size). solver will continue anyway'
1476 CALL XERRWD
(MSG
, 50, 101, 1, 0, 0, 0, 2, TN
, H
)
1477 IF (NHNIL
.LT
. MXHNIL
) GO TO 290
1478 MSG
= 'DVODE-- Above warning has been issued I1 times. '
1479 CALL XERRWD
(MSG
, 50, 102, 1, 0, 0, 0, 0, ZERO
, ZERO
)
1480 MSG
= ' it will not be issued again for this problem'
1481 CALL XERRWD
(MSG
, 50, 102, 1, 1, MXHNIL
, 0, 0, ZERO
, ZERO
)
1483 C-----------------------------------------------------------------------
1484 C CALL DVSTEP (Y, YH, NYH, YH, EWT, SAVF, VSAV, ACOR,
1485 C WM, IWM, F, JAC, F, DVNLSD, RPAR, IPAR)
1486 C-----------------------------------------------------------------------
1487 CALL DVSTEP
(Y
, RWORK
(LYH
), NYH
, RWORK
(LYH
), RWORK
(LEWT
),
1488 1 RWORK
(LSAVF
), Y
, RWORK
(LACOR
), RWORK
(LWM
), IWORK
(LIWM
),
1489 2 F
, JAC
, F
, DVNLSD
, RPAR
, IPAR
)
1491 C Branch on KFLAG. Note..In this version, KFLAG can not be set to -3.
1492 C KFLAG .eq. 0, -1, -2
1493 GO TO (300, 530, 540), KGO
1494 C-----------------------------------------------------------------------
1496 C The following block handles the case of a successful return from the
1497 C core integrator (KFLAG = 0). Test for stop conditions.
1498 C-----------------------------------------------------------------------
1501 GO TO (310, 400, 330, 340, 350), ITASK
1502 C ITASK = 1. If TOUT has been reached, interpolate. -------------------
1503 310 IF ((TN
- TOUT
)*H
.LT
. ZERO
) GO TO 250
1504 CALL DVINDY
(TOUT
, 0, RWORK
(LYH
), NYH
, Y
, IFLAG
)
1507 C ITASK = 3. Jump to exit if TOUT was reached. ------------------------
1508 330 IF ((TN
- TOUT
)*H
.GE
. ZERO
) GO TO 400
1510 C ITASK = 4. See if TOUT or TCRIT was reached. Adjust H if necessary.
1511 340 IF ((TN
- TOUT
)*H
.LT
. ZERO
) GO TO 345
1512 CALL DVINDY
(TOUT
, 0, RWORK
(LYH
), NYH
, Y
, IFLAG
)
1515 345 HMX
= ABS
(TN
) + ABS
(H
)
1516 IHIT
= ABS
(TN
- TCRIT
) .LE
. HUN*UROUND*HMX
1518 TNEXT
= TN
+ HNEW*
(ONE
+ FOUR*UROUND
)
1519 IF ((TNEXT
- TCRIT
)*H
.LE
. ZERO
) GO TO 250
1520 H
= (TCRIT
- TN
)*(ONE
- FOUR*UROUND
)
1523 C ITASK = 5. See if TCRIT was reached and jump to exit. ---------------
1524 350 HMX
= ABS
(TN
) + ABS
(H
)
1525 IHIT
= ABS
(TN
- TCRIT
) .LE
. HUN*UROUND*HMX
1526 C-----------------------------------------------------------------------
1528 C The following block handles all successful returns from DVODE.
1529 C If ITASK .ne. 1, Y is loaded from YH and T is set accordingly.
1530 C ISTATE is set to 2, and the optional output is loaded into the work
1531 C arrays before returning.
1532 C-----------------------------------------------------------------------
1534 CALL DCOPY
(N
, RWORK
(LYH
), 1, Y
, 1)
1536 IF (ITASK
.NE
. 4 .AND
. ITASK
.NE
. 5) GO TO 420
1552 C-----------------------------------------------------------------------
1554 C The following block handles all unsuccessful returns other than
1555 C those for illegal input. First the error message routine is called.
1556 C if there was an error test or convergence test failure, IMXER is set.
1557 C Then Y is loaded from YH, T is set to TN, and the illegal input
1558 C The optional output is loaded into the work arrays before returning.
1559 C-----------------------------------------------------------------------
1560 C The maximum number of steps was taken before reaching TOUT. ----------
1561 500 MSG
= 'DVODE-- At current T (=R1), MXSTEP (=I1) steps '
1562 CALL XERRWD
(MSG
, 50, 201, 1, 0, 0, 0, 0, ZERO
, ZERO
)
1563 MSG
= ' taken on this CALL before reaching TOUT '
1564 CALL XERRWD
(MSG
, 50, 201, 1, 1, MXSTEP
, 0, 1, TN
, ZERO
)
1567 C EWT(i) .le. 0.0 for some i (not at start of problem). ----------------
1568 510 EWTI
= RWORK
(LEWT
+I
-1)
1569 MSG
= 'DVODE-- At T (=R1), EWT(I1) has become R2 .le. 0.'
1570 CALL XERRWD
(MSG
, 50, 202, 1, 1, I
, 0, 2, TN
, EWTI
)
1573 C Too much accuracy requested for machine precision. -------------------
1574 520 MSG
= 'DVODE-- At T (=R1), too much accuracy requested '
1575 CALL XERRWD
(MSG
, 50, 203, 1, 0, 0, 0, 0, ZERO
, ZERO
)
1576 MSG
= ' for precision of machine.. see TOLSF (=R2) '
1577 CALL XERRWD
(MSG
, 50, 203, 1, 0, 0, 0, 2, TN
, TOLSF
)
1581 C KFLAG = -1. Error test failed repeatedly or with ABS(H) = HMIN. -----
1582 530 MSG
= 'DVODE-- At T(=R1) and step size H(=R2), the error'
1583 CALL XERRWD
(MSG
, 50, 204, 1, 0, 0, 0, 0, ZERO
, ZERO
)
1584 MSG
= ' test failed repeatedly or with abs(H) = HMIN'
1585 CALL XERRWD
(MSG
, 50, 204, 1, 0, 0, 0, 2, TN
, H
)
1588 C KFLAG = -2. Convergence failed repeatedly or with abs(H) = HMIN. ----
1589 540 MSG
= 'DVODE-- At T (=R1) and step size H (=R2), the '
1590 CALL XERRWD
(MSG
, 50, 205, 1, 0, 0, 0, 0, ZERO
, ZERO
)
1591 MSG
= ' corrector convergence failed repeatedly '
1592 CALL XERRWD
(MSG
, 50, 205, 1, 0, 0, 0, 0, ZERO
, ZERO
)
1593 MSG
= ' or with abs(H) = HMIN '
1594 CALL XERRWD
(MSG
, 30, 205, 1, 0, 0, 0, 2, TN
, H
)
1596 C Compute IMXER if relevant. -------------------------------------------
1600 SIZE
= ABS
(RWORK
(I
+LACOR
-1)*RWORK
(I
+LEWT
-1))
1601 IF (BIG
.GE
. SIZE
) GO TO 570
1606 C Set Y vector, T, and optional output. --------------------------------
1608 CALL DCOPY
(N
, RWORK
(LYH
), 1, Y
, 1)
1623 C-----------------------------------------------------------------------
1625 C The following block handles all error returns due to illegal input
1626 C (ISTATE = -3), as detected before calling the core integrator.
1627 C First the error message routine is called. If the illegal input
1628 C is a negative ISTATE, the run is aborted (apparent infinite loop).
1629 C-----------------------------------------------------------------------
1630 601 MSG
= 'DVODE-- ISTATE (=I1) illegal '
1631 CALL XERRWD
(MSG
, 30, 1, 1, 1, ISTATE
, 0, 0, ZERO
, ZERO
)
1632 IF (ISTATE
.LT
. 0) GO TO 800
1634 602 MSG
= 'DVODE-- ITASK (=I1) illegal '
1635 CALL XERRWD
(MSG
, 30, 2, 1, 1, ITASK
, 0, 0, ZERO
, ZERO
)
1637 603 MSG
='DVODE-- ISTATE (=I1) .gt. 1 but DVODE not initialized '
1638 CALL XERRWD
(MSG
, 60, 3, 1, 1, ISTATE
, 0, 0, ZERO
, ZERO
)
1640 604 MSG
= 'DVODE-- NEQ (=I1) .lt. 1 '
1641 CALL XERRWD
(MSG
, 30, 4, 1, 1, NEQ
, 0, 0, ZERO
, ZERO
)
1643 605 MSG
= 'DVODE-- ISTATE = 3 and NEQ increased (I1 to I2) '
1644 CALL XERRWD
(MSG
, 50, 5, 1, 2, N
, NEQ
, 0, ZERO
, ZERO
)
1646 606 MSG
= 'DVODE-- ITOL (=I1) illegal '
1647 CALL XERRWD
(MSG
, 30, 6, 1, 1, ITOL
, 0, 0, ZERO
, ZERO
)
1649 607 MSG
= 'DVODE-- IOPT (=I1) illegal '
1650 CALL XERRWD
(MSG
, 30, 7, 1, 1, IOPT
, 0, 0, ZERO
, ZERO
)
1652 608 MSG
= 'DVODE-- MF (=I1) illegal '
1653 CALL XERRWD
(MSG
, 30, 8, 1, 1, MF
, 0, 0, ZERO
, ZERO
)
1655 609 MSG
= 'DVODE-- ML (=I1) illegal.. .lt.0 or .ge.NEQ (=I2)'
1656 CALL XERRWD
(MSG
, 50, 9, 1, 2, ML
, NEQ
, 0, ZERO
, ZERO
)
1658 610 MSG
= 'DVODE-- MU (=I1) illegal.. .lt.0 or .ge.NEQ (=I2)'
1659 CALL XERRWD
(MSG
, 50, 10, 1, 2, MU
, NEQ
, 0, ZERO
, ZERO
)
1661 611 MSG
= 'DVODE-- MAXORD (=I1) .lt. 0 '
1662 CALL XERRWD
(MSG
, 30, 11, 1, 1, MAXORD
, 0, 0, ZERO
, ZERO
)
1664 612 MSG
= 'DVODE-- MXSTEP (=I1) .lt. 0 '
1665 CALL XERRWD
(MSG
, 30, 12, 1, 1, MXSTEP
, 0, 0, ZERO
, ZERO
)
1667 613 MSG
= 'DVODE-- MXHNIL (=I1) .lt. 0 '
1668 CALL XERRWD
(MSG
, 30, 13, 1, 1, MXHNIL
, 0, 0, ZERO
, ZERO
)
1670 614 MSG
= 'DVODE-- TOUT (=R1) behind T (=R2) '
1671 CALL XERRWD
(MSG
, 40, 14, 1, 0, 0, 0, 2, TOUT
, T
)
1672 MSG
= ' integration direction is given by H0 (=R1) '
1673 CALL XERRWD
(MSG
, 50, 14, 1, 0, 0, 0, 1, H0
, ZERO
)
1675 615 MSG
= 'DVODE-- HMAX (=R1) .lt. 0.0 '
1676 CALL XERRWD
(MSG
, 30, 15, 1, 0, 0, 0, 1, HMAX
, ZERO
)
1678 616 MSG
= 'DVODE-- HMIN (=R1) .lt. 0.0 '
1679 CALL XERRWD
(MSG
, 30, 16, 1, 0, 0, 0, 1, HMIN
, ZERO
)
1682 MSG
='DVODE-- RWORK length needed, LENRW (=I1), exceeds LRW (=I2)'
1683 CALL XERRWD
(MSG
, 60, 17, 1, 2, LENRW
, LRW
, 0, ZERO
, ZERO
)
1686 MSG
='DVODE-- IWORK length needed, LENIW (=I1), exceeds LIW (=I2)'
1687 CALL XERRWD
(MSG
, 60, 18, 1, 2, LENIW
, LIW
, 0, ZERO
, ZERO
)
1689 619 MSG
= 'DVODE-- RelTol(I1) is R1 .lt. 0.0 '
1690 CALL XERRWD
(MSG
, 40, 19, 1, 1, I
, 0, 1, RelTolI
, ZERO
)
1692 620 MSG
= 'DVODE-- AbsTol(I1) is R1 .lt. 0.0 '
1693 CALL XERRWD
(MSG
, 40, 20, 1, 1, I
, 0, 1, AbsTolI
, ZERO
)
1695 621 EWTI
= RWORK
(LEWT
+I
-1)
1696 MSG
= 'DVODE-- EWT(I1) is R1 .le. 0.0 '
1697 CALL XERRWD
(MSG
, 40, 21, 1, 1, I
, 0, 1, EWTI
, ZERO
)
1700 MSG
='DVODE-- TOUT (=R1) too close to T(=R2) to start integration'
1701 CALL XERRWD
(MSG
, 60, 22, 1, 0, 0, 0, 2, TOUT
, T
)
1704 MSG
='DVODE-- ITASK = I1 and TOUT (=R1) behind TCUR - HU (= R2) '
1705 CALL XERRWD
(MSG
, 60, 23, 1, 1, ITASK
, 0, 2, TOUT
, TP
)
1708 MSG
='DVODE-- ITASK = 4 or 5 and TCRIT (=R1) behind TCUR (=R2) '
1709 CALL XERRWD
(MSG
, 60, 24, 1, 0, 0, 0, 2, TCRIT
, TN
)
1712 MSG
='DVODE-- ITASK = 4 or 5 and TCRIT (=R1) behind TOUT (=R2) '
1713 CALL XERRWD
(MSG
, 60, 25, 1, 0, 0, 0, 2, TCRIT
, TOUT
)
1715 626 MSG
= 'DVODE-- At start of problem, too much accuracy '
1716 CALL XERRWD
(MSG
, 50, 26, 1, 0, 0, 0, 0, ZERO
, ZERO
)
1717 MSG
=' requested for precision of machine.. see TOLSF (=R1) '
1718 CALL XERRWD
(MSG
, 60, 26, 1, 0, 0, 0, 1, TOLSF
, ZERO
)
1721 627 MSG
='DVODE-- Trouble from DVINDY. ITASK = I1, TOUT = R1. '
1722 CALL XERRWD
(MSG
, 60, 27, 1, 1, ITASK
, 0, 1, TOUT
, ZERO
)
1728 800 MSG
= 'DVODE-- Run aborted.. apparent infinite loop '
1729 CALL XERRWD
(MSG
, 50, 303, 2, 0, 0, 0, 0, ZERO
, ZERO
)
1731 C----------------------- End of Subroutine DVODE -----------------------
1734 SUBROUTINE DVHIN
(N
, T0
, Y0
, YDOT
, F
, RPAR
, IPAR
, TOUT
, UROUND
,
1735 1 EWT
, ITOL
, AbsTol
, Y
, TEMP
, H0
, NITER
, IER
)
1737 KPP_REAL T0
, Y0
, YDOT
, RPAR
, TOUT
, UROUND
, EWT
, AbsTol
, Y
,
1739 INTEGER N
, IPAR
, ITOL
, NITER
, IER
1740 DIMENSION Y0
(*), YDOT
(*), EWT
(*), AbsTol
(*), Y
(*),
1741 1 TEMP
(*), RPAR
(*), IPAR
(*)
1742 C-----------------------------------------------------------------------
1743 C Call sequence input -- N, T0, Y0, YDOT, F, RPAR, IPAR, TOUT, UROUND,
1744 C EWT, ITOL, AbsTol, Y, TEMP
1745 C Call sequence output -- H0, NITER, IER
1746 C COMMON block variables accessed -- None
1748 C Subroutines called by DVHIN.. F
1749 C Function routines called by DVHIN.. DVNORM
1750 C-----------------------------------------------------------------------
1751 C This routine computes the step size, H0, to be attempted on the
1752 C first step, when the user has not supplied a value for this.
1754 C First we check that TOUT - T0 differs significantly from zero. Then
1755 C an iteration is done to approximate the initial second derivative
1756 C and this is used to define h from w.r.m.s.norm(h**2 * yddot / 2) = 1.
1757 C A bias factor of 1/2 is applied to the resulting h.
1758 C The sign of H0 is inferred from the initial values of TOUT and T0.
1760 C Communication with DVHIN is done with the following variables..
1762 C N = Size of ODE system, input.
1763 C T0 = Initial value of independent variable, input.
1764 C Y0 = Vector of initial conditions, input.
1765 C YDOT = Vector of initial first derivatives, input.
1766 C F = Name of subroutine for right-hand side f(t,y), input.
1767 C RPAR, IPAR = Dummy names for user's real and integer work arrays.
1768 C TOUT = First output value of independent variable
1769 C UROUND = Machine unit roundoff
1770 C EWT, ITOL, AbsTol = Error weights and tolerance parameters
1771 C as described in the driver routine, input.
1772 C Y, TEMP = Work arrays of length N.
1773 C H0 = Step size to be attempted, output.
1774 C NITER = Number of iterations (and of f evaluations) to compute H0,
1776 C IER = The error flag, returned with the value
1777 C IER = 0 if no trouble occurred, or
1778 C IER = -1 if TOUT and T0 are considered too close to proceed.
1779 C-----------------------------------------------------------------------
1781 C Type declarations for local variables --------------------------------
1783 KPP_REAL AFI
, AbsTolI
, DELYI
, HALF
, HG
, HLB
, HNEW
, HRAT
,
1784 1 HUB
, HUN
, PT1
, T1
, TDIST
, TROUND
, TWO
, YDDNRM
1788 C Type declaration for function subroutines called ---------------------
1791 C-----------------------------------------------------------------------
1792 C The following Fortran-77 declaration is to cause the values of the
1793 C listed (local) variables to be saved between calls to this integrator.
1794 C-----------------------------------------------------------------------
1795 SAVE HALF
, HUN
, PT1
, TWO
1796 DATA HALF
/0.5D0
/, HUN
/100.0D0
/, PT1
/0.1D0
/, TWO
/2.0D0
/
1799 TDIST
= ABS
(TOUT
- T0
)
1800 TROUND
= UROUND*MAX
(ABS
(T0
),ABS
(TOUT
))
1801 IF (TDIST
.LT
. TWO*TROUND
) GO TO 100
1803 C Set a lower bound on h based on the roundoff level in T0 and TOUT. ---
1805 C Set an upper bound on h based on TOUT-T0 and the initial Y and YDOT. -
1809 IF (ITOL
.EQ
. 2 .OR
. ITOL
.EQ
. 4) AbsTolI
= AbsTol
(I
)
1810 DELYI
= PT1*ABS
(Y0
(I
)) + AbsTolI
1812 IF (AFI*HUB
.GT
. DELYI
) HUB
= DELYI
/AFI
1815 C Set initial guess for h as geometric mean of upper and lower bounds. -
1818 C If the bounds have crossed, exit with the mean value. ----------------
1819 IF (HUB
.LT
. HLB
) THEN
1824 C Looping point for iteration. -----------------------------------------
1826 C Estimate the second derivative as a difference quotient in f. --------
1829 60 Y
(I
) = Y0
(I
) + HG*YDOT
(I
)
1830 CALL F
(N
, T1
, Y
, TEMP
)
1832 70 TEMP
(I
) = (TEMP
(I
) - YDOT
(I
))/HG
1833 YDDNRM
= DVNORM
(N
, TEMP
, EWT
)
1834 C Get the corresponding new value of h. --------------------------------
1835 IF (YDDNRM*HUB*HUB
.GT
. TWO
) THEN
1836 HNEW
= SQRT
(TWO
/YDDNRM
)
1841 C-----------------------------------------------------------------------
1842 C Test the stopping conditions.
1843 C Stop if the new and previous h values differ by a factor of .lt. 2.
1844 C Stop if four iterations have been done. Also, stop with previous h
1845 C if HNEW/HG .gt. 2 after first iteration, as this probably means that
1846 C the second derivative value is bad because of cancellation error.
1847 C-----------------------------------------------------------------------
1848 IF (ITER
.GE
. 4) GO TO 80
1851 IF ( (HRAT
.GT
. HALF
) .AND
. (HRAT
.LT
. TWO
) ) GO TO 80
1852 IF ( (ITER
.GE
. 2) .AND
. (HNEW
.GT
. TWO*HG
) ) THEN
1859 C Iteration done. Apply bounds, bias factor, and sign. Then exit. ----
1861 IF (H0
.LT
. HLB
) H0
= HLB
1862 IF (H0
.GT
. HUB
) H0
= HUB
1863 90 H0
= SIGN
(H0
, TOUT
- T0
)
1867 C Error return for TOUT - T0 too small. --------------------------------
1870 C----------------------- End of Subroutine DVHIN -----------------------
1873 SUBROUTINE DVINDY
(T
, K
, YH
, LDYH
, DKY
, IFLAG
)
1875 INTEGER K
, LDYH
, IFLAG
1876 DIMENSION YH
(LDYH
,*), DKY
(*)
1877 C-----------------------------------------------------------------------
1878 C Call sequence input -- T, K, YH, LDYH
1879 C Call sequence output -- DKY, IFLAG
1880 C COMMON block variables accessed..
1881 C /DVOD01/ -- H, TN, UROUND, L, N, NQ
1884 C Subroutines called by DVINDY.. DSCAL, XERRWD
1885 C Function routines called by DVINDY.. None
1886 C-----------------------------------------------------------------------
1887 C DVINDY computes interpolated values of the K-th derivative of the
1888 C dependent variable vector y, and stores it in DKY. This routine
1889 C is called within the package with K = 0 and T = TOUT, but may
1890 C also be called by the user for any K up to the current order.
1891 C (See detailed instructions in the usage documentation.)
1892 C-----------------------------------------------------------------------
1893 C The computed values in DKY are gotten by interpolation using the
1894 C Nordsieck history array YH. This array corresponds uniquely to a
1895 C vector-valued polynomial of degree NQCUR or less, and DKY is set
1896 C to the K-th derivative of this polynomial at T.
1897 C The formula for DKY is..
1899 C DKY(i) = sum c(j,K) * (T - TN)**(j-K) * H**(-j) * YH(i,j+1)
1901 C where c(j,K) = j*(j-1)*...*(j-K+1), q = NQCUR, TN = TCUR, H = HCUR.
1902 C The quantities NQ = NQCUR, L = NQ+1, N, TN, and H are
1903 C communicated by COMMON. The above sum is done in reverse order.
1904 C IFLAG is returned negative if either K or T is out of bounds.
1906 C Discussion above and comments in driver explain all variables.
1907 C-----------------------------------------------------------------------
1909 C Type declarations for labeled COMMON block DVOD01 --------------------
1911 KPP_REAL ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
,
1912 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
1913 2 RC
, RL1
, TAU
, TQ
, TN
, UROUND
1914 INTEGER ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
1915 1 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
1916 2 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
1917 3 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
1920 C Type declarations for labeled COMMON block DVOD02 --------------------
1923 INTEGER NCFN
, NETF
, NFE
, NJE
, NLU
, NNI
, NQU
, NST
1925 C Type declarations for local variables --------------------------------
1927 KPP_REAL C
, HUN
, R
, S
, TFUZZ
, TN1
, TP
, ZERO
1928 INTEGER I
, IC
, J
, JB
, JB2
, JJ
, JJ1
, JP1
1930 C-----------------------------------------------------------------------
1931 C The following Fortran-77 declaration is to cause the values of the
1932 C listed (local) variables to be saved between calls to this integrator.
1933 C-----------------------------------------------------------------------
1936 COMMON /DVOD01
/ ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
(13),
1937 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
1938 2 RC
, RL1
, TAU
(13), TQ
(5), TN
, UROUND
,
1939 3 ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
1940 4 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
1941 5 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
1942 6 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
1944 COMMON /DVOD02
/ HU
, NCFN
, NETF
, NFE
, NJE
, NLU
, NNI
, NQU
, NST
1946 DATA HUN
/100.0D0
/, ZERO
/0.0D0
/
1949 IF (K
.LT
. 0 .OR
. K
.GT
. NQ
) GO TO 80
1950 TFUZZ
= HUN*UROUND*
(TN
+ HU
)
1951 TP
= TN
- HU
- TFUZZ
1953 IF ((T
-TP
)*(T
-TN1
) .GT
. ZERO
) GO TO 90
1957 IF (K
.EQ
. 0) GO TO 15
1963 20 DKY
(I
) = C*YH
(I
,L
)
1964 IF (K
.EQ
. NQ
) GO TO 55
1970 IF (K
.EQ
. 0) GO TO 35
1976 40 DKY
(I
) = C*YH
(I
,JP1
) + S*DKY
(I
)
1978 IF (K
.EQ
. 0) RETURN
1980 CALL DSCAL
(N
, R
, DKY
, 1)
1983 80 MSG
= 'DVINDY-- K (=I1) illegal '
1984 CALL XERRWD
(MSG
, 30, 51, 1, 1, K
, 0, 0, ZERO
, ZERO
)
1987 90 MSG
= 'DVINDY-- T (=R1) illegal '
1988 CALL XERRWD
(MSG
, 30, 52, 1, 0, 0, 0, 1, T
, ZERO
)
1989 MSG
=' T not in interval TCUR - HU (= R1) to TCUR (=R2) '
1990 CALL XERRWD
(MSG
, 60, 52, 1, 0, 0, 0, 2, TP
, TN
)
1993 C----------------------- End of Subroutine DVINDY ----------------------
1996 SUBROUTINE DVSTEP
(Y
, YH
, LDYH
, YH1
, EWT
, SAVF
, VSAV
, ACOR
,
1997 1 WM
, IWM
, F
, JAC
, PSOL
, VNLS
, RPAR
, IPAR
)
1998 EXTERNAL F
, JAC
, PSOL
, VNLS
1999 KPP_REAL Y
, YH
, YH1
, EWT
, SAVF
, VSAV
, ACOR
, WM
, RPAR
2000 INTEGER LDYH
, IWM
, IPAR
2001 DIMENSION Y
(*), YH
(LDYH
,*), YH1
(*), EWT
(*), SAVF
(*), VSAV
(*),
2002 1 ACOR
(*), WM
(*), IWM
(*), RPAR
(*), IPAR
(*)
2004 C-----------------------------------------------------------------------
2005 C Call sequence input -- Y, YH, LDYH, YH1, EWT, SAVF, VSAV,
2006 C ACOR, WM, IWM, F, JAC, PSOL, VNLS, RPAR, IPAR
2007 C Call sequence output -- YH, ACOR, WM, IWM
2008 C COMMON block variables accessed..
2009 C /DVOD01/ ACNRM, EL(13), H, HMIN, HMXI, HNEW, HSCAL, RC, TAU(13),
2010 C TQ(5), TN, JCUR, JSTART, KFLAG, KUTH,
2011 C L, LMAX, MAXORD, MITER, N, NEWQ, NQ, NQWAIT
2012 C /DVOD02/ HU, NCFN, NETF, NFE, NQU, NST
2014 C Subroutines called by DVSTEP.. F, DAXPY, DCOPY, DSCAL,
2015 C DVJUST, VNLS, DVSET
2016 C Function routines called by DVSTEP.. DVNORM
2017 C-----------------------------------------------------------------------
2018 C DVSTEP performs one step of the integration of an initial value
2019 C problem for a system of ordinary differential equations.
2020 C DVSTEP calls subroutine VNLS for the solution of the nonlinear system
2021 C arising in the time step. Thus it is independent of the problem
2022 C Jacobian structure and the type of nonlinear system solution method.
2023 C DVSTEP returns a completion flag KFLAG (in COMMON).
2024 C A return with KFLAG = -1 or -2 means either ABS(H) = HMIN or 10
2025 C consecutive failures occurred. On a return with KFLAG negative,
2026 C the values of TN and the YH array are as of the beginning of the last
2027 C step, and H is the last step size attempted.
2029 C Communication with DVSTEP is done with the following variables..
2031 C Y = An array of length N used for the dependent variable vector.
2032 C YH = An LDYH by LMAX array containing the dependent variables
2033 C and their approximate scaled derivatives, where
2034 C LMAX = MAXORD + 1. YH(i,j+1) contains the approximate
2035 C j-th derivative of y(i), scaled by H**j/factorial(j)
2036 C (j = 0,1,...,NQ). On entry for the first step, the first
2037 C two columns of YH must be set from the initial values.
2038 C LDYH = A constant integer .ge. N, the first dimension of YH.
2039 C N is the number of ODEs in the system.
2040 C YH1 = A one-dimensional array occupying the same space as YH.
2041 C EWT = An array of length N containing multiplicative weights
2042 C for local error measurements. Local errors in y(i) are
2043 C compared to 1.0/EWT(i) in various error tests.
2044 C SAVF = An array of working storage, of length N.
2045 C also used for input of YH(*,MAXORD+2) when JSTART = -1
2046 C and MAXORD .lt. the current order NQ.
2047 C VSAV = A work array of length N passed to subroutine VNLS.
2048 C ACOR = A work array of length N, used for the accumulated
2049 C corrections. On a successful return, ACOR(i) contains
2050 C the estimated one-step local error in y(i).
2051 C WM,IWM = Real and integer work arrays associated with matrix
2052 C operations in VNLS.
2053 C F = Dummy name for the user supplied subroutine for f.
2054 C JAC = Dummy name for the user supplied Jacobian subroutine.
2055 C PSOL = Dummy name for the subroutine passed to VNLS, for
2056 C possible use there.
2057 C VNLS = Dummy name for the nonlinear system solving subroutine,
2058 C whose real name is dependent on the method used.
2059 C RPAR, IPAR = Dummy names for user's real and integer work arrays.
2060 C-----------------------------------------------------------------------
2062 C Type declarations for labeled COMMON block DVOD01 --------------------
2064 KPP_REAL ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
,
2065 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
2066 2 RC
, RL1
, TAU
, TQ
, TN
, UROUND
2067 INTEGER ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
2068 1 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
2069 2 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
2070 3 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
2073 C Type declarations for labeled COMMON block DVOD02 --------------------
2076 INTEGER NCFN
, NETF
, NFE
, NJE
, NLU
, NNI
, NQU
, NST
2078 C Type declarations for local variables --------------------------------
2080 KPP_REAL ADDON
, BIAS1
,BIAS2
,BIAS3
, CNQUOT
, DDN
, DSM
, DUP
,
2081 1 ETACF
, ETAMIN
, ETAMX1
, ETAMX2
, ETAMX3
, ETAMXF
,
2082 2 ETAQ
, ETAQM1
, ETAQP1
, FLOTL
, ONE
, ONEPSM
,
2083 3 R
, THRESH
, TOLD
, ZERO
2084 INTEGER I
, I1
, I2
, IBACK
, J
, JB
, KFC
, KFH
, MXNCF
, NCF
, NFLAG
2086 C Type declaration for function subroutines called ---------------------
2089 C-----------------------------------------------------------------------
2090 C The following Fortran-77 declaration is to cause the values of the
2091 C listed (local) variables to be saved between calls to this integrator.
2092 C-----------------------------------------------------------------------
2093 SAVE ADDON
, BIAS1
, BIAS2
, BIAS3
,
2094 1 ETACF
, ETAMIN
, ETAMX1
, ETAMX2
, ETAMX3
, ETAMXF
,
2095 2 KFC
, KFH
, MXNCF
, ONEPSM
, THRESH
, ONE
, ZERO
2096 C-----------------------------------------------------------------------
2097 COMMON /DVOD01
/ ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
(13),
2098 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
2099 2 RC
, RL1
, TAU
(13), TQ
(5), TN
, UROUND
,
2100 3 ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
2101 4 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
2102 5 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
2103 6 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
2105 COMMON /DVOD02
/ HU
, NCFN
, NETF
, NFE
, NJE
, NLU
, NNI
, NQU
, NST
2107 DATA KFC
/-3/, KFH
/-7/, MXNCF
/10/
2108 DATA ADDON
/1.0D
-6/, BIAS1
/6.0D0
/, BIAS2
/6.0D0
/,
2109 1 BIAS3
/10.0D0
/, ETACF
/0.25D0
/, ETAMIN
/0.1D0
/,
2110 2 ETAMXF
/0.2D0
/, ETAMX1
/1.0D4
/, ETAMX2
/10.0D1
/,
2111 3 ETAMX3
/10.0D1
/, ONEPSM
/1.00001D0
/, THRESH
/1.5D0
/
2113 DATA ONE
/1.0D0
/, ZERO
/0.0D0
/
2123 IF (JSTART
.GT
. 0) GO TO 20
2124 IF (JSTART
.EQ
. -1) GO TO 100
2125 C-----------------------------------------------------------------------
2126 C On the first call, the order is set to 1, and other variables are
2127 C initialized. ETAMAX is the maximum ratio by which H can be increased
2128 C in a single step. It is normally 1.5, but is larger during the
2129 C first 10 steps to compensate for the small initial H. If a failure
2130 C occurs (in corrector convergence or error test), ETAMAX is set to 1
2131 C for the next increase.
2132 C-----------------------------------------------------------------------
2144 C-----------------------------------------------------------------------
2145 C Take preliminary actions on a normal continuation step (JSTART.GT.0).
2146 C If the driver changed H, then ETA must be reset and NEWH set to 1.
2147 C If a change of order was dictated on the previous step, then
2148 C it is done here and appropriate adjustments in the history are made.
2149 C On an order decrease, the history array is adjusted by DVJUST.
2150 C On an order increase, the history array is augmented by a column.
2151 C On a change of step size H, the history array YH is rescaled.
2152 C-----------------------------------------------------------------------
2154 IF (KUTH
.EQ
. 1) THEN
2155 ETA
= MIN
(ETA
,H
/HSCAL
)
2158 50 IF (NEWH
.EQ
. 0) GO TO 200
2159 IF (NEWQ
.EQ
. NQ
) GO TO 150
2160 IF (NEWQ
.LT
. NQ
) THEN
2161 CALL DVJUST
(YH
, LDYH
, -1)
2167 IF (NEWQ
.GT
. NQ
) THEN
2168 CALL DVJUST
(YH
, LDYH
, 1)
2174 C-----------------------------------------------------------------------
2175 C The following block handles preliminaries needed when JSTART = -1.
2176 C If N was reduced, zero out part of YH to avoid undefined references.
2177 C If MAXORD was reduced to a value less than the tentative order NEWQ,
2178 C then NQ is set to MAXORD, and a new H ratio ETA is chosen.
2179 C Otherwise, we take the same preliminary actions as for JSTART .gt. 0.
2180 C In any case, NQWAIT is reset to L = NQ + 1 to prevent further
2181 C changes in order for that many steps.
2182 C The new H ratio ETA is limited by the input H if KUTH = 1,
2183 C by HMIN if KUTH = 0, and by HMXI in any case.
2184 C Finally, the history array YH is rescaled.
2185 C-----------------------------------------------------------------------
2188 IF (N
.EQ
. LDYH
) GO TO 120
2189 I1
= 1 + (NEWQ
+ 1)*LDYH
2190 I2
= (MAXORD
+ 1)*LDYH
2191 IF (I1
.GT
. I2
) GO TO 120
2194 120 IF (NEWQ
.LE
. MAXORD
) GO TO 140
2196 IF (MAXORD
.LT
. NQ
-1) THEN
2197 DDN
= DVNORM
(N
, SAVF
, EWT
)/TQ
(1)
2198 ETA
= ONE
/((BIAS1*DDN
)**(ONE
/FLOTL
) + ADDON
)
2200 IF (MAXORD
.EQ
. NQ
.AND
. NEWQ
.EQ
. NQ
+1) ETA
= ETAQ
2201 IF (MAXORD
.EQ
. NQ
-1 .AND
. NEWQ
.EQ
. NQ
+1) THEN
2203 CALL DVJUST
(YH
, LDYH
, -1)
2205 IF (MAXORD
.EQ
. NQ
-1 .AND
. NEWQ
.EQ
. NQ
) THEN
2206 DDN
= DVNORM
(N
, SAVF
, EWT
)/TQ
(1)
2207 ETA
= ONE
/((BIAS1*DDN
)**(ONE
/FLOTL
) + ADDON
)
2208 CALL DVJUST
(YH
, LDYH
, -1)
2213 140 IF (KUTH
.EQ
. 1) ETA
= MIN
(ETA
,ABS
(H
/HSCAL
))
2214 IF (KUTH
.EQ
. 0) ETA
= MAX
(ETA
,HMIN
/ABS
(HSCAL
))
2215 ETA
= ETA
/MAX
(ONE
,ABS
(HSCAL
)*HMXI*ETA
)
2218 IF (NEWQ
.LE
. MAXORD
) GO TO 50
2219 C Rescale the history array for a change in H by a factor of ETA. ------
2223 CALL DSCAL
(N
, R
, YH
(1,J
), 1 )
2229 C-----------------------------------------------------------------------
2230 C This section computes the predicted values by effectively
2231 C multiplying the YH array by the Pascal triangle matrix.
2232 C DVSET is called to calculate all integration coefficients.
2233 C RC is the ratio of new to old values of the coefficient H/EL(2)=h/l1.
2234 C-----------------------------------------------------------------------
2239 DO 210 I
= I1
, NQNYH
2240 210 YH1
(I
) = YH1
(I
) + YH1
(I
+LDYH
)
2247 C Call the nonlinear system solver. ------------------------------------
2249 CALL VNLS
(Y
, YH
, LDYH
, VSAV
, SAVF
, EWT
, ACOR
, IWM
, WM
,
2250 1 F
, JAC
, PSOL
, NFLAG
, RPAR
, IPAR
)
2252 IF ((NFLAG
.EQ
. 0).OR
.(H
.LE
.1.2*HMIN
)) GO TO 450
2253 C-----------------------------------------------------------------------
2254 C The VNLS routine failed to achieve convergence (NFLAG .NE. 0).
2255 C The YH array is retracted to its values before prediction.
2256 C The step size H is reduced and the step is retried, if possible.
2257 C Otherwise, an error exit is taken.
2258 C-----------------------------------------------------------------------
2266 DO 420 I
= I1
, NQNYH
2267 420 YH1
(I
) = YH1
(I
) - YH1
(I
+LDYH
)
2269 IF (NFLAG
.LT
. -1) GO TO 680
2270 IF (ABS
(H
) .LE
. HMIN*ONEPSM
) GO TO 670
2271 IF (NCF
.EQ
. MXNCF
) GO TO 670
2273 ETA
= MAX
(ETA
,HMIN
/ABS
(H
))
2276 C-----------------------------------------------------------------------
2277 C The corrector has converged (NFLAG = 0). The local error test is
2278 C made and control passes to statement 500 if it fails.
2279 C-----------------------------------------------------------------------
2282 IF ( (DSM
.GT
. ONE
).and
.(H
.GT
.HMIN
) ) GO TO 500
2283 C-----------------------------------------------------------------------
2284 C After a successful step, update the YH and TAU arrays and decrement
2285 C NQWAIT. If NQWAIT is then 1 and NQ .lt. MAXORD, then ACOR is saved
2286 C for use in a possible order increase on the next step.
2287 C If ETAMAX = 1 (a failure occurred this step), keep NQWAIT .ge. 2.
2288 C-----------------------------------------------------------------------
2293 DO 470 IBACK
= 1, NQ
2295 470 TAU
(I
+1) = TAU
(I
)
2298 CALL DAXPY
(N
, EL
(J
), ACOR
, 1, YH
(1,J
), 1 )
2301 IF ((L
.EQ
. LMAX
) .OR
. (NQWAIT
.NE
. 1)) GO TO 490
2302 CALL DCOPY
(N
, ACOR
, 1, YH
(1,LMAX
), 1 )
2304 490 IF (ETAMAX
.NE
. ONE
) GO TO 560
2305 IF (NQWAIT
.LT
. 2) NQWAIT
= 2
2311 C-----------------------------------------------------------------------
2312 C The error test failed. KFLAG keeps track of multiple failures.
2313 C Restore TN and the YH array to their previous values, and prepare
2314 C to try the step again. Compute the optimum step size for the
2315 C same order. After repeated failures, H is forced to decrease
2317 C-----------------------------------------------------------------------
2318 500 KFLAG
= KFLAG
- 1
2325 DO 510 I
= I1
, NQNYH
2326 510 YH1
(I
) = YH1
(I
) - YH1
(I
+LDYH
)
2328 IF (ABS
(H
) .LE
. HMIN*ONEPSM
) GO TO 660
2330 IF (KFLAG
.LE
. KFC
) GO TO 530
2331 C Compute ratio of new H to current H at the current order. ------------
2333 ETA
= ONE
/((BIAS2*DSM
)**(ONE
/FLOTL
) + ADDON
)
2334 ETA
= MAX
(ETA
,HMIN
/ABS
(H
),ETAMIN
)
2335 IF ((KFLAG
.LE
. -2) .AND
. (ETA
.GT
. ETAMXF
)) ETA
= ETAMXF
2337 C-----------------------------------------------------------------------
2338 C Control reaches this section if 3 or more consecutive failures
2339 C have occurred. It is assumed that the elements of the YH array
2340 C have accumulated errors of the wrong order. The order is reduced
2341 C by one, if possible. Then H is reduced by a factor of 0.1 and
2342 C the step is retried. After a total of 7 consecutive failures,
2343 C an exit is taken with KFLAG = -1.
2344 C-----------------------------------------------------------------------
2345 530 IF (KFLAG
.EQ
. KFH
) GO TO 660
2346 IF (NQ
.EQ
. 1) GO TO 540
2347 ETA
= MAX
(ETAMIN
,HMIN
/ABS
(H
))
2348 CALL DVJUST
(YH
, LDYH
, -1)
2353 540 ETA
= MAX
(ETAMIN
,HMIN
/ABS
(H
))
2357 CALL F
(N
, TN
, Y
, SAVF
)
2360 550 YH
(I
,2) = H*SAVF
(I
)
2363 C-----------------------------------------------------------------------
2364 C If NQWAIT = 0, an increase or decrease in order by one is considered.
2365 C Factors ETAQ, ETAQM1, ETAQP1 are computed by which H could
2366 C be multiplied at order q, q-1, or q+1, respectively.
2367 C The largest of these is determined, and the new order and
2368 C step size set accordingly.
2369 C A change of H or NQ is made only if H increases by at least a
2370 C factor of THRESH. If an order change is considered and rejected,
2371 C then NQWAIT is set to 2 (reconsider it after 2 steps).
2372 C-----------------------------------------------------------------------
2373 C Compute ratio of new H to current H at the current order. ------------
2375 ETAQ
= ONE
/((BIAS2*DSM
)**(ONE
/FLOTL
) + ADDON
)
2376 IF (NQWAIT
.NE
. 0) GO TO 600
2379 IF (NQ
.EQ
. 1) GO TO 570
2380 C Compute ratio of new H to current H at the current order less one. ---
2381 DDN
= DVNORM
(N
, YH
(1,L
), EWT
)/TQ
(1)
2382 ETAQM1
= ONE
/((BIAS1*DDN
)**(ONE
/(FLOTL
- ONE
)) + ADDON
)
2384 IF (L
.EQ
. LMAX
) GO TO 580
2385 C Compute ratio of new H to current H at current order plus one. -------
2386 CNQUOT
= (TQ
(5)/CONP
)*(H
/TAU
(2))**L
2388 575 SAVF
(I
) = ACOR
(I
) - CNQUOT*YH
(I
,LMAX
)
2389 DUP
= DVNORM
(N
, SAVF
, EWT
)/TQ
(3)
2390 ETAQP1
= ONE
/((BIAS3*DUP
)**(ONE
/(FLOTL
+ ONE
)) + ADDON
)
2391 580 IF (ETAQ
.GE
. ETAQP1
) GO TO 590
2392 IF (ETAQP1
.GT
. ETAQM1
) GO TO 620
2394 590 IF (ETAQ
.LT
. ETAQM1
) GO TO 610
2403 CALL DCOPY
(N
, ACOR
, 1, YH
(1,LMAX
), 1)
2404 C Test tentative new H against THRESH, ETAMAX, and HMXI, then exit. ----
2405 630 IF (ETA
.LT
. THRESH
.OR
. ETAMAX
.EQ
. ONE
) GO TO 640
2406 ETA
= MIN
(ETA
,ETAMAX
)
2407 ETA
= ETA
/MAX
(ONE
,ABS
(H
)*HMXI*ETA
)
2416 C-----------------------------------------------------------------------
2417 C All returns are made through this section.
2418 C On a successful return, ETAMAX is reset and ACOR is scaled.
2419 C-----------------------------------------------------------------------
2424 680 IF (NFLAG
.EQ
. -2) KFLAG
= -3
2425 IF (NFLAG
.EQ
. -3) KFLAG
= -4
2428 IF (NST
.LE
. 10) ETAMAX
= ETAMX2
2430 CALL DSCAL
(N
, R
, ACOR
, 1)
2433 C----------------------- End of Subroutine DVSTEP ----------------------
2437 C-----------------------------------------------------------------------
2438 C Call sequence communication.. None
2439 C COMMON block variables accessed..
2440 C /DVOD01/ -- EL(13), H, TAU(13), TQ(5), L(= NQ + 1),
2443 C Subroutines called by DVSET.. None
2444 C Function routines called by DVSET.. None
2445 C-----------------------------------------------------------------------
2446 C DVSET is called by DVSTEP and sets coefficients for use there.
2448 C For each order NQ, the coefficients in EL are calculated by use of
2449 C the generating polynomial lambda(x), with coefficients EL(i).
2450 C lambda(x) = EL(1) + EL(2)*x + ... + EL(NQ+1)*(x**NQ).
2451 C For the backward differentiation formulas,
2453 C lambda(x) = (1 + x/xi*(NQ)) * product (1 + x/xi(i) ) .
2455 C For the Adams formulas,
2457 C (d/dx) lambda(x) = c * product (1 + x/xi(i) ) ,
2459 C lambda(-1) = 0, lambda(0) = 1,
2460 C where c is a normalization constant.
2461 C In both cases, xi(i) is defined by
2462 C H*xi(i) = t sub n - t sub (n-i)
2463 C = H + TAU(1) + TAU(2) + ... TAU(i-1).
2466 C In addition to variables described previously, communication
2467 C with DVSET uses the following..
2468 C TAU = A vector of length 13 containing the past NQ values
2470 C EL = A vector of length 13 in which vset stores the
2471 C coefficients for the corrector formula.
2472 C TQ = A vector of length 5 in which vset stores constants
2473 C used for the convergence test, the error test, and the
2474 C selection of H at a new order.
2475 C METH = The basic method indicator.
2476 C NQ = The current order.
2477 C L = NQ + 1, the length of the vector stored in EL, and
2478 C the number of columns of the YH array being used.
2479 C NQWAIT = A counter controlling the frequency of order changes.
2480 C An order change is about to be considered if NQWAIT = 1.
2481 C-----------------------------------------------------------------------
2483 C Type declarations for labeled COMMON block DVOD01 --------------------
2485 KPP_REAL ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
,
2486 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
2487 2 RC
, RL1
, TAU
, TQ
, TN
, UROUND
2488 INTEGER ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
2489 1 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
2490 2 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
2491 3 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
2494 C Type declarations for local variables --------------------------------
2496 KPP_REAL AHATN0
, ALPH0
, CNQM1
, CORTES
, CSUM
, ELP
, EM
,
2497 1 EM0
, FLOTI
, FLOTL
, FLOTNQ
, HSUM
, ONE
, RXI
, RXIS
, S
, SIX
,
2498 2 T1
, T2
, T3
, T4
, T5
, T6
, TWO
, XI
, ZERO
2499 INTEGER I
, IBACK
, J
, JP1
, NQM1
, NQM2
2502 C-----------------------------------------------------------------------
2503 C The following Fortran-77 declaration is to cause the values of the
2504 C listed (local) variables to be saved between calls to this integrator.
2505 C-----------------------------------------------------------------------
2506 SAVE CORTES
, ONE
, SIX
, TWO
, ZERO
2508 COMMON /DVOD01
/ ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
(13),
2509 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
2510 2 RC
, RL1
, TAU
(13), TQ
(5), TN
, UROUND
,
2511 3 ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
2512 4 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
2513 5 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
2514 6 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
2518 DATA ONE
/1.0D0
/, SIX
/6.0D0
/, TWO
/2.0D0
/, ZERO
/0.0D0
/
2523 GO TO (100, 200), METH
2525 C Set coefficients for Adams methods. ----------------------------------
2526 100 IF (NQ
.NE
. 1) GO TO 110
2536 FLOTNQ
= FLOTL
- ONE
2540 IF ((J
.NE
. NQM1
) .OR
. (NQWAIT
.NE
. 1)) GO TO 130
2544 CSUM
= CSUM
+ S*EM
(I
)/REAL(I
+1)
2546 TQ
(1) = EM
(NQM1
)/(FLOTNQ*CSUM
)
2550 140 EM
(I
) = EM
(I
) + EM
(I
-1)*RXI
2551 HSUM
= HSUM
+ TAU
(J
)
2553 C Compute integral from -1 to 0 of polynomial and of x times it. -------
2559 EM0
= EM0
+ S*EM
(I
)/FLOTI
2560 CSUM
= CSUM
+ S*EM
(I
)/(FLOTI
+ONE
)
2562 C In EL, form coefficients of normalized integrated polynomial. --------
2566 170 EL
(I
+1) = S*EM
(I
)/REAL(I
)
2570 IF (NQWAIT
.NE
. 1) GO TO 300
2571 C For higher order control constant, multiply polynomial by 1+x/xi(q). -
2573 DO 180 IBACK
= 1, NQ
2575 180 EM
(I
) = EM
(I
) + EM
(I
-1)*RXI
2576 C Compute integral of polynomial. --------------------------------------
2580 CSUM
= CSUM
+ S*EM
(I
)/REAL(I
+1)
2582 TQ
(3) = FLOTL*EM0
/CSUM
2585 C Set coefficients for BDF methods. ------------------------------------
2595 IF (NQ
.EQ
. 1) GO TO 240
2597 C In EL, construct coefficients of (1+x/xi(1))*...*(1+x/xi(j+1)). ------
2598 HSUM
= HSUM
+ TAU
(J
)
2601 ALPH0
= ALPH0
- ONE
/REAL(JP1
)
2602 DO 220 IBACK
= 1, JP1
2604 220 EL
(I
) = EL
(I
) + EL
(I
-1)*RXI
2606 ALPH0
= ALPH0
- ONE
/REAL(NQ
)
2607 RXIS
= -EL
(2) - ALPH0
2608 HSUM
= HSUM
+ TAU
(NQM1
)
2610 AHATN0
= -EL
(2) - RXI
2611 DO 235 IBACK
= 1, NQ
2612 I
= (NQ
+ 2) - IBACK
2613 235 EL
(I
) = EL
(I
) + EL
(I
-1)*RXIS
2614 240 T1
= ONE
- AHATN0
+ ALPH0
2615 T2
= ONE
+ REAL(NQ
)*T1
2616 TQ
(2) = ABS
(ALPH0*T2
/T1
)
2617 TQ
(5) = ABS
(T2
/(EL
(L
)*RXI
/RXIS
))
2618 IF (NQWAIT
.NE
. 1) GO TO 300
2620 T3
= ALPH0
+ ONE
/REAL(NQ
)
2622 ELP
= T3
/(ONE
- T4
+ T3
)
2623 TQ
(1) = ABS
(ELP
/CNQM1
)
2624 HSUM
= HSUM
+ TAU
(NQ
)
2626 T5
= ALPH0
- ONE
/REAL(NQ
+1)
2628 ELP
= T2
/(ONE
- T6
+ T5
)
2629 TQ
(3) = ABS
(ELP*RXI*
(FLOTL
+ ONE
)*T5
)
2630 300 TQ
(4) = CORTES*TQ
(2)
2632 C----------------------- End of Subroutine DVSET -----------------------
2635 SUBROUTINE DVJUST
(YH
, LDYH
, IORD
)
2638 DIMENSION YH
(LDYH
,*)
2639 C-----------------------------------------------------------------------
2640 C Call sequence input -- YH, LDYH, IORD
2641 C Call sequence output -- YH
2642 C COMMON block input -- NQ, METH, LMAX, HSCAL, TAU(13), N
2643 C COMMON block variables accessed..
2644 C /DVOD01/ -- HSCAL, TAU(13), LMAX, METH, N, NQ,
2646 C Subroutines called by DVJUST.. DAXPY
2647 C Function routines called by DVJUST.. None
2648 C-----------------------------------------------------------------------
2649 C This subroutine adjusts the YH array on reduction of order,
2650 C and also when the order is increased for the stiff option (METH = 2).
2651 C Communication with DVJUST uses the following..
2652 C IORD = An integer flag used when METH = 2 to indicate an order
2653 C increase (IORD = +1) or an order decrease (IORD = -1).
2654 C HSCAL = Step size H used in scaling of Nordsieck array YH.
2655 C (If IORD = +1, DVJUST assumes that HSCAL = TAU(1).)
2656 C See References 1 and 2 for details.
2657 C-----------------------------------------------------------------------
2659 C Type declarations for labeled COMMON block DVOD01 --------------------
2661 KPP_REAL ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
,
2662 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
2663 2 RC
, RL1
, TAU
, TQ
, TN
, UROUND
2664 INTEGER ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
2665 1 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
2666 2 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
2667 3 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
2670 C Type declarations for local variables --------------------------------
2672 KPP_REAL ALPH0
, ALPH1
, HSUM
, ONE
, PROD
, T1
, XI
,XIOLD
, ZERO
2673 INTEGER I
, IBACK
, J
, JP1
, LP1
, NQM1
, NQM2
, NQP1
2674 C-----------------------------------------------------------------------
2675 C The following Fortran-77 declaration is to cause the values of the
2676 C listed (local) variables to be saved between calls to this integrator.
2677 C-----------------------------------------------------------------------
2680 COMMON /DVOD01
/ ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
(13),
2681 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
2682 2 RC
, RL1
, TAU
(13), TQ
(5), TN
, UROUND
,
2683 3 ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
2684 4 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
2685 5 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
2686 6 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
2689 DATA ONE
/1.0D0
/, ZERO
/0.0D0
/
2691 IF ((NQ
.EQ
. 2) .AND
. (IORD
.NE
. 1)) RETURN
2694 GO TO (100, 200), METH
2695 C-----------------------------------------------------------------------
2696 C Nonstiff option...
2697 C Check to see if the order is being increased or decreased.
2698 C-----------------------------------------------------------------------
2700 IF (IORD
.EQ
. 1) GO TO 180
2701 C Order decrease. ------------------------------------------------------
2707 C Construct coefficients of x*(x+xi(1))*...*(x+xi(j)). -----------------
2708 HSUM
= HSUM
+ TAU
(J
)
2711 DO 120 IBACK
= 1, JP1
2713 120 EL
(I
) = EL
(I
)*XI
+ EL
(I
-1)
2715 C Construct coefficients of integrated polynomial. ---------------------
2717 140 EL
(J
+1) = REAL(NQ
)*EL
(J
)/REAL(J
)
2718 C Subtract correction terms from YH array. -----------------------------
2721 160 YH
(I
,J
) = YH
(I
,J
) - YH
(I
,L
)*EL
(J
)
2724 C Order increase. ------------------------------------------------------
2725 C Zero out next column in YH array. ------------------------------------
2729 190 YH
(I
,LP1
) = ZERO
2731 C-----------------------------------------------------------------------
2733 C Check to see if the order is being increased or decreased.
2734 C-----------------------------------------------------------------------
2736 IF (IORD
.EQ
. 1) GO TO 300
2737 C Order decrease. ------------------------------------------------------
2743 C Construct coefficients of x*x*(x+xi(1))*...*(x+xi(j)). ---------------
2744 HSUM
= HSUM
+ TAU
(J
)
2747 DO 220 IBACK
= 1, JP1
2749 220 EL
(I
) = EL
(I
)*XI
+ EL
(I
-1)
2751 C Subtract correction terms from YH array. -----------------------------
2754 240 YH
(I
,J
) = YH
(I
,J
) - YH
(I
,L
)*EL
(J
)
2757 C Order increase. ------------------------------------------------------
2758 300 DO 310 J
= 1, LMAX
2766 IF (NQ
.EQ
. 1) GO TO 340
2768 C Construct coefficients of x*x*(x+xi(1))*...*(x+xi(j)). ---------------
2770 HSUM
= HSUM
+ TAU
(JP1
)
2773 ALPH0
= ALPH0
- ONE
/REAL(JP1
)
2774 ALPH1
= ALPH1
+ ONE
/XI
2775 DO 320 IBACK
= 1, JP1
2777 320 EL
(I
) = EL
(I
)*XIOLD
+ EL
(I
-1)
2781 T1
= (-ALPH0
- ALPH1
)/PROD
2782 C Load column L + 1 in YH array. ---------------------------------------
2785 350 YH
(I
,LP1
) = T1*YH
(I
,LMAX
)
2786 C Add correction terms to YH array. ------------------------------------
2789 CALL DAXPY
(N
, EL
(J
), YH
(1,LP1
), 1, YH
(1,J
), 1 )
2792 C----------------------- End of Subroutine DVJUST ----------------------
2795 SUBROUTINE DVNLSD
(Y
, YH
, LDYH
, VSAV
, SAVF
, EWT
, ACOR
, IWM
, WM
,
2796 1 F
, JAC
, PDUM
, NFLAG
, RPAR
, IPAR
)
2797 EXTERNAL F
, JAC
, PDUM
2798 KPP_REAL Y
, YH
, VSAV
, SAVF
, EWT
, ACOR
, WM
, RPAR
2799 INTEGER LDYH
, IWM
, NFLAG
, IPAR
2800 DIMENSION Y
(*), YH
(LDYH
,*), VSAV
(*), SAVF
(*), EWT
(*), ACOR
(*),
2801 1 IWM
(*), WM
(*), RPAR
(*), IPAR
(*)
2803 C-----------------------------------------------------------------------
2804 C Call sequence input -- Y, YH, LDYH, SAVF, EWT, ACOR, IWM, WM,
2805 C F, JAC, NFLAG, RPAR, IPAR
2806 C Call sequence output -- YH, ACOR, WM, IWM, NFLAG
2807 C COMMON block variables accessed..
2808 C /DVOD01/ ACNRM, CRATE, DRC, H, RC, RL1, TQ(5), TN, ICF,
2809 C JCUR, METH, MITER, N, NSLP
2810 C /DVOD02/ HU, NCFN, NETF, NFE, NJE, NLU, NNI, NQU, NST
2812 C Subroutines called by DVNLSD.. F, DAXPY, DCOPY, DSCAL, DVJAC, DVSOL
2813 C Function routines called by DVNLSD.. DVNORM
2814 C-----------------------------------------------------------------------
2815 C Subroutine DVNLSD is a nonlinear system solver, which uses functional
2816 C iteration or a chord (modified Newton) method. For the chord method
2817 C direct linear algebraic system solvers are used. Subroutine DVNLSD
2818 C then handles the corrector phase of this integration package.
2820 C Communication with DVNLSD is done with the following variables. (For
2821 C more details, please see the comments in the driver subroutine.)
2823 C Y = The dependent variable, a vector of length N, input.
2824 C YH = The Nordsieck (Taylor) array, LDYH by LMAX, input
2825 C and output. On input, it contains predicted values.
2826 C LDYH = A constant .ge. N, the first dimension of YH, input.
2827 C VSAV = Unused work array.
2828 C SAVF = A work array of length N.
2829 C EWT = An error weight vector of length N, input.
2830 C ACOR = A work array of length N, used for the accumulated
2831 C corrections to the predicted y vector.
2832 C WM,IWM = Real and integer work arrays associated with matrix
2833 C operations in chord iteration (MITER .ne. 0).
2834 C F = Dummy name for user supplied routine for f.
2835 C JAC = Dummy name for user supplied Jacobian routine.
2836 C PDUM = Unused dummy subroutine name. Included for uniformity
2837 C over collection of integrators.
2838 C NFLAG = Input/output flag, with values and meanings as follows..
2840 C 0 first CALL for this time step.
2841 C -1 convergence failure in previous CALL to DVNLSD.
2842 C -2 error test failure in DVSTEP.
2844 C 0 successful completion of nonlinear solver.
2845 C -1 convergence failure or singular matrix.
2846 C -2 unrecoverable error in matrix preprocessing
2847 C (cannot occur here).
2848 C -3 unrecoverable error in solution (cannot occur
2850 C RPAR, IPAR = Dummy names for user's real and integer work arrays.
2852 C IPUP = Own variable flag with values and meanings as follows..
2853 C 0, do not update the Newton matrix.
2854 C MITER .ne. 0, update Newton matrix, because it is the
2855 C initial step, order was changed, the error
2856 C test failed, or an update is indicated by
2857 C the scalar RC or step counter NST.
2859 C For more details, see comments in driver subroutine.
2860 C-----------------------------------------------------------------------
2861 C Type declarations for labeled COMMON block DVOD01 --------------------
2863 KPP_REAL ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
,
2864 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
2865 2 RC
, RL1
, TAU
, TQ
, TN
, UROUND
2866 INTEGER ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
2867 1 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
2868 2 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
2869 3 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
2872 C Type declarations for labeled COMMON block DVOD02 --------------------
2875 INTEGER NCFN
, NETF
, NFE
, NJE
, NLU
, NNI
, NQU
, NST
2877 C Type declarations for local variables --------------------------------
2879 KPP_REAL CCMAX
, CRDOWN
, CSCALE
, DCON
, DEL
, DELP
, ONE
,
2881 INTEGER I
, IERPJ
, IERSL
, M
, MAXCOR
, MSBP
2883 C Type declaration for function subroutines called ---------------------
2885 KPP_REAL DVNORM
, STEPCUT
2886 C-----------------------------------------------------------------------
2887 C The following Fortran-77 declaration is to cause the values of the
2888 C listed (local) variables to be saved between calls to this integrator.
2889 C-----------------------------------------------------------------------
2890 SAVE CCMAX
, CRDOWN
, MAXCOR
, MSBP
, RDIV
, ONE
, TWO
, ZERO
2892 COMMON /DVOD01
/ ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
(13),
2893 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
2894 2 RC
, RL1
, TAU
(13), TQ
(5), TN
, UROUND
,
2895 3 ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
2896 4 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
2897 5 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
2898 6 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
2900 COMMON /DVOD02
/ HU
, NCFN
, NETF
, NFE
, NJE
, NLU
, NNI
, NQU
, NST
2902 COMMON /VERWER
/ IVERWER
, IBEGIN
, STEPCUT
2903 DATA CCMAX
/0.3D0
/, CRDOWN
/0.3D0
/, MAXCOR
/3/, MSBP
/20/,
2905 DATA ONE
/1.0D0
/, TWO
/2.0D0
/, ZERO
/0.0D0
/
2906 C-----------------------------------------------------------------------
2907 C On the first step, on a change of method order, or after a
2908 C nonlinear convergence failure with NFLAG = -2, set IPUP = MITER
2909 C to force a Jacobian update when MITER .ne. 0.
2910 C-----------------------------------------------------------------------
2911 if ( (h
.lt
.stepcut
).and
.(IBEGIN
.eq
.1) ) then
2912 c if (h.lt.stepcut) then
2918 IF (JSTART
.EQ
. 0) NSLP
= 0
2919 IF (NFLAG
.EQ
. 0) ICF
= 0
2920 IF (NFLAG
.EQ
. -2) IPUP
= MITER
2921 IF ( (JSTART
.EQ
. 0) .OR
. (JSTART
.EQ
. -1) ) IPUP
= MITER
2922 C If this is functional iteration, set CRATE .eq. 1 and drop to 220
2923 IF (MITER
.EQ
. 0) THEN
2927 C-----------------------------------------------------------------------
2928 C RC is the ratio of new to old values of the coefficient H/EL(2)=h/l1.
2929 C When RC differs from 1 by more than CCMAX, IPUP is set to MITER
2930 C to force DVJAC to be called, if a Jacobian is involved.
2931 C In any case, DVJAC is called at least every MSBP steps.
2932 C-----------------------------------------------------------------------
2934 IF (DRC
.GT
. CCMAX
.OR
. NST
.GE
. NSLP
+MSBP
) IPUP
= MITER
2935 C-----------------------------------------------------------------------
2936 C Up to MAXCOR corrector iterations are taken. A convergence test is
2937 C made on the r.m.s. norm of each correction, weighted by the error
2938 C weight vector EWT. The sum of the corrections is accumulated in the
2939 C vector ACOR(i). The YH array is not altered in the corrector loop.
2940 C-----------------------------------------------------------------------
2943 CALL DCOPY
(N
, YH
(1,1), 1, Y
, 1 )
2944 CALL F
(N
, TN
, Y
, SAVF
)
2946 IF (IPUP
.LE
. 0) GO TO 250
2947 C-----------------------------------------------------------------------
2948 C If indicated, the matrix P = I - h*rl1*J is reevaluated and
2949 C preprocessed before starting the corrector iteration. IPUP is set
2950 C to 0 as an indicator that this has been done.
2951 C-----------------------------------------------------------------------
2952 IF (IVERWER
.EQ
.0) THEN
2953 CALL DVJAC
(Y
, YH
, LDYH
, EWT
, ACOR
, SAVF
, WM
, IWM
, F
, JAC
, IERPJ
,
2963 C If matrix is singular, take error return to force cut in step size. --
2964 IF (IERPJ
.NE
. 0) GO TO 430
2967 C This is a looping point for the corrector iteration. -----------------
2968 270 IF (MITER
.NE
. 0) GO TO 350
2969 C-----------------------------------------------------------------------
2970 C In the case of functional iteration, update Y directly from
2971 C the result of the last function evaluation.
2972 C-----------------------------------------------------------------------
2974 280 SAVF
(I
) = RL1*
(H*SAVF
(I
) - YH
(I
,2))
2976 290 Y
(I
) = SAVF
(I
) - ACOR
(I
)
2977 DEL
= DVNORM
(N
, Y
, EWT
)
2979 300 Y
(I
) = YH
(I
,1) + SAVF
(I
)
2980 CALL DCOPY
(N
, SAVF
, 1, ACOR
, 1)
2982 C-----------------------------------------------------------------------
2983 C In the case of the chord method, compute the corrector error,
2984 C and solve the linear system with that as right-hand side and
2985 C P as coefficient matrix. The correction is scaled by the factor
2986 C 2/(1+RC) to account for changes in h*rl1 since the last DVJAC call.
2987 C-----------------------------------------------------------------------
2989 if (IVERWER
.EQ
.1) then
2992 Y
(I
) = SAVF
(I
) - ACOR
(I
)
2994 DEL
= DVNORM
(N
, Y
, EWT
)
2996 Y
(I
) = YH
(I
,1) + SAVF
(I
)
2998 CALL DCOPY
(N
, SAVF
, 1, ACOR
, 1)
3002 360 Y
(I
) = (RL1*H
)*SAVF
(I
) - (RL1*YH
(I
,2) + ACOR
(I
))
3003 CALL DVSOL
(WM
, IWM
, Y
, IERSL
)
3005 IF (IERSL
.GT
. 0) GO TO 410
3006 IF (METH
.EQ
. 2 .AND
. RC
.NE
. ONE
) THEN
3007 CSCALE
= TWO
/(ONE
+ RC
)
3008 CALL DSCAL
(N
, CSCALE
, Y
, 1)
3010 DEL
= DVNORM
(N
, Y
, EWT
)
3011 CALL DAXPY
(N
, ONE
, Y
, 1, ACOR
, 1)
3013 380 Y
(I
) = YH
(I
,1) + ACOR
(I
)
3014 C-----------------------------------------------------------------------
3015 C Test for convergence. If M .gt. 0, an estimate of the convergence
3016 C rate constant is stored in CRATE, and this is used in the test.
3017 C-----------------------------------------------------------------------
3018 400 IF (M
.NE
. 0) CRATE
= MAX
(CRDOWN*CRATE
,DEL
/DELP
)
3019 DCON
= DEL*MIN
(ONE
,CRATE
)/TQ
(4)
3020 IF (DCON
.LE
. ONE
) GO TO 450
3022 IF (M
.EQ
. MAXCOR
) GO TO 410
3023 IF (M
.GE
. 2 .AND
. DEL
.GT
. RDIV*DELP
) GO TO 410
3025 CALL F
(N
, TN
, Y
, SAVF
)
3029 410 IF (MITER
.EQ
. 0 .OR
. JCUR
.EQ
. 1) GO TO 430
3040 C Return for successful step. ------------------------------------------
3044 IF (M
.EQ
. 0) ACNRM
= DEL
3045 IF (M
.GT
. 0) ACNRM
= DVNORM
(N
, ACOR
, EWT
)
3047 C----------------------- End of Subroutine DVNLSD ----------------------
3051 SUBROUTINE DVJAC
(Y
, YH
, LDYH
, EWT
, FTEM
, SAVF
, WM
, IWM
, FUN
, JAC
,
3052 1 IERPJ
, RPAR
, IPAR
)
3053 C IMPLICIT KPP_REAL (A-H, O-Z)
3054 INCLUDE
'KPP_ROOT_Parameters.h'
3055 INCLUDE
'KPP_ROOT_Sparse.h'
3057 KPP_REAL Y
, YH
, EWT
, FTEM
, SAVF
, WM
, RPAR
3058 INTEGER LDYH
, IWM
, IERPJ
, IPAR
3059 DIMENSION Y
(*), YH
(LDYH
,*), EWT
(*), FTEM
(*), SAVF
(*),
3060 1 WM
(*), IWM
(*), RPAR
(*), IPAR
(*)
3062 C-----------------------------------------------------------------------
3063 C Call sequence input -- Y, YH, LDYH, EWT, FTEM, SAVF, WM, IWM,
3064 C FUN, JAC, RPAR, IPAR
3065 C Call sequence output -- WM, IWM, IERPJ
3066 C COMMON block variables accessed..
3067 C /DVOD01/ CCMXJ, DRC, H, RL1, TN, UROUND, ICF, JCUR, LOCJS,
3069 C /DVOD02/ NFE, NST, NJE, NLU
3071 C Subroutines called by DVJAC.. FUN, JAC, DACOPY, DCOPY, DGBFA, DGEFA,
3073 C Function routines called by DVJAC.. DVNORM
3074 C-----------------------------------------------------------------------
3075 C DVJAC is called by DVSTEP to compute and process the matrix
3076 C P = I - h*rl1*J , where J is an approximation to the Jacobian.
3077 C Here J is computed by the user-supplied routine JAC if
3078 C MITER = 1 or 4, or by finite differencing if MITER = 2, 3, or 5.
3079 C If MITER = 3, a diagonal approximation to J is used.
3080 C If JSV = -1, J is computed from scratch in all cases.
3081 C If JSV = 1 and MITER = 1, 2, 4, or 5, and if the saved value of J is
3082 C considered acceptable, then P is constructed from the saved J.
3083 C J is stored in wm and replaced by P. If MITER .ne. 3, P is then
3084 C subjected to LU decomposition in preparation for later solution
3085 C of linear systems with P as coefficient matrix. This is done
3086 C by DGEFA if MITER = 1 or 2, and by DGBFA if MITER = 4 or 5.
3088 C Communication with DVJAC is done with the following variables. (For
3089 C more details, please see the comments in the driver subroutine.)
3090 C Y = Vector containing predicted values on entry.
3091 C YH = The Nordsieck array, an LDYH by LMAX array, input.
3092 C LDYH = A constant .ge. N, the first dimension of YH, input.
3093 C EWT = An error weight vector of length N.
3094 C SAVF = Array containing f evaluated at predicted y, input.
3095 C WM = Real work space for matrices. In the output, it containS
3096 C the inverse diagonal matrix if MITER = 3 and the LU
3097 C decomposition of P if MITER is 1, 2 , 4, or 5.
3098 C Storage of matrix elements starts at WM(3).
3099 C Storage of the saved Jacobian starts at WM(LOCJS).
3100 C WM also contains the following matrix-related data..
3101 C WM(1) = SQRT(UROUND), used in numerical Jacobian step.
3102 C WM(2) = H*RL1, saved for later use if MITER = 3.
3103 C IWM = Integer work space containing pivot information,
3104 C starting at IWM(31), if MITER is 1, 2, 4, or 5.
3105 C IWM also contains band parameters ML = IWM(1) and
3106 C MU = IWM(2) if MITER is 4 or 5.
3107 C FUN = Dummy name for the user supplied subroutine for f.
3108 C JAC = Dummy name for the user supplied Jacobian subroutine.
3109 C RPAR, IPAR = Dummy names for user's real and integer work arrays.
3110 C RL1 = 1/EL(2) (input).
3111 C IERPJ = Output error flag, = 0 if no trouble, 1 if the P
3112 C matrix is found to be singular.
3113 C JCUR = Output flag to indicate whether the Jacobian matrix
3114 C (or approximation) is now current.
3115 C JCUR = 0 means J is not current.
3116 C JCUR = 1 means J is current.
3117 C-----------------------------------------------------------------------
3119 C Type declarations for labeled COMMON block DVOD01 --------------------
3121 KPP_REAL ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
,
3122 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
3123 2 RC
, RL1
, TAU
, TQ
, TN
, UROUND
3124 INTEGER ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
3125 1 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
3126 2 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
3127 3 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
3130 C Type declarations for labeled COMMON block DVOD02 --------------------
3133 INTEGER NCFN
, NETF
, NFE
, NJE
, NLU
, NNI
, NQU
, NST
3135 C Type declarations for local variables --------------------------------
3137 KPP_REAL CON
, DI
, FAC
, HRL1
, ONE
, PT1
, R
, R0
, SRUR
, THOU
,
3139 INTEGER I
, I1
, I2
, IER
, II
, J
, J1
, JJ
, JOK
, LENP
, MBA
, MBAND
,
3140 1 MEB1
, MEBAND
, ML
, ML3
, MU
, NP1
3142 C Type declaration for function subroutines called ---------------------
3145 C-----------------------------------------------------------------------
3146 C The following Fortran-77 declaration is to cause the values of the
3147 C listed (local) variables to be saved between calls to this subroutine.
3148 C-----------------------------------------------------------------------
3149 SAVE ONE
, PT1
, THOU
, ZERO
3150 C-----------------------------------------------------------------------
3151 COMMON /DVOD01
/ ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
(13),
3152 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
3153 2 RC
, RL1
, TAU
(13), TQ
(5), TN
, UROUND
,
3154 3 ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
3155 4 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
3156 5 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
3157 6 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
3159 COMMON /DVOD02
/ HU
, NCFN
, NETF
, NFE
, NJE
, NLU
, NNI
, NQU
, NST
3161 DATA ONE
/1.0D0
/, THOU
/1000.0D0
/, ZERO
/0.0D0
/, PT1
/0.1D0
/
3166 C See whether J should be evaluated (JOK = -1) or not (JOK = 1). -------
3168 IF (JSV
.EQ
. 1) THEN
3169 IF (NST
.EQ
. 0 .OR
. NST
.GT
. NSLJ
+MSBJ
) JOK
= -1
3170 IF (ICF
.EQ
. 1 .AND
. DRC
.LT
. CCMXJ
) JOK
= -1
3171 IF (ICF
.EQ
. 2) JOK
= -1
3173 C End of setting JOK. --------------------------------------------------
3175 IF (JOK
.EQ
. -1 .AND
. MITER
.EQ
. 1) THEN
3176 C If JOK = -1 and MITER = 1, CALL JAC to evaluate Jacobian. ------------
3184 c CALL Update_SUN(TN)
3185 c CALL Update_RCONST()
3186 CALL JAC
(N
, TN
, Y
, WM
(3))
3187 IF (JSV
.EQ
. 1) CALL DCOPY
(LENP
, WM
(3), 1, WM
(LOCJS
), 1)
3190 IF (JOK
.EQ
. -1 .AND
. MITER
.EQ
. 2) THEN
3191 C If MITER = 2, make N calls to FUN to approximate the Jacobian. ---------
3195 FAC
= DVNORM
(N
, SAVF
, EWT
)
3196 R0
= THOU*ABS
(H
)*UROUND*REAL
(N
)*FAC
3197 IF (R0
.EQ
. ZERO
) R0
= ONE
3202 R
= MAX
(SRUR*ABS
(YJ
),R0
/EWT
(J
))
3205 CALL FUN
(N
, TN
, Y
, FTEM
)
3207 220 WM
(I
+J1
) = (FTEM
(I
) - SAVF
(I
))*FAC
3213 IF (JSV
.EQ
. 1) CALL DCOPY
(LENP
, WM
(3), 1, WM
(LOCJS
), 1)
3216 IF (JOK
.EQ
. 1 .AND
. (MITER
.EQ
. 1 .OR
. MITER
.EQ
. 2)) THEN
3219 CALL DCOPY
(LENP
, WM
(LOCJS
), 1, WM
(3), 1)
3222 IF (MITER
.EQ
. 1 .OR
. MITER
.EQ
. 2) THEN
3223 C Multiply Jacobian by scalar, add identity, and do LU decomposition. --
3225 CALL DSCAL
(LENP
, CON
, WM
(3), 1)
3229 WM
(2+LU_DIAG
(i
)) = WM
(2+LU_DIAG
(i
)) + ONE
3232 C CALL DGEFA (WM(3), N, N, IWM(31), IER)
3233 CALL KppDecomp
( WM
(3), IER
)
3234 IF (IER
.NE
. 0) IERPJ
= 1
3237 C End of code block for MITER = 1 or 2. --------------------------------
3239 IF (MITER
.EQ
. 3) THEN
3240 C If MITER = 3, construct a diagonal approximation to J and P. ---------
3246 310 Y
(I
) = Y
(I
) + R*
(H*SAVF
(I
) - YH
(I
,2))
3247 CALL FUN
(N
, TN
, Y
, WM
(3))
3250 R0
= H*SAVF
(I
) - YH
(I
,2)
3251 DI
= PT1*R0
- H*
(WM
(I
+2) - SAVF
(I
))
3253 IF (ABS
(R0
) .LT
. UROUND
/EWT
(I
)) GO TO 320
3254 IF (ABS
(DI
) .EQ
. ZERO
) GO TO 330
3261 C End of code block for MITER = 3. -------------------------------------
3263 C Set constants for MITER = 4 or 5. ------------------------------------
3271 IF (JOK
.EQ
. -1 .AND
. MITER
.EQ
. 4) THEN
3272 C If JOK = -1 and MITER = 4, CALL JAC to evaluate Jacobian. ------------
3279 c CALL Update_SUN(TN)
3280 c CALL Update_RCONST()
3281 CALL JAC
(N
, TN
, Y
, WM
(ML3
))
3283 1 CALL DACOPY
(MBAND
, N
, WM
(ML3
), MEBAND
, WM
(LOCJS
), MBAND
)
3286 IF (JOK
.EQ
. -1 .AND
. MITER
.EQ
. 5) THEN
3287 C If MITER = 5, make N calls to FUN to approximate the Jacobian. ---------
3294 FAC
= DVNORM
(N
, SAVF
, EWT
)
3295 R0
= THOU*ABS
(H
)*UROUND*REAL
(N
)*FAC
3296 IF (R0
.EQ
. ZERO
) R0
= ONE
3298 DO 530 I
= J
,N
,MBAND
3300 R
= MAX
(SRUR*ABS
(YI
),R0
/EWT
(I
))
3302 CALL FUN
(N
, TN
, Y
, FTEM
)
3303 DO 550 JJ
= J
,N
,MBAND
3306 R
= MAX
(SRUR*ABS
(YJJ
),R0
/EWT
(JJ
))
3310 II
= JJ*MEB1
- ML
+ 2
3312 540 WM
(II
+I
) = (FTEM
(I
) - SAVF
(I
))*FAC
3317 1 CALL DACOPY
(MBAND
, N
, WM
(ML3
), MEBAND
, WM
(LOCJS
), MBAND
)
3320 IF (JOK
.EQ
. 1) THEN
3322 CALL DACOPY
(MBAND
, N
, WM
(LOCJS
), MBAND
, WM
(ML3
), MEBAND
)
3325 C Multiply Jacobian by scalar, add identity, and do LU decomposition.
3327 CALL DSCAL
(LENP
, CON
, WM
(3), 1 )
3330 WM
(II
) = WM
(II
) + ONE
3331 580 II
= II
+ MEBAND
3333 C CALL DGBFA (WM(3), MEBAND, N, ML, MU, IWM(31), IER)
3334 IF (IER
.NE
. 0) IERPJ
= 1
3336 C End of code block for MITER = 4 or 5. --------------------------------
3338 C----------------------- End of Subroutine DVJAC -----------------------
3341 SUBROUTINE DACOPY
(NROW
, NCOL
, A
, NROWA
, B
, NROWB
)
3343 INTEGER NROW
, NCOL
, NROWA
, NROWB
3344 DIMENSION A
(NROWA
,NCOL
), B
(NROWB
,NCOL
)
3345 C-----------------------------------------------------------------------
3346 C Call sequence input -- NROW, NCOL, A, NROWA, NROWB
3347 C Call sequence output -- B
3348 C COMMON block variables accessed -- None
3350 C Subroutines called by DACOPY.. DCOPY
3351 C Function routines called by DACOPY.. None
3352 C-----------------------------------------------------------------------
3353 C This routine copies one rectangular array, A, to another, B,
3354 C where A and B may have different row dimensions, NROWA and NROWB.
3355 C The data copied consists of NROW rows and NCOL columns.
3356 C-----------------------------------------------------------------------
3360 CALL DCOPY
(NROW
, A
(1,IC
), 1, B
(1,IC
), 1)
3364 C----------------------- End of Subroutine DACOPY ----------------------
3367 SUBROUTINE DVSOL
(WM
, IWM
, X
, IERSL
)
3370 DIMENSION WM
(*), IWM
(*), X
(*)
3371 C-----------------------------------------------------------------------
3372 C Call sequence input -- WM, IWM, X
3373 C Call sequence output -- X, IERSL
3374 C COMMON block variables accessed..
3375 C /DVOD01/ -- H, RL1, MITER, N
3377 C Subroutines called by DVSOL.. DGESL, DGBSL
3378 C Function routines called by DVSOL.. None
3379 C-----------------------------------------------------------------------
3380 C This routine manages the solution of the linear system arising from
3381 C a chord iteration. It is called if MITER .ne. 0.
3382 C If MITER is 1 or 2, it calls DGESL to accomplish this.
3383 C If MITER = 3 it updates the coefficient H*RL1 in the diagonal
3384 C matrix, and then computes the solution.
3385 C If MITER is 4 or 5, it calls DGBSL.
3386 C Communication with DVSOL uses the following variables..
3387 C WM = Real work space containing the inverse diagonal matrix if
3388 C MITER = 3 and the LU decomposition of the matrix otherwise.
3389 C Storage of matrix elements starts at WM(3).
3390 C WM also contains the following matrix-related data..
3391 C WM(1) = SQRT(UROUND) (not used here),
3392 C WM(2) = HRL1, the previous value of H*RL1, used if MITER = 3.
3393 C IWM = Integer work space containing pivot information, starting at
3394 C IWM(31), if MITER is 1, 2, 4, or 5. IWM also contains band
3395 C parameters ML = IWM(1) and MU = IWM(2) if MITER is 4 or 5.
3396 C X = The right-hand side vector on input, and the solution vector
3397 C on output, of length N.
3398 C IERSL = Output flag. IERSL = 0 if no trouble occurred.
3399 C IERSL = 1 if a singular matrix arose with MITER = 3.
3400 C-----------------------------------------------------------------------
3402 C Type declarations for labeled COMMON block DVOD01 --------------------
3404 KPP_REAL ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
,
3405 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
3406 2 RC
, RL1
, TAU
, TQ
, TN
, UROUND
3407 INTEGER ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
3408 1 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
3409 2 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
3410 3 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
3413 C Type declarations for local variables --------------------------------
3415 INTEGER I
, MEBAND
, ML
, MU
3416 KPP_REAL DI
, HRL1
, ONE
, PHRL1
, R
, ZERO
3417 C-----------------------------------------------------------------------
3418 C The following Fortran-77 declaration is to cause the values of the
3419 C listed (local) variables to be saved between calls to this integrator.
3420 C-----------------------------------------------------------------------
3423 COMMON /DVOD01
/ ACNRM
, CCMXJ
, CONP
, CRATE
, DRC
, EL
(13),
3424 1 ETA
, ETAMAX
, H
, HMIN
, HMXI
, HNEW
, HSCAL
, PRL1
,
3425 2 RC
, RL1
, TAU
(13), TQ
(5), TN
, UROUND
,
3426 3 ICF
, INIT
, IPUP
, JCUR
, JSTART
, JSV
, KFLAG
, KUTH
,
3427 4 L
, LMAX
, LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
,
3428 5 LOCJS
, MAXORD
, METH
, MITER
, MSBJ
, MXHNIL
, MXSTEP
,
3429 6 N
, NEWH
, NEWQ
, NHNIL
, NQ
, NQNYH
, NQWAIT
, NSLJ
,
3432 DATA ONE
/1.0D0
/, ZERO
/0.0D0
/
3435 GO TO (100, 100, 300, 400, 400), MITER
3436 C 100 CALL DGESL (WM(3), N, N, IWM(31), X, 0)
3437 100 CALL KppSolve
(WM
(3), X
)
3443 IF (HRL1
.EQ
. PHRL1
) GO TO 330
3446 DI
= ONE
- R*
(ONE
- ONE
/WM
(I
+2))
3447 IF (ABS
(DI
) .EQ
. ZERO
) GO TO 390
3448 320 WM
(I
+2) = ONE
/DI
3451 340 X
(I
) = WM
(I
+2)*X
(I
)
3458 MEBAND
= 2*ML
+ MU
+ 1
3459 CALL KppSolve
(WM
(3), X
)
3461 C----------------------- End of Subroutine DVSOL -----------------------
3464 SUBROUTINE DVSRCO
(RSAV
, ISAV
, JOB
)
3467 DIMENSION RSAV
(*), ISAV
(*)
3468 C-----------------------------------------------------------------------
3469 C Call sequence input -- RSAV, ISAV, JOB
3470 C Call sequence output -- RSAV, ISAV
3471 C COMMON block variables accessed -- All of /DVOD01/ and /DVOD02/
3473 C Subroutines/functions called by DVSRCO.. None
3474 C-----------------------------------------------------------------------
3475 C This routine saves or restores (depending on JOB) the contents of the
3476 C COMMON blocks DVOD01 and DVOD02, which are used internally by DVODE.
3478 C RSAV = real array of length 49 or more.
3479 C ISAV = integer array of length 41 or more.
3480 C JOB = flag indicating to save or restore the COMMON blocks..
3481 C JOB = 1 if COMMON is to be saved (written to RSAV/ISAV).
3482 C JOB = 2 if COMMON is to be restored (read from RSAV/ISAV).
3483 C A CALL with JOB = 2 presumes a prior CALL with JOB = 1.
3484 C-----------------------------------------------------------------------
3485 KPP_REAL RVOD1
, RVOD2
3486 INTEGER IVOD1
, IVOD2
3487 INTEGER I
, LENIV1
, LENIV2
, LENRV1
, LENRV2
3488 C-----------------------------------------------------------------------
3489 C The following Fortran-77 declaration is to cause the values of the
3490 C listed (local) variables to be saved between calls to this integrator.
3491 C-----------------------------------------------------------------------
3492 SAVE LENRV1
, LENIV1
, LENRV2
, LENIV2
3494 COMMON /DVOD01
/ RVOD1
(48), IVOD1
(33)
3495 COMMON /DVOD02
/ RVOD2
(1), IVOD2
(8)
3496 DATA LENRV1
/48/, LENIV1
/33/, LENRV2
/1/, LENIV2
/8/
3498 IF (JOB
.EQ
. 2) GO TO 100
3500 10 RSAV
(I
) = RVOD1
(I
)
3502 15 RSAV
(LENRV1
+I
) = RVOD2
(I
)
3505 20 ISAV
(I
) = IVOD1
(I
)
3507 25 ISAV
(LENIV1
+I
) = IVOD2
(I
)
3513 110 RVOD1
(I
) = RSAV
(I
)
3515 115 RVOD2
(I
) = RSAV
(LENRV1
+I
)
3518 120 IVOD1
(I
) = ISAV
(I
)
3520 125 IVOD2
(I
) = ISAV
(LENIV1
+I
)
3523 C----------------------- End of Subroutine DVSRCO ----------------------
3526 SUBROUTINE DEWSET
(N
, ITOL
, RelTol
, AbsTol
, YCUR
, EWT
)
3527 KPP_REAL RelTol
, AbsTol
, YCUR
, EWT
3529 DIMENSION RelTol
(*), AbsTol
(*), YCUR
(N
), EWT
(N
)
3530 C-----------------------------------------------------------------------
3531 C Call sequence input -- N, ITOL, RelTol, AbsTol, YCUR
3532 C Call sequence output -- EWT
3533 C COMMON block variables accessed -- None
3535 C Subroutines/functions called by DEWSET.. None
3536 C-----------------------------------------------------------------------
3537 C This subroutine sets the error weight vector EWT according to
3538 C EWT(i) = RelTol(i)*abs(YCUR(i)) + AbsTol(i), i = 1,...,N,
3539 C with the subscript on RelTol and/or AbsTol possibly replaced by 1 above,
3540 C depending on the value of ITOL.
3541 C-----------------------------------------------------------------------
3544 GO TO (10, 20, 30, 40), ITOL
3547 15 EWT
(I
) = RelTol
(1)*ABS
(YCUR
(I
)) + AbsTol
(1)
3551 25 EWT
(I
) = RelTol
(1)*ABS
(YCUR
(I
)) + AbsTol
(I
)
3555 35 EWT
(I
) = RelTol
(I
)*ABS
(YCUR
(I
)) + AbsTol
(1)
3559 45 EWT
(I
) = RelTol
(I
)*ABS
(YCUR
(I
)) + AbsTol
(I
)
3561 C----------------------- End of Subroutine DEWSET ----------------------
3564 KPP_REAL
FUNCTION DVNORM
(N
, V
, W
)
3567 DIMENSION V
(N
), W
(N
)
3568 C-----------------------------------------------------------------------
3569 C Call sequence input -- N, V, W
3570 C Call sequence output -- None
3571 C COMMON block variables accessed -- None
3573 C Subroutines/functions called by DVNORM.. None
3574 C-----------------------------------------------------------------------
3575 C This function routine computes the weighted root-mean-square norm
3576 C of the vector of length N contained in the array V, with weights
3577 C contained in the array W of length N..
3578 C DVNORM = sqrt( (1/N) * sum( V(i)*W(i) )**2 )
3580 C LOOP UNROLLING BY ADRIAN SANDU, AUG 2, 1995
3582 C-----------------------------------------------------------------------
3589 if( m
.eq
. 0 ) go to 40
3591 SUM
= SUM
+ (V
(I
)*W
(I
))**2
3593 if( n
.lt
. 7 ) return
3596 SUM
= SUM
+ (V
(I
)*W
(I
))**2
3597 SUM
= SUM
+ (V
(I
+ 1)*W
(I
+ 1))**2
3598 SUM
= SUM
+ (V
(I
+ 2)*W
(I
+ 2))**2
3599 SUM
= SUM
+ (V
(I
+ 3)*W
(I
+ 3))**2
3600 SUM
= SUM
+ (V
(I
+ 4)*W
(I
+ 4))**2
3601 SUM
= SUM
+ (V
(I
+ 5)*W
(I
+ 5))**2
3602 SUM
= SUM
+ (V
(I
+ 6)*W
(I
+ 6))**2
3605 DVNORM
= SQRT
(SUM
/REAL(N
))
3607 C----------------------- End of Function DVNORM ------------------------
3611 KPP_REAL
FUNCTION D1MACH
(IDUM
)
3613 C-----------------------------------------------------------------------
3614 C This routine computes the unit roundoff of the machine.
3615 C This is defined as the smallest positive machine number
3616 C u such that 1.0 + u .ne. 1.0
3618 C Subroutines/functions called by D1MACH.. None
3619 C-----------------------------------------------------------------------
3624 IF (COMP
.NE
. 1.0D0
) GO TO 10
3627 C----------------------- End of Function D1MACH ------------------------
3630 SUBROUTINE XERRWD
(MSG
, NMES
, NERR
, LEVEL
, NI
, I1
, I2
, NR
, R1
, R2
)
3632 INTEGER NMES
, NERR
, LEVEL
, NI
, I1
, I2
, NR
3633 CHARACTER*1 MSG
(NMES
)
3634 C-----------------------------------------------------------------------
3635 C Subroutines XERRWD, XSETF, XSETUN, and the two function routines
3636 C MFLGSV and LUNSAV, as given here, constitute a simplified version of
3637 C the SLATEC error handling package.
3638 C Written by A. C. Hindmarsh and P. N. Brown at LLNL.
3639 C Version of 13 April, 1989.
3640 C This version is in KPP_REAL.
3642 C All arguments are input arguments.
3644 C MSG = The message (character array).
3645 C NMES = The length of MSG (number of characters).
3646 C NERR = The error number (not used).
3647 C LEVEL = The error level..
3648 C 0 or 1 means recoverable (control returns to caller).
3649 C 2 means fatal (run is aborted--see note below).
3650 C NI = Number of integers (0, 1, or 2) to be printed with message.
3651 C I1,I2 = Integers to be printed, depending on NI.
3652 C NR = Number of reals (0, 1, or 2) to be printed with message.
3653 C R1,R2 = Reals to be printed, depending on NR.
3655 C Note.. this routine is machine-dependent and specialized for use
3656 C in limited context, in the following ways..
3657 C 1. The argument MSG is assumed to be of type CHARACTER, and
3658 C the message is printed with a format of (1X,80A1).
3659 C 2. The message is assumed to take only one line.
3660 C Multi-line messages are generated by repeated calls.
3661 C 3. If LEVEL = 2, control passes to the statement STOP
3662 C to abort the run. This statement may be machine-dependent.
3663 C 4. R1 and R2 are assumed to be in KPP_REAL and are printed
3666 C For a different default logical unit number, change the data
3667 C statement in function routine LUNSAV.
3668 C For a different run-abort command, change the statement following
3669 C statement 100 at the end.
3670 C-----------------------------------------------------------------------
3671 C Subroutines called by XERRWD.. None
3672 C Function routines called by XERRWD.. MFLGSV, LUNSAV
3673 C-----------------------------------------------------------------------
3675 INTEGER I
, LUNIT
, LUNSAV
, MESFLG
, MFLGSV
3677 C Get message print flag and logical unit number. ----------------------
3678 MESFLG
= MFLGSV
(0,.FALSE
.)
3679 LUNIT
= LUNSAV
(0,.FALSE
.)
3680 IF (MESFLG
.EQ
. 0) GO TO 100
3681 C Write the message. ---------------------------------------------------
3682 WRITE (LUNIT
,10) (MSG
(I
),I
=1,NMES
)
3684 IF (NI
.EQ
. 1) WRITE (LUNIT
, 20) I1
3685 20 FORMAT(6X
,'In above message, I1 =',I10
)
3686 IF (NI
.EQ
. 2) WRITE (LUNIT
, 30) I1
,I2
3687 30 FORMAT(6X
,'In above message, I1 =',I10
,3X
,'I2 =',I10
)
3688 IF (NR
.EQ
. 1) WRITE (LUNIT
, 40) R1
3689 40 FORMAT(6X
,'In above message, R1 =',D21
.13
)
3690 IF (NR
.EQ
. 2) WRITE (LUNIT
, 50) R1
,R2
3691 50 FORMAT(6X
,'In above, R1 =',D21
.13
,3X
,'R2 =',D21
.13
)
3692 C Abort the run if LEVEL = 2. ------------------------------------------
3693 100 IF (LEVEL
.NE
. 2) RETURN
3695 C----------------------- End of Subroutine XERRWD ----------------------
3698 SUBROUTINE XSETF
(MFLAG
)
3699 C-----------------------------------------------------------------------
3700 C This routine resets the print control flag MFLAG.
3702 C Subroutines called by XSETF.. None
3703 C Function routines called by XSETF.. MFLGSV
3704 C-----------------------------------------------------------------------
3705 INTEGER MFLAG
, JUNK
, MFLGSV
3707 IF (MFLAG
.EQ
. 0 .OR
. MFLAG
.EQ
. 1) JUNK
= MFLGSV
(MFLAG
,.TRUE
.)
3709 C----------------------- End of Subroutine XSETF -----------------------
3712 SUBROUTINE XSETUN
(LUN
)
3713 C-----------------------------------------------------------------------
3714 C This routine resets the logical unit number for messages.
3716 C Subroutines called by XSETUN.. None
3717 C Function routines called by XSETUN.. LUNSAV
3718 C-----------------------------------------------------------------------
3719 INTEGER LUN
, JUNK
, LUNSAV
3721 IF (LUN
.GT
. 0) JUNK
= LUNSAV
(LUN
,.TRUE
.)
3723 C----------------------- End of Subroutine XSETUN ----------------------
3726 INTEGER FUNCTION MFLGSV
(IVALUE
, ISET
)
3729 C-----------------------------------------------------------------------
3730 C MFLGSV saves and recalls the parameter MESFLG which controls the
3731 C printing of the error messages.
3733 C Saved local variable..
3735 C MESFLG = Print control flag..
3736 C 1 means print all messages (the default).
3737 C 0 means no printing.
3741 C IVALUE = The value to be set for the MESFLG parameter,
3742 C if ISET is .TRUE. .
3744 C ISET = Logical flag to indicate whether to read or write.
3745 C If ISET=.TRUE., the MESFLG parameter will be given
3746 C the value IVALUE. If ISET=.FALSE., the MESFLG
3747 C parameter will be unchanged, and IVALUE is a dummy
3752 C The (old) value of the MESFLG parameter will be returned
3753 C in the function value, MFLGSV.
3755 C This is a modification of the SLATEC library routine J4SAVE.
3757 C Subroutines/functions called by MFLGSV.. None
3758 C-----------------------------------------------------------------------
3760 C-----------------------------------------------------------------------
3761 C The following Fortran-77 declaration is to cause the values of the
3762 C listed (local) variables to be saved between calls to this integrator.
3763 C-----------------------------------------------------------------------
3768 IF (ISET
) MESFLG
= IVALUE
3770 C----------------------- End of Function MFLGSV ------------------------
3773 INTEGER FUNCTION LUNSAV
(IVALUE
, ISET
)
3776 C-----------------------------------------------------------------------
3777 C LUNSAV saves and recalls the parameter LUNIT which is the logical
3778 C unit number to which error messages are printed.
3780 C Saved local variable..
3782 C LUNIT = Logical unit number for messages.
3783 C The default is 6 (machine-dependent).
3787 C IVALUE = The value to be set for the LUNIT parameter,
3788 C if ISET is .TRUE. .
3790 C ISET = Logical flag to indicate whether to read or write.
3791 C If ISET=.TRUE., the LUNIT parameter will be given
3792 C the value IVALUE. If ISET=.FALSE., the LUNIT
3793 C parameter will be unchanged, and IVALUE is a dummy
3798 C The (old) value of the LUNIT parameter will be returned
3799 C in the function value, LUNSAV.
3801 C This is a modification of the SLATEC library routine J4SAVE.
3803 C Subroutines/functions called by LUNSAV.. None
3804 C-----------------------------------------------------------------------
3806 C-----------------------------------------------------------------------
3807 C The following Fortran-77 declaration is to cause the values of the
3808 C listed (local) variables to be saved between calls to this integrator.
3809 C-----------------------------------------------------------------------
3814 IF (ISET
) LUNIT
= IVALUE
3816 C----------------------- End of Function LUNSAV ------------------------
3819 SUBROUTINE VODE_FSPLIT_VAR
(N
, T
, Y
, PR
)
3820 INCLUDE
'KPP_ROOT_Parameters.h'
3821 INCLUDE
'KPP_ROOT_Global.h'
3824 REAL*8 Y
(NVAR
), PR
(NVAR
)
3829 CALL Update_RCONST
()
3830 CALL Fun
( Y
, FIX
, RCONST
, PR
)
3835 SUBROUTINE VODE_Jac_SP
(N
, T
, Y
, J
)
3836 INCLUDE
'KPP_ROOT_Parameters.h'
3837 INCLUDE
'KPP_ROOT_Global.h'
3840 REAL*8 Y
(NVAR
), J
(LU_NONZERO
)
3845 CALL Update_RCONST
()
3846 CALL Jac_SP
( Y
, FIX
, RCONST
, J
)