subroutine fft(xr,n,isign) integer n integer isign real*8 xr(2*n) c *************************************************************** c * the fft computes the discrete fast fourier transform of a * c * sequence of n terms. * c * the forward fft computes * c * y(j)= sum (from k=0 to n-1) x(k)*exp(2*pi*i*j*k/n) * c * the backward fft computes * c * y(j)= sum (from k=0 to n-1) x(k)*exp(-2*pi*i*j*k/n) * c * * c * x is a complex array of length n. * c * n is a power of 2. n<=4096. * c * isign is the direction of the transform.if isign>=0 then * c * the fft is forward, otherwise backward. * c * * c * reference * c * j.w.cooley, p.a.w.lewis, and p.d.welch, 'the fast fourier * c * transform and its applications', ieee trans. on education, * c * vol.e-12, no.1, (march 1969),p.29. * c * the fft is a modified version of the program described in * c * this reference.the modification is the use of a table to * c * store the roots of unity. * c *************************************************************** integer maxn parameter(maxn=8192) integer i integer icnt,ii,iir,ijr,j,jj,k,m,ntbl real*8 cstore(2*maxn),dcos,dsin,datan real*8 pi,temp,vr1,vr2,vrr1,vrr2,wr1,wr2,xr1,xr2 save cstore save ntbl data ntbl/0/ c **** store table of roots of unity **** c the roots of unity exp(pi*i*k/j) for j=1,2,4,..,n/2 and c k=0,1,2,..,j-1 are computed once and stored in a table. c this table is used in subsequent calls of fft with parameter c n <= ntbl. if(n.gt.maxn) then print *,'n too big in fft',n stop endif if (n.gt.ntbl) then ntbl=n pi=datan(1.0d0)*4.0d0 j=1 icnt=0 10 continue c s=pi*(0,1)/j do 20 k=0,j-1 icnt=icnt+1 cstore(icnt+icnt-1)=dcos(k*(pi/j)) cstore(icnt+icnt )=dsin(k*(pi/j)) 20 continue j=j+j if (j.lt.n) go to 10 end if c **** bit reversal **** c the x(j) are permuted, in such a way that each new place c number j is the bit reverse of the original place number. j=1 do 30 i=1,n if (i.lt.j) then jj=2*j ii=2*i vrr1=xr(jj-1) xr(jj-1)=xr(ii-1) xr(ii-1)=vrr1 vrr2=xr(jj) xr(jj)=xr(ii) xr(ii)=vrr2 end if m=n/2 25 continue if (j.gt.m) then j=j-m m=m/2 if (m.ge.1) go to 25 else j=j+m end if 30 continue c **** matrix multiplication **** c the roots of unity and the x(j) are multiplied. j=1 icnt=0 40 jj=j+j do 50 k=1,j icnt=icnt+1 wr1=cstore(2*icnt-1) wr2=cstore(2*icnt ) if (isign.lt.0) wr2=-wr2 do 50 i=k,n,jj iir=i+i ijr=(i+j)*2 xr1=xr(ijr-1) xr2=xr(ijr) vr1=wr1*xr1 vr1=vr1-wr2*xr2 temp=xr(iir-1) xr(iir-1)=temp+vr1 xr(ijr-1)=temp-vr1 vr2=wr1*xr2+wr2*xr1 temp=xr(iir) xr(ijr)=temp-vr2 xr(iir)=temp+vr2 50 continue j=jj if (j.lt.n) go to 40 return end c----------------------------- subroutine realft(x,n,isign) integer n integer isign real*8 x(2*n) integer i,i1,i2,i3,i4,n2p3,ppp real*8 c1,c2,h1r,h1i,h2r,h2i real*8 wr,wi,wpr,wpi,wtemp,theta,pi,dsin,datan real*8 x1,x2,x3,x4,uu,vv,wr0,wr1,wr2 c1=0.5 pi=datan(1.0D0)*4 theta=pi/ n if (isign.eq.1) then c2 = -0.5D+00 call fft(x,n,1) else c2=0.5D+00 theta = -theta endif wtemp=dsin(0.5*theta) wpr = -2.0*wtemp*wtemp wpi=dsin(theta) wr=1.0+wpr wi=wpi n2p3=2*n+3 do i=2,n/2 ppp=1 if(ppp.eq.0)then c ... normal code i1=2*i-1 i2=i1+1 i3=n2p3-i2 i4=i3+1 h1r=c1*(x(i1)+x(i3)) h1i=c1*(x(i2)-x(i4)) h2r = -c2*(x(i2)+x(i4)) h2i=c2*(x(i1)-x(i3)) x(i1)= h1r +wr*h2r-wi*h2i x(i3)= h1r -wr*h2r+wi*h2i x(i2)= h1i +wr*h2i+wi*h2r x(i4) = -h1i +wr*h2i+wi*h2r wtemp=wr wr=wtemp*wpr-wi*wpi+wr wi=wi*wpr+wtemp*wpi+wi else c ... optimized for apollo i1=2*i-1 i3=(n2p3-1)-i1 x1=x(i1) x3=x(i3) h2i=c2*(x1-x3) uu= wi*h2i vv= wr*h2i h1r=c1*(x1+x3) x2=x(i1+1) x4=x(i3+1) h2r = -c2*(x2+x4) uu=wr*h2r-uu vv=wi*h2r+vv x(i1)=h1r+uu x(i3)=h1r-uu h1i = c1*(x2-x4) x(i1+1)= h1i+vv x(i3+1) = -h1i+vv wr0=wi*wpi wr1=(1+wpr) wi=wi*wr1 wtemp=wr wr2=wtemp*wr1 wi=wtemp*wpi+wi wr=wr2-wr0 endif enddo if (isign.eq.1) then h1r=x(1) x(1) = h1r+x(2) x(2) = h1r-x(2) else h1r=x(1) x(1)=c1*(h1r+x(2)) x(2)=c1*(h1r-x(2)) call fft(x,n,-1) endif end subroutine dgefa(a,lda,n,ipvt,info) integer lda,n,ipvt(1),info double precision a(lda,1) c c dgefa factors a double precision matrix by gaussian elimination. c c dgefa is usually called by dgeco, but it can be called c directly with a saving in time if rcond is not needed. c (time for dgeco) = (1 + 9/n)*(time for dgefa) . c c on entry c c a double precision(lda, n) c the matrix to be factored. c c lda integer c the leading dimension of the array a . c c n integer c the order of the matrix a . c c on return c c a an upper triangular matrix and the multipliers c which were used to obtain it. c the factorization can be written a = l*u where c l is a product of permutation and unit lower c triangular matrices and u is upper triangular. c c ipvt integer(n) c an integer vector of pivot indices. c c info integer c = 0 normal value. c = k if u(k,k) .eq. 0.0 . this is not an error c condition for this subroutine, but it does c indicate that dgesl or dgedi will divide by zero c if called. use rcond in dgeco for a reliable c indication of singularity. c c linpack. this version dated 08/14/78 . c cleve moler, university of new mexico, argonne national lab. c c subroutines and functions c c blas daxpy,dscal,idamax c c internal variables c double precision t integer idamax,j,k,kp1,l,nm1 c c c gaussian elimination with partial pivoting c info = 0 nm1 = n - 1 if (nm1 .lt. 1) go to 70 do 60 k = 1, nm1 kp1 = k + 1 c c find l = pivot index c l = idamax(n-k+1,a(k,k),1) + k - 1 ipvt(k) = l c c zero pivot implies this column already triangularized c if (a(l,k) .eq. 0.0d0) go to 40 c c interchange if necessary c if (l .eq. k) go to 10 t = a(l,k) a(l,k) = a(k,k) a(k,k) = t 10 continue c c compute multipliers c t = -1.0d0/a(k,k) call dscal(n-k,t,a(k+1,k),1) c c row elimination with column indexing c do 30 j = kp1, n t = a(l,j) if (l .eq. k) go to 20 a(l,j) = a(k,j) a(k,j) = t 20 continue call daxpy(n-k,t,a(k+1,k),1,a(k+1,j),1) 30 continue go to 50 40 continue info = k 50 continue 60 continue 70 continue ipvt(n) = n if (a(n,n) .eq. 0.0d0) info = n return end subroutine dgesl(a,lda,n,ipvt,b,job) integer lda,n,ipvt(1),job double precision a(lda,1),b(1) c c dgesl solves the double precision system c a * x = b or trans(a) * x = b c using the factors computed by dgeco or dgefa. c c on entry c c a double precision(lda, n) c the output from dgeco or dgefa. c c lda integer c the leading dimension of the array a . c c n integer c the order of the matrix a . c c ipvt integer(n) c the pivot vector from dgeco or dgefa. c c b double precision(n) c the right hand side vector. c c job integer c = 0 to solve a*x = b , c = nonzero to solve trans(a)*x = b where c trans(a) is the transpose. c c on return c c b the solution vector x . c c error condition c c a division by zero will occur if the input factor contains a c zero on the diagonal. technically this indicates singularity c but it is often caused by improper arguments or improper c setting of lda . it will not occur if the subroutines are c called correctly and if dgeco has set rcond .gt. 0.0 c or dgefa has set info .eq. 0 . c c to compute inverse(a) * c where c is a matrix c with p columns c call dgeco(a,lda,n,ipvt,rcond,z) c if (rcond is too small) go to ... c do 10 j = 1, p c call dgesl(a,lda,n,ipvt,c(1,j),0) c 10 continue c c linpack. this version dated 08/14/78 . c cleve moler, university of new mexico, argonne national lab. c c subroutines and functions c c blas daxpy,ddot c c internal variables c double precision ddot,t integer k,kb,l,nm1 c nm1 = n - 1 if (job .ne. 0) go to 50 c c job = 0 , solve a * x = b c first solve l*y = b c if (nm1 .lt. 1) go to 30 do 20 k = 1, nm1 l = ipvt(k) t = b(l) if (l .eq. k) go to 10 b(l) = b(k) b(k) = t 10 continue call daxpy(n-k,t,a(k+1,k),1,b(k+1),1) 20 continue 30 continue c c now solve u*x = y c do 40 kb = 1, n k = n + 1 - kb b(k) = b(k)/a(k,k) t = -b(k) call daxpy(k-1,t,a(1,k),1,b(1),1) 40 continue go to 100 50 continue c c job = nonzero, solve trans(a) * x = b c first solve trans(u)*y = b c do 60 k = 1, n t = ddot(k-1,a(1,k),1,b(1),1) b(k) = (b(k) - t)/a(k,k) 60 continue c c now solve trans(l)*x = y c if (nm1 .lt. 1) go to 90 do 80 kb = 1, nm1 k = n - kb b(k) = b(k) + ddot(n-k,a(k+1,k),1,b(k+1),1) l = ipvt(k) if (l .eq. k) go to 70 t = b(l) b(l) = b(k) b(k) = t 70 continue 80 continue 90 continue 100 continue return end subroutine dgbfa(abd,lda,n,ml,mu,ipvt,info) integer lda,n,ml,mu,ipvt(1),info double precision abd(lda,1) c c dgbfa factors a double precision band matrix by elimination. c c dgbfa is usually called by dgbco, but it can be called c directly with a saving in time if rcond is not needed. c c on entry c c abd double precision(lda, n) c contains the matrix in band storage. the columns c of the matrix are stored in the columns of abd and c the diagonals of the matrix are stored in rows c ml+1 through 2*ml+mu+1 of abd . c see the comments below for details. c c lda integer c the leading dimension of the array abd . c lda must be .ge. 2*ml + mu + 1 . c c n integer c the order of the original matrix. c c ml integer c number of diagonals below the main diagonal. c 0 .le. ml .lt. n . c c mu integer c number of diagonals above the main diagonal. c 0 .le. mu .lt. n . c more efficient if ml .le. mu . c on return c c abd an upper triangular matrix in band storage and c the multipliers which were used to obtain it. c the factorization can be written a = l*u where c l is a product of permutation and unit lower c triangular matrices and u is upper triangular. c c ipvt integer(n) c an integer vector of pivot indices. c c info integer c = 0 normal value. c = k if u(k,k) .eq. 0.0 . this is not an error c condition for this subroutine, but it does c indicate that dgbsl will divide by zero if c called. use rcond in dgbco for a reliable c indication of singularity. c c band storage c c if a is a band matrix, the following program segment c will set up the input. c c ml = (band width below the diagonal) c mu = (band width above the diagonal) c m = ml + mu + 1 c do 20 j = 1, n c i1 = max0(1, j-mu) c i2 = min0(n, j+ml) c do 10 i = i1, i2 c k = i - j + m c abd(k,j) = a(i,j) c 10 continue c 20 continue c c this uses rows ml+1 through 2*ml+mu+1 of abd . c in addition, the first ml rows in abd are used for c elements generated during the triangularization. c the total number of rows needed in abd is 2*ml+mu+1 . c the ml+mu by ml+mu upper left triangle and the c ml by ml lower right triangle are not referenced. c c linpack. this version dated 08/14/78 . c cleve moler, university of new mexico, argonne national lab. c c subroutines and functions c c blas daxpy,dscal,idamax c fortran max0,min0 c c internal variables c double precision t integer i,idamax,i0,j,ju,jz,j0,j1,k,kp1,l,lm,m,mm,nm1 c c m = ml + mu + 1 info = 0 c c zero initial fill-in columns c j0 = mu + 2 j1 = min0(n,m) - 1 if (j1 .lt. j0) go to 30 do 20 jz = j0, j1 i0 = m + 1 - jz do 10 i = i0, ml abd(i,jz) = 0.0d0 10 continue 20 continue 30 continue jz = j1 ju = 0 c c gaussian elimination with partial pivoting c nm1 = n - 1 if (nm1 .lt. 1) go to 130 do 120 k = 1, nm1 kp1 = k + 1 c c zero next fill-in column c jz = jz + 1 if (jz .gt. n) go to 50 if (ml .lt. 1) go to 50 do 40 i = 1, ml abd(i,jz) = 0.0d0 40 continue 50 continue c c find l = pivot index c lm = min0(ml,n-k) l = idamax(lm+1,abd(m,k),1) + m - 1 ipvt(k) = l + k - m c c zero pivot implies this column already triangularized c if (abd(l,k) .eq. 0.0d0) go to 100 c c interchange if necessary c if (l .eq. m) go to 60 t = abd(l,k) abd(l,k) = abd(m,k) abd(m,k) = t 60 continue c c compute multipliers c t = -1.0d0/abd(m,k) call dscal(lm,t,abd(m+1,k),1) c c row elimination with column indexing c ju = min0(max0(ju,mu+ipvt(k)),n) mm = m if (ju .lt. kp1) go to 90 do 80 j = kp1, ju l = l - 1 mm = mm - 1 t = abd(l,j) if (l .eq. mm) go to 70 abd(l,j) = abd(mm,j) abd(mm,j) = t 70 continue call daxpy(lm,t,abd(m+1,k),1,abd(mm+1,j),1) 80 continue 90 continue go to 110 100 continue info = k 110 continue 120 continue 130 continue ipvt(n) = n if (abd(m,n) .eq. 0.0d0) info = n return end subroutine dgbsl(abd,lda,n,ml,mu,ipvt,b,job) integer lda,n,ml,mu,ipvt(1),job double precision abd(lda,1),b(1) c c dgbsl solves the double precision band system c a * x = b or trans(a) * x = b c using the factors computed by dgbco or dgbfa. c c on entry c c abd double precision(lda, n) c the output from dgbco or dgbfa. c c lda integer c the leading dimension of the array abd . c c n integer c the order of the original matrix. c c ml integer c number of diagonals below the main diagonal. c c mu integer c number of diagonals above the main diagonal. c c ipvt integer(n) c the pivot vector from dgbco or dgbfa. c c b double precision(n) c the right hand side vector. c c job integer c = 0 to solve a*x = b , c = nonzero to solve trans(a)*x = b , where c trans(a) is the transpose. c c on return c c b the solution vector x . c c error condition c c a division by zero will occur if the input factor contains a c zero on the diagonal. technically this indicates singularity c but it is often caused by improper arguments or improper c setting of lda . it will not occur if the subroutines are c called correctly and if dgbco has set rcond .gt. 0.0 c or dgbfa has set info .eq. 0 . c c to compute inverse(a) * c where c is a matrix c with p columns c call dgbco(abd,lda,n,ml,mu,ipvt,rcond,z) c if (rcond is too small) go to ... c do 10 j = 1, p c call dgbsl(abd,lda,n,ml,mu,ipvt,c(1,j),0) c 10 continue c c linpack. this version dated 08/14/78 . c cleve moler, university of new mexico, argonne national lab. c c subroutines and functions c c blas daxpy,ddot c fortran min0 c c internal variables c double precision ddot,t integer k,kb,l,la,lb,lm,m,nm1 c m = mu + ml + 1 nm1 = n - 1 if (job .ne. 0) go to 50 c c job = 0 , solve a * x = b c first solve l*y = b c if (ml .eq. 0) go to 30 if (nm1 .lt. 1) go to 30 do 20 k = 1, nm1 lm = min0(ml,n-k) l = ipvt(k) t = b(l) if (l .eq. k) go to 10 b(l) = b(k) b(k) = t 10 continue call daxpy(lm,t,abd(m+1,k),1,b(k+1),1) 20 continue 30 continue c c now solve u*x = y c do 40 kb = 1, n k = n + 1 - kb b(k) = b(k)/abd(m,k) lm = min0(k,m) - 1 la = m - lm lb = k - lm t = -b(k) call daxpy(lm,t,abd(la,k),1,b(lb),1) 40 continue go to 100 50 continue c c job = nonzero, solve trans(a) * x = b c first solve trans(u)*y = b c do 60 k = 1, n lm = min0(k,m) - 1 la = m - lm lb = k - lm t = ddot(lm,abd(la,k),1,b(lb),1) b(k) = (b(k) - t)/abd(m,k) 60 continue c c now solve trans(l)*x = y c if (ml .eq. 0) go to 90 if (nm1 .lt. 1) go to 90 do 80 kb = 1, nm1 k = n - kb lm = min0(ml,n-k) b(k) = b(k) + ddot(lm,abd(m+1,k),1,b(k+1),1) l = ipvt(k) if (l .eq. k) go to 70 t = b(l) b(l) = b(k) b(k) = t 70 continue 80 continue 90 continue 100 continue return end subroutine daxpy(n,da,dx,incx,dy,incy) c c constant times a vector plus a vector. c uses unrolled loops for increments equal to one. c jack dongarra, linpack, 3/11/78. c double precision dx(1),dy(1),da integer i,incx,incy,ix,iy,m,mp1,n c if(n.le.0)return if (da .eq. 0.0d0) return if(incx.eq.1.and.incy.eq.1)go to 20 c c code for unequal increments or equal increments c not equal to 1 c ix = 1 iy = 1 if(incx.lt.0)ix = (-n+1)*incx + 1 if(incy.lt.0)iy = (-n+1)*incy + 1 do 10 i = 1,n dy(iy) = dy(iy) + da*dx(ix) ix = ix + incx iy = iy + incy 10 continue return c c code for both increments equal to 1 c c c clean-up loop c 20 m = mod(n,4) if( m .eq. 0 ) go to 40 do 30 i = 1,m dy(i) = dy(i) + da*dx(i) 30 continue if( n .lt. 4 ) return 40 mp1 = m + 1 do 50 i = mp1,n,4 dy(i) = dy(i) + da*dx(i) dy(i + 1) = dy(i + 1) + da*dx(i + 1) dy(i + 2) = dy(i + 2) + da*dx(i + 2) dy(i + 3) = dy(i + 3) + da*dx(i + 3) 50 continue return end subroutine dscal(n,da,dx,incx) c c scales a vector by a constant. c uses unrolled loops for increment equal to one. c jack dongarra, linpack, 3/11/78. c double precision da,dx(1) integer i,incx,m,mp1,n,nincx c if(n.le.0)return if(incx.eq.1)go to 20 c c code for increment not equal to 1 c nincx = n*incx do 10 i = 1,nincx,incx dx(i) = da*dx(i) 10 continue return c c code for increment equal to 1 c c c clean-up loop c 20 m = mod(n,5) if( m .eq. 0 ) go to 40 do 30 i = 1,m dx(i) = da*dx(i) 30 continue if( n .lt. 5 ) return 40 mp1 = m + 1 do 50 i = mp1,n,5 dx(i) = da*dx(i) dx(i + 1) = da*dx(i + 1) dx(i + 2) = da*dx(i + 2) dx(i + 3) = da*dx(i + 3) dx(i + 4) = da*dx(i + 4) 50 continue return end double precision function ddot(n,dx,incx,dy,incy) c c forms the dot product of two vectors. c uses unrolled loops for increments equal to one. c jack dongarra, linpack, 3/11/78. c double precision dx(1),dy(1),dtemp integer i,incx,incy,ix,iy,m,mp1,n c ddot = 0.0d0 dtemp = 0.0d0 if(n.le.0)return if(incx.eq.1.and.incy.eq.1)go to 20 c c code for unequal increments or equal increments c not equal to 1 c ix = 1 iy = 1 if(incx.lt.0)ix = (-n+1)*incx + 1 if(incy.lt.0)iy = (-n+1)*incy + 1 do 10 i = 1,n dtemp = dtemp + dx(ix)*dy(iy) ix = ix + incx iy = iy + incy 10 continue ddot = dtemp return c c code for both increments equal to 1 c c c clean-up loop c 20 m = mod(n,5) if( m .eq. 0 ) go to 40 do 30 i = 1,m dtemp = dtemp + dx(i)*dy(i) 30 continue if( n .lt. 5 ) go to 60 40 mp1 = m + 1 do 50 i = mp1,n,5 dtemp = dtemp + dx(i)*dy(i) + dx(i + 1)*dy(i + 1) + * dx(i + 2)*dy(i + 2) + dx(i + 3)*dy(i + 3) + dx(i + 4)*dy(i + 4) 50 continue 60 ddot = dtemp return end integer function idamax(n,dx,incx) c c finds the index of element having max. absolute value. c jack dongarra, linpack, 3/11/78. c double precision dx(1),dmax integer i,incx,ix,n c idamax = 0 if( n .lt. 1 ) return idamax = 1 if(n.eq.1)return if(incx.eq.1)go to 20 c c code for increment not equal to 1 c ix = 1 dmax = dabs(dx(1)) ix = ix + incx do 10 i = 2,n if(dabs(dx(ix)).le.dmax) go to 5 idamax = i dmax = dabs(dx(ix)) 5 ix = ix + incx 10 continue return c c code for increment equal to 1 c 20 dmax = dabs(dx(1)) do 30 i = 2,n if(dabs(dx(i)).le.dmax) go to 30 idamax = i dmax = dabs(dx(i)) 30 continue return end c subroutine dcopy(n,dx,incx,dy,incy) c c copies a vector, x, to a vector, y. c uses unrolled loops for increments equal to one. c jack dongarra, linpack, 3/11/78. c double precision dx(1),dy(1) integer i,incx,incy,ix,iy,m,mp1,n c if(n.le.0)return if(incx.eq.1.and.incy.eq.1)go to 20 c c code for unequal increments or equal increments c not equal to 1 c ix = 1 iy = 1 if(incx.lt.0)ix = (-n+1)*incx + 1 if(incy.lt.0)iy = (-n+1)*incy + 1 do 10 i = 1,n dy(iy) = dx(ix) ix = ix + incx iy = iy + incy 10 continue return c c code for both increments equal to 1 c c c clean-up loop c 20 m = mod(n,7) if( m .eq. 0 ) go to 40 do 30 i = 1,m dy(i) = dx(i) 30 continue if( n .lt. 7 ) return 40 mp1 = m + 1 do 50 i = mp1,n,7 dy(i) = dx(i) dy(i + 1) = dx(i + 1) dy(i + 2) = dx(i + 2) dy(i + 3) = dx(i + 3) dy(i + 4) = dx(i + 4) dy(i + 5) = dx(i + 5) dy(i + 6) = dx(i + 6) 50 continue return end subroutine lsode (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(1), y(1), rtol(1), atol(1), rwork(lrw), iwork(liw) c----------------------------------------------------------------------- c this is the march 30, 1987 version of c lsode.. livermore solver for ordinary differential equations. c this version is in double precision. c c lsode solves the initial value problem for stiff or nonstiff c 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(neq)) (i = 1,...,neq). c lsode is a package based on the gear and gearb packages, and on the c october 23, 1978 version of the tentative odepack user interface c standard, with minor modifications. 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 author and contact.. alan c. hindmarsh, c computing and mathematics research div., l-316 c lawrence livermore national laboratory c livermore, ca 94550. c----------------------------------------------------------------------- c summary of usage. c c communication between the user and the lsode package, for normal c situations, is summarized here. this summary describes only a subset c of the full set of options available. see the full description for c details, including optional communication, nonstandard options, c and instructions for special situations. see also the example c problem (with program and output) following this summary. c c a. first provide a subroutine of the form.. c subroutine f (neq, t, y, ydot) c dimension y(neq), ydot(neq) c which supplies the vector function f by loading ydot(i) with 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 eigenvalue c whose real part is negative and large in magnitude, compared to the c reciprocal of the t span of interest. if the problem is nonstiff, c use a method flag mf = 10. if it is stiff, there are four standard c choices for mf, and lsode requires the jacobian matrix in some form. c this matrix is regarded either as full (mf = 21 or 22), c or banded (mf = 24 or 25). in the banded case, lsode requires two c half-bandwidth parameters ml and mu. these are, respectively, the c widths of the lower and upper parts of the band, excluding the main c diagonal. thus the band consists of the locations (i,j) with c i-ml .le. j .le. i+mu, and the full bandwidth is ml+mu+1. c c c. if the problem is stiff, you are encouraged to supply the jacobian c directly (mf = 21 or 24), but if this is not feasible, lsode will c compute it internally by difference quotients (mf = 22 or 25). c if you are supplying the jacobian, provide a subroutine of the form.. c subroutine jac (neq, t, y, ml, mu, pd, nrowpd) c dimension y(neq), pd(nrowpd,neq) c which supplies 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 the c 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 rows of c pd from the top down. c in either case, only nonzero elements need be loaded. c c d. write a main program which calls subroutine lsode once for c each 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 lsode. on the first call to lsode, supply arguments as follows.. c f = name of subroutine for right-hand side vector f. c this name must be declared external in calling program. c neq = number of first order ode-s. c y = array of initial values, of length neq. c t = the initial value of the independent variable. c tout = first point where output is desired (.ne. t). c itol = 1 or 2 according as atol (below) is a scalar or array. c rtol = relative tolerance parameter (scalar). c atol = absolute tolerance parameter (scalar or array). c the estimated local error in y(i) will be controlled so as c to be roughly less (in magnitude) than 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 thus the local error test passes if, in each component, c either the absolute error is less than atol (or atol(i)), c or the relative error is less than rtol. c use rtol = 0.0 for pure absolute error control, and c use atol = 0.0 (or atol(i) = 0.0) for pure relative error c control. caution.. actual (global) errors may exceed these c local tolerances, so choose them conservatively. c itask = 1 for normal computation of output values of y at t = tout. c istate = integer flag (input and output). set istate = 1. c iopt = 0 to indicate no optional inputs used. c rwork = 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 lrw = declared length of rwork (in user-s dimension). c iwork = integer work array of length at least.. c 20 for mf = 10, c 20 + neq for mf = 21, 22, 24, or 25. c if mf = 24 or 25, input in iwork(1),iwork(2) the lower c and upper half-bandwidths ml,mu. c liw = declared length of iwork (in user-s dimension). c jac = name of subroutine for jacobian matrix (mf = 21 or 24). c if used, this name must be declared external in calling c program. if not used, pass a dummy name. c mf = method flag. standard values are.. c 10 for nonstiff (adams) method, no jacobian used. c 21 for stiff (bdf) method, user-supplied full jacobian. c 22 for stiff method, internally generated full jacobian. c 24 for stiff method, user-supplied banded jacobian. c 25 for stiff method, internally generated banded jacobian. c note that the main program must declare arrays y, rwork, iwork, c and possibly atol. c c e. the output from the first call (or any call) is.. c y = array of computed values of y(t) vector. c t = corresponding value of independent variable (normally tout). c istate = 2 if lsode was successful, negative otherwise. c -1 means excess work done on this call (perhaps wrong mf). c -2 means excess accuracy requested (tolerances too small). c -3 means illegal input detected (see printed message). c -4 means repeated error test failures (check all inputs). c -5 means repeated convergence failures (perhaps bad jacobian c supplied or wrong choice of mf or tolerances). c -6 means error weight became zero during problem. (solution c component i vanished, and atol or atol(i) = 0.) c c f. to continue the integration after a successful return, simply c reset tout and call lsode again. no other parameters need be reset. c c----------------------------------------------------------------------- c example problem. c c the following is a simple example problem, with the coding c needed for its solution by lsode. the problem is from chemical c kinetics, and consists of the following three rate equations.. 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 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 lsode, using mf = 21 c and printing results at t = .4, 4., ..., 4.e10. it uses c itol = 2 and atol much smaller for y2 than y1 or y3 because c y2 has much smaller values. c at the end of the run, statistical quantities of interest are c printed (see optional outputs in the full description below). c c external fex, jex c double precision atol, rtol, rwork, t, tout, y c dimension y(3), atol(3), rwork(58), iwork(23) 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 lsode(fex,neq,y,t,tout,itol,rtol,atol,itask,istate, c 1 iopt,rwork,lrw,iwork,liw,jex,mf) c write(6,20)t,y(1),y(2),y(3) c 20 format(7h at t =,e12.4,6h y =,3e14.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(/12h no. steps =,i4,11h no. f-s =,i4,11h no. j-s =,i4) c stop c 80 write(6,90)istate c 90 format(///22h error halt.. istate =,i3) c stop c end c c subroutine fex (neq, t, y, ydot) c double precision t, y, ydot c dimension 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 double precision pd, t, y c dimension 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 of this program (on a cdc-7600 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.494529e-06 2.197824e-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.170586e-08 -2.868234e-13 1.000000e+00 c c no. steps = 330 no. f-s = 405 no. j-s = 69 c----------------------------------------------------------------------- c full description of user interface to lsode. c c the user interface to lsode consists of the following parts. c c i. the call sequence to subroutine lsode, which is a driver c routine for the solver. this includes descriptions of both c the call sequence arguments and of user-supplied routines. c following these descriptions is a description of c optional inputs available through the call sequence, and then c a description of optional outputs (in the work arrays). c c ii. descriptions of other routines in the lsode package that may be c (optionally) called by the user. these provide the ability to c alter error message handling, save and restore the internal c common, and obtain specified derivatives of the solution y(t). c c iii. descriptions of common blocks to be declared in overlay c or similar environments, or to be saved when doing an interrupt c of the problem and continued solution later. c c iv. description of two routines in the lsode 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 i. call sequence. c c the call sequence parameters used for input only are c f, neq, tout, itol, rtol, atol, itask, iopt, lrw, liw, jac, mf, c and those used for both input and output are c y, t, istate. c the work arrays rwork and iwork are also used for conditional and c optional inputs and optional outputs. (the term output here refers c to the return from subroutine lsode to the user-s calling 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 c ode system. the system must be put in the first-order c form dy/dt = f(t,y), where f is a vector-valued function c of the scalar t and the vector y. subroutine f is to c compute the function f. it is to have the form c subroutine f (neq, t, y, ydot) c dimension y(1), ydot(1) c where neq, t, and y are input, and the array ydot = f(t,y) c is output. y and ydot are arrays of length neq. c (in the dimension statement above, 1 is a dummy c dimension.. it can be replaced by any value.) c subroutine f should not alter y(1),...,y(neq). c f must be 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 lsode, 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 intdy 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 problem. c if neq is decreased (with istate = 3 on input), the c remaining components of y should be left undisturbed, if c these are to be accessed in f and/or jac. c c normally, neq is a scalar, and it is generally referred to c as a scalar in this user interface description. however, c neq may be an array, with neq(1) set to the system size. c (the lsode package accesses only neq(1).) in either case, c this parameter is passed as the neq argument in all calls c to f and jac. hence, if it is an array, locations c neq(2),... may be used to store other integer data and pass c it to f and/or jac. subroutines f and/or jac must include c neq in a dimension statement 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 the c first call (istate = 1), and only for output on other calls. c on the first call, y must contain the vector of initial c values. on output, y contains the computed solution vector, c evaluated at t. if desired, the y array may be used c for other purposes between calls to the solver. c c this array is passed as the y argument in all calls to c f 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 lsode package accesses only c y(1),...,y(neq).) c c t = the independent variable. on input, t is used only on the c 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 tout). c on an error return, t is the farthest point reached. c c tout = the next value of t at which a computed solution is desired. c used only for input. c c when starting the problem (istate = 1), tout may be equal c to t for one call, then should .ne. t for the next call. c for the initial t, an input value of tout .ne. t is used c in order to determine the direction of the integration c (i.e. the algebraic sign of the step sizes) and the rough c scale of the problem. integration in either direction c (forward or backward in t) is permitted. c c if itask = 2 or 5 (one-step modes), tout is ignored after c the first call (i.e. the first call with tout .ne. t). c 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 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 atol. c 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 c the 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 rms-norm of ( e(i)/ewt(i) ) .le. 1, c where ewt(i) = rtol(i)*abs(y(i)) + atol(i), c and the rms-norm (root-mean-square norm) here is c rms-norm(v) = sqrt(sum v(i)**2 / neq). here ewt = (ewt(i)) c is a vector of weights which must always be positive, and c the values of rtol and atol should all be non-negative. c the following table gives the types (scalar/array) of c rtol and atol, and the corresponding form of ewt(i). c c itol rtol atol ewt(i) 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 iv 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 scaled c down uniformly. c c itask = an index specifying the task to be performed. c input only. itask has the following values and meanings. c 1 means normal computation of output values of y(t) at c t = tout (by overshooting and interpolating). c 2 means take one step only and return. c 3 means stop at the first internal mesh point at or c beyond t = tout and return. c 4 means normal computation of output values of y(t) at c t = tout but without overshooting t = tcrit. c tcrit must be input as rwork(1). tcrit may be equal to c or 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 means 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 tcrit, c in which case answers at t = tout are returned first). c c istate = an index used for input and output to specify the c the state of the calculation. c c on input, the values of istate are as follows. c 1 means this is the first call for the problem c (initializations will be done). see note below. c 2 means this is not the first call, and the calculation c is to continue normally, with no change in any input c parameters except possibly tout and itask. c (if itol, rtol, and/or atol are changed between calls c with istate = 2, the new values will be used but not c tested for legality.) c 3 means this is not the first call, and the c calculation is to continue normally, but with c a change in input parameters other than c tout and itask. changes are allowed in c neq, itol, rtol, atol, iopt, lrw, liw, mf, ml, mu, c and any of the optional inputs except h0. c (see iwork description for ml and mu.) c note.. a preliminary call with tout = t is not counted c as 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.) c thus the first call for which tout .ne. t requires c istate = 1 on input. c c on output, istate has the following values and meanings. c 1 means nothing was done, as tout was equal to t with c istate = 1 on input. (however, an internal counter was c set to detect and prevent repeated calls of this type.) c 2 means the integration was performed successfully. c -1 means an excessive amount of work (more than mxstep c steps) 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 .gt. 1 and call again c (the excess work step counter will be reset to 0). c in addition, the user may increase mxstep to avoid c this error return (see below on optional inputs). c -2 means too much accuracy was requested for the precision c of 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 tolerance c parameters must be reset, and istate must be set c to 3. the optional output tolsf may be used for this c purpose. (note.. if this condition is detected before c taking any steps, then an illegal input return c (istate = -3) occurs instead.) c -3 means 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 calls c to the solver with illegal input, it will cause c the run to stop. c -4 means there were repeated error test failures on c one attempted step, before completing the requested c task, but the integration was successful as far as t. c the problem may have a singularity, or the input c may be inappropriate. c -5 means there were repeated convergence test failures on c one attempted step, before completing the requested c task, but the integration was successful as far as t. c this may be caused by an inaccurate jacobian matrix, c if one is being used. c -6 means ewt(i) became zero for some i during the c integration. pure relative error control (atol(i)=0.0) c was requested on a variable which has now vanished. c the integration was successful as far as t. c c note.. since the normal output value of istate is 2, c it does not need to be reset for normal continuation. c also, since a negative input value of istate will be c regarded as illegal, a negative output value requires the c user to change it, and possibly other inputs, before c calling the solver again. c c iopt = an integer flag to specify whether or not any optional c inputs are being used on this call. input only. c the optional inputs are listed separately below. c iopt = 0 means no optional inputs are being used. c default values will be used in all cases. c iopt = 1 means one or more optional inputs are being used. c c rwork = a real working array (double precision). c the length of rwork must be at least c 20 + nyh*(maxord + 1) + 3*neq + lwm 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 is 1 or 2, c lwm = neq + 2 if miter = 3, and c lwm = (2*ml+mu+1)*neq + 2 if miter is 4 or 5. c (see the mf description for meth and miter.) 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 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 = critical value of t which the solver c is not to overshoot. required if itask is c 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. the length of iwork 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 the first few words of iwork are used for conditional and c optional inputs and optional outputs. c c the following 2 words in iwork are conditional inputs.. c iwork(1) = ml these are the lower and upper c iwork(2) = mu half-bandwidths, respectively, of the c banded jacobian, excluding the main diagonal. c the band is defined by the matrix locations c (i,j) with i-ml .le. j .le. i+mu. ml and mu c must satisfy 0 .le. ml,mu .le. neq-1. c these are required if miter is 4 or 5, and c ignored otherwise. ml and mu may in fact be c the band parameters for a matrix to which c df/dy is only 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 lsode 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 lsode 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 c the scalar t and the vector y. it is to have the form c subroutine jac (neq, t, y, ml, mu, pd, nrowpd) c dimension y(1), pd(nrowpd,1) c where neq, t, y, ml, mu, and nrowpd are input and the array c pd is to be loaded with partial derivatives (elements of c the jacobian matrix) on output. pd must be given a first c dimension of nrowpd. t and y have the same meaning as in c subroutine f. (in the dimension statement above, 1 is a c dummy dimension.. it can be replaced by any value.) 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 in the band matrix case (miter = 4), the elements c within the band are to be loaded into pd in columnwise c manner, with diagonal lines of df/dy loaded into the rows c of pd. thus df(i)/dy(j) is to be loaded into pd(i-j+mu+1,j). c ml 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 lsode. c jac need not provide df/dy exactly. a crude c approximation (possibly with a smaller bandwidth) will do. c in either case, pd is preset to zero by the solver, c so 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 be c saved in a user common block by f and not recomputed by jac, c if desired. also, jac may alter the y array, if desired. c jac must be declared external in the calling program. 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 neq(1). c see the descriptions of neq and y above. c c mf = the method flag. used only for input. the legal values of c mf are 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, and 25. c mf has decimal digits meth and miter.. mf = 10*meth + miter. c meth indicates the basic linear multistep method.. c meth = 1 means the implicit adams method. c meth = 2 means the method based on backward c differentiation formulas (bdf-s). c miter indicates the corrector iteration method.. c miter = 0 means functional iteration (no jacobian matrix c is involved). c miter = 1 means chord iteration with a user-supplied c full (neq by neq) jacobian. c miter = 2 means chord iteration with an internally c generated (difference quotient) full jacobian c (using neq extra calls to f per df/dy value). c miter = 3 means chord iteration with an internally c generated diagonal jacobian approximation. c (using 1 extra call to f per df/dy evaluation). c miter = 4 means chord iteration with a user-supplied c banded jacobian. c miter = 5 means chord iteration with an internally c generated banded jacobian (using ml+mu+1 extra c calls to f per df/dy evaluation). 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 ii.) 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 c case all of these inputs are examined. a value of zero for any c of 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, and c then set those of interest to nonzero values. c c name location meaning and default value c c h0 rwork(5) the step size to be attempted on the first step. c the default value is determined by the solver. c c hmax rwork(6) the maximum absolute step size allowed. c the default value is infinite. c c hmin rwork(7) the minimum absolute step size allowed. c the default value is 0. (this lower bound is not c enforced on the final step before reaching tcrit c when itask = 4 or 5.) c c maxord iwork(5) the maximum order to be allowed. the default c value is 12 if meth = 1, and 5 if meth = 2. c if maxord exceeds the default value, it will c be reduced to the default value. c if maxord is changed during the problem, it may c cause the current order to be reduced. c c mxstep iwork(6) maximum number of (internally defined) steps c allowed during one call to the solver. c the default value is 500. c c mxhnil iwork(7) maximum number of messages printed (per problem) c warning that t + h = t on a step (h = step size). c this must be positive to result in a non-default c value. the default value is 10. c----------------------------------------------------------------------- c optional outputs. c c as optional additional output from lsode, the variables listed c below are quantities related to the performance of lsode c which are available to the user. these are communicated by way of c the work arrays, but also have internal mnemonic names as shown. c except where stated otherwise, all of these outputs are defined c on any successful return from lsode, and on any return with c istate = -1, -2, -4, -5, or -6. on an illegal input return c (istate = -3), they will be unchanged from their existing values c (if any), except possibly for tolsf, lenrw, and leniw. c on any error return, outputs relevant to the error will be defined, c as noted below. c c name location meaning c c hu rwork(11) the step size in t last used (successfully). c c hcur rwork(12) the step size to be attempted on the next step. c c tcur rwork(13) the current value of the independent variable c which the solver has actually reached, i.e. the c current internal mesh point in t. on output, tcur c will always be at least as far as the argument c t, but may be farther (if interpolation was done). c c tolsf rwork(14) a tolerance scale factor, greater than 1.0, c computed when a request for too much accuracy was c detected (istate = -3 if detected at the start of c the problem, istate = -2 otherwise). if itol is c left unaltered but rtol and atol are uniformly c scaled up by a factor of tolsf for the next call, c then the solver is deemed likely to succeed. c (the user may also ignore tolsf and alter the c tolerance parameters in any other way appropriate.) c c nst iwork(11) the number of steps taken for the problem so far. c c nfe iwork(12) the number of f evaluations for the problem so far. c c nje iwork(13) the number of jacobian evaluations (and of matrix c lu decompositions) for the problem so far. c c nqu iwork(14) the method order last used (successfully). c c nqcur iwork(15) the order to be attempted on the next step. c c imxer iwork(16) the 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 c lenrw iwork(17) the length of rwork actually required. c this is defined on normal returns and on an illegal c input return for insufficient storage. c c leniw iwork(18) the length of iwork actually required. c this is 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 c may also be of interest to the user as optional outputs. c for each array, the table below gives its internal name, c its base address 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 c of neq. for j = 0,1,...,nqcur, column j+1 c of yh contains hcur**j/factorial(j) times c the j-th derivative of the interpolating c polynomial currently representing the solution, c evaluated at t = tcur. c c acor lenrw-neq+1 array of size neq used for the accumulated c corrections on each step, scaled on output c to represent the estimated local error in y c on the last step. this is the vector e in c the description of the error control. it is c defined only on a successful return from lsode. c c----------------------------------------------------------------------- c part ii. other routines callable. c c the following are optional calls which the user may make to c gain additional capabilities in conjunction with lsode. c (the routines xsetun and xsetf are designed to conform to the c slatec error handling package.) c c form of call function c call xsetun(lun) set the logical unit number, lun, for c output of messages from lsode, if c the default is not desired. c the default value of lun is 6. c c call xsetf(mflag) set a flag to control the printing of c messages by lsode. c mflag = 0 means do not print. (danger.. c this risks losing valuable information.) c mflag = 1 means print (the default). c c either of the above calls may be made at c any time and will take effect immediately. c c call srcom(rsav,isav,job) saves and restores the contents of c the internal common blocks used by c lsode (see part iii below). c rsav must be a real array of length 218 c or more, and isav must be an integer c array of length 41 or more. c job=1 means save common into rsav/isav. c job=2 means restore common from rsav/isav. c srcom is useful if one is c interrupting a run and restarting c later, or alternating between two or c more problems solved with lsode. c c call intdy(,,,,,) provide derivatives of y, of various c (see below) orders, at a specified point t, if c desired. it may be called only after c a successful return from lsode. c c the detailed instructions for using intdy are as follows. c the form of the call is.. c c call intdy (t, k, rwork(21), nyh, dky, iflag) c c the input parameters are.. c c t = value of independent variable where answers are desired c (normally the same as the t last returned by lsode). c for valid results, t must lie between tcur - hu and tcur. c (see optional outputs for tcur and hu.) c k = integer order of the derivative desired. k must satisfy c 0 .le. k .le. nqcur, where nqcur is the current order c (see optional outputs). the capability corresponding c to k = 0, i.e. computing y(t), is already provided c by lsode directly. since nqcur .ge. 1, the first c derivative dy/dt is always available with intdy. c rwork(21) = the base address of the history array yh. c nyh = column length of yh, equal to the initial value of neq. c c the output parameters are.. c c dky = a real array of length neq containing the computed value c of the k-th derivative of y(t). c iflag = integer flag, returned as 0 if k and t were legal, c -1 if k was illegal, and -2 if t was illegal. c on an error return, a message is also written. c----------------------------------------------------------------------- c part iii. common blocks. c c if lsode is to be used in an overlay situation, the user c must declare, in the primary overlay, the variables in.. c (1) the call sequence to lsode, c (2) the two internal common blocks c /ls0001/ of length 257 (218 double precision words c followed by 39 integer words), c /eh0001/ of length 2 (integer words). c c if lsode is used on a system in which the contents of internal c common blocks are not preserved between calls, the user should c declare the above two common blocks in his main program to insure c that their contents are preserved. c c if the solution of a given problem by lsode is to be interrupted c and then later continued, such as when restarting an interrupted run c or alternating between two or more problems, the user should save, c following the return from the last lsode call prior to the c interruption, the contents of the call sequence variables and the c internal common blocks, and later restore these values before the c next lsode call for that problem. to save and restore the common c blocks, use subroutine srcom (see part ii above). c c----------------------------------------------------------------------- c part iv. optionally replaceable solver routines. c c below are descriptions of two routines in the lsode package which c relate to the measurement of errors. either routine can be c replaced by a user-supplied version, if desired. however, since such c a replacement may have a major impact on performance, it should be c done only when absolutely necessary, and only with great caution. c (note.. the means by which the package version of a routine is c superseded by the user-s version may be system-dependent.) c c (a) ewset. c the following subroutine is called just before each internal c integration step, and sets the array of error weights, ewt, as c described under itol/rtol/atol above.. c subroutine ewset (neq, itol, rtol, atol, ycur, ewt) c where neq, itol, rtol, and atol are as in the lsode call sequence, c ycur contains the current dependent variable vector, and c ewt is the array of weights set by ewset. c c if the user supplies this subroutine, it must return in ewt(i) c (i = 1,...,neq) a positive quantity suitable for comparing errors c in y(i) to. the ewt array returned by ewset is passed to the c vnorm routine (see below), and also used by lsode in the computation c of the optional output imxer, the diagonal jacobian approximation, c and the increments for difference quotient jacobians. c c in the user-supplied version of ewset, it may be desirable to use c the current values of derivatives of y. derivatives up to order nq c are available from the history array yh, described above under c optional outputs. in ewset, yh is identical to the ycur array, c extended to nq + 1 columns with a column length of nyh and scale c factors of h**j/factorial(j). on the first call for the problem, c given by nst = 0, nq is 1 and h is temporarily set to 1.0. c the quantities nq, nyh, h, and nst can be obtained by including c in ewset the statements.. c double precision h, rls c common /ls0001/ rls(218),ils(39) c nq = ils(35) c nyh = ils(14) c nst = ils(36) c h = rls(212) c thus, for example, the current value of dy/dt can be obtained as c ycur(nyh+i)/h (i=1,...,neq) (and the division by h is c unnecessary when nst = 0). c c (b) vnorm. c the following is a real function routine which computes the weighted c root-mean-square norm of a vector v.. c d = vnorm (n, v, w) c where.. c n = the length of the vector, c v = real array of length n containing the vector, c w = real array of length n containing weights, c d = sqrt( (1/n) * sum(v(i)*w(i))**2 ). c vnorm is called with n = neq and with w(i) = 1.0/ewt(i), where c ewt is as set by subroutine ewset. c c if the user supplies this function, it should return a non-negative c value of vnorm suitable for use in the error control in lsode. c none of the arguments should be altered by vnorm. c for example, a user-supplied vnorm routine might.. c -substitute a max-norm of (v(i)*w(i)) for the rms-norm, or c -ignore some components of v in the norm, with the effect of c suppressing the error control on those components of y. c----------------------------------------------------------------------- c----------------------------------------------------------------------- c other routines in the lsode package. c c in addition to subroutine lsode, the lsode package includes the c following subroutines and function routines.. c intdy computes an interpolated value of the y vector at t = tout. c stode is the core integrator, which does one step of the c integration and the associated error control. c cfode sets all method coefficients and test constants. c prepj computes and preprocesses the jacobian matrix j = df/dy c and the newton iteration matrix p = i - h*l0*j. c solsy manages solution of linear system in chord iteration. c ewset sets the error weight vector ewt before each step. c vnorm computes the weighted r.m.s. norm of a vector. c srcom is a user-callable routine to save and restore c the contents of the internal common blocks. c dgefa and dgesl are routines from linpack for solving full c systems of linear algebraic equations. c dgbfa and dgbsl are routines from linpack for solving banded c linear systems. c daxpy, dscal, idamax, and ddot are basic linear algebra modules c (blas) used by the above linpack routines. c d1mach computes the unit roundoff in a machine-independent manner. c xerrwv, xsetun, and xsetf handle the printing of all error c messages and warnings. xerrwv is machine-dependent. c note.. vnorm, idamax, ddot, and d1mach are function routines. c all the others are subroutines. c c the intrinsic and external routines used by lsode are.. c dabs, dmax1, dmin1, dfloat, max0, min0, mod, dsign, dsqrt, and write. c c a block data subprogram is also included with the package, c for loading some of the variables in internal common. c c----------------------------------------------------------------------- c the following card is for optimized compilation on llnl compilers. clll. optimize c----------------------------------------------------------------------- external prepj, solsy integer illin, init, lyh, lewt, lacor, lsavf, lwm, liwm, 1 mxstep, mxhnil, nhnil, ntrep, nslast, nyh, iowns integer icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter, 1 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu integer i, i1, i2, iflag, imxer, kgo, lf0, 1 leniw, lenrw, lenwm, ml, mord, mu, mxhnl0, mxstp0 double precision rowns, 1 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround double precision atoli, ayi, big, ewti, h0, hmax, hmx, rh, rtoli, 1 tcrit, tdist, tnext, tol, tolsf, tp, size, sum, w0, 2 d1mach, vnorm dimension mord(2) logical ihit c----------------------------------------------------------------------- c the following internal common block contains c (a) variables which are local to any subroutine but whose values must c be preserved between calls to the routine (own variables), and c (b) variables which are communicated between subroutines. c the structure of the block is as follows.. all real variables are c listed first, followed by all integers. within each type, the c variables are grouped with those local to subroutine lsode first, c then those local to subroutine stode, and finally those used c for communication. the block is declared in subroutines c lsode, intdy, stode, prepj, and solsy. groups of variables are c replaced by dummy arrays in the common declarations in routines c where those variables are not used. c----------------------------------------------------------------------- common /ls0001/ rowns(209), 1 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround, 2 illin, init, lyh, lewt, lacor, lsavf, lwm, liwm, 3 mxstep, mxhnil, nhnil, ntrep, nslast, nyh, iowns(6), 4 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter, 5 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu c data mord(1),mord(2)/12,5/, mxstp0/500/, mxhnl0/10/ c----------------------------------------------------------------------- c block a. c this code block is executed on every call. c it tests istate and itask for legality and branches appropriately. c if istate .gt. 1 but the flag init shows that initialization has c not yet been done, an error return occurs. c if istate = 1 and tout = t, jump to block g and return immediately. c----------------------------------------------------------------------- if (istate .lt. 1 .or. istate .gt. 3) go to 601 if (itask .lt. 1 .or. itask .gt. 5) go to 602 if (istate .eq. 1) go to 10 if (init .eq. 0) go to 603 if (istate .eq. 2) go to 200 go to 20 10 init = 0 if (tout .eq. t) go to 430 20 ntrep = 0 c----------------------------------------------------------------------- c block b. c the next code block is executed for the initial call (istate = 1), c or for a continuation call with parameter changes (istate = 3). c it contains checking of all inputs and various initializations. c c first check legality of the non-optional inputs neq, itol, iopt, c mf, ml, and mu. c----------------------------------------------------------------------- if (neq(1) .le. 0) go to 604 if (istate .eq. 1) go to 25 if (neq(1) .gt. n) go to 605 25 n = neq(1) if (itol .lt. 1 .or. itol .gt. 4) go to 606 if (iopt .lt. 0 .or. iopt .gt. 1) go to 607 meth = mf/10 miter = mf - 10*meth if (meth .lt. 1 .or. meth .gt. 2) go to 608 if (miter .lt. 0 .or. miter .gt. 5) go to 608 if (miter .le. 3) go to 30 ml = iwork(1) mu = iwork(2) if (ml .lt. 0 .or. ml .ge. n) go to 609 if (mu .lt. 0 .or. mu .ge. n) go to 610 30 continue c next process and check the optional inputs. -------------------------- if (iopt .eq. 1) go to 40 maxord = mord(meth) mxstep = mxstp0 mxhnil = mxhnl0 if (istate .eq. 1) h0 = 0.0d0 hmxi = 0.0d0 hmin = 0.0d0 go to 60 40 maxord = iwork(5) if (maxord .lt. 0) go to 611 if (maxord .eq. 0) maxord = 100 maxord = min0(maxord,mord(meth)) mxstep = iwork(6) if (mxstep .lt. 0) go to 612 if (mxstep .eq. 0) mxstep = mxstp0 mxhnil = iwork(7) if (mxhnil .lt. 0) go to 613 if (mxhnil .eq. 0) mxhnil = mxhnl0 if (istate .ne. 1) go to 50 h0 = rwork(5) if ((tout - t)*h0 .lt. 0.0d0) go to 614 50 hmax = rwork(6) if (hmax .lt. 0.0d0) go to 615 hmxi = 0.0d0 if (hmax .gt. 0.0d0) hmxi = 1.0d0/hmax hmin = rwork(7) if (hmin .lt. 0.0d0) go to 616 c----------------------------------------------------------------------- c set work array pointers and check lengths lrw and liw. c pointers to segments of rwork and iwork are named by prefixing l to c the name of the segment. e.g., the segment yh starts at rwork(lyh). c segments of rwork (in order) are denoted yh, wm, ewt, savf, acor. c----------------------------------------------------------------------- 60 lyh = 21 if (istate .eq. 1) nyh = n lwm = lyh + (maxord + 1)*nyh if (miter .eq. 0) lenwm = 0 if (miter .eq. 1 .or. miter .eq. 2) lenwm = n*n + 2 if (miter .eq. 3) lenwm = n + 2 if (miter .ge. 4) lenwm = (2*ml + mu + 1)*n + 2 lewt = lwm + lenwm lsavf = lewt + n lacor = lsavf + n lenrw = lacor + n - 1 iwork(17) = lenrw liwm = 1 leniw = 20 + n if (miter .eq. 0 .or. miter .eq. 3) leniw = 20 iwork(18) = leniw if (lenrw .gt. lrw) go to 617 if (leniw .gt. liw) go to 618 c check rtol and atol for legality. ------------------------------------ rtoli = rtol(1) atoli = atol(1) do 70 i = 1,n if (itol .ge. 3) rtoli = rtol(i) if (itol .eq. 2 .or. itol .eq. 4) atoli = atol(i) if (rtoli .lt. 0.0d0) go to 619 if (atoli .lt. 0.0d0) go to 620 70 continue if (istate .eq. 1) go to 100 c if istate = 3, set flag to signal parameter changes to stode. -------- jstart = -1 if (nq .le. maxord) go to 90 c maxord was reduced below nq. copy yh(*,maxord+2) into savf. --------- do 80 i = 1,n 80 rwork(i+lsavf-1) = rwork(i+lwm-1) c reload wm(1) = rwork(lwm), since lwm may have changed. --------------- 90 if (miter .gt. 0) rwork(lwm) = dsqrt(uround) if (n .eq. nyh) go to 200 c neq was reduced. zero part of yh to avoid undefined references. ----- i1 = lyh + l*nyh i2 = lyh + (maxord + 1)*nyh - 1 if (i1 .gt. i2) go to 200 do 95 i = i1,i2 95 rwork(i) = 0.0d0 go to 200 c----------------------------------------------------------------------- c block c. c the next block is for the initial call only (istate = 1). c it contains all remaining initializations, the initial call to f, c and the calculation of the initial step size. c the error weights in ewt are inverted after being loaded. c----------------------------------------------------------------------- 100 uround = d1mach(4) tn = t if (itask .ne. 4 .and. itask .ne. 5) go to 110 tcrit = rwork(1) if ((tcrit - tout)*(tout - t) .lt. 0.0d0) go to 625 if (h0 .ne. 0.0d0 .and. (t + h0 - tcrit)*h0 .gt. 0.0d0) 1 h0 = tcrit - t 110 jstart = 0 if (miter .gt. 0) rwork(lwm) = dsqrt(uround) nhnil = 0 nst = 0 nje = 0 nslast = 0 hu = 0.0d0 nqu = 0 ccmax = 0.3d0 maxcor = 3 msbp = 20 mxncf = 10 c initial call to f. (lf0 points to yh(*,2).) ------------------------- lf0 = lyh + nyh call f (neq, t, y, rwork(lf0)) nfe = 1 c load the initial value vector in yh. --------------------------------- do 115 i = 1,n 115 rwork(i+lyh-1) = y(i) c load and invert the ewt array. (h is temporarily set to 1.0.) ------- nq = 1 h = 1.0d0 call ewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt)) do 120 i = 1,n if (rwork(i+lewt-1) .le. 0.0d0) go to 621 120 rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1) c----------------------------------------------------------------------- c the coding below computes the step size, h0, to be attempted on the c first step, unless the user has supplied a value for this. c first check that tout - t differs significantly from zero. c a scalar tolerance quantity tol is computed, as max(rtol(i)) c if this is positive, or max(atol(i)/abs(y(i))) otherwise, adjusted c so as to be between 100*uround and 1.0e-3. c then the computed value h0 is given by.. c neq c h0**2 = tol / ( w0**-2 + (1/neq) * sum ( f(i)/ywt(i) )**2 ) c 1 c where w0 = max ( abs(t), abs(tout) ), c f(i) = i-th component of initial value of f, c ywt(i) = ewt(i)/tol (a weight for y(i)). c the sign of h0 is inferred from the initial values of tout and t. c----------------------------------------------------------------------- if (h0 .ne. 0.0d0) go to 180 tdist = dabs(tout - t) w0 = dmax1(dabs(t),dabs(tout)) if (tdist .lt. 2.0d0*uround*w0) go to 622 tol = rtol(1) if (itol .le. 2) go to 140 do 130 i = 1,n 130 tol = dmax1(tol,rtol(i)) 140 if (tol .gt. 0.0d0) go to 160 atoli = atol(1) do 150 i = 1,n if (itol .eq. 2 .or. itol .eq. 4) atoli = atol(i) ayi = dabs(y(i)) if (ayi .ne. 0.0d0) tol = dmax1(tol,atoli/ayi) 150 continue 160 tol = dmax1(tol,100.0d0*uround) tol = dmin1(tol,0.001d0) sum = vnorm (n, rwork(lf0), rwork(lewt)) sum = 1.0d0/(tol*w0*w0) + tol*sum**2 h0 = 1.0d0/dsqrt(sum) h0 = dmin1(h0,tdist) h0 = dsign(h0,tout-t) c adjust h0 if necessary to meet hmax bound. --------------------------- 180 rh = dabs(h0)*hmxi if (rh .gt. 1.0d0) h0 = h0/rh c load h with h0 and scale yh(*,2) by h0. ------------------------------ h = h0 do 190 i = 1,n 190 rwork(i+lf0-1) = h0*rwork(i+lf0-1) go to 270 c----------------------------------------------------------------------- c block d. c the next code block is for continuation calls only (istate = 2 or 3) c and is to check stop conditions before taking a step. c----------------------------------------------------------------------- 200 nslast = nst go to (210, 250, 220, 230, 240), itask 210 if ((tn - tout)*h .lt. 0.0d0) go to 250 call intdy (tout, 0, rwork(lyh), nyh, y, iflag) if (iflag .ne. 0) go to 627 t = tout go to 420 220 tp = tn - hu*(1.0d0 + 100.0d0*uround) if ((tp - tout)*h .gt. 0.0d0) go to 623 if ((tn - tout)*h .lt. 0.0d0) go to 250 go to 400 230 tcrit = rwork(1) if ((tn - tcrit)*h .gt. 0.0d0) go to 624 if ((tcrit - tout)*h .lt. 0.0d0) go to 625 if ((tn - tout)*h .lt. 0.0d0) go to 245 call intdy (tout, 0, rwork(lyh), nyh, y, iflag) if (iflag .ne. 0) go to 627 t = tout go to 420 240 tcrit = rwork(1) if ((tn - tcrit)*h .gt. 0.0d0) go to 624 245 hmx = dabs(tn) + dabs(h) ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx if (ihit) go to 400 tnext = tn + h*(1.0d0 + 4.0d0*uround) if ((tnext - tcrit)*h .le. 0.0d0) go to 250 h = (tcrit - tn)*(1.0d0 - 4.0d0*uround) if (istate .eq. 2) jstart = -2 c----------------------------------------------------------------------- c block e. c the next block is normally executed for all calls and contains c the call to the one-step core integrator stode. c c this is a looping point for the integration steps. c c first check for too many steps being taken, update ewt (if not at c start of problem), check for too much accuracy being requested, and c check for h below the roundoff level in t. c----------------------------------------------------------------------- 250 continue if ((nst-nslast) .ge. mxstep) go to 500 call ewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt)) do 260 i = 1,n if (rwork(i+lewt-1) .le. 0.0d0) go to 510 260 rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1) 270 tolsf = uround*vnorm (n, rwork(lyh), rwork(lewt)) if (tolsf .le. 1.0d0) go to 280 tolsf = tolsf*2.0d0 if (nst .eq. 0) go to 626 go to 520 280 if ((tn + h) .ne. tn) go to 290 nhnil = nhnil + 1 if (nhnil .gt. mxhnil) go to 290 call xerrwv(50hlsode-- warning..internal t (=r1) and h (=r2) are, 1 50, 101, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) call xerrwv( 1 60h such that in the machine, t + h = t on the next step , 1 60, 101, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) call xerrwv(50h (h = step size). solver will continue anyway, 1 50, 101, 0, 0, 0, 0, 2, tn, h) if (nhnil .lt. mxhnil) go to 290 call xerrwv(50hlsode-- above warning has been issued i1 times. , 1 50, 102, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) call xerrwv(50h it will not be issued again for this problem, 1 50, 102, 0, 1, mxhnil, 0, 0, 0.0d0, 0.0d0) 290 continue c----------------------------------------------------------------------- c call stode(neq,y,yh,nyh,yh,ewt,savf,acor,wm,iwm,f,jac,prepj,solsy) c----------------------------------------------------------------------- call stode (neq, y, rwork(lyh), nyh, rwork(lyh), rwork(lewt), 1 rwork(lsavf), rwork(lacor), rwork(lwm), iwork(liwm), 2 f, jac, prepj, solsy) kgo = 1 - kflag go to (300, 530, 540), kgo c----------------------------------------------------------------------- c block f. c the following block handles the case of a successful return from the c core integrator (kflag = 0). test for stop conditions. c----------------------------------------------------------------------- 300 init = 1 go to (310, 400, 330, 340, 350), itask c itask = 1. if tout has been reached, interpolate. ------------------- 310 if ((tn - tout)*h .lt. 0.0d0) go to 250 call intdy (tout, 0, rwork(lyh), nyh, y, iflag) t = tout go to 420 c itask = 3. jump to exit if tout was reached. ------------------------ 330 if ((tn - tout)*h .ge. 0.0d0) go to 400 go to 250 c itask = 4. see if tout or tcrit was reached. adjust h if necessary. 340 if ((tn - tout)*h .lt. 0.0d0) go to 345 call intdy (tout, 0, rwork(lyh), nyh, y, iflag) t = tout go to 420 345 hmx = dabs(tn) + dabs(h) ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx if (ihit) go to 400 tnext = tn + h*(1.0d0 + 4.0d0*uround) if ((tnext - tcrit)*h .le. 0.0d0) go to 250 h = (tcrit - tn)*(1.0d0 - 4.0d0*uround) jstart = -2 go to 250 c itask = 5. see if tcrit was reached and jump to exit. --------------- 350 hmx = dabs(tn) + dabs(h) ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx c----------------------------------------------------------------------- c block g. c the following block handles all successful returns from lsode. c if itask .ne. 1, y is loaded from yh and t is set accordingly. c istate is set to 2, the illegal input counter is zeroed, and the c optional outputs are loaded into the work arrays before returning. c if istate = 1 and tout = t, there is a return with no action taken, c except that if this has happened repeatedly, the run is terminated. c----------------------------------------------------------------------- 400 do 410 i = 1,n 410 y(i) = rwork(i+lyh-1) t = tn if (itask .ne. 4 .and. itask .ne. 5) go to 420 if (ihit) t = tcrit 420 istate = 2 illin = 0 rwork(11) = hu rwork(12) = h rwork(13) = tn iwork(11) = nst iwork(12) = nfe iwork(13) = nje iwork(14) = nqu iwork(15) = nq return c 430 ntrep = ntrep + 1 if (ntrep .lt. 5) return call xerrwv( 1 60hlsode-- repeated calls with istate = 1 and tout = t (=r1) , 1 60, 301, 0, 0, 0, 0, 1, t, 0.0d0) go to 800 c----------------------------------------------------------------------- c block h. c the following block handles all unsuccessful returns other than c those for illegal input. first the error message routine is called. c if there was an error test or convergence test failure, imxer is set. c then y is loaded from yh, t is set to tn, and the illegal input c counter illin is set to 0. the optional outputs are loaded into c the work arrays before returning. c----------------------------------------------------------------------- c the maximum number of steps was taken before reaching tout. ---------- 500 call xerrwv(50hlsode-- at current t (=r1), mxstep (=i1) steps , 1 50, 201, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) call xerrwv(50h taken on this call before reaching tout , 1 50, 201, 0, 1, mxstep, 0, 1, tn, 0.0d0) istate = -1 go to 580 c ewt(i) .le. 0.0 for some i (not at start of problem). ---------------- 510 ewti = rwork(lewt+i-1) call xerrwv(50hlsode-- at t (=r1), ewt(i1) has become r2 .le. 0., 1 50, 202, 0, 1, i, 0, 2, tn, ewti) istate = -6 go to 580 c too much accuracy requested for machine precision. ------------------- 520 call xerrwv(50hlsode-- at t (=r1), too much accuracy requested , 1 50, 203, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) call xerrwv(50h for precision of machine.. see tolsf (=r2) , 1 50, 203, 0, 0, 0, 0, 2, tn, tolsf) rwork(14) = tolsf istate = -2 go to 580 c kflag = -1. error test failed repeatedly or with abs(h) = hmin. ----- 530 call xerrwv(50hlsode-- at t(=r1) and step size h(=r2), the error, 1 50, 204, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) call xerrwv(50h test failed repeatedly or with abs(h) = hmin, 1 50, 204, 0, 0, 0, 0, 2, tn, h) istate = -4 go to 560 c kflag = -2. convergence failed repeatedly or with abs(h) = hmin. ---- 540 call xerrwv(50hlsode-- at t (=r1) and step size h (=r2), the , 1 50, 205, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) call xerrwv(50h corrector convergence failed repeatedly , 1 50, 205, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) call xerrwv(30h or with abs(h) = hmin , 1 30, 205, 0, 0, 0, 0, 2, tn, h) istate = -5 c compute imxer if relevant. ------------------------------------------- 560 big = 0.0d0 imxer = 1 do 570 i = 1,n size = dabs(rwork(i+lacor-1)*rwork(i+lewt-1)) if (big .ge. size) go to 570 big = size imxer = i 570 continue iwork(16) = imxer c set y vector, t, illin, and optional outputs. ------------------------ 580 do 590 i = 1,n 590 y(i) = rwork(i+lyh-1) t = tn illin = 0 rwork(11) = hu rwork(12) = h rwork(13) = tn iwork(11) = nst iwork(12) = nfe iwork(13) = nje iwork(14) = nqu iwork(15) = nq return c----------------------------------------------------------------------- c block i. c the following block handles all error returns due to illegal input c (istate = -3), as detected before calling the core integrator. c first the error message routine is called. then if there have been c 5 consecutive such returns just before this call to the solver, c the run is halted. c----------------------------------------------------------------------- 601 call xerrwv(30hlsode-- istate (=i1) illegal , 1 30, 1, 0, 1, istate, 0, 0, 0.0d0, 0.0d0) go to 700 602 call xerrwv(30hlsode-- itask (=i1) illegal , 1 30, 2, 0, 1, itask, 0, 0, 0.0d0, 0.0d0) go to 700 603 call xerrwv(50hlsode-- istate .gt. 1 but lsode not initialized , 1 50, 3, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) go to 700 604 call xerrwv(30hlsode-- neq (=i1) .lt. 1 , 1 30, 4, 0, 1, neq(1), 0, 0, 0.0d0, 0.0d0) go to 700 605 call xerrwv(50hlsode-- istate = 3 and neq increased (i1 to i2) , 1 50, 5, 0, 2, n, neq(1), 0, 0.0d0, 0.0d0) go to 700 606 call xerrwv(30hlsode-- itol (=i1) illegal , 1 30, 6, 0, 1, itol, 0, 0, 0.0d0, 0.0d0) go to 700 607 call xerrwv(30hlsode-- iopt (=i1) illegal , 1 30, 7, 0, 1, iopt, 0, 0, 0.0d0, 0.0d0) go to 700 608 call xerrwv(30hlsode-- mf (=i1) illegal , 1 30, 8, 0, 1, mf, 0, 0, 0.0d0, 0.0d0) go to 700 609 call xerrwv(50hlsode-- ml (=i1) illegal.. .lt.0 or .ge.neq (=i2), 1 50, 9, 0, 2, ml, neq(1), 0, 0.0d0, 0.0d0) go to 700 610 call xerrwv(50hlsode-- mu (=i1) illegal.. .lt.0 or .ge.neq (=i2), 1 50, 10, 0, 2, mu, neq(1), 0, 0.0d0, 0.0d0) go to 700 611 call xerrwv(30hlsode-- maxord (=i1) .lt. 0 , 1 30, 11, 0, 1, maxord, 0, 0, 0.0d0, 0.0d0) go to 700 612 call xerrwv(30hlsode-- mxstep (=i1) .lt. 0 , 1 30, 12, 0, 1, mxstep, 0, 0, 0.0d0, 0.0d0) go to 700 613 call xerrwv(30hlsode-- mxhnil (=i1) .lt. 0 , 1 30, 13, 0, 1, mxhnil, 0, 0, 0.0d0, 0.0d0) go to 700 614 call xerrwv(40hlsode-- tout (=r1) behind t (=r2) , 1 40, 14, 0, 0, 0, 0, 2, tout, t) call xerrwv(50h integration direction is given by h0 (=r1) , 1 50, 14, 0, 0, 0, 0, 1, h0, 0.0d0) go to 700 615 call xerrwv(30hlsode-- hmax (=r1) .lt. 0.0 , 1 30, 15, 0, 0, 0, 0, 1, hmax, 0.0d0) go to 700 616 call xerrwv(30hlsode-- hmin (=r1) .lt. 0.0 , 1 30, 16, 0, 0, 0, 0, 1, hmin, 0.0d0) go to 700 617 call xerrwv( 1 60hlsode-- rwork length needed, lenrw (=i1), exceeds lrw (=i2), 1 60, 17, 0, 2, lenrw, lrw, 0, 0.0d0, 0.0d0) go to 700 618 call xerrwv( 1 60hlsode-- iwork length needed, leniw (=i1), exceeds liw (=i2), 1 60, 18, 0, 2, leniw, liw, 0, 0.0d0, 0.0d0) go to 700 619 call xerrwv(40hlsode-- rtol(i1) is r1 .lt. 0.0 , 1 40, 19, 0, 1, i, 0, 1, rtoli, 0.0d0) go to 700 620 call xerrwv(40hlsode-- atol(i1) is r1 .lt. 0.0 , 1 40, 20, 0, 1, i, 0, 1, atoli, 0.0d0) go to 700 621 ewti = rwork(lewt+i-1) call xerrwv(40hlsode-- ewt(i1) is r1 .le. 0.0 , 1 40, 21, 0, 1, i, 0, 1, ewti, 0.0d0) go to 700 622 call xerrwv( 1 60hlsode-- tout (=r1) too close to t(=r2) to start integration, 1 60, 22, 0, 0, 0, 0, 2, tout, t) go to 700 623 call xerrwv( 1 60hlsode-- itask = i1 and tout (=r1) behind tcur - hu (= r2) , 1 60, 23, 0, 1, itask, 0, 2, tout, tp) go to 700 624 call xerrwv( 1 60hlsode-- itask = 4 or 5 and tcrit (=r1) behind tcur (=r2) , 1 60, 24, 0, 0, 0, 0, 2, tcrit, tn) go to 700 625 call xerrwv( 1 60hlsode-- itask = 4 or 5 and tcrit (=r1) behind tout (=r2) , 1 60, 25, 0, 0, 0, 0, 2, tcrit, tout) go to 700 626 call xerrwv(50hlsode-- at start of problem, too much accuracy , 1 50, 26, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) call xerrwv( 1 60h requested for precision of machine.. see tolsf (=r1) , 1 60, 26, 0, 0, 0, 0, 1, tolsf, 0.0d0) rwork(14) = tolsf go to 700 627 call xerrwv(50hlsode-- trouble from intdy. itask = i1, tout = r1, 1 50, 27, 0, 1, itask, 0, 1, tout, 0.0d0) c 700 if (illin .eq. 5) go to 710 illin = illin + 1 istate = -3 return 710 call xerrwv(50hlsode-- repeated occurrences of illegal input , 1 50, 302, 0, 0, 0, 0, 0, 0.0d0, 0.0d0) c 800 call xerrwv(50hlsode-- run aborted.. apparent infinite loop , 1 50, 303, 2, 0, 0, 0, 0, 0.0d0, 0.0d0) return c----------------------- end of subroutine lsode ----------------------- end c subroutine solsy (wm, iwm, x, tem) clll. optimize integer iwm integer iownd, iowns, 1 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter, 2 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu integer i, meband, ml, mu double precision wm, x, tem double precision rowns, 1 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround double precision di, hl0, phl0, r dimension wm(1), iwm(1), x(1), tem(1) common /ls0001/ rowns(209), 2 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround, 3 iownd(14), iowns(6), 4 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter, 5 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu c----------------------------------------------------------------------- c this routine manages the solution of the linear system arising from c a chord iteration. it is called if miter .ne. 0. c if miter is 1 or 2, it calls dgesl to accomplish this. c if miter = 3 it updates the coefficient h*el0 in the diagonal c matrix, and then computes the solution. c if miter is 4 or 5, it calls dgbsl. c communication with solsy uses the following variables.. c wm = real work space containing the inverse diagonal matrix if c miter = 3 and the lu decomposition of the matrix otherwise. c storage of matrix elements starts at wm(3). c wm also contains the following matrix-related data.. c wm(1) = sqrt(uround) (not used here), c wm(2) = hl0, the previous value of h*el0, used if miter = 3. c iwm = integer work space containing pivot information, starting at c iwm(21), if miter is 1, 2, 4, or 5. iwm also contains band c parameters ml = iwm(1) and mu = iwm(2) if miter is 4 or 5. c x = the right-hand side vector on input, and the solution vector c on output, of length n. c tem = vector of work space of length n, not used in this version. c iersl = output flag (in common). iersl = 0 if no trouble occurred. c iersl = 1 if a singular matrix arose with miter = 3. c this routine also uses the common variables el0, h, miter, and n. c----------------------------------------------------------------------- iersl = 0 go to (100, 100, 300, 400, 400), miter 100 call dgesl (wm(3), n, n, iwm(21), x, 0) return c 300 phl0 = wm(2) hl0 = h*el0 wm(2) = hl0 if (hl0 .eq. phl0) go to 330 r = hl0/phl0 do 320 i = 1,n di = 1.0d0 - r*(1.0d0 - 1.0d0/wm(i+2)) if (dabs(di) .eq. 0.0d0) go to 390 320 wm(i+2) = 1.0d0/di 330 do 340 i = 1,n 340 x(i) = wm(i+2)*x(i) return 390 iersl = 1 return c 400 ml = iwm(1) mu = iwm(2) meband = 2*ml + mu + 1 call dgbsl (wm(3), meband, n, ml, mu, iwm(21), x, 0) return c----------------------- end of subroutine solsy ----------------------- end c subroutine prepj (neq, y, yh, nyh, ewt, ftem, savf, wm, iwm, 1 f, jac) clll. optimize external f, jac integer neq, nyh, iwm integer iownd, iowns, 1 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter, 2 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu integer i, i1, i2, ier, ii, j, j1, jj, lenp, 1 mba, mband, meb1, meband, ml, ml3, mu, np1 double precision y, yh, ewt, ftem, savf, wm double precision rowns, 1 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround double precision con, di, fac, hl0, r, r0, srur, yi, yj, yjj, 1 vnorm dimension neq(1), y(1), yh(nyh,1), ewt(1), ftem(1), savf(1), 1 wm(1), iwm(1) common /ls0001/ rowns(209), 2 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround, 3 iownd(14), iowns(6), 4 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter, 5 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu c----------------------------------------------------------------------- c prepj is called by stode to compute and process the matrix c p = i - h*el(1)*j , where j is an approximation to the jacobian. c here j is computed by the user-supplied routine jac if c miter = 1 or 4, or by finite differencing if miter = 2, 3, or 5. c if miter = 3, a diagonal approximation to j is used. c j is stored in wm and replaced by p. if miter .ne. 3, p is then c subjected to lu decomposition in preparation for later solution c of linear systems with p as coefficient matrix. this is done c by dgefa if miter = 1 or 2, and by dgbfa if miter = 4 or 5. c c in addition to variables described previously, communication c with prepj uses the following.. c y = array containing predicted values on entry. c ftem = work array of length n (acor in stode). c savf = array containing f evaluated at predicted y. c wm = real work space for matrices. on output it contains the c inverse diagonal matrix if miter = 3 and the lu decomposition c of p if miter is 1, 2 , 4, or 5. c storage of matrix elements starts at wm(3). c wm also contains the following matrix-related data.. c wm(1) = sqrt(uround), used in numerical jacobian increments. c wm(2) = h*el0, saved for later use if miter = 3. c iwm = integer work space containing pivot information, starting at c iwm(21), if miter is 1, 2, 4, or 5. iwm also contains band c parameters ml = iwm(1) and mu = iwm(2) if miter is 4 or 5. c el0 = el(1) (input). c ierpj = output error flag, = 0 if no trouble, .gt. 0 if c p matrix found to be singular. c jcur = output flag = 1 to indicate that the jacobian matrix c (or approximation) is now current. c this routine also uses the common variables el0, h, tn, uround, c miter, n, nfe, and nje. c----------------------------------------------------------------------- nje = nje + 1 ierpj = 0 jcur = 1 hl0 = h*el0 go to (100, 200, 300, 400, 500), miter c if miter = 1, call jac and multiply by scalar. ----------------------- 100 lenp = n*n do 110 i = 1,lenp 110 wm(i+2) = 0.0d0 call jac (neq, tn, y, 0, 0, wm(3), n) con = -hl0 do 120 i = 1,lenp 120 wm(i+2) = wm(i+2)*con go to 240 c if miter = 2, make n calls to f to approximate j. -------------------- 200 fac = vnorm (n, savf, ewt) r0 = 1000.0d0*dabs(h)*uround*n*fac if (r0 .eq. 0.0d0) r0 = 1.0d0 srur = wm(1) j1 = 2 do 230 j = 1,n yj = y(j) r = dmax1(srur*dabs(yj),r0/ewt(j)) y(j) = y(j) + r fac = -hl0/r call f (neq, tn, y, ftem) do 220 i = 1,n 220 wm(i+j1) = (ftem(i) - savf(i))*fac y(j) = yj j1 = j1 + n 230 continue nfe = nfe + n c add identity matrix. ------------------------------------------------- 240 j = 3 np1 = n + 1 do 250 i = 1,n wm(j) = wm(j) + 1.0d0 250 j = j + np1 c do lu decomposition on p. -------------------------------------------- call dgefa (wm(3), n, n, iwm(21), ier) if (ier .ne. 0) ierpj = 1 return c if miter = 3, construct a diagonal approximation to j and p. --------- 300 wm(2) = hl0 r = el0*0.1d0 do 310 i = 1,n 310 y(i) = y(i) + r*(h*savf(i) - yh(i,2)) call f (neq, tn, y, wm(3)) nfe = nfe + 1 do 320 i = 1,n r0 = h*savf(i) - yh(i,2) di = 0.1d0*r0 - h*(wm(i+2) - savf(i)) wm(i+2) = 1.0d0 if (dabs(r0) .lt. uround/ewt(i)) go to 320 if (dabs(di) .eq. 0.0d0) go to 330 wm(i+2) = 0.1d0*r0/di 320 continue return 330 ierpj = 1 return c if miter = 4, call jac and multiply by scalar. ----------------------- 400 ml = iwm(1) mu = iwm(2) ml3 = ml + 3 mband = ml + mu + 1 meband = mband + ml lenp = meband*n do 410 i = 1,lenp 410 wm(i+2) = 0.0d0 call jac (neq, tn, y, ml, mu, wm(ml3), meband) con = -hl0 do 420 i = 1,lenp 420 wm(i+2) = wm(i+2)*con go to 570 c if miter = 5, make mband calls to f to approximate j. ---------------- 500 ml = iwm(1) mu = iwm(2) mband = ml + mu + 1 mba = min0(mband,n) meband = mband + ml meb1 = meband - 1 srur = wm(1) fac = vnorm (n, savf, ewt) r0 = 1000.0d0*dabs(h)*uround*n*fac if (r0 .eq. 0.0d0) r0 = 1.0d0 do 560 j = 1,mba do 530 i = j,n,mband yi = y(i) r = dmax1(srur*dabs(yi),r0/ewt(i)) 530 y(i) = y(i) + r call f (neq, tn, y, ftem) do 550 jj = j,n,mband y(jj) = yh(jj,1) yjj = y(jj) r = dmax1(srur*dabs(yjj),r0/ewt(jj)) fac = -hl0/r i1 = max0(jj-mu,1) i2 = min0(jj+ml,n) ii = jj*meb1 - ml + 2 do 540 i = i1,i2 540 wm(ii+i) = (ftem(i) - savf(i))*fac 550 continue 560 continue nfe = nfe + mba c add identity matrix. ------------------------------------------------- 570 ii = mband + 2 do 580 i = 1,n wm(ii) = wm(ii) + 1.0d0 580 ii = ii + meband c do lu decomposition of p. -------------------------------------------- call dgbfa (wm(3), meband, n, ml, mu, iwm(21), ier) if (ier .ne. 0) ierpj = 1 return c----------------------- end of subroutine prepj ----------------------- end c subroutine stode (neq, y, yh, nyh, yh1, ewt, savf, acor, 1 wm, iwm, f, jac, pjac, slvs) clll. optimize external f, jac, pjac, slvs integer neq, nyh, iwm integer iownd, ialth, ipup, lmax, meo, nqnyh, nslp, 1 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter, 2 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu integer i, i1, iredo, iret, j, jb, m, ncf, newq double precision y, yh, yh1, ewt, savf, acor, wm double precision conit, crate, el, elco, hold, rmax, tesco, 2 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround double precision dcon, ddn, del, delp, dsm, dup, exdn, exsm, exup, 1 r, rh, rhdn, rhsm, rhup, told, vnorm dimension neq(1), y(1), yh(nyh,1), yh1(1), ewt(1), savf(1), 1 acor(1), wm(1), iwm(1) common /ls0001/ conit, crate, el(13), elco(13,12), 1 hold, rmax, tesco(3,12), 2 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround, iownd(14), 3 ialth, ipup, lmax, meo, nqnyh, nslp, 4 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter, 5 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu c----------------------------------------------------------------------- c stode performs one step of the integration of an initial value c problem for a system of ordinary differential equations. c note.. stode is independent of the value of the iteration method c indicator miter, when this is .ne. 0, and hence is independent c of the type of chord method used, or the jacobian structure. c communication with stode is done with the following variables.. c c neq = integer array containing problem size in neq(1), and c passed as the neq argument in all calls to f and jac. c y = an array of length .ge. n used as the y argument in c all calls to f and jac. c yh = an nyh by lmax array containing the dependent variables c and their approximate scaled derivatives, where c lmax = maxord + 1. yh(i,j+1) contains the approximate c j-th derivative of y(i), scaled by h**j/factorial(j) c (j = 0,1,...,nq). on entry for the first step, the first c two columns of yh must be set from the initial values. c nyh = a constant integer .ge. n, the first dimension of yh. c yh1 = a one-dimensional array occupying the same space as yh. c ewt = an array of length n containing multiplicative weights c for local error measurements. local errors in y(i) are c compared to 1.0/ewt(i) in various error tests. c savf = an array of working storage, of length n. c also used for input of yh(*,maxord+2) when jstart = -1 c and maxord .lt. the current order nq. c acor = a work array of length n, used for the accumulated c corrections. on a successful return, acor(i) contains c the estimated one-step local error in y(i). c wm,iwm = real and integer work arrays associated with matrix c operations in chord iteration (miter .ne. 0). c pjac = name of routine to evaluate and preprocess jacobian matrix c and p = i - h*el0*jac, if a chord method is being used. c slvs = name of routine to solve linear system in chord iteration. c ccmax = maximum relative change in h*el0 before pjac is called. c h = the step size to be attempted on the next step. c h is altered by the error control algorithm during the c problem. h can be either positive or negative, but its c sign must remain constant throughout the problem. c hmin = the minimum absolute value of the step size h to be used. c hmxi = inverse of the maximum absolute value of h to be used. c hmxi = 0.0 is allowed and corresponds to an infinite hmax. c hmin and hmxi may be changed at any time, but will not c take effect until the next change of h is considered. c tn = the independent variable. tn is updated on each step taken. c jstart = an integer used for input only, with the following c values and meanings.. c 0 perform the first step. c .gt.0 take a new step continuing from the last. c -1 take the next step with a new value of h, maxord, c n, meth, miter, and/or matrix parameters. c -2 take the next step with a new value of h, c but with other inputs unchanged. c on return, jstart is set to 1 to facilitate continuation. c kflag = a completion code with the following meanings.. c 0 the step was succesful. c -1 the requested error could not be achieved. c -2 corrector convergence could not be achieved. c -3 fatal error in pjac or slvs. c a return with kflag = -1 or -2 means either c abs(h) = hmin or 10 consecutive failures occurred. c on a return with kflag negative, the values of tn and c the yh array are as of the beginning of the last c step, and h is the last step size attempted. c maxord = the maximum order of integration method to be allowed. c maxcor = the maximum number of corrector iterations allowed. c msbp = maximum number of steps between pjac calls (miter .gt. 0). c mxncf = maximum number of convergence failures allowed. c meth/miter = the method flags. see description in driver. c n = the number of first-order differential equations. c----------------------------------------------------------------------- kflag = 0 told = tn ncf = 0 ierpj = 0 iersl = 0 jcur = 0 icf = 0 delp = 0.0d0 if (jstart .gt. 0) go to 200 if (jstart .eq. -1) go to 100 if (jstart .eq. -2) go to 160 c----------------------------------------------------------------------- c on the first call, the order is set to 1, and other variables are c initialized. rmax is the maximum ratio by which h can be increased c in a single step. it is initially 1.e4 to compensate for the small c initial h, but then is normally equal to 10. if a failure c occurs (in corrector convergence or error test), rmax is set at 2 c for the next increase. c----------------------------------------------------------------------- lmax = maxord + 1 nq = 1 l = 2 ialth = 2 rmax = 10000.0d0 rc = 0.0d0 el0 = 1.0d0 crate = 0.7d0 hold = h meo = meth nslp = 0 ipup = miter iret = 3 go to 140 c----------------------------------------------------------------------- c the following block handles preliminaries needed when jstart = -1. c ipup is set to miter to force a matrix update. c if an order increase is about to be considered (ialth = 1), c ialth is reset to 2 to postpone consideration one more step. c if the caller has changed meth, cfode is called to reset c the coefficients of the method. c if the caller has changed maxord to a value less than the current c order nq, nq is reduced to maxord, and a new h chosen accordingly. c if h is to be changed, yh must be rescaled. c if h or meth is being changed, ialth is reset to l = nq + 1 c to prevent further changes in h for that many steps. c----------------------------------------------------------------------- 100 ipup = miter lmax = maxord + 1 if (ialth .eq. 1) ialth = 2 if (meth .eq. meo) go to 110 call cfode (meth, elco, tesco) meo = meth if (nq .gt. maxord) go to 120 ialth = l iret = 1 go to 150 110 if (nq .le. maxord) go to 160 120 nq = maxord l = lmax do 125 i = 1,l 125 el(i) = elco(i,nq) nqnyh = nq*nyh rc = rc*el(1)/el0 el0 = el(1) conit = 0.5d0/(nq+2) ddn = vnorm (n, savf, ewt)/tesco(1,l) exdn = 1.0d0/l rhdn = 1.0d0/(1.3d0*ddn**exdn + 0.0000013d0) rh = dmin1(rhdn,1.0d0) iredo = 3 if (h .eq. hold) go to 170 rh = dmin1(rh,dabs(h/hold)) h = hold go to 175 c----------------------------------------------------------------------- c cfode is called to get all the integration coefficients for the c current meth. then the el vector and related constants are reset c whenever the order nq is changed, or at the start of the problem. c----------------------------------------------------------------------- 140 call cfode (meth, elco, tesco) 150 do 155 i = 1,l 155 el(i) = elco(i,nq) nqnyh = nq*nyh rc = rc*el(1)/el0 el0 = el(1) conit = 0.5d0/(nq+2) go to (160, 170, 200), iret c----------------------------------------------------------------------- c if h is being changed, the h ratio rh is checked against c rmax, hmin, and hmxi, and the yh array rescaled. ialth is set to c l = nq + 1 to prevent a change of h for that many steps, unless c forced by a convergence or error test failure. c----------------------------------------------------------------------- 160 if (h .eq. hold) go to 200 rh = h/hold h = hold iredo = 3 go to 175 170 rh = dmax1(rh,hmin/dabs(h)) 175 rh = dmin1(rh,rmax) rh = rh/dmax1(1.0d0,dabs(h)*hmxi*rh) r = 1.0d0 do 180 j = 2,l r = r*rh do 180 i = 1,n 180 yh(i,j) = yh(i,j)*r h = h*rh rc = rc*rh ialth = l if (iredo .eq. 0) go to 690 c----------------------------------------------------------------------- c this section computes the predicted values by effectively c multiplying the yh array by the pascal triangle matrix. c rc is the ratio of new to old values of the coefficient h*el(1). c when rc differs from 1 by more than ccmax, ipup is set to miter c to force pjac to be called, if a jacobian is involved. c in any case, pjac is called at least every msbp steps. c----------------------------------------------------------------------- 200 if (dabs(rc-1.0d0) .gt. ccmax) ipup = miter if (nst .ge. nslp+msbp) ipup = miter tn = tn + h i1 = nqnyh + 1 do 215 jb = 1,nq i1 = i1 - nyh cdir$ ivdep do 210 i = i1,nqnyh 210 yh1(i) = yh1(i) + yh1(i+nyh) 215 continue c----------------------------------------------------------------------- c up to maxcor corrector iterations are taken. a convergence test is c made on the r.m.s. norm of each correction, weighted by the error c weight vector ewt. the sum of the corrections is accumulated in the c vector acor(i). the yh array is not altered in the corrector loop. c----------------------------------------------------------------------- 220 m = 0 do 230 i = 1,n 230 y(i) = yh(i,1) call f (neq, tn, y, savf) nfe = nfe + 1 if (ipup .le. 0) go to 250 c----------------------------------------------------------------------- c if indicated, the matrix p = i - h*el(1)*j is reevaluated and c preprocessed before starting the corrector iteration. ipup is set c to 0 as an indicator that this has been done. c----------------------------------------------------------------------- call pjac (neq, y, yh, nyh, ewt, acor, savf, wm, iwm, f, jac) ipup = 0 rc = 1.0d0 nslp = nst crate = 0.7d0 if (ierpj .ne. 0) go to 430 250 do 260 i = 1,n 260 acor(i) = 0.0d0 270 if (miter .ne. 0) go to 350 c----------------------------------------------------------------------- c in the case of functional iteration, update y directly from c the result of the last function evaluation. c----------------------------------------------------------------------- do 290 i = 1,n savf(i) = h*savf(i) - yh(i,2) 290 y(i) = savf(i) - acor(i) del = vnorm (n, y, ewt) do 300 i = 1,n y(i) = yh(i,1) + el(1)*savf(i) 300 acor(i) = savf(i) go to 400 c----------------------------------------------------------------------- c in the case of the chord method, compute the corrector error, c and solve the linear system with that as right-hand side and c p as coefficient matrix. c----------------------------------------------------------------------- 350 do 360 i = 1,n 360 y(i) = h*savf(i) - (yh(i,2) + acor(i)) call slvs (wm, iwm, y, savf) if (iersl .lt. 0) go to 430 if (iersl .gt. 0) go to 410 del = vnorm (n, y, ewt) do 380 i = 1,n acor(i) = acor(i) + y(i) 380 y(i) = yh(i,1) + el(1)*acor(i) c----------------------------------------------------------------------- c test for convergence. if m.gt.0, an estimate of the convergence c rate constant is stored in crate, and this is used in the test. c----------------------------------------------------------------------- 400 if (m .ne. 0) crate = dmax1(0.2d0*crate,del/delp) dcon = del*dmin1(1.0d0,1.5d0*crate)/(tesco(2,nq)*conit) if (dcon .le. 1.0d0) go to 450 m = m + 1 if (m .eq. maxcor) go to 410 if (m .ge. 2 .and. del .gt. 2.0d0*delp) go to 410 delp = del call f (neq, tn, y, savf) nfe = nfe + 1 go to 270 c----------------------------------------------------------------------- c the corrector iteration failed to converge. c if miter .ne. 0 and the jacobian is out of date, pjac is called for c the next try. otherwise the yh array is retracted to its values c before prediction, and h is reduced, if possible. if h cannot be c reduced or mxncf failures have occurred, exit with kflag = -2. c----------------------------------------------------------------------- 410 if (miter .eq. 0 .or. jcur .eq. 1) go to 430 icf = 1 ipup = miter go to 220 430 icf = 2 ncf = ncf + 1 rmax = 2.0d0 tn = told i1 = nqnyh + 1 do 445 jb = 1,nq i1 = i1 - nyh cdir$ ivdep do 440 i = i1,nqnyh 440 yh1(i) = yh1(i) - yh1(i+nyh) 445 continue if (ierpj .lt. 0 .or. iersl .lt. 0) go to 680 if (dabs(h) .le. hmin*1.00001d0) go to 670 if (ncf .eq. mxncf) go to 670 rh = 0.25d0 ipup = miter iredo = 1 go to 170 c----------------------------------------------------------------------- c the corrector has converged. jcur is set to 0 c to signal that the jacobian involved may need updating later. c the local error test is made and control passes to statement 500 c if it fails. c----------------------------------------------------------------------- 450 jcur = 0 if (m .eq. 0) dsm = del/tesco(2,nq) if (m .gt. 0) dsm = vnorm (n, acor, ewt)/tesco(2,nq) if (dsm .gt. 1.0d0) go to 500 c----------------------------------------------------------------------- c after a successful step, update the yh array. c consider changing h if ialth = 1. otherwise decrease ialth by 1. c if ialth is then 1 and nq .lt. maxord, then acor is saved for c use in a possible order increase on the next step. c if a change in h is considered, an increase or decrease in order c by one is considered also. a change in h is made only if it is by a c factor of at least 1.1. if not, ialth is set to 3 to prevent c testing for that many steps. c----------------------------------------------------------------------- kflag = 0 iredo = 0 nst = nst + 1 hu = h nqu = nq do 470 j = 1,l do 470 i = 1,n 470 yh(i,j) = yh(i,j) + el(j)*acor(i) ialth = ialth - 1 if (ialth .eq. 0) go to 520 if (ialth .gt. 1) go to 700 if (l .eq. lmax) go to 700 do 490 i = 1,n 490 yh(i,lmax) = acor(i) go to 700 c----------------------------------------------------------------------- c the error test failed. kflag keeps track of multiple failures. c restore tn and the yh array to their previous values, and prepare c to try the step again. compute the optimum step size for this or c one lower order. after 2 or more failures, h is forced to decrease c by a factor of 0.2 or less. c----------------------------------------------------------------------- 500 kflag = kflag - 1 tn = told i1 = nqnyh + 1 do 515 jb = 1,nq i1 = i1 - nyh cdir$ ivdep do 510 i = i1,nqnyh 510 yh1(i) = yh1(i) - yh1(i+nyh) 515 continue rmax = 2.0d0 if (dabs(h) .le. hmin*1.00001d0) go to 660 if (kflag .le. -3) go to 640 iredo = 2 rhup = 0.0d0 go to 540 c----------------------------------------------------------------------- c regardless of the success or failure of the step, factors c rhdn, rhsm, and rhup are computed, by which h could be multiplied c at order nq - 1, order nq, or order nq + 1, respectively. c in the case of failure, rhup = 0.0 to avoid an order increase. c the largest of these is determined and the new order chosen c accordingly. if the order is to be increased, we compute one c additional scaled derivative. c----------------------------------------------------------------------- 520 rhup = 0.0d0 if (l .eq. lmax) go to 540 do 530 i = 1,n 530 savf(i) = acor(i) - yh(i,lmax) dup = vnorm (n, savf, ewt)/tesco(3,nq) exup = 1.0d0/(l+1) rhup = 1.0d0/(1.4d0*dup**exup + 0.0000014d0) 540 exsm = 1.0d0/l rhsm = 1.0d0/(1.2d0*dsm**exsm + 0.0000012d0) rhdn = 0.0d0 if (nq .eq. 1) go to 560 ddn = vnorm (n, yh(1,l), ewt)/tesco(1,nq) exdn = 1.0d0/nq rhdn = 1.0d0/(1.3d0*ddn**exdn + 0.0000013d0) 560 if (rhsm .ge. rhup) go to 570 if (rhup .gt. rhdn) go to 590 go to 580 570 if (rhsm .lt. rhdn) go to 580 newq = nq rh = rhsm go to 620 580 newq = nq - 1 rh = rhdn if (kflag .lt. 0 .and. rh .gt. 1.0d0) rh = 1.0d0 go to 620 590 newq = l rh = rhup if (rh .lt. 1.1d0) go to 610 r = el(l)/l do 600 i = 1,n 600 yh(i,newq+1) = acor(i)*r go to 630 610 ialth = 3 go to 700 620 if ((kflag .eq. 0) .and. (rh .lt. 1.1d0)) go to 610 if (kflag .le. -2) rh = dmin1(rh,0.2d0) c----------------------------------------------------------------------- c if there is a change of order, reset nq, l, and the coefficients. c in any case h is reset according to rh and the yh array is rescaled. c then exit from 690 if the step was ok, or redo the step otherwise. c----------------------------------------------------------------------- if (newq .eq. nq) go to 170 630 nq = newq l = nq + 1 iret = 2 go to 150 c----------------------------------------------------------------------- c control reaches this section if 3 or more failures have occured. c if 10 failures have occurred, exit with kflag = -1. c it is assumed that the derivatives that have accumulated in the c yh array have errors of the wrong order. hence the first c derivative is recomputed, and the order is set to 1. then c h is reduced by a factor of 10, and the step is retried, c until it succeeds or h reaches hmin. c----------------------------------------------------------------------- 640 if (kflag .eq. -10) go to 660 rh = 0.1d0 rh = dmax1(hmin/dabs(h),rh) h = h*rh do 645 i = 1,n 645 y(i) = yh(i,1) call f (neq, tn, y, savf) nfe = nfe + 1 do 650 i = 1,n 650 yh(i,2) = h*savf(i) ipup = miter ialth = 5 if (nq .eq. 1) go to 200 nq = 1 l = 2 iret = 3 go to 150 c----------------------------------------------------------------------- c all returns are made through this section. h is saved in hold c to allow the caller to change h on the next step. c----------------------------------------------------------------------- 660 kflag = -1 go to 720 670 kflag = -2 go to 720 680 kflag = -3 go to 720 690 rmax = 10.0d0 700 r = 1.0d0/tesco(2,nqu) do 710 i = 1,n 710 acor(i) = acor(i)*r 720 hold = h jstart = 1 return c----------------------- end of subroutine stode ----------------------- end c double precision function vnorm (n, v, w) clll. optimize c----------------------------------------------------------------------- c this function routine computes the weighted root-mean-square norm c of the vector of length n contained in the array v, with weights c contained in the array w of length n.. c vnorm = sqrt( (1/n) * sum( v(i)*w(i) )**2 ) c----------------------------------------------------------------------- integer n, i double precision v, w, sum dimension v(n), w(n) sum = 0.0d0 do 10 i = 1,n 10 sum = sum + (v(i)*w(i))**2 vnorm = dsqrt(sum/n) return c----------------------- end of function vnorm ------------------------- end c subroutine cfode (meth, elco, tesco) clll. optimize integer meth integer i, ib, nq, nqm1, nqp1 double precision elco, tesco double precision agamq, fnq, fnqm1, pc, pint, ragq, 1 rqfac, rq1fac, tsign, xpin dimension elco(13,12), tesco(3,12) c----------------------------------------------------------------------- c cfode is called by the integrator routine to set coefficients c needed there. the coefficients for the current method, as c given by the value of meth, are set for all orders and saved. c the maximum order assumed here is 12 if meth = 1 and 5 if meth = 2. c (a smaller value of the maximum order is also allowed.) c cfode is called once at the beginning of the problem, c and is not called again unless and until meth is changed. c c the elco array contains the basic method coefficients. c the coefficients el(i), 1 .le. i .le. nq+1, for the method of c order nq are stored in elco(i,nq). they are given by a genetrating c polynomial, i.e., c l(x) = el(1) + el(2)*x + ... + el(nq+1)*x**nq. c for the implicit adams methods, l(x) is given by c dl/dx = (x+1)*(x+2)*...*(x+nq-1)/factorial(nq-1), l(-1) = 0. c for the bdf methods, l(x) is given by c l(x) = (x+1)*(x+2)* ... *(x+nq)/k, c where k = factorial(nq)*(1 + 1/2 + ... + 1/nq). c c the tesco array contains test constants used for the c local error test and the selection of step size and/or order. c at order nq, tesco(k,nq) is used for the selection of step c size at order nq - 1 if k = 1, at order nq if k = 2, and at order c nq + 1 if k = 3. c----------------------------------------------------------------------- dimension pc(12) c go to (100, 200), meth c 100 elco(1,1) = 1.0d0 elco(2,1) = 1.0d0 tesco(1,1) = 0.0d0 tesco(2,1) = 2.0d0 tesco(1,2) = 1.0d0 tesco(3,12) = 0.0d0 pc(1) = 1.0d0 rqfac = 1.0d0 do 140 nq = 2,12 c----------------------------------------------------------------------- c the pc array will contain the coefficients of the polynomial c p(x) = (x+1)*(x+2)*...*(x+nq-1). c initially, p(x) = 1. c----------------------------------------------------------------------- rq1fac = rqfac rqfac = rqfac/nq nqm1 = nq - 1 fnqm1 = nqm1 nqp1 = nq + 1 c form coefficients of p(x)*(x+nq-1). ---------------------------------- pc(nq) = 0.0d0 do 110 ib = 1,nqm1 i = nqp1 - ib 110 pc(i) = pc(i-1) + fnqm1*pc(i) pc(1) = fnqm1*pc(1) c compute integral, -1 to 0, of p(x) and x*p(x). ----------------------- pint = pc(1) xpin = pc(1)/2.0d0 tsign = 1.0d0 do 120 i = 2,nq tsign = -tsign pint = pint + tsign*pc(i)/i 120 xpin = xpin + tsign*pc(i)/(i+1) c store coefficients in elco and tesco. -------------------------------- elco(1,nq) = pint*rq1fac elco(2,nq) = 1.0d0 do 130 i = 2,nq 130 elco(i+1,nq) = rq1fac*pc(i)/i agamq = rqfac*xpin ragq = 1.0d0/agamq tesco(2,nq) = ragq if (nq .lt. 12) tesco(1,nqp1) = ragq*rqfac/nqp1 tesco(3,nqm1) = ragq 140 continue return c 200 pc(1) = 1.0d0 rq1fac = 1.0d0 do 230 nq = 1,5 c----------------------------------------------------------------------- c the pc array will contain the coefficients of the polynomial c p(x) = (x+1)*(x+2)*...*(x+nq). c initially, p(x) = 1. c----------------------------------------------------------------------- fnq = nq nqp1 = nq + 1 c form coefficients of p(x)*(x+nq). ------------------------------------ pc(nqp1) = 0.0d0 do 210 ib = 1,nq i = nq + 2 - ib 210 pc(i) = pc(i-1) + fnq*pc(i) pc(1) = fnq*pc(1) c store coefficients in elco and tesco. -------------------------------- do 220 i = 1,nqp1 220 elco(i,nq) = pc(i)/pc(2) elco(2,nq) = 1.0d0 tesco(1,nq) = rq1fac tesco(2,nq) = nqp1/elco(1,nq) tesco(3,nq) = (nq+2)/elco(1,nq) rq1fac = rq1fac/fnq 230 continue return c----------------------- end of subroutine cfode ----------------------- end c subroutine intdy (t, k, yh, nyh, dky, iflag) clll. optimize integer k, nyh, iflag integer iownd, iowns, 1 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter, 2 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu integer i, ic, j, jb, jb2, jj, jj1, jp1 double precision t, yh, dky double precision rowns, 1 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround double precision c, r, s, tp dimension yh(nyh,1), dky(1) common /ls0001/ rowns(209), 2 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround, 3 iownd(14), iowns(6), 4 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter, 5 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu c----------------------------------------------------------------------- c intdy computes interpolated values of the k-th derivative of the c dependent variable vector y, and stores it in dky. this routine c is called within the package with k = 0 and t = tout, but may c also be called by the user for any k up to the current order. c (see detailed instructions in the usage documentation.) c----------------------------------------------------------------------- c the computed values in dky are gotten by interpolation using the c nordsieck history array yh. this array corresponds uniquely to a c vector-valued polynomial of degree nqcur or less, and dky is set c to the k-th derivative of this polynomial at t. c the formula for dky is.. c q c dky(i) = sum c(j,k) * (t - tn)**(j-k) * h**(-j) * yh(i,j+1) c j=k c where c(j,k) = j*(j-1)*...*(j-k+1), q = nqcur, tn = tcur, h = hcur. c the quantities nq = nqcur, l = nq+1, n = neq, tn, and h are c communicated by common. the above sum is done in reverse order. c iflag is returned negative if either k or t is out of bounds. c----------------------------------------------------------------------- iflag = 0 if (k .lt. 0 .or. k .gt. nq) go to 80 tp = tn - hu - 100.0d0*uround*(tn + hu) if ((t-tp)*(t-tn) .gt. 0.0d0) go to 90 c s = (t - tn)/h ic = 1 if (k .eq. 0) go to 15 jj1 = l - k do 10 jj = jj1,nq 10 ic = ic*jj 15 c = ic do 20 i = 1,n 20 dky(i) = c*yh(i,l) if (k .eq. nq) go to 55 jb2 = nq - k do 50 jb = 1,jb2 j = nq - jb jp1 = j + 1 ic = 1 if (k .eq. 0) go to 35 jj1 = jp1 - k do 30 jj = jj1,j 30 ic = ic*jj 35 c = ic do 40 i = 1,n 40 dky(i) = c*yh(i,jp1) + s*dky(i) 50 continue if (k .eq. 0) return 55 r = h**(-k) do 60 i = 1,n 60 dky(i) = r*dky(i) return c 80 call xerrwv(30hintdy-- k (=i1) illegal , 1 30, 51, 0, 1, k, 0, 0, 0.0d0, 0.0d0) iflag = -1 return 90 call xerrwv(30hintdy-- t (=r1) illegal , 1 30, 52, 0, 0, 0, 0, 1, t, 0.0d0) call xerrwv( 1 60h t not in interval tcur - hu (= r1) to tcur (=r2) , 1 60, 52, 0, 0, 0, 0, 2, tp, tn) iflag = -2 return c----------------------- end of subroutine intdy ----------------------- end c subroutine xerrwv (msg, nmes, nerr, level, ni, i1, i2, nr, r1, r2) integer msg, nmes, nerr, level, ni, i1, i2, nr, 1 i, lun, lunit, mesflg, ncpw, nch, nwds double precision r1, r2 dimension msg(nmes) c----------------------------------------------------------------------- c subroutines xerrwv, xsetf, and xsetun, as given here, constitute c a simplified version of the slatec error handling package. c written by a. c. hindmarsh at llnl. version of march 30, 1987. c this version is in double precision. c c all arguments are input arguments. c c msg = the message (hollerith literal or integer array). c nmes = the length of msg (number of characters). c nerr = the error number (not used). c level = the error level.. c 0 or 1 means recoverable (control returns to caller). c 2 means fatal (run is aborted--see note below). c ni = number of integers (0, 1, or 2) to be printed with message. c i1,i2 = integers to be printed, depending on ni. c nr = number of reals (0, 1, or 2) to be printed with message. c r1,r2 = reals to be printed, depending on nr. c c note.. this routine is machine-dependent and specialized for use c in limited context, in the following ways.. c 1. the number of hollerith characters stored per word, denoted c by ncpw below, is a data-loaded constant. c 2. the value of nmes is assumed to be at most 60. c (multi-line messages are generated by repeated calls.) c 3. if level = 2, control passes to the statement stop c to abort the run. this statement may be machine-dependent. c 4. r1 and r2 are assumed to be in double precision and are printed c in d21.13 format. c 5. the common block /eh0001/ below is data-loaded (a machine- c dependent feature) with default values. c this block is needed for proper retention of parameters used by c this routine which the user can reset by calling xsetf or xsetun. c the variables in this block are as follows.. c mesflg = print control flag.. c 1 means print all messages (the default). c 0 means no printing. c lunit = logical unit number for messages. c the default is 6 (machine-dependent). c----------------------------------------------------------------------- c the following are instructions for installing this routine c in different machine environments. c c to change the default output unit, change the data statement c in the block data subprogram below. c c for a different number of characters per word, change the c data statement setting ncpw below, and format 10. alternatives for c various computers are shown in comment cards. c c for a different run-abort command, change the statement following c statement 100 at the end. c----------------------------------------------------------------------- common /eh0001/ mesflg, lunit c----------------------------------------------------------------------- c the following data-loaded value of ncpw is valid for the cdc-6600 c and cdc-7600 computers. c data ncpw/10/ c the following is valid for the cray-1 computer. c data ncpw/8/ c the following is valid for the burroughs 6700 and 7800 computers. c data ncpw/6/ c the following is valid for the pdp-10 computer. c data ncpw/5/ c the following is valid for the vax computer with 4 bytes per integer, c and for the ibm-360, ibm-370, ibm-303x, and ibm-43xx computers. data ncpw/4/ c the following is valid for the pdp-11, or vax with 2-byte integers. c data ncpw/2/ c----------------------------------------------------------------------- if (mesflg .eq. 0) go to 100 c get logical unit number. --------------------------------------------- lun = lunit c get number of words in message. -------------------------------------- nch = min0(nmes,60) nwds = nch/ncpw if (nch .ne. nwds*ncpw) nwds = nwds + 1 c write the message. --------------------------------------------------- write (lun, 10) (msg(i),i=1,nwds) c----------------------------------------------------------------------- c the following format statement is to have the form c 10 format(1x,mmann) c where nn = ncpw and mm is the smallest integer .ge. 60/ncpw. c the following is valid for ncpw = 10. c 10 format(1x,6a10) c the following is valid for ncpw = 8. c 10 format(1x,8a8) c the following is valid for ncpw = 6. c 10 format(1x,10a6) c the following is valid for ncpw = 5. c 10 format(1x,12a5) c the following is valid for ncpw = 4. 10 format(1x,15a4) c the following is valid for ncpw = 2. c 10 format(1x,30a2) c----------------------------------------------------------------------- if (ni .eq. 1) write (lun, 20) i1 20 format(6x,23hin above message, i1 =,i10) if (ni .eq. 2) write (lun, 30) i1,i2 30 format(6x,23hin above message, i1 =,i10,3x,4hi2 =,i10) if (nr .eq. 1) write (lun, 40) r1 40 format(6x,23hin above message, r1 =,d21.13) if (nr .eq. 2) write (lun, 50) r1,r2 50 format(6x,15hin above, r1 =,d21.13,3x,4hr2 =,d21.13) c abort the run if level = 2. ------------------------------------------ 100 if (level .ne. 2) return stop c----------------------- end of subroutine xerrwv ---------------------- end c block data c----------------------------------------------------------------------- c this data subprogram loads variables into the internal common c blocks used by the odepack solvers. the variables are c defined as follows.. c illin = counter for the number of consecutive times the package c was called with illegal input. the run is stopped when c illin reaches 5. c ntrep = counter for the number of consecutive times the package c was called with istate = 1 and tout = t. the run is c stopped when ntrep reaches 5. c mesflg = flag to control printing of error messages. 1 means print, c 0 means no printing. c lunit = default value of logical unit number for printing of error c messages. c----------------------------------------------------------------------- integer illin, iduma, ntrep, idumb, iowns, icomm, mesflg, lunit double precision rowns, rcomm common /ls0001/ rowns(209), rcomm(9), 1 illin, iduma(10), ntrep, idumb(2), iowns(6), icomm(19) common /eh0001/ mesflg, lunit data illin/0/, ntrep/0/ data mesflg/1/, lunit/6/ c c----------------------- end of block data ----------------------------- end c subroutine ewset (n, itol, rtol, atol, ycur, ewt) clll. optimize c----------------------------------------------------------------------- c this subroutine sets the error weight vector ewt according to c ewt(i) = rtol(i)*abs(ycur(i)) + atol(i), i = 1,...,n, c with the subscript on rtol and/or atol possibly replaced by 1 above, c depending on the value of itol. c----------------------------------------------------------------------- integer n, itol integer i double precision rtol, atol, ycur, ewt dimension rtol(1), atol(1), ycur(n), ewt(n) c go to (10, 20, 30, 40), itol 10 continue do 15 i = 1,n 15 ewt(i) = rtol(1)*dabs(ycur(i)) + atol(1) return 20 continue do 25 i = 1,n 25 ewt(i) = rtol(1)*dabs(ycur(i)) + atol(i) return 30 continue do 35 i = 1,n 35 ewt(i) = rtol(i)*dabs(ycur(i)) + atol(1) return 40 continue do 45 i = 1,n 45 ewt(i) = rtol(i)*dabs(ycur(i)) + atol(i) return c----------------------- end of subroutine ewset ----------------------- end c DOUBLE PRECISION FUNCTION D1MACH (IDUM) INTEGER IDUM C----------------------------------------------------------------------- C This routine computes the unit roundoff of the machine. C This is defined as the smallest positive machine number C u such that 1.0 + u .ne. 1.0 C C Subroutines/functions called by D1MACH.. None C----------------------------------------------------------------------- DOUBLE PRECISION U, COMP U = 1.0D0 10 U = U*0.5D0 COMP = 1.0D0 + U IF (COMP .NE. 1.0D0) GO TO 10 D1MACH = U*2.0D0 RETURN C----------------------- End of Function D1MACH ------------------------ END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT VANDERPOL PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=2,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),true(nd), + error(nd) REAL*4 TARRAY(2) EXTERNAL FVANDER,JVANDER c ------ FILE DE DONNEES ---------- write(6,3080) 3080 format(1x,'results for lsode on vdp') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP summ=0.0D+0 summh=0.0D+0 C --- DIMENSION OF THE SYSTEM N=2 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 MF=21 C --- INITIAL VALUES X=0.0D0 Y(1)=2.0D0 Y(2)=0.0D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=10000 C --- ENDPOINT OF INTEGRATION XEND=1.0D0 c CALL DTIME(TARRAY) it1=mclock() DO 20 I=1,11 C --- CALL OF THE SUBROUTINE CALL LSODE(FVANDER,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JVANDER,MF) C --- PRINT SOLUTION c WRITE (6,*) Y(1) c WRITE (6,*) Y(2) XEND=XEND+1.D0 if(i.eq.1) then true(1)=-0.1863646254808130E+01 true(2)= 0.7535430865435460E+00 else if(i.eq.2) then true(1)= 0.1706167732170456E+01 true(2)= -0.8928097010248257E+00 else if(i.eq.3) then true(1)= -0.1510606936744095E+01 true(2)= 0.1178380000730945E+01 else if(i.eq.4) then true(1)= 0.1194414677695905E+01 true(2)= -0.2799585996540082E+01 else if(i.eq.5) then true(1)= 0.1890428596416747E+01 true(2)= -0.7345118680166940E+00 else if(i.eq.6) then true(1)=-0.1737716306805883E+01 true(2)= 0.8604008653025923E+00 else if(i.eq.7) then true(1)= 0.1551614645548223E+01 true(2)= -0.1102382892533321E+01 else if(i.eq.8) then true(1)=-0.1278631984330405E+01 true(2)= 0.2013890883009155E+01 else if(i.eq.9) then true(1)= -0.1916552949489830E+01 true(2)= 0.7169573003463228E+00 else if(i.eq.10) then true(1)= 0.1768163792391936E+01 true(2)=-0.8315276407898496E+00 else if(i.eq.11) then true(1)=-0.1590150544829062E+01 true(2)= 0.1040279389212485E+01 endif sum=0.0D+0 do 270 k=1,2 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 continue it2=mclock() tarray(1)=(it2-it1)/100.0D+0 write(6,*) x,y(1),y(2) WRITE(6,*)TARRAY(1),summ,sumh/11.0d+0 summ=summ*atol sumh=sumh*atol/(11.0D+0) write(6,*) summ,sumh ID=0 WRITE(6,*)ID,ID,ID,ID,ID,ID,ID WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' write(6,91) iwork(12),iwork(13),iwork(11),id,id,iwork(13),id 91 format(' fcn =',i5,' jac =' ,i4,' step=',i4, + 'accept=',i4,'reject=', i4, 'dec=',i4, 'sol=',i4) C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE STOP END c SUBROUTINE FVANDER(N,X,Y,F) C --- RIGHT-HAND SIDE OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),F(N) EPS=1.D-6 F(1)=Y(2) PROD=1.D0-Y(1)*Y(1) F(2)=(PROD*Y(2)-Y(1))/EPS RETURN END C SUBROUTINE JVANDER(N,X,Y,ML,MU,DFY,LDFY) C --- JACOBIAN OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(LDFY,N) EPS=1.D-6 DFY(1,1)=0.D0 DFY(1,2)=1.D0 DFY(2,1)=(-2.0D0*Y(1)*Y(2)-1.0D0)/EPS DFY(2,2)=(1.0D0-Y(1)**2)/EPS RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT ROBERTSON PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * compile equation_lsode compile //venus/user/hairer/hailib/time cfeh driver_lsode //venus/user/hairer/programme/lsode/lsode equation_lsode time IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=3,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),true(nd), + error(nd) REAL*4 TARRAY(2) EXTERNAL FROBER,JROBER c ------ FILE DE DONNEES ---------- write(6,3500) 3500 format(1x,'results on robertson by lsode') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP summ=0.0D+0 sumh=0.0D+0 C --- DIMENSION OF THE SYSTEM N=3 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE= 2 istate=1 IOPT=0 iopt=1 MF=21 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=10000 C --- INITIAL VALUES X=0.0D0 Y(1)=1.0D0 Y(2)=0.0D0 Y(3)=0.0D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=1.0D-6*RTOL ITOL=1 C --- ENDPOINT OF INTEGRATION XEND=1.0D0 c CALL DTIME(TARRAY) it1=mclock() DO 20 I=1,12 C --- CALL OF THE SUBROUTINE CALL LSODE(FROBER,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JROBER,MF) C --- PRINT SOLUTION c WRITE (8,*) Y(1) c WRITE (8,*) Y(2) c WRITE (8,*) Y(3) XEND=XEND*10.D0 c CALL DTIME(TARRAY) if(i.eq.1) then true(1)= 0.9664597373330035E+00 true(2)=0.3074626578578675E-04 true(3)=0.3350951640121071E-01 else if(i.eq.2) then true(1)=0.8413699238414729E+00 true(2)=0.1623390937990473E-04 true(3)=0.1586138422491472E+00 else if(i.eq.3) then true(1)=0.6172348823960878E+00 true(2)=0.6153591274639123E-05 true(3)=0.3827589640126376E+00 else if(i.eq.4) then true(1)=0.3368745306607069E+00 true(2)=0.2013702318261393E-05 true(3)=0.6631234556369748E+00 else if(i.eq.5) then true(1)=0.1073004285378040E+00 true(2)=0.4800166972571660E-06 true(3)=0.8926990914454987E+00 else if(i.eq.6) then true(1)=0.1786592114209946E-01 true(2)=0.7274751468436319E-07 true(3)=0.9821340061103859E+00 else if(i.eq.7) then true(1)= 0.2031483924973415E-02 true(2)=0.8142277783356159E-08 true(3)=0.9979685079327488E+00 else if(i.eq.8) then true(1)=0.2076093439016395E-03 true(2)=0.8306077485067610E-09 true(3)=0.9997923898254906E+00 else if(i.eq.9) then true(1)=0.2082417512179460E-04 true(2)=0.8329841429908955E-10 true(3)=0.9999791757415798E+00 else if(i.eq.10) then true(1)=0.2083229471647004E-05 true(2)=0.8332935037760723E-11 true(3)=0.9999979167621954E+00 else if(i.eq.11) then true(1)=0.2083328471883087E-06 true(2)=0.8333315602809495E-12 true(3)=0.9999997916663195E+00 else if(i.eq.12) then true(1)=0.2083340149701284E-07 true(2)=0.8333360770334744E-13 true(3)=0.9999999791665152E+00 end if sum=0.0d+0 do 270 k=1,3 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 CONTINUE CCC CALL DTIME(TARRAY) it2=mclock() tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh/12.0D+0 summ=summ*atol sumh=sumh*atol/12.0D+0 write(6,*) SUMM,SUMH ID=0 WRITE(6,*)IWORK(12),IWORK(13),IWORK(11),ID,ID,IWORK(13),ID WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' WRITE(6,91)IWORK(12),IWORK(13),IWORK(11),ID,ID,IWORK(13),ID 91 FORMAT(' fcn=',I5,' jac=',I4,' step=',I4, & ' accpt=',I4,' rejct=',I3,' dec=',I4, & ' sol=',I5) C -------- NEW TOLERANCE --- TOLST=TOLST*TOLFC 30 CONTINUE STOP END c SUBROUTINE FROBER(N,X,Y,F) C --- RIGHT-HAND SIDE OF ROBERTSON EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),F(N) F(1)=-0.04D0*Y(1)+1.D4*Y(2)*Y(3) F(3)=3.D7*Y(2)*Y(2) F(2)=-F(1)-F(3) RETURN END C SUBROUTINE JROBER(N,X,Y,ML,MU,DFY,LDFY) C --- JACOBIAN OF ROBERTSON EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(LDFY,N) PROD1=1.0D4*Y(2) PROD2=1.0D4*Y(3) PROD3=6.0D7*Y(2) DFY(1,1)=-0.04D0 DFY(1,2)=PROD2 DFY(1,3)=PROD1 DFY(2,1)=0.04D0 DFY(2,2)=-PROD2-PROD3 DFY(2,3)=-PROD1 DFY(3,1)=0.D0 DFY(3,2)=PROD3 DFY(3,3)=0.D0 RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE C * * * * * * * * * * * * * * * * * * * * * * * * * compile equation_lsode compile //venus/user/hairer/hailib/time cfeh driver_lsode //venus/user/hairer/programme/lsode/lsode equation_lsode time IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=8,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),true(nd), + error(nd) REAL*4 TARRAY(2) EXTERNAL FHIRES,JHIRES c ------ FILE DE DONNEES ---------- OPEN(8,FILE='res_lsode') REWIND 8 C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP sumh=0.0D+0 summ=0.0D+0 C --- DIMENSION OF THE SYSTEM N=8 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 MF=21 C --- INITIAL VALUES X=0.0D0 Y (1) = 1.D0 Y (2) = 0.D0 Y (3) = 0.D0 Y (4) = 0.D0 Y (5) = 0.D0 Y (6) = 0.D0 Y (7) = 0.D0 Y (8) = 0.0057D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=1.0D-4*RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=10000 C --- ENDPOINT OF INTEGRATION XEND=321.8122D0 it1=mclock() DO 20 I=1,2 C --- CALL OF THE SUBROUTINE SDIRK4 CALL LSODE(FHIRES,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JHIRES,MF) C --- PRINT SOLUTION c DO 15 K=1,8 c 15 WRITE (8,*)Y(K) XEND=XEND+100.D0 if(i.eq.1) then true(1)=0.000737131257332567 true(2)=0.000144248572631618 true(3)=0.000058887297409676 true(4)=0.001175651343283149 true(5)=0.002386356198831330 true(6)=0.006238968252742796 true(7)=0.002849998395185769 true(8)=0.002850001604814231 else if(i.eq.2) then true(1)=0.000670305503581864 true(2)=0.000130996846986347 true(3)=0.000046862231597733 true(4)=0.001044668020551705 true(5)=0.000594883830951485 true(6)=0.001399628833942774 true(7)=0.001014492757718480 true(8)=0.004685507242281520 end if sum=0.0D+0 do 270 k=1,8 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 CONTINUE CCC CALL DTIME(TARRAY) it2=mclock() tarray(1)=(it2-it1)/100.0D+0 do 15 k=1,8 write(6,*) y(k) 15 continue WRITE(6,*)TARRAY(1),summ,sumh/2.0D+0 summ=summ*atol sumh=sumh*atol/2.0D+0 write(6,*) summ,sumh write(6,91) iwork(12),iwork(13),iwork(11),id,id,iwork(13),id 91 format(' fcn =',i5,' jac =' ,i4,' step=',i4, + 'accept=',i4,'reject=', i4, 'dec=',i4, 'sol=',i4) WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' C -------- NEW TOLERANCE --- ID=0 WRITE(8,*)ID,ID,ID,ID,ID,ID,ID C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE STOP END c C SUBROUTINE FHIRES (N, X, Y, DY) INTEGER N DOUBLE PRECISION X, Y, DY DIMENSION Y (8), DY (8) DY (1) = -1.71D0*Y(1) + 0.43D0*Y(2) + 8.32D0*Y(3) + 0.0007D0 DY (2) = 1.71D0*Y(1) - 8.75D0*Y(2) DY (3) = -10.03D0*Y(3) + 0.43D0*Y(4) + 0.035D0*Y(5) DY (4) = 8.32D0*Y(2) + 1.71D0*Y(3) - 1.12D0*Y(4) DY (5) = -1.745D0*Y(5) + 0.43D0*Y(6) + 0.43D0*Y(7) DY (6) = -280.0D0*Y(6)*Y(8) + 0.69D0*Y(4) + 1.71D0*Y(5) - & 0.43D0*Y(6) + 0.69D0*Y(7) DY (7) = 280.0D0*Y(6)*Y(8) - 1.81D0*Y(7) DY (8) = -DY (7) RETURN END SUBROUTINE JHIRES(N,X,Y,ML,MU,DFY,LDFY) C -------- JACOBIAN FOR HIRES PROBLEM -------- IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(LDFY,N) C------ METTRE A ZERO ------- DO 1 I=1,N DO 1 J=1,N 1 DFY(I,J)=0.D0 C DFY(1,1)= -1.71D0 DFY(1,2)= 0.43D0 DFY(1,3)= + 8.32D0 C DFY(2,1)= 1.71D0 DFY(2,2)= - 8.75D0 C DFY(3,3)= -10.03D0 DFY(3,4)= 0.43D0 DFY(3,5)= + 0.035D0 C DFY(4,2)= 8.32D0 DFY(4,3)= + 1.71D0 DFY(4,4)= - 1.12D0 C DFY(5,5)= -1.745D0 DFY(5,6)= + 0.43D0 DFY(5,7)= + 0.43D0 C DFY(6,4)= + 0.69D0 DFY(6,5)= + 1.71D0 DFY(6,6)= - 0.43D0 -280.0D0*Y(8) DFY(6,7)= + 0.69D0 DFY(6,8)= -280.0D0*Y(6) C DFY(7,6)= 280.0D0*Y(8) DFY(7,7)= - 1.81D0 DFY(7,8)= 280.0D0*Y(6) C DFY(8,6)= - 280.0D0*Y(8) DFY(8,7)= 1.81D0 DFY(8,8)= - 280.0D0*Y(6) RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT OREGONATOR PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * compile equation_lsode compile //venus/user/hairer/hailib/time cfeh driver_lsode //venus/user/hairer/programme/lsode/lsode equation_lsode time IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=3,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),true(nd), + error(nd) REAL*4 TARRAY(2) EXTERNAL FOREGON,JOREGON c ------ FILE DE DONNEES ---------- OPEN(8,FILE='res_lsode') REWIND 8 C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP sumh=0.0D+0 summ=0.0D+0 C --- DIMENSION OF THE SYSTEM N=3 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 MF=21 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=10000 C --- INITIAL VALUES X=0.0D0 Y(1)=1.0D0 Y(2)=2.0D0 Y(3)=3.0D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=1.0D-6*RTOL ITOL=1 C --- ENDPOINT OF INTEGRATION XEND=30.0D0 it1=mclock() DO 20 I=1,12 C --- CALL OF THE SUBROUTINE CALL LSODE(FOREGON,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JOREGON,MF,RPAR,IPAR) C --- PRINT SOLUTION c WRITE (8,*) Y(1) c WRITE (8,*) Y(2) c WRITE (8,*) Y(3) XEND=XEND+30.D0 if(i.eq.1) then true(1)=0.1000661467180497E+01 true(2)=0.1512778937348249E+04 true(3)=0.1035854312767229E+05 else if(i.eq.2) then true(1)=0.1000874625199626E+01 true(2)=0.1144336972384497E+04 true(3)=0.8372149966624639E+02 else if(i.eq.3) then true(1)=0.1001890368438751E+01 true(2)=0.5299926232295553E+03 true(3)=0.1662279579042420E+01 else if(i.eq.4) then true(1)=0.1004118022612645E+01 true(2)=0.2438326079910346E+03 true(3)=0.1008822224048647E+01 else if(i.eq.5) then true(1)=0.1008995416634061E+01 true(2)=0.1121664388662539E+03 true(3)=0.1007783229065319E+01 else if(i.eq.6) then true(1)=0.1019763472537298E+01 true(2)=0.5159761322947535E+02 true(3)=0.1016985778956374E+01 else if(i.eq.7) then true(1)= 0.1043985088527474E+01 true(2)=0.2373442027531524E+02 true(3)=0.1037691843544522E+01 else if(i.eq.8) then true(1)=0.1100849071667922E+01 true(2)=0.1091533805469020E+02 true(3)=0.1085831969810860E+01 else if(i.eq.9) then true(1)=0.1249102130020572E+01 true(2)=0.5013945178605446E+01 true(3)=0.1208326626237875E+01 else if(i.eq.10) then true(1)=0.1779724751937019E+01 true(2)=0.2281852385542403E+01 true(3)=0.1613754023671725E+01 else if(i.eq.11) then true(1)=0.1000889326903503E+01 true(2)=0.1125438585746596E+04 true(3)=0.1641049483777168E+05 else if(i.eq.12) then true(1)=0.1000814870318523E+01 true(2)=0.1228178521549889E+04 true(3)=0.1320554942846513E+03 endif sum=0.0D+0 do 270 k=1,3 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 CONTINUE CCC CALL DTIME(TARRAY) it2=mclock() write(6,*) y(1) write(6,*) y(2) write(6,*) y(3) tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh/12.0D+0 summ=summ*atol sumh=sumh*atol/12.0D+0 write(6,*) summ,sumh ID=0 ID=0 write(6,91) iwork(12),iwork(13),iwork(11),id,id,iwork(13),id 91 format(' fcn =',i5,' jac =' ,i4,' step=',i4, + 'accept=',i4,'reject=', i4, 'dec=',i4, 'sol=',i4) WRITE(8,*)ID,ID,ID,ID,ID,ID,ID WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' C -------- NEW TOLERANCE --- TOLST=TOLST*TOLFC 30 CONTINUE STOP END c SUBROUTINE FOREGON(N,X,Y,F) C --- RIGHT-HAND SIDE OF OREGON EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),F(N) F(1)=77.27D0*(Y(2)+Y(1)*(1.D0-8.375D-6*Y(1)-Y(2))) F(2)=(Y(3)-(1.D0+Y(1))*Y(2))/77.27D0 F(3)=0.161D0*(Y(1)-Y(3)) RETURN END C SUBROUTINE JOREGON(N,X,Y,ML,MU,DFY,LDFY) C --- JACOBIAN OF OREGON EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(LDFY,N) DFY(1,1)=77.27D0*(1.D0-2.D0*8.375D-6*Y(1)-Y(2)) DFY(1,2)=77.27D0*(1.D0-Y(1)) DFY(1,3)=0.D0 DFY(2,1)=-Y(2)/77.27D0 DFY(2,2)=-(1.D0+Y(1))/77.27D0 DFY(2,3)=1.D0/77.27D0 DFY(3,1)=.161D0 DFY(3,2)=.0D0 DFY(3,3)=-.161D0 RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT ROBERTSON PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=4,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK) dimension true(nd),error(nd) REAL*4 TARRAY(2) EXTERNAL FE5,JE5 c ------ FILE DE DONNEES ---------- write(6,3500) 3500 format(1x,'results on E5 by Lsode') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP sumh=0.0D+0 summ=0.0D+0 C --- DIMENSION OF THE SYSTEM N=4 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 MF=21 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=10000 C --- INITIAL VALUES X=0.0D0 Y(1)=1.76D-3 Y(2)=0.0D0 Y(3)=0.0D0 Y(4)=0.0D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=1.7D-24 ITOL=1 C --- ENDPOINT OF INTEGRATION XEND=10.0D0 it1=mclock() DO 20 I=1,7 C --- CALL OF THE SUBROUTINE CALL LSODE(FE5,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JE5,MF,RPAR,IPAR) C --- PRINT SOLUTION c WRITE (8,*) Y(1) c WRITE (8,*) Y(2) c WRITE (8,*) Y(3) c WRITE (8,*) Y(4) c write (6,*) y(2), y(3)+y(4) XEND=XEND*100.D0 if(i.eq.1) then true(1)=1.7599259497677897058D-003 true(2)=1.3846281519376516449D-011 true(3)=7.6370038530073911180D-013 true(4)=1.3082581134075777338D-011 else if(i.eq.2) then true(1)=1.6180769999072942552D-003 true(2)=1.3822370304983735443D-010 true(3)=8.2515735006838336088D-012 true(4)=1.2997212954915352082D-010 else if(i.eq.3) then true(1)=7.4813208224292220114D-006 true(2)=2.3734781561205975019D-012 true(3)=2.2123586689581663654D-012 true(4)=1.6111948716243113653D-013 else if(i.eq.4) then true(1)=4.7150333630401632232D-010 true(2)=1.8188895860807021729D-014 true(3)=1.8188812376786725407D-014 true(4)=8.3484020296321693074D-020 else if(i.eq.5) then true(1)=3.1317148329356996037D-014 true(2)=1.4840957952870064294D-016 true(3)=1.4840957948345691466D-016 true(4)=4.5243728279782625194D-026 else if(i.eq.6) then true(1)=3.8139035189787091771D-049 true(2)=1.0192582567660293322D-020 true(3)=1.0192582567660293322D-020 true(4)=3.7844935507486221171D-065 else if(i.eq.7) then true(1)=0.0000000000000000000D-000 true(2)=8.8612334976263783420D-023 true(3)=8.8612334976263783421D-023 true(4)=0.0000000000000000000D-000 end if sum=0.0D+0 do 270 k=1,4 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 CONTINUE CCC CALL DTIME(TARRAY) it2=mclock() tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh/7.0D+0 summ=summ*rtol sumh=sumh*rtol/7.0D+0 write(6,*) summ,sumh ID=0 it2=mclock() WRITE(8,*)TARRAY(1) ID=0 WRITE(6,*)IWORK(12),IWORK(13),IWORK(11),ID,ID,IWORK(13),ID WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' WRITE(6,91)IWORK(12),IWORK(13),IWORK(11),ID,ID,IWORK(13),ID 91 FORMAT(' fcn=',I5,' jac=',I4,' step=',I4, & ' accpt=',I4,' rejct=',I3,' dec=',I4, & ' sol=',I5) C -------- NEW TOLERANCE --- TOLST=TOLST*TOLFC 30 CONTINUE STOP END c SUBROUTINE FE5(N,X,Y,F) C --- RIGHT-HAND SIDE OF ROBERTSON EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),F(N) PROD1=7.89D-10*Y(1) PROD2=1.1D7*Y(1)*Y(3) PROD3=1.13D9*Y(2)*Y(3) PROD4=1.13D3*Y(4) F(1)=-PROD1-PROD2 F(2)=PROD1-PROD3 F(4)=PROD2-PROD4 F(3)=F(2)-F(4) RETURN END C SUBROUTINE JE5(N,X,Y,ML,MU,DFY,LDFY) C --- JACOBIAN OF ROBERTSON EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(LDFY,N) A=7.89D-10 B=1.1D7 CM=1.13D9 C=1.13D3 DFY(1,1)=-A-B*Y(3) DFY(1,2)=0.D0 DFY(1,3)=-B*Y(1) DFY(1,4)=0.D0 DFY(2,1)=A DFY(2,2)=-CM*Y(3) DFY(2,3)=-CM*Y(2) DFY(2,4)=0.D0 DFY(3,1)=A-B*Y(3) DFY(3,2)=-CM*Y(3) DFY(3,3)=-B*Y(1)-CM*Y(2) DFY(3,4)=C DFY(4,1)=B*Y(3) DFY(4,2)=0.D0 DFY(4,3)=B*Y(1) DFY(4,4)=-C RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=80,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK) dimension true(nd),error(nd) REAL*4 TARRAY(2) COMMON/NNNN/NCOM,NNCOM,NSQ,NQUATR,DELTAS EXTERNAL FTIGE c ------ FILE DE DONNEES ---------- write(6,3500) 3500 format(1x,'results on beam by lsode') C --- LOOP FOR DIFFERENT TOLERANCES DO 66 IORDMX=8,12 NTOLMN=6 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP sumh=0.0D+0 summ=0.0D+0 C ---------- CONSTANTS -------------- N=40 NN=2*N NCOM=N NSQ=N*N NQUATR=NSQ*NSQ NNCOM=NN AN=N DELTAS=1.D0/AN C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 C --------- MAXIMAL ORDER ----- IWORK(5)=IORDMX-7 ITASK=1 ISTATE=1 IOPT=1 MF=22 C --------- INITIAL VALUES ------------- T=0.D0 DO 1 I=1,NN 1 Y(I)=0.D0 TEND=5.D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=100000 it1=mclock() C --- CALL OF THE SUBROUTINE SDIRK4 CALL LSODE(FTIGE,NN,Y,T,TEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & FTIGE,MF) C --- PRINT SOLUTION true(1)=-0.005792366591294675 true(2)=-0.016952985507199259 true(3)=-0.027691033129713322 true(4)=-0.038008156558781729 true(5)=-0.047906168597422688 true(6)=-0.057387104352737008 true(7)=-0.066453273134522699 true(8)=-0.075107305819780661 true(9)=-0.083352197654124544 true(10)=-0.091191346546446469 true(11)=-0.098628587001297248 true(12)=-0.105668220037774708 true(13)=-0.112315039540924422 true(14)=-0.1 18574355272698475 true(15)=-0.124452012875526880 true(16)=-0.129954411326390999 true(17)=-0.135088518061004200 true(18)=-0.139861881919410397 true(19)=-0.144282644101482929 true(20)=-0.148359547246256976 true(21)=-0.152101942900106414 true(22)=-0.155519797806080921 true(23)=-0.158623699341992299 true(24)=-0.161424860370167541 true(25)=-0.163935123819275499 true(26)=-0.166166967344037066 true(27)=-0.168133508177817718 true(28)=-0.169848508060189926 true(29)=-0.171326378244038509 true(30)=-0.172582184746215274 true(31)=-0.173631653797526901 true(32)=-0.174491177383960691 true(33)=-0.175177818786287100 true(34)=-0.175709317871242317 true(35)=-0.176104096022807288 true(36)=-0.176381260717507812 true(37)=-0.176560609756417469 true(38)=-0.176662635226010517 true(39)=-0.176708527080694206 true(40)=-0.176720176107510191 true(41)= 0.037473626808570053 true(42)=0.109911788012810762 true(43)=0.179836047447039129 true(44)=0.247242730557127186 true(45)=0.312129382035491301 true(46)=0.374494737701689822 true(47)=0.434338607372647125 true(48)=0.491662035432760524 true(49)=0.546467785483476383 true(50)=0.598760970245279030 true(51)=0.648549361126755851 true(52)=0.695843516905088648 true(53)=0.740657266848912124 true(54)=0.783008174791347177 true(55)=0.822917665884869456 true(56)=0.860411030561688098 true(57)=0.895517550233742218 true(58)=0.928270826293034365 true(59)=0.958708933474210358 true(60)=0.986874782150222219 true(61)=1.012816579967983789 true(62)=1.036587736684594479 true(63)=1.058246826485315033 true(64)=1.077857811432700289 true(65)=1.095490221995530989 true(66)=1.111219164319120026 true(67)=1.125125269269998022 true(68)=1.137294526582397119 true(69)=1.147818025203744592 true(70)=1.156792131966898566 true(71)=1.164318845152484938 true(72)=1.170505992580311363 true(73)=1.175467424328008220 true(74)=1.179323003206967714 true(75)=1.182198586301326345 true(76)=1.184226111211404704 true(77)=1.185543909813440450 true(78)=1.186297084230907673 true(79)=1.186637618874913665 true(80)=1.186724615129383839 sum=0.0D+0 do 270 k=1,80 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/80.0D+0) sumh=sumh+sum summ=max(summ,sum) 20 continue it2=mclock() tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh ID=0 WRITE(IORDMX,9921)(Y(I),I=1,NN) 9921 FORMAT(1X,F22.16) WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' IF(TARRAY(1).GT.300.)GOTO 66 C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE 66 CONTINUE STOP END c SUBROUTINE FTIGE(NN,T,TH,F) C --- RIGHT-HAND SIDE OF TIGEPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION TH(NN),F(NN) DIMENSION U(150),V(150),W(150) DIMENSION ALPHA(150),BETA(150),STH(150),CTH(150) COMMON/NNNN/N,NNCOM,NSQ,NQUATR,DELTAS COMMON/TOLD/TOLD c----------- C ----- CALCUL DES TH(I) ET DES SIN ET COS ------------- DO 22 I=2,N THDIFF=TH(I)-TH(I-1) STH(I)=DSIN(THDIFF) 22 CTH(I)=DCOS(THDIFF) C -------- CALCUL DU COTE DROIT DU SYSTEME LINEAIRE ----- IF(T.GT.3.14159265358979324D0)THEN C --------- CASE T GREATER PI ------------ C ---------- I=1 ------------ TERM1=(-3.D0*TH(1)+TH(2))*NQUATR V(1)=TERM1 C -------- I=2,..,N-1 ----------- DO 32 I=2,N-1 TERM1=(TH(I-1)-2.D0*TH(I)+TH(I+1))*NQUATR 32 V(I)=TERM1 C ----------- I=N ------------- TERM1=(TH(N-1)-TH(N))*NQUATR V(N)=TERM1 ELSE C --------- CASE T LESS EQUAL PI ------------ FABS=1.5D0*DSIN(T)*DSIN(T) FX=-FABS FY= FABS C ---------- I=1 ------------ TERM1=(-3.D0*TH(1)+TH(2))*NQUATR TERM2=NSQ*(FY*DCOS(TH(1))-FX*DSIN(TH(1))) V(1)=TERM1+TERM2 C -------- I=2,..,N-1 ----------- DO 34 I=2,N-1 TERM1=(TH(I-1)-2.D0*TH(I)+TH(I+1))*NQUATR TERM2=NSQ*(FY*DCOS(TH(I))-FX*DSIN(TH(I))) 34 V(I)=TERM1+TERM2 C ----------- I=N ------------- TERM1=(TH(N-1)-TH(N))*NQUATR TERM2=NSQ*(FY*DCOS(TH(N))-FX*DSIN(TH(N))) V(N)=TERM1+TERM2 END IF C -------- COMPUTE PRODUCT DV=W ------------ W(1)=STH(2)*V(2) DO 43 I=2,N-1 43 W(I)=-STH(I)*V(I-1)+STH(I+1)*V(I+1) W(N)=-STH(N)*V(N-1) C -------- TERME 3 ----------------- DO 435 I=1,N 435 W(I)=W(I)+TH(N+I)*TH(N+I) C ------- SOLVE SYSTEM CW=W --------- ALPHA(1)=1.D0 DO 44 I=2,N ALPHA(I)=2.D0 44 BETA(I-1)=-CTH(I) ALPHA(N)=3.D0 DO 45 I=N-1,1,-1 Q=BETA(I)/ALPHA(I+1) W(I)=W(I)-W(I+1)*Q 45 ALPHA(I)=ALPHA(I)-BETA(I)*Q W(1)=W(1)/ALPHA(1) DO 46 I=2,N 46 W(I)=(W(I)-BETA(I-1)*W(I-1))/ALPHA(I) C -------- COMPUTE U=CV+DW --------- U(1)=V(1)-CTH(2)*V(2)+STH(2)*W(2) DO 47 I=2,N-1 47 U(I)=2.D0*V(I)-CTH(I)*V(I-1)-CTH(I+1)*V(I+1) & -STH(I)*W(I-1)+STH(I+1)*W(I+1) U(N)=3.D0*V(N)-CTH(N)*V(N-1)-STH(N)*W(N-1) C -------- PUT DERIVATIVES IN RIGHT PLACE ------------- DO 54 I=1,N F(I)=TH(N+I) 54 F(N+I)=U(I) RETURN END C SUBROUTINE JTIGE(N,X,Y,ML,MU,DFY,LDFY) C --- JACOBIAN OF TIGEPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(LDFY,N) WRITE(6,*)' NE PAS ARRIVER DANS JTIGE ' STOP END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER(MX=8,MY=5,MACHS1=2,MACHS2=4) PARAMETER (ND=2*MX*MY) PARAMETER (LWORK=22+9*ND+ND**2,LIWORK=ND+20) dimension true(nd),error(nd) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK) REAL*4 TARRAY(2) EXTERNAL FPLATE,JPLATE C -------- CONSTANTES ------------------ COMMON/TRANS/NX,NXM1,NY,NYM1,NDEMI,NACHS1,NACHS2,NDUMMY, & OMEGA,STIFFN,DELX,USH4,FAC,WEIGHT NX=MX NY=MY NACHS1=MACHS1 NACHS2=MACHS2 NXM1=NX-1 NYM1=NY-1 NDEMI=NX*NY OMEGA=1000.D0 STIFFN=100.D0 WEIGHT=200.D0 DENOM=NX+1 DELX=2.D0/DENOM USH4=1.D0/(DELX**4) FAC=STIFFN*USH4 c ------ FILE DE DONNEES ---------- write(6,3500) 3500 format(1x,'lsode results on the plate problem') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP sumh=0.0D+0 summ=0.0D+0 C --- DIMENSION OF THE SYSTEM N=ND C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 MF=21 C --- INITIAL VALUES X=0.0D0 DO 101 I=1,N 101 Y(I)=0.D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=10000 C --- ENDPOINT OF INTEGRATION XEND=7.D0 co CALL DTIME(TARRAY) it1=mclock() C --- CALL OF THE SUBROUTINE SDIRK4 CALL LSODE(FPLATE,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JPLATE,MF) C ########## PRINT c write(6,*)' exit lsode, x,istate=',x,istate c ############### C --- PRINT SOLUTION DO 15 K=1,N 15 WRITE (6,*)Y(K) c CALL DTIME(TARRAY) true(1)=0.000490143813851336 true(2)=0.000980081485560611 true(3)=0.001462893811482190 true(4)=0.001915822464411935 true(5)=0.002285152533727002 true(6)=0.002461353376688549 true(7)=0.002254597413097122 true(8)=0.001438312591933600 true(9)=0.000849025149228402 true(10)=0.001697885005625757 true(11)=0.002535239886068847 true(12)=0.003323989552181772 true(13)=0.003977902193560667 true(14)=0.004320231736082990 true(15)=0.004025679955083897 true(16)=0.002643206356123840 true(17)=0.000980287627702671 true(18)=0.001960162971121222 true(19)=0.002925787622964379 true(20)=0.003831644928823870 true(21)=0.004570305067454005 true(22)=0.004922706753377098 true(23)=0.004509194826194244 true(24)=0.002876625183867201 true(25)=0.000849025149228402 true(26)= 0.001697885005625757 true(27)=0.002535239886068847 true(28)=0.003323989552181772 true(29)=0.003977902193560667 true(30)=0.004320231736082990 true(31)=0.004025679955083897 true(32)=0.002643206356123840 true(33)=0.000490143813851336 true(34)=0.000980081485560611 true(35)=0.001462893811482190 true(36)=0.001915822464411935 true(37)=0.002285152533727002 true(38)=0.002461353376688549 true(39)=0.002254597413097122 true(40)=0.001438312591933600 true(41)=- 0.001177590304545409 true(42)=-0.002409005827992214 true(43)=-0.003722140831656533 true(44)=-0.005078780056048207 true(45)=-0.006302661811097914 true(46)=-0.006973399942926759 true(47)=-0.006394575120415784 true(48)=-0.003960464551310118 true(49)=-0.002040148244040460 true(50)=-0.004174829877953482 true(51)=-0.006456510337516159 true(52)=-0.008832503276738242 true(53)=-0.011029624807177369 true(54)=-0.012352389570141255 true(55)=-0.011524177328690540 true(56)=-0.007253301886026949 true(57)=-0.002355180609090818 true(58)=-0.004818011655984428 true(59)=-0.007444281663313065 true(60)=-0.010157560112096413 true(61)=-0.012605323622195828 true(62)=-0.013946799885853517 true(63)=-0.012789150240831569 true(64)=-0.007920929102620235 true(65)=-0.002040148244040460 true(66)=-0.004174829877953482 true(67)=-0.006456510337516159 true(68)=-0.008832503276738242 true(69)=-0.011029624807177369 true(70)=-0.012352389570141255 true(71)=-0.011524177328690540 true(72)=-0.007253301886026949 true(73)=-0.001177590304545409 true(74)=-0.002409005827992214 true(75)=-0.003722140831656533 true(76)=-0.005078780056048207 true(77)=-0.006302661811097914 true(78)=-0.006973399942926759 true(79)=-0.006394575120415784 true(80)=-0.003960464551310118 sum=0.0D+0 do 270 k=1,80 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/80.0D+0) sumh=sumh+sum summ=max(summ,sum) 20 CONTINUE CCC CALL DTIME(TARRAY) it2=mclock() tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh ID=0 write(6,91) iwork(12),iwork(13),iwork(11),id,id,iwork(13),id 91 format(' fcn =',i5,' jac =' ,i4,' step=',i4, + 'accept=',i4,'reject=', i4, 'dec=',i4, 'sol=',i4) WRITE(8,*)ID,ID,ID,ID,ID,ID,ID WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE STOP END C SUBROUTINE FPLATE (N, X, Y, F) IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N), F(N) COMMON/TRANS/NX,NXM1,NY,NYM1,NDEMI,NACHS1,NACHS2,NDUMMY, & OMEGA,STIFFN,DELX,USH4,FAC,WEIGHT c ################ print c write(6,*)' dans fplate, n,x=',n,x c############## C -------- LA BOUCLE ------- DO 1 I=1,NX DO 1 J=1,NY K=I+NX*(J-1) C -------- DERIVEE DEUXIEME ---- F(K)=Y(K+NDEMI) C ------ POINT CENTRAL --- UC=16.D0*Y(K) IF(I.GT.1)THEN UC=UC+Y(K) UC=UC-8.D0*Y(K-1) END IF IF(I.LT.NX)THEN UC=UC+Y(K) UC=UC-8.D0*Y(K+1) END IF IF(J.GT.1)THEN UC=UC+Y(K) UC=UC-8.D0*Y(K-NX) END IF IF(J.LT.NY)THEN UC=UC+Y(K) UC=UC-8.D0*Y(K+NX) END IF IF(I.GT.1 .AND.J.GT.1 )UC=UC+2.D0*Y(K-NX-1) IF(I.LT.NX.AND.J.GT.1 )UC=UC+2.D0*Y(K-NX+1) IF(I.GT.1 .AND.J.LT.NY)UC=UC+2.D0*Y(K+NX-1) IF(I.LT.NX.AND.J.LT.NY)UC=UC+2.D0*Y(K+NX+1) IF(I.GT.2)UC=UC+Y(K-2) IF(I.LT.NXM1)UC=UC+Y(K+2) IF(J.GT.2)UC=UC+Y(K-2*NX) IF(J.LT.NYM1)UC=UC+Y(K+2*NX) IF(J.EQ.NACHS1.OR.J.EQ.NACHS2)THEN XI=I*DELX FORCE=EXP(-5.D0*(X-XI-2.D0)**2)+EXP(-5.D0*(X-XI-5.D0)**2) ELSE FORCE=0.D0 END IF F(K+NDEMI)=-OMEGA*Y(K+NDEMI)-FAC*UC+FORCE*WEIGHT 1 CONTINUE RETURN END SUBROUTINE JPLATE(N,X,Y,ML,MU,DFY,LDFY) IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(LDFY,N) COMMON/TRANS/NX,NXM1,NY,NYM1,NDEMI,NACHS1,NACHS2,NDUMMY, & OMEGA,STIFFN,DELX,USH4,FAC,WEIGHT c ################ print c write(6,*)' dans jac , n,x=',n,x c############## C------ METTRE A ZERO ------- DO 1 I=1,N DO 1 J=1,N 1 DFY(I,J)=0.D0 C -------- LA BOUCLE ------- DO 2 I=1,NX DO 2 J=1,NY K=I+NX*(J-1) C -------- DERIVEE DEUXIEME ---- DFY(K,K+NDEMI)=1.D0 C ------ POINT CENTRAL --- DFY(K+NDEMI,K)=-FAC*16.D0 IF(I.GT.1)THEN DFY(K+NDEMI,K)=DFY(K+NDEMI,K)-FAC DFY(K+NDEMI,K-1)=FAC*8.D0 END IF IF(I.LT.NX)THEN DFY(K+NDEMI,K)=DFY(K+NDEMI,K)-FAC DFY(K+NDEMI,K+1)=FAC*8.D0 END IF IF(J.GT.1)THEN DFY(K+NDEMI,K)=DFY(K+NDEMI,K)-FAC DFY(K+NDEMI,K-NX)=FAC*8.D0 END IF IF(J.LT.NY)THEN DFY(K+NDEMI,K)=DFY(K+NDEMI,K)-FAC DFY(K+NDEMI,K+NX)=FAC*8.D0 END IF IF(I.GT.1 .AND.J.GT.1 )DFY(K+NDEMI,K-NX-1)=-FAC*2.D0 IF(I.LT.NX.AND.J.GT.1 )DFY(K+NDEMI,K-NX+1)=-FAC*2.D0 IF(I.GT.1 .AND.J.LT.NY)DFY(K+NDEMI,K+NX-1)=-FAC*2.D0 IF(I.LT.NX.AND.J.LT.NY)DFY(K+NDEMI,K+NX+1)=-FAC*2.D0 IF(I.GT.2)DFY(K+NDEMI,K-2)=-FAC IF(I.LT.NXM1)DFY(K+NDEMI,K+2)=-FAC IF(J.GT.2)DFY(K+NDEMI,K-2*NX)=-FAC IF(J.LT.NYM1)DFY(K+NDEMI,K+2*NX)=-FAC DFY(K+NDEMI,K+NDEMI)= -OMEGA 2 CONTINUE RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=96,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK) dimension true(nd),error(nd) REAL*4 TARRAY(2) COMMON/NERVES/NNERV COMMON/DIFFCOEF/DIFFUS EXTERNAL FCUSP,JCUSP c ------ FILE DE DONNEES ---------- write(6,3500) 3500 format(1x,'results on cusp for lsode') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP sumh=0.0D+0 summ=0.0D+0 c -------- INITIAL CONSTANTES -------- NNERV=32 DIFFUS=1.D0*NNERV*NNERV/144.D0 N=3*NNERV C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 MF=25 ML=3 MU=3 IWORK(1)=ML IWORK(2)=MU C ---------- VAL INIT ------------ X=0.D0 XEND=1.1D0 ANERV=NNERV DEL=2.D0*3.14159265358979324D0/ANERV DO 13 INERV=1,NNERV Y(3*INERV-2)=0.D0 Y(3*INERV-1)=-2.D0*COS(INERV*DEL) 13 Y(3*INERV)=2.D0*SIN(INERV*DEL) C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=100000 it1=mclock() C --- CALL OF THE SUBROUTINE SDIRK4 CALL LSODE(FCUSP,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & FCUSP,MF) C --- PRINT SOLUTION true(1)=-1.335038235173363825 true(2)=-0.141920661299976116 true(3)=2.189999851122752954 true(4)=-1.290165517136865728 true(5)=0.292210513241939329 true(6)=2.524498007953815718 true(7)=-1.206268463248866837 true(8)=0.702876002804259450 true(9)=2.603037671957832137 true(10)=-1.081173370722796200 true(11)=1.054547339698463687 true(12)=2.403900155664309457 true(13)=-0.922551477213655165 true(14)=1.326991956338080918 true(15)=2.009305096775369514 true(16)=-0.743049818521982534 true(17)=1.516881284521938182 true(18)=1.537256339189765457 true(19)=-0.555201077072863929 true(20)=1.632603197056899916 true(21)=1.077437487481636876 true(22)=-0.369158363066035655 true(23)=1.687674223256960258 true(24)=0.673204001909134905 true(25)=-0.192671593795137051 true(26)=1.695724385342398648 true(27)=0.333758479535656796 true(28)=-0.030615931836238017 true(29)=1.667262708083148298 true(30)=0.050978698243957534 true(31)=0.117513584875619235 true(32)=1.607508563419502269 true(33)=-0.190604748914752998 true(34)=0.259898961244445617 true(35)=1.514823442340568479 true(36)=-0.411323787318084589 true(37)=0.411809029672400558 true(38)=1.379804789392094260 true(39)=-0.638121744946811883 true(40)=0.590441346230457812 true(41)=1.185589061664514451 true(42)=-0.905945997151089418 true(43)=0.803741778414404449 true(44)=0.910756427168161885 true(45)=-1.251345457775128863 true(46)=1.037877442048335801 true(47)=0.545036626743780133 true(48)=-1.683821753687386274 true(49)=1.239043542405442416 true(50)=0.169981336507011738 true(51)=-2.112958754094543822 true(52)=1.406385681620871097 true(53)=-0.235380986562835855 true(54)=-2.450796096861493262 true(55)=1.524334200774267799 true(56)=-0.633461856049010260 true(57)=-2.576413161518578492 true(58)=1.588649099727842025 true(59)=-0.986582203794960052 true(60)=-2.442161394270367795 true(61)=1.606022353430074771 true(62)=-1.269240297385074114 true(63)=-2.104018859237057304 true(64)=1.588788794126354791 true(65)=-1.473056296837721718 true(66)=-1.670122571729852451 true(67)=1.549115780473624505 true(68)=-1.603417743271582846 true(69)=-1.233609811984700428 true(70)=1.495889929838369103 true(71)=-1.672805947347039028 true(72)=-0.844976238622025912 true(73)=1.434154221021214460 true(74)=-1.695067644864453216 true(75)=-0.518751841694241591 true(76)=1.365334914988092461 true(77)=-1.681659890115195530 true(78)=-0.249120054639391870 true(79)=1.286403800980685275 true(80)=-1.639285126097438457 true(81)=-0.019980596158691364 true(82)=1.184974025791693888 true(83)=-1.567910985925968939 true(84)=0.194039539947058944 true(85)=1.011140518164431143 true(86)=-1.455860565434940201 true(87)=0.436843623543739620 true(88)=-1.349821324547813729 true(89)=-1.223845158570813537 true(90)=0.809099908070360854 true(91)=-1.355008974443540401 true(92)=-0.926131110369012061 true(93)=1.232945832067604962 true(94)=-1.352261107347051711 true(95)=-0.559070645046367311 true(96)=1.716745798614099647 sum=0.0D+0 do 270 k=1,96 error(k)=dabs(y(k)-true(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/96.0D+0) sumh=sumh+sum summ=max(sum,summ) it2=mclock() tarray(1)=(it2-it1)/100.0D+0 20 CONTINUE C --- PRINT STATISTICS WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' write (6,*) y(1),y(n/2),y(n) ID=0 write(6,91) iwork(12),iwork(13),iwork(11),id,id,iwork(13),id 91 format(' fcn =',i5,' jac =' ,i4,' step=',i4, + 'accept=',i4,'reject=', i4, 'dec=',i4, 'sol=',i4) C -------- NEW TOLERANCE --- TOLST=TOLST*TOLFC 30 CONTINUE STOP END C SUBROUTINE FCUSP(N,T,Y,F) IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),F(N) COMMON/NERVES/NNERV COMMON/DIFFCOEF/DIFFUS c----------- DO 25 INERV=1,NNERV X=Y(3*INERV-2) A=Y(3*INERV-1) B=Y(3*INERV) IF(INERV.EQ.1)THEN XRIGHT=Y(3*NNERV-2) ARIGHT=Y(3*NNERV-1) BRIGHT=Y(3*NNERV) ELSE XRIGHT=Y(3*INERV-5) ARIGHT=Y(3*INERV-4) BRIGHT=Y(3*INERV-3) END IF IF(INERV.EQ.NNERV)THEN XLEFT=Y(1) ALEFT=Y(2) BLEFT=Y(3) ELSE XLEFT=Y(3*INERV+1) ALEFT=Y(3*INERV+2) BLEFT=Y(3*INERV+3) END IF XDOT=-10000.D0*(B+X*(A+X*X)) U=(X-0.7D0)*(X-1.3D0) V=U/(U+0.1D0) ADOT=B+0.07D0*V BDOT=(1.D0*(1.D0-A*A)*B-A)-0.4D0*X+0.035D0*V F(3*INERV-2)=XDOT+DIFFUS*(XLEFT-2.D0*X+XRIGHT) F(3*INERV-1)=ADOT+DIFFUS*(ALEFT-2.D0*A+ARIGHT) F(3*INERV) =BDOT+DIFFUS*(BLEFT-2.D0*B+BRIGHT) 25 CONTINUE RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE PARAMETER (ND=1000,LIWORK=ND+20) PARAMETER (ML=2,MU=2,LWORK=22+(10+2*ML+MU)*ND) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK) dimension error(nd),true(nd) REAL*4 TARRAY(2) EXTERNAL FBRUS,JBRUS COMMON/PARAM/N,N2,GAMMA,GAMMA2 c ------ FILE DE DONNEES ---------- write(6,3500) 3500 format(1x,'results on bruss by lsode') c -------- INITIAL CONSTANTES -------- PI=3.14159265358979324D0 N=500 N2=2*N USDELQ=(DBLE(N+1))**2 GAMMA=0.02D0*USDELQ GAMMA2=2.D0*GAMMA C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP sumh=0.0D+0 summ=0.0D+0 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 C ----- BANDED ANALYTIC JACOBIAN -- MF=24 c MF=25 IWORK(1)=ML IWORK(2)=MU C ---------- VAL INIT ------------ X=0.D0 XEND=10.D0 DO 1 I=1,N ANP1=N+1 XI=I/ANP1 Y(2*I)=3.D0 1 Y(2*I-1)=1.D0+0.5D0*DSIN(2.D0*PI*XI) C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=10000 it1=mclock() C --- CALL OF THE SUBROUTINE CALL LSODE(FBRUS,N2,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JBRUS,MF) C --- PRINT SOLUTION true(1)=0.9949197002317599 true(8)=3.0213845767604077 true(15)=0.9594350193986054 true(22)=3.0585989778165419 true(29)=0.9243010095428502 true(36)=3.0952478919989637 true(43)=0.8897959106772672 true(50)=3.1310118289054731 true(57)=0.8561653620284367 true(64)=3.1656101198770159 true(71)=0.8236197147449046 true(78)=3.1988043370624344 true(85)=0.7923328094811884 true(92)=3.2303999530641514 true(99)=0.7624421042573115 true(106)=3.2602463873623941 true(113)=0.7340499750795348 true(120)=3.2882356529108807 true(127)=0.7072259700779899 true(134)=3.3142998590079271 true(141)=0.6820097782458483 true(148)=3.3384078449410937 true(155)=0.6584146743834650 true(162)=3.3605612157873943 true(169)=0.6364312187752559 true(176)=3.3807900316323134 true(183)=0.6160310186921587 true(190)=3.3991483695914764 true(197)=0.5971703941198909 true(204)=3.4157099395342736 true(211)=0.5797938277687891 true(218)=3.4305638938070224 true(225)=0.5638371159206763 true(232)=3.4438109320334580 true(239)=0.5492301695479158 true(246)=3.4555597666485198 true(253)=0.5358994429426996 true(260)=3.4659239846027008 true(267)=0.5237699892215797 true(274)=3.4750193162238476 true(281)=0.5127671585747183 true(288)=3.4829613034792271 true(295)=0.5028179665048467 true(302)=3.4898633463634923 true(309)=0.4938521662914935 true(316)=3.4958350971335204 true(323)=0.4858030633656755 true(330)=3.5009811668111510 true(337)=0.4786081100251151 TRUE(344)=3.5054001059792705 true(351)=0.4722093177200750 true(358)=3.5091836216744015 true(365)=0.4665535216425440 true(372)=3.5124159935026285 true(379)=0.4615925290790646 true(386)=3.5151736544621075 true(393)=0.4572831793403656 true(400)=3.5175249049438184 true(407)=0.4535873393501199 true(414)=3.5195297317024448 true(421)=0.4504718553589467 true(428)=3.5212397070273984 true(435)=0.4479084778719241 true(442)=3.5226979467564341 true(449)=0.4458737738041973 true(456)=3.5239391090719634 true(463)=0.4443490371324889 true(470)=3.5249894191569453 true(477)=0.4433202068820853 true(484)=3.5258667077466495 true(491)=0.4427777991494095 true(498)=3.5265804544017270 true(505)=0.4427168579654424 true(512)=3.5271318289682063 true(519)=0.4431369281018266 true(526)=3.5275137272135266 true(533)=0.4440420513508381 true(540)=3.5277107990730161 true(547)=0.4454407863109616 true(554)=3.5276994703501980 true(561)=0.4473462502188303 true(568)=3.5274479611304068 true(575)=0.4497761798232572 true(582)=3.5269163066324394 true(589)=0.4527530066369863 true(596)=3.5260563887768472 true(603)=0.4563039400688689 true(610)=3.5248119894251024 true(617)=0.4604610498812091 true(624)=3.5231188790654930 true(631)=0.4652613370907894 true(638)=3.5209049576992761 true(645)=0.4707467798082714 true(652)=3.5180904678044698 true(659)=0.4769643375804777 true(666)=3.5145883024867057 true(673)=0.4839658945842979 true(680)=3.5103044351908528 true(687)=0.4918081185812277 true(694)=3.5051385005173827 true(701)=0.5005522089940899 true(708)=3.4989845585737802 true(715)=0.5102635039989190 true(722)=3.4917320776245013 true(729)=0.5210109134090777 true(736)=3.4832671712209993 true(743)=0.5328661417420937 true(750)=3.4734741260299615 true(757)=0.5459026646938675 true(764)=3.4622372546582585 true(771)=0.5601944229089820 true(778)=3.4494431032230182 true(785)=0.5758142001453760 true(792)=3.4349830354873361 true(799)=0.5928316594749734 true(806)=3.4187562033108012 true(813)=0.6113110218368440 true(820)=3.4006728962523969 true(827)=0.6313083867734524 true(834)=3.3806582409098729 true(841)=0.6528687160104193 true(848)=3.3586561928427350 true(855)=0.6760225267555723 true(862)=3.3346337311179157 true(869)=0.7007823726569721 true(876)=3.3085851288057930 true(883)=0.7271392249346637 true(890)=3.2805361342349380 true(897)=0.7550589020044152 true(904)=3.2505478606008622 true(911)=0.7844787296769868 true(918)=3.2187201496972175 true(925)=0.8153046416214843 true(932)=3.1851941538893653 true(939)=0.8474089465959840 true(946)=3.1501538739882800 true(953)=0.8806289904192589 true(960)=3.1138264039027113 true(967)=0.9147669230929857 true(974)=3.0764806689389470 true(981)=0.9495907429372025 true(988)=3.0384245041548366 true(995)=0.9848367306701233 sum=0.0D+0 do 270 k=1,995,7 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/143.0D+0) sumh=sumh+sum summ=max(summ,sum) 20 CONTINUE CCC CALL DTIME(TARRAY) it2=mclock() tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' WRITE(6,91)IWORK(12),IWORK(13),IWORK(11),ID,ID,IWORK(13),ID 91 FORMAT(' fcn=',I5,' jac=',I4,' step=',I4, & ' accpt=',I4,' rejct=',I3,' dec=',I4, & ' sol=',I5) C -------- NEW TOLERANCE --- IF (TARRAY(1).GT.500.) STOP TOLST=TOLST*TOLFC 30 CONTINUE STOP END c SUBROUTINE FBRUS(NNN,X,Y,F) C --- RIGHT-HAND SIDE OF BRUSPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(NNN),F(NNN) COMMON/PARAM/N,N2,GAMMA,GAMMA2 I=1 IU=2*I-1 IV=2*I UI=Y(IU) VI=Y(IV) UIM=1.D0 VIM=3.D0 UIP=Y(IU+2) VIP=Y(IV+2) PROD=UI*UI*VI F(IU)=1.D0+PROD-4.D0*UI+GAMMA*(UIM-2.D0*UI+UIP) F(IV)=3.D0*UI-PROD+GAMMA*(VIM-2.D0*VI+VIP) DO 5 I=2,N-1 IU=2*I-1 IV=2*I UI=Y(IU) VI=Y(IV) UIM=Y(IU-2) VIM=Y(IV-2) UIP=Y(IU+2) VIP=Y(IV+2) PROD=UI*UI*VI F(IU)=1.D0+PROD-4.D0*UI+GAMMA*(UIM-2.D0*UI+UIP) F(IV)=3.D0*UI-PROD+GAMMA*(VIM-2.D0*VI+VIP) 5 CONTINUE I=N IU=2*I-1 IV=2*I UI=Y(IU) VI=Y(IV) UIM=Y(IU-2) VIM=Y(IV-2) UIP=1.D0 VIP=3.D0 PROD=UI*UI*VI F(IU)=1.D0+PROD-4.D0*UI+GAMMA*(UIM-2.D0*UI+UIP) F(IV)=3.D0*UI-PROD+GAMMA*(VIM-2.D0*VI+VIP) RETURN END C SUBROUTINE JBRUS(NNN,X,Y,ML,MU,DFY,LDFY) C --- JACOBIAN OF BRUSPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(NNN),DFY(LDFY,NNN) COMMON/PARAM/N,N2,GAMMA,GAMMA2 DO 1 I=1,N IU=2*I-1 IV=2*I UI=Y(IU) VI=Y(IV) UIVI=UI*VI UI2=UI*UI DFY(3,IU)=2.D0*UIVI-4.D0-GAMMA2 DFY(2,IV)=UI2 DFY(4,IU)=3.D0-2.D0*UIVI DFY(3,IV)=-UI2-GAMMA2 DFY(2,IU)=0.D0 DFY(4,IV)=0.D0 1 CONTINUE DO 2 I=1,N2-2 DFY(1,I+2)=GAMMA DFY(5,I)=GAMMA 2 CONTINUE RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT KS PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR RADAU5 (BANDED JACOBIAN) PARAMETER (MMM=9) PARAMETER (NH=2**MMM,N=2*NH,ND=2*NH-2) PARAMETER (IJAC=1,MLJAC=0,MUJAC=0,IMAS=0) PARAMETER (LE=2*MLJAC+MUJAC+1) PARAMETER (LWORK=ND*(LE+10)+22,LIWORK=ND+20) C --- DECLARATIONS DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),U(N) dimension true(nd),error(nd) COMMON/TRANS/QQ,UZERO REAL*4 TARRAY(2) EXTERNAL FKS,JKS,SOLOUT C --- DATA FOR THE PROBLEM QQ=0.025D0 c ------ FILE DE DONNEES ---------- write(6,3500) 3500 format(1x,'lsode on ks problem') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=7 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP summ=0.0D+0 sumh=0.0D+0 C --- OUTPUT DURING INTEGRATION --- IOUT=0 C --- INITIAL VALUES T=0.0D0 C --- INITIAL POSITIONS IN Y-SPACE ---- AN=N DO I=1,N DELX=1.D0/AN X=DELX*(I-1) U1=MIN(X-0.0D0,0.1D0-X) U2=20.D0*(X-0.2D0)*(0.3D0-X) U3=MIN(X-0.6D0,0.7D0-X) U4=MIN(X-0.9D0,1.0D0-X) U(I)=16.D0*MAX(0.D0,U1,U2,U3,U4) END DO C --- FOURIER TRANSFORM --- CALL REALFT(U,NH,+1) DO I=1,N U(I)=U(I)/AN END DO C --- INITIAL POSITION IN FOURIER MODES --- UZERO=U(1) DO I=1,ND Y(I)=U(I+2) END DO C --- WRITE DATA TO FILE PLUS CONTROL --- U(1)=UZERO U(2)=0.D0 DO I=3,N U(I)=Y(I-2) END DO CALL REALFT(U,NH,-1) DO I=1,N U(I)=2.D0*U(I) END DO C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 C ----- BANDED ANALYTIC JACOBIAN -- MF=24 IWORK(1)=MLJAC IWORK(2)=MUJAC C ---------- VAL INIT ------------ X=0.D0 XEND=100.D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=10000 it1=mclock() C --- CALL OF THE SUBROUTINE CALL LSODE(FKS,ND,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JKS,MF) C --- PRINT SOLUTION true(1)=0.0387294818017374 true(2)=0.0011594920936697 true(3)=0.0161135569739015 true(4)=-0.0497378990194494 true(5)=0.0161388094706610 true(6)=-0.0790294186417376 true(7)=-0.0562945063709753 true(8)=-0.0194501629216551 true(9)=-0.0317390967305054 true(10)=-0.0256301653146683 true(11)=-0.0896908152487471 true(16)=0.0452570608746347 true(21)=0.0110762324013310 true(26)=0.0095676261122614 true(31)=0.1089375008451597 true(36)=-0.1201229482736044 true(41)=-0.1354295218545231 true(46)=-0.0146538030311935 true(51)=-0.0092223615970260 true(56)=-0.2760611800802050 true(61)=-0.0174686339809433 true(66)=0.1982033914963349 true(71)=-0.1768843940011891 true(76)=0.3090308065592430 true(81)=-0.0952958329765616 true(86)=-0.1063846133920493 true(91)=0.0390151203721951 true(96)=0.0451950368314852 true(101)=0.0477521089259518 true(151)=0.0112038077853544 true(201)=0.0003656188545739 true(251)=-0.0001443415867781 true(301)=-0.0000090034942150 true(351)=0.0000016423881092 true(401)=0.0000001490634819 true(451)=0.0000000334389501 true(501)=-0.0000000020970060 true(551)=-0.0000000017295829 true(601)=0.0000000000353463 true(651)=0.0000000000036143 true(701)=0.0000000000004182 true(751)=-0.0000000000000002 true(801)=-0.0000000000000070 true(851)=-0.0000000000000012 true(901)=0.0000000000000001 true(951)=0.0000000000000000 true(1001)=0.0000000000000000 summ=0.0D+0 do 270 k=1,10 error(k)=dabs(y(k)-true(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue do 271 k=11,100,5 error(k)=dabs(y(k)-true(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 271 continue do 272 k=101,1024,50 error(k)=dabs(y(k)-true(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 272 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 CONTINUE CCC CALL DTIME(TARRAY) it2=mclock() tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh ID=0 ID=0 WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' WRITE(6,91)IWORK(12),IWORK(13),IWORK(11),ID,ID,IWORK(13),ID 91 FORMAT(' fcn=',I5,' jac=',I4,' step=',I4, & ' accpt=',I4,' rejct=',I3,' dec=',I4, & ' sol=',I5) C -------- NEW TOLERANCE --- TOLST=TOLST*TOLFC IF (TARRAY(1).GT.1000.) STOP 30 CONTINUE STOP END C include 'fft.f' cc This module calculates the r.h.s for the KS equation cc cc d/dt u = - (dx^2+ dx^4)u - u u' cc cc in its form with fourier modes. cc I.e., the system cc cc dt u_n = (n^2 q^2 - n^4 q^4) u_n cc - (i q n/2) sum_{n_1+n_2=n} u_{n_1} u_{n_2} cc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc subroutine FKS(ND,T,Y,F) IMPLICIT REAL*8 (A-H,O-Z) PARAMETER (MMM=9) PARAMETER (NH=2**MMM,N=2*NH) DIMENSION y(ND),f(ND) DIMENSION U(N) COMMON/TRANS/QQ,UZERO c --- copy y to u U(1)=UZERO U(2)=0.D0 DO I=3,N U(I)=Y(I-2) END DO CALL REALFT(U,NH,-1) DO I=1,N U(I)=2.D0*U(I) END DO C --- SQUARE ------ DO I=1,N U(I)=U(I)**2/2.D0 END DO C --- TRANSFORM BACK --- CALL REALFT(U,NH,+1) AN=N DO I=1,N U(I)=U(I)/AN END DO do J=1,NH-1 DIAG=(QQ*J)**2*(1.D0-(QQ*J)**2) F(2*J-1)=DIAG*Y(2*J-1) +QQ*J*U(2*J+2) F(2*J )=DIAG*Y(2*J ) -QQ*J*U(2*J+1) enddo end c-------------------------------------------------------------- subroutine JKS(ND,x,y,ML,MU,dfy,ldfy) PARAMETER (MMM=9) PARAMETER (NH=2**MMM,N=2*NH) IMPLICIT REAL*8 (A-H,O-Z) DIMENSION y(ND),DFY(LDFY,ND) COMMON/TRANS/QQ,UZERO do J=1,NH-1 DIAG=(QQ*J)**2*(1.D0-(QQ*J)**2) DFY(1,2*J-1)=DIAG DFY(1,2*J )=DIAG enddo end C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT VANDERPOL PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=15,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),yend(nd), + error(nd) REAL*4 TARRAY(2) common/const/pi EXTERNAL FVANDER,JVANDER c ------ FILE DE DONNEES ---------- write(6,3080) 3080 format(1x,'results for lsode on vdp') pi=4.0D+0*datan(1.0D+0) C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=3 NTOLMX=12 NTOLDF=2 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP summ=0.0D+0 summh=0.0D+0 C --- DIMENSION OF THE SYSTEM N=15 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 MF=21 C --- INITIAL VALUES X=0.0D0 do 751 ijk=1,15 y(ijk)=0.0D+0 751 continue C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=100000 C --- ENDPOINT OF INTEGRATION XEND=1.0d-3 c CALL DTIME(TARRAY) it1=mclock() DO 20 I=1,1 C --- CALL OF THE SUBROUTINE CALL LSODE(FVANDER,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JVANDER,MF) C --- PRINT SOLUTION c WRITE (6,*) Y(1) c WRITE (6,*) Y(2) yend(1)=-0.170799033d-1 yend(2)=-0.6660979d-2 yend(3)=+0.27531919d0 yend(4)=-0.39115732d0 yend(5)=-0.38851731d0 yend(6)=+0.27795920d0 yend(7)=+0.1114600281d0 yend(8)=+0.2979129627d-6 yend(9)=-0.31427403d-7 yend(10)=+0.70165883d-3 yend(11)=+0.85207538d-3 yend(12)=-0.77741454d-3 yend(13)=-0.77631967d-3 yend(14)=+0.78439426d-4 yend(15)=+0.252322784d-4 c sum=0.0D+0 do 270 k=1,15 error(k)=dabs(yend(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 continue it2=mclock() tarray(1)=(it2-it1)/100.0D+0 write(6,*) x,y(1),y(2) WRITE(6,*)TARRAY(1),summ,sumh/11.0d+0 summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh ID=0 WRITE(6,*)ID,ID,ID,ID,ID,ID,ID WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' write(6,91) iwork(12),iwork(13),iwork(11),id,id,iwork(13),id 91 format(' fcn =',i5,' jac =' ,i4,' step=',i4, + 'accept=',i4,'reject=', i4, 'dec=',i4, 'sol=',i4) C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE STOP END c SUBROUTINE FVANDER(N,tn,Y,dy) C --- RIGHT-HAND SIDE OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),dy(N) c double precision y0, yN double precision kcns,pi,mi,dif,dx,amult,prod,rat common /const/pi double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri,rc, + gamma,delta,sumer, + uin1,uin2,ud1,ud2,ud3,ud4,qud1,qud2,qud3,qud4 parameter (c=1.6d-8,cs=1d-9,cp=1d-8,r=25d3,rp=50d0, + lh=4.45d0,ls1=2d-3,ls2=5d-4,ls3=5d-4, + rg1=36.3d0,rg2=17.3d0,rg3=17.3d0,ri=5d1,rc=6d2, + gamma=40.67286402d-9,delta=17.7493332d0) uin1=0.5d0*sin(2.0d3*pi*tn) uin2=2.0d0*sin(2.0d4*pi*tn) ud1=+y(3)-y(5)-y(7)-uin2 ud2=-y(4)+y(6)-y(7)-uin2 ud3=+y(4)+y(5)+y(7)+uin2 ud4=-y(3)-y(6)+y(7)+uin2 qud1=gamma*(exp(delta*ud1)-1.0d0) qud2=gamma*(exp(delta*ud2)-1.0d0) qud3=gamma*(exp(delta*ud3)-1.0d0) qud4=gamma*(exp(delta*ud4)-1.0d0) dy(1)=(y(8)-0.5d0*y(10)+0.5d0*y(11)+y(14)-y(1)/r)/c dy(2)=(y(9)-0.5d0*y(12)+0.5d0*y(13)+y(15)-y(2)/r)/c dy(3)=(y(10)-qud1+qud4)/cs dy(4)=(-y(11)+qud2-qud3)/cs dy(5)=(y(12)+qud1-qud3)/cs dy(6)=(-y(13)-qud2+qud4)/cs dy(7)=(-y(7)/rp+qud1+qud2-qud3-qud4)/cp dy(8)=-y(1)/lh dy(9)=-y(2)/lh dy(10)=(0.5d0*y(1)-y(3)-rg2*y(10))/ls2 dy(11)=(-0.5d0*y(1)+y(4)-rg3*y(11))/ls3 dy(12)=(0.5d0*y(2)-y(5)-rg2*y(12))/ls2 dy(13)=(-0.5d0*y(2)+y(6)-rg3*y(13))/ls3 dy(14)=(-y(1)+uin1-(ri+rg1)*y(14))/ls1 dy(15)=(-y(2)-(rc+rg1)*y(15))/ls1 return end C SUBROUTINE JVANDER(N,tn,Y,ML,MU,PD,LDFY) C --- JACOBIAN OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),pd(LDFY,N) double precision kcns,pi,mi,dif,dx,amult,prod,rat,a1,a2,a3,u common /const/pi double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri,rc, + gamma,delta,sumer, + uin2,ud1,ud2,ud3,ud4,qpud1,qpud2,qpud3,qpud4 parameter (c=1.6d-8,cs=1d-9,cp=1d-8,r=25d3,rp=50d0, + lh=4.45d0,ls1=2d-3,ls2=5d-4,ls3=5d-4, + rg1=36.3d0,rg2=17.3d0,rg3=17.3d0,ri=5d1,rc=6d2, + gamma=40.67286402d-9,delta=17.7493332d0) do 177 i=1,n do 177 j=1,n pd(i,j)=0.0D+0 177 continue uin2=2.0d0*sin(2.0d4*pi*tn) ud1=+y(3)-y(5)-y(7)-uin2 ud2=-y(4)+y(6)-y(7)-uin2 ud3=+y(4)+y(5)+y(7)+uin2 ud4=-y(3)-y(6)+y(7)+uin2 qpud1=gamma*delta*exp(delta*ud1) qpud2=gamma*delta*exp(delta*ud2) qpud3=gamma*delta*exp(delta*ud3) qpud4=gamma*delta*exp(delta*ud4) pd(1,1)=-1.0d0/(c*r) pd(1,8)=-1.0d0/c pd(1,10)=-0.5d0/c pd(1,11)=-pd(1,10) pd(1,14)=pd(1,8) pd(2,2)=pd(1,1) pd(2,9)=pd(1,8) pd(2,12)=pd(1,10) pd(2,13)=pd(1,11) pd(2,15)=pd(1,14) pd(3,3)=(-qpud1-qpud4)/cs pd(3,5)=qpud1/cs pd(3,6)=-qpud4/cs pd(3,7)=(qpud1+qpud4)/cs pd(3,10)=1.0d0/cs pd(4,4)=(-qpud2-qpud3)/cs pd(4,5)=-qpud3/cs pd(4,6)=qpud2/cs pd(4,7)=(-qpud2-qpud3)/cs pd(4,11)=-1.0d0/cs pd(5,3)=qpud1/cs pd(5,4)=-qpud3/cs pd(5,5)=(-qpud1-qpud3)/cs pd(5,7)=(-qpud1-qpud3)/cs pd(5,12)=1.0d0/cs pd(6,3)=-qpud4/cs pd(6,4)=qpud2/cs pd(6,6)=(-qpud2-qpud4)/cs pd(6,7)=(qpud2+qpud4)/cs pd(6,13)=-1.0d0/cs pd(7,3)=(qpud1+qpud4)/cp pd(7,4)=(-qpud2-qpud3)/cp pd(7,5)=(-qpud1-qpud3)/cp pd(7,6)=(qpud2+qpud4)/cp pd(7,7)=(-qpud1-qpud2-qpud3-qpud4-1.0d0/rp)/cp pd(8,1)=-1.0d0/lh pd(9,2)=pd(8,1) pd(10,1)=0.5d0/ls2 pd(10,3)=-1.0d0/ls2 pd(10,10)=-rg2/ls2 pd(11,1)=-0.5d0/ls3 pd(11,4)=1.0d0/ls3 pd(11,11)=-rg3/ls3 pd(12,2)=pd(10,1) pd(12,5)=pd(10,3) pd(12,12)=pd(10,10) pd(13,2)=pd(11,1) pd(13,6)=pd(11,4) pd(13,13)=pd(11,11) pd(14,1)=-1.0d0/ls1 pd(14,14)=-(ri+rg1)/ls1 pd(15,2)=pd(14,1) pd(15,15)=-(rc+rg1)/ls1 return end C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT VANDERPOL PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=6,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),true(nd), + error(nd) REAL*4 TARRAY(2) EXTERNAL FVANDER,JVANDER c ------ FILE DE DONNEES ---------- write(6,3080) 3080 format(1x,'results for lsode on b5') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP summ=0.0D+0 sumh=0.0D+0 C --- DIMENSION OF THE SYSTEM N=6 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK= 2 itask=1 c itask = 2 for step by step and =1 for whole interval. ISTATE=1 IOPT=1 MF=21 C --- INITIAL VALUES X=0.0D0 do 800 ijk=1,6 y(ijk)=1.0D+0 800 continue C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=100000 C --- ENDPOINT OF INTEGRATION XEND=20.0D0 c CALL DTIME(TARRAY) it1=mclock() C --- CALL OF THE SUBROUTINE 220 continue CALL LSODE(FVANDER,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JVANDER,MF) C --- PRINT SOLUTION c WRITE (6,*) Y(1) c WRITE (6,*) Y(2) true(1)=dexp(-10.0D+0*x)*(cos(1000.0D+0*x)+sin(1000.0D+0*x)) true(2)=dexp(-10.0D+0*x)*(cos(1000.0D+0*x)-sin(1000.0D+0*x)) true(3)=dexp(-4.0D+0*x) true(4)=dexp(-x) true(5)=dexp(-0.5D+0*x) true(6)=dexp(-0.1D+0*x) sum=0.0D+0 do 345 ik=1,6 error(ik)=true(ik)-y(ik) sum=sum+((error(ik)/(rtol*dabs(y(ik))+atol))**2) 345 continue sum=dsqrt(sum/6.0D+0) if(sum.gt.summ) summ=sum if(x.lt.xend) GOTO 220 955 continue xout=x aa=cos(1000.0D+0*xout) bb=sin(1000.0D+0*xout) cc=dexp(-10.0D+0*xout) true(1)=cc*(aa+bb) true(2)=cc*(aa-bb) true(3)=dexp(-4.0D+0*xout) true(4)=dexp(-xout) true(5)=dexp(-0.5D+0*xout) true(6)=dexp(-0.1D+0*xout) sum=0.0D+0 do 270 k=1,6 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum it2=mclock() tarray(1)=(it2-it1)/100.0D+0 write(6,*) x,y(1),y(2) WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh ID=0 WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' write(6,91) iwork(12),iwork(13),iwork(11),id,id,iwork(13),id 91 format(' fcn =',i5,' jac =' ,i4,' step=',i4, + 'accept=',i4,'reject=', i4, 'dec=',i4, 'sol=',i4) C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE STOP END c c SUBROUTINE Fvander(N,X,Y,DF) C --- RIGHT-HAND SIDE OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DF(N) df(1)=-10.0D+0*y(1)+1000.0D+0*y(2) df(2)=-1000.0D+0*y(1)-10.0D+0*y(2) df(3)=-4.0D+0*y(3) df(4)=-y(4) df(5)=-0.5D+0*y(5) df(6)=-0.1D+0*y(6) RETURN END C SUBROUTINE jvander(n,X,Y,ml,mu,DFY,ldfy) C --- JACOBIAN OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(ldfy,N) DFY(1,1)=-10.0D0 DFY(1,2)=1000.D0 DFY(2,1)=-1000.0D+0 DFY(2,2)=-10.0D+0 dfy(3,3)=-4.0D+0 dfy(4,4)=-1.0D+0 dfy(5,5)=-0.5D+0 dfy(6,6)=-0.1D+0 RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT KS PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR RADAU5 (BANDED JACOBIAN) PARAMETER (MMM=9) PARAMETER (NH=2**MMM,N=2*NH,ND=2*NH-2) PARAMETER (IJAC=1,MLJAC=0,MUJAC=0,IMAS=0) PARAMETER (LE=2*MLJAC+MUJAC+1) PARAMETER (LWORK=ND*(LE+10)+22,LIWORK=ND+20) C --- DECLARATIONS DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),U(N) dimension true(nd),error(nd) COMMON/TRANS/QQ,UZERO REAL*4 TARRAY(2) EXTERNAL FKS,JKS,SOLOUT open(6,file='lsodeks.res') C --- DATA FOR THE PROBLEM QQ=0.025D0 c ------ FILE DE DONNEES ---------- write(6,3500) 3500 format(1x,'lsode on ks problem') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=12 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP summ=0.0D+0 sumh=0.0D+0 C --- OUTPUT DURING INTEGRATION --- IOUT=0 C --- INITIAL VALUES T=0.0D0 C --- INITIAL POSITIONS IN Y-SPACE ---- AN=N DO I=1,N DELX=1.D0/AN X=DELX*(I-1) U1=MIN(X-0.0D0,0.1D0-X) U2=20.D0*(X-0.2D0)*(0.3D0-X) U3=MIN(X-0.6D0,0.7D0-X) U4=MIN(X-0.9D0,1.0D0-X) U(I)=16.D0*MAX(0.D0,U1,U2,U3,U4) END DO C --- FOURIER TRANSFORM --- CALL REALFT(U,NH,+1) DO I=1,N U(I)=U(I)/AN END DO C --- INITIAL POSITION IN FOURIER MODES --- UZERO=U(1) DO I=1,ND Y(I)=U(I+2) END DO C --- WRITE DATA TO FILE PLUS CONTROL --- U(1)=UZERO U(2)=0.D0 DO I=3,N U(I)=Y(I-2) END DO CALL REALFT(U,NH,-1) DO I=1,N U(I)=2.D0*U(I) END DO C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 C ----- BANDED ANALYTIC JACOBIAN -- MF=24 IWORK(1)=MLJAC IWORK(2)=MUJAC C ---------- VAL INIT ------------ X=0.D0 XEND=100.D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=10000 it1=mclock() C --- CALL OF THE SUBROUTINE CALL LSODE(FKS,ND,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JKS,MF) C --- PRINT SOLUTION true(1)=0.0387294818017374 true(2)=0.0011594920936697 true(3)=0.0161135569739015 true(4)=-0.0497378990194494 true(5)=0.0161388094706610 true(6)=-0.0790294186417376 true(7)=-0.0562945063709753 true(8)=-0.0194501629216551 true(9)=-0.0317390967305054 true(10)=-0.0256301653146683 true(11)=-0.0896908152487471 true(16)=0.0452570608746347 true(21)=0.0110762324013310 true(26)=0.0095676261122614 true(31)=0.1089375008451597 true(36)=-0.1201229482736044 true(41)=-0.1354295218545231 true(46)=-0.0146538030311935 true(51)=-0.0092223615970260 true(56)=-0.2760611800802050 true(61)=-0.0174686339809433 true(66)=0.1982033914963349 true(71)=-0.1768843940011891 true(76)=0.3090308065592430 true(81)=-0.0952958329765616 true(86)=-0.1063846133920493 true(91)=0.0390151203721951 true(96)=0.0451950368314852 true(101)=0.0477521089259518 true(151)=0.0112038077853544 true(201)=0.0003656188545739 true(251)=-0.0001443415867781 true(301)=-0.0000090034942150 true(351)=0.0000016423881092 true(401)=0.0000001490634819 true(451)=0.0000000334389501 true(501)=-0.0000000020970060 true(551)=-0.0000000017295829 true(601)=0.0000000000353463 true(651)=0.0000000000036143 true(701)=0.0000000000004182 true(751)=-0.0000000000000002 true(801)=-0.0000000000000070 true(851)=-0.0000000000000012 true(901)=0.0000000000000001 true(951)=0.0000000000000000 true(1001)=0.0000000000000000 summ=0.0D+0 do 270 k=1,10 error(k)=dabs(y(k)-true(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue do 271 k=11,100,5 error(k)=dabs(y(k)-true(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 271 continue do 272 k=101,1024,50 error(k)=dabs(y(k)-true(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 272 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 CONTINUE CCC CALL DTIME(TARRAY) it2=mclock() tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh us=log10(summ) ut=log10(sumh) write(6,*) us,ut ID=0 ID=0 WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' WRITE(6,91)IWORK(12),IWORK(13),IWORK(11),ID,ID,IWORK(13),ID 91 FORMAT(' fcn=',I5,' jac=',I4,' step=',I4, & ' accpt=',I4,' rejct=',I3,' dec=',I4, & ' sol=',I5) C -------- NEW TOLERANCE --- TOLST=TOLST*TOLFC IF (TARRAY(1).GT.1000.) STOP 30 CONTINUE STOP END C include 'fft.f' cc This module calculates the r.h.s for the KS equation cc cc d/dt u = - (dx^2+ dx^4)u - u u' cc cc in its form with fourier modes. cc I.e., the system cc cc dt u_n = (n^2 q^2 - n^4 q^4) u_n cc - (i q n/2) sum_{n_1+n_2=n} u_{n_1} u_{n_2} cc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc subroutine FKS(ND,T,Y,F) IMPLICIT REAL*8 (A-H,O-Z) PARAMETER (MMM=9) PARAMETER (NH=2**MMM,N=2*NH) DIMENSION y(ND),f(ND) DIMENSION U(N) COMMON/TRANS/QQ,UZERO c --- copy y to u U(1)=UZERO U(2)=0.D0 DO I=3,N U(I)=Y(I-2) END DO CALL REALFT(U,NH,-1) DO I=1,N U(I)=2.D0*U(I) END DO C --- SQUARE ------ DO I=1,N U(I)=U(I)**2/2.D0 END DO C --- TRANSFORM BACK --- CALL REALFT(U,NH,+1) AN=N DO I=1,N U(I)=U(I)/AN END DO do J=1,NH-1 DIAG=(QQ*J)**2*(1.D0-(QQ*J)**2) F(2*J-1)=DIAG*Y(2*J-1) +QQ*J*U(2*J+2) F(2*J )=DIAG*Y(2*J ) -QQ*J*U(2*J+1) enddo end c-------------------------------------------------------------- subroutine JKS(ND,x,y,ML,MU,dfy,ldfy) PARAMETER (MMM=9) PARAMETER (NH=2**MMM,N=2*NH) IMPLICIT REAL*8 (A-H,O-Z) DIMENSION y(ND),DFY(LDFY,ND) COMMON/TRANS/QQ,UZERO do J=1,NH-1 DIAG=(QQ*J)**2*(1.D0-(QQ*J)**2) DFY(1,2*J-1)=DIAG DFY(1,2*J )=DIAG enddo end C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT VANDERPOL PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=15,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),yend(nd), + error(nd) REAL*4 TARRAY(2) common/const/pi EXTERNAL FVANDER,JVANDER c ------ FILE DE DONNEES ---------- write(6,3080) 3080 format(1x,'results for lsode on vdp') pi=4.0D+0*datan(1.0D+0) C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=3 NTOLMX=12 NTOLDF=2 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP summ=0.0D+0 summh=0.0D+0 C --- DIMENSION OF THE SYSTEM N=15 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 MF=21 C --- INITIAL VALUES X=0.0D0 do 751 ijk=1,15 y(ijk)=0.0D+0 751 continue C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=100000 C --- ENDPOINT OF INTEGRATION XEND=1.0d-3 c CALL DTIME(TARRAY) it1=mclock() DO 20 I=1,1 C --- CALL OF THE SUBROUTINE CALL LSODE(FVANDER,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JVANDER,MF) C --- PRINT SOLUTION c WRITE (6,*) Y(1) c WRITE (6,*) Y(2) yend(1)=-0.170799033d-1 yend(2)=-0.6660979d-2 yend(3)=+0.27531919d0 yend(4)=-0.39115732d0 yend(5)=-0.38851731d0 yend(6)=+0.27795920d0 yend(7)=+0.1114600281d0 yend(8)=+0.2979129627d-6 yend(9)=-0.31427403d-7 yend(10)=+0.70165883d-3 yend(11)=+0.85207538d-3 yend(12)=-0.77741454d-3 yend(13)=-0.77631967d-3 yend(14)=+0.78439426d-4 yend(15)=+0.252322784d-4 c sum=0.0D+0 do 270 k=1,15 error(k)=dabs(yend(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 continue it2=mclock() tarray(1)=(it2-it1)/100.0D+0 write(6,*) x,y(1),y(2) WRITE(6,*)TARRAY(1),summ,sumh/11.0d+0 summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh ID=0 WRITE(6,*)ID,ID,ID,ID,ID,ID,ID WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' write(6,91) iwork(12),iwork(13),iwork(11),id,id,iwork(13),id 91 format(' fcn =',i5,' jac =' ,i4,' step=',i4, + 'accept=',i4,'reject=', i4, 'dec=',i4, 'sol=',i4) C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE STOP END c SUBROUTINE FVANDER(N,tn,Y,dy) C --- RIGHT-HAND SIDE OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),dy(N) c double precision y0, yN double precision kcns,pi,mi,dif,dx,amult,prod,rat common /const/pi double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri,rc, + gamma,delta,sumer, + uin1,uin2,ud1,ud2,ud3,ud4,qud1,qud2,qud3,qud4 parameter (c=1.6d-8,cs=1d-9,cp=1d-8,r=25d3,rp=50d0, + lh=4.45d0,ls1=2d-3,ls2=5d-4,ls3=5d-4, + rg1=36.3d0,rg2=17.3d0,rg3=17.3d0,ri=5d1,rc=6d2, + gamma=40.67286402d-9,delta=17.7493332d0) uin1=0.5d0*sin(2.0d3*pi*tn) uin2=2.0d0*sin(2.0d4*pi*tn) ud1=+y(3)-y(5)-y(7)-uin2 ud2=-y(4)+y(6)-y(7)-uin2 ud3=+y(4)+y(5)+y(7)+uin2 ud4=-y(3)-y(6)+y(7)+uin2 qud1=gamma*(exp(delta*ud1)-1.0d0) qud2=gamma*(exp(delta*ud2)-1.0d0) qud3=gamma*(exp(delta*ud3)-1.0d0) qud4=gamma*(exp(delta*ud4)-1.0d0) dy(1)=(y(8)-0.5d0*y(10)+0.5d0*y(11)+y(14)-y(1)/r)/c dy(2)=(y(9)-0.5d0*y(12)+0.5d0*y(13)+y(15)-y(2)/r)/c dy(3)=(y(10)-qud1+qud4)/cs dy(4)=(-y(11)+qud2-qud3)/cs dy(5)=(y(12)+qud1-qud3)/cs dy(6)=(-y(13)-qud2+qud4)/cs dy(7)=(-y(7)/rp+qud1+qud2-qud3-qud4)/cp dy(8)=-y(1)/lh dy(9)=-y(2)/lh dy(10)=(0.5d0*y(1)-y(3)-rg2*y(10))/ls2 dy(11)=(-0.5d0*y(1)+y(4)-rg3*y(11))/ls3 dy(12)=(0.5d0*y(2)-y(5)-rg2*y(12))/ls2 dy(13)=(-0.5d0*y(2)+y(6)-rg3*y(13))/ls3 dy(14)=(-y(1)+uin1-(ri+rg1)*y(14))/ls1 dy(15)=(-y(2)-(rc+rg1)*y(15))/ls1 return end C SUBROUTINE JVANDER(N,tn,Y,ML,MU,PD,LDFY) C --- JACOBIAN OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),pd(LDFY,N) double precision kcns,pi,mi,dif,dx,amult,prod,rat,a1,a2,a3,u common /const/pi double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri,rc, + gamma,delta,sumer, + uin2,ud1,ud2,ud3,ud4,qpud1,qpud2,qpud3,qpud4 parameter (c=1.6d-8,cs=1d-9,cp=1d-8,r=25d3,rp=50d0, + lh=4.45d0,ls1=2d-3,ls2=5d-4,ls3=5d-4, + rg1=36.3d0,rg2=17.3d0,rg3=17.3d0,ri=5d1,rc=6d2, + gamma=40.67286402d-9,delta=17.7493332d0) do 177 i=1,n do 177 j=1,n pd(i,j)=0.0D+0 177 continue uin2=2.0d0*sin(2.0d4*pi*tn) ud1=+y(3)-y(5)-y(7)-uin2 ud2=-y(4)+y(6)-y(7)-uin2 ud3=+y(4)+y(5)+y(7)+uin2 ud4=-y(3)-y(6)+y(7)+uin2 qpud1=gamma*delta*exp(delta*ud1) qpud2=gamma*delta*exp(delta*ud2) qpud3=gamma*delta*exp(delta*ud3) qpud4=gamma*delta*exp(delta*ud4) pd(1,1)=-1.0d0/(c*r) pd(1,8)=-1.0d0/c pd(1,10)=-0.5d0/c pd(1,11)=-pd(1,10) pd(1,14)=pd(1,8) pd(2,2)=pd(1,1) pd(2,9)=pd(1,8) pd(2,12)=pd(1,10) pd(2,13)=pd(1,11) pd(2,15)=pd(1,14) pd(3,3)=(-qpud1-qpud4)/cs pd(3,5)=qpud1/cs pd(3,6)=-qpud4/cs pd(3,7)=(qpud1+qpud4)/cs pd(3,10)=1.0d0/cs pd(4,4)=(-qpud2-qpud3)/cs pd(4,5)=-qpud3/cs pd(4,6)=qpud2/cs pd(4,7)=(-qpud2-qpud3)/cs pd(4,11)=-1.0d0/cs pd(5,3)=qpud1/cs pd(5,4)=-qpud3/cs pd(5,5)=(-qpud1-qpud3)/cs pd(5,7)=(-qpud1-qpud3)/cs pd(5,12)=1.0d0/cs pd(6,3)=-qpud4/cs pd(6,4)=qpud2/cs pd(6,6)=(-qpud2-qpud4)/cs pd(6,7)=(qpud2+qpud4)/cs pd(6,13)=-1.0d0/cs pd(7,3)=(qpud1+qpud4)/cp pd(7,4)=(-qpud2-qpud3)/cp pd(7,5)=(-qpud1-qpud3)/cp pd(7,6)=(qpud2+qpud4)/cp pd(7,7)=(-qpud1-qpud2-qpud3-qpud4-1.0d0/rp)/cp pd(8,1)=-1.0d0/lh pd(9,2)=pd(8,1) pd(10,1)=0.5d0/ls2 pd(10,3)=-1.0d0/ls2 pd(10,10)=-rg2/ls2 pd(11,1)=-0.5d0/ls3 pd(11,4)=1.0d0/ls3 pd(11,11)=-rg3/ls3 pd(12,2)=pd(10,1) pd(12,5)=pd(10,3) pd(12,12)=pd(10,10) pd(13,2)=pd(11,1) pd(13,6)=pd(11,4) pd(13,13)=pd(11,11) pd(14,1)=-1.0d0/ls1 pd(14,14)=-(ri+rg1)/ls1 pd(15,2)=pd(14,1) pd(15,15)=-(rc+rg1)/ls1 return end C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT VANDERPOL PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=6,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),true(nd), + error(nd) REAL*4 TARRAY(2) EXTERNAL FVANDER,JVANDER c ------ FILE DE DONNEES ---------- write(6,3080) 3080 format(1x,'results for lsode on b5') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP summ=0.0D+0 sumh=0.0D+0 C --- DIMENSION OF THE SYSTEM N=6 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK= 2 itask=1 c itask = 2 for step by step and =1 for whole interval. ISTATE=1 IOPT=1 MF=21 C --- INITIAL VALUES X=0.0D0 do 800 ijk=1,6 y(ijk)=1.0D+0 800 continue C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=100000 C --- ENDPOINT OF INTEGRATION XEND=20.0D0 c CALL DTIME(TARRAY) it1=mclock() C --- CALL OF THE SUBROUTINE 220 continue CALL LSODE(FVANDER,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JVANDER,MF) C --- PRINT SOLUTION c WRITE (6,*) Y(1) c WRITE (6,*) Y(2) true(1)=dexp(-10.0D+0*x)*(cos(1000.0D+0*x)+sin(1000.0D+0*x)) true(2)=dexp(-10.0D+0*x)*(cos(1000.0D+0*x)-sin(1000.0D+0*x)) true(3)=dexp(-4.0D+0*x) true(4)=dexp(-x) true(5)=dexp(-0.5D+0*x) true(6)=dexp(-0.1D+0*x) sum=0.0D+0 do 345 ik=1,6 error(ik)=true(ik)-y(ik) sum=sum+((error(ik)/(rtol*dabs(y(ik))+atol))**2) 345 continue sum=dsqrt(sum/6.0D+0) if(sum.gt.summ) summ=sum if(x.lt.xend) GOTO 220 955 continue xout=x aa=cos(1000.0D+0*xout) bb=sin(1000.0D+0*xout) cc=dexp(-10.0D+0*xout) true(1)=cc*(aa+bb) true(2)=cc*(aa-bb) true(3)=dexp(-4.0D+0*xout) true(4)=dexp(-xout) true(5)=dexp(-0.5D+0*xout) true(6)=dexp(-0.1D+0*xout) sum=0.0D+0 do 270 k=1,6 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum it2=mclock() tarray(1)=(it2-it1)/100.0D+0 write(6,*) x,y(1),y(2) WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh ID=0 WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' write(6,91) iwork(12),iwork(13),iwork(11),id,id,iwork(13),id 91 format(' fcn =',i5,' jac =' ,i4,' step=',i4, + 'accept=',i4,'reject=', i4, 'dec=',i4, 'sol=',i4) C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE STOP END c c SUBROUTINE Fvander(N,X,Y,DF) C --- RIGHT-HAND SIDE OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DF(N) df(1)=-10.0D+0*y(1)+1000.0D+0*y(2) df(2)=-1000.0D+0*y(1)-10.0D+0*y(2) df(3)=-4.0D+0*y(3) df(4)=-y(4) df(5)=-0.5D+0*y(5) df(6)=-0.1D+0*y(6) RETURN END C SUBROUTINE jvander(n,X,Y,ml,mu,DFY,ldfy) C --- JACOBIAN OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(ldfy,N) DFY(1,1)=-10.0D0 DFY(1,2)=1000.D0 DFY(2,1)=-1000.0D+0 DFY(2,2)=-10.0D+0 dfy(3,3)=-4.0D+0 dfy(4,4)=-1.0D+0 dfy(5,5)=-0.5D+0 dfy(6,6)=-0.1D+0 RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=80,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK) dimension true(nd),error(nd) REAL*4 TARRAY(2) COMMON/NNNN/NCOM,NNCOM,NSQ,NQUATR,DELTAS EXTERNAL FTIGE c ------ FILE DE DONNEES ---------- open(6,file= 'lsodebeam.res2') write(6,3500) 3500 format(1x,'results on beam by lsode') C --- LOOP FOR DIFFERENT TOLERANCES DO 66 IORDMX=8,12 NTOLMN=2 NTOLMX=10 NTOLDF=2 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP sumh=0.0D+0 summ=0.0D+0 C ---------- CONSTANTS -------------- N=40 NN=2*N NCOM=N NSQ=N*N NQUATR=NSQ*NSQ NNCOM=NN AN=N DELTAS=1.D0/AN C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 C --------- MAXIMAL ORDER ----- IWORK(5)=IORDMX-7 ITASK=1 ISTATE=1 IOPT=1 MF=22 C --------- INITIAL VALUES ------------- T=0.D0 DO 1 I=1,NN 1 Y(I)=0.D0 TEND=5.D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=100000 it1=mclock() C --- CALL OF THE SUBROUTINE SDIRK4 CALL LSODE(FTIGE,NN,Y,T,TEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & FTIGE,MF) C --- PRINT SOLUTION true(1)=-0.005792366591294675 true(2)=-0.016952985507199259 true(3)=-0.027691033129713322 true(4)=-0.038008156558781729 true(5)=-0.047906168597422688 true(6)=-0.057387104352737008 true(7)=-0.066453273134522699 true(8)=-0.075107305819780661 true(9)=-0.083352197654124544 true(10)=-0.091191346546446469 true(11)=-0.098628587001297248 true(12)=-0.105668220037774708 true(13)=-0.112315039540924422 true(14)=-0.1 18574355272698475 true(15)=-0.124452012875526880 true(16)=-0.129954411326390999 true(17)=-0.135088518061004200 true(18)=-0.139861881919410397 true(19)=-0.144282644101482929 true(20)=-0.148359547246256976 true(21)=-0.152101942900106414 true(22)=-0.155519797806080921 true(23)=-0.158623699341992299 true(24)=-0.161424860370167541 true(25)=-0.163935123819275499 true(26)=-0.166166967344037066 true(27)=-0.168133508177817718 true(28)=-0.169848508060189926 true(29)=-0.171326378244038509 true(30)=-0.172582184746215274 true(31)=-0.173631653797526901 true(32)=-0.174491177383960691 true(33)=-0.175177818786287100 true(34)=-0.175709317871242317 true(35)=-0.176104096022807288 true(36)=-0.176381260717507812 true(37)=-0.176560609756417469 true(38)=-0.176662635226010517 true(39)=-0.176708527080694206 true(40)=-0.176720176107510191 true(41)= 0.037473626808570053 true(42)=0.109911788012810762 true(43)=0.179836047447039129 true(44)=0.247242730557127186 true(45)=0.312129382035491301 true(46)=0.374494737701689822 true(47)=0.434338607372647125 true(48)=0.491662035432760524 true(49)=0.546467785483476383 true(50)=0.598760970245279030 true(51)=0.648549361126755851 true(52)=0.695843516905088648 true(53)=0.740657266848912124 true(54)=0.783008174791347177 true(55)=0.822917665884869456 true(56)=0.860411030561688098 true(57)=0.895517550233742218 true(58)=0.928270826293034365 true(59)=0.958708933474210358 true(60)=0.986874782150222219 true(61)=1.012816579967983789 true(62)=1.036587736684594479 true(63)=1.058246826485315033 true(64)=1.077857811432700289 true(65)=1.095490221995530989 true(66)=1.111219164319120026 true(67)=1.125125269269998022 true(68)=1.137294526582397119 true(69)=1.147818025203744592 true(70)=1.156792131966898566 true(71)=1.164318845152484938 true(72)=1.170505992580311363 true(73)=1.175467424328008220 true(74)=1.179323003206967714 true(75)=1.182198586301326345 true(76)=1.184226111211404704 true(77)=1.185543909813440450 true(78)=1.186297084230907673 true(79)=1.186637618874913665 true(80)=1.186724615129383839 sum=0.0D+0 do 270 k=1,80 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/80.0D+0) sumh=sumh+sum summ=max(summ,sum) 20 continue it2=mclock() tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh us=log10(summ) ut=log10(sumh) write(6,*) us,ut ID=0 WRITE(IORDMX,9921)(Y(I),I=1,NN) 9921 FORMAT(1X,F22.16) WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' IF(TARRAY(1).GT.300.)GOTO 66 C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE 66 CONTINUE STOP END c SUBROUTINE FTIGE(NN,T,TH,F) C --- RIGHT-HAND SIDE OF TIGEPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION TH(NN),F(NN) DIMENSION U(150),V(150),W(150) DIMENSION ALPHA(150),BETA(150),STH(150),CTH(150) COMMON/NNNN/N,NNCOM,NSQ,NQUATR,DELTAS COMMON/TOLD/TOLD c----------- C ----- CALCUL DES TH(I) ET DES SIN ET COS ------------- DO 22 I=2,N THDIFF=TH(I)-TH(I-1) STH(I)=DSIN(THDIFF) 22 CTH(I)=DCOS(THDIFF) C -------- CALCUL DU COTE DROIT DU SYSTEME LINEAIRE ----- IF(T.GT.3.14159265358979324D0)THEN C --------- CASE T GREATER PI ------------ C ---------- I=1 ------------ TERM1=(-3.D0*TH(1)+TH(2))*NQUATR V(1)=TERM1 C -------- I=2,..,N-1 ----------- DO 32 I=2,N-1 TERM1=(TH(I-1)-2.D0*TH(I)+TH(I+1))*NQUATR 32 V(I)=TERM1 C ----------- I=N ------------- TERM1=(TH(N-1)-TH(N))*NQUATR V(N)=TERM1 ELSE C --------- CASE T LESS EQUAL PI ------------ FABS=1.5D0*DSIN(T)*DSIN(T) FX=-FABS FY= FABS C ---------- I=1 ------------ TERM1=(-3.D0*TH(1)+TH(2))*NQUATR TERM2=NSQ*(FY*DCOS(TH(1))-FX*DSIN(TH(1))) V(1)=TERM1+TERM2 C -------- I=2,..,N-1 ----------- DO 34 I=2,N-1 TERM1=(TH(I-1)-2.D0*TH(I)+TH(I+1))*NQUATR TERM2=NSQ*(FY*DCOS(TH(I))-FX*DSIN(TH(I))) 34 V(I)=TERM1+TERM2 C ----------- I=N ------------- TERM1=(TH(N-1)-TH(N))*NQUATR TERM2=NSQ*(FY*DCOS(TH(N))-FX*DSIN(TH(N))) V(N)=TERM1+TERM2 END IF C -------- COMPUTE PRODUCT DV=W ------------ W(1)=STH(2)*V(2) DO 43 I=2,N-1 43 W(I)=-STH(I)*V(I-1)+STH(I+1)*V(I+1) W(N)=-STH(N)*V(N-1) C -------- TERME 3 ----------------- DO 435 I=1,N 435 W(I)=W(I)+TH(N+I)*TH(N+I) C ------- SOLVE SYSTEM CW=W --------- ALPHA(1)=1.D0 DO 44 I=2,N ALPHA(I)=2.D0 44 BETA(I-1)=-CTH(I) ALPHA(N)=3.D0 DO 45 I=N-1,1,-1 Q=BETA(I)/ALPHA(I+1) W(I)=W(I)-W(I+1)*Q 45 ALPHA(I)=ALPHA(I)-BETA(I)*Q W(1)=W(1)/ALPHA(1) DO 46 I=2,N 46 W(I)=(W(I)-BETA(I-1)*W(I-1))/ALPHA(I) C -------- COMPUTE U=CV+DW --------- U(1)=V(1)-CTH(2)*V(2)+STH(2)*W(2) DO 47 I=2,N-1 47 U(I)=2.D0*V(I)-CTH(I)*V(I-1)-CTH(I+1)*V(I+1) & -STH(I)*W(I-1)+STH(I+1)*W(I+1) U(N)=3.D0*V(N)-CTH(N)*V(N-1)-STH(N)*W(N-1) C -------- PUT DERIVATIVES IN RIGHT PLACE ------------- DO 54 I=1,N F(I)=TH(N+I) 54 F(N+I)=U(I) RETURN END C SUBROUTINE JTIGE(N,X,Y,ML,MU,DFY,LDFY) C --- JACOBIAN OF TIGEPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(LDFY,N) WRITE(6,*)' NE PAS ARRIVER DANS JTIGE ' STOP END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=80,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK) dimension true(nd),error(nd) REAL*4 TARRAY(2) COMMON/NNNN/NCOM,NNCOM,NSQ,NQUATR,DELTAS EXTERNAL FTIGE c ------ FILE DE DONNEES ---------- open(6,file='lsodebeam.res') write(6,3500) 3500 format(1x,'results on beam by lsode') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=2 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP sumh=0.0D+0 summ=0.0D+0 C ---------- CONSTANTS -------------- N=40 NN=2*N NCOM=N NSQ=N*N NQUATR=NSQ*NSQ NNCOM=NN AN=N DELTAS=1.D0/AN C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 C --------- MAXIMAL ORDER ----- IWORK(5)=5 ITASK=1 ISTATE=1 IOPT=1 MF=22 C --------- INITIAL VALUES ------------- T=0.D0 DO 1 I=1,NN 1 Y(I)=0.D0 TEND=5.D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=100000 it1=mclock() C --- CALL OF THE SUBROUTINE SDIRK4 CALL LSODE(FTIGE,NN,Y,T,TEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & FTIGE,MF) C --- PRINT SOLUTION true(1)=-0.005792366591294675 true(2)=-0.016952985507199259 true(3)=-0.027691033129713322 true(4)=-0.038008156558781729 true(5)=-0.047906168597422688 true(6)=-0.057387104352737008 true(7)=-0.066453273134522699 true(8)=-0.075107305819780661 true(9)=-0.083352197654124544 true(10)=-0.091191346546446469 true(11)=-0.098628587001297248 true(12)=-0.105668220037774708 true(13)=-0.112315039540924422 true(14)=-0.1 18574355272698475 true(15)=-0.124452012875526880 true(16)=-0.129954411326390999 true(17)=-0.135088518061004200 true(18)=-0.139861881919410397 true(19)=-0.144282644101482929 true(20)=-0.148359547246256976 true(21)=-0.152101942900106414 true(22)=-0.155519797806080921 true(23)=-0.158623699341992299 true(24)=-0.161424860370167541 true(25)=-0.163935123819275499 true(26)=-0.166166967344037066 true(27)=-0.168133508177817718 true(28)=-0.169848508060189926 true(29)=-0.171326378244038509 true(30)=-0.172582184746215274 true(31)=-0.173631653797526901 true(32)=-0.174491177383960691 true(33)=-0.175177818786287100 true(34)=-0.175709317871242317 true(35)=-0.176104096022807288 true(36)=-0.176381260717507812 true(37)=-0.176560609756417469 true(38)=-0.176662635226010517 true(39)=-0.176708527080694206 true(40)=-0.176720176107510191 true(41)= 0.037473626808570053 true(42)=0.109911788012810762 true(43)=0.179836047447039129 true(44)=0.247242730557127186 true(45)=0.312129382035491301 true(46)=0.374494737701689822 true(47)=0.434338607372647125 true(48)=0.491662035432760524 true(49)=0.546467785483476383 true(50)=0.598760970245279030 true(51)=0.648549361126755851 true(52)=0.695843516905088648 true(53)=0.740657266848912124 true(54)=0.783008174791347177 true(55)=0.822917665884869456 true(56)=0.860411030561688098 true(57)=0.895517550233742218 true(58)=0.928270826293034365 true(59)=0.958708933474210358 true(60)=0.986874782150222219 true(61)=1.012816579967983789 true(62)=1.036587736684594479 true(63)=1.058246826485315033 true(64)=1.077857811432700289 true(65)=1.095490221995530989 true(66)=1.111219164319120026 true(67)=1.125125269269998022 true(68)=1.137294526582397119 true(69)=1.147818025203744592 true(70)=1.156792131966898566 true(71)=1.164318845152484938 true(72)=1.170505992580311363 true(73)=1.175467424328008220 true(74)=1.179323003206967714 true(75)=1.182198586301326345 true(76)=1.184226111211404704 true(77)=1.185543909813440450 true(78)=1.186297084230907673 true(79)=1.186637618874913665 true(80)=1.186724615129383839 sum=0.0D+0 do 270 k=1,80 error(k)=dabs(true(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/80.0D+0) sumh=sumh+sum summ=max(summ,sum) 20 continue it2=mclock() tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh ID=0 c WRITE(IORDMX,9921)(Y(I),I=1,NN) 9921 FORMAT(1X,F22.16) WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' IF(TARRAY(1).GT.300.)GOTO 66 C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE 66 CONTINUE STOP END c SUBROUTINE FTIGE(NN,T,TH,F) C --- RIGHT-HAND SIDE OF TIGEPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION TH(NN),F(NN) DIMENSION U(150),V(150),W(150) DIMENSION ALPHA(150),BETA(150),STH(150),CTH(150) COMMON/NNNN/N,NNCOM,NSQ,NQUATR,DELTAS COMMON/TOLD/TOLD c----------- C ----- CALCUL DES TH(I) ET DES SIN ET COS ------------- DO 22 I=2,N THDIFF=TH(I)-TH(I-1) STH(I)=DSIN(THDIFF) 22 CTH(I)=DCOS(THDIFF) C -------- CALCUL DU COTE DROIT DU SYSTEME LINEAIRE ----- IF(T.GT.3.14159265358979324D0)THEN C --------- CASE T GREATER PI ------------ C ---------- I=1 ------------ TERM1=(-3.D0*TH(1)+TH(2))*NQUATR V(1)=TERM1 C -------- I=2,..,N-1 ----------- DO 32 I=2,N-1 TERM1=(TH(I-1)-2.D0*TH(I)+TH(I+1))*NQUATR 32 V(I)=TERM1 C ----------- I=N ------------- TERM1=(TH(N-1)-TH(N))*NQUATR V(N)=TERM1 ELSE C --------- CASE T LESS EQUAL PI ------------ FABS=1.5D0*DSIN(T)*DSIN(T) FX=-FABS FY= FABS C ---------- I=1 ------------ TERM1=(-3.D0*TH(1)+TH(2))*NQUATR TERM2=NSQ*(FY*DCOS(TH(1))-FX*DSIN(TH(1))) V(1)=TERM1+TERM2 C -------- I=2,..,N-1 ----------- DO 34 I=2,N-1 TERM1=(TH(I-1)-2.D0*TH(I)+TH(I+1))*NQUATR TERM2=NSQ*(FY*DCOS(TH(I))-FX*DSIN(TH(I))) 34 V(I)=TERM1+TERM2 C ----------- I=N ------------- TERM1=(TH(N-1)-TH(N))*NQUATR TERM2=NSQ*(FY*DCOS(TH(N))-FX*DSIN(TH(N))) V(N)=TERM1+TERM2 END IF C -------- COMPUTE PRODUCT DV=W ------------ W(1)=STH(2)*V(2) DO 43 I=2,N-1 43 W(I)=-STH(I)*V(I-1)+STH(I+1)*V(I+1) W(N)=-STH(N)*V(N-1) C -------- TERME 3 ----------------- DO 435 I=1,N 435 W(I)=W(I)+TH(N+I)*TH(N+I) C ------- SOLVE SYSTEM CW=W --------- ALPHA(1)=1.D0 DO 44 I=2,N ALPHA(I)=2.D0 44 BETA(I-1)=-CTH(I) ALPHA(N)=3.D0 DO 45 I=N-1,1,-1 Q=BETA(I)/ALPHA(I+1) W(I)=W(I)-W(I+1)*Q 45 ALPHA(I)=ALPHA(I)-BETA(I)*Q W(1)=W(1)/ALPHA(1) DO 46 I=2,N 46 W(I)=(W(I)-BETA(I-1)*W(I-1))/ALPHA(I) C -------- COMPUTE U=CV+DW --------- U(1)=V(1)-CTH(2)*V(2)+STH(2)*W(2) DO 47 I=2,N-1 47 U(I)=2.D0*V(I)-CTH(I)*V(I-1)-CTH(I+1)*V(I+1) & -STH(I)*W(I-1)+STH(I+1)*W(I+1) U(N)=3.D0*V(N)-CTH(N)*V(N-1)-STH(N)*W(N-1) C -------- PUT DERIVATIVES IN RIGHT PLACE ------------- DO 54 I=1,N F(I)=TH(N+I) 54 F(N+I)=U(I) RETURN END C SUBROUTINE JTIGE(N,X,Y,ML,MU,DFY,LDFY) C --- JACOBIAN OF TIGEPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(LDFY,N) WRITE(6,*)' NE PAS ARRIVER DANS JTIGE ' STOP END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT KS PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR RADAU5 (BANDED JACOBIAN) PARAMETER (MMM=9) PARAMETER (NH=2**MMM,N=2*NH,ND=2*NH-2) PARAMETER (IJAC=1,MLJAC=0,MUJAC=0,IMAS=0) PARAMETER (LE=2*MLJAC+MUJAC+1) PARAMETER (LWORK=ND*(LE+10)+22,LIWORK=ND+20) C --- DECLARATIONS DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),U(N) dimension true(nd),error(nd) COMMON/TRANS/QQ,UZERO REAL*4 TARRAY(2) EXTERNAL FKS,JKS,SOLOUT C --- DATA FOR THE PROBLEM QQ=0.025D0 c ------ FILE DE DONNEES ---------- write(6,3500) 3500 format(1x,'lsode on ks problem') C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=7 NTOLMX=10 NTOLDF=4 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP summ=0.0D+0 sumh=0.0D+0 C --- OUTPUT DURING INTEGRATION --- IOUT=0 C --- INITIAL VALUES T=0.0D0 C --- INITIAL POSITIONS IN Y-SPACE ---- AN=N DO I=1,N DELX=1.D0/AN X=DELX*(I-1) U1=MIN(X-0.0D0,0.1D0-X) U2=20.D0*(X-0.2D0)*(0.3D0-X) U3=MIN(X-0.6D0,0.7D0-X) U4=MIN(X-0.9D0,1.0D0-X) U(I)=16.D0*MAX(0.D0,U1,U2,U3,U4) END DO C --- FOURIER TRANSFORM --- CALL REALFT(U,NH,+1) DO I=1,N U(I)=U(I)/AN END DO C --- INITIAL POSITION IN FOURIER MODES --- UZERO=U(1) DO I=1,ND Y(I)=U(I+2) END DO C --- WRITE DATA TO FILE PLUS CONTROL --- U(1)=UZERO U(2)=0.D0 DO I=3,N U(I)=Y(I-2) END DO CALL REALFT(U,NH,-1) DO I=1,N U(I)=2.D0*U(I) END DO C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 C ----- BANDED ANALYTIC JACOBIAN -- MF=24 IWORK(1)=MLJAC IWORK(2)=MUJAC C ---------- VAL INIT ------------ X=0.D0 XEND=100.D0 C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=10000 it1=mclock() C --- CALL OF THE SUBROUTINE CALL LSODE(FKS,ND,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JKS,MF) C --- PRINT SOLUTION true(1)=0.0387294818017374 true(2)=0.0011594920936697 true(3)=0.0161135569739015 true(4)=-0.0497378990194494 true(5)=0.0161388094706610 true(6)=-0.0790294186417376 true(7)=-0.0562945063709753 true(8)=-0.0194501629216551 true(9)=-0.0317390967305054 true(10)=-0.0256301653146683 true(11)=-0.0896908152487471 true(16)=0.0452570608746347 true(21)=0.0110762324013310 true(26)=0.0095676261122614 true(31)=0.1089375008451597 true(36)=-0.1201229482736044 true(41)=-0.1354295218545231 true(46)=-0.0146538030311935 true(51)=-0.0092223615970260 true(56)=-0.2760611800802050 true(61)=-0.0174686339809433 true(66)=0.1982033914963349 true(71)=-0.1768843940011891 true(76)=0.3090308065592430 true(81)=-0.0952958329765616 true(86)=-0.1063846133920493 true(91)=0.0390151203721951 true(96)=0.0451950368314852 true(101)=0.0477521089259518 true(151)=0.0112038077853544 true(201)=0.0003656188545739 true(251)=-0.0001443415867781 true(301)=-0.0000090034942150 true(351)=0.0000016423881092 true(401)=0.0000001490634819 true(451)=0.0000000334389501 true(501)=-0.0000000020970060 true(551)=-0.0000000017295829 true(601)=0.0000000000353463 true(651)=0.0000000000036143 true(701)=0.0000000000004182 true(751)=-0.0000000000000002 true(801)=-0.0000000000000070 true(851)=-0.0000000000000012 true(901)=0.0000000000000001 true(951)=0.0000000000000000 true(1001)=0.0000000000000000 summ=0.0D+0 do 270 k=1,10 error(k)=dabs(y(k)-true(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue do 271 k=11,100,5 error(k)=dabs(y(k)-true(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 271 continue do 272 k=101,1024,50 error(k)=dabs(y(k)-true(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 272 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 CONTINUE CCC CALL DTIME(TARRAY) it2=mclock() tarray(1)=(it2-it1)/100.0D+0 WRITE(6,*)TARRAY(1),summ,sumh summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh ID=0 ID=0 WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' WRITE(6,91)IWORK(12),IWORK(13),IWORK(11),ID,ID,IWORK(13),ID 91 FORMAT(' fcn=',I5,' jac=',I4,' step=',I4, & ' accpt=',I4,' rejct=',I3,' dec=',I4, & ' sol=',I5) C -------- NEW TOLERANCE --- TOLST=TOLST*TOLFC IF (TARRAY(1).GT.1000.) STOP 30 CONTINUE STOP END C include 'fft.f' cc This module calculates the r.h.s for the KS equation cc cc d/dt u = - (dx^2+ dx^4)u - u u' cc cc in its form with fourier modes. cc I.e., the system cc cc dt u_n = (n^2 q^2 - n^4 q^4) u_n cc - (i q n/2) sum_{n_1+n_2=n} u_{n_1} u_{n_2} cc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc subroutine FKS(ND,T,Y,F) IMPLICIT REAL*8 (A-H,O-Z) PARAMETER (MMM=9) PARAMETER (NH=2**MMM,N=2*NH) DIMENSION y(ND),f(ND) DIMENSION U(N) COMMON/TRANS/QQ,UZERO c --- copy y to u U(1)=UZERO U(2)=0.D0 DO I=3,N U(I)=Y(I-2) END DO CALL REALFT(U,NH,-1) DO I=1,N U(I)=2.D0*U(I) END DO C --- SQUARE ------ DO I=1,N U(I)=U(I)**2/2.D0 END DO C --- TRANSFORM BACK --- CALL REALFT(U,NH,+1) AN=N DO I=1,N U(I)=U(I)/AN END DO do J=1,NH-1 DIAG=(QQ*J)**2*(1.D0-(QQ*J)**2) F(2*J-1)=DIAG*Y(2*J-1) +QQ*J*U(2*J+2) F(2*J )=DIAG*Y(2*J ) -QQ*J*U(2*J+1) enddo end c-------------------------------------------------------------- subroutine JKS(ND,x,y,ML,MU,dfy,ldfy) PARAMETER (MMM=9) PARAMETER (NH=2**MMM,N=2*NH) IMPLICIT REAL*8 (A-H,O-Z) DIMENSION y(ND),DFY(LDFY,ND) COMMON/TRANS/QQ,UZERO do J=1,NH-1 DIAG=(QQ*J)**2*(1.D0-(QQ*J)**2) DFY(1,2*J-1)=DIAG DFY(1,2*J )=DIAG enddo end PROGRAM LSODRIV DOUBLE PRECISION pi, hmax, hstart, hnext, t, tend, tol DOUBLE PRECISION y(60000),atol,rtol,dx,sumer DOUBLE PRECISION mi,kcns,dif,err,errm,tout,rwork(800000) INTEGER iprob,n,nbsol,mf,ml,mu,miter,itol,itask, + iwork(61000),lrw,liw EXTERNAL f, jac REAL time, tbks, tlu COMMON /TIMVAR/tbks,tlu COMMON /bsub/nbsol COMMON /MXER/ERRM COMMON /ipr/iprob,ntop,atol,rtol COMMON /const/kcns,pi,mi,dif,dx common /dim/n open(6,file='lsodeflood.hardres') pi=4.0d0*datan(1.0d0) c c... Burger's equation parameter. c mi=1.0d-05 ntop=20 c c... Diffusion coefficient. c dif=2.0d-05 c dif=4.0d+0/500000.0d+0 c c... Stiffness parameter. c kcns=5.0d1 c c... iprob=1 Heat flow, iprob=2 Stiff parabolic, c iprob=3 Advection-Diffusion, iprob=4 Burger's equation. write(6,*) write(6,*) ' tol ',' fns ',' bsubs ',' jacs ',' fact', + ' stps ',' time ',' max err',' end err' write(6,*) c c... Solve for tolerances 10**(-i). c c c... Number of equations. c n=1999 write(6,*) n,dif do 10 i=2,10 c lrw = 22+10*n+(2*ml+mu)*n c liw = 20 + n lrw=800000 liw=61000 c c... Spatial Mesh (x-mesh) stepsize. c dx=4.0d0/(n+1.0d0) c mf=25 ml = 1 mu = 1 c c...mu, ml upper, lower bandwidth respectively. c iwork(1) = ml iwork(2) = mu c do 40 j=1,n y(j)=dexp(-(-2.0d0+j*dx)**2) 40 continue c c... Integration interval (in respect to time). c t=0.0d0 c c... Advection-diffusion. tend=4.d0 c tout=tend c c... Starting stepsize. c iopt = 1 istate = 1 itask = 2 itol = 1 hstart = 1.0d-5 hmax = tend-t rwork(5) = hstart rwork(6) = hmax atol = 10.d0**(-i) rtol = atol c it1 = mclock() errm=0.0d0 tbks=0.0 tlu=0.0 60 IF ( t.ge.tend ) goto 70 call lsode(f, n, y, t, tout, itol, rtol, atol, itask, + istate, iopt, rwork, lrw, iwork, liw, jac, mf) err=0.0d0 do 30 j=1,n err=err+((y(j)-(1.0d0/dsqrt(1.0d0+4.0d0*dif*t))* & dexp(-((-2.0d0+j*dx-t)**2)/(1.0d0+4.0d0*dif*t)))**2) + /((rtol*dabs(y(j))+atol)**2) 30 continue c err=dsqrt(err/n)*atol errm=dmax1(errm,err) write(6,*) errm,err hnext = rwork(12) if ( t+hnext.gt.tend ) then itask = 1 tout = tend endif goto 60 70 it2 = mclock() time = .01*float(it2-it1) err=0.0d0 c... Advection Diffusion. do 130 j=1,n err=err+((y(j)-(1.d0/dsqrt(1.d0+4.d0*dif*t))* & dexp(-((-2.d0+j*dx-t)**2)/(1.0d0+4.0d0*dif*t)))**2) + /((atol+rtol*dabs(y(j)))**2) 130 continue err=dsqrt(err/n)*atol write(6,600)-i,iwork(12),NBSOL,iwork(13),iwork(13),iwork(11), & time,errm,err 10 continue 600 format (I5,I5,I6,I6,I6,I5,F8.2,E9.3,E9.3) 500 format (5(F20.16)) stop end c c c... Right Hand side of y'=f(t,y) c c c subroutine f(n,tn,y,dy) integer n double precision tn,y(*),dy(*) c c implicit double precision (a-h,o-z) integer iprob common /ipr/iprob,ntop,atol,rtol double precision y0, yN double precision kcns,pi,mi,dif,dx,amult,prod,rat common /const/kcns,pi,mi,dif,dx double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri,rc, + gamma,delta,sumer, + uin1,uin2,ud1,ud2,ud3,ud4,qud1,qud2,qud3,qud4 parameter (c=1.6d-8,cs=1d-9,cp=1d-8,r=25d3,rp=50d0, + lh=4.45d0,ls1=2d-3,ls2=5d-4,ls3=5d-4, + rg1=36.3d0,rg2=17.3d0,rg3=17.3d0,ri=5d1,rc=6d2, + gamma=40.67286402d-9,delta=17.7493332d0) c c... Heat Equation (non insulated rod) c amult=2.0d0*dx prod=dx*dx y0=(1.0d0/dsqrt(1.d0+4.0d0*dif*tn))*dexp(-((-2.0d0-tn)**2)/ & (1.0d0+4.0d0*dif*tn)) yN=(1.0d0/dsqrt(1.d0+4.d0*dif*tn))*dexp(-((2.d0-tn)**2)/ & (1.0d0+4.0d0*dif*tn)) dy(1)=dif*(y0-2.d0*y(1)+y(2))/(dx*dx)-(y(2)-y0)/(2.d0*dx) rat=dif/prod do 30 i=2,n-1 dy(i)=rat*(y(i-1)-2.0d0*y(i)+y(i+1))- & (y(i+1)-y(i-1))/(amult) 30 continue dy(n)=dif*(y(n-1)-2.d0*y(n)+yN)/(dx*dx)-(yN-y(n-1))/(2.d0*dx) return end c c c subroutine fcn(tn,y,dy) double precision tn, y(*), dy(*) common /dim/n c call f(n,tn,y,dy) c return end c c c... Jacobian matrix df/dy c c subroutine jac(n,tn,y,ml,mu,pd,meband) integer n, ml, mu, meband double precision tn,y(*),pd(meband,n) c c c implicit double precision (a-h,o-z) integer iprob common /ipr/iprob,ntop,atol,rtol double precision kcns,pi,mi,dif,dx,amult,prod,rat,a1,a2,a3,u common /const/kcns,pi,mi,dif,dx double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri,rc, + gamma,delta,sumer, + uin2,ud1,ud2,ud3,ud4,qpud1,qpud2,qpud3,qpud4 parameter (c=1.6d-8,cs=1d-9,cp=1d-8,r=25d3,rp=50d0, + lh=4.45d0,ls1=2d-3,ls2=5d-4,ls3=5d-4, + rg1=36.3d0,rg2=17.3d0,rg3=17.3d0,ri=5d1,rc=6d2, + gamma=40.67286402d-9,delta=17.7493332d0) prod=dx*dx amult=2.0d0*dx a1=dif/prod a2=-1.0d0/amult a3=-2.0d0*a1 u=a1+a2 do 70 j=2,n pd(1,j)=u 70 continue do 80 j=1,n pd(2,j)=a3 80 continue u=a1-a2 do 90 j=1,n-1 pd(3,j)=u 90 continue return end c c c subroutine maxerr(n,tn,errm,y) integer n double precision tn,errm,y(n) c integer iprob,ntol common /ipr/iprob,ntop,atol,rtol double precision err,kcns,dif,dx,mi,pi,sumer common /const/kcns,pi,mi,dif,dx c err=0.0d0 do 30 j=1,n err=err+((y(j)-(1.0d0/dsqrt(1.0d0+4.0d0*dif*tn))* & dexp(-((-2.0d0+j*dx-tn)**2)/(1.0d0+4.0d0*dif*tn)))**2) + /((rtol*dabs(y(j))+atol)**2) 30 continue c err=dsqrt(err/n)*atol errm=dmax1(errm,err) write(6,*) errm,err c return end PROGRAM LSODRIV DOUBLE PRECISION pi, hmax, hstart, hnext, t, tend, tol DOUBLE PRECISION y(60000),atol,rtol,dx,sumer DOUBLE PRECISION mi,kcns,dif,err,errm,tout,rwork(800000) INTEGER iprob,n,nbsol,mf,ml,mu,miter,itol,itask, + iwork(61000),lrw,liw EXTERNAL f, jac REAL time, tbks, tlu COMMON /TIMVAR/tbks,tlu COMMON /bsub/nbsol COMMON /MXER/ERRM COMMON /ipr/iprob,ntop COMMON /const/kcns,pi,mi,dif,dx common /dim/n open(6,file='lsodehard.bigres250') pi=4.0d0*datan(1.0d0) c c... Burger's equation parameter. c mi=1.0d-05 ntop=250 n=49999 write(6,*) ntop,n c 8335 format(1x,g22.10,i8) c... Diffusion coefficient. c dif=2.0d-05 c dif=4.0d+0/500000.0d+0 c c... Stiffness parameter. c kcns=5.0d1 c c... iprob=1 Heat flow, iprob=2 Stiff parabolic, c iprob=3 Advection-Diffusion, iprob=4 Burger's equation. c iprob = 5 c write(6,*) write(6,*) ' tol ',' fns ',' bsubs ',' jacs ',' fact', + ' stps ',' time ',' max err',' end err' write(6,*) c c... Solve for tolerances 10**(-i). c c c... Number of equations. c 8440 format(1x,i8) do 10 i=2,10 c lrw = 22+10*n+(2*ml+mu)*n c liw = 20 + n lrw=800000 liw=61000 c c... Spatial Mesh (x-mesh) stepsize. c dx=1.0d0/(n+1.0d0) c mf=25 ml = 1 mu = 1 err=0.0D+0 errm=0.0D+0 c c...mu, ml upper, lower bandwidth respectively. c iwork(1) = ml iwork(2) = mu c do 201 j=1,n sumer=0.0d+0 do 21 jj=1,ntop sumer=sumer+dsin(pi*jj*j*dx) 21 continue y(j)=sumer 201 continue c c... Integration interval (in respect to time). c t=0.0d0 c tend=2.0d+0 c tout=tend c c... Starting stepsize. c iopt = 1 istate = 1 itask = 2 itol = 1 hstart = 1.0d-5 hmax = tend-t rwork(5) = hstart rwork(6) = hmax atol = 10.d0**(-i) rtol = atol c it1 = mclock() errm=0.0d0 tbks=0.0 tlu=0.0 60 IF ( t.ge.tend ) goto 70 call lsode(f, n, y, t, tout, itol, rtol, atol, itask, + istate, iopt, rwork, lrw, iwork, liw, jac, mf) err=0.0d0 do 120 j=1,n sumer=0.0d+0 do 121 jj=1,ntop sumer=sumer+dexp(-pi*pi*t*jj*jj)*dsin(pi*jj*j*dx) 121 continue err=err+((y(j)-sumer)/(rtol*dabs(y(j))+atol))**2 120 continue err=dsqrt(err/n)*atol if(err.gt.errm) errm=err hnext = rwork(12) if ( t+hnext.gt.tend ) then itask = 1 tout = tend endif goto 60 70 it2 = mclock() time = .01*float(it2-it1) err=0.0d0 do 1200 j=1,n sumer=0.0d+0 do 1201 jj=1,ntop sumer=sumer+dexp(-pi*pi*t*jj*jj)*dsin(pi*jj*j*dx) 1201 continue err=err+((y(j)-sumer)/(rtol*dabs(y(j))+atol))**2 1200 continue err=dsqrt(err/n)*atol write(6,600)-i,iwork(12),NBSOL,iwork(13),iwork(13),iwork(11), & time,errm,err 10 continue 600 format (I5,I5,I6,I6,I6,I5,F8.2,E9.3,E9.3) 500 format (5(F20.16)) stop end c c c... Right Hand side of y'=f(t,y) c c c subroutine f(n,tn,y,dy) integer n double precision tn,y(*),dy(*) c c implicit double precision (a-h,o-z) integer iprob common /ipr/iprob,ntop double precision y0, yN double precision kcns,pi,mi,dif,dx,amult,prod,rat common /const/kcns,pi,mi,dif,dx double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri,rc, + gamma,delta,sumer, + uin1,uin2,ud1,ud2,ud3,ud4,qud1,qud2,qud3,qud4 parameter (c=1.6d-8,cs=1d-9,cp=1d-8,r=25d3,rp=50d0, + lh=4.45d0,ls1=2d-3,ls2=5d-4,ls3=5d-4, + rg1=36.3d0,rg2=17.3d0,rg3=17.3d0,ri=5d1,rc=6d2, + gamma=40.67286402d-9,delta=17.7493332d0) c c... Heat Equation (non insulated rod) c amult=2.0d0*dx prod=dx*dx SUMER=0.0D+0 do 103 i=1,ntop sumer=sumer+dexp(-pi*pi*tn*i*i)*dsin(pi*dx*i) 103 continue dy(1)=(y(2)-2.0d0*y(1))/(dx*dx)+y(1)**2-0.5d+0*y(1)*sumer- + 0.5d+0*sumer**2 do 101 i=2,n-1 sumer=0.0d+0 do 104 ii=1,ntop sumer=sumer+dexp(-pi*pi*tn*ii*ii)*dsin(pi*i*ii*dx) 104 continue dy(i)=(y(i-1)-2.0d0*y(i)+y(i+1))/prod + +y(I)**2-0.5D+0*y(i)*sumer-0.5D+0*sumer**2 101 continue sumer=0.0D+0 do 105 II=1,ntop sumer=sumer+dexp(-pi*pi*tn*ii*ii)*dsin(pi*n*dx*ii) 105 continue dy(n)=(y(n-1)-2.0d0*y(n))/(dx*dx) + +y(n)**2-0.5D+0*y(n)*sumer-0.5D+0*sumer**2 return end c c subroutine fcn(tn,y,dy) double precision tn, y(*), dy(*) common /dim/n c call f(n,tn,y,dy) c return end c c c... Jacobian matrix df/dy c c subroutine jac(n,tn,y,ml,mu,pd,meband) integer n, ml, mu, meband double precision tn,y(*),pd(meband,n) c c c implicit double precision (a-h,o-z) integer iprob common /ipr/iprob,ntop double precision kcns,pi,mi,dif,dx,amult,prod,rat,a1,a2,a3,u common /const/kcns,pi,mi,dif,dx double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri,rc, + gamma,delta,sumer, + uin2,ud1,ud2,ud3,ud4,qpud1,qpud2,qpud3,qpud4 parameter (c=1.6d-8,cs=1d-9,cp=1d-8,r=25d3,rp=50d0, + lh=4.45d0,ls1=2d-3,ls2=5d-4,ls3=5d-4, + rg1=36.3d0,rg2=17.3d0,rg3=17.3d0,ri=5d1,rc=6d2, + gamma=40.67286402d-9,delta=17.7493332d0) prod=dx*dx amult=2.0d0*dx a1=1.0d0/prod a2=-2.0d0/prod do 141 j=2,n pd(1,j)=a1 141 continue u=a2 do 142 j=1,n sumer=0.0D+0 do 143 k=1,ntop sumer=sumer+dexp(-pi*pi*tn*k*k)*dsin(pi*j*dx*k) 143 continue pd(2,j)=u+2.0D+0*y(j)-0.5D+0*sumer 142 continue do 144 j=1,n-1 pd(3,j)=a1 144 continue return end c c c c subroutine maxerr(n,tn,errm,y) integer n double precision tn,errm,y(n) c integer iprob,ntol common /ipr/iprob,ntop double precision err,kcns,dif,dx,mi,pi,sumer common /const/kcns,pi,mi,dif,dx c err=0.0d0 c if ( iprob.eq.1 ) then do 10 j=1,n err=err+(y(j)-exp(-(pi*pi+1.0)*tn)*sin(pi*j*dx))**2 10 continue else if ( iprob.eq.2 ) then do 20 j=1,n err=err+(y(j)-exp(-pi*pi*tn)*sin(pi*j*dx) - + exp(-kcns*kcns*pi*pi*tn)*sin(kcns*pi*j*dx))**2 20 continue else if ( iprob.eq.3 ) then do 30 j=1,n err=err+(y(j)-(1.0d0/dsqrt(1.0d0+4.0d0*dif*tn))* & dexp(-((-2.0d0+j*dx-tn)**2)/(1.0d0+4.0d0*dif*tn)))**2 30 continue else if ( iprob.eq.4 ) then do 40 j=1,n err=err+ + (y(j)-1.0d0/(1.0d0+exp((j*dx)/(2.0d0*mi)- +tn/(4.0d0*mi))))**2 40 continue else if(iprob.eq.5) then do 31 j=1,n sumer=0.0D+0 do 33 i=1,ntop sumer=sumer+dexp(-tn*pi*pi*i*i)*dsin(dx*pi*i*j) 33 continue err=err+(y(j)-sumer)**2 c write(6,3048) err,sumer,y(j),j 3048 format(1x,3g22.10,i8) 31 continue else if(iprob.eq.6) then do 35 j=1,n aco=dexp(-0.05d+0*(j*dx-0.5D+0+4.95D+0*tn)/mi) bco=dexp(-0.25D+0*(j*dx-0.5D+0+0.75D+0*tn)/mi) cco=dexp(-0.5D+0*(j*dx-0.375D+0)/mi) err=err+(y(j)-(0.1D+0*aco+0.5D+0*bco+cco)/(aco+bco+cco))**2 35 continue else if(iprob.eq.7) then err=0.0D+0 endif c err=dsqrt(err/n) errm=dmax1(errm,err) c return end PROGRAM LSODRIV DOUBLE PRECISION pi, hmax, hstart, hnext, t, tend, tol DOUBLE PRECISION y(60000),atol,rtol,dx,sumer DOUBLE PRECISION mi,kcns,dif,err,errm,tout,rwork(800000) INTEGER iprob,n,nbsol,mf,ml,mu,miter,itol,itask, + iwork(61000),lrw,liw EXTERNAL f, jac REAL time, tbks, tlu COMMON /TIMVAR/tbks,tlu COMMON /bsub/nbsol COMMON /MXER/ERRM COMMON /ipr/iprob,ntop,atol,rtol COMMON /const/kcns,pi,mi,dif,dx common /dim/n open(6,file='lsodeflood.hardres') pi=4.0d0*datan(1.0d0) c c... Burger's equation parameter. c mi=1.0d-05 ntop=20 c c... Diffusion coefficient. c dif=2.0d-05 dif=4.0d+0/500000.0d+0 c c... Stiffness parameter. c kcns=5.0d1 c c... iprob=1 Heat flow, iprob=2 Stiff parabolic, c iprob=3 Advection-Diffusion, iprob=4 Burger's equation. write(6,*) write(6,*) ' tol ',' fns ',' bsubs ',' jacs ',' fact', + ' stps ',' time ',' max err',' end err' write(6,*) c c... Solve for tolerances 10**(-i). c c c... Number of equations. c n=49999 write(6,*) n,dif do 10 i=2,10 c lrw = 22+10*n+(2*ml+mu)*n c liw = 20 + n lrw=800000 liw=61000 c c... Spatial Mesh (x-mesh) stepsize. c dx=4.0d0/(n+1.0d0) c mf=25 ml = 1 mu = 1 c c...mu, ml upper, lower bandwidth respectively. c iwork(1) = ml iwork(2) = mu c do 40 j=1,n y(j)=dexp(-(-2.0d0+j*dx)**2) 40 continue c c... Integration interval (in respect to time). c t=0.0d0 c c... Advection-diffusion. tend=4.d0 c tout=tend c c... Starting stepsize. c iopt = 1 istate = 1 itask = 2 itol = 1 hstart = 1.0d-5 hmax = tend-t rwork(5) = hstart rwork(6) = hmax atol = 10.d0**(-i) rtol = atol c it1 = mclock() errm=0.0d0 tbks=0.0 tlu=0.0 60 IF ( t.ge.tend ) goto 70 call lsode(f, n, y, t, tout, itol, rtol, atol, itask, + istate, iopt, rwork, lrw, iwork, liw, jac, mf) err=0.0d0 do 30 j=1,n err=err+((y(j)-(1.0d0/dsqrt(1.0d0+4.0d0*dif*t))* & dexp(-((-2.0d0+j*dx-t)**2)/(1.0d0+4.0d0*dif*t)))**2) + /((rtol*dabs(y(j))+atol)**2) 30 continue c err=dsqrt(err/n)*atol errm=dmax1(errm,err) hnext = rwork(12) if ( t+hnext.gt.tend ) then itask = 1 tout = tend endif goto 60 70 it2 = mclock() time = .01*float(it2-it1) err=0.0d0 c... Advection Diffusion. do 130 j=1,n err=err+((y(j)-(1.d0/dsqrt(1.d0+4.d0*dif*t))* & dexp(-((-2.d0+j*dx-t)**2)/(1.0d0+4.0d0*dif*t)))**2) + /((atol+rtol*dabs(y(j)))**2) 130 continue err=dsqrt(err/n)*atol write(6,600)-i,iwork(12),NBSOL,iwork(13),iwork(13),iwork(11), & time,errm,err 10 continue 600 format (I5,I5,I6,I6,I6,I5,F8.2,E9.3,E9.3) 500 format (5(F20.16)) stop end c c c... Right Hand side of y'=f(t,y) c c c subroutine f(n,tn,y,dy) integer n double precision tn,y(*),dy(*) c c implicit double precision (a-h,o-z) integer iprob common /ipr/iprob,ntop,atol,rtol double precision y0, yN double precision kcns,pi,mi,dif,dx,amult,prod,rat common /const/kcns,pi,mi,dif,dx double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri,rc, + gamma,delta,sumer, + uin1,uin2,ud1,ud2,ud3,ud4,qud1,qud2,qud3,qud4 parameter (c=1.6d-8,cs=1d-9,cp=1d-8,r=25d3,rp=50d0, + lh=4.45d0,ls1=2d-3,ls2=5d-4,ls3=5d-4, + rg1=36.3d0,rg2=17.3d0,rg3=17.3d0,ri=5d1,rc=6d2, + gamma=40.67286402d-9,delta=17.7493332d0) c c... Heat Equation (non insulated rod) c amult=2.0d0*dx prod=dx*dx y0=(1.0d0/dsqrt(1.d0+4.0d0*dif*tn))*dexp(-((-2.0d0-tn)**2)/ & (1.0d0+4.0d0*dif*tn)) yN=(1.0d0/dsqrt(1.d0+4.d0*dif*tn))*dexp(-((2.d0-tn)**2)/ & (1.0d0+4.0d0*dif*tn)) dy(1)=dif*(y0-2.d0*y(1)+y(2))/(dx*dx)-(y(2)-y0)/(2.d0*dx) rat=dif/prod do 30 i=2,n-1 dy(i)=rat*(y(i-1)-2.0d0*y(i)+y(i+1))- & (y(i+1)-y(i-1))/(amult) 30 continue dy(n)=dif*(y(n-1)-2.d0*y(n)+yN)/(dx*dx)-(yN-y(n-1))/(2.d0*dx) return end c c c subroutine fcn(tn,y,dy) double precision tn, y(*), dy(*) common /dim/n c call f(n,tn,y,dy) c return end c c c... Jacobian matrix df/dy c c subroutine jac(n,tn,y,ml,mu,pd,meband) integer n, ml, mu, meband double precision tn,y(*),pd(meband,n) c c c implicit double precision (a-h,o-z) integer iprob common /ipr/iprob,ntop,atol,rtol double precision kcns,pi,mi,dif,dx,amult,prod,rat,a1,a2,a3,u common /const/kcns,pi,mi,dif,dx double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri,rc, + gamma,delta,sumer, + uin2,ud1,ud2,ud3,ud4,qpud1,qpud2,qpud3,qpud4 parameter (c=1.6d-8,cs=1d-9,cp=1d-8,r=25d3,rp=50d0, + lh=4.45d0,ls1=2d-3,ls2=5d-4,ls3=5d-4, + rg1=36.3d0,rg2=17.3d0,rg3=17.3d0,ri=5d1,rc=6d2, + gamma=40.67286402d-9,delta=17.7493332d0) prod=dx*dx amult=2.0d0*dx a1=dif/prod a2=-1.0d0/amult a3=-2.0d0*a1 u=a1+a2 do 70 j=2,n pd(1,j)=u 70 continue do 80 j=1,n pd(2,j)=a3 80 continue u=a1-a2 do 90 j=1,n-1 pd(3,j)=u 90 continue return end PROGRAM LSODRIV DOUBLE PRECISION pi, hmax, hstart, hnext, t, tend, tol DOUBLE PRECISION y(60000),atol,rtol,dx,sumer DOUBLE PRECISION mi,kcns,dif,err,errm,tout,rwork(800000) INTEGER iprob,n,nbsol,mf,ml,mu,miter,itol,itask, + iwork(61000),lrw,liw EXTERNAL f, jac REAL time, tbks, tlu COMMON /TIMVAR/tbks,tlu COMMON /bsub/nbsol COMMON /MXER/ERRM COMMON /ipr/iprob,ntop,atol,rtol COMMON /const/kcns,pi,mi,dif,dx common /dim/n open(6,file='lsodeflood.hardres') pi=4.0d0*datan(1.0d0) c c... Burger's equation parameter. c mi=1.0d-05 ntop=20 c c... Diffusion coefficient. c c dif=2.0d-05 dif=4.0d+0/500000.0d+0 c c... Stiffness parameter. c kcns=5.0d1 c c... iprob=1 Heat flow, iprob=2 Stiff parabolic, c iprob=3 Advection-Diffusion, iprob=4 Burger's equation. write(6,*) write(6,*) ' tol ',' fns ',' bsubs ',' jacs ',' fact', + ' stps ',' time ',' max err',' end err' write(6,*) c c... Solve for tolerances 10**(-i). c c c... Number of equations. c n=49999 write(6,*) n,dif do 10 i=2,4 c lrw = 22+10*n+(2*ml+mu)*n c liw = 20 + n lrw=800000 liw=61000 c c... Spatial Mesh (x-mesh) stepsize. c dx=4.0d0/(n+1.0d0) c mf=25 ml = 1 mu = 1 c c...mu, ml upper, lower bandwidth respectively. c iwork(1) = ml iwork(2) = mu c do 40 j=1,n y(j)=dexp(-(-2.0d0+j*dx)**2) 40 continue c c... Integration interval (in respect to time). c t=0.0d0 c c... Advection-diffusion. tend=4.d0 c tout=tend c c... Starting stepsize. c iopt = 1 istate = 1 itask = 2 itol = 1 hstart = 1.0d-5 hmax = tend-t rwork(5) = df(3)=-4.0D+0*y(3) df(4)=-y(4) df(5)=-0.5D+0*y(5) df(6)=-0.1D+0*y(6) RETURN END C SUBROUTINE jvander(n,X,Y,ml,mu,DFY,ldfy) C --- JACOBIAN OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),DFY(ldfy,N) DFY(1,1)=-10.0D0 DFY(1,2)=500.D0 DFY(2,1)=-500.0D+0 DFY(2,2)=-10.0D+0 dfy(3,3)=-4.0D+0 dfy(4,4)=-1.0D+0 dfy(5,5)=-0.5D+0 dfy(6,6)=-0.1D+0 RETURN END C * * * * * * * * * * * * * * * * * * * * * * * * * C --- DRIVER FOR LSODE AT VANDERPOL PROBLEM C * * * * * * * * * * * * * * * * * * * * * * * * * IMPLICIT REAL*8 (A-H,O-Z) C --- PARAMETERS FOR LSODE (FULL JACOBIAN) PARAMETER (ND=15,LWORK=22+9*ND+ND**2,LIWORK=ND+20) DIMENSION Y(ND),WORK(LWORK),IWORK(LIWORK),yend(nd), + error(nd) REAL*4 TARRAY(2) common/const/pi EXTERNAL FVANDER,JVANDER c ------ FILE DE DONNEES ---------- open(6,file='lsodebigring.res') write(6,3080) 3080 format(1x,'results for lsode on bigring') pi=4.0D+0*datan(1.0D+0) C --- LOOP FOR DIFFERENT TOLERANCES NTOLMN=3 NTOLMX=12 NTOLDF=2 NRLOOP=(NTOLMX-NTOLMN)*NTOLDF+1 TOLST=0.1D0**NTOLMN TOLFC=0.1D0**(1.D0/NTOLDF) DO 30 NTOL=1,NRLOOP summ=0.0D+0 summh=0.0D+0 C --- DIMENSION OF THE SYSTEM N=15 C --- SET DEFAULT VALUES DO 12 I=5,10 WORK(I)=0.D0 12 IWORK(I)=0 ITASK=1 ISTATE=1 IOPT=1 MF=21 C --- INITIAL VALUES X=0.0D0 do 751 ijk=1,15 y(ijk)=0.0D+0 751 continue C --- REQUIRED TOLERANCE RTOL=TOLST ATOL=RTOL ITOL=1 C --- MAXIMAL NUMBER OF STEPS IWORK(6)=5000000 C --- ENDPOINT OF INTEGRATION XEND=1.0d-3 c CALL DTIME(TARRAY) it1=mclock() DO 20 I=1,1 C --- CALL OF THE SUBROUTINE CALL LSODE(FVANDER,N,Y,X,XEND, & ITOL,RTOL,ATOL, & ITASK,ISTATE,IOPT, & WORK,LWORK,IWORK,LIWORK, & JVANDER,MF) C --- PRINT SOLUTION c WRITE (6,*) Y(1) c WRITE (6,*) Y(2) c yend(1)=-0.233905735842070174E-01 yend(2)=-0.736748548598215210E-02 yend(3)=0.258295670891733276 yend(4)=-0.406446572164108511 yend(5)=-0.403945566551075719 yend(6)=0.260796676505321678 yend(7)= 0.110676186126208484 yend(8)=0.293990434238965346E-06 yend(9)=-0.284002993248608379E-07 yend(10)=0.726719826722729682E-03 yend(11)=0.792948719688146885E-03 yend(12)= -0.725528349561929123E-03 yend(13)=-0.794140196849026266E-03 yend(14)=0.708849541688199994E-04 yend(15)=0.239005907525775679E-04 sum=0.0D+0 do 270 k=1,15 error(k)=dabs(yend(k)-y(k)) sum=sum+((error(k)/(rtol*dabs(y(k))+atol))**2) 270 continue sum=dsqrt(sum/dble(nd)) sumh=sumh+sum summ=max(summ,sum) 20 continue it2=mclock() tarray(1)=(it2-it1)/100.0D+0 write(6,*) x,y(1),y(2) WRITE(6,*)TARRAY(1),summ,sumh/11.0d+0 summ=summ*atol sumh=sumh*atol write(6,*) summ,sumh ID=0 WRITE(6,*)ID,ID,ID,ID,ID,ID,ID WRITE(6,*)' ***** TOL=',RTOL,' ELAPSED TIME=',TARRAY(1),' ****' write(6,91) iwork(12),iwork(13),iwork(11),id,id,iwork(13),id 91 format(' fcn =',i5,' jac =' ,i4,' step=',i4, + 'accept=',i4,'reject=', i4, 'dec=',i4, 'sol=',i4) C -------- NEW TOLERANCE --- 25 TOLST=TOLST*TOLFC 30 CONTINUE STOP END c SUBROUTINE FVANDER(N,tn,Y,dy) C --- RIGHT-HAND SIDE OF VANDERPOL EQUATION IMPLICIT REAL*8 (A-H,O-Z) DIMENSION Y(N),dy(N) c double precision y0, yN double precision kcns,pi,mi,dif,dx,amult,prod,rat common /const/pi double precision + c,cs,cp,r,rp,lh,ls1,ls2,ls3,rg1,rg2,rg3,ri