1 SUBROUTINE INTEGRATE
( TIN
, TOUT
)
3 INCLUDE
'KPP_ROOT_params.h'
4 INCLUDE
'KPP_ROOT_global.h'
13 EXTERNAL FUNC_CHEM
, JAC_CHEM
17 CALL ROS3
(NVAR
,TIN
,TOUT
,STEPMIN
,STEPMAX
,
18 + STEPMIN
,VAR
,ATOL
,RTOL
,
19 + Info
,FUNC_CHEM
,JAC_CHEM
)
25 SUBROUTINE ROS3
(N
,T
,Tnext
,Hmin
,Hmax
,Hstart
,
27 + Info
,FUNC_CHEM
,JAC_CHEM
)
29 INCLUDE
'KPP_ROOT_params.h'
30 INCLUDE
'KPP_ROOT_sparse.h'
32 C L-stable Rosenbrock 3(2), with
33 C strongly A-stable embedded formula for error control.
35 C All the arguments aggree with the KPP syntax.
38 C y = Vector of (NVAR) concentrations, contains the
39 C initial values on input
40 C [T, Tnext] = the integration interval
41 C Hmin, Hmax = lower and upper bounds for the selected step-size.
42 C Note that for Step = Hmin the current computed
43 C solution is unconditionally accepted by the error
45 C AbsTol, RelTol = (NVAR) dimensional vectors of
46 C componentwise absolute and relative tolerances.
47 C FUNC_CHEM = name of routine of derivatives. KPP syntax.
48 C See the header below.
49 C JAC_CHEM = name of routine that computes the Jacobian, in
50 C sparse format. KPP syntax. See the header below.
51 C Info(1) = 1 for autonomous system
52 C = 0 for nonautonomous system
55 C y = the values of concentrations at Tend.
56 C T = equals Tend on output.
57 C Info(2) = # of FUNC_CHEM calls.
58 C Info(3) = # of JAC_CHEM calls.
59 C Info(4) = # of accepted steps.
60 C Info(5) = # of rejected steps.
62 C Adrian Sandu, April 1996
63 C The Center for Global and Regional Environmental Research
65 KPP_REAL K1
(NVAR
), K2
(NVAR
), K3
(NVAR
)
66 KPP_REAL F1
(NVAR
), JAC
(LU_NONZERO
)
67 KPP_REAL Hmin
,Hmax
,Hnew
,Hstart
,ghinv
,uround
68 KPP_REAL y
(NVAR
), ynew
(NVAR
)
69 KPP_REAL AbsTol
(NVAR
), RelTol
(NVAR
)
70 KPP_REAL T
, Tnext
, Tplus
, H
, elo
71 KPP_REAL ERR
, factor
, facmax
72 KPP_REAL gam
, c21
, c31
, c32
, b1
, b2
, b3
73 KPP_REAL d1
, d2
, d3
, a21
, a31
, a32
74 KPP_REAL alpha2
, alpha3
, g1
, g2
, g3
75 KPP_REAL tau
, x1
, x2
, x3
, dround
, ytol
76 INTEGER n
,nfcn
,njac
,Naccept
,Nreject
,i
,j
,ier
78 LOGICAL IsReject
,Autonomous
79 EXTERNAL FUNC_CHEM
, JAC_CHEM
81 gam
= .43586652150845899941601945119356d
+00
82 c21
= -.10156171083877702091975600115545d
+01
83 c31
= .40759956452537699824805835358067d
+01
84 c32
= .92076794298330791242156818474003d
+01
85 b1
= .10000000000000000000000000000000d
+01
86 b2
= .61697947043828245592553615689730d
+01
87 b3
= -.42772256543218573326238373806514d
+00
88 d1
= .50000000000000000000000000000000d
+00
89 d2
= -.29079558716805469821718236208017d
+01
90 d3
= .22354069897811569627360909276199d
+00
96 g1
= .43586652150845899941601945119356d
+00
97 g2
= .24291996454816804366592249683314d
+00
98 g3
= .21851380027664058511513169485832d
+01
101 c Initialization of counters, etc.
102 Autonomous
= Info
(1) .EQ
. 1
104 dround
= DSQRT
(uround
)
105 IF (Hmax
.le
.0.D0
) THEN
108 H
= DMAX1
(1.d
-8, Hstart
)
116 C === Starting the time loop ===
120 if ( Tplus
.gt
. Tnext
) then
125 CALL JAC_CHEM
(NVAR
, T
, y
, JAC
)
127 gHinv
= -1.0d0
/(gam*H
)
132 JAC
(LU_DIAG
(j
)) = JAC
(LU_DIAG
(j
)) - gHinv
134 CALL KppDecomp
(JAC
, ier
)
141 print
*,'IER <> 0, H=',H
146 CALL FUNC_CHEM
(NVAR
, T
, y
, F1
)
148 C ====== NONAUTONOMOUS CASE ===============
149 IF (.not
. Autonomous
) THEN
150 tau
= DSIGN
(dround*DMAX1
( 1.0d
-6, DABS
(T
) ), T
)
151 CALL FUNC_CHEM
(NVAR
, T
+tau
, y
, K2
)
154 K3
(j
) = ( K2
(j
)-F1
(j
) )/tau
157 C ----- STAGE 1 (NONAUTONOMOUS) -----
160 K1
(j
) = F1
(j
) + x1*K3
(j
)
162 CALL KppSolve
(JAC
, K1
)
164 C ----- STAGE 2 (NONAUTONOMOUS) -----
166 ynew
(j
) = y
(j
) + K1
(j
)
168 CALL FUNC_CHEM
(NVAR
, T
+gam*H
, ynew
, F1
)
173 K2
(j
) = F1
(j
) + x1*K1
(j
) + x2*K3
(j
)
175 CALL KppSolve
(JAC
, K2
)
177 C ----- STAGE 3 (NONAUTONOMOUS) -----
182 K3
(j
) = F1
(j
) + x1*K1
(j
) + x2*K2
(j
) + x3*K3
(j
)
184 CALL KppSolve
(JAC
, K3
)
187 C ====== AUTONOMOUS CASE ===============
190 C ----- STAGE 1 (AUTONOMOUS) -----
194 CALL KppSolve
(JAC
, K1
)
196 C ----- STAGE 2 (AUTONOMOUS) -----
198 ynew
(j
) = y
(j
) + K1
(j
)
200 CALL FUNC_CHEM
(NVAR
, T
+ gam*H
, ynew
, F1
)
204 K2
(j
) = F1
(j
) + x1*K1
(j
)
206 CALL KppSolve
(JAC
, K2
)
208 C ----- STAGE 3 (AUTONOMOUS) -----
212 K3
(j
) = F1
(j
) + x1*K1
(j
) + x2*K2
(j
)
214 CALL KppSolve
(JAC
, K3
)
216 END IF ! Autonomousous
218 C ---- The Solution ---
221 ynew
(j
) = y
(j
) + b1*K1
(j
) + b2*K2
(j
) + b3*K3
(j
)
225 C ====== Error estimation ========
229 ytol
= AbsTol
(i
) + RelTol
(i
)*DMAX1
(DABS
(y
(i
)),DABS
(ynew
(i
)))
230 ERR
=ERR
+((d1*K1
(i
)+d2*K2
(i
)+d3*K3
(i
))/ytol
)**2
232 ERR
= DMAX1
( uround
, DSQRT
( ERR
/NVAR
) )
234 C ======= Choose the stepsize ===============================
236 elo
= 3.0D0
! estimator local order
237 factor
= DMAX1
(2.0D
-1,DMIN1
(6.0D0
,ERR**
(1.0D0
/elo
)/.9D0
))
238 Hnew
= DMIN1
(Hmax
,DMAX1
(Hmin
, H
/factor
))
240 C ======= Rejected/Accepted Step ============================
242 IF ( (ERR
.gt
.1).and
.(H
.gt
.Hmin
) ) THEN
251 IF (.NOT
.IsReject
) THEN
252 H
= Hnew
! Do not increase stepsize
if previos step was rejected
259 C ======= End of the time loop ===============================
260 if ( T
.lt
. Tnext
) go to 10
263 C ======= Output Information =================================
275 SUBROUTINE FUNC_CHEM
(N
, T
, Y
, P
)
276 INCLUDE
'KPP_ROOT_params.h'
277 INCLUDE
'KPP_ROOT_global.h'
280 KPP_REAL Y
(NVAR
), P
(NVAR
)
285 CALL Fun
( Y
, FIX
, RCONST
, P
)
290 SUBROUTINE JAC_CHEM
(N
, T
, Y
, J
)
291 INCLUDE
'KPP_ROOT_params.h'
292 INCLUDE
'KPP_ROOT_global.h'
295 KPP_REAL Y
(NVAR
), J
(LU_NONZERO
)
300 CALL Jac_SP
( Y
, FIX
, RCONST
, J
)