1 SUBROUTINE INTEGRATE
( TIN
, TOUT
)
3 IMPLICIT KPP_REAL
(A
-H
,O
-Z
)
4 INCLUDE
'KPP_ROOT_params.h'
5 INCLUDE
'KPP_ROOT_global.h'
13 PARAMETER (LWORK
=2*NVAR*NVAR
+14*NVAR
+20,LIWORK
=NVAR
+20)
16 EXTERNAL FUNC_CHEM
,JAC_CHEM
19 ITOL
=1 ! --- VECTOR TOLERANCES
20 IJAC
=1 ! --- COMPUTE THE JACOBIAN ANALYTICALLY
21 MLJAC
=NVAR
! --- JACOBIAN IS A FULL MATRIX
22 MUJAC
=NVAR
! --- JACOBIAN IS A FULL MATRIX
23 IMAS
=0 ! --- DIFFERENTIAL EQUATION IS IN EXPLICIT FORM
24 IOUT
=0 ! --- OUTPUT ROUTINE IS NOT USED DURING INTEGRATION
25 IDFX
=0 ! --- INTERNAL TIME DERIVATIVE
34 CALL ATMRODAS
(NVAR
,FUNC_CHEM
,Autonomous
,TIN
,VAR
,TOUT
,
35 & STEPMIN
,RTOL
,ATOL
,ITOL
,
36 & JAC_CHEM
,IJAC
,MLJAC
,MUJAC
,FUNC_CHEM
,IDFX
,
38 & WORK
,LWORK
,IWORK
,LIWORK
,IDID
)
41 print
*,'ATMRODAS: Unsucessfull exit at T=',
42 & TIN
,' (IDID=',IDID
,')'
50 SUBROUTINE ATMRODAS
(N
,FCN
,IFCN
,X
,Y
,XEND
,H
,
52 & JAC
,IJAC
,MLJAC
,MUJAC
,DFX
,IDFX
,
54 & WORK
,LWORK
,IWORK
,LIWORK
,IDID
)
55 C ----------------------------------------------------------
56 C NUMERICAL SOLUTION OF A STIFF (OR DIFFERENTIAL ALGEBRAIC)
57 C SYSTEM OF FIRST 0RDER ORDINARY DIFFERENTIAL EQUATIONS MY'=F(X,Y).
58 C THIS IS AN EMBEDDED ROSENBROCK METHOD OF ORDER (3)4
59 C (WITH STEP SIZE CONTROL).
60 C C.F. SECTIONS IV.7 AND VI.3
62 C AUTHORS: E. HAIRER AND G. WANNER
63 C UNIVERSITE DE GENEVE, DEPT. DE MATHEMATIQUES
64 C CH-1211 GENEVE 24, SWITZERLAND
65 C E-MAIL: HAIRER@DIVSUN.UNIGE.CH, WANNER@DIVSUN.UNIGE.CH
66 C ---------------------------------------------------------
67 C *** *** *** *** *** *** *** *** *** *** *** *** ***
69 C *** *** *** *** *** *** *** *** *** *** *** *** ***
70 IMPLICIT KPP_REAL
(A
-H
,O
-Z
)
71 DIMENSION Y
(N
),AbsTol
(*),RelTol
(*),WORK
(LWORK
),IWORK
(LIWORK
)
72 LOGICAL AUTNMS
,IMPLCT
,JBAND
,ARRET
,PRED
73 EXTERNAL FCN
,JAC
,DFX
,MAS
74 COMMON /STATISTICS
/ NFCN
,NACCPT
,NREJCT
,NSTEP
,NJAC
,NDEC
,NSOL
75 C *** *** *** *** *** *** ***
76 C SETTING THE PARAMETERS
77 C *** *** *** *** *** *** ***
81 C -------- PRED STEP SIZE CONTROL
91 C -------- MAXIMAL STEP SIZE
92 IF(WORK
(2).EQ
.0.D0
)THEN
97 C ------- FAC1,FAC2 PARAMETERS FOR STEP SIZE SELECTION
98 IF(WORK
(3).EQ
.0.D0
)THEN
103 IF(WORK
(4).EQ
.0.D0
)THEN
108 IF (FAC1
.LT
.1.0D0
.OR
.FAC2
.GT
.1.0D0
) THEN
109 WRITE(6,*)' CURIOUS INPUT WORK(3,4)=',WORK
(3),WORK
(4)
112 C --------- SAFE SAFETY FACTOR IN STEP SIZE PREDICTION
114 C --------- CHECK IF TOLERANCES ARE O.K.
116 IF (AbsTol
(1).LE
.0.D0
.OR
.RelTol
(1).LE
.10.D0*UROUND
) THEN
117 WRITE (6,*) ' TOLERANCES ARE TOO SMALL'
122 IF (AbsTol
(I
).LE
.0.D0
.OR
.RelTol
(I
).LE
.10.D0*UROUND
) THEN
123 WRITE (6,*) ' TOLERANCES(',I
,') ARE TOO SMALL'
131 C *** *** *** *** *** *** *** *** *** *** *** *** ***
132 C COMPUTATION OF ARRAY ENTRIES
133 C *** *** *** *** *** *** *** *** *** *** *** *** ***
134 C ---- AUTONOMOUS, IMPLICIT, BANDED OR NOT ?
138 C -------- COMPUTATION OF THE ROW-DIMENSIONS OF THE 2-ARRAYS ---
139 C -- JACOBIAN AND MATRIX E
146 print
*, 'Implicit 1'
152 C ------- PREPARE THE ENTRY-POINTS FOR THE ARRAYS IN WORK -----
167 C ------ TOTAL STORAGE REQUIREMENT -----------
169 IF(ISTORE
.GT
.LWORK
)THEN
170 WRITE(6,*)' INSUFFICIENT STORAGE FOR WORK, MIN. LWORK=',ISTORE
173 C ------- ENTRY POINTS FOR INTEGER WORKSPACE -----
176 IF(ISTORE
.GT
.LIWORK
)THEN
177 WRITE(6,*)' INSUFF. STORAGE FOR IWORK, MIN. LIWORK=',ISTORE
180 C ------ WHEN A FAIL HAS OCCURED, WE RETURN WITH IDID=-1
185 C -------- CALL TO CORE INTEGRATOR ------------
186 CALL ROSCOR
(N
,FCN
,X
,Y
,XEND
,HMAX
,H
,RelTol
,AbsTol
,ITOL
,JAC
,IJAC
,
187 & MLJAC
,MUJAC
,DFX
,IDFX
,MAS
,MLMAS
,MUMAS
,IOUT
,IDID
,NMAX
,
188 & UROUND
,METH
,IJOB
,FAC1
,FAC2
,SAFE
,AUTNMS
,IMPLCT
,JBAND
,PRED
,LDJAC
,
189 & LDE
,LDMAS2
,WORK
(IEYNEW
),WORK
(IEDY1
),WORK
(IEDY
),WORK
(IEAK1
),
190 & WORK
(IEAK2
),WORK
(IEAK3
),WORK
(IEAK4
),WORK
(IEAK5
),WORK
(IEAK6
),
191 & WORK
(IEFX
),WORK
(IEJAC
),WORK
(IEE
),WORK
(IEMAS
),IWORK
(IEIP
),
193 & M1
,M2
,NM1
,NFCN
,NJAC
,NSTEP
,NACCPT
,NREJCT
,NDEC
,NSOL
)
201 C ----------- RETURN -----------
207 C ----- ... AND HERE IS THE CORE INTEGRATOR ----------
209 SUBROUTINE ROSCOR
(N
,FCN
,X
,Y
,XEND
,HMAX
,H
,RelTol
,AbsTol
,
211 & MLJAC
,MUJAC
,DFX
,IDFX
,MAS
,MLMAS
,MUMAS
,IOUT
,IDID
,NMAX
,
212 & UROUND
,METH
,IJOB
,FAC1
,FAC2
,SAFE
,AUTNMS
,IMPLCT
,BANDED
,
214 & LDE
,LDMAS
,YNEW
,DY1
,DY
,AK1
,AK2
,AK3
,AK4
,AK5
,AK6
,
215 & FX
,FJAC
,E
,FMAS
,IP
,CONT
,
216 & M1
,M2
,NM1
,NFCN
,NJAC
,NSTEP
,NACCPT
,NREJCT
,NDEC
,NSOL
)
217 C ----------------------------------------------------------
218 C CORE INTEGRATOR FOR RODAS
219 C PARAMETERS SAME AS IN RODAS WITH WORKSPACE ADDED
220 C ----------------------------------------------------------
222 C ----------------------------------------------------------
223 IMPLICIT KPP_REAL
(A
-H
,O
-Z
)
224 INCLUDE
'KPP_ROOT_params.h'
225 INCLUDE
'KPP_ROOT_sparse.h'
226 DIMENSION Y
(N
),YNEW
(N
),DY1
(N
),DY
(N
),AK1
(N
),
227 * AK2
(N
),AK3
(N
),AK4
(N
),AK5
(N
),AK6
(N
),FX
(N
),
228 * FJAC
(LU_NONZERO
),E
(LDE
,NM1
),FMAS
(LDMAS
,NM1
),
229 * AbsTol
(*),RelTol
(*)
232 LOGICAL REJECT
,AUTNMS
,IMPLCT
,BANDED
233 LOGICAL ONE
,LAST
,PRED
,SINGULAR
234 EXTERNAL FCN
, MAS
, JAC
, DFX
235 COMMON/LINAL
/MLE
,MUE
,MBJAC
,MBB
,MDIAG
,MDIFF
,MBDIAG
236 COMMON /CONROS
/XOLD
,HOUT
,NN
237 C *** *** *** *** *** *** ***
239 C *** *** *** *** *** *** ***
244 C ------- COMPUTE MASS MATRIX FOR IMPLICIT CASE ----------
245 IF (IMPLCT
) CALL MAS
(NM1
,FMAS
,LDMAS
)
246 C ------ SET THE PARAMETERS OF THE METHOD -----
247 CALL ROCOE
(METH
,A21
,A31
,A32
,A41
,A42
,A43
,A51
,A52
,A53
,A54
,
248 & C21
,C31
,C32
,C41
,C42
,C43
,C51
,C52
,C53
,C54
,C61
,
249 & C62
,C63
,C64
,C65
,GAMMA
,C2
,C3
,C4
,D1
,D2
,D3
,D4
,
250 & D21
,D22
,D23
,D24
,D25
,D31
,D32
,D33
,D34
,D35
)
251 C --- INITIAL PREPARATIONS
252 IF (M1
.GT
.0) IJOB
=IJOB
+10
253 POSNEG
=SIGN
(1.D0
,XEND
-X
)
254 HMAXN
=DMIN1
(DABS
(HMAX
),DABS
(XEND
-X
))
255 IF (DABS
(H
).LE
.10.D0*UROUND
) H
=1.0D
-6
256 H
=DMIN1
(DABS
(H
),HMAXN
)
270 C -------- PREPARE BAND-WIDTHS --------
273 C --- BASIC INTEGRATION STEP
276 IF (.NOT
. REJECT
) THEN
277 IF (NSTEP
.GT
.NMAX
) CALL FAIL_EXIT
(3,X
,IDID
,H
,NMAX
)
278 IF ( 0.1D0*DABS
(H
) .LE
. DABS
(X
)*UROUND
)
279 * CALL FAIL_EXIT
(2,X
,IDID
,H
,NMAX
)
281 IF ((X
+H*1
.0001D0
-XEND
)*POSNEG
.GE
.0.D0
) THEN
285 C *** *** *** *** *** *** ***
286 C COMPUTATION OF THE JACOBIAN
287 C *** *** *** *** *** *** ***
289 CALL JAC
(N
,X
,Y
,FJAC
,LDJAC
)
293 IF (.NOT
.AUTNMS
) THEN
294 C --- COMPUTE NUMERICALLY THE DERIVATIVE WITH RESPECT TO X
295 DELT
=DSQRT
(UROUND*DMAX1
(1.D
-5,DABS
(X
)))
297 CALL FCN
(N
,XDELT
,Y
,AK1
)
299 FX
(J
)=(AK1
(J
)-DY1
(J
))/DELT
304 C *** *** *** *** *** *** ***
306 C *** *** *** *** *** *** ***
310 CALL DECOMR
(N
,FJAC
,LDJAC
,FMAS
,LDMAS
,MLMAS
,MUMAS
,
311 & M1
,M2
,NM1
,FAC
,E
,LDE
,IP
,IER
,IJOB
,IMPLCT
,IP
)
315 IF (NSING
.GE
.5) CALL FAIL_EXIT
(1,X
,IDID
,H
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CALL FCN
(N
,X
+H
,YNEW
,DY
)
381 AK6
(I
)=HC52*AK2
(I
)+HC54*AK4
(I
)+HC51*AK1
(I
)+HC53*AK3
(I
)
383 CALL SLVROD
(N
,FJAC
,LDJAC
,MLJAC
,MUJAC
,FMAS
,LDMAS
,MLMAS
,MUMAS
,
384 & M1
,M2
,NM1
,FAC
,E
,LDE
,IP
,DY
,AK5
,FX
,AK6
,0.D0
,IJOB
,.TRUE
.)
385 C ------------ EMBEDDED SOLUTION ---------------
387 YNEW
(I
)=YNEW
(I
)+AK5
(I
)
389 CALL FCN
(N
,X
+H
,YNEW
,DY
)
391 AK5
(I
)=HC61*AK1
(I
)+HC62*AK2
(I
)+HC65*AK5
(I
)
392 & +HC64*AK4
(I
)+HC63*AK3
(I
)
394 CALL SLVROD
(N
,FJAC
,LDJAC
,MLJAC
,MUJAC
,FMAS
,LDMAS
,MLMAS
,MUMAS
,
395 & M1
,M2
,NM1
,FAC
,E
,LDE
,IP
,DY
,AK6
,FX
,AK5
,0.D0
,IJOB
,.TRUE
.)
396 C ------------ NEW SOLUTION ---------------
398 YNEW
(I
)=YNEW
(I
)+AK6
(I
)
403 C *** *** *** *** *** *** ***
405 C *** *** *** *** *** *** ***
407 C ------------ COMPUTE ERROR ESTIMATION ----------------
411 SK
=AbsTol
(1)+RelTol
(1)*DMAX1
(DABS
(Y
(I
)),DABS
(YNEW
(I
)))
413 SK
=AbsTol
(I
)+RelTol
(I
)*DMAX1
(DABS
(Y
(I
)),DABS
(YNEW
(I
)))
415 ERR
=ERR
+(AK6
(I
)/SK
)**2
416 c2 ERR = DMAX1(ERR, AK6(I)/SK)
420 C --- COMPUTATION OF HNEW
421 C --- WE REQUIRE .2<=HNEW/H<=6.
422 FAC
=DMAX1
(FAC2
,DMIN1
(FAC1
,(ERR
)**0.25D0
/SAFE
))
423 HNEW
=DMAX1
(H
/FAC
, STEPMIN
)
425 C *** *** *** *** *** *** ***
426 C IS THE ERROR SMALL ENOUGH ?
427 C *** *** *** *** *** *** ***
429 IF ( (ERR
.LE
.1.D0
).or
.(H
.LE
.STEPMIN
) ) THEN
430 C --- STEP IS ACCEPTED
433 C --- PREDICTIVE CONTROLLER OF GUSTAFSSON
434 IF (NACCPT
.GT
.1) THEN
435 FACGUS
=(HACC
/H
)*(ERR**2
/ERRACC
)**0.25D0
/SAFE
436 FACGUS
=DMAX1
(FAC2
,DMIN1
(FAC1
,FACGUS
))
437 FAC
=DMAX1
(FAC
,FACGUS
)
438 HNEW
=DMAX1
(H
/FAC
, STEPMIN
)
441 ERRACC
=DMAX1
(1.0D
-2,ERR
)
448 IF (DABS
(HNEW
).GT
.HMAXN
) HNEW
=POSNEG*HMAXN
449 IF (REJECT
) HNEW
=POSNEG*DMIN1
(DABS
(HNEW
),DABS
(H
))
453 C --- STEP IS REJECTED
457 IF (NACCPT
.GE
.1) NREJCT
=NREJCT
+1
463 SUBROUTINE FAIL_EXIT
(NERR
,X
,IDID
,H
,NMAX
)
469 WRITE(6,*) ' MATRIX IS REPEATEDLY SINGULAR, IER=',IER
474 WRITE(6,*) ' STEP SIZE TOO SMALL, H=',H
479 WRITE(6,*) ' MORE THAN NMAX =',NMAX
,'STEPS ARE NEEDED'
482 C --- EXIT CAUSED BY solout
485 979 FORMAT(' EXIT OF RODAS AT X=',E18
.4
)
490 SUBROUTINE ROCOE
(METH
,A21
,A31
,A32
,A41
,A42
,A43
,A51
,A52
,A53
,A54
,
491 & C21
,C31
,C32
,C41
,C42
,C43
,C51
,C52
,C53
,C54
,C61
,
492 & C62
,C63
,C64
,C65
,GAMMA
,C2
,C3
,C4
,D1
,D2
,D3
,D4
,
493 & D21
,D22
,D23
,D24
,D25
,D31
,D32
,D33
,D34
,D35
)
494 IMPLICIT KPP_REAL
(A
-H
,O
-Z
)
496 if (METH
.ne
.1) print
*, 'WRONG CHOICE OF METHOD'
503 D1
= 0.2500000000000000D
+00
504 D2
=-0.1043000000000000D
+00
505 D3
= 0.1035000000000000D
+00
506 D4
=-0.3620000000000023D
-01
507 A21
= 0.1544000000000000D
+01
508 A31
= 0.9466785280815826D
+00
509 A32
= 0.2557011698983284D
+00
510 A41
= 0.3314825187068521D
+01
511 A42
= 0.2896124015972201D
+01
512 A43
= 0.9986419139977817D
+00
513 A51
= 0.1221224509226641D
+01
514 A52
= 0.6019134481288629D
+01
515 A53
= 0.1253708332932087D
+02
516 A54
=-0.6878860361058950D
+00
517 C21
=-0.5668800000000000D
+01
518 C31
=-0.2430093356833875D
+01
519 C32
=-0.2063599157091915D
+00
520 C41
=-0.1073529058151375D
+00
521 C42
=-0.9594562251023355D
+01
522 C43
=-0.2047028614809616D
+02
523 C51
= 0.7496443313967647D
+01
524 C52
=-0.1024680431464352D
+02
525 C53
=-0.3399990352819905D
+02
526 C54
= 0.1170890893206160D
+02
527 C61
= 0.8083246795921522D
+01
528 C62
=-0.7981132988064893D
+01
529 C63
=-0.3152159432874371D
+02
530 C64
= 0.1631930543123136D
+02
531 C65
=-0.6058818238834054D
+01
532 GAMMA
= 0.2500000000000000D
+00
534 D21
= 0.1012623508344586D
+02
535 D22
=-0.7487995877610167D
+01
536 D23
=-0.3480091861555747D
+02
537 D24
=-0.7992771707568823D
+01
538 D25
= 0.1025137723295662D
+01
539 D31
=-0.6762803392801253D
+00
540 D32
= 0.6087714651680015D
+01
541 D33
= 0.1643084320892478D
+02
542 D34
= 0.2476722511418386D
+02
543 D35
=-0.6594389125716872D
+01
548 C ******************************************
549 C VERSION OF SEPTEMBER 18, 1995
550 C ******************************************
552 SUBROUTINE DECOMR
(N
,FJAC
,LDJAC
,FMAS
,LDMAS
,MLMAS
,MUMAS
,
553 & M1
,M2
,NM1
,FAC1
,E1
,LDE1
,IP1
,IER
,IJOB
,CALHES
,IPHES
)
554 IMPLICIT KPP_REAL
(A
-H
,O
-Z
)
555 INCLUDE
'KPP_ROOT_params.h'
556 INCLUDE
'KPP_ROOT_sparse.h'
557 DIMENSION FJAC
(LU_NONZERO
),FMAS
(LDMAS
,NM1
),E1
(LU_NONZERO
),
560 COMMON/LINAL
/MLE
,MUE
,MBJAC
,MBB
,MDIAG
,MDIFF
,MBDIAG
564 C --- B=IDENTITY, JACOBIAN A FULL MATRIX
569 E1
(LU_DIAG
(J
)) = E1
(LU_DIAG
(J
)) + FAC1
571 CALL KppDecomp
(E1
,IER
)
575 C END OF SUBROUTINE DECOMR
577 C ***********************************************************
582 SUBROUTINE SLVROD
(N
,FJAC
,LDJAC
,MLJAC
,MUJAC
,FMAS
,LDMAS
,MLMAS
,MUMAS
,
583 & M1
,M2
,NM1
,FAC1
,E
,LDE
,IP
,DY
,AK
,FX
,YNEW
,HD
,IJOB
,STAGE1
)
584 IMPLICIT KPP_REAL
(A
-H
,O
-Z
)
585 INCLUDE
'KPP_ROOT_params.h'
586 INCLUDE
'KPP_ROOT_sparse.h'
587 DIMENSION FJAC
(LU_NONZERO
),FMAS
(LDMAS
,NM1
),E
(LU_NONZERO
),
588 & IP
(NM1
),DY
(N
),AK
(N
),FX
(N
),YNEW
(N
)
590 COMMON/LINAL
/MLE
,MUE
,MBJAC
,MBB
,MDIAG
,MDIFF
,MBDIAG
602 C --- B=IDENTITY, JACOBIAN A FULL MATRIX
612 C END OF SUBROUTINE SLVROD
615 C ***********************************************************
618 SUBROUTINE FUNC_CHEM
(N
, T
, Y
, P
)
619 INCLUDE
'KPP_ROOT_params.h'
620 INCLUDE
'KPP_ROOT_global.h'
623 KPP_REAL Y
(NVAR
), P
(NVAR
)
628 CALL Fun
( Y
, FIX
, RCONST
, P
)
634 SUBROUTINE JAC_CHEM
(N
, T
, Y
, J
)
635 INCLUDE
'KPP_ROOT_params.h'
636 INCLUDE
'KPP_ROOT_global.h'
639 KPP_REAL Y
(NVAR
), J
(LU_NONZERO
)
644 CALL Jac_SP
( Y
, FIX
, RCONST
, J
)