rmvs2_step.f 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. c*************************************************************************
  2. c RMVS2_STEP.F
  3. c*************************************************************************
  4. c This subroutine takes a step in helio coord.
  5. c both massive and test particles
  6. c INCLUDES close approuches between test particles and planets
  7. c
  8. c VERSION 2 of RMVS
  9. c
  10. c Input:
  11. c i1st ==> = 0 if first step; = 1 not (int scalar)
  12. c time ==> current time (real scalar)
  13. c nbod ==> number of massive bodies (int scalar)
  14. c ntp ==> number of massive bodies (int scalar)
  15. c mass ==> mass of bodies (real array)
  16. c j2rp2,j4rp4 ==> J2*radii_pl^2 and J4*radii_pl^4
  17. c (real scalars)
  18. c xh,yh,zh ==> initial planet position in helio coord
  19. c (real arrays)
  20. c vxh,vyh,vzh ==> initial planet velocity in helio coord
  21. c (real arrays)
  22. c xht,yht,zht ==> initial tp position in helio coord
  23. c (real arrays)
  24. c vxht,vyht,vzht ==> initial tp velocity in helio coord
  25. c (real arrays)
  26. c istat ==> status of the test paricles
  27. c (2d integer array)
  28. c istat(i,1) = 0 ==> active: = 1 not
  29. c istat(i,2) = -1 ==> Danby did not work
  30. c rstat ==> status of the test paricles
  31. c (2d real array)
  32. c dt ==> time step
  33. c Output:
  34. c xh,yh,zh ==> final planet position in helio coord
  35. c (real arrays)
  36. c vxh,vyh,vzh ==> final planet velocity in helio coord
  37. c (real arrays)
  38. c xht,yht,zht ==> final tp position in helio coord
  39. c (real arrays)
  40. c vxht,vyht,vzht ==> final tp position in helio coord
  41. c (real arrays)
  42. c
  43. c
  44. c Remarks: Adopted from martin's nbwh.f program
  45. c Authors: Hal Levison
  46. c Date: 2/19/93
  47. c Last revision: 8/25/94
  48. subroutine rmvs2_step(i1st,time,nbod,ntp,mass,j2rp2,j4rp4,
  49. & xh,yh,zh,vxh,vyh,vzh,xht,yht,zht,vxht,vyht,vzht,
  50. & istat,rstat,dt)
  51. include '../swift.inc'
  52. include '../rmvs/rmvs.inc'
  53. c... Inputs Only:
  54. integer nbod,ntp,i1st
  55. real*8 mass(nbod),dt,time,j2rp2,j4rp4
  56. c... Inputs and Outputs:
  57. integer istat(NTPMAX,NSTAT)
  58. real*8 rstat(NTPMAX,NSTATR)
  59. real*8 xh(nbod),yh(nbod),zh(nbod)
  60. real*8 vxh(nbod),vyh(nbod),vzh(nbod)
  61. real*8 xht(ntp),yht(ntp),zht(ntp)
  62. real*8 vxht(ntp),vyht(ntp),vzht(ntp)
  63. c... Internals
  64. integer i1sttp,i1stpl,i1sto,icflg,i,j,np
  65. real*8 xtmp(NPLMAX,NTPENC),ytmp(NPLMAX,NTPENC)
  66. real*8 ztmp(NPLMAX,NTPENC),peri(NTPMAX)
  67. real*8 xtmpo(NPLMAX,NTENC),ytmpo(NPLMAX,NTENC)
  68. real*8 ztmpo(NPLMAX,NTENC)
  69. real*8 xbeg(NPLMAX),ybeg(NPLMAX),zbeg(NPLMAX)
  70. real*8 vxbeg(NPLMAX),vybeg(NPLMAX),vzbeg(NPLMAX)
  71. real*8 xend(NPLMAX),yend(NPLMAX),zend(NPLMAX)
  72. real*8 vxend(NPLMAX),vyend(NPLMAX),vzend(NPLMAX)
  73. Integer nenco(NPLMAX),itpenco(NTPMAX,NPLMAX),nenci(NPLMAX)
  74. integer itpenci(NTPMAX,NPLMAX),ienci(NTPMAX),ienco(NTPMAX)
  75. integer istattmp(NTPMAX,NSTAT),isperi(NTPMAX)
  76. c----
  77. c... Executable code
  78. i1sttp = i1st
  79. i1sto = i1st
  80. c... are there any encounters?
  81. call rmvs_chk(nbod,ntp,mass,xh,yh,zh,vxh,vyh,vzh,xht,yht,zht,
  82. & vxht,vyht,vzht,istat,dt,icflg,nenco,itpenco,nenci,
  83. & itpenci,ienci,ienco)
  84. c... keep track of encounters in the inner region
  85. call rmvs_elog(ntp,icflg,ienci,istat)
  86. c.... if not just do a normal step and leave
  87. if(icflg.eq.0) then
  88. call step_kdk(i1st,time,nbod,ntp,mass,j2rp2,j4rp4,xh,yh,zh,
  89. & vxh,vyh,vzh,xht,yht,zht,vxht,vyht,vzht,istat,rstat,dt)
  90. do i=1,ntp
  91. if(istat(i,1).eq.0) then
  92. istat(i,2) = 0
  93. endif
  94. enddo
  95. return ! NOTE AN EXIT
  96. endif
  97. c... ENCOUNTER STUFF FROM HERE ON!!!!!
  98. c... save initial x and v of planets if there are planocentric enc
  99. do i=1,nbod
  100. xbeg(i) = xh(i)
  101. ybeg(i) = yh(i)
  102. zbeg(i) = zh(i)
  103. vxbeg(i) = vxh(i)
  104. vybeg(i) = vyh(i)
  105. vzbeg(i) = vzh(i)
  106. enddo
  107. c... do a full step for the planets
  108. i1stpl = i1st
  109. call step_kdk_pl(i1stpl,nbod,mass,j2rp2,j4rp4,xh,yh,zh,
  110. & vxh,vyh,vzh,dt)
  111. c... save the final position and velocity of planets
  112. do i=1,nbod
  113. xend(i) = xh(i)
  114. yend(i) = yh(i)
  115. zend(i) = zh(i)
  116. vxend(i) = vxh(i)
  117. vyend(i) = vyh(i)
  118. vzend(i) = vzh(i)
  119. enddo
  120. c... Now do the interpolation for intermediate steps
  121. if(icflg.eq.-1) then
  122. call rmvs2_interp(nbod,xbeg,ybeg,zbeg,vxbeg,vybeg,vzbeg,
  123. & xend,yend,zend,vxend,vyend,vzend,dt,mass(1),
  124. & xtmp,ytmp,ztmp,xtmpo,ytmpo,ztmpo)
  125. else
  126. call rmvs2_interp_o(nbod,xbeg,ybeg,zbeg,vxbeg,vybeg,vzbeg,
  127. & xend,yend,zend,vxend,vyend,vzend,dt,mass(1),
  128. & xtmpo,ytmpo,ztmpo)
  129. endif
  130. c... first do the outer region integration, save the planet position
  131. call rmvs2_step_out(i1st,nbod,ntp,mass,j2rp2,j4rp4,
  132. & xbeg,ybeg,zbeg,xtmpo,ytmpo,ztmpo,xht,yht,zht,
  133. & vxht,vyht,vzht,istat,ienco,dt)
  134. c... do the plaocentric stuff if necessary
  135. if(icflg.eq.-1) then
  136. call rmvs_step_in(i1sttp,nbod,ntp,mass,j2rp2,j4rp4,xtmp,
  137. & ytmp,ztmp,xbeg,ybeg,zbeg,vxbeg,vybeg,vzbeg,
  138. & xend,yend,zend,vxend,vyend,vzend,xht,yht,zht,
  139. & vxht,vyht,vzht,istat,nenci,itpenci,isperi,peri,dt)
  140. do i=1,ntp
  141. if(istat(i,1).eq.0) then
  142. istat(i,2) = 0
  143. endif
  144. enddo
  145. endif
  146. c... As of this point all the test particles that are involved in an
  147. c... encounter have been moved. But not the ones that have not.
  148. c... so move those, BUT NOT the onces in the encounter
  149. c... make a temporary istat array ao only they are active
  150. do i=1,ntp
  151. if(istat(i,1).eq.0) then
  152. if( (ienco(i).ne.0) .or. (ienci(i).ne.0) ) then
  153. istattmp(i,1) = 1 ! don't integrate it
  154. else
  155. istattmp(i,1) = 0 ! integrate it
  156. endif
  157. do j=2,NSTAT
  158. istattmp(i,j) = 0
  159. enddo
  160. else
  161. istattmp(i,1) = 1 ! don't integrate it
  162. endif
  163. enddo
  164. c... do a full step
  165. i1sto = 0 ! we need to recalculate accel arrays
  166. call step_kdk_tp(i1sto,nbod,ntp,mass,j2rp2,j4rp4,
  167. & xbeg,ybeg,zbeg,xend,yend,zend,
  168. & xht,yht,zht,vxht,vyht,vzht,istattmp,dt)
  169. c... fix up the istat array
  170. do i=1,ntp
  171. if(istattmp(i,2) .ne. 0) then ! danby screwed up
  172. istat(i,1) = 1
  173. do j=2,NSTAT
  174. istat(i,j) = istattmp(i,j)
  175. enddo
  176. endif
  177. enddo
  178. c... put the enc info into istat
  179. do i=1,ntp
  180. if(istat(i,1).eq.0) then
  181. if(ienci(i).ne.0) then
  182. istat(i,2) = -ienci(i)
  183. istat(i,3) = ienci(i)
  184. if(isperi(i).eq.0) then
  185. rstat(i,3) = peri(i)
  186. np = NSTATP + ienci(i) - 1
  187. if(rstat(i,np).eq.0) then
  188. rstat(i,np) = peri(i)
  189. else
  190. rstat(i,np) = min(rstat(i,np),peri(i))
  191. endif
  192. else
  193. rstat(i,3) = 0.0d0
  194. endif
  195. else if(ienco(i).ne.0) then
  196. istat(i,2) = ienco(i)
  197. else
  198. istat(i,2) = 0
  199. endif
  200. endif
  201. enddo
  202. c... we MUST make sure that the saved accel arrays are ok
  203. c... calculate them again
  204. i1st = 0
  205. return
  206. end ! step_enc
  207. c------------------------------------------------------------------------