discard_pl_close.f 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. c*************************************************************************
  2. c DISCARD_PL_CLOSE.F
  3. c*************************************************************************
  4. c Subroutine to check if a test particle and planet
  5. c are having or **will** have a encounter w/ r^2<r2crit within
  6. c in the next timestep. Uses LINEAR exploitation.
  7. c
  8. c Input:
  9. c xr,yr,zr ==> relative position of tp wrt planet
  10. c (real scalar)
  11. c vxr,vyr,vzr ==> relative velocity of tp wrt planet
  12. c (real scalor)
  13. c dt ==> time step (real scalor)
  14. c r2crit ==> boundary of encounter region
  15. c (real scalor)
  16. c Output:
  17. c iflg ==> encounter? = 0 no
  18. c = 1 yes
  19. c r2min ==> square of smallest predicted distance
  20. c
  21. c Remarks: Based on rmvs_chk_ind.f
  22. c Authors: Hal Levison
  23. c Date: 2/21/94
  24. c Last revision: 7/14/94
  25. subroutine discard_pl_close(xr,yr,zr,vxr,vyr,vzr,dt,r2crit,iflg,
  26. & r2min)
  27. include '../swift.inc'
  28. c... Inputs:
  29. real*8 xr,yr,zr,vxr,vyr,vzr,dt,r2crit
  30. c... Outputs
  31. integer iflg
  32. real*8 r2min
  33. c... Internals
  34. real*8 r2,v2,vdotr,tmin
  35. c-----
  36. c... Executable code
  37. c... First check if we're already in the encounter region. If so return
  38. c. with flag set to one.
  39. r2 = xr**2 + yr**2 + zr**2
  40. if (r2 .le. r2crit) then
  41. iflg = 1
  42. return
  43. endif
  44. c... If we're heading outward, then we are done
  45. vdotr = xr*vxr + yr*vyr + zr*vzr
  46. if (vdotr . gt. 0.d0) then
  47. iflg = 0
  48. return
  49. endif
  50. c... We're not yet inside and are converging so we need to calc. the
  51. c. minimum separation attained in time dt.
  52. v2 = vxr**2 + vyr**2 + vzr**2
  53. tmin = -vdotr/v2
  54. if(tmin.lt.dt) then
  55. r2min = r2 -(vdotr**2)/v2
  56. else
  57. r2min = r2 + 2.d0*vdotr*dt + v2*dt*dt
  58. endif
  59. r2min = dmin1(r2min,r2) ! really make sure
  60. if (r2min.le.r2crit)then
  61. iflg = 1
  62. else
  63. iflg = 0
  64. endif
  65. return
  66. end ! discard_pl_close
  67. c--------------------------------------------------------------