1 !**********************************************************************************
2 ! This computer software was prepared by Battelle Memorial Institute, hereinafter
3 ! the Contractor, under Contract No. DE-AC05-76RL0 1830 with the Department of
4 ! Energy (DOE). NEITHER THE GOVERNMENT NOR THE CONTRACTOR MAKES ANY WARRANTY,
5 ! EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE.
7 ! MOSAIC module: see module_mosaic_driver.F for information and terms of use
8 !**********************************************************************************
10 ! 27-oct-2005 rce - do not declare functions that are in the module
11 !-----------------------------------------------------------------------
12 ! module_cmu_dvode_solver - from vode.f & vode_subs.f on 27-oct-2005
13 ! (vode.f - downloaded from www.netlib.org on 28-jul-2004)
14 ! (vode_subs.f - created on 28-jul-2004
15 ! by downloading following from www.netlib.org
16 ! 1. daxpy, dcopy, ddot, dnrm2, dscal, idamax from blas
17 ! 2. dgbfa, dbgsl, dgefa, dgesl from linpack)
19 ! first converted to lowercase
20 ! then converted to fortran-90
21 ! then converted to module
22 ! for this step, had to comment out declarations of any
23 ! functions that are part of the module
24 ! also changed common block names to reduce potential for conflicts
25 ! dvod01 --> dvod_cmn01
26 ! dvod02 --> dvod_cmn02
27 !-----------------------------------------------------------------------
29 module module_cmu_dvode_solver
37 !-----------------------------------------------------------------------
38 ! vode.f - downloaded from www.netlib.org on 28-jul-2004
39 !-----------------------------------------------------------------------
42 subroutine dvode (f, neq, y, t, tout, itol, rtol, atol, itask, &
43 istate, iopt, rwork, lrw, iwork, liw, jac, mf, &
46 double precision y, t, tout, rtol, atol, rwork, rpar
47 integer neq, itol, itask, istate, iopt, lrw, iwork, liw, &
49 dimension y(*), rtol(*), atol(*), rwork(lrw), iwork(liw), &
51 !-----------------------------------------------------------------------
52 ! dvode: variable-coefficient ordinary differential equation solver,
53 ! with fixed-leading-coefficient implementation.
54 ! this version is in double precision.
56 ! dvode solves the initial value problem for stiff or nonstiff
57 ! systems of first order odes,
58 ! dy/dt = f(t,y) , or, in component form,
59 ! dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(neq)) (i = 1,...,neq).
60 ! dvode is a package based on the episode and episodeb packages, and
61 ! on the odepack user interface standard, with minor modifications.
62 !-----------------------------------------------------------------------
64 ! peter n. brown and alan c. hindmarsh
65 ! center for applied scientific computing, l-561
66 ! lawrence livermore national laboratory
70 ! illinois institute of technology
72 !-----------------------------------------------------------------------
75 ! 1. p. n. brown, g. d. byrne, and a. c. hindmarsh, 'vode: a variable
76 ! coefficient ode solver,' siam j. sci. stat. comput., 10 (1989),
77 ! pp. 1038-1051. also, llnl report ucrl-98412, june 1988.
78 ! 2. g. d. byrne and a. c. hindmarsh, 'a polyalgorithm for the
79 ! numerical solution of ordinary differential equations,'
80 ! acm trans. math. software, 1 (1975), pp. 71-96.
81 ! 3. a. c. hindmarsh and g. d. byrne, 'episode: an effective package
82 ! for the integration of systems of ordinary differential
83 ! equations,' llnl report ucid-30112, rev. 1, april 1977.
84 ! 4. g. d. byrne and a. c. hindmarsh, 'episodeb: an experimental
85 ! package for the integration of systems of ordinary differential
86 ! equations with banded jacobians,' llnl report ucid-30132, april
88 ! 5. a. c. hindmarsh, 'odepack, a systematized collection of ode
89 ! solvers,' in scientific computing, r. s. stepleman et al., eds.,
90 ! north-holland, amsterdam, 1983, pp. 55-64.
91 ! 6. k. r. jackson and r. sacks-davis, 'an alternative implementation
92 ! of variable step-size multistep formulas for stiff odes,' acm
93 ! trans. math. software, 6 (1980), pp. 295-318.
94 !-----------------------------------------------------------------------
97 ! communication between the user and the dvode package, for normal
98 ! situations, is summarized here. this summary describes only a subset
99 ! of the full set of options available. see the full description for
100 ! details, including optional communication, nonstandard options,
101 ! and instructions for special situations. see also the example
102 ! problem (with program and output) following this summary.
104 ! a. first provide a subroutine of the form:
105 ! subroutine f (neq, t, y, ydot, rpar, ipar)
106 ! double precision t, y(neq), ydot(neq), rpar
107 ! which supplies the vector function f by loading ydot(i) with f(i).
109 ! b. next determine (or guess) whether or not the problem is stiff.
110 ! stiffness occurs when the jacobian matrix df/dy has an eigenvalue
111 ! whose real part is negative and large in magnitude, compared to the
112 ! reciprocal of the t span of interest. if the problem is nonstiff,
113 ! use a method flag mf = 10. if it is stiff, there are four standard
114 ! choices for mf (21, 22, 24, 25), and dvode requires the jacobian
115 ! matrix in some form. in these cases (mf .gt. 0), dvode will use a
116 ! saved copy of the jacobian matrix. if this is undesirable because of
117 ! storage limitations, set mf to the corresponding negative value
118 ! (-21, -22, -24, -25). (see full description of mf below.)
119 ! the jacobian matrix is regarded either as full (mf = 21 or 22),
120 ! or banded (mf = 24 or 25). in the banded case, dvode requires two
121 ! half-bandwidth parameters ml and mu. these are, respectively, the
122 ! widths of the lower and upper parts of the band, excluding the main
123 ! diagonal. thus the band consists of the locations (i,j) with
124 ! i-ml .le. j .le. i+mu, and the full bandwidth is ml+mu+1.
126 ! c. if the problem is stiff, you are encouraged to supply the jacobian
127 ! directly (mf = 21 or 24), but if this is not feasible, dvode will
128 ! compute it internally by difference quotients (mf = 22 or 25).
129 ! if you are supplying the jacobian, provide a subroutine of the form:
130 ! subroutine jac (neq, t, y, ml, mu, pd, nrowpd, rpar, ipar)
131 ! double precision t, y(neq), pd(nrowpd,neq), rpar
132 ! which supplies df/dy by loading pd as follows:
133 ! for a full jacobian (mf = 21), load pd(i,j) with df(i)/dy(j),
134 ! the partial derivative of f(i) with respect to y(j). (ignore the
135 ! ml and mu arguments in this case.)
136 ! for a banded jacobian (mf = 24), load pd(i-j+mu+1,j) with
137 ! df(i)/dy(j), i.e. load the diagonal lines of df/dy into the rows of
138 ! pd from the top down.
139 ! in either case, only nonzero elements need be loaded.
141 ! d. write a main program which calls subroutine dvode once for
142 ! each point at which answers are desired. this should also provide
143 ! for possible use of logical unit 6 for output of error messages
144 ! by dvode. on the first call to dvode, supply arguments as follows:
145 ! f = name of subroutine for right-hand side vector f.
146 ! this name must be declared external in calling program.
147 ! neq = number of first order odes.
148 ! y = array of initial values, of length neq.
149 ! t = the initial value of the independent variable.
150 ! tout = first point where output is desired (.ne. t).
151 ! itol = 1 or 2 according as atol (below) is a scalar or array.
152 ! rtol = relative tolerance parameter (scalar).
153 ! atol = absolute tolerance parameter (scalar or array).
154 ! the estimated local error in y(i) will be controlled so as
155 ! to be roughly less (in magnitude) than
156 ! ewt(i) = rtol*abs(y(i)) + atol if itol = 1, or
157 ! ewt(i) = rtol*abs(y(i)) + atol(i) if itol = 2.
158 ! thus the local error test passes if, in each component,
159 ! either the absolute error is less than atol (or atol(i)),
160 ! or the relative error is less than rtol.
161 ! use rtol = 0.0 for pure absolute error control, and
162 ! use atol = 0.0 (or atol(i) = 0.0) for pure relative error
163 ! control. caution: actual (global) errors may exceed these
164 ! local tolerances, so choose them conservatively.
165 ! itask = 1 for normal computation of output values of y at t = tout.
166 ! istate = integer flag (input and output). set istate = 1.
167 ! iopt = 0 to indicate no optional input used.
168 ! rwork = real work array of length at least:
169 ! 20 + 16*neq for mf = 10,
170 ! 22 + 9*neq + 2*neq**2 for mf = 21 or 22,
171 ! 22 + 11*neq + (3*ml + 2*mu)*neq for mf = 24 or 25.
172 ! lrw = declared length of rwork (in user's dimension statement).
173 ! iwork = integer work array of length at least:
175 ! 30 + neq for mf = 21, 22, 24, or 25.
176 ! if mf = 24 or 25, input in iwork(1),iwork(2) the lower
177 ! and upper half-bandwidths ml,mu.
178 ! liw = declared length of iwork (in user's dimension statement).
179 ! jac = name of subroutine for jacobian matrix (mf = 21 or 24).
180 ! if used, this name must be declared external in calling
181 ! program. if not used, pass a dummy name.
182 ! mf = method flag. standard values are:
183 ! 10 for nonstiff (adams) method, no jacobian used.
184 ! 21 for stiff (bdf) method, user-supplied full jacobian.
185 ! 22 for stiff method, internally generated full jacobian.
186 ! 24 for stiff method, user-supplied banded jacobian.
187 ! 25 for stiff method, internally generated banded jacobian.
188 ! rpar,ipar = user-defined real and integer arrays passed to f and jac.
189 ! note that the main program must declare arrays y, rwork, iwork,
190 ! and possibly atol, rpar, and ipar.
192 ! e. the output from the first call (or any call) is:
193 ! y = array of computed values of y(t) vector.
194 ! t = corresponding value of independent variable (normally tout).
195 ! istate = 2 if dvode was successful, negative otherwise.
196 ! -1 means excess work done on this call. (perhaps wrong mf.)
197 ! -2 means excess accuracy requested. (tolerances too small.)
198 ! -3 means illegal input detected. (see printed message.)
199 ! -4 means repeated error test failures. (check all input.)
200 ! -5 means repeated convergence failures. (perhaps bad
201 ! jacobian supplied or wrong choice of mf or tolerances.)
202 ! -6 means error weight became zero during problem. (solution
203 ! component i vanished, and atol or atol(i) = 0.)
205 ! f. to continue the integration after a successful return, simply
206 ! reset tout and call dvode again. no other parameters need be reset.
208 !-----------------------------------------------------------------------
211 ! the following is a simple example problem, with the coding
212 ! needed for its solution by dvode. the problem is from chemical
213 ! kinetics, and consists of the following three rate equations:
214 ! dy1/dt = -.04*y1 + 1.e4*y2*y3
215 ! dy2/dt = .04*y1 - 1.e4*y2*y3 - 3.e7*y2**2
216 ! dy3/dt = 3.e7*y2**2
217 ! on the interval from t = 0.0 to t = 4.e10, with initial conditions
218 ! y1 = 1.0, y2 = y3 = 0. the problem is stiff.
220 ! the following coding solves this problem with dvode, using mf = 21
221 ! and printing results at t = .4, 4., ..., 4.e10. it uses
222 ! itol = 2 and atol much smaller for y2 than y1 or y3 because
223 ! y2 has much smaller values.
224 ! at the end of the run, statistical quantities of interest are
225 ! printed. (see optional output in the full description below.)
226 ! to generate fortran source code, replace c in column 1 with a blank
227 ! in the coding below.
230 ! double precision atol, rpar, rtol, rwork, t, tout, y
231 ! dimension y(3), atol(3), rwork(67), iwork(33)
250 ! call dvode(fex,neq,y,t,tout,itol,rtol,atol,itask,istate,
251 ! 1 iopt,rwork,lrw,iwork,liw,jex,mf,rpar,ipar)
252 ! write(6,20)t,y(1),y(2),y(3)
253 ! 20 format(' at t =',d12.4,' y =',3d14.6)
254 ! if (istate .lt. 0) go to 80
256 ! write(6,60) iwork(11),iwork(12),iwork(13),iwork(19),
257 ! 1 iwork(20),iwork(21),iwork(22)
258 ! 60 format(/' no. steps =',i4,' no. f-s =',i4,
259 ! 1 ' no. j-s =',i4,' no. lu-s =',i4/
260 ! 2 ' no. nonlinear iterations =',i4/
261 ! 3 ' no. nonlinear convergence failures =',i4/
262 ! 4 ' no. error test failures =',i4/)
264 ! 80 write(6,90)istate
265 ! 90 format(///' error halt: istate =',i3)
269 ! subroutine fex (neq, t, y, ydot, rpar, ipar)
270 ! double precision rpar, t, y, ydot
271 ! dimension y(neq), ydot(neq)
272 ! ydot(1) = -.04d0*y(1) + 1.d4*y(2)*y(3)
273 ! ydot(3) = 3.d7*y(2)*y(2)
274 ! ydot(2) = -ydot(1) - ydot(3)
278 ! subroutine jex (neq, t, y, ml, mu, pd, nrpd, rpar, ipar)
279 ! double precision pd, rpar, t, y
280 ! dimension y(neq), pd(nrpd,neq)
282 ! pd(1,2) = 1.d4*y(3)
283 ! pd(1,3) = 1.d4*y(2)
286 ! pd(3,2) = 6.d7*y(2)
287 ! pd(2,2) = -pd(1,2) - pd(3,2)
291 ! the following output was obtained from the above program on a
292 ! cray-1 computer with the cft compiler.
294 ! at t = 4.0000e-01 y = 9.851680e-01 3.386314e-05 1.479817e-02
295 ! at t = 4.0000e+00 y = 9.055255e-01 2.240539e-05 9.445214e-02
296 ! at t = 4.0000e+01 y = 7.158108e-01 9.184883e-06 2.841800e-01
297 ! at t = 4.0000e+02 y = 4.505032e-01 3.222940e-06 5.494936e-01
298 ! at t = 4.0000e+03 y = 1.832053e-01 8.942690e-07 8.167938e-01
299 ! at t = 4.0000e+04 y = 3.898560e-02 1.621875e-07 9.610142e-01
300 ! at t = 4.0000e+05 y = 4.935882e-03 1.984013e-08 9.950641e-01
301 ! at t = 4.0000e+06 y = 5.166183e-04 2.067528e-09 9.994834e-01
302 ! at t = 4.0000e+07 y = 5.201214e-05 2.080593e-10 9.999480e-01
303 ! at t = 4.0000e+08 y = 5.213149e-06 2.085271e-11 9.999948e-01
304 ! at t = 4.0000e+09 y = 5.183495e-07 2.073399e-12 9.999995e-01
305 ! at t = 4.0000e+10 y = 5.450996e-08 2.180399e-13 9.999999e-01
307 ! no. steps = 595 no. f-s = 832 no. j-s = 13 no. lu-s = 112
308 ! no. nonlinear iterations = 831
309 ! no. nonlinear convergence failures = 0
310 ! no. error test failures = 22
311 !-----------------------------------------------------------------------
312 ! full description of user interface to dvode.
314 ! the user interface to dvode consists of the following parts.
316 ! i. the call sequence to subroutine dvode, which is a driver
317 ! routine for the solver. this includes descriptions of both
318 ! the call sequence arguments and of user-supplied routines.
319 ! following these descriptions is
320 ! * a description of optional input available through the
322 ! * a description of optional output (in the work arrays), and
323 ! * instructions for interrupting and restarting a solution.
325 ! ii. descriptions of other routines in the dvode package that may be
326 ! (optionally) called by the user. these provide the ability to
327 ! alter error message handling, save and restore the internal
328 ! common, and obtain specified derivatives of the solution y(t).
330 ! iii. descriptions of common blocks to be declared in overlay
331 ! or similar environments.
333 ! iv. description of two routines in the dvode package, either of
334 ! which the user may replace with his own version, if desired.
335 ! these relate to the measurement of errors.
337 !-----------------------------------------------------------------------
338 ! part i. call sequence.
340 ! the call sequence parameters used for input only are
341 ! f, neq, tout, itol, rtol, atol, itask, iopt, lrw, liw, jac, mf,
342 ! and those used for both input and output are
344 ! the work arrays rwork and iwork are also used for conditional and
345 ! optional input and optional output. (the term output here refers
346 ! to the return from subroutine dvode to the user's calling program.)
348 ! the legality of input parameters will be thoroughly checked on the
349 ! initial call for the problem, but not checked thereafter unless a
350 ! change in input parameters is flagged by istate = 3 in the input.
352 ! the descriptions of the call arguments are as follows.
354 ! f = the name of the user-supplied subroutine defining the
355 ! ode system. the system must be put in the first-order
356 ! form dy/dt = f(t,y), where f is a vector-valued function
357 ! of the scalar t and the vector y. subroutine f is to
358 ! compute the function f. it is to have the form
359 ! subroutine f (neq, t, y, ydot, rpar, ipar)
360 ! double precision t, y(neq), ydot(neq), rpar
361 ! where neq, t, and y are input, and the array ydot = f(t,y)
362 ! is output. y and ydot are arrays of length neq.
363 ! subroutine f should not alter y(1),...,y(neq).
364 ! f must be declared external in the calling program.
366 ! subroutine f may access user-defined real and integer
367 ! work arrays rpar and ipar, which are to be dimensioned
368 ! in the main program.
370 ! if quantities computed in the f routine are needed
371 ! externally to dvode, an extra call to f should be made
372 ! for this purpose, for consistent and accurate results.
373 ! if only the derivative dy/dt is needed, use dvindy instead.
375 ! neq = the size of the ode system (number of first order
376 ! ordinary differential equations). used only for input.
377 ! neq may not be increased during the problem, but
378 ! can be decreased (with istate = 3 in the input).
380 ! y = a real array for the vector of dependent variables, of
381 ! length neq or more. used for both input and output on the
382 ! first call (istate = 1), and only for output on other calls.
383 ! on the first call, y must contain the vector of initial
384 ! values. in the output, y contains the computed solution
385 ! evaluated at t. if desired, the y array may be used
386 ! for other purposes between calls to the solver.
388 ! this array is passed as the y argument in all calls to
391 ! t = the independent variable. in the input, t is used only on
392 ! the first call, as the initial point of the integration.
393 ! in the output, after each call, t is the value at which a
394 ! computed solution y is evaluated (usually the same as tout).
395 ! on an error return, t is the farthest point reached.
397 ! tout = the next value of t at which a computed solution is desired.
398 ! used only for input.
400 ! when starting the problem (istate = 1), tout may be equal
401 ! to t for one call, then should .ne. t for the next call.
402 ! for the initial t, an input value of tout .ne. t is used
403 ! in order to determine the direction of the integration
404 ! (i.e. the algebraic sign of the step sizes) and the rough
405 ! scale of the problem. integration in either direction
406 ! (forward or backward in t) is permitted.
408 ! if itask = 2 or 5 (one-step modes), tout is ignored after
409 ! the first call (i.e. the first call with tout .ne. t).
410 ! otherwise, tout is required on every call.
412 ! if itask = 1, 3, or 4, the values of tout need not be
413 ! monotone, but a value of tout which backs up is limited
414 ! to the current internal t interval, whose endpoints are
415 ! tcur - hu and tcur. (see optional output, below, for
418 ! itol = an indicator for the type of error control. see
419 ! description below under atol. used only for input.
421 ! rtol = a relative error tolerance parameter, either a scalar or
422 ! an array of length neq. see description below under atol.
425 ! atol = an absolute error tolerance parameter, either a scalar or
426 ! an array of length neq. input only.
428 ! the input parameters itol, rtol, and atol determine
429 ! the error control performed by the solver. the solver will
430 ! control the vector e = (e(i)) of estimated local errors
431 ! in y, according to an inequality of the form
432 ! rms-norm of ( e(i)/ewt(i) ) .le. 1,
433 ! where ewt(i) = rtol(i)*abs(y(i)) + atol(i),
434 ! and the rms-norm (root-mean-square norm) here is
435 ! rms-norm(v) = sqrt(sum v(i)**2 / neq). here ewt = (ewt(i))
436 ! is a vector of weights which must always be positive, and
437 ! the values of rtol and atol should all be non-negative.
438 ! the following table gives the types (scalar/array) of
439 ! rtol and atol, and the corresponding form of ewt(i).
441 ! itol rtol atol ewt(i)
442 ! 1 scalar scalar rtol*abs(y(i)) + atol
443 ! 2 scalar array rtol*abs(y(i)) + atol(i)
444 ! 3 array scalar rtol(i)*abs(y(i)) + atol
445 ! 4 array array rtol(i)*abs(y(i)) + atol(i)
447 ! when either of these parameters is a scalar, it need not
448 ! be dimensioned in the user's calling program.
450 ! if none of the above choices (with itol, rtol, and atol
451 ! fixed throughout the problem) is suitable, more general
452 ! error controls can be obtained by substituting
453 ! user-supplied routines for the setting of ewt and/or for
454 ! the norm calculation. see part iv below.
456 ! if global errors are to be estimated by making a repeated
457 ! run on the same problem with smaller tolerances, then all
458 ! components of rtol and atol (i.e. of ewt) should be scaled
461 ! itask = an index specifying the task to be performed.
462 ! input only. itask has the following values and meanings.
463 ! 1 means normal computation of output values of y(t) at
464 ! t = tout (by overshooting and interpolating).
465 ! 2 means take one step only and return.
466 ! 3 means stop at the first internal mesh point at or
467 ! beyond t = tout and return.
468 ! 4 means normal computation of output values of y(t) at
469 ! t = tout but without overshooting t = tcrit.
470 ! tcrit must be input as rwork(1). tcrit may be equal to
471 ! or beyond tout, but not behind it in the direction of
472 ! integration. this option is useful if the problem
473 ! has a singularity at or beyond t = tcrit.
474 ! 5 means take one step, without passing tcrit, and return.
475 ! tcrit must be input as rwork(1).
477 ! note: if itask = 4 or 5 and the solver reaches tcrit
478 ! (within roundoff), it will return t = tcrit (exactly) to
479 ! indicate this (unless itask = 4 and tout comes before tcrit,
480 ! in which case answers at t = tout are returned first).
482 ! istate = an index used for input and output to specify the
483 ! the state of the calculation.
485 ! in the input, the values of istate are as follows.
486 ! 1 means this is the first call for the problem
487 ! (initializations will be done). see note below.
488 ! 2 means this is not the first call, and the calculation
489 ! is to continue normally, with no change in any input
490 ! parameters except possibly tout and itask.
491 ! (if itol, rtol, and/or atol are changed between calls
492 ! with istate = 2, the new values will be used but not
493 ! tested for legality.)
494 ! 3 means this is not the first call, and the
495 ! calculation is to continue normally, but with
496 ! a change in input parameters other than
497 ! tout and itask. changes are allowed in
498 ! neq, itol, rtol, atol, iopt, lrw, liw, mf, ml, mu,
499 ! and any of the optional input except h0.
500 ! (see iwork description for ml and mu.)
501 ! note: a preliminary call with tout = t is not counted
502 ! as a first call here, as no initialization or checking of
503 ! input is done. (such a call is sometimes useful to include
504 ! the initial conditions in the output.)
505 ! thus the first call for which tout .ne. t requires
506 ! istate = 1 in the input.
508 ! in the output, istate has the following values and meanings.
509 ! 1 means nothing was done, as tout was equal to t with
510 ! istate = 1 in the input.
511 ! 2 means the integration was performed successfully.
512 ! -1 means an excessive amount of work (more than mxstep
513 ! steps) was done on this call, before completing the
514 ! requested task, but the integration was otherwise
515 ! successful as far as t. (mxstep is an optional input
516 ! and is normally 500.) to continue, the user may
517 ! simply reset istate to a value .gt. 1 and call again.
518 ! (the excess work step counter will be reset to 0.)
519 ! in addition, the user may increase mxstep to avoid
520 ! this error return. (see optional input below.)
521 ! -2 means too much accuracy was requested for the precision
522 ! of the machine being used. this was detected before
523 ! completing the requested task, but the integration
524 ! was successful as far as t. to continue, the tolerance
525 ! parameters must be reset, and istate must be set
526 ! to 3. the optional output tolsf may be used for this
527 ! purpose. (note: if this condition is detected before
528 ! taking any steps, then an illegal input return
529 ! (istate = -3) occurs instead.)
530 ! -3 means illegal input was detected, before taking any
531 ! integration steps. see written message for details.
532 ! note: if the solver detects an infinite loop of calls
533 ! to the solver with illegal input, it will cause
535 ! -4 means there were repeated error test failures on
536 ! one attempted step, before completing the requested
537 ! task, but the integration was successful as far as t.
538 ! the problem may have a singularity, or the input
539 ! may be inappropriate.
540 ! -5 means there were repeated convergence test failures on
541 ! one attempted step, before completing the requested
542 ! task, but the integration was successful as far as t.
543 ! this may be caused by an inaccurate jacobian matrix,
544 ! if one is being used.
545 ! -6 means ewt(i) became zero for some i during the
546 ! integration. pure relative error control (atol(i)=0.0)
547 ! was requested on a variable which has now vanished.
548 ! the integration was successful as far as t.
550 ! note: since the normal output value of istate is 2,
551 ! it does not need to be reset for normal continuation.
552 ! also, since a negative input value of istate will be
553 ! regarded as illegal, a negative output value requires the
554 ! user to change it, and possibly other input, before
555 ! calling the solver again.
557 ! iopt = an integer flag to specify whether or not any optional
558 ! input is being used on this call. input only.
559 ! the optional input is listed separately below.
560 ! iopt = 0 means no optional input is being used.
561 ! default values will be used in all cases.
562 ! iopt = 1 means optional input is being used.
564 ! rwork = a real working array (double precision).
565 ! the length of rwork must be at least
566 ! 20 + nyh*(maxord + 1) + 3*neq + lwm where
567 ! nyh = the initial value of neq,
568 ! maxord = 12 (if meth = 1) or 5 (if meth = 2) (unless a
569 ! smaller value is given as an optional input),
570 ! lwm = length of work space for matrix-related data:
571 ! lwm = 0 if miter = 0,
572 ! lwm = 2*neq**2 + 2 if miter = 1 or 2, and mf.gt.0,
573 ! lwm = neq**2 + 2 if miter = 1 or 2, and mf.lt.0,
574 ! lwm = neq + 2 if miter = 3,
575 ! lwm = (3*ml+2*mu+2)*neq + 2 if miter = 4 or 5, and mf.gt.0,
576 ! lwm = (2*ml+mu+1)*neq + 2 if miter = 4 or 5, and mf.lt.0.
577 ! (see the mf description for meth and miter.)
578 ! thus if maxord has its default value and neq is constant,
580 ! 20 + 16*neq for mf = 10,
581 ! 22 + 16*neq + 2*neq**2 for mf = 11 or 12,
582 ! 22 + 16*neq + neq**2 for mf = -11 or -12,
583 ! 22 + 17*neq for mf = 13,
584 ! 22 + 18*neq + (3*ml+2*mu)*neq for mf = 14 or 15,
585 ! 22 + 17*neq + (2*ml+mu)*neq for mf = -14 or -15,
586 ! 20 + 9*neq for mf = 20,
587 ! 22 + 9*neq + 2*neq**2 for mf = 21 or 22,
588 ! 22 + 9*neq + neq**2 for mf = -21 or -22,
589 ! 22 + 10*neq for mf = 23,
590 ! 22 + 11*neq + (3*ml+2*mu)*neq for mf = 24 or 25.
591 ! 22 + 10*neq + (2*ml+mu)*neq for mf = -24 or -25.
592 ! the first 20 words of rwork are reserved for conditional
593 ! and optional input and optional output.
595 ! the following word in rwork is a conditional input:
596 ! rwork(1) = tcrit = critical value of t which the solver
597 ! is not to overshoot. required if itask is
598 ! 4 or 5, and ignored otherwise. (see itask.)
600 ! lrw = the length of the array rwork, as declared by the user.
601 ! (this will be checked by the solver.)
603 ! iwork = an integer work array. the length of iwork must be at least
604 ! 30 if miter = 0 or 3 (mf = 10, 13, 20, 23), or
605 ! 30 + neq otherwise (abs(mf) = 11,12,14,15,21,22,24,25).
606 ! the first 30 words of iwork are reserved for conditional and
607 ! optional input and optional output.
609 ! the following 2 words in iwork are conditional input:
610 ! iwork(1) = ml these are the lower and upper
611 ! iwork(2) = mu half-bandwidths, respectively, of the
612 ! banded jacobian, excluding the main diagonal.
613 ! the band is defined by the matrix locations
614 ! (i,j) with i-ml .le. j .le. i+mu. ml and mu
615 ! must satisfy 0 .le. ml,mu .le. neq-1.
616 ! these are required if miter is 4 or 5, and
617 ! ignored otherwise. ml and mu may in fact be
618 ! the band parameters for a matrix to which
619 ! df/dy is only approximately equal.
621 ! liw = the length of the array iwork, as declared by the user.
622 ! (this will be checked by the solver.)
624 ! note: the work arrays must not be altered between calls to dvode
625 ! for the same problem, except possibly for the conditional and
626 ! optional input, and except for the last 3*neq words of rwork.
627 ! the latter space is used for internal scratch space, and so is
628 ! available for use by the user outside dvode between calls, if
629 ! desired (but not for use by f or jac).
631 ! jac = the name of the user-supplied routine (miter = 1 or 4) to
632 ! compute the jacobian matrix, df/dy, as a function of
633 ! the scalar t and the vector y. it is to have the form
634 ! subroutine jac (neq, t, y, ml, mu, pd, nrowpd,
636 ! double precision t, y(neq), pd(nrowpd,neq), rpar
637 ! where neq, t, y, ml, mu, and nrowpd are input and the array
638 ! pd is to be loaded with partial derivatives (elements of the
639 ! jacobian matrix) in the output. pd must be given a first
640 ! dimension of nrowpd. t and y have the same meaning as in
642 ! in the full matrix case (miter = 1), ml and mu are
643 ! ignored, and the jacobian is to be loaded into pd in
644 ! columnwise manner, with df(i)/dy(j) loaded into pd(i,j).
645 ! in the band matrix case (miter = 4), the elements
646 ! within the band are to be loaded into pd in columnwise
647 ! manner, with diagonal lines of df/dy loaded into the rows
648 ! of pd. thus df(i)/dy(j) is to be loaded into pd(i-j+mu+1,j).
649 ! ml and mu are the half-bandwidth parameters. (see iwork).
650 ! the locations in pd in the two triangular areas which
651 ! correspond to nonexistent matrix elements can be ignored
652 ! or loaded arbitrarily, as they are overwritten by dvode.
653 ! jac need not provide df/dy exactly. a crude
654 ! approximation (possibly with a smaller bandwidth) will do.
655 ! in either case, pd is preset to zero by the solver,
656 ! so that only the nonzero elements need be loaded by jac.
657 ! each call to jac is preceded by a call to f with the same
658 ! arguments neq, t, and y. thus to gain some efficiency,
659 ! intermediate quantities shared by both calculations may be
660 ! saved in a user common block by f and not recomputed by jac,
661 ! if desired. also, jac may alter the y array, if desired.
662 ! jac must be declared external in the calling program.
663 ! subroutine jac may access user-defined real and integer
664 ! work arrays, rpar and ipar, whose dimensions are set by the
665 ! user in the main program.
667 ! mf = the method flag. used only for input. the legal values of
668 ! mf are 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25,
669 ! -11, -12, -14, -15, -21, -22, -24, -25.
670 ! mf is a signed two-digit integer, mf = jsv*(10*meth + miter).
671 ! jsv = sign(mf) indicates the jacobian-saving strategy:
672 ! jsv = 1 means a copy of the jacobian is saved for reuse
673 ! in the corrector iteration algorithm.
674 ! jsv = -1 means a copy of the jacobian is not saved
675 ! (valid only for miter = 1, 2, 4, or 5).
676 ! meth indicates the basic linear multistep method:
677 ! meth = 1 means the implicit adams method.
678 ! meth = 2 means the method based on backward
679 ! differentiation formulas (bdf-s).
680 ! miter indicates the corrector iteration method:
681 ! miter = 0 means functional iteration (no jacobian matrix
683 ! miter = 1 means chord iteration with a user-supplied
684 ! full (neq by neq) jacobian.
685 ! miter = 2 means chord iteration with an internally
686 ! generated (difference quotient) full jacobian
687 ! (using neq extra calls to f per df/dy value).
688 ! miter = 3 means chord iteration with an internally
689 ! generated diagonal jacobian approximation
690 ! (using 1 extra call to f per df/dy evaluation).
691 ! miter = 4 means chord iteration with a user-supplied
693 ! miter = 5 means chord iteration with an internally
694 ! generated banded jacobian (using ml+mu+1 extra
695 ! calls to f per df/dy evaluation).
696 ! if miter = 1 or 4, the user must supply a subroutine jac
697 ! (the name is arbitrary) as described above under jac.
698 ! for other values of miter, a dummy argument can be used.
700 ! rpar user-specified array used to communicate real parameters
701 ! to user-supplied subroutines. if rpar is a vector, then
702 ! it must be dimensioned in the user's main program. if it
703 ! is unused or it is a scalar, then it need not be
706 ! ipar user-specified array used to communicate integer parameter
707 ! to user-supplied subroutines. the comments on dimensioning
708 ! rpar apply to ipar.
709 !-----------------------------------------------------------------------
712 ! the following is a list of the optional input provided for in the
713 ! call sequence. (see also part ii.) for each such input variable,
714 ! this table lists its name as used in this documentation, its
715 ! location in the call sequence, its meaning, and the default value.
716 ! the use of any of this input requires iopt = 1, and in that
717 ! case all of this input is examined. a value of zero for any
718 ! of these optional input variables will cause the default value to be
719 ! used. thus to use a subset of the optional input, simply preload
720 ! locations 5 to 10 in rwork and iwork to 0.0 and 0 respectively, and
721 ! then set those of interest to nonzero values.
723 ! name location meaning and default value
725 ! h0 rwork(5) the step size to be attempted on the first step.
726 ! the default value is determined by the solver.
728 ! hmax rwork(6) the maximum absolute step size allowed.
729 ! the default value is infinite.
731 ! hmin rwork(7) the minimum absolute step size allowed.
732 ! the default value is 0. (this lower bound is not
733 ! enforced on the final step before reaching tcrit
734 ! when itask = 4 or 5.)
736 ! maxord iwork(5) the maximum order to be allowed. the default
737 ! value is 12 if meth = 1, and 5 if meth = 2.
738 ! if maxord exceeds the default value, it will
739 ! be reduced to the default value.
740 ! if maxord is changed during the problem, it may
741 ! cause the current order to be reduced.
743 ! mxstep iwork(6) maximum number of (internally defined) steps
744 ! allowed during one call to the solver.
745 ! the default value is 500.
747 ! mxhnil iwork(7) maximum number of messages printed (per problem)
748 ! warning that t + h = t on a step (h = step size).
749 ! this must be positive to result in a non-default
750 ! value. the default value is 10.
752 !-----------------------------------------------------------------------
755 ! as optional additional output from dvode, the variables listed
756 ! below are quantities related to the performance of dvode
757 ! which are available to the user. these are communicated by way of
758 ! the work arrays, but also have internal mnemonic names as shown.
759 ! except where stated otherwise, all of this output is defined
760 ! on any successful return from dvode, and on any return with
761 ! istate = -1, -2, -4, -5, or -6. on an illegal input return
762 ! (istate = -3), they will be unchanged from their existing values
763 ! (if any), except possibly for tolsf, lenrw, and leniw.
764 ! on any error return, output relevant to the error will be defined,
767 ! name location meaning
769 ! hu rwork(11) the step size in t last used (successfully).
771 ! hcur rwork(12) the step size to be attempted on the next step.
773 ! tcur rwork(13) the current value of the independent variable
774 ! which the solver has actually reached, i.e. the
775 ! current internal mesh point in t. in the output,
776 ! tcur will always be at least as far from the
777 ! initial value of t as the current argument t,
778 ! but may be farther (if interpolation was done).
780 ! tolsf rwork(14) a tolerance scale factor, greater than 1.0,
781 ! computed when a request for too much accuracy was
782 ! detected (istate = -3 if detected at the start of
783 ! the problem, istate = -2 otherwise). if itol is
784 ! left unaltered but rtol and atol are uniformly
785 ! scaled up by a factor of tolsf for the next call,
786 ! then the solver is deemed likely to succeed.
787 ! (the user may also ignore tolsf and alter the
788 ! tolerance parameters in any other way appropriate.)
790 ! nst iwork(11) the number of steps taken for the problem so far.
792 ! nfe iwork(12) the number of f evaluations for the problem so far.
794 ! nje iwork(13) the number of jacobian evaluations so far.
796 ! nqu iwork(14) the method order last used (successfully).
798 ! nqcur iwork(15) the order to be attempted on the next step.
800 ! imxer iwork(16) the index of the component of largest magnitude in
801 ! the weighted local error vector ( e(i)/ewt(i) ),
802 ! on an error return with istate = -4 or -5.
804 ! lenrw iwork(17) the length of rwork actually required.
805 ! this is defined on normal returns and on an illegal
806 ! input return for insufficient storage.
808 ! leniw iwork(18) the length of iwork actually required.
809 ! this is defined on normal returns and on an illegal
810 ! input return for insufficient storage.
812 ! nlu iwork(19) the number of matrix lu decompositions so far.
814 ! nni iwork(20) the number of nonlinear (newton) iterations so far.
816 ! ncfn iwork(21) the number of convergence failures of the nonlinear
819 ! netf iwork(22) the number of error test failures of the integrator
822 ! the following two arrays are segments of the rwork array which
823 ! may also be of interest to the user as optional output.
824 ! for each array, the table below gives its internal name,
825 ! its base address in rwork, and its description.
827 ! name base address description
829 ! yh 21 the nordsieck history array, of size nyh by
830 ! (nqcur + 1), where nyh is the initial value
831 ! of neq. for j = 0,1,...,nqcur, column j+1
832 ! of yh contains hcur**j/factorial(j) times
833 ! the j-th derivative of the interpolating
834 ! polynomial currently representing the
835 ! solution, evaluated at t = tcur.
837 ! acor lenrw-neq+1 array of size neq used for the accumulated
838 ! corrections on each step, scaled in the output
839 ! to represent the estimated local error in y
840 ! on the last step. this is the vector e in
841 ! the description of the error control. it is
842 ! defined only on a successful return from dvode.
844 !-----------------------------------------------------------------------
845 ! interrupting and restarting
847 ! if the integration of a given problem by dvode is to be
848 ! interrrupted and then later continued, such as when restarting
849 ! an interrupted run or alternating between two or more ode problems,
850 ! the user should save, following the return from the last dvode call
851 ! prior to the interruption, the contents of the call sequence
852 ! variables and internal common blocks, and later restore these
853 ! values before the next dvode call for that problem. to save
854 ! and restore the common blocks, use subroutine dvsrco, as
855 ! described below in part ii.
857 ! in addition, if non-default values for either lun or mflag are
858 ! desired, an extra call to xsetun and/or xsetf should be made just
859 ! before continuing the integration. see part ii below for details.
861 !-----------------------------------------------------------------------
862 ! part ii. other routines callable.
864 ! the following are optional calls which the user may make to
865 ! gain additional capabilities in conjunction with dvode.
866 ! (the routines xsetun and xsetf are designed to conform to the
867 ! slatec error handling package.)
869 ! form of call function
870 ! call xsetun(lun) set the logical unit number, lun, for
871 ! output of messages from dvode, if
872 ! the default is not desired.
873 ! the default value of lun is 6.
875 ! call xsetf(mflag) set a flag to control the printing of
877 ! mflag = 0 means do not print. (danger:
878 ! this risks losing valuable information.)
879 ! mflag = 1 means print (the default).
881 ! either of the above calls may be made at
882 ! any time and will take effect immediately.
884 ! call dvsrco(rsav,isav,job) saves and restores the contents of
885 ! the internal common blocks used by
886 ! dvode. (see part iii below.)
887 ! rsav must be a real array of length 49
888 ! or more, and isav must be an integer
889 ! array of length 40 or more.
890 ! job=1 means save common into rsav/isav.
891 ! job=2 means restore common from rsav/isav.
892 ! dvsrco is useful if one is
893 ! interrupting a run and restarting
894 ! later, or alternating between two or
895 ! more problems solved with dvode.
897 ! call dvindy(,,,,,) provide derivatives of y, of various
898 ! (see below.) orders, at a specified point t, if
899 ! desired. it may be called only after
900 ! a successful return from dvode.
902 ! the detailed instructions for using dvindy are as follows.
903 ! the form of the call is:
905 ! call dvindy (t, k, rwork(21), nyh, dky, iflag)
907 ! the input parameters are:
909 ! t = value of independent variable where answers are desired
910 ! (normally the same as the t last returned by dvode).
911 ! for valid results, t must lie between tcur - hu and tcur.
912 ! (see optional output for tcur and hu.)
913 ! k = integer order of the derivative desired. k must satisfy
914 ! 0 .le. k .le. nqcur, where nqcur is the current order
915 ! (see optional output). the capability corresponding
916 ! to k = 0, i.e. computing y(t), is already provided
917 ! by dvode directly. since nqcur .ge. 1, the first
918 ! derivative dy/dt is always available with dvindy.
919 ! rwork(21) = the base address of the history array yh.
920 ! nyh = column length of yh, equal to the initial value of neq.
922 ! the output parameters are:
924 ! dky = a real array of length neq containing the computed value
925 ! of the k-th derivative of y(t).
926 ! iflag = integer flag, returned as 0 if k and t were legal,
927 ! -1 if k was illegal, and -2 if t was illegal.
928 ! on an error return, a message is also written.
929 !-----------------------------------------------------------------------
930 ! part iii. common blocks.
931 ! if dvode is to be used in an overlay situation, the user
932 ! must declare, in the primary overlay, the variables in:
933 ! (1) the call sequence to dvode,
934 ! (2) the two internal common blocks
935 ! /dvod_cmn01/ of length 81 (48 double precision words
936 ! followed by 33 integer words),
937 ! /dvod_cmn02/ of length 9 (1 double precision word
938 ! followed by 8 integer words),
940 ! if dvode is used on a system in which the contents of internal
941 ! common blocks are not preserved between calls, the user should
942 ! declare the above two common blocks in his main program to insure
943 ! that their contents are preserved.
945 !-----------------------------------------------------------------------
946 ! part iv. optionally replaceable solver routines.
948 ! below are descriptions of two routines in the dvode package which
949 ! relate to the measurement of errors. either routine can be
950 ! replaced by a user-supplied version, if desired. however, since such
951 ! a replacement may have a major impact on performance, it should be
952 ! done only when absolutely necessary, and only with great caution.
953 ! (note: the means by which the package version of a routine is
954 ! superseded by the user's version may be system-dependent.)
957 ! the following subroutine is called just before each internal
958 ! integration step, and sets the array of error weights, ewt, as
959 ! described under itol/rtol/atol above:
960 ! subroutine dewset (neq, itol, rtol, atol, ycur, ewt)
961 ! where neq, itol, rtol, and atol are as in the dvode call sequence,
962 ! ycur contains the current dependent variable vector, and
963 ! ewt is the array of weights set by dewset.
965 ! if the user supplies this subroutine, it must return in ewt(i)
966 ! (i = 1,...,neq) a positive quantity suitable for comparison with
967 ! errors in y(i). the ewt array returned by dewset is passed to the
968 ! dvnorm routine (see below.), and also used by dvode in the computation
969 ! of the optional output imxer, the diagonal jacobian approximation,
970 ! and the increments for difference quotient jacobians.
972 ! in the user-supplied version of dewset, it may be desirable to use
973 ! the current values of derivatives of y. derivatives up to order nq
974 ! are available from the history array yh, described above under
975 ! optional output. in dewset, yh is identical to the ycur array,
976 ! extended to nq + 1 columns with a column length of nyh and scale
977 ! factors of h**j/factorial(j). on the first call for the problem,
978 ! given by nst = 0, nq is 1 and h is temporarily set to 1.0.
979 ! nyh is the initial value of neq. the quantities nq, h, and nst
980 ! can be obtained by including in dewset the statements:
981 ! double precision rvod, h, hu
982 ! common /dvod_cmn01/ rvod(48), ivod(33)
983 ! common /dvod_cmn02/ hu, ncfn, netf, nfe, nje, nlu, nni, nqu, nst
986 ! thus, for example, the current value of dy/dt can be obtained as
987 ! ycur(nyh+i)/h (i=1,...,neq) (and the division by h is
988 ! unnecessary when nst = 0).
991 ! the following is a real function routine which computes the weighted
992 ! root-mean-square norm of a vector v:
993 ! d = dvnorm (n, v, w)
995 ! n = the length of the vector,
996 ! v = real array of length n containing the vector,
997 ! w = real array of length n containing weights,
998 ! d = sqrt( (1/n) * sum(v(i)*w(i))**2 ).
999 ! dvnorm is called with n = neq and with w(i) = 1.0/ewt(i), where
1000 ! ewt is as set by subroutine dewset.
1002 ! if the user supplies this function, it should return a non-negative
1003 ! value of dvnorm suitable for use in the error control in dvode.
1004 ! none of the arguments should be altered by dvnorm.
1005 ! for example, a user-supplied dvnorm routine might:
1006 ! -substitute a max-norm of (v(i)*w(i)) for the rms-norm, or
1007 ! -ignore some components of v in the norm, with the effect of
1008 ! suppressing the error control on those components of y.
1009 !-----------------------------------------------------------------------
1010 ! revision history (yyyymmdd)
1011 ! 19890615 date written. initial release.
1012 ! 19890922 added interrupt/restart ability, minor changes throughout.
1013 ! 19910228 minor revisions in line format, prologue, etc.
1014 ! 19920227 modifications by d. pang:
1015 ! (1) applied subgennam to get generic intrinsic names.
1016 ! (2) changed intrinsic names to generic in comments.
1017 ! (3) added *deck lines before each routine.
1018 ! 19920721 names of routines and labeled common blocks changed, so as
1019 ! to be unique in combined single/double precision code (ach).
1020 ! 19920722 minor revisions to prologue (ach).
1021 ! 19920831 conversion to double precision done (ach).
1022 ! 19921106 fixed minor bug: etaq,etaqm1 in dvstep save statement (ach).
1023 ! 19921118 changed lunsav/mflgsv to ixsav (ach).
1024 ! 19941222 removed mf overwrite; attached sign to h in estimated second
1025 ! deriv. in dvhin; misc. comment changes throughout (ach).
1026 ! 19970515 minor corrections to comments in prologue, dvjac (ach).
1027 ! 19981111 corrected block b by adding final line, go to 200 (ach).
1028 ! 20020430 various upgrades (ach): use odepack error handler package.
1029 ! replaced d1mach by dumach. various changes to main
1030 ! prologue and other routine prologues.
1031 !-----------------------------------------------------------------------
1032 ! other routines in the dvode package.
1034 ! in addition to subroutine dvode, the dvode package includes the
1035 ! following subroutines and function routines:
1036 ! dvhin computes an approximate step size for the initial step.
1037 ! dvindy computes an interpolated value of the y vector at t = tout.
1038 ! dvstep is the core integrator, which does one step of the
1039 ! integration and the associated error control.
1040 ! dvset sets all method coefficients and test constants.
1041 ! dvnlsd solves the underlying nonlinear system -- the corrector.
1042 ! dvjac computes and preprocesses the jacobian matrix j = df/dy
1043 ! and the newton iteration matrix p = i - (h/l1)*j.
1044 ! dvsol manages solution of linear system in chord iteration.
1045 ! dvjust adjusts the history array on a change of order.
1046 ! dewset sets the error weight vector ewt before each step.
1047 ! dvnorm computes the weighted r.m.s. norm of a vector.
1048 ! dvsrco is a user-callable routine to save and restore
1049 ! the contents of the internal common blocks.
1050 ! dacopy is a routine to copy one two-dimensional array to another.
1051 ! dgefa and dgesl are routines from linpack for solving full
1052 ! systems of linear algebraic equations.
1053 ! dgbfa and dgbsl are routines from linpack for solving banded
1055 ! daxpy, dscal, and dcopy are basic linear algebra modules (blas).
1056 ! dumach sets the unit roundoff of the machine.
1057 ! xerrwd, xsetun, xsetf, ixsav, and iumach handle the printing of all
1058 ! error messages and warnings. xerrwd is machine-dependent.
1059 ! note: dvnorm, dumach, ixsav, and iumach are function routines.
1060 ! all the others are subroutines.
1062 !-----------------------------------------------------------------------
1064 ! type declarations for labeled common block dvod_cmn01 --------------------
1066 double precision acnrm, ccmxj, conp, crate, drc, el, &
1067 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
1068 rc, rl1, tau, tq, tn, uround
1069 integer icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
1070 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
1071 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
1072 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
1075 ! type declarations for labeled common block dvod_cmn02 --------------------
1078 integer ncfn, netf, nfe, nje, nlu, nni, nqu, nst
1080 ! type declarations for local variables --------------------------------
1082 ! 27-oct-2005 rce - do not declare functions that are in the module
1085 double precision atoli, big, ewti, four, h0, hmax, hmx, hun, one, &
1086 pt2, rh, rtoli, size, tcrit, tnext, tolsf, tp, two, zero
1087 integer i, ier, iflag, imxer, jco, kgo, leniw, lenj, lenp, lenrw, &
1088 lenwm, lf0, mband, mfa, ml, mord, mu, mxhnl0, mxstp0, niter, &
1092 ! type declaration for function subroutines called ---------------------
1094 ! 27-oct-2005 rce - do not declare functions that are in the module
1095 ! double precision dumach, dvnorm
1098 !-----------------------------------------------------------------------
1099 ! the following fortran-77 declaration is to cause the values of the
1100 ! listed (local) variables to be saved between calls to dvode.
1101 !-----------------------------------------------------------------------
1102 save mord, mxhnl0, mxstp0
1103 save zero, one, two, four, pt2, hun
1104 !-----------------------------------------------------------------------
1105 ! the following internal common blocks contain variables which are
1106 ! communicated between subroutines in the dvode package, or which are
1107 ! to be saved between calls to dvode.
1108 ! in each block, real variables precede integers.
1109 ! the block /dvod_cmn01/ appears in subroutines dvode, dvindy, dvstep,
1110 ! dvset, dvnlsd, dvjac, dvsol, dvjust and dvsrco.
1111 ! the block /dvod_cmn02/ appears in subroutines dvode, dvindy, dvstep,
1112 ! dvnlsd, dvjac, and dvsrco.
1114 ! the variables stored in the internal common blocks are as follows:
1116 ! acnrm = weighted r.m.s. norm of accumulated correction vectors.
1117 ! ccmxj = threshhold on drc for updating the jacobian. (see drc.)
1118 ! conp = the saved value of tq(5).
1119 ! crate = estimated corrector convergence rate constant.
1120 ! drc = relative change in h*rl1 since last dvjac call.
1121 ! el = real array of integration coefficients. see dvset.
1122 ! eta = saved tentative ratio of new to old h.
1123 ! etamax = saved maximum value of eta to be allowed.
1124 ! h = the step size.
1125 ! hmin = the minimum absolute value of the step size h to be used.
1126 ! hmxi = inverse of the maximum absolute value of h to be used.
1127 ! hmxi = 0.0 is allowed and corresponds to an infinite hmax.
1128 ! hnew = the step size to be attempted on the next step.
1129 ! hscal = stepsize in scaling of yh array.
1130 ! prl1 = the saved value of rl1.
1131 ! rc = ratio of current h*rl1 to value on last dvjac call.
1132 ! rl1 = the reciprocal of the coefficient el(1).
1133 ! tau = real vector of past nq step sizes, length 13.
1134 ! tq = a real vector of length 5 in which dvset stores constants
1135 ! used for the convergence test, the error test, and the
1136 ! selection of h at a new order.
1137 ! tn = the independent variable, updated on each step taken.
1138 ! uround = the machine unit roundoff. the smallest positive real number
1139 ! such that 1.0 + uround .ne. 1.0
1140 ! icf = integer flag for convergence failure in dvnlsd:
1141 ! 0 means no failures.
1142 ! 1 means convergence failure with out of date jacobian
1143 ! (recoverable error).
1144 ! 2 means convergence failure with current jacobian or
1145 ! singular matrix (unrecoverable error).
1146 ! init = saved integer flag indicating whether initialization of the
1147 ! problem has been done (init = 1) or not.
1148 ! ipup = saved flag to signal updating of newton matrix.
1149 ! jcur = output flag from dvjac showing jacobian status:
1150 ! jcur = 0 means j is not current.
1151 ! jcur = 1 means j is current.
1152 ! jstart = integer flag used as input to dvstep:
1153 ! 0 means perform the first step.
1154 ! 1 means take a new step continuing from the last.
1155 ! -1 means take the next step with a new value of maxord,
1156 ! hmin, hmxi, n, meth, miter, and/or matrix parameters.
1157 ! on return, dvstep sets jstart = 1.
1158 ! jsv = integer flag for jacobian saving, = sign(mf).
1159 ! kflag = a completion code from dvstep with the following meanings:
1160 ! 0 the step was succesful.
1161 ! -1 the requested error could not be achieved.
1162 ! -2 corrector convergence could not be achieved.
1163 ! -3, -4 fatal error in vnls (can not occur here).
1164 ! kuth = input flag to dvstep showing whether h was reduced by the
1165 ! driver. kuth = 1 if h was reduced, = 0 otherwise.
1166 ! l = integer variable, nq + 1, current order plus one.
1167 ! lmax = maxord + 1 (used for dimensioning).
1168 ! locjs = a pointer to the saved jacobian, whose storage starts at
1169 ! wm(locjs), if jsv = 1.
1170 ! lyh, lewt, lacor, lsavf, lwm, liwm = saved integer pointers
1171 ! to segments of rwork and iwork.
1172 ! maxord = the maximum order of integration method to be allowed.
1173 ! meth/miter = the method flags. see mf.
1174 ! msbj = the maximum number of steps between j evaluations, = 50.
1175 ! mxhnil = saved value of optional input mxhnil.
1176 ! mxstep = saved value of optional input mxstep.
1177 ! n = the number of first-order odes, = neq.
1178 ! newh = saved integer to flag change of h.
1179 ! newq = the method order to be used on the next step.
1180 ! nhnil = saved counter for occurrences of t + h = t.
1181 ! nq = integer variable, the current integration method order.
1182 ! nqnyh = saved value of nq*nyh.
1183 ! nqwait = a counter controlling the frequency of order changes.
1184 ! an order change is about to be considered if nqwait = 1.
1185 ! nslj = the number of steps taken as of the last jacobian update.
1186 ! nslp = saved value of nst as of last newton matrix update.
1187 ! nyh = saved value of the initial value of neq.
1188 ! hu = the step size in t last used.
1189 ! ncfn = number of nonlinear convergence failures so far.
1190 ! netf = the number of error test failures of the integrator so far.
1191 ! nfe = the number of f evaluations for the problem so far.
1192 ! nje = the number of jacobian evaluations so far.
1193 ! nlu = the number of matrix lu decompositions so far.
1194 ! nni = number of nonlinear iterations so far.
1195 ! nqu = the method order last used.
1196 ! nst = the number of steps taken for the problem so far.
1197 !-----------------------------------------------------------------------
1198 common /dvod_cmn01/ acnrm, ccmxj, conp, crate, drc, el(13), &
1199 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
1200 rc, rl1, tau(13), tq(5), tn, uround, &
1201 icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
1202 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
1203 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
1204 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
1206 common /dvod_cmn02/ hu, ncfn, netf, nfe, nje, nlu, nni, nqu, nst
1208 data mord(1) /12/, mord(2) /5/, mxstp0 /500/, mxhnl0 /10/
1209 data zero /0.0d0/, one /1.0d0/, two /2.0d0/, four /4.0d0/, &
1210 pt2 /0.2d0/, hun /100.0d0/
1211 !-----------------------------------------------------------------------
1213 ! this code block is executed on every call.
1214 ! it tests istate and itask for legality and branches appropriately.
1215 ! if istate .gt. 1 but the flag init shows that initialization has
1216 ! not yet been done, an error return occurs.
1217 ! if istate = 1 and tout = t, return immediately.
1218 !-----------------------------------------------------------------------
1219 if (istate .lt. 1 .or. istate .gt. 3) go to 601
1220 if (itask .lt. 1 .or. itask .gt. 5) go to 602
1221 if (istate .eq. 1) go to 10
1222 if (init .ne. 1) go to 603
1223 if (istate .eq. 2) go to 200
1226 if (tout .eq. t) return
1227 !-----------------------------------------------------------------------
1229 ! the next code block is executed for the initial call (istate = 1),
1230 ! or for a continuation call with parameter changes (istate = 3).
1231 ! it contains checking of all input and various initializations.
1233 ! first check legality of the non-optional input neq, itol, iopt,
1235 !-----------------------------------------------------------------------
1236 20 if (neq .le. 0) go to 604
1237 if (istate .eq. 1) go to 25
1238 if (neq .gt. n) go to 605
1240 if (itol .lt. 1 .or. itol .gt. 4) go to 606
1241 if (iopt .lt. 0 .or. iopt .gt. 1) go to 607
1245 miter = mfa - 10*meth
1246 if (meth .lt. 1 .or. meth .gt. 2) go to 608
1247 if (miter .lt. 0 .or. miter .gt. 5) go to 608
1248 if (miter .le. 3) go to 30
1251 if (ml .lt. 0 .or. ml .ge. n) go to 609
1252 if (mu .lt. 0 .or. mu .ge. n) go to 610
1254 ! next process and check the optional input. ---------------------------
1255 if (iopt .eq. 1) go to 40
1259 if (istate .eq. 1) h0 = zero
1263 40 maxord = iwork(5)
1264 if (maxord .lt. 0) go to 611
1265 if (maxord .eq. 0) maxord = 100
1266 maxord = min(maxord,mord(meth))
1268 if (mxstep .lt. 0) go to 612
1269 if (mxstep .eq. 0) mxstep = mxstp0
1271 if (mxhnil .lt. 0) go to 613
1272 if (mxhnil .eq. 0) mxhnil = mxhnl0
1273 if (istate .ne. 1) go to 50
1275 if ((tout - t)*h0 .lt. zero) go to 614
1277 if (hmax .lt. zero) go to 615
1279 if (hmax .gt. zero) hmxi = one/hmax
1281 if (hmin .lt. zero) go to 616
1282 !-----------------------------------------------------------------------
1283 ! set work array pointers and check lengths lrw and liw.
1284 ! pointers to segments of rwork and iwork are named by prefixing l to
1285 ! the name of the segment. e.g., the segment yh starts at rwork(lyh).
1286 ! segments of rwork (in order) are denoted yh, wm, ewt, savf, acor.
1287 ! within wm, locjs is the location of the saved jacobian (jsv .gt. 0).
1288 !-----------------------------------------------------------------------
1290 if (istate .eq. 1) nyh = n
1291 lwm = lyh + (maxord + 1)*nyh
1293 if (miter .eq. 0) lenwm = 0
1294 if (miter .eq. 1 .or. miter .eq. 2) then
1295 lenwm = 2 + (1 + jco)*n*n
1298 if (miter .eq. 3) lenwm = 2 + n
1299 if (miter .eq. 4 .or. miter .eq. 5) then
1301 lenp = (mband + ml)*n
1303 lenwm = 2 + lenp + jco*lenj
1309 lenrw = lacor + n - 1
1313 if (miter .eq. 0 .or. miter .eq. 3) leniw = 30
1315 if (lenrw .gt. lrw) go to 617
1316 if (leniw .gt. liw) go to 618
1317 ! check rtol and atol for legality. ------------------------------------
1321 if (itol .ge. 3) rtoli = rtol(i)
1322 if (itol .eq. 2 .or. itol .eq. 4) atoli = atol(i)
1323 if (rtoli .lt. zero) go to 619
1324 if (atoli .lt. zero) go to 620
1326 if (istate .eq. 1) go to 100
1327 ! if istate = 3, set flag to signal parameter changes to dvstep. -------
1329 if (nq .le. maxord) go to 90
1330 ! maxord was reduced below nq. copy yh(*,maxord+2) into savf. ---------
1331 call dcopy (n, rwork(lwm), 1, rwork(lsavf), 1)
1332 ! reload wm(1) = rwork(lwm), since lwm may have changed. ---------------
1333 90 if (miter .gt. 0) rwork(lwm) = sqrt(uround)
1335 !-----------------------------------------------------------------------
1337 ! the next block is for the initial call only (istate = 1).
1338 ! it contains all remaining initializations, the initial call to f,
1339 ! and the calculation of the initial step size.
1340 ! the error weights in ewt are inverted after being loaded.
1341 !-----------------------------------------------------------------------
1342 100 uround = dumach()
1344 if (itask .ne. 4 .and. itask .ne. 5) go to 110
1346 if ((tcrit - tout)*(tout - t) .lt. zero) go to 625
1347 if (h0 .ne. zero .and. (t + h0 - tcrit)*h0 .gt. zero) &
1350 if (miter .gt. 0) rwork(lwm) = sqrt(uround)
1364 ! initial call to f. (lf0 points to yh(*,2).) -------------------------
1366 call f (n, t, y, rwork(lf0), rpar, ipar)
1368 ! load the initial value vector in yh. ---------------------------------
1369 call dcopy (n, y, 1, rwork(lyh), 1)
1370 ! load and invert the ewt array. (h is temporarily set to 1.0.) -------
1373 call dewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt))
1375 if (rwork(i+lewt-1) .le. zero) go to 621
1376 120 rwork(i+lewt-1) = one/rwork(i+lewt-1)
1377 if (h0 .ne. zero) go to 180
1378 ! call dvhin to set initial step size h0 to be attempted. --------------
1379 call dvhin (n, t, rwork(lyh), rwork(lf0), f, rpar, ipar, tout, &
1380 uround, rwork(lewt), itol, atol, y, rwork(lacor), h0, &
1383 if (ier .ne. 0) go to 622
1384 ! adjust h0 if necessary to meet hmax bound. ---------------------------
1385 180 rh = abs(h0)*hmxi
1386 if (rh .gt. one) h0 = h0/rh
1387 ! load h with h0 and scale yh(*,2) by h0. ------------------------------
1389 call dscal (n, h0, rwork(lf0), 1)
1391 !-----------------------------------------------------------------------
1393 ! the next code block is for continuation calls only (istate = 2 or 3)
1394 ! and is to check stop conditions before taking a step.
1395 !-----------------------------------------------------------------------
1398 go to (210, 250, 220, 230, 240), itask
1399 210 if ((tn - tout)*h .lt. zero) go to 250
1400 call dvindy (tout, 0, rwork(lyh), nyh, y, iflag)
1401 if (iflag .ne. 0) go to 627
1404 220 tp = tn - hu*(one + hun*uround)
1405 if ((tp - tout)*h .gt. zero) go to 623
1406 if ((tn - tout)*h .lt. zero) go to 250
1408 230 tcrit = rwork(1)
1409 if ((tn - tcrit)*h .gt. zero) go to 624
1410 if ((tcrit - tout)*h .lt. zero) go to 625
1411 if ((tn - tout)*h .lt. zero) go to 245
1412 call dvindy (tout, 0, rwork(lyh), nyh, y, iflag)
1413 if (iflag .ne. 0) go to 627
1416 240 tcrit = rwork(1)
1417 if ((tn - tcrit)*h .gt. zero) go to 624
1418 245 hmx = abs(tn) + abs(h)
1419 ihit = abs(tn - tcrit) .le. hun*uround*hmx
1421 tnext = tn + hnew*(one + four*uround)
1422 if ((tnext - tcrit)*h .le. zero) go to 250
1423 h = (tcrit - tn)*(one - four*uround)
1425 !-----------------------------------------------------------------------
1427 ! the next block is normally executed for all calls and contains
1428 ! the call to the one-step core integrator dvstep.
1430 ! this is a looping point for the integration steps.
1432 ! first check for too many steps being taken, update ewt (if not at
1433 ! start of problem), check for too much accuracy being requested, and
1434 ! check for h below the roundoff level in t.
1435 !-----------------------------------------------------------------------
1437 if ((nst-nslast) .ge. mxstep) go to 500
1438 call dewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt))
1440 if (rwork(i+lewt-1) .le. zero) go to 510
1441 260 rwork(i+lewt-1) = one/rwork(i+lewt-1)
1442 270 tolsf = uround*dvnorm (n, rwork(lyh), rwork(lewt))
1443 if (tolsf .le. one) go to 280
1445 if (nst .eq. 0) go to 626
1447 280 if ((tn + h) .ne. tn) go to 290
1449 if (nhnil .gt. mxhnil) go to 290
1450 msg = 'dvode-- warning: internal t (=r1) and h (=r2) are'
1451 call xerrwd (msg, 50, 101, 1, 0, 0, 0, 0, zero, zero)
1452 msg=' such that in the machine, t + h = t on the next step '
1453 call xerrwd (msg, 60, 101, 1, 0, 0, 0, 0, zero, zero)
1454 msg = ' (h = step size). solver will continue anyway'
1455 call xerrwd (msg, 50, 101, 1, 0, 0, 0, 2, tn, h)
1456 if (nhnil .lt. mxhnil) go to 290
1457 msg = 'dvode-- above warning has been issued i1 times. '
1458 call xerrwd (msg, 50, 102, 1, 0, 0, 0, 0, zero, zero)
1459 msg = ' it will not be issued again for this problem'
1460 call xerrwd (msg, 50, 102, 1, 1, mxhnil, 0, 0, zero, zero)
1462 !-----------------------------------------------------------------------
1463 ! call dvstep (y, yh, nyh, yh, ewt, savf, vsav, acor,
1464 ! wm, iwm, f, jac, f, dvnlsd, rpar, ipar)
1465 !-----------------------------------------------------------------------
1466 call dvstep (y, rwork(lyh), nyh, rwork(lyh), rwork(lewt), &
1467 rwork(lsavf), y, rwork(lacor), rwork(lwm), iwork(liwm), &
1468 f, jac, f, dvnlsd, rpar, ipar)
1470 ! branch on kflag. note: in this version, kflag can not be set to -3.
1471 ! kflag .eq. 0, -1, -2
1472 go to (300, 530, 540), kgo
1473 !-----------------------------------------------------------------------
1475 ! the following block handles the case of a successful return from the
1476 ! core integrator (kflag = 0). test for stop conditions.
1477 !-----------------------------------------------------------------------
1480 go to (310, 400, 330, 340, 350), itask
1481 ! itask = 1. if tout has been reached, interpolate. -------------------
1482 310 if ((tn - tout)*h .lt. zero) go to 250
1483 call dvindy (tout, 0, rwork(lyh), nyh, y, iflag)
1486 ! itask = 3. jump to exit if tout was reached. ------------------------
1487 330 if ((tn - tout)*h .ge. zero) go to 400
1489 ! itask = 4. see if tout or tcrit was reached. adjust h if necessary.
1490 340 if ((tn - tout)*h .lt. zero) go to 345
1491 call dvindy (tout, 0, rwork(lyh), nyh, y, iflag)
1494 345 hmx = abs(tn) + abs(h)
1495 ihit = abs(tn - tcrit) .le. hun*uround*hmx
1497 tnext = tn + hnew*(one + four*uround)
1498 if ((tnext - tcrit)*h .le. zero) go to 250
1499 h = (tcrit - tn)*(one - four*uround)
1502 ! itask = 5. see if tcrit was reached and jump to exit. ---------------
1503 350 hmx = abs(tn) + abs(h)
1504 ihit = abs(tn - tcrit) .le. hun*uround*hmx
1505 !-----------------------------------------------------------------------
1507 ! the following block handles all successful returns from dvode.
1508 ! if itask .ne. 1, y is loaded from yh and t is set accordingly.
1509 ! istate is set to 2, and the optional output is loaded into the work
1510 ! arrays before returning.
1511 !-----------------------------------------------------------------------
1513 call dcopy (n, rwork(lyh), 1, y, 1)
1515 if (itask .ne. 4 .and. itask .ne. 5) go to 420
1531 !-----------------------------------------------------------------------
1533 ! the following block handles all unsuccessful returns other than
1534 ! those for illegal input. first the error message routine is called.
1535 ! if there was an error test or convergence test failure, imxer is set.
1536 ! then y is loaded from yh, and t is set to tn.
1537 ! the optional output is loaded into the work arrays before returning.
1538 !-----------------------------------------------------------------------
1539 ! the maximum number of steps was taken before reaching tout. ----------
1540 500 msg = 'dvode-- at current t (=r1), mxstep (=i1) steps '
1541 call xerrwd (msg, 50, 201, 1, 0, 0, 0, 0, zero, zero)
1542 msg = ' taken on this call before reaching tout '
1543 call xerrwd (msg, 50, 201, 1, 1, mxstep, 0, 1, tn, zero)
1546 ! ewt(i) .le. 0.0 for some i (not at start of problem). ----------------
1547 510 ewti = rwork(lewt+i-1)
1548 msg = 'dvode-- at t (=r1), ewt(i1) has become r2 .le. 0.'
1549 call xerrwd (msg, 50, 202, 1, 1, i, 0, 2, tn, ewti)
1552 ! too much accuracy requested for machine precision. -------------------
1553 520 msg = 'dvode-- at t (=r1), too much accuracy requested '
1554 call xerrwd (msg, 50, 203, 1, 0, 0, 0, 0, zero, zero)
1555 msg = ' for precision of machine: see tolsf (=r2) '
1556 call xerrwd (msg, 50, 203, 1, 0, 0, 0, 2, tn, tolsf)
1560 ! kflag = -1. error test failed repeatedly or with abs(h) = hmin. -----
1561 530 msg = 'dvode-- at t(=r1) and step size h(=r2), the error'
1562 call xerrwd (msg, 50, 204, 1, 0, 0, 0, 0, zero, zero)
1563 msg = ' test failed repeatedly or with abs(h) = hmin'
1564 call xerrwd (msg, 50, 204, 1, 0, 0, 0, 2, tn, h)
1567 ! kflag = -2. convergence failed repeatedly or with abs(h) = hmin. ----
1568 540 msg = 'dvode-- at t (=r1) and step size h (=r2), the '
1569 call xerrwd (msg, 50, 205, 1, 0, 0, 0, 0, zero, zero)
1570 msg = ' corrector convergence failed repeatedly '
1571 call xerrwd (msg, 50, 205, 1, 0, 0, 0, 0, zero, zero)
1572 msg = ' or with abs(h) = hmin '
1573 call xerrwd (msg, 30, 205, 1, 0, 0, 0, 2, tn, h)
1575 ! compute imxer if relevant. -------------------------------------------
1579 size = abs(rwork(i+lacor-1)*rwork(i+lewt-1))
1580 if (big .ge. size) go to 570
1585 ! set y vector, t, and optional output. --------------------------------
1587 call dcopy (n, rwork(lyh), 1, y, 1)
1602 !-----------------------------------------------------------------------
1604 ! the following block handles all error returns due to illegal input
1605 ! (istate = -3), as detected before calling the core integrator.
1606 ! first the error message routine is called. if the illegal input
1607 ! is a negative istate, the run is aborted (apparent infinite loop).
1608 !-----------------------------------------------------------------------
1609 601 msg = 'dvode-- istate (=i1) illegal '
1610 call xerrwd (msg, 30, 1, 1, 1, istate, 0, 0, zero, zero)
1611 if (istate .lt. 0) go to 800
1613 602 msg = 'dvode-- itask (=i1) illegal '
1614 call xerrwd (msg, 30, 2, 1, 1, itask, 0, 0, zero, zero)
1616 603 msg='dvode-- istate (=i1) .gt. 1 but dvode not initialized '
1617 call xerrwd (msg, 60, 3, 1, 1, istate, 0, 0, zero, zero)
1619 604 msg = 'dvode-- neq (=i1) .lt. 1 '
1620 call xerrwd (msg, 30, 4, 1, 1, neq, 0, 0, zero, zero)
1622 605 msg = 'dvode-- istate = 3 and neq increased (i1 to i2) '
1623 call xerrwd (msg, 50, 5, 1, 2, n, neq, 0, zero, zero)
1625 606 msg = 'dvode-- itol (=i1) illegal '
1626 call xerrwd (msg, 30, 6, 1, 1, itol, 0, 0, zero, zero)
1628 607 msg = 'dvode-- iopt (=i1) illegal '
1629 call xerrwd (msg, 30, 7, 1, 1, iopt, 0, 0, zero, zero)
1631 608 msg = 'dvode-- mf (=i1) illegal '
1632 call xerrwd (msg, 30, 8, 1, 1, mf, 0, 0, zero, zero)
1634 609 msg = 'dvode-- ml (=i1) illegal: .lt.0 or .ge.neq (=i2)'
1635 call xerrwd (msg, 50, 9, 1, 2, ml, neq, 0, zero, zero)
1637 610 msg = 'dvode-- mu (=i1) illegal: .lt.0 or .ge.neq (=i2)'
1638 call xerrwd (msg, 50, 10, 1, 2, mu, neq, 0, zero, zero)
1640 611 msg = 'dvode-- maxord (=i1) .lt. 0 '
1641 call xerrwd (msg, 30, 11, 1, 1, maxord, 0, 0, zero, zero)
1643 612 msg = 'dvode-- mxstep (=i1) .lt. 0 '
1644 call xerrwd (msg, 30, 12, 1, 1, mxstep, 0, 0, zero, zero)
1646 613 msg = 'dvode-- mxhnil (=i1) .lt. 0 '
1647 call xerrwd (msg, 30, 13, 1, 1, mxhnil, 0, 0, zero, zero)
1649 614 msg = 'dvode-- tout (=r1) behind t (=r2) '
1650 call xerrwd (msg, 40, 14, 1, 0, 0, 0, 2, tout, t)
1651 msg = ' integration direction is given by h0 (=r1) '
1652 call xerrwd (msg, 50, 14, 1, 0, 0, 0, 1, h0, zero)
1654 615 msg = 'dvode-- hmax (=r1) .lt. 0.0 '
1655 call xerrwd (msg, 30, 15, 1, 0, 0, 0, 1, hmax, zero)
1657 616 msg = 'dvode-- hmin (=r1) .lt. 0.0 '
1658 call xerrwd (msg, 30, 16, 1, 0, 0, 0, 1, hmin, zero)
1661 msg='dvode-- rwork length needed, lenrw (=i1), exceeds lrw (=i2)'
1662 call xerrwd (msg, 60, 17, 1, 2, lenrw, lrw, 0, zero, zero)
1665 msg='dvode-- iwork length needed, leniw (=i1), exceeds liw (=i2)'
1666 call xerrwd (msg, 60, 18, 1, 2, leniw, liw, 0, zero, zero)
1668 619 msg = 'dvode-- rtol(i1) is r1 .lt. 0.0 '
1669 call xerrwd (msg, 40, 19, 1, 1, i, 0, 1, rtoli, zero)
1671 620 msg = 'dvode-- atol(i1) is r1 .lt. 0.0 '
1672 call xerrwd (msg, 40, 20, 1, 1, i, 0, 1, atoli, zero)
1674 621 ewti = rwork(lewt+i-1)
1675 msg = 'dvode-- ewt(i1) is r1 .le. 0.0 '
1676 call xerrwd (msg, 40, 21, 1, 1, i, 0, 1, ewti, zero)
1679 msg='dvode-- tout (=r1) too close to t(=r2) to start integration'
1680 call xerrwd (msg, 60, 22, 1, 0, 0, 0, 2, tout, t)
1683 msg='dvode-- itask = i1 and tout (=r1) behind tcur - hu (= r2) '
1684 call xerrwd (msg, 60, 23, 1, 1, itask, 0, 2, tout, tp)
1687 msg='dvode-- itask = 4 or 5 and tcrit (=r1) behind tcur (=r2) '
1688 call xerrwd (msg, 60, 24, 1, 0, 0, 0, 2, tcrit, tn)
1691 msg='dvode-- itask = 4 or 5 and tcrit (=r1) behind tout (=r2) '
1692 call xerrwd (msg, 60, 25, 1, 0, 0, 0, 2, tcrit, tout)
1694 626 msg = 'dvode-- at start of problem, too much accuracy '
1695 call xerrwd (msg, 50, 26, 1, 0, 0, 0, 0, zero, zero)
1696 msg=' requested for precision of machine: see tolsf (=r1) '
1697 call xerrwd (msg, 60, 26, 1, 0, 0, 0, 1, tolsf, zero)
1700 627 msg='dvode-- trouble from dvindy. itask = i1, tout = r1. '
1701 call xerrwd (msg, 60, 27, 1, 1, itask, 0, 1, tout, zero)
1707 800 msg = 'dvode-- run aborted: apparent infinite loop '
1708 call xerrwd (msg, 50, 303, 2, 0, 0, 0, 0, zero, zero)
1710 !----------------------- end of subroutine dvode -----------------------
1711 end subroutine dvode
1713 subroutine dvhin (n, t0, y0, ydot, f, rpar, ipar, tout, uround, &
1714 ewt, itol, atol, y, temp, h0, niter, ier)
1716 double precision t0, y0, ydot, rpar, tout, uround, ewt, atol, y, &
1718 integer n, ipar, itol, niter, ier
1719 dimension y0(*), ydot(*), ewt(*), atol(*), y(*), &
1720 temp(*), rpar(*), ipar(*)
1721 !-----------------------------------------------------------------------
1722 ! call sequence input -- n, t0, y0, ydot, f, rpar, ipar, tout, uround,
1723 ! ewt, itol, atol, y, temp
1724 ! call sequence output -- h0, niter, ier
1725 ! common block variables accessed -- none
1727 ! subroutines called by dvhin: f
1728 ! function routines called by dvhi: dvnorm
1729 !-----------------------------------------------------------------------
1730 ! this routine computes the step size, h0, to be attempted on the
1731 ! first step, when the user has not supplied a value for this.
1733 ! first we check that tout - t0 differs significantly from zero. then
1734 ! an iteration is done to approximate the initial second derivative
1735 ! and this is used to define h from w.r.m.s.norm(h**2 * yddot / 2) = 1.
1736 ! a bias factor of 1/2 is applied to the resulting h.
1737 ! the sign of h0 is inferred from the initial values of tout and t0.
1739 ! communication with dvhin is done with the following variables:
1741 ! n = size of ode system, input.
1742 ! t0 = initial value of independent variable, input.
1743 ! y0 = vector of initial conditions, input.
1744 ! ydot = vector of initial first derivatives, input.
1745 ! f = name of subroutine for right-hand side f(t,y), input.
1746 ! rpar, ipar = dummy names for user's real and integer work arrays.
1747 ! tout = first output value of independent variable
1748 ! uround = machine unit roundoff
1749 ! ewt, itol, atol = error weights and tolerance parameters
1750 ! as described in the driver routine, input.
1751 ! y, temp = work arrays of length n.
1752 ! h0 = step size to be attempted, output.
1753 ! niter = number of iterations (and of f evaluations) to compute h0,
1755 ! ier = the error flag, returned with the value
1756 ! ier = 0 if no trouble occurred, or
1757 ! ier = -1 if tout and t0 are considered too close to proceed.
1758 !-----------------------------------------------------------------------
1760 ! type declarations for local variables --------------------------------
1762 double precision afi, atoli, delyi, h, half, hg, hlb, hnew, hrat, &
1763 hub, hun, pt1, t1, tdist, tround, two, yddnrm
1766 ! type declaration for function subroutines called ---------------------
1768 ! 27-oct-2005 rce - do not declare functions that are in the module
1769 ! double precision dvnorm
1770 !-----------------------------------------------------------------------
1771 ! the following fortran-77 declaration is to cause the values of the
1772 ! listed (local) variables to be saved between calls to this integrator.
1773 !-----------------------------------------------------------------------
1774 save half, hun, pt1, two
1775 data half /0.5d0/, hun /100.0d0/, pt1 /0.1d0/, two /2.0d0/
1778 tdist = abs(tout - t0)
1779 tround = uround*max(abs(t0),abs(tout))
1780 if (tdist .lt. two*tround) go to 100
1782 ! set a lower bound on h based on the roundoff level in t0 and tout. ---
1784 ! set an upper bound on h based on tout-t0 and the initial y and ydot. -
1788 if (itol .eq. 2 .or. itol .eq. 4) atoli = atol(i)
1789 delyi = pt1*abs(y0(i)) + atoli
1791 if (afi*hub .gt. delyi) hub = delyi/afi
1794 ! set initial guess for h as geometric mean of upper and lower bounds. -
1797 ! if the bounds have crossed, exit with the mean value. ----------------
1798 if (hub .lt. hlb) then
1803 ! looping point for iteration. -----------------------------------------
1805 ! estimate the second derivative as a difference quotient in f. --------
1806 h = sign (hg, tout - t0)
1809 60 y(i) = y0(i) + h*ydot(i)
1810 call f (n, t1, y, temp, rpar, ipar)
1812 70 temp(i) = (temp(i) - ydot(i))/h
1813 yddnrm = dvnorm (n, temp, ewt)
1814 ! get the corresponding new value of h. --------------------------------
1815 if (yddnrm*hub*hub .gt. two) then
1816 hnew = sqrt(two/yddnrm)
1821 !-----------------------------------------------------------------------
1822 ! test the stopping conditions.
1823 ! stop if the new and previous h values differ by a factor of .lt. 2.
1824 ! stop if four iterations have been done. also, stop with previous h
1825 ! if hnew/hg .gt. 2 after first iteration, as this probably means that
1826 ! the second derivative value is bad because of cancellation error.
1827 !-----------------------------------------------------------------------
1828 if (iter .ge. 4) go to 80
1830 if ( (hrat .gt. half) .and. (hrat .lt. two) ) go to 80
1831 if ( (iter .ge. 2) .and. (hnew .gt. two*hg) ) then
1838 ! iteration done. apply bounds, bias factor, and sign. then exit. ----
1840 if (h0 .lt. hlb) h0 = hlb
1841 if (h0 .gt. hub) h0 = hub
1842 90 h0 = sign(h0, tout - t0)
1846 ! error return for tout - t0 too small. --------------------------------
1849 !----------------------- end of subroutine dvhin -----------------------
1850 end subroutine dvhin
1852 subroutine dvindy (t, k, yh, ldyh, dky, iflag)
1853 double precision t, yh, dky
1854 integer k, ldyh, iflag
1855 dimension yh(ldyh,*), dky(*)
1856 !-----------------------------------------------------------------------
1857 ! call sequence input -- t, k, yh, ldyh
1858 ! call sequence output -- dky, iflag
1859 ! common block variables accessed:
1860 ! /dvod_cmn01/ -- h, tn, uround, l, n, nq
1861 ! /dvod_cmn02/ -- hu
1863 ! subroutines called by dvindy: dscal, xerrwd
1864 ! function routines called by dvindy: none
1865 !-----------------------------------------------------------------------
1866 ! dvindy computes interpolated values of the k-th derivative of the
1867 ! dependent variable vector y, and stores it in dky. this routine
1868 ! is called within the package with k = 0 and t = tout, but may
1869 ! also be called by the user for any k up to the current order.
1870 ! (see detailed instructions in the usage documentation.)
1871 !-----------------------------------------------------------------------
1872 ! the computed values in dky are gotten by interpolation using the
1873 ! nordsieck history array yh. this array corresponds uniquely to a
1874 ! vector-valued polynomial of degree nqcur or less, and dky is set
1875 ! to the k-th derivative of this polynomial at t.
1876 ! the formula for dky is:
1878 ! dky(i) = sum c(j,k) * (t - tn)**(j-k) * h**(-j) * yh(i,j+1)
1880 ! where c(j,k) = j*(j-1)*...*(j-k+1), q = nqcur, tn = tcur, h = hcur.
1881 ! the quantities nq = nqcur, l = nq+1, n, tn, and h are
1882 ! communicated by common. the above sum is done in reverse order.
1883 ! iflag is returned negative if either k or t is out of bounds.
1885 ! discussion above and comments in driver explain all variables.
1886 !-----------------------------------------------------------------------
1888 ! type declarations for labeled common block dvod_cmn01 --------------------
1890 double precision acnrm, ccmxj, conp, crate, drc, el, &
1891 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
1892 rc, rl1, tau, tq, tn, uround
1893 integer icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
1894 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
1895 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
1896 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
1899 ! type declarations for labeled common block dvod_cmn02 --------------------
1902 integer ncfn, netf, nfe, nje, nlu, nni, nqu, nst
1904 ! type declarations for local variables --------------------------------
1906 double precision c, hun, r, s, tfuzz, tn1, tp, zero
1907 integer i, ic, j, jb, jb2, jj, jj1, jp1
1909 !-----------------------------------------------------------------------
1910 ! the following fortran-77 declaration is to cause the values of the
1911 ! listed (local) variables to be saved between calls to this integrator.
1912 !-----------------------------------------------------------------------
1915 common /dvod_cmn01/ acnrm, ccmxj, conp, crate, drc, el(13), &
1916 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
1917 rc, rl1, tau(13), tq(5), tn, uround, &
1918 icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
1919 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
1920 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
1921 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
1923 common /dvod_cmn02/ hu, ncfn, netf, nfe, nje, nlu, nni, nqu, nst
1925 data hun /100.0d0/, zero /0.0d0/
1928 if (k .lt. 0 .or. k .gt. nq) go to 80
1929 tfuzz = hun*uround*(tn + hu)
1930 tp = tn - hu - tfuzz
1932 if ((t-tp)*(t-tn1) .gt. zero) go to 90
1936 if (k .eq. 0) go to 15
1942 20 dky(i) = c*yh(i,l)
1943 if (k .eq. nq) go to 55
1949 if (k .eq. 0) go to 35
1955 40 dky(i) = c*yh(i,jp1) + s*dky(i)
1957 if (k .eq. 0) return
1959 call dscal (n, r, dky, 1)
1962 80 msg = 'dvindy-- k (=i1) illegal '
1963 call xerrwd (msg, 30, 51, 1, 1, k, 0, 0, zero, zero)
1966 90 msg = 'dvindy-- t (=r1) illegal '
1967 call xerrwd (msg, 30, 52, 1, 0, 0, 0, 1, t, zero)
1968 msg=' t not in interval tcur - hu (= r1) to tcur (=r2) '
1969 call xerrwd (msg, 60, 52, 1, 0, 0, 0, 2, tp, tn)
1972 !----------------------- end of subroutine dvindy ----------------------
1973 end subroutine dvindy
1975 subroutine dvstep (y, yh, ldyh, yh1, ewt, savf, vsav, acor, &
1976 wm, iwm, f, jac, psol, vnls, rpar, ipar)
1977 external f, jac, psol, vnls
1978 double precision y, yh, yh1, ewt, savf, vsav, acor, wm, rpar
1979 integer ldyh, iwm, ipar
1980 dimension y(*), yh(ldyh,*), yh1(*), ewt(*), savf(*), vsav(*), &
1981 acor(*), wm(*), iwm(*), rpar(*), ipar(*)
1982 !-----------------------------------------------------------------------
1983 ! call sequence input -- y, yh, ldyh, yh1, ewt, savf, vsav,
1984 ! acor, wm, iwm, f, jac, psol, vnls, rpar, ipar
1985 ! call sequence output -- yh, acor, wm, iwm
1986 ! common block variables accessed:
1987 ! /dvod_cmn01/ acnrm, el(13), h, hmin, hmxi, hnew, hscal, rc, tau(13),
1988 ! tq(5), tn, jcur, jstart, kflag, kuth,
1989 ! l, lmax, maxord, n, newq, nq, nqwait
1990 ! /dvod_cmn02/ hu, ncfn, netf, nfe, nqu, nst
1992 ! subroutines called by dvstep: f, daxpy, dcopy, dscal,
1993 ! dvjust, vnls, dvset
1994 ! function routines called by dvstep: dvnorm
1995 !-----------------------------------------------------------------------
1996 ! dvstep performs one step of the integration of an initial value
1997 ! problem for a system of ordinary differential equations.
1998 ! dvstep calls subroutine vnls for the solution of the nonlinear system
1999 ! arising in the time step. thus it is independent of the problem
2000 ! jacobian structure and the type of nonlinear system solution method.
2001 ! dvstep returns a completion flag kflag (in common).
2002 ! a return with kflag = -1 or -2 means either abs(h) = hmin or 10
2003 ! consecutive failures occurred. on a return with kflag negative,
2004 ! the values of tn and the yh array are as of the beginning of the last
2005 ! step, and h is the last step size attempted.
2007 ! communication with dvstep is done with the following variables:
2009 ! y = an array of length n used for the dependent variable vector.
2010 ! yh = an ldyh by lmax array containing the dependent variables
2011 ! and their approximate scaled derivatives, where
2012 ! lmax = maxord + 1. yh(i,j+1) contains the approximate
2013 ! j-th derivative of y(i), scaled by h**j/factorial(j)
2014 ! (j = 0,1,...,nq). on entry for the first step, the first
2015 ! two columns of yh must be set from the initial values.
2016 ! ldyh = a constant integer .ge. n, the first dimension of yh.
2017 ! n is the number of odes in the system.
2018 ! yh1 = a one-dimensional array occupying the same space as yh.
2019 ! ewt = an array of length n containing multiplicative weights
2020 ! for local error measurements. local errors in y(i) are
2021 ! compared to 1.0/ewt(i) in various error tests.
2022 ! savf = an array of working storage, of length n.
2023 ! also used for input of yh(*,maxord+2) when jstart = -1
2024 ! and maxord .lt. the current order nq.
2025 ! vsav = a work array of length n passed to subroutine vnls.
2026 ! acor = a work array of length n, used for the accumulated
2027 ! corrections. on a successful return, acor(i) contains
2028 ! the estimated one-step local error in y(i).
2029 ! wm,iwm = real and integer work arrays associated with matrix
2030 ! operations in vnls.
2031 ! f = dummy name for the user supplied subroutine for f.
2032 ! jac = dummy name for the user supplied jacobian subroutine.
2033 ! psol = dummy name for the subroutine passed to vnls, for
2034 ! possible use there.
2035 ! vnls = dummy name for the nonlinear system solving subroutine,
2036 ! whose real name is dependent on the method used.
2037 ! rpar, ipar = dummy names for user's real and integer work arrays.
2038 !-----------------------------------------------------------------------
2040 ! type declarations for labeled common block dvod_cmn01 --------------------
2042 double precision acnrm, ccmxj, conp, crate, drc, el, &
2043 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
2044 rc, rl1, tau, tq, tn, uround
2045 integer icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
2046 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
2047 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
2048 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
2051 ! type declarations for labeled common block dvod_cmn02 --------------------
2054 integer ncfn, netf, nfe, nje, nlu, nni, nqu, nst
2056 ! type declarations for local variables --------------------------------
2058 double precision addon, bias1,bias2,bias3, cnquot, ddn, dsm, dup, &
2059 etacf, etamin, etamx1, etamx2, etamx3, etamxf, &
2060 etaq, etaqm1, etaqp1, flotl, one, onepsm, &
2061 r, thresh, told, zero
2062 integer i, i1, i2, iback, j, jb, kfc, kfh, mxncf, ncf, nflag
2064 ! type declaration for function subroutines called ---------------------
2066 ! 27-oct-2005 rce - do not declare functions that are in the module
2067 ! double precision dvnorm
2068 !-----------------------------------------------------------------------
2069 ! the following fortran-77 declaration is to cause the values of the
2070 ! listed (local) variables to be saved between calls to this integrator.
2071 !-----------------------------------------------------------------------
2072 save addon, bias1, bias2, bias3, &
2073 etacf, etamin, etamx1, etamx2, etamx3, etamxf, etaq, etaqm1, &
2074 kfc, kfh, mxncf, onepsm, thresh, one, zero
2075 !-----------------------------------------------------------------------
2076 common /dvod_cmn01/ acnrm, ccmxj, conp, crate, drc, el(13), &
2077 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
2078 rc, rl1, tau(13), tq(5), tn, uround, &
2079 icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
2080 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
2081 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
2082 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
2084 common /dvod_cmn02/ hu, ncfn, netf, nfe, nje, nlu, nni, nqu, nst
2086 data kfc/-3/, kfh/-7/, mxncf/10/
2087 data addon /1.0d-6/, bias1 /6.0d0/, bias2 /6.0d0/, &
2088 bias3 /10.0d0/, etacf /0.25d0/, etamin /0.1d0/, &
2089 etamxf /0.2d0/, etamx1 /1.0d4/, etamx2 /10.0d0/, &
2090 etamx3 /10.0d0/, onepsm /1.00001d0/, thresh /1.5d0/
2091 data one/1.0d0/, zero/0.0d0/
2098 if (jstart .gt. 0) go to 20
2099 if (jstart .eq. -1) go to 100
2100 !-----------------------------------------------------------------------
2101 ! on the first call, the order is set to 1, and other variables are
2102 ! initialized. etamax is the maximum ratio by which h can be increased
2103 ! in a single step. it is normally 10, but is larger during the
2104 ! first step to compensate for the small initial h. if a failure
2105 ! occurs (in corrector convergence or error test), etamax is set to 1
2106 ! for the next increase.
2107 !-----------------------------------------------------------------------
2119 !-----------------------------------------------------------------------
2120 ! take preliminary actions on a normal continuation step (jstart.gt.0).
2121 ! if the driver changed h, then eta must be reset and newh set to 1.
2122 ! if a change of order was dictated on the previous step, then
2123 ! it is done here and appropriate adjustments in the history are made.
2124 ! on an order decrease, the history array is adjusted by dvjust.
2125 ! on an order increase, the history array is augmented by a column.
2126 ! on a change of step size h, the history array yh is rescaled.
2127 !-----------------------------------------------------------------------
2129 if (kuth .eq. 1) then
2130 eta = min(eta,h/hscal)
2133 50 if (newh .eq. 0) go to 200
2134 if (newq .eq. nq) go to 150
2135 if (newq .lt. nq) then
2136 call dvjust (yh, ldyh, -1)
2142 if (newq .gt. nq) then
2143 call dvjust (yh, ldyh, 1)
2149 !-----------------------------------------------------------------------
2150 ! the following block handles preliminaries needed when jstart = -1.
2151 ! if n was reduced, zero out part of yh to avoid undefined references.
2152 ! if maxord was reduced to a value less than the tentative order newq,
2153 ! then nq is set to maxord, and a new h ratio eta is chosen.
2154 ! otherwise, we take the same preliminary actions as for jstart .gt. 0.
2155 ! in any case, nqwait is reset to l = nq + 1 to prevent further
2156 ! changes in order for that many steps.
2157 ! the new h ratio eta is limited by the input h if kuth = 1,
2158 ! by hmin if kuth = 0, and by hmxi in any case.
2159 ! finally, the history array yh is rescaled.
2160 !-----------------------------------------------------------------------
2163 if (n .eq. ldyh) go to 120
2164 i1 = 1 + (newq + 1)*ldyh
2165 i2 = (maxord + 1)*ldyh
2166 if (i1 .gt. i2) go to 120
2169 120 if (newq .le. maxord) go to 140
2171 if (maxord .lt. nq-1) then
2172 ddn = dvnorm (n, savf, ewt)/tq(1)
2173 eta = one/((bias1*ddn)**(one/flotl) + addon)
2175 if (maxord .eq. nq .and. newq .eq. nq+1) eta = etaq
2176 if (maxord .eq. nq-1 .and. newq .eq. nq+1) then
2178 call dvjust (yh, ldyh, -1)
2180 if (maxord .eq. nq-1 .and. newq .eq. nq) then
2181 ddn = dvnorm (n, savf, ewt)/tq(1)
2182 eta = one/((bias1*ddn)**(one/flotl) + addon)
2183 call dvjust (yh, ldyh, -1)
2188 140 if (kuth .eq. 1) eta = min(eta,abs(h/hscal))
2189 if (kuth .eq. 0) eta = max(eta,hmin/abs(hscal))
2190 eta = eta/max(one,abs(hscal)*hmxi*eta)
2193 if (newq .le. maxord) go to 50
2194 ! rescale the history array for a change in h by a factor of eta. ------
2198 call dscal (n, r, yh(1,j), 1 )
2204 !-----------------------------------------------------------------------
2205 ! this section computes the predicted values by effectively
2206 ! multiplying the yh array by the pascal triangle matrix.
2207 ! dvset is called to calculate all integration coefficients.
2208 ! rc is the ratio of new to old values of the coefficient h/el(2)=h/l1.
2209 !-----------------------------------------------------------------------
2214 do 210 i = i1, nqnyh
2215 210 yh1(i) = yh1(i) + yh1(i+ldyh)
2222 ! call the nonlinear system solver. ------------------------------------
2224 call vnls (y, yh, ldyh, vsav, savf, ewt, acor, iwm, wm, &
2225 f, jac, psol, nflag, rpar, ipar)
2227 if (nflag .eq. 0) go to 450
2228 !-----------------------------------------------------------------------
2229 ! the vnls routine failed to achieve convergence (nflag .ne. 0).
2230 ! the yh array is retracted to its values before prediction.
2231 ! the step size h is reduced and the step is retried, if possible.
2232 ! otherwise, an error exit is taken.
2233 !-----------------------------------------------------------------------
2241 do 420 i = i1, nqnyh
2242 420 yh1(i) = yh1(i) - yh1(i+ldyh)
2244 if (nflag .lt. -1) go to 680
2245 if (abs(h) .le. hmin*onepsm) go to 670
2246 if (ncf .eq. mxncf) go to 670
2248 eta = max(eta,hmin/abs(h))
2251 !-----------------------------------------------------------------------
2252 ! the corrector has converged (nflag = 0). the local error test is
2253 ! made and control passes to statement 500 if it fails.
2254 !-----------------------------------------------------------------------
2257 if (dsm .gt. one) go to 500
2258 !-----------------------------------------------------------------------
2259 ! after a successful step, update the yh and tau arrays and decrement
2260 ! nqwait. if nqwait is then 1 and nq .lt. maxord, then acor is saved
2261 ! for use in a possible order increase on the next step.
2262 ! if etamax = 1 (a failure occurred this step), keep nqwait .ge. 2.
2263 !-----------------------------------------------------------------------
2268 do 470 iback = 1, nq
2270 470 tau(i+1) = tau(i)
2273 call daxpy (n, el(j), acor, 1, yh(1,j), 1 )
2276 if ((l .eq. lmax) .or. (nqwait .ne. 1)) go to 490
2277 call dcopy (n, acor, 1, yh(1,lmax), 1 )
2279 490 if (etamax .ne. one) go to 560
2280 if (nqwait .lt. 2) nqwait = 2
2286 !-----------------------------------------------------------------------
2287 ! the error test failed. kflag keeps track of multiple failures.
2288 ! restore tn and the yh array to their previous values, and prepare
2289 ! to try the step again. compute the optimum step size for the
2290 ! same order. after repeated failures, h is forced to decrease
2292 !-----------------------------------------------------------------------
2293 500 kflag = kflag - 1
2300 do 510 i = i1, nqnyh
2301 510 yh1(i) = yh1(i) - yh1(i+ldyh)
2303 if (abs(h) .le. hmin*onepsm) go to 660
2305 if (kflag .le. kfc) go to 530
2306 ! compute ratio of new h to current h at the current order. ------------
2308 eta = one/((bias2*dsm)**(one/flotl) + addon)
2309 eta = max(eta,hmin/abs(h),etamin)
2310 if ((kflag .le. -2) .and. (eta .gt. etamxf)) eta = etamxf
2312 !-----------------------------------------------------------------------
2313 ! control reaches this section if 3 or more consecutive failures
2314 ! have occurred. it is assumed that the elements of the yh array
2315 ! have accumulated errors of the wrong order. the order is reduced
2316 ! by one, if possible. then h is reduced by a factor of 0.1 and
2317 ! the step is retried. after a total of 7 consecutive failures,
2318 ! an exit is taken with kflag = -1.
2319 !-----------------------------------------------------------------------
2320 530 if (kflag .eq. kfh) go to 660
2321 if (nq .eq. 1) go to 540
2322 eta = max(etamin,hmin/abs(h))
2323 call dvjust (yh, ldyh, -1)
2328 540 eta = max(etamin,hmin/abs(h))
2332 call f (n, tn, y, savf, rpar, ipar)
2335 550 yh(i,2) = h*savf(i)
2338 !-----------------------------------------------------------------------
2339 ! if nqwait = 0, an increase or decrease in order by one is considered.
2340 ! factors etaq, etaqm1, etaqp1 are computed by which h could
2341 ! be multiplied at order q, q-1, or q+1, respectively.
2342 ! the largest of these is determined, and the new order and
2343 ! step size set accordingly.
2344 ! a change of h or nq is made only if h increases by at least a
2345 ! factor of thresh. if an order change is considered and rejected,
2346 ! then nqwait is set to 2 (reconsider it after 2 steps).
2347 !-----------------------------------------------------------------------
2348 ! compute ratio of new h to current h at the current order. ------------
2350 etaq = one/((bias2*dsm)**(one/flotl) + addon)
2351 if (nqwait .ne. 0) go to 600
2354 if (nq .eq. 1) go to 570
2355 ! compute ratio of new h to current h at the current order less one. ---
2356 ddn = dvnorm (n, yh(1,l), ewt)/tq(1)
2357 etaqm1 = one/((bias1*ddn)**(one/(flotl - one)) + addon)
2359 if (l .eq. lmax) go to 580
2360 ! compute ratio of new h to current h at current order plus one. -------
2361 cnquot = (tq(5)/conp)*(h/tau(2))**l
2363 575 savf(i) = acor(i) - cnquot*yh(i,lmax)
2364 dup = dvnorm (n, savf, ewt)/tq(3)
2365 etaqp1 = one/((bias3*dup)**(one/(flotl + one)) + addon)
2366 580 if (etaq .ge. etaqp1) go to 590
2367 if (etaqp1 .gt. etaqm1) go to 620
2369 590 if (etaq .lt. etaqm1) go to 610
2378 call dcopy (n, acor, 1, yh(1,lmax), 1)
2379 ! test tentative new h against thresh, etamax, and hmxi, then exit. ----
2380 630 if (eta .lt. thresh .or. etamax .eq. one) go to 640
2381 eta = min(eta,etamax)
2382 eta = eta/max(one,abs(h)*hmxi*eta)
2391 !-----------------------------------------------------------------------
2392 ! all returns are made through this section.
2393 ! on a successful return, etamax is reset and acor is scaled.
2394 !-----------------------------------------------------------------------
2399 680 if (nflag .eq. -2) kflag = -3
2400 if (nflag .eq. -3) kflag = -4
2403 if (nst .le. 10) etamax = etamx2
2405 call dscal (n, r, acor, 1)
2408 !----------------------- end of subroutine dvstep ----------------------
2409 end subroutine dvstep
2412 !-----------------------------------------------------------------------
2413 ! call sequence communication: none
2414 ! common block variables accessed:
2415 ! /dvod_cmn01/ -- el(13), h, tau(13), tq(5), l(= nq + 1),
2418 ! subroutines called by dvset: none
2419 ! function routines called by dvset: none
2420 !-----------------------------------------------------------------------
2421 ! dvset is called by dvstep and sets coefficients for use there.
2423 ! for each order nq, the coefficients in el are calculated by use of
2424 ! the generating polynomial lambda(x), with coefficients el(i).
2425 ! lambda(x) = el(1) + el(2)*x + ... + el(nq+1)*(x**nq).
2426 ! for the backward differentiation formulas,
2428 ! lambda(x) = (1 + x/xi*(nq)) * product (1 + x/xi(i) ) .
2430 ! for the adams formulas,
2432 ! (d/dx) lambda(x) = c * product (1 + x/xi(i) ) ,
2434 ! lambda(-1) = 0, lambda(0) = 1,
2435 ! where c is a normalization constant.
2436 ! in both cases, xi(i) is defined by
2437 ! h*xi(i) = t sub n - t sub (n-i)
2438 ! = h + tau(1) + tau(2) + ... tau(i-1).
2441 ! in addition to variables described previously, communication
2442 ! with dvset uses the following:
2443 ! tau = a vector of length 13 containing the past nq values
2445 ! el = a vector of length 13 in which vset stores the
2446 ! coefficients for the corrector formula.
2447 ! tq = a vector of length 5 in which vset stores constants
2448 ! used for the convergence test, the error test, and the
2449 ! selection of h at a new order.
2450 ! meth = the basic method indicator.
2451 ! nq = the current order.
2452 ! l = nq + 1, the length of the vector stored in el, and
2453 ! the number of columns of the yh array being used.
2454 ! nqwait = a counter controlling the frequency of order changes.
2455 ! an order change is about to be considered if nqwait = 1.
2456 !-----------------------------------------------------------------------
2458 ! type declarations for labeled common block dvod_cmn01 --------------------
2460 double precision acnrm, ccmxj, conp, crate, drc, el, &
2461 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
2462 rc, rl1, tau, tq, tn, uround
2463 integer icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
2464 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
2465 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
2466 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
2469 ! type declarations for local variables --------------------------------
2471 double precision ahatn0, alph0, cnqm1, cortes, csum, elp, em, &
2472 em0, floti, flotl, flotnq, hsum, one, rxi, rxis, s, six, &
2473 t1, t2, t3, t4, t5, t6, two, xi, zero
2474 integer i, iback, j, jp1, nqm1, nqm2
2477 !-----------------------------------------------------------------------
2478 ! the following fortran-77 declaration is to cause the values of the
2479 ! listed (local) variables to be saved between calls to this integrator.
2480 !-----------------------------------------------------------------------
2481 save cortes, one, six, two, zero
2483 common /dvod_cmn01/ acnrm, ccmxj, conp, crate, drc, el(13), &
2484 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
2485 rc, rl1, tau(13), tq(5), tn, uround, &
2486 icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
2487 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
2488 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
2489 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
2493 data one /1.0d0/, six /6.0d0/, two /2.0d0/, zero /0.0d0/
2498 go to (100, 200), meth
2500 ! set coefficients for adams methods. ----------------------------------
2501 100 if (nq .ne. 1) go to 110
2511 flotnq = flotl - one
2515 if ((j .ne. nqm1) .or. (nqwait .ne. 1)) go to 130
2519 csum = csum + s*em(i)/real(i+1)
2521 tq(1) = em(nqm1)/(flotnq*csum)
2525 140 em(i) = em(i) + em(i-1)*rxi
2526 hsum = hsum + tau(j)
2528 ! compute integral from -1 to 0 of polynomial and of x times it. -------
2534 em0 = em0 + s*em(i)/floti
2535 csum = csum + s*em(i)/(floti+one)
2537 ! in el, form coefficients of normalized integrated polynomial. --------
2541 170 el(i+1) = s*em(i)/real(i)
2545 if (nqwait .ne. 1) go to 300
2546 ! for higher order control constant, multiply polynomial by 1+x/xi(q). -
2548 do 180 iback = 1, nq
2550 180 em(i) = em(i) + em(i-1)*rxi
2551 ! compute integral of polynomial. --------------------------------------
2555 csum = csum + s*em(i)/real(i+1)
2557 tq(3) = flotl*em0/csum
2560 ! set coefficients for bdf methods. ------------------------------------
2570 if (nq .eq. 1) go to 240
2572 ! in el, construct coefficients of (1+x/xi(1))*...*(1+x/xi(j+1)). ------
2573 hsum = hsum + tau(j)
2576 alph0 = alph0 - one/real(jp1)
2577 do 220 iback = 1, jp1
2579 220 el(i) = el(i) + el(i-1)*rxi
2581 alph0 = alph0 - one/real(nq)
2582 rxis = -el(2) - alph0
2583 hsum = hsum + tau(nqm1)
2585 ahatn0 = -el(2) - rxi
2586 do 235 iback = 1, nq
2587 i = (nq + 2) - iback
2588 235 el(i) = el(i) + el(i-1)*rxis
2589 240 t1 = one - ahatn0 + alph0
2590 t2 = one + real(nq)*t1
2591 tq(2) = abs(alph0*t2/t1)
2592 tq(5) = abs(t2/(el(l)*rxi/rxis))
2593 if (nqwait .ne. 1) go to 300
2595 t3 = alph0 + one/real(nq)
2597 elp = t3/(one - t4 + t3)
2598 tq(1) = abs(elp/cnqm1)
2599 hsum = hsum + tau(nq)
2601 t5 = alph0 - one/real(nq+1)
2603 elp = t2/(one - t6 + t5)
2604 tq(3) = abs(elp*rxi*(flotl + one)*t5)
2605 300 tq(4) = cortes*tq(2)
2607 !----------------------- end of subroutine dvset -----------------------
2608 end subroutine dvset
2610 subroutine dvjust (yh, ldyh, iord)
2613 dimension yh(ldyh,*)
2614 !-----------------------------------------------------------------------
2615 ! call sequence input -- yh, ldyh, iord
2616 ! call sequence output -- yh
2617 ! common block input -- nq, meth, lmax, hscal, tau(13), n
2618 ! common block variables accessed:
2619 ! /dvod_cmn01/ -- hscal, tau(13), lmax, meth, n, nq,
2621 ! subroutines called by dvjust: daxpy
2622 ! function routines called by dvjust: none
2623 !-----------------------------------------------------------------------
2624 ! this subroutine adjusts the yh array on reduction of order,
2625 ! and also when the order is increased for the stiff option (meth = 2).
2626 ! communication with dvjust uses the following:
2627 ! iord = an integer flag used when meth = 2 to indicate an order
2628 ! increase (iord = +1) or an order decrease (iord = -1).
2629 ! hscal = step size h used in scaling of nordsieck array yh.
2630 ! (if iord = +1, dvjust assumes that hscal = tau(1).)
2631 ! see references 1 and 2 for details.
2632 !-----------------------------------------------------------------------
2634 ! type declarations for labeled common block dvod_cmn01 --------------------
2636 double precision acnrm, ccmxj, conp, crate, drc, el, &
2637 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
2638 rc, rl1, tau, tq, tn, uround
2639 integer icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
2640 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
2641 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
2642 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
2645 ! type declarations for local variables --------------------------------
2647 double precision alph0, alph1, hsum, one, prod, t1, xi,xiold, zero
2648 integer i, iback, j, jp1, lp1, nqm1, nqm2, nqp1
2649 !-----------------------------------------------------------------------
2650 ! the following fortran-77 declaration is to cause the values of the
2651 ! listed (local) variables to be saved between calls to this integrator.
2652 !-----------------------------------------------------------------------
2655 common /dvod_cmn01/ acnrm, ccmxj, conp, crate, drc, el(13), &
2656 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
2657 rc, rl1, tau(13), tq(5), tn, uround, &
2658 icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
2659 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
2660 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
2661 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
2664 data one /1.0d0/, zero /0.0d0/
2666 if ((nq .eq. 2) .and. (iord .ne. 1)) return
2669 go to (100, 200), meth
2670 !-----------------------------------------------------------------------
2671 ! nonstiff option...
2672 ! check to see if the order is being increased or decreased.
2673 !-----------------------------------------------------------------------
2675 if (iord .eq. 1) go to 180
2676 ! order decrease. ------------------------------------------------------
2682 ! construct coefficients of x*(x+xi(1))*...*(x+xi(j)). -----------------
2683 hsum = hsum + tau(j)
2686 do 120 iback = 1, jp1
2688 120 el(i) = el(i)*xi + el(i-1)
2690 ! construct coefficients of integrated polynomial. ---------------------
2692 140 el(j+1) = real(nq)*el(j)/real(j)
2693 ! subtract correction terms from yh array. -----------------------------
2696 160 yh(i,j) = yh(i,j) - yh(i,l)*el(j)
2699 ! order increase. ------------------------------------------------------
2700 ! zero out next column in yh array. ------------------------------------
2704 190 yh(i,lp1) = zero
2706 !-----------------------------------------------------------------------
2708 ! check to see if the order is being increased or decreased.
2709 !-----------------------------------------------------------------------
2711 if (iord .eq. 1) go to 300
2712 ! order decrease. ------------------------------------------------------
2718 ! construct coefficients of x*x*(x+xi(1))*...*(x+xi(j)). ---------------
2719 hsum = hsum + tau(j)
2722 do 220 iback = 1, jp1
2724 220 el(i) = el(i)*xi + el(i-1)
2726 ! subtract correction terms from yh array. -----------------------------
2729 240 yh(i,j) = yh(i,j) - yh(i,l)*el(j)
2732 ! order increase. ------------------------------------------------------
2733 300 do 310 j = 1, lmax
2741 if (nq .eq. 1) go to 340
2743 ! construct coefficients of x*x*(x+xi(1))*...*(x+xi(j)). ---------------
2745 hsum = hsum + tau(jp1)
2748 alph0 = alph0 - one/real(jp1)
2749 alph1 = alph1 + one/xi
2750 do 320 iback = 1, jp1
2752 320 el(i) = el(i)*xiold + el(i-1)
2756 t1 = (-alph0 - alph1)/prod
2757 ! load column l + 1 in yh array. ---------------------------------------
2760 350 yh(i,lp1) = t1*yh(i,lmax)
2761 ! add correction terms to yh array. ------------------------------------
2764 call daxpy (n, el(j), yh(1,lp1), 1, yh(1,j), 1 )
2767 !----------------------- end of subroutine dvjust ----------------------
2768 end subroutine dvjust
2770 subroutine dvnlsd (y, yh, ldyh, vsav, savf, ewt, acor, iwm, wm, &
2771 f, jac, pdum, nflag, rpar, ipar)
2772 external f, jac, pdum
2773 double precision y, yh, vsav, savf, ewt, acor, wm, rpar
2774 integer ldyh, iwm, nflag, ipar
2775 dimension y(*), yh(ldyh,*), vsav(*), savf(*), ewt(*), acor(*), &
2776 iwm(*), wm(*), rpar(*), ipar(*)
2777 !-----------------------------------------------------------------------
2778 ! call sequence input -- y, yh, ldyh, savf, ewt, acor, iwm, wm,
2779 ! f, jac, nflag, rpar, ipar
2780 ! call sequence output -- yh, acor, wm, iwm, nflag
2781 ! common block variables accessed:
2782 ! /dvod_cmn01/ acnrm, crate, drc, h, rc, rl1, tq(5), tn, icf,
2783 ! jcur, meth, miter, n, nslp
2784 ! /dvod_cmn02/ hu, ncfn, netf, nfe, nje, nlu, nni, nqu, nst
2786 ! subroutines called by dvnlsd: f, daxpy, dcopy, dscal, dvjac, dvsol
2787 ! function routines called by dvnlsd: dvnorm
2788 !-----------------------------------------------------------------------
2789 ! subroutine dvnlsd is a nonlinear system solver, which uses functional
2790 ! iteration or a chord (modified newton) method. for the chord method
2791 ! direct linear algebraic system solvers are used. subroutine dvnlsd
2792 ! then handles the corrector phase of this integration package.
2794 ! communication with dvnlsd is done with the following variables. (for
2795 ! more details, please see the comments in the driver subroutine.)
2797 ! y = the dependent variable, a vector of length n, input.
2798 ! yh = the nordsieck (taylor) array, ldyh by lmax, input
2799 ! and output. on input, it contains predicted values.
2800 ! ldyh = a constant .ge. n, the first dimension of yh, input.
2801 ! vsav = unused work array.
2802 ! savf = a work array of length n.
2803 ! ewt = an error weight vector of length n, input.
2804 ! acor = a work array of length n, used for the accumulated
2805 ! corrections to the predicted y vector.
2806 ! wm,iwm = real and integer work arrays associated with matrix
2807 ! operations in chord iteration (miter .ne. 0).
2808 ! f = dummy name for user supplied routine for f.
2809 ! jac = dummy name for user supplied jacobian routine.
2810 ! pdum = unused dummy subroutine name. included for uniformity
2811 ! over collection of integrators.
2812 ! nflag = input/output flag, with values and meanings as follows:
2814 ! 0 first call for this time step.
2815 ! -1 convergence failure in previous call to dvnlsd.
2816 ! -2 error test failure in dvstep.
2818 ! 0 successful completion of nonlinear solver.
2819 ! -1 convergence failure or singular matrix.
2820 ! -2 unrecoverable error in matrix preprocessing
2821 ! (cannot occur here).
2822 ! -3 unrecoverable error in solution (cannot occur
2824 ! rpar, ipar = dummy names for user's real and integer work arrays.
2826 ! ipup = own variable flag with values and meanings as follows:
2827 ! 0, do not update the newton matrix.
2828 ! miter .ne. 0, update newton matrix, because it is the
2829 ! initial step, order was changed, the error
2830 ! test failed, or an update is indicated by
2831 ! the scalar rc or step counter nst.
2833 ! for more details, see comments in driver subroutine.
2834 !-----------------------------------------------------------------------
2835 ! type declarations for labeled common block dvod_cmn01 --------------------
2837 double precision acnrm, ccmxj, conp, crate, drc, el, &
2838 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
2839 rc, rl1, tau, tq, tn, uround
2840 integer icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
2841 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
2842 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
2843 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
2846 ! type declarations for labeled common block dvod_cmn02 --------------------
2849 integer ncfn, netf, nfe, nje, nlu, nni, nqu, nst
2851 ! type declarations for local variables --------------------------------
2853 double precision ccmax, crdown, cscale, dcon, del, delp, one, &
2855 integer i, ierpj, iersl, m, maxcor, msbp
2857 ! type declaration for function subroutines called ---------------------
2859 ! 27-oct-2005 rce - do not declare functions that are in the module
2860 ! double precision dvnorm
2861 !-----------------------------------------------------------------------
2862 ! the following fortran-77 declaration is to cause the values of the
2863 ! listed (local) variables to be saved between calls to this integrator.
2864 !-----------------------------------------------------------------------
2865 save ccmax, crdown, maxcor, msbp, rdiv, one, two, zero
2867 common /dvod_cmn01/ acnrm, ccmxj, conp, crate, drc, el(13), &
2868 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
2869 rc, rl1, tau(13), tq(5), tn, uround, &
2870 icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
2871 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
2872 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
2873 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
2875 common /dvod_cmn02/ hu, ncfn, netf, nfe, nje, nlu, nni, nqu, nst
2877 data ccmax /0.3d0/, crdown /0.3d0/, maxcor /3/, msbp /20/, &
2879 data one /1.0d0/, two /2.0d0/, zero /0.0d0/
2880 !-----------------------------------------------------------------------
2881 ! on the first step, on a change of method order, or after a
2882 ! nonlinear convergence failure with nflag = -2, set ipup = miter
2883 ! to force a jacobian update when miter .ne. 0.
2884 !-----------------------------------------------------------------------
2885 if (jstart .eq. 0) nslp = 0
2886 if (nflag .eq. 0) icf = 0
2887 if (nflag .eq. -2) ipup = miter
2888 if ( (jstart .eq. 0) .or. (jstart .eq. -1) ) ipup = miter
2889 ! if this is functional iteration, set crate .eq. 1 and drop to 220
2890 if (miter .eq. 0) then
2894 !-----------------------------------------------------------------------
2895 ! rc is the ratio of new to old values of the coefficient h/el(2)=h/l1.
2896 ! when rc differs from 1 by more than ccmax, ipup is set to miter
2897 ! to force dvjac to be called, if a jacobian is involved.
2898 ! in any case, dvjac is called at least every msbp steps.
2899 !-----------------------------------------------------------------------
2901 if (drc .gt. ccmax .or. nst .ge. nslp+msbp) ipup = miter
2902 !-----------------------------------------------------------------------
2903 ! up to maxcor corrector iterations are taken. a convergence test is
2904 ! made on the r.m.s. norm of each correction, weighted by the error
2905 ! weight vector ewt. the sum of the corrections is accumulated in the
2906 ! vector acor(i). the yh array is not altered in the corrector loop.
2907 !-----------------------------------------------------------------------
2910 call dcopy (n, yh(1,1), 1, y, 1 )
2911 call f (n, tn, y, savf, rpar, ipar)
2913 if (ipup .le. 0) go to 250
2914 !-----------------------------------------------------------------------
2915 ! if indicated, the matrix p = i - h*rl1*j is reevaluated and
2916 ! preprocessed before starting the corrector iteration. ipup is set
2917 ! to 0 as an indicator that this has been done.
2918 !-----------------------------------------------------------------------
2919 call dvjac (y, yh, ldyh, ewt, acor, savf, wm, iwm, f, jac, ierpj, &
2926 ! if matrix is singular, take error return to force cut in step size. --
2927 if (ierpj .ne. 0) go to 430
2930 ! this is a looping point for the corrector iteration. -----------------
2931 270 if (miter .ne. 0) go to 350
2932 !-----------------------------------------------------------------------
2933 ! in the case of functional iteration, update y directly from
2934 ! the result of the last function evaluation.
2935 !-----------------------------------------------------------------------
2937 280 savf(i) = rl1*(h*savf(i) - yh(i,2))
2939 290 y(i) = savf(i) - acor(i)
2940 del = dvnorm (n, y, ewt)
2942 300 y(i) = yh(i,1) + savf(i)
2943 call dcopy (n, savf, 1, acor, 1)
2945 !-----------------------------------------------------------------------
2946 ! in the case of the chord method, compute the corrector error,
2947 ! and solve the linear system with that as right-hand side and
2948 ! p as coefficient matrix. the correction is scaled by the factor
2949 ! 2/(1+rc) to account for changes in h*rl1 since the last dvjac call.
2950 !-----------------------------------------------------------------------
2952 360 y(i) = (rl1*h)*savf(i) - (rl1*yh(i,2) + acor(i))
2953 call dvsol (wm, iwm, y, iersl)
2955 if (iersl .gt. 0) go to 410
2956 if (meth .eq. 2 .and. rc .ne. one) then
2957 cscale = two/(one + rc)
2958 call dscal (n, cscale, y, 1)
2960 del = dvnorm (n, y, ewt)
2961 call daxpy (n, one, y, 1, acor, 1)
2963 380 y(i) = yh(i,1) + acor(i)
2964 !-----------------------------------------------------------------------
2965 ! test for convergence. if m .gt. 0, an estimate of the convergence
2966 ! rate constant is stored in crate, and this is used in the test.
2967 !-----------------------------------------------------------------------
2968 400 if (m .ne. 0) crate = max(crdown*crate,del/delp)
2969 dcon = del*min(one,crate)/tq(4)
2970 if (dcon .le. one) go to 450
2972 if (m .eq. maxcor) go to 410
2973 if (m .ge. 2 .and. del .gt. rdiv*delp) go to 410
2975 call f (n, tn, y, savf, rpar, ipar)
2979 410 if (miter .eq. 0 .or. jcur .eq. 1) go to 430
2990 ! return for successful step. ------------------------------------------
2994 if (m .eq. 0) acnrm = del
2995 if (m .gt. 0) acnrm = dvnorm (n, acor, ewt)
2997 !----------------------- end of subroutine dvnlsd ----------------------
2998 end subroutine dvnlsd
3000 subroutine dvjac (y, yh, ldyh, ewt, ftem, savf, wm, iwm, f, jac, &
3003 double precision y, yh, ewt, ftem, savf, wm, rpar
3004 integer ldyh, iwm, ierpj, ipar
3005 dimension y(*), yh(ldyh,*), ewt(*), ftem(*), savf(*), &
3006 wm(*), iwm(*), rpar(*), ipar(*)
3007 !-----------------------------------------------------------------------
3008 ! call sequence input -- y, yh, ldyh, ewt, ftem, savf, wm, iwm,
3009 ! f, jac, rpar, ipar
3010 ! call sequence output -- wm, iwm, ierpj
3011 ! common block variables accessed:
3012 ! /dvod_cmn01/ ccmxj, drc, h, rl1, tn, uround, icf, jcur, locjs,
3013 ! miter, msbj, n, nslj
3014 ! /dvod_cmn02/ nfe, nst, nje, nlu
3016 ! subroutines called by dvjac: f, jac, dacopy, dcopy, dgbfa, dgefa,
3018 ! function routines called by dvjac: dvnorm
3019 !-----------------------------------------------------------------------
3020 ! dvjac is called by dvnlsd to compute and process the matrix
3021 ! p = i - h*rl1*j , where j is an approximation to the jacobian.
3022 ! here j is computed by the user-supplied routine jac if
3023 ! miter = 1 or 4, or by finite differencing if miter = 2, 3, or 5.
3024 ! if miter = 3, a diagonal approximation to j is used.
3025 ! if jsv = -1, j is computed from scratch in all cases.
3026 ! if jsv = 1 and miter = 1, 2, 4, or 5, and if the saved value of j is
3027 ! considered acceptable, then p is constructed from the saved j.
3028 ! j is stored in wm and replaced by p. if miter .ne. 3, p is then
3029 ! subjected to lu decomposition in preparation for later solution
3030 ! of linear systems with p as coefficient matrix. this is done
3031 ! by dgefa if miter = 1 or 2, and by dgbfa if miter = 4 or 5.
3033 ! communication with dvjac is done with the following variables. (for
3034 ! more details, please see the comments in the driver subroutine.)
3035 ! y = vector containing predicted values on entry.
3036 ! yh = the nordsieck array, an ldyh by lmax array, input.
3037 ! ldyh = a constant .ge. n, the first dimension of yh, input.
3038 ! ewt = an error weight vector of length n.
3039 ! savf = array containing f evaluated at predicted y, input.
3040 ! wm = real work space for matrices. in the output, it contains
3041 ! the inverse diagonal matrix if miter = 3 and the lu
3042 ! decomposition of p if miter is 1, 2 , 4, or 5.
3043 ! storage of matrix elements starts at wm(3).
3044 ! storage of the saved jacobian starts at wm(locjs).
3045 ! wm also contains the following matrix-related data:
3046 ! wm(1) = sqrt(uround), used in numerical jacobian step.
3047 ! wm(2) = h*rl1, saved for later use if miter = 3.
3048 ! iwm = integer work space containing pivot information,
3049 ! starting at iwm(31), if miter is 1, 2, 4, or 5.
3050 ! iwm also contains band parameters ml = iwm(1) and
3051 ! mu = iwm(2) if miter is 4 or 5.
3052 ! f = dummy name for the user supplied subroutine for f.
3053 ! jac = dummy name for the user supplied jacobian subroutine.
3054 ! rpar, ipar = dummy names for user's real and integer work arrays.
3055 ! rl1 = 1/el(2) (input).
3056 ! ierpj = output error flag, = 0 if no trouble, 1 if the p
3057 ! matrix is found to be singular.
3058 ! jcur = output flag to indicate whether the jacobian matrix
3059 ! (or approximation) is now current.
3060 ! jcur = 0 means j is not current.
3061 ! jcur = 1 means j is current.
3062 !-----------------------------------------------------------------------
3064 ! type declarations for labeled common block dvod_cmn01 --------------------
3066 double precision acnrm, ccmxj, conp, crate, drc, el, &
3067 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
3068 rc, rl1, tau, tq, tn, uround
3069 integer icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
3070 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
3071 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
3072 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
3075 ! type declarations for labeled common block dvod_cmn02 --------------------
3078 integer ncfn, netf, nfe, nje, nlu, nni, nqu, nst
3080 ! type declarations for local variables --------------------------------
3082 double precision con, di, fac, hrl1, one, pt1, r, r0, srur, thou, &
3084 integer i, i1, i2, ier, ii, j, j1, jj, jok, lenp, mba, mband, &
3085 meb1, meband, ml, ml3, mu, np1
3087 ! type declaration for function subroutines called ---------------------
3089 ! 27-oct-2005 rce - do not declare functions that are in the module
3090 ! double precision dvnorm
3091 !-----------------------------------------------------------------------
3092 ! the following fortran-77 declaration is to cause the values of the
3093 ! listed (local) variables to be saved between calls to this subroutine.
3094 !-----------------------------------------------------------------------
3095 save one, pt1, thou, zero
3096 !-----------------------------------------------------------------------
3097 common /dvod_cmn01/ acnrm, ccmxj, conp, crate, drc, el(13), &
3098 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
3099 rc, rl1, tau(13), tq(5), tn, uround, &
3100 icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
3101 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
3102 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
3103 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
3105 common /dvod_cmn02/ hu, ncfn, netf, nfe, nje, nlu, nni, nqu, nst
3107 data one /1.0d0/, thou /1000.0d0/, zero /0.0d0/, pt1 /0.1d0/
3111 ! see whether j should be evaluated (jok = -1) or not (jok = 1). -------
3113 if (jsv .eq. 1) then
3114 if (nst .eq. 0 .or. nst .gt. nslj+msbj) jok = -1
3115 if (icf .eq. 1 .and. drc .lt. ccmxj) jok = -1
3116 if (icf .eq. 2) jok = -1
3118 ! end of setting jok. --------------------------------------------------
3120 if (jok .eq. -1 .and. miter .eq. 1) then
3121 ! if jok = -1 and miter = 1, call jac to evaluate jacobian. ------------
3128 call jac (n, tn, y, 0, 0, wm(3), n, rpar, ipar)
3129 if (jsv .eq. 1) call dcopy (lenp, wm(3), 1, wm(locjs), 1)
3132 if (jok .eq. -1 .and. miter .eq. 2) then
3133 ! if miter = 2, make n calls to f to approximate the jacobian. ---------
3137 fac = dvnorm (n, savf, ewt)
3138 r0 = thou*abs(h)*uround*real(n)*fac
3139 if (r0 .eq. zero) r0 = one
3144 r = max(srur*abs(yj),r0/ewt(j))
3147 call f (n, tn, y, ftem, rpar, ipar)
3149 220 wm(i+j1) = (ftem(i) - savf(i))*fac
3155 if (jsv .eq. 1) call dcopy (lenp, wm(3), 1, wm(locjs), 1)
3158 if (jok .eq. 1 .and. (miter .eq. 1 .or. miter .eq. 2)) then
3161 call dcopy (lenp, wm(locjs), 1, wm(3), 1)
3164 if (miter .eq. 1 .or. miter .eq. 2) then
3165 ! multiply jacobian by scalar, add identity, and do lu decomposition. --
3167 call dscal (lenp, con, wm(3), 1)
3174 call dgefa (wm(3), n, n, iwm(31), ier)
3175 if (ier .ne. 0) ierpj = 1
3178 ! end of code block for miter = 1 or 2. --------------------------------
3180 if (miter .eq. 3) then
3181 ! if miter = 3, construct a diagonal approximation to j and p. ---------
3187 310 y(i) = y(i) + r*(h*savf(i) - yh(i,2))
3188 call f (n, tn, y, wm(3), rpar, ipar)
3191 r0 = h*savf(i) - yh(i,2)
3192 di = pt1*r0 - h*(wm(i+2) - savf(i))
3194 if (abs(r0) .lt. uround/ewt(i)) go to 320
3195 if (abs(di) .eq. zero) go to 330
3202 ! end of code block for miter = 3. -------------------------------------
3204 ! set constants for miter = 4 or 5. ------------------------------------
3212 if (jok .eq. -1 .and. miter .eq. 4) then
3213 ! if jok = -1 and miter = 4, call jac to evaluate jacobian. ------------
3219 call jac (n, tn, y, ml, mu, wm(ml3), meband, rpar, ipar)
3221 call dacopy (mband, n, wm(ml3), meband, wm(locjs), mband)
3224 if (jok .eq. -1 .and. miter .eq. 5) then
3225 ! if miter = 5, make ml+mu+1 calls to f to approximate the jacobian. ---
3232 fac = dvnorm (n, savf, ewt)
3233 r0 = thou*abs(h)*uround*real(n)*fac
3234 if (r0 .eq. zero) r0 = one
3236 do 530 i = j,n,mband
3238 r = max(srur*abs(yi),r0/ewt(i))
3240 call f (n, tn, y, ftem, rpar, ipar)
3241 do 550 jj = j,n,mband
3244 r = max(srur*abs(yjj),r0/ewt(jj))
3248 ii = jj*meb1 - ml + 2
3250 540 wm(ii+i) = (ftem(i) - savf(i))*fac
3255 call dacopy (mband, n, wm(ml3), meband, wm(locjs), mband)
3258 if (jok .eq. 1) then
3260 call dacopy (mband, n, wm(locjs), mband, wm(ml3), meband)
3263 ! multiply jacobian by scalar, add identity, and do lu decomposition.
3265 call dscal (lenp, con, wm(3), 1 )
3268 wm(ii) = wm(ii) + one
3269 580 ii = ii + meband
3271 call dgbfa (wm(3), meband, n, ml, mu, iwm(31), ier)
3272 if (ier .ne. 0) ierpj = 1
3274 ! end of code block for miter = 4 or 5. --------------------------------
3276 !----------------------- end of subroutine dvjac -----------------------
3277 end subroutine dvjac
3279 subroutine dacopy (nrow, ncol, a, nrowa, b, nrowb)
3280 double precision a, b
3281 integer nrow, ncol, nrowa, nrowb
3282 dimension a(nrowa,ncol), b(nrowb,ncol)
3283 !-----------------------------------------------------------------------
3284 ! call sequence input -- nrow, ncol, a, nrowa, nrowb
3285 ! call sequence output -- b
3286 ! common block variables accessed -- none
3288 ! subroutines called by dacopy: dcopy
3289 ! function routines called by dacopy: none
3290 !-----------------------------------------------------------------------
3291 ! this routine copies one rectangular array, a, to another, b,
3292 ! where a and b may have different row dimensions, nrowa and nrowb.
3293 ! the data copied consists of nrow rows and ncol columns.
3294 !-----------------------------------------------------------------------
3298 call dcopy (nrow, a(1,ic), 1, b(1,ic), 1)
3302 !----------------------- end of subroutine dacopy ----------------------
3303 end subroutine dacopy
3305 subroutine dvsol (wm, iwm, x, iersl)
3306 double precision wm, x
3308 dimension wm(*), iwm(*), x(*)
3309 !-----------------------------------------------------------------------
3310 ! call sequence input -- wm, iwm, x
3311 ! call sequence output -- x, iersl
3312 ! common block variables accessed:
3313 ! /dvod_cmn01/ -- h, rl1, miter, n
3315 ! subroutines called by dvsol: dgesl, dgbsl
3316 ! function routines called by dvsol: none
3317 !-----------------------------------------------------------------------
3318 ! this routine manages the solution of the linear system arising from
3319 ! a chord iteration. it is called if miter .ne. 0.
3320 ! if miter is 1 or 2, it calls dgesl to accomplish this.
3321 ! if miter = 3 it updates the coefficient h*rl1 in the diagonal
3322 ! matrix, and then computes the solution.
3323 ! if miter is 4 or 5, it calls dgbsl.
3324 ! communication with dvsol uses the following variables:
3325 ! wm = real work space containing the inverse diagonal matrix if
3326 ! miter = 3 and the lu decomposition of the matrix otherwise.
3327 ! storage of matrix elements starts at wm(3).
3328 ! wm also contains the following matrix-related data:
3329 ! wm(1) = sqrt(uround) (not used here),
3330 ! wm(2) = hrl1, the previous value of h*rl1, used if miter = 3.
3331 ! iwm = integer work space containing pivot information, starting at
3332 ! iwm(31), if miter is 1, 2, 4, or 5. iwm also contains band
3333 ! parameters ml = iwm(1) and mu = iwm(2) if miter is 4 or 5.
3334 ! x = the right-hand side vector on input, and the solution vector
3335 ! on output, of length n.
3336 ! iersl = output flag. iersl = 0 if no trouble occurred.
3337 ! iersl = 1 if a singular matrix arose with miter = 3.
3338 !-----------------------------------------------------------------------
3340 ! type declarations for labeled common block dvod_cmn01 --------------------
3342 double precision acnrm, ccmxj, conp, crate, drc, el, &
3343 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
3344 rc, rl1, tau, tq, tn, uround
3345 integer icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
3346 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
3347 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
3348 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
3351 ! type declarations for local variables --------------------------------
3353 integer i, meband, ml, mu
3354 double precision di, hrl1, one, phrl1, r, zero
3355 !-----------------------------------------------------------------------
3356 ! the following fortran-77 declaration is to cause the values of the
3357 ! listed (local) variables to be saved between calls to this integrator.
3358 !-----------------------------------------------------------------------
3361 common /dvod_cmn01/ acnrm, ccmxj, conp, crate, drc, el(13), &
3362 eta, etamax, h, hmin, hmxi, hnew, hscal, prl1, &
3363 rc, rl1, tau(13), tq(5), tn, uround, &
3364 icf, init, ipup, jcur, jstart, jsv, kflag, kuth, &
3365 l, lmax, lyh, lewt, lacor, lsavf, lwm, liwm, &
3366 locjs, maxord, meth, miter, msbj, mxhnil, mxstep, &
3367 n, newh, newq, nhnil, nq, nqnyh, nqwait, nslj, &
3370 data one /1.0d0/, zero /0.0d0/
3373 go to (100, 100, 300, 400, 400), miter
3374 100 call dgesl (wm(3), n, n, iwm(31), x, 0)
3380 if (hrl1 .eq. phrl1) go to 330
3383 di = one - r*(one - one/wm(i+2))
3384 if (abs(di) .eq. zero) go to 390
3385 320 wm(i+2) = one/di
3388 340 x(i) = wm(i+2)*x(i)
3395 meband = 2*ml + mu + 1
3396 call dgbsl (wm(3), meband, n, ml, mu, iwm(31), x, 0)
3398 !----------------------- end of subroutine dvsol -----------------------
3399 end subroutine dvsol
3401 subroutine dvsrco (rsav, isav, job)
3402 double precision rsav
3404 dimension rsav(*), isav(*)
3405 !-----------------------------------------------------------------------
3406 ! call sequence input -- rsav, isav, job
3407 ! call sequence output -- rsav, isav
3408 ! common block variables accessed -- all of /dvod_cmn01/ and /dvod_cmn02/
3410 ! subroutines/functions called by dvsrco: none
3411 !-----------------------------------------------------------------------
3412 ! this routine saves or restores (depending on job) the contents of the
3413 ! common blocks dvod_cmn01 and dvod_cmn02, which are used internally by dvode.
3415 ! rsav = real array of length 49 or more.
3416 ! isav = integer array of length 41 or more.
3417 ! job = flag indicating to save or restore the common blocks:
3418 ! job = 1 if common is to be saved (written to rsav/isav).
3419 ! job = 2 if common is to be restored (read from rsav/isav).
3420 ! a call with job = 2 presumes a prior call with job = 1.
3421 !-----------------------------------------------------------------------
3422 double precision rvod1, rvod2
3423 integer ivod1, ivod2
3424 integer i, leniv1, leniv2, lenrv1, lenrv2
3425 !-----------------------------------------------------------------------
3426 ! the following fortran-77 declaration is to cause the values of the
3427 ! listed (local) variables to be saved between calls to this integrator.
3428 !-----------------------------------------------------------------------
3429 save lenrv1, leniv1, lenrv2, leniv2
3431 common /dvod_cmn01/ rvod1(48), ivod1(33)
3432 common /dvod_cmn02/ rvod2(1), ivod2(8)
3433 data lenrv1/48/, leniv1/33/, lenrv2/1/, leniv2/8/
3435 if (job .eq. 2) go to 100
3437 10 rsav(i) = rvod1(i)
3439 15 rsav(lenrv1+i) = rvod2(i)
3442 20 isav(i) = ivod1(i)
3444 25 isav(leniv1+i) = ivod2(i)
3450 110 rvod1(i) = rsav(i)
3452 115 rvod2(i) = rsav(lenrv1+i)
3455 120 ivod1(i) = isav(i)
3457 125 ivod2(i) = isav(leniv1+i)
3460 !----------------------- end of subroutine dvsrco ----------------------
3461 end subroutine dvsrco
3463 subroutine dewset (n, itol, rtol, atol, ycur, ewt)
3464 !***begin prologue dewset
3466 !***purpose set error weight vector.
3467 !***type double precision (sewset-s, dewset-d)
3468 !***author hindmarsh, alan c., (llnl)
3471 ! this subroutine sets the error weight vector ewt according to
3472 ! ewt(i) = rtol(i)*abs(ycur(i)) + atol(i), i = 1,...,n,
3473 ! with the subscript on rtol and/or atol possibly replaced by 1 above,
3474 ! depending on the value of itol.
3477 !***routines called (none)
3478 !***revision history (yymmdd)
3479 ! 791129 date written
3480 ! 890501 modified prologue to slatec/ldoc format. (fnf)
3481 ! 890503 minor cosmetic changes. (fnf)
3482 ! 930809 renamed to allow single/double precision versions. (ach)
3483 !***end prologue dewset
3487 double precision rtol, atol, ycur, ewt
3488 dimension rtol(*), atol(*), ycur(n), ewt(n)
3490 !***first executable statement dewset
3491 go to (10, 20, 30, 40), itol
3494 15 ewt(i) = rtol(1)*abs(ycur(i)) + atol(1)
3498 25 ewt(i) = rtol(1)*abs(ycur(i)) + atol(i)
3502 35 ewt(i) = rtol(i)*abs(ycur(i)) + atol(1)
3506 45 ewt(i) = rtol(i)*abs(ycur(i)) + atol(i)
3508 !----------------------- end of subroutine dewset ----------------------
3509 end subroutine dewset
3511 double precision function dvnorm (n, v, w)
3512 !***begin prologue dvnorm
3514 !***purpose weighted root-mean-square vector norm.
3515 !***type double precision (svnorm-s, dvnorm-d)
3516 !***author hindmarsh, alan c., (llnl)
3519 ! this function routine computes the weighted root-mean-square norm
3520 ! of the vector of length n contained in the array v, with weights
3521 ! contained in the array w of length n:
3522 ! dvnorm = sqrt( (1/n) * sum( v(i)*w(i) )**2 )
3525 !***routines called (none)
3526 !***revision history (yymmdd)
3527 ! 791129 date written
3528 ! 890501 modified prologue to slatec/ldoc format. (fnf)
3529 ! 890503 minor cosmetic changes. (fnf)
3530 ! 930809 renamed to allow single/double precision versions. (ach)
3531 !***end prologue dvnorm
3534 double precision v, w, sum
3535 dimension v(n), w(n)
3537 !***first executable statement dvnorm
3540 10 sum = sum + (v(i)*w(i))**2
3541 dvnorm = sqrt(sum/n)
3543 !----------------------- end of function dvnorm ------------------------
3546 subroutine xerrwd (msg, nmes, nerr, level, ni, i1, i2, nr, r1, r2)
3547 !***begin prologue xerrwd
3549 !***purpose write error message with values.
3551 !***type double precision (xerrwv-s, xerrwd-d)
3552 !***author hindmarsh, alan c., (llnl)
3555 ! subroutines xerrwd, xsetf, xsetun, and the function routine ixsav,
3556 ! as given here, constitute a simplified version of the slatec error
3559 ! all arguments are input arguments.
3561 ! msg = the message (character array).
3562 ! nmes = the length of msg (number of characters).
3563 ! nerr = the error number (not used).
3564 ! level = the error level..
3565 ! 0 or 1 means recoverable (control returns to caller).
3566 ! 2 means fatal (run is aborted--see note below).
3567 ! ni = number of integers (0, 1, or 2) to be printed with message.
3568 ! i1,i2 = integers to be printed, depending on ni.
3569 ! nr = number of reals (0, 1, or 2) to be printed with message.
3570 ! r1,r2 = reals to be printed, depending on nr.
3572 ! note.. this routine is machine-dependent and specialized for use
3573 ! in limited context, in the following ways..
3574 ! 1. the argument msg is assumed to be of type character, and
3575 ! the message is printed with a format of (1x,a).
3576 ! 2. the message is assumed to take only one line.
3577 ! multi-line messages are generated by repeated calls.
3578 ! 3. if level = 2, control passes to the statement stop
3579 ! to abort the run. this statement may be machine-dependent.
3580 ! 4. r1 and r2 are assumed to be in double precision and are printed
3583 !***routines called ixsav
3584 !***revision history (yymmdd)
3585 ! 920831 date written
3586 ! 921118 replaced mflgsv/lunsav by ixsav. (ach)
3587 ! 930329 modified prologue to slatec format. (fnf)
3588 ! 930407 changed msg from character*1 array to variable. (fnf)
3589 ! 930922 minor cosmetic change. (fnf)
3590 !***end prologue xerrwd
3594 ! for a different default logical unit number, ixsav (or a subsidiary
3595 ! routine that it calls) will need to be modified.
3596 ! for a different run-abort command, change the statement following
3597 ! statement 100 at the end.
3598 !-----------------------------------------------------------------------
3599 ! subroutines called by xerrwd.. none
3600 ! function routine called by xerrwd.. ixsav
3601 !-----------------------------------------------------------------------
3604 ! declare arguments.
3606 double precision r1, r2
3607 integer nmes, nerr, level, ni, i1, i2, nr
3610 ! declare local variables.
3612 ! 27-oct-2005 rce - do not declare functions that are in the module
3613 ! integer lunit, ixsav, mesflg
3614 integer lunit, mesflg
3616 ! get logical unit number and message print flag.
3618 !***first executable statement xerrwd
3619 lunit = ixsav (1, 0, .false.)
3620 mesflg = ixsav (2, 0, .false.)
3621 if (mesflg .eq. 0) go to 100
3623 ! write the message.
3625 write (lunit,10) msg
3627 if (ni .eq. 1) write (lunit, 20) i1
3628 20 format(6x,'in above message, i1 =',i10)
3629 if (ni .eq. 2) write (lunit, 30) i1,i2
3630 30 format(6x,'in above message, i1 =',i10,3x,'i2 =',i10)
3631 if (nr .eq. 1) write (lunit, 40) r1
3632 40 format(6x,'in above message, r1 =',d21.13)
3633 if (nr .eq. 2) write (lunit, 50) r1,r2
3634 50 format(6x,'in above, r1 =',d21.13,3x,'r2 =',d21.13)
3636 ! abort the run if level = 2.
3638 100 if (level .ne. 2) return
3640 !----------------------- end of subroutine xerrwd ----------------------
3641 end subroutine xerrwd
3643 subroutine xsetf (mflag)
3644 !***begin prologue xsetf
3645 !***purpose reset the error print control flag.
3647 !***type all (xsetf-a)
3648 !***keywords error control
3649 !***author hindmarsh, alan c., (llnl)
3652 ! xsetf sets the error print control flag to mflag:
3653 ! mflag=1 means print all messages (the default).
3654 ! mflag=0 means no printing.
3656 !***see also xerrwd, xerrwv
3657 !***references (none)
3658 !***routines called ixsav
3659 !***revision history (yymmdd)
3660 ! 921118 date written
3661 ! 930329 added slatec format prologue. (fnf)
3662 ! 930407 corrected see also section. (fnf)
3663 ! 930922 made user-callable, and other cosmetic changes. (fnf)
3664 !***end prologue xsetf
3666 ! subroutines called by xsetf.. none
3667 ! function routine called by xsetf.. ixsav
3668 !-----------------------------------------------------------------------
3670 ! 27-oct-2005 rce - do not declare functions that are in the module
3671 ! integer mflag, junk, ixsav
3674 !***first executable statement xsetf
3675 if (mflag .eq. 0 .or. mflag .eq. 1) junk = ixsav (2,mflag,.true.)
3677 !----------------------- end of subroutine xsetf -----------------------
3678 end subroutine xsetf
3680 subroutine xsetun (lun)
3681 !***begin prologue xsetun
3682 !***purpose reset the logical unit number for error messages.
3684 !***type all (xsetun-a)
3685 !***keywords error control
3688 ! xsetun sets the logical unit number for error messages to lun.
3690 !***author hindmarsh, alan c., (llnl)
3691 !***see also xerrwd, xerrwv
3692 !***references (none)
3693 !***routines called ixsav
3694 !***revision history (yymmdd)
3695 ! 921118 date written
3696 ! 930329 added slatec format prologue. (fnf)
3697 ! 930407 corrected see also section. (fnf)
3698 ! 930922 made user-callable, and other cosmetic changes. (fnf)
3699 !***end prologue xsetun
3701 ! subroutines called by xsetun.. none
3702 ! function routine called by xsetun.. ixsav
3703 !-----------------------------------------------------------------------
3705 ! 27-oct-2005 rce - do not declare functions that are in the module
3706 ! integer lun, junk, ixsav
3709 !***first executable statement xsetun
3710 if (lun .gt. 0) junk = ixsav (1,lun,.true.)
3712 !----------------------- end of subroutine xsetun ----------------------
3713 end subroutine xsetun
3715 integer function ixsav (ipar, ivalue, iset)
3716 !***begin prologue ixsav
3718 !***purpose save and recall error message control parameters.
3720 !***type all (ixsav-a)
3721 !***author hindmarsh, alan c., (llnl)
3724 ! ixsav saves and recalls one of two error message parameters:
3725 ! lunit, the logical unit number to which messages are printed, and
3726 ! mesflg, the message print flag.
3727 ! this is a modification of the slatec library routine j4save.
3729 ! saved local variables..
3730 ! lunit = logical unit number for messages. the default is obtained
3731 ! by a call to iumach (may be machine-dependent).
3732 ! mesflg = print control flag..
3733 ! 1 means print all messages (the default).
3734 ! 0 means no printing.
3737 ! ipar = parameter indicator (1 for lunit, 2 for mesflg).
3738 ! ivalue = the value to be set for the parameter, if iset = .true.
3739 ! iset = logical flag to indicate whether to read or write.
3740 ! if iset = .true., the parameter will be given
3741 ! the value ivalue. if iset = .false., the parameter
3742 ! will be unchanged, and ivalue is a dummy argument.
3745 ! ixsav = the (old) value of the parameter.
3747 !***see also xerrwd, xerrwv
3748 !***routines called iumach
3749 !***revision history (yymmdd)
3750 ! 921118 date written
3751 ! 930329 modified prologue to slatec format. (fnf)
3752 ! 930915 added iumach call to get default output unit. (ach)
3753 ! 930922 minor cosmetic changes. (fnf)
3754 ! 010425 type declaration for iumach added. (ach)
3755 !***end prologue ixsav
3757 ! subroutines called by ixsav.. none
3758 ! function routine called by ixsav.. iumach
3759 !-----------------------------------------------------------------------
3762 integer ipar, ivalue
3763 !-----------------------------------------------------------------------
3764 ! 27-oct-2005 rce - do not declare functions that are in the module
3765 ! integer iumach, lunit, mesflg
3766 integer lunit, mesflg
3767 !-----------------------------------------------------------------------
3768 ! the following fortran-77 declaration is to cause the values of the
3769 ! listed (local) variables to be saved between calls to this routine.
3770 !-----------------------------------------------------------------------
3772 data lunit/-1/, mesflg/1/
3774 !***first executable statement ixsav
3775 if (ipar .eq. 1) then
3776 if (lunit .eq. -1) lunit = iumach()
3778 if (iset) lunit = ivalue
3781 if (ipar .eq. 2) then
3783 if (iset) mesflg = ivalue
3787 !----------------------- end of function ixsav -------------------------
3790 integer function iumach()
3791 !***begin prologue iumach
3792 !***purpose provide standard output unit number.
3794 !***type integer (iumach-i)
3795 !***keywords machine constants
3796 !***author hindmarsh, alan c., (llnl)
3799 ! integer lout, iumach
3802 ! *function return values:
3803 ! lout : the standard logical unit for fortran output.
3805 !***references (none)
3806 !***routines called (none)
3807 !***revision history (yymmdd)
3808 ! 930915 date written
3809 ! 930922 made user-callable, and other cosmetic changes. (fnf)
3810 !***end prologue iumach
3813 ! the built-in value of 6 is standard on a wide range of fortran
3814 ! systems. this may be machine-dependent.
3816 !***first executable statement iumach
3820 !----------------------- end of function iumach ------------------------
3823 double precision function dumach ()
3824 !***begin prologue dumach
3825 !***purpose compute the unit roundoff of the machine.
3827 !***type double precision (rumach-s, dumach-d)
3828 !***keywords machine constants
3829 !***author hindmarsh, alan c., (llnl)
3832 ! double precision a, dumach
3835 ! *function return values:
3836 ! a : the unit roundoff of the machine.
3839 ! the unit roundoff is defined as the smallest positive machine
3840 ! number u such that 1.0 + u .ne. 1.0. this is computed by dumach
3841 ! in a machine-independent manner.
3843 !***references (none)
3844 !***routines called dumsum
3845 !***revision history (yyyymmdd)
3846 ! 19930216 date written
3847 ! 19930818 added slatec-format prologue. (fnf)
3848 ! 20030707 added dumsum to force normal storage of comp. (ach)
3849 !***end prologue dumach
3851 double precision u, comp
3852 !***first executable statement dumach
3855 call dumsum(1.0d0, u, comp)
3856 if (comp .ne. 1.0d0) go to 10
3859 !----------------------- end of function dumach ------------------------
3861 subroutine dumsum(a,b,c)
3862 ! routine to force normal storing of a + b, for dumach.
3863 double precision a, b, c
3866 end subroutine dumsum
3868 !-----------------------------------------------------------------------
3869 ! vode_subs.f - created on 28-jul-2004
3870 ! by downloading following from www.netlib.org
3871 ! 1. daxpy, dcopy, ddot, dnrm2, dscal, idamax from blas
3872 ! 2. dgbfa, dbgsl, dgefa, dgesl from linpack
3874 ! 27-oct-2005 rce - change '1' dimensions in subr dgefa & dgesl
3875 !-----------------------------------------------------------------------
3878 !-----------------------------------------------------------------------
3879 subroutine daxpy(n,da,dx,incx,dy,incy)
3881 ! constant times a vector plus a vector.
3882 ! uses unrolled loops for increments equal to one.
3883 ! jack dongarra, linpack, 3/11/78.
3884 ! modified 12/3/93, array(1) declarations changed to array(*)
3886 double precision dx(*),dy(*),da
3887 integer i,incx,incy,ix,iy,m,mp1,n
3890 if (da .eq. 0.0d0) return
3891 if(incx.eq.1.and.incy.eq.1)go to 20
3893 ! code for unequal increments or equal increments
3898 if(incx.lt.0)ix = (-n+1)*incx + 1
3899 if(incy.lt.0)iy = (-n+1)*incy + 1
3901 dy(iy) = dy(iy) + da*dx(ix)
3907 ! code for both increments equal to 1
3913 if( m .eq. 0 ) go to 40
3915 dy(i) = dy(i) + da*dx(i)
3917 if( n .lt. 4 ) return
3920 dy(i) = dy(i) + da*dx(i)
3921 dy(i + 1) = dy(i + 1) + da*dx(i + 1)
3922 dy(i + 2) = dy(i + 2) + da*dx(i + 2)
3923 dy(i + 3) = dy(i + 3) + da*dx(i + 3)
3926 end subroutine daxpy
3929 !-----------------------------------------------------------------------
3930 subroutine dcopy(n,dx,incx,dy,incy)
3932 ! copies a vector, x, to a vector, y.
3933 ! uses unrolled loops for increments equal to one.
3934 ! jack dongarra, linpack, 3/11/78.
3935 ! modified 12/3/93, array(1) declarations changed to array(*)
3937 double precision dx(*),dy(*)
3938 integer i,incx,incy,ix,iy,m,mp1,n
3941 if(incx.eq.1.and.incy.eq.1)go to 20
3943 ! code for unequal increments or equal increments
3948 if(incx.lt.0)ix = (-n+1)*incx + 1
3949 if(incy.lt.0)iy = (-n+1)*incy + 1
3957 ! code for both increments equal to 1
3963 if( m .eq. 0 ) go to 40
3967 if( n .lt. 7 ) return
3971 dy(i + 1) = dx(i + 1)
3972 dy(i + 2) = dx(i + 2)
3973 dy(i + 3) = dx(i + 3)
3974 dy(i + 4) = dx(i + 4)
3975 dy(i + 5) = dx(i + 5)
3976 dy(i + 6) = dx(i + 6)
3979 end subroutine dcopy
3982 double precision function ddot(n,dx,incx,dy,incy)
3984 ! forms the dot product of two vectors.
3985 ! uses unrolled loops for increments equal to one.
3986 ! jack dongarra, linpack, 3/11/78.
3987 ! modified 12/3/93, array(1) declarations changed to array(*)
3989 double precision dx(*),dy(*),dtemp
3990 integer i,incx,incy,ix,iy,m,mp1,n
3995 if(incx.eq.1.and.incy.eq.1)go to 20
3997 ! code for unequal increments or equal increments
4002 if(incx.lt.0)ix = (-n+1)*incx + 1
4003 if(incy.lt.0)iy = (-n+1)*incy + 1
4005 dtemp = dtemp + dx(ix)*dy(iy)
4012 ! code for both increments equal to 1
4018 if( m .eq. 0 ) go to 40
4020 dtemp = dtemp + dx(i)*dy(i)
4022 if( n .lt. 5 ) go to 60
4025 dtemp = dtemp + dx(i)*dy(i) + dx(i + 1)*dy(i + 1) + &
4026 dx(i + 2)*dy(i + 2) + dx(i + 3)*dy(i + 3) + dx(i + 4)*dy(i + 4)
4033 !-----------------------------------------------------------------------
4034 double precision function dnrm2 ( n, x, incx )
4035 ! .. scalar arguments ..
4037 ! .. array arguments ..
4038 double precision x( * )
4041 ! dnrm2 returns the euclidean norm of a vector via the function
4044 ! dnrm2 := sqrt( x'*x )
4048 ! -- this version written on 25-october-1982.
4049 ! modified on 14-october-1993 to inline the call to dlassq.
4050 ! sven hammarling, nag ltd.
4054 double precision one , zero
4055 parameter ( one = 1.0d+0, zero = 0.0d+0 )
4056 ! .. local scalars ..
4058 double precision absxi, norm, scale, ssq
4059 ! .. intrinsic functions ..
4062 ! .. executable statements ..
4063 if( n.lt.1 .or. incx.lt.1 )then
4065 else if( n.eq.1 )then
4066 norm = abs( x( 1 ) )
4070 ! the following loop is equivalent to this call to the lapack
4071 ! auxiliary routine:
4072 ! call dlassq( n, x, incx, scale, ssq )
4074 do 10, ix = 1, 1 + ( n - 1 )*incx, incx
4075 if( x( ix ).ne.zero )then
4076 absxi = abs( x( ix ) )
4077 if( scale.lt.absxi )then
4078 ssq = one + ssq*( scale/absxi )**2
4081 ssq = ssq + ( absxi/scale )**2
4085 norm = scale * sqrt( ssq )
4096 !-----------------------------------------------------------------------
4097 subroutine dscal(n,da,dx,incx)
4099 ! scales a vector by a constant.
4100 ! uses unrolled loops for increment equal to one.
4101 ! jack dongarra, linpack, 3/11/78.
4102 ! modified 3/93 to return if incx .le. 0.
4103 ! modified 12/3/93, array(1) declarations changed to array(*)
4105 double precision da,dx(*)
4106 integer i,incx,m,mp1,n,nincx
4108 if( n.le.0 .or. incx.le.0 )return
4109 if(incx.eq.1)go to 20
4111 ! code for increment not equal to 1
4114 do 10 i = 1,nincx,incx
4119 ! code for increment equal to 1
4125 if( m .eq. 0 ) go to 40
4129 if( n .lt. 5 ) return
4133 dx(i + 1) = da*dx(i + 1)
4134 dx(i + 2) = da*dx(i + 2)
4135 dx(i + 3) = da*dx(i + 3)
4136 dx(i + 4) = da*dx(i + 4)
4139 end subroutine dscal
4142 !-----------------------------------------------------------------------
4143 integer function idamax(n,dx,incx)
4145 ! finds the index of element having max. absolute value.
4146 ! jack dongarra, linpack, 3/11/78.
4147 ! modified 3/93 to return if incx .le. 0.
4148 ! modified 12/3/93, array(1) declarations changed to array(*)
4150 double precision dx(*),dmax
4154 if( n.lt.1 .or. incx.le.0 ) return
4157 if(incx.eq.1)go to 20
4159 ! code for increment not equal to 1
4165 if(dabs(dx(ix)).le.dmax) go to 5
4172 ! code for increment equal to 1
4174 20 dmax = dabs(dx(1))
4176 if(dabs(dx(i)).le.dmax) go to 30
4184 !-----------------------------------------------------------------------
4185 subroutine dgbfa(abd,lda,n,ml,mu,ipvt,info)
4186 integer lda,n,ml,mu,ipvt(1),info
4187 double precision abd(lda,1)
4189 ! dgbfa factors a double precision band matrix by elimination.
4191 ! dgbfa is usually called by dgbco, but it can be called
4192 ! directly with a saving in time if rcond is not needed.
4196 ! abd double precision(lda, n)
4197 ! contains the matrix in band storage. the columns
4198 ! of the matrix are stored in the columns of abd and
4199 ! the diagonals of the matrix are stored in rows
4200 ! ml+1 through 2*ml+mu+1 of abd .
4201 ! see the comments below for details.
4204 ! the leading dimension of the array abd .
4205 ! lda must be .ge. 2*ml + mu + 1 .
4208 ! the order of the original matrix.
4211 ! number of diagonals below the main diagonal.
4212 ! 0 .le. ml .lt. n .
4215 ! number of diagonals above the main diagonal.
4216 ! 0 .le. mu .lt. n .
4217 ! more efficient if ml .le. mu .
4220 ! abd an upper triangular matrix in band storage and
4221 ! the multipliers which were used to obtain it.
4222 ! the factorization can be written a = l*u where
4223 ! l is a product of permutation and unit lower
4224 ! triangular matrices and u is upper triangular.
4227 ! an integer vector of pivot indices.
4231 ! = k if u(k,k) .eq. 0.0 . this is not an error
4232 ! condition for this subroutine, but it does
4233 ! indicate that dgbsl will divide by zero if
4234 ! called. use rcond in dgbco for a reliable
4235 ! indication of singularity.
4239 ! if a is a band matrix, the following program segment
4240 ! will set up the input.
4242 ! ml = (band width below the diagonal)
4243 ! mu = (band width above the diagonal)
4246 ! i1 = max0(1, j-mu)
4247 ! i2 = min0(n, j+ml)
4254 ! this uses rows ml+1 through 2*ml+mu+1 of abd .
4255 ! in addition, the first ml rows in abd are used for
4256 ! elements generated during the triangularization.
4257 ! the total number of rows needed in abd is 2*ml+mu+1 .
4258 ! the ml+mu by ml+mu upper left triangle and the
4259 ! ml by ml lower right triangle are not referenced.
4261 ! linpack. this version dated 08/14/78 .
4262 ! cleve moler, university of new mexico, argonne national lab.
4264 ! subroutines and functions
4266 ! blas daxpy,dscal,idamax
4269 ! internal variables
4272 ! 27-oct-2005 rce - do not declare functions that are in the module
4273 ! integer i,idamax,i0,j,ju,jz,j0,j1,k,kp1,l,lm,m,mm,nm1
4274 integer i, i0,j,ju,jz,j0,j1,k,kp1,l,lm,m,mm,nm1
4280 ! zero initial fill-in columns
4284 if (j1 .lt. j0) go to 30
4295 ! gaussian elimination with partial pivoting
4298 if (nm1 .lt. 1) go to 130
4302 ! zero next fill-in column
4305 if (jz .gt. n) go to 50
4306 if (ml .lt. 1) go to 50
4312 ! find l = pivot index
4315 l = idamax(lm+1,abd(m,k),1) + m - 1
4318 ! zero pivot implies this column already triangularized
4320 if (abd(l,k) .eq. 0.0d0) go to 100
4322 ! interchange if necessary
4324 if (l .eq. m) go to 60
4330 ! compute multipliers
4333 call dscal(lm,t,abd(m+1,k),1)
4335 ! row elimination with column indexing
4337 ju = min0(max0(ju,mu+ipvt(k)),n)
4339 if (ju .lt. kp1) go to 90
4344 if (l .eq. mm) go to 70
4345 abd(l,j) = abd(mm,j)
4348 call daxpy(lm,t,abd(m+1,k),1,abd(mm+1,j),1)
4358 if (abd(m,n) .eq. 0.0d0) info = n
4360 end subroutine dgbfa
4363 !-----------------------------------------------------------------------
4364 subroutine dgbsl(abd,lda,n,ml,mu,ipvt,b,job)
4365 integer lda,n,ml,mu,ipvt(1),job
4366 double precision abd(lda,1),b(1)
4368 ! dgbsl solves the double precision band system
4369 ! a * x = b or trans(a) * x = b
4370 ! using the factors computed by dgbco or dgbfa.
4374 ! abd double precision(lda, n)
4375 ! the output from dgbco or dgbfa.
4378 ! the leading dimension of the array abd .
4381 ! the order of the original matrix.
4384 ! number of diagonals below the main diagonal.
4387 ! number of diagonals above the main diagonal.
4390 ! the pivot vector from dgbco or dgbfa.
4392 ! b double precision(n)
4393 ! the right hand side vector.
4396 ! = 0 to solve a*x = b ,
4397 ! = nonzero to solve trans(a)*x = b , where
4398 ! trans(a) is the transpose.
4402 ! b the solution vector x .
4406 ! a division by zero will occur if the input factor contains a
4407 ! zero on the diagonal. technically this indicates singularity
4408 ! but it is often caused by improper arguments or improper
4409 ! setting of lda . it will not occur if the subroutines are
4410 ! called correctly and if dgbco has set rcond .gt. 0.0
4411 ! or dgbfa has set info .eq. 0 .
4413 ! to compute inverse(a) * c where c is a matrix
4415 ! call dgbco(abd,lda,n,ml,mu,ipvt,rcond,z)
4416 ! if (rcond is too small) go to ...
4418 ! call dgbsl(abd,lda,n,ml,mu,ipvt,c(1,j),0)
4421 ! linpack. this version dated 08/14/78 .
4422 ! cleve moler, university of new mexico, argonne national lab.
4424 ! subroutines and functions
4429 ! internal variables
4431 ! 27-oct-2005 rce - do not declare functions that are in the module
4432 ! double precision ddot,t
4434 integer k,kb,l,la,lb,lm,m,nm1
4438 if (job .ne. 0) go to 50
4440 ! job = 0 , solve a * x = b
4441 ! first solve l*y = b
4443 if (ml .eq. 0) go to 30
4444 if (nm1 .lt. 1) go to 30
4449 if (l .eq. k) go to 10
4453 call daxpy(lm,t,abd(m+1,k),1,b(k+1),1)
4461 b(k) = b(k)/abd(m,k)
4466 call daxpy(lm,t,abd(la,k),1,b(lb),1)
4471 ! job = nonzero, solve trans(a) * x = b
4472 ! first solve trans(u)*y = b
4478 t = ddot(lm,abd(la,k),1,b(lb),1)
4479 b(k) = (b(k) - t)/abd(m,k)
4482 ! now solve trans(l)*x = y
4484 if (ml .eq. 0) go to 90
4485 if (nm1 .lt. 1) go to 90
4489 b(k) = b(k) + ddot(lm,abd(m+1,k),1,b(k+1),1)
4491 if (l .eq. k) go to 70
4500 end subroutine dgbsl
4503 !-----------------------------------------------------------------------
4504 subroutine dgefa(a,lda,n,ipvt,info)
4505 ! 27-oct-2005 rce - change '1' dimensions
4506 ! integer lda,n,ipvt(1),info
4507 integer lda,n,ipvt(n),info
4508 ! double precision a(lda,1)
4509 double precision a(lda,n)
4511 ! dgefa factors a double precision matrix by gaussian elimination.
4513 ! dgefa is usually called by dgeco, but it can be called
4514 ! directly with a saving in time if rcond is not needed.
4515 ! (time for dgeco) = (1 + 9/n)*(time for dgefa) .
4519 ! a double precision(lda, n)
4520 ! the matrix to be factored.
4523 ! the leading dimension of the array a .
4526 ! the order of the matrix a .
4530 ! a an upper triangular matrix and the multipliers
4531 ! which were used to obtain it.
4532 ! the factorization can be written a = l*u where
4533 ! l is a product of permutation and unit lower
4534 ! triangular matrices and u is upper triangular.
4537 ! an integer vector of pivot indices.
4541 ! = k if u(k,k) .eq. 0.0 . this is not an error
4542 ! condition for this subroutine, but it does
4543 ! indicate that dgesl or dgedi will divide by zero
4544 ! if called. use rcond in dgeco for a reliable
4545 ! indication of singularity.
4547 ! linpack. this version dated 08/14/78 .
4548 ! cleve moler, university of new mexico, argonne national lab.
4550 ! subroutines and functions
4552 ! blas daxpy,dscal,idamax
4554 ! internal variables
4557 ! 27-oct-2005 rce - do not declare functions that are in the module
4558 ! integer idamax,j,k,kp1,l,nm1
4559 integer j,k,kp1,l,nm1
4562 ! gaussian elimination with partial pivoting
4566 if (nm1 .lt. 1) go to 70
4570 ! find l = pivot index
4572 l = idamax(n-k+1,a(k,k),1) + k - 1
4575 ! zero pivot implies this column already triangularized
4577 if (a(l,k) .eq. 0.0d0) go to 40
4579 ! interchange if necessary
4581 if (l .eq. k) go to 10
4587 ! compute multipliers
4590 call dscal(n-k,t,a(k+1,k),1)
4592 ! row elimination with column indexing
4596 if (l .eq. k) go to 20
4600 call daxpy(n-k,t,a(k+1,k),1,a(k+1,j),1)
4609 if (a(n,n) .eq. 0.0d0) info = n
4611 end subroutine dgefa
4614 !-----------------------------------------------------------------------
4615 subroutine dgesl(a,lda,n,ipvt,b,job)
4616 ! 27-oct-2005 rce - change '1' dimensions
4617 ! integer lda,n,ipvt(1),job
4618 integer lda,n,ipvt(n),job
4619 ! double precision a(lda,1),b(1)
4620 double precision a(lda,n),b(n)
4622 ! dgesl solves the double precision system
4623 ! a * x = b or trans(a) * x = b
4624 ! using the factors computed by dgeco or dgefa.
4628 ! a double precision(lda, n)
4629 ! the output from dgeco or dgefa.
4632 ! the leading dimension of the array a .
4635 ! the order of the matrix a .
4638 ! the pivot vector from dgeco or dgefa.
4640 ! b double precision(n)
4641 ! the right hand side vector.
4644 ! = 0 to solve a*x = b ,
4645 ! = nonzero to solve trans(a)*x = b where
4646 ! trans(a) is the transpose.
4650 ! b the solution vector x .
4654 ! a division by zero will occur if the input factor contains a
4655 ! zero on the diagonal. technically this indicates singularity
4656 ! but it is often caused by improper arguments or improper
4657 ! setting of lda . it will not occur if the subroutines are
4658 ! called correctly and if dgeco has set rcond .gt. 0.0
4659 ! or dgefa has set info .eq. 0 .
4661 ! to compute inverse(a) * c where c is a matrix
4663 ! call dgeco(a,lda,n,ipvt,rcond,z)
4664 ! if (rcond is too small) go to ...
4666 ! call dgesl(a,lda,n,ipvt,c(1,j),0)
4669 ! linpack. this version dated 08/14/78 .
4670 ! cleve moler, university of new mexico, argonne national lab.
4672 ! subroutines and functions
4676 ! internal variables
4678 ! 27-oct-2005 rce - do not declare functions that are in the module
4679 ! double precision ddot,t
4684 if (job .ne. 0) go to 50
4686 ! job = 0 , solve a * x = b
4687 ! first solve l*y = b
4689 if (nm1 .lt. 1) go to 30
4693 if (l .eq. k) go to 10
4697 call daxpy(n-k,t,a(k+1,k),1,b(k+1),1)
4707 call daxpy(k-1,t,a(1,k),1,b(1),1)
4712 ! job = nonzero, solve trans(a) * x = b
4713 ! first solve trans(u)*y = b
4716 t = ddot(k-1,a(1,k),1,b(1),1)
4717 b(k) = (b(k) - t)/a(k,k)
4720 ! now solve trans(l)*x = y
4722 if (nm1 .lt. 1) go to 90
4725 b(k) = b(k) + ddot(n-k,a(k+1,k),1,b(k+1),1)
4727 if (l .eq. k) go to 70
4736 end subroutine dgesl
4740 end module module_cmu_dvode_solver