Nbody6
 All Files Functions Variables
nblist.f
Go to the documentation of this file.
1  SUBROUTINE nblist(I,RS0)
2 *
3 *
4 * Neighbour list & radius.
5 * ------------------------
6 *
7  include 'common6.h'
8 *
9 *
10 * Form square neighbour radius.
11  rs2 = rs0**2
12  ilist(1) = 0
13 *
14 * Modify initial radius for Plummer or King-Michie models.
15  IF (kz(5).GT.0.OR.kz(22).GE.2) THEN
16  ri2 = (x(1,i) - rdens(1))**2 + (x(2,i) - rdens(2))**2 +
17  & (x(3,i) - rdens(3))**2
18 * Note possible large RS0 set in routine MERGE at later times.
19  IF (time.EQ.0.0d0) THEN
20  rs2 = rs2*(1.0 + ri2)
21 * ELSE
22 * RSX = 0.3*(1000.0/FLOAT(N - NPAIRS))**0.3333
23 * RS2 = (RSX*RSCALE)**2*(1.0 + RI2)
24  END IF
25  END IF
26 *
27  vi2 = xdot(1,i)**2 + xdot(2,i)**2 + xdot(3,i)**2
28  IF (vi2.GT.0.0) THEN
29  dtr = 0.1*rs0/sqrt(vi2)
30  vrfac = -0.1*rs2/dtr
31 * Estimated radial velocity factor for outer sphere.
32  ELSE
33  vrfac = 0.0
34  END IF
35 *
36 * Search all single particles & c.m. bodies.
37  1 rcrit2 = 1.59*rs2
38  nnb = 1
39  DO 10 j = ifirst,ntot
40  rij2 = (x(1,i) - x(1,j))**2 + (x(2,i) - x(2,j))**2 +
41  & (x(3,i) - x(3,j))**2
42  IF (rij2.GT.rcrit2) go to 10
43  IF (rij2.GT.rs2) THEN
44 * Skip velocity test for primordial binaries.
45  IF (time.LE.0.0d0.AND.j.LE.2*nbin0) go to 6
46  rijdot = 0.0
47  DO 4 k = 1,3
48  rijdot = rijdot +
49  & (x(k,i) - x(k,j))*(xdot(k,i) - xdot(k,j))
50  4 CONTINUE
51 * Accept member if maximum penetration factor is significant.
52  IF (rijdot.GE.vrfac) go to 10
53  ELSE
54  IF (j.EQ.i) go to 10
55  END IF
56 * Include both components in case of primordial binaries.
57  6 IF (j.LE.2*nbin0.AND.time.EQ.0.0d0) THEN
58  jpair = kvec(j)
59 * Consider odd and even locations and skip body $I.
60  IF (j.EQ.2*jpair-1) THEN
61  nnb = nnb + 1
62  ilist(nnb) = j
63  IF (i.NE.j + 1) THEN
64  nnb = nnb + 1
65  ilist(nnb) = j + 1
66  END IF
67 * Exclude previously saved component.
68  ELSE IF (ilist(nnb).LT.j-1) THEN
69  IF (i.NE.j - 1) THEN
70  nnb = nnb + 1
71  ilist(nnb) = j - 1
72  END IF
73  nnb = nnb + 1
74  ilist(nnb) = j
75  END IF
76  ELSE
77  nnb = nnb + 1
78  ilist(nnb) = j
79  END IF
80  10 CONTINUE
81 *
82 * Check membership (NNB > 2 for primordial binaries).
83  IF (nnb.EQ.1.OR.(i.LE.2*nbin0.AND.nnb.EQ.2)) THEN
84 * Double the neighbour sphere and try again.
85  rs2 = 1.59*rs2
86  nbvoid = nbvoid + 1
87  go to 1
88  ELSE IF (nnb.GE.nnbmax) THEN
89 * Reduce neighbour sphere but avoid possible looping.
90  a1 = znbmax/float(nnb)
91  IF (abs(a1 - 0.5).LT.0.05) a1 = 1.2*a1
92  rs2 = rs2*a1**0.66667
93  nbfull = nbfull + 1
94  go to 1
95  END IF
96 *
97 * Set neighbour radius and copy list membership.
98  rs(i) = sqrt(rs2)
99  list(1,i) = nnb - 1
100  DO 20 l = 2,nnb
101  list(l,i) = ilist(l)
102  20 CONTINUE
103 *
104  RETURN
105 *
106  END