anal_energy.f 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. c*************************************************************************
  2. c ANAL_ENERGY.F
  3. c*************************************************************************
  4. c Calculates the energy of the total system (massive bodies) wrt time.
  5. c returns the total energy of n objects by direct pairwise summation
  6. c G = 1., and we allow diff. masses. Also returns square of total ang. mom.
  7. c
  8. c Input:
  9. c t ==> current time
  10. c nbod ==> number of massive bodies (int scalar)
  11. c mass ==> mass of bodies (real array)
  12. c j2rp2 ==> scaled value of j2 moment (real*8 scalar)
  13. c j4rp4 ==> scaled value of j4 moment (real*8 scalar)
  14. c xh,yh,zh ==> current position in heliocentric coord
  15. c (real arrays)
  16. c vxh,vyh,vzh ==> current velocity in heliocentric coord
  17. c (real arrays)
  18. c
  19. c Output:
  20. c ke ==> kinetic energy
  21. c pot ==> potential energy
  22. c energy ==> Total energy
  23. c eltot ==> components of total angular momentum
  24. c (real array)
  25. c
  26. c Remarks:
  27. c Authors: Martin Duncan
  28. c Date: ?
  29. c Last revision: 1/24/97 HFL
  30. subroutine anal_energy(nbod,mass,j2rp2,j4rp4,xh,yh,zh,
  31. & vxh,vyh,vzh,ke,pot,energy,eltot)
  32. include '../swift.inc'
  33. c... Inputs:
  34. integer nbod
  35. real*8 mass(nbod),j2rp2,j4rp4
  36. real*8 xh(nbod),yh(nbod),zh(nbod)
  37. real*8 vxh(nbod),vyh(nbod),vzh(nbod)
  38. c... Output
  39. real*8 energy,eltot(3),ke,pot
  40. c... Internals
  41. real*8 elx,ely,elz
  42. real*8 xx,yy,zz,rr2,oblpot,msys,irh(NTPMAX),ir3h(NTPMAX)
  43. real*8 xb(NTPMAX),yb(NTPMAX),zb(NTPMAX) ! Used NTPMAX for symba
  44. real*8 vxb(NTPMAX),vyb(NTPMAX),vzb(NTPMAX)
  45. integer i,j
  46. c----
  47. c... Executable code
  48. call coord_h2b(nbod,mass,xh,yh,zh,vxh,vyh,vzh,
  49. & xb,yb,zb,vxb,vyb,vzb,msys)
  50. eltot(1)=(yb(nbod)*vzb(nbod)-zb(nbod)*vyb(nbod))*mass(nbod)
  51. eltot(2)=(zb(nbod)*vxb(nbod)-xb(nbod)*vzb(nbod))*mass(nbod)
  52. eltot(3)=(xb(nbod)*vyb(nbod)-yb(nbod)*vxb(nbod))*mass(nbod)
  53. ke = 0.5*mass(nbod)*(vxb(nbod)**2 + vyb(nbod)**2 + vzb(nbod)**2)
  54. pot= 0.d0
  55. do i = 1,nbod-1
  56. elx=(yb(i)*vzb(i)-zb(i)*vyb(i))*mass(i)
  57. ely=(zb(i)*vxb(i)-xb(i)*vzb(i))*mass(i)
  58. elz=(xb(i)*vyb(i)-yb(i)*vxb(i))*mass(i)
  59. eltot(1) = eltot(1) + elx
  60. eltot(2) = eltot(2) + ely
  61. eltot(3) = eltot(3) + elz
  62. ke = ke + 0.5*mass(i)*(vxb(i)**2 + vyb(i)**2 + vzb(i)**2)
  63. do j = i+1,nbod
  64. xx = xb(i) - xb(j)
  65. yy = yb(i) - yb(j)
  66. zz = zb(i) - zb(j)
  67. rr2 = xx**2 + yy**2 + zz**2
  68. if((mass(i).ne.0.0d0).and.(mass(j).ne.0.0d0)) then
  69. pot = pot - mass(i)*mass(j)/(sqrt(rr2))
  70. endif
  71. enddo
  72. enddo
  73. if(j2rp2.ne.0.0d0) then
  74. call getacch_ir3(nbod,2,xh,yh,zh,ir3h,irh)
  75. call obl_pot(nbod,mass,j2rp2,j4rp4,xh,yh,zh,irh,
  76. & oblpot)
  77. pot = pot + oblpot
  78. endif
  79. energy = ke + pot
  80. return
  81. end ! anal_energy
  82. c-----------------------------------------------------------------------