Nbody6
 All Files Functions Variables
setsys.f
Go to the documentation of this file.
1  SUBROUTINE setsys
2 *
3 *
4 * Selection of chain system.
5 * --------------------------
6 *
7  include 'common6.h'
8  parameter(nmx=10,nmx3=3*nmx,nmxm=nmx*(nmx-1)/2)
9  REAL*8 m,mass,mc,mij,mkk
10  common/chain1/ xch(nmx3),vch(nmx3),m(nmx),
11  & zz(nmx3),wc(nmx3),mc(nmx),
12  & xi(nmx3),pi(nmx3),mass,rinv(nmxm),rsum,mkk(nmx),
13  & mij(nmx,nmx),tkk(nmx),tk1(nmx),iname(nmx),nn
14  common/chainc/ xc(3,ncmax),uc(3,ncmax),bodyc(ncmax),ich,
15  & listc(lmax)
16  common/chreg/ timec,tmax,rmaxc,cm(10),namec(6),nstep1,kz27,kz30
17  common/binary/ zm(4,mmax),xrel(3,mmax),vrel(3,mmax),
18  & hm(mmax),um(4,mmax),umdot(4,mmax),tmdis(mmax),
19  & namem(mmax),nameg(mmax),kstarm(mmax),iflag(mmax)
20  SAVE jsave
21  INTEGER jsave(3)
22 *
23 *
24 * Check whether new (or renewed) chain or addition of member(s).
25  IF (nch.GT.0) go to 10
26 *
27 * Include treatment for common envelope stage (denoted by NCH < 0).
28  IF (nch.LT.0) THEN
29  nch = -nch
30 * Copy members from JLIST (set in CHTERM and modified in CMBODY).
31  DO 1 l = 1,nch
32  j = jlist(l)
33  namec(l) = name(j)
34  bodyc(l) = body(j)
35  m(l) = body(j)
36  1 CONTINUE
37  go to 50
38  END IF
39 *
40 * Initialize chain indices, names & masses for maximum membership.
41  DO 5 l = 1,4
42  jlist(l) = 2*npairs + l
43  namec(l) = name(2*npairs+l)
44  bodyc(l) = body(2*npairs+l)
45  m(l) = body(2*npairs+l)
46  5 CONTINUE
47  cm(9) = ebch0
48 *
49 * Include treatment for near-synchronous binary as inert body (B-B).
50  IF (jclose.GT.n.AND.kz(26).LT.2) THEN
51  rsum = rmin
52  nch = 2
53  go to 10
54  END IF
55 *
56 * Define chain membership for three-body or four-body case.
57  IF (jclose.LE.n.AND.jclose.GT.0) THEN
58  nch = 3
59  jlist(3) = jclose
60  namec(3) = name(jclose)
61  bodyc(3) = body(jclose)
62  m(3) = body(jclose)
63 * See whether a second single body should be added.
64  IF (jcmax.LE.n.AND.jcmax.GE.ifirst) THEN
65  jlist(4) = jcmax
66  namec(4) = name(jcmax)
67  bodyc(4) = body(jcmax)
68  m(4) = body(jcmax)
69  nch = 4
70  END IF
71  ELSE
72  nch = 4
73  END IF
74 *
75 * Check for addition of binary (NCH <= 4).
76  IF (jcmax.GT.n.AND.nch.LE.4) THEN
77  ksp2 = jcmax - n
78  IF (ksp2.GT.kspair) ksp2 = ksp2 - 1
79  kspair = ksp2
80  jcomp = 0
81 * Save current members to prevent over-writing in KSTERM.
82  DO 6 l = 1,nch
83  jsave(l) = jlist(l)
84  6 CONTINUE
85  CALL ksterm
86 * Note that second binary will now come first in N-body arrays.
87  DO 7 l = 1,nch
88  jlist(l) = jsave(l)
89  7 CONTINUE
90 * Add terminated KS components to chain arrays.
91  DO 8 l = 1,2
92  nch = nch + 1
93  jlist(nch) = 2*npairs + l
94  namec(nch) = name(2*npairs+l)
95  bodyc(nch) = body(2*npairs+l)
96  m(nch) = body(2*npairs+l)
97  8 CONTINUE
98  END IF
99  go to 50
100 *
101 * Improve coordinates & velocities of single perturber or c.m. body.
102  10 CALL xvpred(jclose,-1)
103 *
104 * Expand membership and save chain variables (single body or KS pair).
105  IF (jclose.LE.n) THEN
106  nch = nch + 1
107  jlist(nch) = jclose
108  namec(nch) = name(jclose)
109  bodyc(nch) = body(jclose)
110  m(nch) = body(jclose)
111  ELSE
112  kspair = jclose - n
113 * Check for synchronous tidal binary (save dormant energy in ECOLL).
114  IF (kz(27).GT.0.AND.kz(26).LT.2) THEN
115  semi = -0.5*body(jclose)/h(kspair)
116  IF (semi.LT.0.01*rsum) THEN
117  nch = nch + 1
118  jlist(nch) = jclose
119  namec(nch) = name(jclose)
120  bodyc(nch) = body(jclose)
121  m(nch) = body(jclose)
122 * Define temporary KS ghost by saving masses and binding energy.
123  t0(2*kspair-1) = 1.0e+06
124  list(1,2*kspair-1) = 0
125  bodyc(9) = body(2*kspair-1)
126  bodyc(10) = body(2*kspair)
127  zmu = body(2*kspair-1)*body(2*kspair)/body(jclose)
128  ecoll = ecoll + zmu*h(kspair)
129  body(2*kspair-1) = 0.0d0
130  body(2*kspair) = 0.0d0
131  go to 50
132  END IF
133  END IF
134 *
135 * Re-activate any merged binary before terminating as last pair.
136  jg = 0
137  IF (name(jclose).LT.0) THEN
138 * Identify merger index and ghost for addition to chain.
139  DO 12 k = 1,nmerge
140  IF (namem(k).EQ.name(jclose)) THEN
141  im = k
142  END IF
143  12 CONTINUE
144 * Note ghost must be single for maximum chain membership of 6.
145  DO 14 j = 1,n
146  IF (body(j).EQ.0.0d0.AND.name(j).EQ.nameg(im)) THEN
147  jg = j
148  END IF
149  14 CONTINUE
150  WRITE (6,15) name(jclose), name(jg), rsum, r(jclose-n)
151  15 FORMAT (' SETSYS HIARCH NM NMG RSUM RB ',
152  & i6,i5,1p,2e10.2)
153  iphase = 7
154  CALL reset
155  kspair = npairs
156  END IF
157 *
158 * Save global indices of existing members (KSTERM uses JLIST).
159  DO 16 l = 1,nch
160  jpert(l) = jlist(l)
161  16 CONTINUE
162 *
163 * Add energy of absorbed binary to the current initial energy.
164  eb = body(2*kspair-1)*body(2*kspair)*h(kspair)/body(n+kspair)
165  cm(9) = cm(9) + eb
166  ebch0 = ebch0 + eb
167 *
168 * Check saving of c.m. type and names.
169  IF (ksave(1).EQ.0.OR.kstar(n+kspair).NE.0) THEN
170  ksave(1) = kstar(n+kspair)
171  ksave(2) = name(2*kspair-1) + name(2*kspair)
172  END IF
173 *
174 * Terminate KS pair and copy components (JCOMP=0 excludes ghost).
175  iphase = 8
176  jcomp = 0
177  CALL ksterm
178 *
179 * Restore old members.
180  DO 18 l = 1,nch
181  jlist(l) = jpert(l)
182  18 CONTINUE
183 *
184 * Add terminated KS components to chain arrays.
185  DO 20 l = 1,2
186  nch = nch + 1
187  jlist(nch) = 2*npairs + l
188  namec(nch) = name(2*npairs+l)
189  bodyc(nch) = body(2*npairs+l)
190  m(nch) = body(2*npairs+l)
191  20 CONTINUE
192 * See whether to include merger ghost.
193  IF (jg.GT.0) THEN
194  nch = nch + 1
195  jlist(nch) = jg
196  namec(nch) = name(jg)
197  bodyc(nch) = body(jg)
198  m(nch) = body(jg)
199  END IF
200  IF (nch.GT.6) THEN
201  WRITE (6,30) nch
202  30 FORMAT (' DANGER! NCH ',i4)
203  stop
204  END IF
205  END IF
206 *
207 * Specify membership for chain COMMON.
208  50 nn = nch
209 *
210  RETURN
211 *
212  END