1 SUBROUTINE INTEGRATE
( TIN
, TOUT
)
3 INCLUDE
'KPP_ROOT_params.h'
4 INCLUDE
'KPP_ROOT_global.h'
13 EXTERNAL FUNC_CHEM
, JAC_CHEM
16 CALL RODAS3
(NVAR
,TIN
,TOUT
,STEPMIN
,STEPMAX
,STEPMIN
,
18 + Info
,FUNC_CHEM
,JAC_CHEM
)
25 SUBROUTINE RODAS3
(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 Stiffly accurate Rosenbrock 3(2), with
33 C stiffly accurate 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, March 1996
63 C The Center for Global and Regional Environmental Research
65 KPP_REAL K1
(NVAR
), K2
(NVAR
), K3
(NVAR
), K4
(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
, H
, Hold
, Tplus
71 KPP_REAL ERR
, factor
, facmax
72 KPP_REAL c43
, tau
, x1
, x2
, ytol
, elo
74 INTEGER n
,nfcn
,njac
,Naccept
,Nreject
,i
,j
,ier
76 LOGICAL IsReject
,Autonomous
77 EXTERNAL FUNC_CHEM
, JAC_CHEM
79 c Initialization of counters, etc.
80 Autonomous
= Info
(1) .EQ
. 1
83 H
= DMAX1
(1.d
-8, Hstart
)
84 Hmin
= DMAX1
(Hmin
,uround*
(Tnext
-T
))
85 Hmax
= DMIN1
(Hmax
,Tnext
-T
)
94 C === Starting the time loop ===
97 if ( Tplus
.gt
. Tnext
) then
102 CALL JAC_CHEM
(NVAR
, T
, y
, JAC
)
106 JAC
(LU_DIAG
(j
)) = JAC
(LU_DIAG
(j
)) + gHinv
108 CALL KppDecomp
(JAC
, ier
)
115 print
*,'IER <> 0, H=',H
120 CALL FUNC_CHEM
(NVAR
, T
, y
, F1
)
122 C ====== NONAUTONOMOUS CASE ===============
123 IF (.not
. Autonomous
) THEN
124 tau
= DSQRT
( uround*DMAX1
( 1.0d
-5, DABS
(T
) ) )
125 CALL FUNC_CHEM
(NVAR
, T
+tau
, y
, K2
)
128 K3
(j
) = ( K2
(j
)-F1
(j
) )/tau
131 C ----- STAGE 1 (NONAUTONOMOUS) -----
134 K1
(j
) = F1
(j
) + x1*K3
(j
)
136 CALL KppSolve
(JAC
, K1
)
138 C ----- STAGE 2 (NONAUTONOMOUS) -----
142 K2
(j
) = F1
(j
) - x1*K1
(j
) + x2*K3
(j
)
144 CALL KppSolve
(JAC
, K2
)
146 C ====== AUTONOMOUS CASE ===============
148 C ----- STAGE 1 (AUTONOMOUS) -----
152 CALL KppSolve
(JAC
, K1
)
154 C ----- STAGE 2 (AUTONOMOUS) -----
157 K2
(j
) = F1
(j
) - x1*K1
(j
)
159 CALL KppSolve
(JAC
, K2
)
162 C ----- STAGE 3 -----
164 ynew
(j
) = y
(j
) - 2.0d0*K1
(j
)
166 CALL FUNC_CHEM
(NVAR
, T
+H
, ynew
, F1
)
169 K3
(j
) = F1
(j
) + ( -K1
(j
) + K2
(j
) )/H
171 CALL KppSolve
(JAC
, K3
)
173 C ----- STAGE 4 -----
175 ynew
(j
) = y
(j
) - 2.0d0*K1
(j
) - K3
(j
)
177 CALL FUNC_CHEM
(NVAR
, T
+H
, ynew
, F1
)
180 K4
(j
) = F1
(j
) + ( -K1
(j
) + K2
(j
) - C43*K3
(j
) )/H
182 CALL KppSolve
(JAC
, K4
)
184 C ---- The Solution ---
187 ynew
(j
) = y
(j
) - 2.0d0*K1
(j
) - K3
(j
) - K4
(j
)
191 C ====== Error estimation ========
195 ytol
= AbsTol
(i
) + RelTol
(i
)*DABS
(ynew
(i
))
196 ERR
= ERR
+ ( K4
(i
)/ytol
)**2
198 ERR
= DMAX1
( uround
, DSQRT
( ERR
/NVAR
) )
200 C ======= Choose the stepsize ===============================
201 elo
= 3.0D0
! estimator local order
202 factor
= DMAX1
(2.0D
-1,DMIN1
(6.0D0
,ERR**
(1.0D0
/elo
)/.9D0
))
203 Hnew
= DMIN1
(Hmax
,DMAX1
(Hmin
, H
/factor
))
205 C ======= Rejected/Accepted Step ============================
207 IF ( (ERR
.gt
.1).and
.(H
.gt
.Hmin
) ) THEN
216 IF (.NOT
.IsReject
) THEN
217 H
= Hnew
! Do not increase stepsize
if previos step was rejected
224 C ======= End of the time loop ===============================
225 if ( T
.lt
. Tnext
) go to 10
229 C ======= Output Information =================================
241 SUBROUTINE FUNC_CHEM
(N
, T
, Y
, P
)
242 INCLUDE
'KPP_ROOT_params.h'
243 INCLUDE
'KPP_ROOT_global.h'
246 KPP_REAL Y
(NVAR
), P
(NVAR
)
251 CALL Fun
( Y
, FIX
, RCONST
, P
)
257 SUBROUTINE JAC_CHEM
(N
, T
, Y
, J
)
258 INCLUDE
'KPP_ROOT_params.h'
259 INCLUDE
'KPP_ROOT_global.h'
262 KPP_REAL Y
(NVAR
), J
(LU_NONZERO
)
267 CALL Jac_SP
( Y
, FIX
, RCONST
, J
)