Nbody6
 All Files Functions Variables
energy.f
Go to the documentation of this file.
1  SUBROUTINE energy
2 *
3 *
4 * Total energy.
5 * -------------
6 *
7  include 'common6.h'
8 *
9 *
10 * Sum the total energy of regularized pairs.
11  ebin = 0.0d0
12  DO 10 ipair = 1,npairs
13 * Skip pairs with zero mass of c.m. particle (merged binary ghost).
14  IF (body(n+ipair).GT.0.0d0) THEN
15 * Predict coordinates, velocities & binding energy.
16  CALL resolv(ipair,1)
17  ebin = ebin + body(2*ipair-1)*body(2*ipair)*ht/
18  & body(n+ipair)
19  END IF
20  10 CONTINUE
21 *
22 * Calculate the potential energy.
23  zkin = 0.d00
24  pot = 0.0
25  vir = 0.0
26  i = 1
27  20 jmin = i + 1
28  IF (i.LE.2*npairs) THEN
29 * Binding energy of regularized pairs is included explicitly above.
30  ipair = kvec(i)
31  jmin = 2*ipair + 1
32  END IF
33  potj = 0.d00
34 *
35  DO 30 j = jmin,n
36  IF (body(j).EQ.0.0d0) go to 30
37  a1 = x(1,i) - x(1,j)
38  a2 = x(2,i) - x(2,j)
39  a3 = x(3,i) - x(3,j)
40  potj = potj + body(j)/sqrt(a1*a1 + a2*a2 + a3*a3)
41  30 CONTINUE
42 *
43  pot = pot + body(i)*potj
44  i = i + 1
45  IF (i.LT.n) go to 20
46 *
47 * Sum the kinetic energy (include c.m. bodies but not components).
48  DO 40 i = ifirst,ntot
49  zkin = zkin + body(i)*(xdot(1,i)**2 + xdot(2,i)**2 +
50  & xdot(3,i)**2)
51  40 CONTINUE
52  zkin = 0.5d0*zkin
53 *
54 * Obtain the tidal potential energy for linearized external field.
55  IF (kz(14).EQ.0) THEN
56 * Note: ETIDE holds accumulated tidal energy if KZ(14) = 3.
57  etide = 0.0d0
58  ELSE
59 * Employ general expression sum {m*r*F} for virial energy.
60  CALL xtrnlv(1,n)
61 * Form tidal energy with Plummer potential (note ETIDE use for #14=3).
62  IF (kz(14).EQ.4) THEN
63  etide = 0.0
64  DO 50 i = 1,n
65  ri2 = ap2
66  DO 45 k = 1,3
67  ri2 = ri2 + x(k,i)**2
68  45 CONTINUE
69  etide = etide - body(i)*mp/sqrt(ri2)
70  50 CONTINUE
71  END IF
72  END IF
73 *
74 * Check differential potential energy due to chain subsystem.
75  IF (nch.GT.0) THEN
76  CALL chpot(dp)
77  pot = pot + dp
78  END IF
79 *
80 * Total energy = ZKIN - POT + ETIDE + EBIN + ESUB + EMERGE + ECOLL.
81 *
82  RETURN
83 *
84  END