2 c-----------------------------------------------------------------------
3 c Demonstration program for the DLSODES package.
4 c This is the version of 14 June 2001.
6 c This version is in double precision.
8 c The package is used for each of the relevant values of mf to solve
9 c the problem ydot = A * y, where A is the 9 by 9 sparse matrix
21 c The initial conditions are y(0) = (1, 2, 3, ..., 9).
22 c Output is printed at t = 1, 2, and 3.
23 c Each case is solved first with nominal (large) values of lrw and liw,
24 c and then with values given by lenrw and leniw (optional outputs)
25 c on the first run, as a check on these computed work array lengths.
26 c If the errors are too large, or other difficulty occurs,
27 c a warning message is printed.
28 c All output is on unit lout, which is data-loaded to 6 below.
29 c-----------------------------------------------------------------------
31 integer i
, ia
, igrid
, iopt
, iout
, irun
, istate
, itask
, itol
,
32 1 iwork
, j
, ja
, k
, l
, leniw
, lenrw
, liw
, lout
, lrw
,
33 2 m
, meth
, mf
, miter
, moss
, neq
, nerr
, nfe
, nfea
,
34 3 ngp
, nje
, nlu
, nnz
, nout
, nqu
, nst
, nzl
, nzu
35 double precision atol
, erm
, ero
, hu
, rtol
, rwork
, t
, tout
, y
36 dimension y
(9), ia
(10), ja
(50), iwork
(90), rwork
(1000)
37 equivalence
(ia
(1),iwork
(31)), (ja
(1),iwork
(41))
40 c Write heading and set fixed parameters.
42 10 format(/'Demonstration problem for the DLSODES package'//)
69 if (l
.lt
. igrid
) then
76 write (lout
,80)neq
,t
,rtol
,atol
,(y
(i
),i
=1,neq
)
77 80 format(' neq =',i4
,5x
,'t0 =',f4
.1
,5x
,'rtol =',d12
.3
,5x
,
78 1 'atol =',d12
.3
//' Initial y vector = ',9f5
.1
)
80 c Loop over all relevant values of mf.
84 if ( (miter
.eq
.0 .or
. miter
.eq
.3) .and
. moss
.ne
.0) go to 191
85 mf
= 100*moss
+ 10*meth
+ miter
88 c First run: nominal work array lengths, 3 output points.
94 write (lout
,120)mf
,lrw
,liw
95 120 format(//'Run with mf =',i4
,'.',5x
,
96 1 'Input work lengths lrw, liw =',2i6
/)
103 c Loop over output points. Do output and accuracy check at each.
105 call dlsodes
(fdem
, neq
, y
, t
, tout
, itol
, rtol
, atol
, itask
,
106 1 istate
, iopt
, rwork
, lrw
, iwork
, liw
, jdem
, mf
)
110 call edit
(y
, iout
, erm
)
111 write(lout
,140)t
,nst
,hu
,nqu
,erm
,(y
(i
),i
=1,neq
)
112 140 format('At t =',f5
.1
,3x
,'nst =',i4
,3x
,'hu =',d12
.3
,3x
,
113 1 'nqu =',i3
,3x
,' max. err. =',d11
.3
/
114 2 ' y array = ',4d15
.6
/5d15
.6
)
115 if (istate
.lt
. 0) go to 175
118 if (erm
.gt
. 100.0d0
) then
120 150 format(//' Warning: error exceeds 100 * tolerance'//)
126 if (istate
.lt
. 0) nerr
= nerr
+ 1
127 if (irun
.eq
. 2) go to 191
128 c Print final statistics (first run only)
140 if (miter
.eq
. 2) nfea
= nfe
- ngp*nje
141 if (miter
.eq
. 3) nfea
= nfe
- nje
142 write (lout
,180) lenrw
,leniw
,nst
,nfe
,nfea
,nje
,ero
143 180 format(/'Final statistics for this run:'/
144 1 ' rwork size =',i4
,' iwork size =',i4
/
145 2 ' number of steps =',i5
/
146 3 ' number of f-s =',i5
/
147 4 ' (excluding J-s) =',i5
/
148 5 ' number of J-s =',i5
/
149 6 ' error overrun =',d10
.2
)
150 if (miter
.eq
. 1 .or
. miter
.eq
. 2)
151 1 write (lout
,185)nnz
,ngp
,nlu
,nzl
,nzu
152 185 format(' number of nonzeros in J = ',i5
/
153 1 ' number of J index groups =',i5
/
154 2 ' number of LU decomp-s =',i5
/
155 3 ' nonzeros in strict lower factor =',i5
/
156 4 ' nonzeros in strict upper factor =',i5
)
157 if (istate
.lt
. 0) go to 191
158 if (miter
.eq
. 1 .or
. miter
.eq
. 2)
159 1 call ssout
(neq
, rwork
(21), iwork
, lout
)
160 c Return for second run: minimal work array lengths, 1 output point.
171 write (lout
,200) nerr
172 200 format(//'Number of errors encountered =',i3
)
176 subroutine fdem
(neq
, t
, y
, ydot
)
177 integer neq
, i
, igrid
, j
, l
, m
178 double precision t
, y
, ydot
179 dimension y
(neq
), ydot
(neq
)
185 j
= l
+ (m
- 1)*igrid
186 if (m
.ne
. 1) ydot
(j
-igrid
) = ydot
(j
-igrid
) + y
(j
)
187 if (l
.ne
. 1) ydot
(j
-1) = ydot
(j
-1) + y
(j
)
188 ydot
(j
) = ydot
(j
) - 4.0d0*y
(j
)
189 if (l
.ne
. igrid
) ydot
(j
+1) = ydot
(j
+1) + y
(j
)
195 subroutine jdem
(neq
, t
, y
, j
, ia
, ja
, pdj
)
196 integer neq
, j
, ia
, ja
, igrid
, l
, m
197 double precision t
, y
, pdj
198 dimension y
(neq
), ia
(*), ja
(*), pdj
(neq
)
200 m
= (j
- 1)/igrid
+ 1
201 l
= j
- (m
- 1)*igrid
203 if (m
.ne
. 1) pdj
(j
-igrid
) = 1.0d0
204 if (l
.ne
. 1) pdj
(j
-1) = 1.0d0
205 if (l
.ne
. igrid
) pdj
(j
+1) = 1.0d0
209 subroutine edit
(y
, iout
, erm
)
211 double precision y
, erm
, er
, yex
212 dimension y
(*),yex
(9,3)
214 data yex
/6.687279d
-01, 9.901910d
-01, 7.603061d
-01,
215 1 8.077979d
-01, 1.170226e+00, 8.810605d
-01, 5.013331d
-01,
216 2 7.201389d
-01, 5.379644d
-01, 1.340488d
-01, 1.917157d
-01,
217 3 1.374034d
-01, 1.007882d
-01, 1.437868d
-01, 1.028010d
-01,
218 4 3.844343d
-02, 5.477593d
-02, 3.911435d
-02, 1.929166d
-02,
219 5 2.735444d
-02, 1.939611d
-02, 1.055981d
-02, 1.496753d
-02,
220 6 1.060897d
-02, 2.913689d
-03, 4.128975d
-03, 2.925977d
-03/
223 er
= abs
(y
(i
) - yex
(i
,iout
))
228 subroutine ssout
(neq
, iwk
, iwork
, lout
)
229 integer neq
, iwk
, iwork
, lout
230 integer i
, i1
, i2
, ipian
, ipjan
, nnz
231 dimension iwk
(*), iwork
(*)
237 write (lout
,10)(iwk
(i
),i
=i1
,i2
)
238 10 format(/' structure descriptor array ian ='/(20i4
))
241 write (lout
,20)(iwk
(i
),i
=i1
,i2
)
242 20 format(/' structure descriptor array jan ='/(20i4
))