-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlsode.f
4189 lines (4189 loc) · 165 KB
/
dlsode.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*DECK DLSODE
SUBROUTINE DLSODE (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK,
1 ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, MF)
EXTERNAL F, JAC
INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, MF
DOUBLE PRECISION Y, T, TOUT, RTOL, ATOL, RWORK
DIMENSION NEQ(*), Y(*), RTOL(*), ATOL(*), RWORK(LRW), IWORK(LIW)
C***BEGIN PROLOGUE DLSODE
C***PURPOSE Livermore Solver for Ordinary Differential Equations.
C DLSODE solves the initial-value problem for stiff or
C nonstiff systems of first-order ODE's,
C dy/dt = f(t,y), or, in component form,
C dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(N)), i=1,...,N.
C***CATEGORY I1A
C***TYPE DOUBLE PRECISION (SLSODE-S, DLSODE-D)
C***KEYWORDS ORDINARY DIFFERENTIAL EQUATIONS, INITIAL VALUE PROBLEM,
C STIFF, NONSTIFF
C***AUTHOR Hindmarsh, Alan C., (LLNL)
C Center for Applied Scientific Computing, L-561
C Lawrence Livermore National Laboratory
C Livermore, CA 94551.
C***DESCRIPTION
C
C NOTE: The "Usage" and "Arguments" sections treat only a subset of
C available options, in condensed fashion. The options
C covered and the information supplied will support most
C standard uses of DLSODE.
C
C For more sophisticated uses, full details on all options are
C given in the concluding section, headed "Long Description."
C A synopsis of the DLSODE Long Description is provided at the
C beginning of that section; general topics covered are:
C - Elements of the call sequence; optional input and output
C - Optional supplemental routines in the DLSODE package
C - internal COMMON block
C
C *Usage:
C Communication between the user and the DLSODE package, for normal
C situations, is summarized here. This summary describes a subset
C of the available options. See "Long Description" for complete
C details, including optional communication, nonstandard options,
C and instructions for special situations.
C
C A sample program is given in the "Examples" section.
C
C Refer to the argument descriptions for the definitions of the
C quantities that appear in the following sample declarations.
C
C For MF = 10,
C PARAMETER (LRW = 20 + 16*NEQ, LIW = 20)
C For MF = 21 or 22,
C PARAMETER (LRW = 22 + 9*NEQ + NEQ**2, LIW = 20 + NEQ)
C For MF = 24 or 25,
C PARAMETER (LRW = 22 + 10*NEQ + (2*ML+MU)*NEQ,
C * LIW = 20 + NEQ)
C
C EXTERNAL F, JAC
C INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK(LIW),
C * LIW, MF
C DOUBLE PRECISION Y(NEQ), T, TOUT, RTOL, ATOL(ntol), RWORK(LRW)
C
C CALL DLSODE (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK,
C * ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, MF)
C
C *Arguments:
C F :EXT Name of subroutine for right-hand-side vector f.
C This name must be declared EXTERNAL in calling
C program. The form of F must be:
C
C SUBROUTINE F (NEQ, T, Y, YDOT)
C INTEGER NEQ
C DOUBLE PRECISION T, Y(*), YDOT(*)
C
C The inputs are NEQ, T, Y. F is to set
C
C YDOT(i) = f(i,T,Y(1),Y(2),...,Y(NEQ)),
C i = 1, ..., NEQ .
C
C NEQ :IN Number of first-order ODE's.
C
C Y :INOUT Array of values of the y(t) vector, of length NEQ.
C Input: For the first call, Y should contain the
C values of y(t) at t = T. (Y is an input
C variable only if ISTATE = 1.)
C Output: On return, Y will contain the values at the
C new t-value.
C
C T :INOUT Value of the independent variable. On return it
C will be the current value of t (normally TOUT).
C
C TOUT :IN Next point where output is desired (.NE. T).
C
C ITOL :IN 1 or 2 according as ATOL (below) is a scalar or
C an array.
C
C RTOL :IN Relative tolerance parameter (scalar).
C
C ATOL :IN Absolute tolerance parameter (scalar or array).
C If ITOL = 1, ATOL need not be dimensioned.
C If ITOL = 2, ATOL must be dimensioned at least NEQ.
C
C The estimated local error in Y(i) will be controlled
C so as to be roughly less (in magnitude) than
C
C EWT(i) = RTOL*ABS(Y(i)) + ATOL if ITOL = 1, or
C EWT(i) = RTOL*ABS(Y(i)) + ATOL(i) if ITOL = 2.
C
C Thus the local error test passes if, in each
C component, either the absolute error is less than
C ATOL (or ATOL(i)), or the relative error is less
C than RTOL.
C
C Use RTOL = 0.0 for pure absolute error control, and
C use ATOL = 0.0 (or ATOL(i) = 0.0) for pure relative
C error control. Caution: Actual (global) errors may
C exceed these local tolerances, so choose them
C conservatively.
C
C ITASK :IN Flag indicating the task DLSODE is to perform.
C Use ITASK = 1 for normal computation of output
C values of y at t = TOUT.
C
C ISTATE:INOUT Index used for input and output to specify the state
C of the calculation.
C Input:
C 1 This is the first call for a problem.
C 2 This is a subsequent call.
C Output:
C 1 Nothing was done, because TOUT was equal to T.
C 2 DLSODE was successful (otherwise, negative).
C Note that ISTATE need not be modified after a
C successful return.
C -1 Excess work done on this call (perhaps wrong
C MF).
C -2 Excess accuracy requested (tolerances too
C small).
C -3 Illegal input detected (see printed message).
C -4 Repeated error test failures (check all
C inputs).
C -5 Repeated convergence failures (perhaps bad
C Jacobian supplied or wrong choice of MF or
C tolerances).
C -6 Error weight became zero during problem
C (solution component i vanished, and ATOL or
C ATOL(i) = 0.).
C
C IOPT :IN Flag indicating whether optional inputs are used:
C 0 No.
C 1 Yes. (See "Optional inputs" under "Long
C Description," Part 1.)
C
C RWORK :WORK Real work array of length at least:
C 20 + 16*NEQ for MF = 10,
C 22 + 9*NEQ + NEQ**2 for MF = 21 or 22,
C 22 + 10*NEQ + (2*ML + MU)*NEQ for MF = 24 or 25.
C
C LRW :IN Declared length of RWORK (in user's DIMENSION
C statement).
C
C IWORK :WORK Integer work array of length at least:
C 20 for MF = 10,
C 20 + NEQ for MF = 21, 22, 24, or 25.
C
C If MF = 24 or 25, input in IWORK(1),IWORK(2) the
C lower and upper Jacobian half-bandwidths ML,MU.
C
C On return, IWORK contains information that may be
C of interest to the user:
C
C Name Location Meaning
C ----- --------- -----------------------------------------
C NST IWORK(11) Number of steps taken for the problem so
C far.
C NFE IWORK(12) Number of f evaluations for the problem
C so far.
C NJE IWORK(13) Number of Jacobian evaluations (and of
C matrix LU decompositions) for the problem
C so far.
C NQU IWORK(14) Method order last used (successfully).
C LENRW IWORK(17) Length of RWORK actually required. This
C is defined on normal returns and on an
C illegal input return for insufficient
C storage.
C LENIW IWORK(18) Length of IWORK actually required. This
C is defined on normal returns and on an
C illegal input return for insufficient
C storage.
C
C LIW :IN Declared length of IWORK (in user's DIMENSION
C statement).
C
C JAC :EXT Name of subroutine for Jacobian matrix (MF =
C 21 or 24). If used, this name must be declared
C EXTERNAL in calling program. If not used, pass a
C dummy name. The form of JAC must be:
C
C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD)
C INTEGER NEQ, ML, MU, NROWPD
C DOUBLE PRECISION T, Y(*), PD(NROWPD,*)
C
C See item c, under "Description" below for more
C information about JAC.
C
C MF :IN Method flag. Standard values are:
C 10 Nonstiff (Adams) method, no Jacobian used.
C 21 Stiff (BDF) method, user-supplied full Jacobian.
C 22 Stiff method, internally generated full
C Jacobian.
C 24 Stiff method, user-supplied banded Jacobian.
C 25 Stiff method, internally generated banded
C Jacobian.
C
C *Description:
C DLSODE solves the initial value problem for stiff or nonstiff
C systems of first-order ODE's,
C
C dy/dt = f(t,y) ,
C
C or, in component form,
C
C dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(NEQ))
C (i = 1, ..., NEQ) .
C
C DLSODE is a package based on the GEAR and GEARB packages, and on
C the October 23, 1978, version of the tentative ODEPACK user
C interface standard, with minor modifications.
C
C The steps in solving such a problem are as follows.
C
C a. First write a subroutine of the form
C
C SUBROUTINE F (NEQ, T, Y, YDOT)
C INTEGER NEQ
C DOUBLE PRECISION T, Y(*), YDOT(*)
C
C which supplies the vector function f by loading YDOT(i) with
C f(i).
C
C b. Next determine (or guess) whether or not the problem is stiff.
C Stiffness occurs when the Jacobian matrix df/dy has an
C eigenvalue whose real part is negative and large in magnitude
C compared to the reciprocal of the t span of interest. If the
C problem is nonstiff, use method flag MF = 10. If it is stiff,
C there are four standard choices for MF, and DLSODE requires the
C Jacobian matrix in some form. This matrix is regarded either
C as full (MF = 21 or 22), or banded (MF = 24 or 25). In the
C banded case, DLSODE requires two half-bandwidth parameters ML
C and MU. These are, respectively, the widths of the lower and
C upper parts of the band, excluding the main diagonal. Thus the
C band consists of the locations (i,j) with
C
C i - ML <= j <= i + MU ,
C
C and the full bandwidth is ML + MU + 1 .
C
C c. If the problem is stiff, you are encouraged to supply the
C Jacobian directly (MF = 21 or 24), but if this is not feasible,
C DLSODE will compute it internally by difference quotients (MF =
C 22 or 25). If you are supplying the Jacobian, write a
C subroutine of the form
C
C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD)
C INTEGER NEQ, ML, MU, NRWOPD
C DOUBLE PRECISION T, Y(*), PD(NROWPD,*)
C
C which provides df/dy by loading PD as follows:
C - For a full Jacobian (MF = 21), load PD(i,j) with df(i)/dy(j),
C the partial derivative of f(i) with respect to y(j). (Ignore
C the ML and MU arguments in this case.)
C - For a banded Jacobian (MF = 24), load PD(i-j+MU+1,j) with
C df(i)/dy(j); i.e., load the diagonal lines of df/dy into the
C rows of PD from the top down.
C - In either case, only nonzero elements need be loaded.
C
C d. Write a main program that calls subroutine DLSODE once for each
C point at which answers are desired. This should also provide
C for possible use of logical unit 6 for output of error messages
C by DLSODE.
C
C Before the first call to DLSODE, set ISTATE = 1, set Y and T to
C the initial values, and set TOUT to the first output point. To
C continue the integration after a successful return, simply
C reset TOUT and call DLSODE again. No other parameters need be
C reset.
C
C *Examples:
C The following is a simple example problem, with the coding needed
C for its solution by DLSODE. The problem is from chemical kinetics,
C and consists of the following three rate equations:
C
C dy1/dt = -.04*y1 + 1.E4*y2*y3
C dy2/dt = .04*y1 - 1.E4*y2*y3 - 3.E7*y2**2
C dy3/dt = 3.E7*y2**2
C
C on the interval from t = 0.0 to t = 4.E10, with initial conditions
C y1 = 1.0, y2 = y3 = 0. The problem is stiff.
C
C The following coding solves this problem with DLSODE, using
C MF = 21 and printing results at t = .4, 4., ..., 4.E10. It uses
C ITOL = 2 and ATOL much smaller for y2 than for y1 or y3 because y2
C has much smaller values. At the end of the run, statistical
C quantities of interest are printed.
C
C EXTERNAL FEX, JEX
C INTEGER IOPT, IOUT, ISTATE, ITASK, ITOL, IWORK(23), LIW, LRW,
C * MF, NEQ
C DOUBLE PRECISION ATOL(3), RTOL, RWORK(58), T, TOUT, Y(3)
C NEQ = 3
C Y(1) = 1.D0
C Y(2) = 0.D0
C Y(3) = 0.D0
C T = 0.D0
C TOUT = .4D0
C ITOL = 2
C RTOL = 1.D-4
C ATOL(1) = 1.D-6
C ATOL(2) = 1.D-10
C ATOL(3) = 1.D-6
C ITASK = 1
C ISTATE = 1
C IOPT = 0
C LRW = 58
C LIW = 23
C MF = 21
C DO 40 IOUT = 1,12
C CALL DLSODE (FEX, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK,
C * ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JEX, MF)
C WRITE(6,20) T, Y(1), Y(2), Y(3)
C 20 FORMAT(' At t =',D12.4,' y =',3D14.6)
C IF (ISTATE .LT. 0) GO TO 80
C 40 TOUT = TOUT*10.D0
C WRITE(6,60) IWORK(11), IWORK(12), IWORK(13)
C 60 FORMAT(/' No. steps =',i4,', No. f-s =',i4,', No. J-s =',i4)
C STOP
C 80 WRITE(6,90) ISTATE
C 90 FORMAT(///' Error halt.. ISTATE =',I3)
C STOP
C END
C
C SUBROUTINE FEX (NEQ, T, Y, YDOT)
C INTEGER NEQ
C DOUBLE PRECISION T, Y(3), YDOT(3)
C YDOT(1) = -.04D0*Y(1) + 1.D4*Y(2)*Y(3)
C YDOT(3) = 3.D7*Y(2)*Y(2)
C YDOT(2) = -YDOT(1) - YDOT(3)
C RETURN
C END
C
C SUBROUTINE JEX (NEQ, T, Y, ML, MU, PD, NRPD)
C INTEGER NEQ, ML, MU, NRPD
C DOUBLE PRECISION T, Y(3), PD(NRPD,3)
C PD(1,1) = -.04D0
C PD(1,2) = 1.D4*Y(3)
C PD(1,3) = 1.D4*Y(2)
C PD(2,1) = .04D0
C PD(2,3) = -PD(1,3)
C PD(3,2) = 6.D7*Y(2)
C PD(2,2) = -PD(1,2) - PD(3,2)
C RETURN
C END
C
C The output from this program (on a Cray-1 in single precision)
C is as follows.
C
C At t = 4.0000e-01 y = 9.851726e-01 3.386406e-05 1.479357e-02
C At t = 4.0000e+00 y = 9.055142e-01 2.240418e-05 9.446344e-02
C At t = 4.0000e+01 y = 7.158050e-01 9.184616e-06 2.841858e-01
C At t = 4.0000e+02 y = 4.504846e-01 3.222434e-06 5.495122e-01
C At t = 4.0000e+03 y = 1.831701e-01 8.940379e-07 8.168290e-01
C At t = 4.0000e+04 y = 3.897016e-02 1.621193e-07 9.610297e-01
C At t = 4.0000e+05 y = 4.935213e-03 1.983756e-08 9.950648e-01
C At t = 4.0000e+06 y = 5.159269e-04 2.064759e-09 9.994841e-01
C At t = 4.0000e+07 y = 5.306413e-05 2.122677e-10 9.999469e-01
C At t = 4.0000e+08 y = 5.494530e-06 2.197825e-11 9.999945e-01
C At t = 4.0000e+09 y = 5.129458e-07 2.051784e-12 9.999995e-01
C At t = 4.0000e+10 y = -7.170603e-08 -2.868241e-13 1.000000e+00
C
C No. steps = 330, No. f-s = 405, No. J-s = 69
C
C *Accuracy:
C The accuracy of the solution depends on the choice of tolerances
C RTOL and ATOL. Actual (global) errors may exceed these local
C tolerances, so choose them conservatively.
C
C *Cautions:
C The work arrays should not be altered between calls to DLSODE for
C the same problem, except possibly for the conditional and optional
C inputs.
C
C *Portability:
C Since NEQ is dimensioned inside DLSODE, some compilers may object
C to a call to DLSODE with NEQ a scalar variable. In this event,
C use DIMENSION NEQ(1). Similar remarks apply to RTOL and ATOL.
C
C Note to Cray users:
C For maximum efficiency, use the CFT77 compiler. Appropriate
C compiler optimization directives have been inserted for CFT77.
C
C *Reference:
C Alan C. Hindmarsh, "ODEPACK, A Systematized Collection of ODE
C Solvers," in Scientific Computing, R. S. Stepleman, et al., Eds.
C (North-Holland, Amsterdam, 1983), pp. 55-64.
C
C *Long Description:
C The following complete description of the user interface to
C DLSODE consists of four parts:
C
C 1. The call sequence to subroutine DLSODE, which is a driver
C routine for the solver. This includes descriptions of both
C the call sequence arguments and user-supplied routines.
C Following these descriptions is a description of optional
C inputs available through the call sequence, and then a
C description of optional outputs in the work arrays.
C
C 2. Descriptions of other routines in the DLSODE package that may
C be (optionally) called by the user. These provide the ability
C to alter error message handling, save and restore the internal
C COMMON, and obtain specified derivatives of the solution y(t).
C
C 3. Descriptions of COMMON block to be declared in overlay or
C similar environments, or to be saved when doing an interrupt
C of the problem and continued solution later.
C
C 4. Description of two routines in the DLSODE package, either of
C which the user may replace with his own version, if desired.
C These relate to the measurement of errors.
C
C
C Part 1. Call Sequence
C ----------------------
C
C Arguments
C ---------
C The call sequence parameters used for input only are
C
C F, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, IOPT, LRW, LIW, JAC, MF,
C
C and those used for both input and output are
C
C Y, T, ISTATE.
C
C The work arrays RWORK and IWORK are also used for conditional and
C optional inputs and optional outputs. (The term output here
C refers to the return from subroutine DLSODE to the user's calling
C program.)
C
C The legality of input parameters will be thoroughly checked on the
C initial call for the problem, but not checked thereafter unless a
C change in input parameters is flagged by ISTATE = 3 on input.
C
C The descriptions of the call arguments are as follows.
C
C F The name of the user-supplied subroutine defining the ODE
C system. The system must be put in the first-order form
C dy/dt = f(t,y), where f is a vector-valued function of
C the scalar t and the vector y. Subroutine F is to compute
C the function f. It is to have the form
C
C SUBROUTINE F (NEQ, T, Y, YDOT)
C DOUBLE PRECISION T, Y(*), YDOT(*)
C
C where NEQ, T, and Y are input, and the array YDOT =
C f(T,Y) is output. Y and YDOT are arrays of length NEQ.
C Subroutine F should not alter Y(1),...,Y(NEQ). F must be
C declared EXTERNAL in the calling program.
C
C Subroutine F may access user-defined quantities in
C NEQ(2),... and/or in Y(NEQ(1)+1),..., if NEQ is an array
C (dimensioned in F) and/or Y has length exceeding NEQ(1).
C See the descriptions of NEQ and Y below.
C
C If quantities computed in the F routine are needed
C externally to DLSODE, an extra call to F should be made
C for this purpose, for consistent and accurate results.
C If only the derivative dy/dt is needed, use DINTDY
C instead.
C
C NEQ The size of the ODE system (number of first-order
C ordinary differential equations). Used only for input.
C NEQ may be decreased, but not increased, during the
C problem. If NEQ is decreased (with ISTATE = 3 on input),
C the remaining components of Y should be left undisturbed,
C if these are to be accessed in F and/or JAC.
C
C Normally, NEQ is a scalar, and it is generally referred
C to as a scalar in this user interface description.
C However, NEQ may be an array, with NEQ(1) set to the
C system size. (The DLSODE package accesses only NEQ(1).)
C In either case, this parameter is passed as the NEQ
C argument in all calls to F and JAC. Hence, if it is an
C array, locations NEQ(2),... may be used to store other
C integer data and pass it to F and/or JAC. Subroutines
C F and/or JAC must include NEQ in a DIMENSION statement
C in that case.
C
C Y A real array for the vector of dependent variables, of
C length NEQ or more. Used for both input and output on
C the first call (ISTATE = 1), and only for output on
C other calls. On the first call, Y must contain the
C vector of initial values. On output, Y contains the
C computed solution vector, evaluated at T. If desired,
C the Y array may be used for other purposes between
C calls to the solver.
C
C This array is passed as the Y argument in all calls to F
C and JAC. Hence its length may exceed NEQ, and locations
C Y(NEQ+1),... may be used to store other real data and
C pass it to F and/or JAC. (The DLSODE package accesses
C only Y(1),...,Y(NEQ).)
C
C T The independent variable. On input, T is used only on
C the first call, as the initial point of the integration.
C On output, after each call, T is the value at which a
C computed solution Y is evaluated (usually the same as
C TOUT). On an error return, T is the farthest point
C reached.
C
C TOUT The next value of T at which a computed solution is
C desired. Used only for input.
C
C When starting the problem (ISTATE = 1), TOUT may be equal
C to T for one call, then should not equal T for the next
C call. For the initial T, an input value of TOUT .NE. T
C is used in order to determine the direction of the
C integration (i.e., the algebraic sign of the step sizes)
C and the rough scale of the problem. Integration in
C either direction (forward or backward in T) is permitted.
C
C If ITASK = 2 or 5 (one-step modes), TOUT is ignored
C after the first call (i.e., the first call with
C TOUT .NE. T). Otherwise, TOUT is required on every call.
C
C If ITASK = 1, 3, or 4, the values of TOUT need not be
C monotone, but a value of TOUT which backs up is limited
C to the current internal T interval, whose endpoints are
C TCUR - HU and TCUR. (See "Optional Outputs" below for
C TCUR and HU.)
C
C
C ITOL An indicator for the type of error control. See
C description below under ATOL. Used only for input.
C
C RTOL A relative error tolerance parameter, either a scalar or
C an array of length NEQ. See description below under
C ATOL. Input only.
C
C ATOL An absolute error tolerance parameter, either a scalar or
C an array of length NEQ. Input only.
C
C The input parameters ITOL, RTOL, and ATOL determine the
C error control performed by the solver. The solver will
C control the vector e = (e(i)) of estimated local errors
C in Y, according to an inequality of the form
C
C rms-norm of ( e(i)/EWT(i) ) <= 1,
C
C where
C
C EWT(i) = RTOL(i)*ABS(Y(i)) + ATOL(i),
C
C and the rms-norm (root-mean-square norm) here is
C
C rms-norm(v) = SQRT(sum v(i)**2 / NEQ).
C
C Here EWT = (EWT(i)) is a vector of weights which must
C always be positive, and the values of RTOL and ATOL
C should all be nonnegative. The following table gives the
C types (scalar/array) of RTOL and ATOL, and the
C corresponding form of EWT(i).
C
C ITOL RTOL ATOL EWT(i)
C ---- ------ ------ -----------------------------
C 1 scalar scalar RTOL*ABS(Y(i)) + ATOL
C 2 scalar array RTOL*ABS(Y(i)) + ATOL(i)
C 3 array scalar RTOL(i)*ABS(Y(i)) + ATOL
C 4 array array RTOL(i)*ABS(Y(i)) + ATOL(i)
C
C When either of these parameters is a scalar, it need not
C be dimensioned in the user's calling program.
C
C If none of the above choices (with ITOL, RTOL, and ATOL
C fixed throughout the problem) is suitable, more general
C error controls can be obtained by substituting
C user-supplied routines for the setting of EWT and/or for
C the norm calculation. See Part 4 below.
C
C If global errors are to be estimated by making a repeated
C run on the same problem with smaller tolerances, then all
C components of RTOL and ATOL (i.e., of EWT) should be
C scaled down uniformly.
C
C ITASK An index specifying the task to be performed. Input
C only. ITASK has the following values and meanings:
C 1 Normal computation of output values of y(t) at
C t = TOUT (by overshooting and interpolating).
C 2 Take one step only and return.
C 3 Stop at the first internal mesh point at or beyond
C t = TOUT and return.
C 4 Normal computation of output values of y(t) at
C t = TOUT but without overshooting t = TCRIT. TCRIT
C must be input as RWORK(1). TCRIT may be equal to or
C beyond TOUT, but not behind it in the direction of
C integration. This option is useful if the problem
C has a singularity at or beyond t = TCRIT.
C 5 Take one step, without passing TCRIT, and return.
C TCRIT must be input as RWORK(1).
C
C Note: If ITASK = 4 or 5 and the solver reaches TCRIT
C (within roundoff), it will return T = TCRIT (exactly) to
C indicate this (unless ITASK = 4 and TOUT comes before
C TCRIT, in which case answers at T = TOUT are returned
C first).
C
C ISTATE An index used for input and output to specify the state
C of the calculation.
C
C On input, the values of ISTATE are as follows:
C 1 This is the first call for the problem
C (initializations will be done). See "Note" below.
C 2 This is not the first call, and the calculation is to
C continue normally, with no change in any input
C parameters except possibly TOUT and ITASK. (If ITOL,
C RTOL, and/or ATOL are changed between calls with
C ISTATE = 2, the new values will be used but not
C tested for legality.)
C 3 This is not the first call, and the calculation is to
C continue normally, but with a change in input
C parameters other than TOUT and ITASK. Changes are
C allowed in NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, MF,
C ML, MU, and any of the optional inputs except H0.
C (See IWORK description for ML and MU.)
C
C Note: A preliminary call with TOUT = T is not counted as
C a first call here, as no initialization or checking of
C input is done. (Such a call is sometimes useful for the
C purpose of outputting the initial conditions.) Thus the
C first call for which TOUT .NE. T requires ISTATE = 1 on
C input.
C
C On output, ISTATE has the following values and meanings:
C 1 Nothing was done, as TOUT was equal to T with
C ISTATE = 1 on input.
C 2 The integration was performed successfully.
C -1 An excessive amount of work (more than MXSTEP steps)
C was done on this call, before completing the
C requested task, but the integration was otherwise
C successful as far as T. (MXSTEP is an optional input
C and is normally 500.) To continue, the user may
C simply reset ISTATE to a value >1 and call again (the
C excess work step counter will be reset to 0). In
C addition, the user may increase MXSTEP to avoid this
C error return; see "Optional Inputs" below.
C -2 Too much accuracy was requested for the precision of
C the machine being used. This was detected before
C completing the requested task, but the integration
C was successful as far as T. To continue, the
C tolerance parameters must be reset, and ISTATE must
C be set to 3. The optional output TOLSF may be used
C for this purpose. (Note: If this condition is
C detected before taking any steps, then an illegal
C input return (ISTATE = -3) occurs instead.)
C -3 Illegal input was detected, before taking any
C integration steps. See written message for details.
C (Note: If the solver detects an infinite loop of
C calls to the solver with illegal input, it will cause
C the run to stop.)
C -4 There were repeated error-test failures on one
C attempted step, before completing the requested task,
C but the integration was successful as far as T. The
C problem may have a singularity, or the input may be
C inappropriate.
C -5 There were repeated convergence-test failures on one
C attempted step, before completing the requested task,
C but the integration was successful as far as T. This
C may be caused by an inaccurate Jacobian matrix, if
C one is being used.
C -6 EWT(i) became zero for some i during the integration.
C Pure relative error control (ATOL(i)=0.0) was
C requested on a variable which has now vanished. The
C integration was successful as far as T.
C
C Note: Since the normal output value of ISTATE is 2, it
C does not need to be reset for normal continuation. Also,
C since a negative input value of ISTATE will be regarded
C as illegal, a negative output value requires the user to
C change it, and possibly other inputs, before calling the
C solver again.
C
C IOPT An integer flag to specify whether any optional inputs
C are being used on this call. Input only. The optional
C inputs are listed under a separate heading below.
C 0 No optional inputs are being used. Default values
C will be used in all cases.
C 1 One or more optional inputs are being used.
C
C RWORK A real working array (double precision). The length of
C RWORK must be at least
C
C 20 + NYH*(MAXORD + 1) + 3*NEQ + LWM
C
C where
C NYH = the initial value of NEQ,
C MAXORD = 12 (if METH = 1) or 5 (if METH = 2) (unless a
C smaller value is given as an optional input),
C LWM = 0 if MITER = 0,
C LWM = NEQ**2 + 2 if MITER = 1 or 2,
C LWM = NEQ + 2 if MITER = 3, and
C LWM = (2*ML + MU + 1)*NEQ + 2
C if MITER = 4 or 5.
C (See the MF description below for METH and MITER.)
C
C Thus if MAXORD has its default value and NEQ is constant,
C this length is:
C 20 + 16*NEQ for MF = 10,
C 22 + 16*NEQ + NEQ**2 for MF = 11 or 12,
C 22 + 17*NEQ for MF = 13,
C 22 + 17*NEQ + (2*ML + MU)*NEQ for MF = 14 or 15,
C 20 + 9*NEQ for MF = 20,
C 22 + 9*NEQ + NEQ**2 for MF = 21 or 22,
C 22 + 10*NEQ for MF = 23,
C 22 + 10*NEQ + (2*ML + MU)*NEQ for MF = 24 or 25.
C
C The first 20 words of RWORK are reserved for conditional
C and optional inputs and optional outputs.
C
C The following word in RWORK is a conditional input:
C RWORK(1) = TCRIT, the critical value of t which the
C solver is not to overshoot. Required if ITASK
C is 4 or 5, and ignored otherwise. See ITASK.
C
C LRW The length of the array RWORK, as declared by the user.
C (This will be checked by the solver.)
C
C IWORK An integer work array. Its length must be at least
C 20 if MITER = 0 or 3 (MF = 10, 13, 20, 23), or
C 20 + NEQ otherwise (MF = 11, 12, 14, 15, 21, 22, 24, 25).
C (See the MF description below for MITER.) The first few
C words of IWORK are used for conditional and optional
C inputs and optional outputs.
C
C The following two words in IWORK are conditional inputs:
C IWORK(1) = ML These are the lower and upper half-
C IWORK(2) = MU bandwidths, respectively, of the banded
C Jacobian, excluding the main diagonal.
C The band is defined by the matrix locations
C (i,j) with i - ML <= j <= i + MU. ML and MU
C must satisfy 0 <= ML,MU <= NEQ - 1. These are
C required if MITER is 4 or 5, and ignored
C otherwise. ML and MU may in fact be the band
C parameters for a matrix to which df/dy is only
C approximately equal.
C
C LIW The length of the array IWORK, as declared by the user.
C (This will be checked by the solver.)
C
C Note: The work arrays must not be altered between calls to DLSODE
C for the same problem, except possibly for the conditional and
C optional inputs, and except for the last 3*NEQ words of RWORK.
C The latter space is used for internal scratch space, and so is
C available for use by the user outside DLSODE between calls, if
C desired (but not for use by F or JAC).
C
C JAC The name of the user-supplied routine (MITER = 1 or 4) to
C compute the Jacobian matrix, df/dy, as a function of the
C scalar t and the vector y. (See the MF description below
C for MITER.) It is to have the form
C
C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD)
C DOUBLE PRECISION T, Y(*), PD(NROWPD,*)
C
C where NEQ, T, Y, ML, MU, and NROWPD are input and the
C array PD is to be loaded with partial derivatives
C (elements of the Jacobian matrix) on output. PD must be
C given a first dimension of NROWPD. T and Y have the same
C meaning as in subroutine F.
C
C In the full matrix case (MITER = 1), ML and MU are
C ignored, and the Jacobian is to be loaded into PD in
C columnwise manner, with df(i)/dy(j) loaded into PD(i,j).
C
C In the band matrix case (MITER = 4), the elements within
C the band are to be loaded into PD in columnwise manner,
C with diagonal lines of df/dy loaded into the rows of PD.
C Thus df(i)/dy(j) is to be loaded into PD(i-j+MU+1,j). ML
C and MU are the half-bandwidth parameters (see IWORK).
C The locations in PD in the two triangular areas which
C correspond to nonexistent matrix elements can be ignored
C or loaded arbitrarily, as they are overwritten by DLSODE.
C
C JAC need not provide df/dy exactly. A crude approximation
C (possibly with a smaller bandwidth) will do.
C
C In either case, PD is preset to zero by the solver, so
C that only the nonzero elements need be loaded by JAC.
C Each call to JAC is preceded by a call to F with the same
C arguments NEQ, T, and Y. Thus to gain some efficiency,
C intermediate quantities shared by both calculations may
C be saved in a user COMMON block by F and not recomputed
C by JAC, if desired. Also, JAC may alter the Y array, if
C desired. JAC must be declared EXTERNAL in the calling
C program.
C
C Subroutine JAC may access user-defined quantities in
C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array
C (dimensioned in JAC) and/or Y has length exceeding
C NEQ(1). See the descriptions of NEQ and Y above.
C
C MF The method flag. Used only for input. The legal values
C of MF are 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24,
C and 25. MF has decimal digits METH and MITER:
C MF = 10*METH + MITER .
C
C METH indicates the basic linear multistep method:
C 1 Implicit Adams method.
C 2 Method based on backward differentiation formulas
C (BDF's).
C
C MITER indicates the corrector iteration method:
C 0 Functional iteration (no Jacobian matrix is
C involved).
C 1 Chord iteration with a user-supplied full (NEQ by
C NEQ) Jacobian.
C 2 Chord iteration with an internally generated
C (difference quotient) full Jacobian (using NEQ
C extra calls to F per df/dy value).
C 3 Chord iteration with an internally generated
C diagonal Jacobian approximation (using one extra call
C to F per df/dy evaluation).
C 4 Chord iteration with a user-supplied banded Jacobian.
C 5 Chord iteration with an internally generated banded
C Jacobian (using ML + MU + 1 extra calls to F per
C df/dy evaluation).
C
C If MITER = 1 or 4, the user must supply a subroutine JAC
C (the name is arbitrary) as described above under JAC.
C For other values of MITER, a dummy argument can be used.
C
C Optional Inputs
C ---------------
C The following is a list of the optional inputs provided for in the
C call sequence. (See also Part 2.) For each such input variable,
C this table lists its name as used in this documentation, its
C location in the call sequence, its meaning, and the default value.
C The use of any of these inputs requires IOPT = 1, and in that case
C all of these inputs are examined. A value of zero for any of
C these optional inputs will cause the default value to be used.
C Thus to use a subset of the optional inputs, simply preload
C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively,
C and then set those of interest to nonzero values.
C
C Name Location Meaning and default value
C ------ --------- -----------------------------------------------
C H0 RWORK(5) Step size to be attempted on the first step.
C The default value is determined by the solver.
C HMAX RWORK(6) Maximum absolute step size allowed. The
C default value is infinite.
C HMIN RWORK(7) Minimum absolute step size allowed. The
C default value is 0. (This lower bound is not
C enforced on the final step before reaching
C TCRIT when ITASK = 4 or 5.)
C MAXORD IWORK(5) Maximum order to be allowed. The default value
C is 12 if METH = 1, and 5 if METH = 2. (See the
C MF description above for METH.) If MAXORD
C exceeds the default value, it will be reduced
C to the default value. If MAXORD is changed
C during the problem, it may cause the current
C order to be reduced.
C MXSTEP IWORK(6) Maximum number of (internally defined) steps
C allowed during one call to the solver. The
C default value is 500.
C MXHNIL IWORK(7) Maximum number of messages printed (per
C problem) warning that T + H = T on a step
C (H = step size). This must be positive to
C result in a nondefault value. The default
C value is 10.
C
C Optional Outputs
C ----------------
C As optional additional output from DLSODE, the variables listed
C below are quantities related to the performance of DLSODE which
C are available to the user. These are communicated by way of the
C work arrays, but also have internal mnemonic names as shown.
C Except where stated otherwise, all of these outputs are defined on
C any successful return from DLSODE, and on any return with ISTATE =
C -1, -2, -4, -5, or -6. On an illegal input return (ISTATE = -3),
C they will be unchanged from their existing values (if any), except
C possibly for TOLSF, LENRW, and LENIW. On any error return,
C outputs relevant to the error will be defined, as noted below.
C
C Name Location Meaning
C ----- --------- ------------------------------------------------
C HU RWORK(11) Step size in t last used (successfully).
C HCUR RWORK(12) Step size to be attempted on the next step.
C TCUR RWORK(13) Current value of the independent variable which
C the solver has actually reached, i.e., the
C current internal mesh point in t. On output,
C TCUR will always be at least as far as the
C argument T, but may be farther (if interpolation
C was done).
C TOLSF RWORK(14) Tolerance scale factor, greater than 1.0,
C computed when a request for too much accuracy
C was detected (ISTATE = -3 if detected at the
C start of the problem, ISTATE = -2 otherwise).
C If ITOL is left unaltered but RTOL and ATOL are
C uniformly scaled up by a factor of TOLSF for the
C next call, then the solver is deemed likely to
C succeed. (The user may also ignore TOLSF and
C alter the tolerance parameters in any other way
C appropriate.)
C NST IWORK(11) Number of steps taken for the problem so far.
C NFE IWORK(12) Number of F evaluations for the problem so far.
C NJE IWORK(13) Number of Jacobian evaluations (and of matrix LU
C decompositions) for the problem so far.
C NQU IWORK(14) Method order last used (successfully).
C NQCUR IWORK(15) Order to be attempted on the next step.
C IMXER IWORK(16) Index of the component of largest magnitude in
C the weighted local error vector ( e(i)/EWT(i) ),
C on an error return with ISTATE = -4 or -5.
C LENRW IWORK(17) Length of RWORK actually required. This is
C defined on normal returns and on an illegal
C input return for insufficient storage.
C LENIW IWORK(18) Length of IWORK actually required. This is
C defined on normal returns and on an illegal
C input return for insufficient storage.
C
C The following two arrays are segments of the RWORK array which may
C also be of interest to the user as optional outputs. For each
C array, the table below gives its internal name, its base address
C in RWORK, and its description.
C
C Name Base address Description
C ---- ------------ ----------------------------------------------
C YH 21 The Nordsieck history array, of size NYH by
C (NQCUR + 1), where NYH is the initial value of
C NEQ. For j = 0,1,...,NQCUR, column j + 1 of
C YH contains HCUR**j/factorial(j) times the jth
C derivative of the interpolating polynomial
C currently representing the solution, evaluated
C at t = TCUR.
C ACOR LENRW-NEQ+1 Array of size NEQ used for the accumulated
C corrections on each step, scaled on output to
C represent the estimated local error in Y on
C the last step. This is the vector e in the
C description of the error control. It is
C defined only on successful return from DLSODE.
C
C
C Part 2. Other Callable Routines
C --------------------------------
C
C The following are optional calls which the user may make to gain
C additional capabilities in conjunction with DLSODE.
C
C Form of call Function
C ------------------------ ----------------------------------------
C CALL XSETUN(LUN) Set the logical unit number, LUN, for
C output of messages from DLSODE, if the
C default is not desired. The default
C value of LUN is 6. This call may be made
C at any time and will take effect
C immediately.
C CALL XSETF(MFLAG) Set a flag to control the printing of
C messages by DLSODE. MFLAG = 0 means do
C not print. (Danger: this risks losing
C valuable information.) MFLAG = 1 means
C print (the default). This call may be
C made at any time and will take effect
C immediately.
C CALL DSRCOM(RSAV,ISAV,JOB) Saves and restores the contents of the
C internal COMMON blocks used by DLSODE
C (see Part 3 below). RSAV must be a
C real array of length 218 or more, and
C ISAV must be an integer array of length
C 37 or more. JOB = 1 means save COMMON
C into RSAV/ISAV. JOB = 2 means restore
C COMMON from same. DSRCOM is useful if
C one is interrupting a run and restarting
C later, or alternating between two or
C more problems solved with DLSODE.
C CALL DINTDY(,,,,,) Provide derivatives of y, of various
C (see below) orders, at a specified point t, if
C desired. It may be called only after a
C successful return from DLSODE. Detailed
C instructions follow.
C
C Detailed instructions for using DINTDY
C --------------------------------------
C The form of the CALL is:
C
C CALL DINTDY (T, K, RWORK(21), NYH, DKY, IFLAG)
C
C The input parameters are:
C
C T Value of independent variable where answers are
C desired (normally the same as the T last returned by
C DLSODE). For valid results, T must lie between
C TCUR - HU and TCUR. (See "Optional Outputs" above
C for TCUR and HU.)
C K Integer order of the derivative desired. K must
C satisfy 0 <= K <= NQCUR, where NQCUR is the current