Nbody6
 All Files Functions Variables
switch.f
Go to the documentation of this file.
1  SUBROUTINE switch(Y)
2 *
3 *
4 * Switching of chain.
5 * -------------------
6 *
7  include 'commonc.h'
8  include 'common2.h'
9  LOGICAL kslow,kcoll,itest
10  REAL*8 y(nmx8),xcnew(nmx3),ksch,ksnew(nmx)
11  common/slow1/ tk2(0:nmx),ejump,ksch(nmx),kslow,kcoll
12  INTEGER iold(nmx)
13 *
14 *
15 * Copy Y-array to COMMON.
16  CALL ysave(y)
17 *
18 * First transform to chain coordinates.
19  DO i=1,n-1
20  l1=3*(i-1)+1
21  ks1=4*(i-1)+1
22  CALL ksphys(q(ks1),p(ks1),xc(l1),wc(l1))
23  END DO
24 *
25  l2=3*(iname(1)-1)
26  DO k=1,3
27  x(l2+k)=0.0
28  END DO
29 *
30 * Set X for determining new chain indices.
31  DO i=1,n-1
32  l=3*(i-1)
33  l1=l2
34  l2=3*(iname(i+1)-1)
35  DO k=1,3
36  x(l2+k)=x(l1+k)+xc(l+k)
37  END DO
38  END DO
39 *
40 * Save the old chain indices.
41  DO i=1,n
42  iold(i)=iname(i)
43  END DO
44 *
45 * Select new indices.
46  CALL SELECT
47 *
48 * EXit if chain vectors are unchanged.
49  isw=0
50  DO i=1,n
51  IF(iname(i).NE.iold(i))isw=isw+1
52  END DO
53  IF(isw.EQ.0)RETURN
54 *
55 * Transform chain momenta.
56  l1=3*(iold(1)-1)
57  ln=3*(iold(n)-1)
58  l=3*(n-2)
59  DO k=1,3
60  pi(l1+k)=-wc(k)
61  pi(ln+k)=wc(l+k)
62  END DO
63  DO i=2,n-1
64  l=3*(i-1)
65  li=3*(iold(i)-1)
66  DO k=1,3
67  pi(li+k)=wc(l+k-3)-wc(l+k)
68  END DO
69  END DO
70  l1=3*(iname(1)-1)
71  ln=3*(iname(n)-1)
72  l=3*(n-2)
73  DO k=1,3
74  wc(k)=-pi(l1+k)
75  wc(l+k)=pi(ln+k)
76  END DO
77  DO i=2,n-2
78  l=3*(i-1)
79  li=3*(iname(i)-1)
80  DO k=1,3
81  wc(l+k)=wc(l+k-3)-pi(li+k)
82  END DO
83  END DO
84 *
85 * Construct new chain coordinates.
86  DO i=1,3*(n-1)
87  xcnew(i)=0.0
88  END DO
89 * Transformation matrix (old to new) has only coefficients -1, 0 or +1.
90  DO icnew=1,n-1
91 * Find K0 & K1 for IOLD(K0) = INAME(ICNEW) & IOLD(K1) = INAME(ICNEW+1).
92  lnew=3*(icnew-1)
93  DO i=1,n
94  IF(iold(i).EQ.iname(icnew))k0=i
95  IF(iold(i).EQ.iname(icnew+1))k1=i
96  END DO
97  DO icold=1,n-1
98  lold=3*(icold-1)
99  IF((k1.GT.icold).AND.(k0.LE.icold))THEN
100 * Add.
101  DO k=1,3
102  xcnew(lnew+k)=xcnew(lnew+k)+xc(lold+k)
103  END DO
104  ELSE IF((k1.LE.icold).AND.(k0.GT.icold))THEN
105 * Subtract.
106  DO k=1,3
107  xcnew(lnew+k)=xcnew(lnew+k)-xc(lold+k)
108  END DO
109  END IF
110  END DO
111  END DO
112 *
113 * Perform KS-transformations and update chain coordinates & RINV.
114  DO i=1,n-1
115  l1=3*(i-1)+1
116  ks1=4*(i-1)+1
117  CALL physks(xcnew(l1),wc(l1),q(ks1),p(ks1))
118  DO k=1,3
119  xc(l1+k-1)=xcnew(l1+k-1)
120  END DO
121  rinv(i)=1.0/(q(ks1)**2+q(ks1+1)**2+q(ks1+2)**2+q(ks1+3)**2)
122  END DO
123 *
124 * Swop Ksch acording to Iold and Iname.
125  do i=1,n-1
126  ksnew(i)=1.0
127  end do
128  do i=1,n-1
129  if(ksch(i).ne.1.0d0)then
130  i1=iold(i)
131  i2=iold(i+1)
132  do j=1,n-1
133  itest=((i1.eq.iname(j)).and.(i2.eq.iname(j+1))).or.
134  & ((i2.eq.iname(j)).and.(i1.eq.iname(j+1)))
135  if(itest)then
136  ksnew(j)=ksch(i)
137  end if
138  end do
139  end if
140  end do
141  do i=1,n-1
142  ksch(i)=ksnew(i)
143  end do
144 * Define auxiliary quantities.
145  mass=0.0
146  DO i=1,n
147  l=3*(i-1)
148  mc(i)=m(iname(i))
149  mass=mass+mc(i)
150  END DO
151 *
152  do i=1,n
153  tk1(i)=-1./mc(i)
154  end do
155  do i=1,n-1
156  if(ksch(i).ne.1.0d0)then
157  tk1(i)=tk1(i)/ksch(i)
158  tk1(i+1)=tk1(i+1)/ksch(i)
159  end if
160  end do
161  DO i=1,n-1
162  tkk(i)=.5d0*(-tk1(i)-tk1(i+1))
163  mkk(i)=mc(i)*mc(i+1)/ksch(i)
164  DO j=i+1,n
165  mij(i,j)=mc(i)*mc(j)
166  mij(j,i)=mij(i,j)
167  END DO
168  END DO
169  do i=1,n-1
170  m12=mc(i)+mc(i+1)
171  dt12=0.5d0*(1.d0-1.d0/ksch(i))/m12
172  if(i.gt.1) tkk(i-1)=tkk(i-1)+dt12
173  if(i.lt.n-1) tkk(i+1)=tkk(i+1)+dt12
174  if(i.gt.1.and.i.lt.n-1) tk2(i)=-2.0d0*dt12
175  end do
176 * Note: TK2(0) & TK2(N) should be zero but never used.
177  tk2(0) = 0.0
178  tk2(n) = 0.0
179 *
180 * Copy Y-array from COMMON.
181  CALL ycopy(y)
182 *
183  RETURN
184  END