anal_energy_mtiny.f 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. c*************************************************************************
  2. c ANAL_ENERGY_MTINY.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 nbodm ==> Location of last massive body(int scalar)
  12. c mass ==> mass of bodies (real array)
  13. c j2rp2 ==> scaled value of j2 moment (real*8 scalar)
  14. c j4rp4 ==> scaled value of j4 moment (real*8 scalar)
  15. c xh,yh,zh ==> current position in heliocentric coord
  16. c (real arrays)
  17. c vxh,vyh,vzh ==> current velocity in heliocentric coord
  18. c (real arrays)
  19. c
  20. c Output:
  21. c ke ==> kinetic energy
  22. c pot ==> potential energy
  23. c energy ==> Total energy
  24. c eltot ==> components of total angular momentum
  25. c (real array)
  26. c
  27. c Remarks: Based on anal_energy
  28. c Authors: Hal Levison
  29. c Date: 12/16/06
  30. c Last revision:
  31. subroutine anal_energy_mtiny(nbod,nbodm,mass,j2rp2,j4rp4,xh,yh,zh,
  32. & vxh,vyh,vzh,ke,pot,energy,eltot)
  33. include '../swift.inc'
  34. c... Inputs:
  35. integer nbod,nbodm
  36. real*8 mass(nbod),j2rp2,j4rp4
  37. real*8 xh(nbod),yh(nbod),zh(nbod)
  38. real*8 vxh(nbod),vyh(nbod),vzh(nbod)
  39. c... Output
  40. real*8 energy,eltot(3),ke,pot
  41. c... Internals
  42. real*8 elx,ely,elz
  43. real*8 xx,yy,zz,rr2,oblpot,msys,irh(NTPMAX),ir3h(NTPMAX)
  44. real*8 xb(NTPMAX),yb(NTPMAX),zb(NTPMAX) ! Used NTPMAX for symba
  45. real*8 vxb(NTPMAX),vyb(NTPMAX),vzb(NTPMAX)
  46. integer i,j
  47. c----
  48. c... Executable code
  49. call coord_h2b(nbod,mass,xh,yh,zh,vxh,vyh,vzh,
  50. & xb,yb,zb,vxb,vyb,vzb,msys)
  51. eltot(1)=(yb(nbod)*vzb(nbod)-zb(nbod)*vyb(nbod))*mass(nbod)
  52. eltot(2)=(zb(nbod)*vxb(nbod)-xb(nbod)*vzb(nbod))*mass(nbod)
  53. eltot(3)=(xb(nbod)*vyb(nbod)-yb(nbod)*vxb(nbod))*mass(nbod)
  54. ke = 0.5*mass(nbod)*(vxb(nbod)**2 + vyb(nbod)**2 + vzb(nbod)**2)
  55. pot= 0.d0
  56. do i = 1,nbodm
  57. elx=(yb(i)*vzb(i)-zb(i)*vyb(i))*mass(i)
  58. ely=(zb(i)*vxb(i)-xb(i)*vzb(i))*mass(i)
  59. elz=(xb(i)*vyb(i)-yb(i)*vxb(i))*mass(i)
  60. eltot(1) = eltot(1) + elx
  61. eltot(2) = eltot(2) + ely
  62. eltot(3) = eltot(3) + elz
  63. ke = ke + 0.5*mass(i)*(vxb(i)**2 + vyb(i)**2 + vzb(i)**2)
  64. do j = i+1,nbod
  65. xx = xb(i) - xb(j)
  66. yy = yb(i) - yb(j)
  67. zz = zb(i) - zb(j)
  68. rr2 = xx**2 + yy**2 + zz**2
  69. if((mass(i).ne.0.0d0).and.(mass(j).ne.0.0d0)) then
  70. pot = pot - mass(i)*mass(j)/(sqrt(rr2))
  71. endif
  72. enddo
  73. enddo
  74. do i = nbodm+1,nbod-1
  75. ke = ke + 0.5*mass(i)*(vxb(i)**2 + vyb(i)**2 + vzb(i)**2)
  76. elx=(yb(i)*vzb(i)-zb(i)*vyb(i))*mass(i)
  77. ely=(zb(i)*vxb(i)-xb(i)*vzb(i))*mass(i)
  78. elz=(xb(i)*vyb(i)-yb(i)*vxb(i))*mass(i)
  79. eltot(1) = eltot(1) + elx
  80. eltot(2) = eltot(2) + ely
  81. eltot(3) = eltot(3) + elz
  82. enddo
  83. if(j2rp2.ne.0.0d0) then
  84. call getacch_ir3(nbod,2,xh,yh,zh,ir3h,irh)
  85. call obl_pot(nbod,mass,j2rp2,j4rp4,xh,yh,zh,irh,
  86. & oblpot)
  87. pot = pot + oblpot
  88. endif
  89. energy = ke + pot
  90. return
  91. end ! anal_energy
  92. c-----------------------------------------------------------------------