Nbody6
 All Files Functions Variables
merge.f
Go to the documentation of this file.
1  SUBROUTINE merge
2 *
3 *
4 * Merging of hierarchical binary.
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 * COMMON variables for merge procedure
15 * ************************************
16 *
17 * ------------------------------------------------------------------
18 * CM Component masses of merged binary (2nd binary in CM(3&4)).
19 * HM Binding energy per unit mass of merged binary.
20 * KSTARM Roche stage indicator (KSTAR for 1st c.m.; ghost is OK).
21 * NAMEG Name of the associated ghost component.
22 * NAMEM Name of new c.m. (< 0) for identification of merger index.
23 * NMERG Total number of stable mergers (exclude flybys).
24 * NMERGE Current number of merged binaries (maximum is MMAX).
25 * UM Regularized coordinates of merged binary.
26 * UMDOT Regularized velocity of merged binary.
27 * VREL Relative velocity of merged binary components.
28 * XREL Relative coordinates of merged binary components.
29 * ------------------------------------------------------------------
30 *
31 *
32 * Check merger limit.
33  IF (nmerge.GE.mmax) THEN
34  WRITE (6,5) nmerge
35  5 FORMAT (/,5x,'WARNING! MERGER LIMIT EXCEEDED NMERGE =',i4)
36  go to 100
37  END IF
38 *
39 * Use double hierarchy procedure if one binary is already a merger.
40  IF (name(n+kspair).LT.0.OR.name(jcomp).LT.0) THEN
41  CALL merge2
42  go to 100
43  END IF
44 *
45 * Check switching of inner and outer binary for improved restart.
46  IF (jcomp.GT.n) THEN
47  semi2 = -0.5*body(jcomp)/h(jcomp-n)
48  IF (semi2.GT.r(kspair)) THEN
49  k = kspair
50  kspair = jcomp - n
51  jcomp = n + k
52  END IF
53  END IF
54 *
55 * Set pair index & c.m. of inner binary and save outer component.
56  ipair = kspair
57  i = n + ipair
58  jcomp1 = jcomp
59 *
60 * Check optional diagnostics for hierarchy.
61  IF ((kz(18).EQ.1.OR.kz(18).EQ.3).AND.kstar(i).LE.20) THEN
62  CALL hiarch(ipair)
63  END IF
64 *
65 * Increase merger counter and set current merger index.
66  nmerg = nmerg + 1
67  nmerge = nmerge + 1
68  imerge = nmerge
69 *
70 * Save component masses and evaluate energy of the inner binary.
71  cm(1,imerge) = body(2*ipair-1)
72  cm(2,imerge) = body(2*ipair)
73  cm(3,imerge) = 0.0d0
74  zmu = body(2*ipair-1)*body(2*ipair)/body(n+ipair)
75 * EB = ZMU*H(IPAIR)
76 *
77 * Set current energy of any second perturbed binary (from XVPRED).
78  IF (jcomp.GT.n) THEN
79  CALL xvpred(jcomp,-1)
80  jpair = jcomp - n
81  IF (list(1,2*jpair-1).GT.0) h(jpair) = ht
82 * Ensure that outer binary components are resolved.
83  CALL ksres(jpair,j1,j2,0.0d0)
84 * Enforce non-zero membership for potential correction in NBPOT.
85  list(1,2*jpair-1) = 1
86 * Reduce index of outer component if JPAIR moved up at termination.
87  IF (ipair.LT.jpair) THEN
88  jpair = jpair - 1
89  jcomp1 = jcomp1 - 1
90  END IF
91  END IF
92 *
93 * Save the neighbours for correction procedure & rename if moved up.
94  nnb = list(1,i)
95  DO 15 l = 1,nnb
96  j = list(l+1,i)
97  IF (j.GT.i) j = j - 1
98  IF (j.LE.2*npairs.AND.j.GT.2*ipair) j = j - 2
99  jsave(l) = j
100  15 CONTINUE
101 *
102 * Reduce steps of perturbers (new force uses c.m. approximation).
103 * NP1 = LIST(1,2*IPAIR-1) + 1
104 * DO 20 L = 2,NP1
105 * J = LIST(L,2*IPAIR-1)
106 * STEP(J) = MAX(0.5D0*STEP(J),TIME - T0(J))
107 * 20 CONTINUE
108 *
109 * Delay saving KS variables in block version until end-point in KSTERM.
110  IF (time.GT.tblock) THEN
111 * Retain basic KS variables for explicit restart at merge termination.
112  hm(imerge) = h(ipair)
113  DO 25 k = 1,4
114  um(k,imerge) = u(k,ipair)
115  umdot(k,imerge) = udot(k,ipair)
116  25 CONTINUE
117  END IF
118 *
119 * Save c.m. type index.
120  kstarm(imerge) = kstar(i)
121 *
122 * Terminate inner pair in order to merge components after updating.
123  CALL ksterm
124 *
125 * Predict outer component to highest order if not on the block.
126  IF (time - t0(jcomp1).GT.0.0d0) THEN
127  CALL xvpred(jcomp1,-1)
128  END IF
129 *
130 * Copy perturber list (NB! JPERT used by KSTERM).
131  DO 28 l = 1,nnb
132  jpert(l) = jsave(l)
133  28 CONTINUE
134 *
135 * Obtain potential energy with respect to inner components.
136  jlist(1) = icomp
137  jlist(2) = jcomp
138  CALL nbpot(2,nnb,pot1)
139 *
140 * Save relative configuration and define old binary as composite body.
141  DO 30 k = 1,3
142  xrel(k,imerge) = x(k,icomp) - x(k,jcomp)
143  vrel(k,imerge) = x0dot(k,icomp) - x0dot(k,jcomp)
144  x(k,icomp) = (body(icomp)*x(k,icomp) + body(jcomp)*x(k,jcomp))
145  & /(body(icomp) + body(jcomp))
146  x0dot(k,icomp) = (body(icomp)*x0dot(k,icomp) +
147  & body(jcomp)*x0dot(k,jcomp))/
148  & (body(icomp) + body(jcomp))
149 * Initialize primary velocity of JCOMP1 (needed in KSREG & KSINIT).
150  x0dot(k,jcomp1) = xdot(k,jcomp1)
151  30 CONTINUE
152 *
153 * Form new c.m. body & associated ghost of zero mass and neighbours.
154  body(icomp) = body(icomp) + body(jcomp)
155  body(jcomp) = 0.0d0
156  list(1,jcomp) = 0
157 *
158 * Initialize integration variables to prevent spurious predictions.
159  DO 40 k = 1,3
160  x0dot(k,jcomp) = 0.0d0
161  xdot(k,jcomp) = 0.0d0
162  f(k,jcomp) = 0.0d0
163  fdot(k,jcomp) = 0.0d0
164  d2(k,jcomp) = 0.0d0
165  d3(k,jcomp) = 0.0d0
166  d2r(k,jcomp) = 0.0d0
167  d3r(k,jcomp) = 0.0d0
168  40 CONTINUE
169 *
170 * Set large value of T0 which avoids integration of ghost particle.
171  t0(jcomp) = 1.0e+06
172 * Set large X0 & X to avoid neighbour problems (no escape removal).
173  x0(1,jcomp) = 1.0e+06
174  x(1,jcomp) = 1.0e+06
175 *
176 * See whether modifications due to second binary are needed.
177  pot3 = 0.0d0
178  pot4 = 0.0d0
179  IF (jcomp1.LE.n) go to 50
180 *
181 * Initialize unperturbed ghost binary of outer component.
182  t0(2*jpair-1) = 1.0e+06
183  list(1,2*jpair-1) = 0
184 *
185 * Apply tidal correction for outer binary perturbers.
186  jlist(1) = 2*jpair - 1
187  jlist(2) = 2*jpair
188 * Note that inner binary correction is included with IPAIR.
189  CALL nbpot(2,nnb,pot3)
190  jlist(1) = jcomp1
191  CALL nbpot(1,nnb,pot4)
192 *
193 * Update merger energy to maintain conservation.
194  eb1 = body(2*jpair-1)*body(2*jpair)*h(jpair)/body(jcomp1)
195  emerge = emerge + eb1
196 *
197 * Save component masses and initialize ghost components.
198  cm(3,imerge) = body(2*jpair-1)
199  cm(4,imerge) = body(2*jpair)
200  body(2*jpair-1) = 0.0d0
201  body(2*jpair) = 0.0d0
202 *
203 * Include interaction of inner c.m. & neighbours to give net effect.
204  50 jlist(1) = icomp
205  CALL nbpot(1,nnb,pot2)
206 *
207 * Form square of c.m. velocity correction due to tidal effects.
208 * VI2 = X0DOT(1,ICOMP)**2 + X0DOT(2,ICOMP)**2 + X0DOT(3,ICOMP)**2
209  dphi = (pot2 - pot1) + (pot4 - pot3)
210 * CORR = 1.0 + 2.0*DPHI/(BODY(ICOMP)*VI2)
211 * IF (CORR.LE.0.0D0) CORR = 0.0
212 *
213 * Adjust c.m. velocity by net tidal energy correction.
214 * DO 60 K = 1,3
215 * X0DOT(K,ICOMP) = SQRT(CORR)*X0DOT(K,ICOMP)
216 * 60 CONTINUE
217 *
218 * Remove ghost from local neighbour lists (any others done in REGINT).
219  jlist(1) = jcomp
220  CALL nbrem(icomp,1,nnb)
221 *
222 * Also remove ghost from list of ICOMP (use NTOT as dummy here).
223  jpert(1) = icomp
224  CALL nbrem(ntot,1,1)
225 *
226 * Check for sufficient perturbers (RMAX = apocentre set in IMPACT).
227  IF (sqrt(cmsep2)*rmax.GT.2.0*rs(icomp).OR.nnb.LE.3) THEN
228  fac = nnbmax/nnb
229  fac = min(fac,4.0d0)
230  rsi = fac**0.3333*rs(icomp)
231  IF (rsi.GT.rs(i)) THEN
232  CALL nblist(icomp,rsi)
233  END IF
234  END IF
235 *
236 * Perform KS regularization of hierarchical system (ICOMP & JCOMP1).
237  jcomp = jcomp1
238  CALL ksreg
239 *
240 * Define negative c.m. name for identification & termination.
241  name(ntot) = nzero - name(ntot)
242 *
243 * Set c.m. & ghost names for merger identification (include escape).
244  namem(imerge) = name(ntot)
245  nameg(imerge) = name(jcomp1)
246 * Subtract 1 for hyperbolic flybys to count stable systems only.
247  IF (h(npairs).GT.0.0) nmerg = nmerg - 1
248 
249 * Copy stability limit for termination test A(1 - E) < R0 in KSINT.
250  r0(npairs) = pcrit
251 * Ensure that flag denotes new rather than primordial binary.
252  list(2,jcomp) = 0
253 *
254 * Add merger energy (or: in clude DPHI and activate X0DOT correction).
255  emerge = emerge + zmu*hm(imerge) + dphi
256 *
257 * Set phase indicator = -1 for new time-step list in routine INTGRT.
258  iphase = -1
259 *
260  100 RETURN
261 *
262  END