1 void INTEGRATE( double DT
)
3 KPP_REAL P_VAR
[NVAR
], D_VAR
[NVAR
], V1
[NVAR
], V2
[NVAR
];
5 KPP_REAL T
, Tnext
, STEP
, STEPold
, Told
, SUP
;
6 KPP_REAL ERR
, ERRold
, ratio
, factor
, facmax
, tmp
;
17 /* -- BELOW THIS LIMIT USE TAYLOR INSTEAD OF EXP --- */
27 FSPLIT_VAR ( VAR
, P_VAR
, D_VAR
);
29 for( i
= 0; i
< NVAR
; i
++ ) {
30 if ( fabs(D_VAR
[i
]) > SUP
) {
31 ratio
= P_VAR
[i
] / D_VAR
[i
];
32 tmp
= (KPP_REAL
)exp( (double)(-D_VAR
[i
] * STEP
* 0.5) );
33 V1
[i
] = tmp
* tmp
* (VAR
[i
] - ratio
) + ratio
;
34 V2
[i
] = tmp
* (VAR
[i
] - ratio
) + ratio
;
36 tmp
= D_VAR
[i
] * STEP
* 0.5;
37 V1
[i
] = VAR
[i
] + P_VAR
[i
] * STEP
* ( 1 - tmp
*
38 ( 1 - 2.0 / 3.0 * tmp
) );
39 V2
[i
] = VAR
[i
] + P_VAR
[i
] * 0.5 * STEP
* ( 1 - 0.5 * tmp
*
40 ( 1 - 1.0 / 3.0 * tmp
) );
44 FSPLIT_VAR( V2
, P_VAR
, D_VAR
);
46 for( i
= 0; i
< NVAR
; i
++ ) {
47 if ( fabs(D_VAR
[i
]) > SUP
) {
48 ratio
= P_VAR
[i
] / D_VAR
[i
];
49 tmp
= (KPP_REAL
)exp( (double)(-D_VAR
[i
] * STEP
* 0.5) );
50 V2
[i
] = tmp
* (V2
[i
] - ratio
) + ratio
;
52 tmp
= D_VAR
[i
] * STEP
* 0.5;
53 V2
[i
] = V2
[i
] + P_VAR
[i
] * 0.5 * STEP
* ( 1 - 0.5 * tmp
*
54 ( 1 - 1.0 / 3.0 * tmp
) );
57 /* ==== Extrapolation and error estimation ======== */
61 for( i
= 0; i
< NVAR
; i
++ ) {
62 V1
[i
] = 2.*V2
[i
] - V1
[i
];
63 tmp
= (V2
[i
] - V1
[i
]) / (ATOL
[i
] + RTOL
[i
]*V2
[i
]);
69 /* ===== choosing the stepsize ==================== */
71 factor
= 0.9 / pow(ERR
,0.35) * pow(ERRold
,0.2);
72 facmax
= IsReject
? 1.0 : 5.0;
74 factor
= max( 0.2, min(factor
,facmax
) );
75 STEP
= min( STEPMAX
, max(STEPMIN
,factor
*STEP
) );
77 /*================================================= */
79 if ( (ERR
> 1) && (STEPold
> STEPMIN
) ) {
85 for( i
= 0; i
< NVAR
; i
++ )
86 VAR
[i
] = max( V1
[i
], 0.0 );