2 c-----------------------------------------------------------------------
3 c Demonstration program for the DLSODE 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 to solve two simple problems,
9 c one with a full Jacobian, the other with a banded Jacobian,
10 c with all 8 of the appropriate values of mf in each case.
11 c If the errors are too large, or other difficulty occurs,
12 c a warning message is printed. All output is on unit lout = 6.
13 c-----------------------------------------------------------------------
14 external f1
, jac1
, f2
, jac2
15 integer i
, iopar
, iopt
, iout
, istate
, itask
, itol
, iwork
,
16 1 leniw
, lenrw
, liw
, lout
, lrw
, mband
, meth
, mf
, miter
,
17 2 ml
, mu
, neq
(1), nerr
, nfe
, nfea
, nje
, nout
, nqu
, nst
18 double precision atol
, dtout
, er
, erm
, ero
, hu
, rtol
, rwork
, t
,
20 dimension y
(25), rwork
(697), iwork
(45), rtol
(1), atol
(1)
21 data lout
/6/, tout1
/1.39283880203d0
/, dtout
/2.214773875d0
/
35 write (lout
,110) neq
(1),itol
,rtol
(1),atol
(1)
36 110 format(/' Demonstration program for DLSODE package'///
37 1 ' Problem 1: Van der Pol oscillator:'/
38 2 ' xdotdot - 3*(1 - x**2)*xdot + x = 0, ',
39 3 ' x(0) = 2, xdot(0) = 0'/
41 5 ' itol =',i3
,' rtol =',d10
.1
,' atol =',d10
.1
//)
47 120 format(///' Solution with mf =',i3
//
48 1 5x
,'t x xdot nq h'//)
57 call dlsode
(f1
,neq
,y
,t
,tout
,itol
,rtol
,atol
,itask
,istate
,
58 1 iopt
,rwork
,lrw
,iwork
,liw
,jac1
,mf
)
61 write (lout
,140) t
,y
(1),y
(2),nqu
,hu
62 140 format(d15
.5
,d16
.5
,d14
.3
,i5
,d14
.3
)
63 if (istate
.lt
. 0) go to 175
64 iopar
= iout
- 2*(iout
/2)
65 if (iopar
.ne
. 0) go to 170
66 er
= abs
(y
(1))/atol
(1)
68 if (er
.gt
. 1000.0d0
) then
70 150 format(//' Warning: error exceeds 1000 * tolerance'//)
73 170 tout
= tout
+ dtout
75 if (istate
.lt
. 0) nerr
= nerr
+ 1
82 if (miter
.eq
. 2) nfea
= nfe
- neq
(1)*nje
83 if (miter
.eq
. 3) nfea
= nfe
- nje
84 write (lout
,180) lenrw
,leniw
,nst
,nfe
,nfea
,nje
,ero
85 180 format(//' Final statistics for this run:'/
86 1 ' rwork size =',i4
,' iwork size =',i4
/
87 2 ' number of steps =',i5
/
88 3 ' number of f-s =',i5
/
89 4 ' (excluding J-s) =',i5
/
90 5 ' number of J-s =',i5
/
91 6 ' error overrun =',d10
.2
)
104 write (lout
,210) neq
(1),ml
,mu
,itol
,rtol
(1),atol
(1)
105 210 format(///70('-')///
106 1 ' Problem 2: ydot = A * y , where',
107 2 ' A is a banded lower triangular matrix'/
108 3 12x
, 'derived from 2-D advection PDE'/
109 4 ' neq =',i3
,' ml =',i2
,' mu =',i2
/
110 5 ' itol =',i3
,' rtol =',d10
.1
,' atol =',d10
.1
//)
113 if (miter
.eq
. 1 .or
. miter
.eq
. 2) go to 290
116 220 format(///' Solution with mf =',i3
//
117 1 5x
,'t max.err. nq h'//)
127 call dlsode
(f2
,neq
,y
,t
,tout
,itol
,rtol
,atol
,itask
,istate
,
128 1 iopt
,rwork
,lrw
,iwork
,liw
,jac2
,mf
)
132 write (lout
,240) t
,erm
,nqu
,hu
133 240 format(d15
.5
,d14
.3
,i5
,d14
.3
)
134 if (istate
.lt
. 0) go to 275
137 if (er
.gt
. 1000.0d0
) then
141 270 tout
= tout*10
.0d0
143 if (istate
.lt
. 0) nerr
= nerr
+ 1
150 if (miter
.eq
. 5) nfea
= nfe
- mband*nje
151 if (miter
.eq
. 3) nfea
= nfe
- nje
152 write (lout
,180) lenrw
,leniw
,nst
,nfe
,nfea
,nje
,ero
155 write (lout
,300) nerr
156 300 format(////' Number of errors encountered =',i3
)
160 subroutine f1
(neq
, t
, y
, ydot
)
162 double precision t
, y
, ydot
163 dimension y
(*), ydot
(*)
166 ydot
(2) = 3.0d0*
(1.0d0
- y
(1)*y
(1))*y
(2) - y
(1)
170 subroutine jac1
(neq
, t
, y
, ml
, mu
, pd
, nrowpd
)
171 integer neq
, ml
, mu
, nrowpd
172 double precision t
, y
, pd
173 dimension y
(*), pd
(nrowpd
,*)
177 pd
(2,1) = -6.0d0*y
(1)*y
(2) - 1.0d0
178 pd
(2,2) = 3.0d0*
(1.0d0
- y
(1)*y
(1))
182 subroutine f2
(neq
, t
, y
, ydot
)
183 integer neq
, i
, j
, k
, ng
184 double precision t
, y
, ydot
, alph1
, alph2
, d
185 dimension y
(*), ydot
(*)
187 data alph1
/1.0d0
/, alph2
/1.0d0
/, ng
/5/
192 if (i
.ne
. 1) d
= d
+ y
(k
-1)*alph1
193 if (j
.ne
. 1) d
= d
+ y
(k
-ng
)*alph2
198 subroutine jac2
(neq
, t
, y
, ml
, mu
, pd
, nrowpd
)
199 integer neq
, ml
, mu
, nrowpd
, j
, mband
, mu1
, mu2
, ng
200 double precision t
, y
, pd
, alph1
, alph2
201 dimension y
(*), pd
(nrowpd
,*)
203 data alph1
/1.0d0
/, alph2
/1.0d0
/, ng
/5/
210 10 pd
(mband
,j
) = alph2
211 do 20 j
= ng
,neq
(1),ng
216 subroutine edit2
(y
, t
, erm
)
218 double precision y
, t
, erm
, alph1
, alph2
, a1
, a2
, er
, ex
, yt
220 data alph1
/1.0d0
/, alph2
/1.0d0
/, ng
/5/
222 if (t
.eq
. 0.0d0
) return
224 if (t
.le
. 30.0d0
) ex
= exp
(-2.0d0*t
)
230 yt
= t**
(i
+j
-2)*ex*a1*a2