Nbody6
 All Files Functions Variables
reset.f
Go to the documentation of this file.
1  SUBROUTINE reset
2 *
3 *
4 * Restore hierarchical configuration.
5 * -----------------------------------
6 *
7  include 'common6.h'
8  common/binary/ cm(4,mmax),xrel(3,mmax),vrel(3,mmax),
9  & hm(mmax),um(4,mmax),umdot(4,mmax),tmdis(mmax),
10  & namem(mmax),nameg(mmax),kstarm(mmax),iflag(mmax)
11  INTEGER jsave(lmax)
12 *
13 *
14 * Set index of disrupted pair and save output parameters.
15  ipair = kspair
16  i = n + ipair
17 *
18 * Check special termination of double hierarchy (routine RESET2).
19  IF (name(i).LT.-2*nzero) THEN
20  CALL reset2
21  go to 100
22  END IF
23 *
24  e1 = body(2*ipair-1)*body(2*ipair)*h(ipair)/body(i)
25  g1 = gamma(ipair)
26  r1 = r(ipair)
27  semi1 = -0.5*body(i)/h(ipair)
28 *
29 * Locate current position in the merger table.
30  imerge = 0
31  DO 1 k = 1,nmerge
32  IF (namem(k).EQ.name(i)) imerge = k
33  1 CONTINUE
34 *
35 * Check optional diagnostics for hierarchy.
36  IF ((kz(18).EQ.1.OR.kz(18).EQ.3).AND.kstarm(imerge).LE.20) THEN
37  CALL hiarch(ipair)
38  END IF
39 *
40 * Save neighbours for correction procedure and rename if moved up.
41  nnb = list(1,i) + 1
42  DO 4 l = 2,nnb
43  j = list(l,i)
44  IF (j.GT.i) j = j - 1
45  IF (j.LE.2*npairs.AND.j.GT.2*ipair) j = j - 2
46  jsave(l) = j
47  4 CONTINUE
48 *
49 * Ensure that c.m. coordinates are known to highest order.
50  CALL xvpred(i,0)
51 *
52 * Restore original c.m. name and terminate outer KS pair.
53  name(i) = nzero - name(i)
54  CALL ksterm
55 *
56 * Predict neighbour coordinates & velocities (XDOT used by FPOLY1).
57  DO 5 l = 2,nnb
58  jpert(l) = jsave(l)
59  j = jpert(l)
60  CALL xvpred(j,0)
61  5 CONTINUE
62 *
63 * Add outer component to perturber list and set old dipole range.
64  jpert(1) = jcomp
65 * RCRIT2 = CMSEP2*(XREL(1,IMERGE)**2 + XREL(2,IMERGE)**2 +
66 * & XREL(3,IMERGE)**2)
67 *
68 * Sum first part of potential energy correction due to tidal effect.
69  jlist(1) = icomp
70  CALL nbpot(1,nnb,pot1)
71 *
72 * Find the nearest neighbour and reduce steps of active perturbers.
73  rjmin2 = 100.0
74  jmin = n
75  DO 8 l = 1,nnb
76  j = jpert(l)
77  rij2 = (x(1,j) - x(1,icomp))**2 + (x(2,j) - x(2,icomp))**2 +
78  & (x(3,j) - x(3,icomp))**2
79 * Identify the closest perturber for dominant force calculation.
80  IF (rij2.LT.rjmin2.AND.j.NE.jcomp) THEN
81  rjmin2 = rij2
82  jmin = j
83  END IF
84 * IF (RIJ2.LT.RCRIT2) THEN
85 * Reduce step of inner binary perturbers (c.m. approximation used).
86 * STEP(J) = MAX(0.5D0*STEP(J),TIME - T0(J))
87 * END IF
88  8 CONTINUE
89 *
90 * Find correct location of ghost particle using identification name.
91  jcomp1 = jcomp
92 * Note that ghost may be saved in an old binary c.m. (search NTOT).
93  DO 10 i = 1,ntot
94  IF (body(i).EQ.0.0d0.AND.name(i).EQ.nameg(imerge)) jcomp = i
95  10 CONTINUE
96 *
97 * Regularize two-body configuration if JCOMP cannot be identified.
98  IF (jcomp.EQ.jcomp1) THEN
99  WRITE (6,12) nameg(imerge)
100  12 FORMAT (/,5x,'DANGER! JCOMP NOT IDENTIFIED IN RESET',
101  & ' NAMEG =',i5)
102  stop
103  END IF
104 *
105 * Restore masses, coordinates & velocities of inner binary.
106  body(icomp) = cm(1,imerge)
107  body(jcomp) = cm(2,imerge)
108  zm = -body(icomp)/(body(icomp) + body(jcomp))
109 *
110 * Begin with second component since ICOMP holds new c.m. variables.
111  i = jcomp
112  DO 20 kcomp = 1,2
113  DO 15 k = 1,3
114  x(k,i) = x(k,icomp) + zm*xrel(k,imerge)
115  x0dot(k,i) = x0dot(k,icomp) + zm*vrel(k,imerge)
116  xdot(k,i) = x0dot(k,i)
117 * Note that XDOT is only needed for improved polynomials of JCOMP.
118  15 CONTINUE
119  i = icomp
120  zm = body(jcomp)/(body(icomp) + body(jcomp))
121  20 CONTINUE
122 *
123 * Add #JCOMP to neighbour lists containing ICOMP (KSREG sets c.m.).
124  jlist(1) = jcomp
125  CALL nbrest(icomp,1,nnb)
126 *
127 * Ensure that any rare case of missing second component is included.
128  DO 30 i = 1,ntot
129  nnb1 = list(1,i) + 1
130  DO 25 l = 2,nnb1
131  IF (list(l,i).GT.icomp) go to 30
132 *
133 * Now see whether #JCOMP has already been added.
134  DO 22 k = l,nnb1
135  IF (list(k,i).EQ.jcomp) go to 30
136  22 CONTINUE
137 *
138 * Specify index #I and add body #JCOMP as above.
139  jpert(1) = i
140  CALL nbrest(icomp,1,1)
141  25 CONTINUE
142  30 CONTINUE
143 *
144 * Set dominant F & FDOT on inner components including main intruder.
145  jlist(1) = icomp
146  jlist(2) = jcomp
147  jlist(3) = jcomp1
148  jlist(4) = jmin
149 *
150  CALL fclose(icomp,4)
151  CALL fclose(jcomp,4)
152 *
153 * Initialize force polynomials for outer component using resolved c.m.
154  CALL fpoly1(jcomp1,jcomp1,0)
155  CALL fpoly2(jcomp1,jcomp1,0)
156 *
157 * Rename perturber list for routine NBPOT.
158  jpert(1) = jcomp
159 *
160 * Copy basic KS variables for inner binary (small TDOT2 near apo/peri).
161  jp1 = npairs + 1
162  h(jp1) = hm(imerge)
163  r(jp1) = 0.0d0
164  tdot2(jp1) = 0.0d0
165  DO 40 k = 1,4
166  u(k,jp1) = um(k,imerge)
167  u0(k,jp1) = u(k,jp1)
168  udot(k,jp1) = umdot(k,imerge)
169  r(jp1) = r(jp1) + u(k,jp1)**2
170  40 CONTINUE
171 *
172 * Save ghost index and re-activate inner binary (JCOMP <-> JCOMP1).
173  jcomp1 = jcomp
174  CALL ksreg
175 *
176 * Restore Roche stage indicator (any ghost c.m. is OK).
177  kstar(n+npairs) = kstarm(imerge)
178 *
179 * See whether the outer component is a single or composite particle.
180  pot3 = 0.0d0
181  pot4 = 0.0d0
182  IF (jcomp1.LE.n) go to 50
183 *
184 * Restore component masses for outer binary.
185  jpair = jcomp1 - n
186  body(2*jpair-1) = cm(3,imerge)
187  body(2*jpair) = cm(4,imerge)
188 *
189 * Update look-up times & radii and check possible Roche condition.
190  IF (kz(19).GE.3) THEN
191 * Reduce evolution time-scale after any delay during ghost stage.
192  IF (tev(2*jpair-1).LT.time + 0.01*tcr) tev(2*jpair-1) = time
193  IF (tev(2*jpair).LT.time + 0.01*tcr) tev(2*jpair) = time
194  IF (kstar(jcomp1).GT.0.AND.kstar(jcomp1).LE.10) THEN
195  CALL trflow(jpair,dtr)
196  tev(jcomp1) = time + dtr
197  tmdot = min(tev(jcomp1),tmdot)
198  tmdot = min(tev(2*jpair),tmdot)
199  END IF
200  END IF
201 *
202 * Obtain coordinates & velocities of unperturbed binary components.
203  CALL resolv(jpair,1)
204 *
205 * Select new perturbers and initialize polynomials for KS motion.
206  CALL kslist(jpair)
207  CALL kspoly(jpair,1)
208 *
209 * Apply tidal correction for outer binary perturbers.
210  jlist(1) = 2*jpair - 1
211  jlist(2) = 2*jpair
212 * Note that inner binary correction is included with IPAIR.
213  CALL nbpot(2,nnb,pot3)
214  jlist(1) = jcomp1
215  CALL nbpot(1,nnb,pot4)
216 *
217 * Update the merger energy.
218  eb2 = body(2*jpair-1)*body(2*jpair)*h(jpair)/body(jcomp1)
219  emerge = emerge - eb2
220 *
221  e2 = e1/eb2
222  eb2 = eb2/be(3)
223  dp = pot4 - pot3
224  IF (kz(15).GT.1) THEN
225  WRITE (6,45) jpair, h(jpair), body(2*jpair-1),
226  & body(2*jpair), e2, eb2, r(jpair), gamma(jpair),
227  & dp
228  45 FORMAT (' END QUAD',i4,' H =',f7.1,' M =',2f7.4,
229  & ' E1 =',f6.3,' EB2 =',f6.3,' RB2 =',1pe8.1,
230  & ' G2 =',e8.1,' DP =',e8.1)
231  END IF
232 *
233 * Include interaction of body #ICOMP & JCOMP with perturbers.
234  50 jlist(1) = icomp
235  jlist(2) = jcomp
236  CALL nbpot(2,nnb,pot2)
237 *
238 * Form square of c.m. velocity correction due to tidal effects.
239 * VI2 = X0DOT(1,NTOT)**2 + X0DOT(2,NTOT)**2 + X0DOT(3,NTOT)**2
240  dphi = (pot2 - pot1) + (pot4 - pot3)
241 * CORR = 1.0 + 2.0*DPHI/(BODY(NTOT)*VI2)
242 * IF (CORR.LE.0.0D0) CORR = 0.0
243 *
244 * Adjust c.m. velocity by net tidal energy correction.
245 * DO 60 K = 1,3
246 * X0DOT(K,NTOT) = SQRT(CORR)*X0DOT(K,NTOT)
247 * 60 CONTINUE
248 *
249 * Modify the merger energy to maintain conservation.
250  eb = body(2*npairs-1)*body(2*npairs)*h(npairs)/body(ntot)
251 * Note that EMERGE may contain escaped mergers.
252  emerge = emerge - eb + dphi
253 *
254  e1 = e1/eb
255  eb = eb/be(3)
256  IF (kz(15).GT.1) THEN
257  WRITE (6,65) imerge, time+toff, body(2*npairs-1),
258  & body(2*npairs), r1, semi1, eb, e1,
259  & gamma(npairs), g1, nnb
260  65 FORMAT (' END MERGER',i3,' T =',f8.2,' M =',2f7.4,
261  & ' R1 =',1pe8.1,' A1 =',e8.1,' EB =',0pf6.3,
262  & ' E1 =',f6.3,' GB =',1pe8.1,' G =',0pf6.3,
263  & ' NB =',i3)
264  END IF
265 *
266 * Check Roche look-up time.
267  IF (kstar(ntot).GE.10.AND.kstar(ntot).LE.20) THEN
268 * Reduce evolution time-scale after any delay during ghost stage.
269  IF (tev(2*npairs-1).LT.time + 0.01*tcr) tev(2*npairs-1) = time
270  CALL trflow(npairs,dtr)
271 * Note DTR < 0 is possible for active Roche after termination.
272  tev(ntot) = time + max(dtr,0.0d0)
273  tmdot = min(tev(ntot),tev(icomp),tmdot)
274  END IF
275 *
276 * Reduce merger counter and update tables (unless last or only pair).
277  70 nmerge = nmerge - 1
278  DO 80 l = imerge,nmerge
279  l1 = l + 1
280  hm(l) = hm(l1)
281  nameg(l) = nameg(l1)
282  namem(l) = namem(l1)
283  kstarm(l) = kstarm(l1)
284  DO 74 k = 1,3
285  xrel(k,l) = xrel(k,l1)
286  vrel(k,l) = vrel(k,l1)
287  74 CONTINUE
288  DO 75 k = 1,4
289  cm(k,l) = cm(k,l1)
290  um(k,l) = um(k,l1)
291  umdot(k,l) = umdot(k,l1)
292  75 CONTINUE
293  80 CONTINUE
294 *
295 * Examine merger list for possible escapers (retain up to 3 levels).
296  DO 90 l = 1,nmerge
297  DO 85 j = 1,npairs
298  IF (namem(l).EQ.name(n+j).OR.
299  & namem(l).EQ.name(n+j) + 2*nzero.OR.
300  & namem(l).EQ.name(n+j) + 4*nzero) go to 90
301  85 CONTINUE
302 * Remove tables for any merger not identified.
303  imerge = l
304  go to 70
305  90 CONTINUE
306 *
307 * Include consistency check on merger names.
308  DO 96 i = n+1,ntot
309  IF (name(i).LT.0) THEN
310  DO 94 l = 1,nmerge
311  IF (namem(l).EQ.name(i)) go to 96
312  94 CONTINUE
313  WRITE (6,95) i, name(i), (namem(l),l=1,nmerge)
314  95 FORMAT (' DANGER! RESET I NAMI NAMEM ',10i6)
315  stop
316  END IF
317  96 CONTINUE
318 *
319 * Reduce merger energy on zero membership for consistency.
320  IF (nmerge.EQ.0) THEN
321  be(3) = be(3) - emerge
322  emerge = 0.0
323  END IF
324 *
325 * Set phase indicator < 0 for new time-step list in routine INTGRT.
326  iphase = -1
327 *
328  100 RETURN
329 *
330  END