1 SUBROUTINE INTEGRATE
( TIN
, TOUT
)
3 INCLUDE
'KPP_ROOT_params.h'
4 INCLUDE
'KPP_ROOT_global.h'
12 KPP_REAL V
(NVAR
), VOLD
(NVAR
), VNEW
(NVAR
)
13 KPP_REAL startdt
, hmin
, hmax
, h
20 c Number of Jacobi-Seidel iterations
28 CALL twostepj
(NVAR
,TIN
,TOUT
,h
,hmin
,hmax
,
31 + nfcn
,naccpt
,nrejec
,nstart
,startdt
,ITER
)
39 SUBROUTINE ITER
(n
,T
,y
,yp
,yl
)
40 INCLUDE
'KPP_ROOT_params.h'
41 INCLUDE
'KPP_ROOT_global.h'
42 REAL*8 T
, y
(NVAR
), yp
(NVAR
), yl
(NVAR
)
47 CALL FunSPLIT_VAR
(y
,Rad
,yp
,yl
)
53 subroutine twostepj
(n
,t
,te
,dt
,dtmin
,dtmax
,
56 + nfcn
,naccpt
,nrejec
,nstart
,startdt
,ITER
)
57 implicit real*8 (a
-h
,o
-z
)
59 integer n
,numit
,nfcn
,naccpt
,nrejec
,nstart
,i
,j
60 real*8 t
,te
,dt
,dtmin
,dtmax
,startdt
,ytol
,
61 + ratio
,dtold
,a1
,a2
,c
,cp1
,dtg
,errlte
,dy
62 real*8 yold
(n
),y
(n
),ynew
(n
),yp
(n
),yl
(n
),
63 + work
(n
),sum
(n
),atol
(n
),rtol
(n
)
64 logical accept
,failer
,restart
67 c Initialization of counters, etc.
77 c Initial stepsize computation.
79 10 if (dtmin
.eq
.dtmax
) then
81 dt
=min
(dtmin
,(te
-t
)/2)
84 CALL ITER
(n
,t
,y
,yp
,yl
)
88 ytol
=atol
(i
)+rtol
(i
)*abs
(y
(i
))
90 if (dy
.ne
.0.0) dt
=min
(dt
,ytol
/abs
(dy
))
93 if (restart
) dt
=dt
/10.0
95 dt
=max
(dtmin
,min
(dt
,dtmax
))
100 c The starting step is carried out, using the implicit Euler method.
108 CALL ITER
(n
,t
+dt
,ynew
,yp
,yl
)
110 ynew
(i2i
) = (sum
(i2i
) + dt*yp
(i2i
))/(1.+dt*yl
(i2i
))
120 c Subsequent steps are carried out with the two-step BDF method.
127 a1
=((c
+1.0)**2)/(c*c
+2.0*c
)
129 dtg
=dt*
(1.0+c
)/(2.0+c
)
131 sum
(j
)=a1*y
(j
)+a2*yold
(j
)
132 ynew
(j
)=max
(0.0,y
(j
)+ratio*
(y
(j
)-yold
(j
)))
135 CALL ITER
(n
,t
+dt
,ynew
,yp
,yl
)
137 ynew
(i2i
) = (sum
(i2i
) + dtg*yp
(i2i
))/(1.+dtg*yl
(i2i
))
142 c If stepsizes should remain equal, stepsize control is omitted.
144 if (dtmin
.eq
.dtmax
) then
151 if (dt
.ne
.dtold
) then
157 if (t
.ge
.te
) goto 120
161 c Otherwise stepsize control is carried out.
165 ytol
=atol
(i
)+rtol
(i
)*abs
(y
(i
))
166 errlte
=max
(errlte
,abs
(c*ynew
(i
)-cp1*y
(i
)+yold
(i
))/ytol
)
168 errlte
=2.0*errlte
/(c
+c*c
)
169 CALL NEWDT
(t
,te
,dt
,dtold
,ratio
,errlte
,accept
,
172 c Here the step has been accepted.
175 201 format(2(E24
.16
,1X
))
184 if (t
.ge
.te
) goto 120
188 c A restart check is carried out.
201 c Here the step has been rejected.
209 c=====================================================================
211 subroutine NEWDT
(t
,te
,dt
,dtold
,ratio
,errlte
,
212 + accept
,dtmin
,dtmax
)
213 real*8 t
,te
,dt
,dtold
,ratio
,errlte
,ts
,dtmin
,dtmax
215 if (errlte
.gt
.1.0.and
.dt
.gt
.dtmin
) then
223 dt
=max
(0.5,min
(2.0,0.8/sqrt
(errlte
)))*dt
224 dt
=max
(dtmin
,min
(dt
,dtmax
))
229 subroutine FIT
(t
,te
,dt
)
233 if (rns
.gt
.10.0) goto 10
242 C End of MAIN function
243 C ****************************************************************