Nbody6
 All Files Functions Variables
check.f
Go to the documentation of this file.
1  SUBROUTINE check(DE)
2 *
3 *
4 * Error check and restart.
5 * ------------------------
6 *
7  include 'common6.h'
8 *
9 *
10 * See whether output intervals should be increased (at main output).
11  IF (kz(32).GT.0.AND.time.GE.tnext) THEN
12 * Check current energy level (factor of 2) for possible increase.
13  k = kz(32)
14  ecrit = 0.25/2.0**k
15  IF (abs(e(3)).LT.ecrit) THEN
16 * Define dynamical crossing time in case energy is near zero.
17  tdyn = 2.0*rscale/sqrt(2.0*zkin/zmass)
18  IF (2.0*dtadj.GT.tdyn.OR.time.LE.0.0d0) go to 5
19  dtadj = 2.0*dtadj
20  deltat = 2.0*deltat
21 * Increase SMAX similarly and re-initialize hierarchical step array.
22  smax = 2.0*smax
23  CALL iblock
24  qe = sqrt(2.0)*qe
25  kz(32) = kz(32) + 1
26  WRITE (6,1) dtadj, deltat, qe, smax
27  1 FORMAT (/,5x,'NEW INTERVALS: DTADJ =',f6.2,
28  & ' DELTAT =',f6.2,' QE =',1p,e8.1,
29  & ' SMAX =',0p,f7.3)
30  END IF
31  END IF
32 *
33 * Perform automatic error check & restart (option 2).
34  5 de = abs(de)
35  etacor = 1.0
36 *
37 * Skip error check after recent mass loss (otherwise reduce KZ(19)).
38  IF (kz(19).EQ.2) THEN
39  kz(19) = kz(19) - 1
40  de = 0.0
41  go to 70
42  END IF
43 *
44 * Check restart for large errors (two attempts permitted).
45  IF (de.LT.5.0*qe) go to 30
46 *
47 * Terminate run if no further restart is allowed.
48  IF (kz(2).LE.1.OR.ndump.GE.2) THEN
49  WRITE (6,10)
50  10 FORMAT (/,9x,'CALCULATIONS HALTED * * *')
51 * Increase NDUMP to prevent 3rd restart (safety check in routine MAIN).
52  ndump = 2
53  IF (kz(1).NE.0.AND.kz(2).GE.1) CALL mydump(1,1)
54  stop
55  END IF
56 *
57 * Repeat the previous interval with reduced time-step parameters.
58  tcomp = cpu
59  ntemp = ndump
60  CALL mydump(0,2)
61  cpu = tcomp
62  ndump = ntemp + 1
63 * Control variable NDUMP used to prevent a third restart.
64  etacor = 0.5
65  etai = etacor*etai
66  etar = etacor*etar
67  IF (kz(17).GT.1) etau = etacor*etau
68  dtmin = sqrt(etacor)*dtmin
69  smin = sqrt(etacor)*smin
70  WRITE (6,20) time+toff, etai, etar, etau
71  20 FORMAT (/,9x,'RESTART * * * TIME =',f8.2,' ETAI =',f7.3,
72  & ' ETAR =',f7.3,' ETAU =',f7.3)
73  CALL mydump(1,2)
74  go to 50
75 *
76 * Reset counter and check optional modification of accuracy parameters.
77  30 ndump = 0
78  IF (kz(17).EQ.0) go to 50
79 *
80  IF (de.GT.qe) THEN
81 * Continue calculation but reduce the time-step parameters.
82  etacor = sqrt(qe/de)
83  etai = etacor*etai
84  etar = etacor*etar
85  IF (kz(17).GT.1) etau = etacor*etau
86  dtmin = sqrt(etacor)*dtmin
87  smin = sqrt(etacor)*smin
88  IF (etacor.LT.0.99) WRITE (6,40) etai, etar, etau
89  40 FORMAT (8x,'ETAI =',f7.3,' ETAR =',f7.3,' ETAU =',f7.3)
90  ELSE IF (de.LT.0.2*qe) THEN
91 * Increase the time-step parameters (up to initial value only).
92  IF (time.GT.0.0d0) THEN
93  etacor = min(1.2d0,eta0/etai)
94  etai = etacor*etai
95  etar = etacor*etar
96  IF (kz(17).GT.1) etau = etacor*etau
97  dtmin = sqrt(etacor)*dtmin
98  smin = sqrt(etacor)*smin
99  IF (etacor.GT.1.01) WRITE (6,40) etai, etar, etau
100  END IF
101  END IF
102 *
103 * See whether the time-steps should be reduced (Note: KZ(2) > 2).
104  50 IF (etacor.LT.1.0.AND.kz(2).GT.2) THEN
105  etacor = sqrt(etacor)
106  DO 60 i = ifirst,ntot
107  IF (dmod(t0(i),0.5d0*step(i)).EQ.0.0d0) THEN
108  step(i) = 0.5*step(i)
109  tnew(i) = t0(i) + step(i)
110  END IF
111  IF (dmod(t0r(i),0.5d0*stepr(i)).EQ.0.0d0) THEN
112  stepr(i) = 0.5*stepr(i)
113  END IF
114  60 CONTINUE
115 *
116 * Set IPHASE = -1 to ensure new time-step list in INTGRT.
117  iphase = -1
118  END IF
119 *
120  70 RETURN
121 *
122  END