1
c-----------------------------------------------------------------------
2
c Demonstration program for the DLSODA package.
3
c This is the version of 14 June 2001.
5
c This version is in double precision.
7
c The package is used to solve two simple problems,
8
c one with a full Jacobian, the other with a banded Jacobian,
9
c with the 2 appropriate values of jt in each case.
10
c If the errors are too large, or other difficulty occurs,
11
c a warning message is printed. All output is on unit lout = 6.
12
c-----------------------------------------------------------------------
13
external f1, jac1, f2, jac2
14
integer i, iopar, iopt, iout, istate, itask, itol, iwork,
15
1 jt, leniw, lenrw, liw, lout, lrw, mband, mused,
16
2 ml, mu, neq, nerr, nfe, nfea, nje, nout, nqu, nst
17
double precision atol, dtout, dtout0, dtout1, er, erm, ero, hu,
18
1 rtol, rwork, t, tout, tout1, tsw, y
19
dimension y(25), rwork(522), iwork(45), neq(1), atol(1), rtol(1)
20
data lout/6/, tout1/16.921743d0/, dtout/17.341162d0/
34
write (lout,110) neq(1),itol,rtol(1),atol(1)
35
110 format(/'Demonstration program for DLSODA package'////
36
1 ' Problem 1: Van der Pol oscillator:'/
37
2 ' xdotdot - 20*(1 - x**2)*xdot + x = 0, ',
38
3 ' x(0) = 2, xdot(0) = 0'/' neq =',i2/
39
4 ' itol =',i3,' rtol =',d10.1,' atol =',d10.1//)
43
120 format(//' Solution with jt =',i3//
56
call dlsoda(f1,neq,y,t,tout,itol,rtol,atol,itask,istate,
57
1 iopt,rwork,lrw,iwork,liw,jac1,jt)
62
write (lout,140) t,y(1),y(2),mused,nqu,hu,tsw
63
140 format(d12.5,d16.5,d14.3,2i6,2d13.3)
64
if (istate .lt. 0) go to 175
65
iopar = iout - 2*(iout/2)
66
if (iopar .ne. 0) go to 160
69
if (er .gt. 1.0d-2) then
71
150 format(//' Warning: value at root exceeds 1.0d-2'//)
74
160 if (iout .eq. 1) tout = tout + dtout0
75
if (iout .gt. 1) tout = tout + dtout1
78
if (istate .lt. 0) nerr = nerr + 1
85
if (jt .eq. 2) nfea = nfe - neq(1)*nje
86
write (lout,180) lenrw,leniw,nst,nfe,nfea,nje,ero
87
180 format(//' Final statistics for this run:'/
88
1 ' rwork size =',i4,' iwork size =',i4/
89
2 ' number of steps =',i5/
90
3 ' number of f-s =',i5/
91
4 ' (excluding J-s) =',i5/
92
5 ' number of J-s =',i5/
93
6 ' max. error at root =',d10.2)
106
write (lout,210) neq(1),ml,mu,itol,rtol(1),atol(1)
107
210 format(///80('-')///
108
1 ' Problem 2: ydot = A * y , where',
109
2 ' A is a banded lower triangular matrix'/
110
2 ' derived from 2-D advection PDE'/
111
3 ' neq =',i3,' ml =',i2,' mu =',i2/
112
4 ' itol =',i3,' rtol =',d10.1,' atol =',d10.1//)
115
220 format(//' Solution with jt =',i3//
116
1 ' t max.err. meth ',
127
call dlsoda(f2,neq,y,t,tout,itol,rtol,atol,itask,istate,
128
1 iopt,rwork,lrw,iwork,liw,jac2,jt)
134
write (lout,240) t,erm,mused,nqu,hu,tsw
135
240 format(d15.5,d14.3,2i6,2d14.3)
136
if (istate .lt. 0) go to 275
139
if (er .gt. 1000.0d0) then
143
270 tout = tout*10.0d0
145
if (istate .lt. 0) nerr = nerr + 1
152
if (jt .eq. 5) nfea = nfe - mband*nje
153
write (lout,280) lenrw,leniw,nst,nfe,nfea,nje,ero
154
280 format(//' Final statistics for this run:'/
155
1 ' rwork size =',i4,' iwork size =',i4/
156
2 ' number of steps =',i5/
157
3 ' number of f-s =',i5/
158
4 ' (excluding J-s) =',i5/
159
5 ' number of J-s =',i5/
160
6 ' error overrun =',d10.2)
162
write (lout,300) nerr
163
300 format(///' Number of errors encountered =',i3)
167
subroutine f1 (neq, t, y, ydot)
169
double precision t, y, ydot
170
dimension y(*), ydot(*)
173
ydot(2) = 20.0d0*(1.0d0 - y(1)*y(1))*y(2) - y(1)
177
subroutine jac1 (neq, t, y, ml, mu, pd, nrowpd)
178
integer neq, ml, mu, nrowpd
179
double precision t, y, pd
180
dimension y(*), pd(nrowpd,*)
184
pd(2,1) = -40.0d0*y(1)*y(2) - 1.0d0
185
pd(2,2) = 20.0d0*(1.0d0 - y(1)*y(1))
189
subroutine f2 (neq, t, y, ydot)
190
integer neq, i, j, k, ng
191
double precision t, y, ydot, alph1, alph2, d
192
dimension y(*), ydot(*)
194
data alph1/1.0d0/, alph2/1.0d0/, ng/5/
199
if (i .ne. 1) d = d + y(k-1)*alph1
200
if (j .ne. 1) d = d + y(k-ng)*alph2
205
subroutine jac2 (neq, t, y, ml, mu, pd, nrowpd)
206
integer neq, ml, mu, nrowpd, j, mband, mu1, mu2, ng
207
double precision t, y, pd, alph1, alph2
208
dimension y(*), pd(nrowpd,*)
210
data alph1/1.0d0/, alph2/1.0d0/, ng/5/
217
10 pd(mband,j) = alph2
218
do 20 j = ng,neq(1),ng
223
subroutine edit2 (y, t, erm)
225
double precision y, t, erm, alph1, alph2, a1, a2, er, ex, yt
227
data alph1/1.0d0/, alph2/1.0d0/, ng/5/
229
if (t .eq. 0.0d0) return
231
if (t .le. 30.0d0) ex = exp(-2.0d0*t)
237
yt = t**(i+j-2)*ex*a1*a2