bs_int.f 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. C**************************************************************************
  2. C BS_INT
  3. C**************************************************************************
  4. c This is the subroutine that does the the bs integration step.
  5. c
  6. c Input:
  7. c nbod ==> number of planets (int scalar)
  8. c ntp ==> number of test particles (int scalar)
  9. c mass ==> mass of bodies (real array)
  10. c j2rp2,j4rp4 ==> J2*radii_pl^2 and J4*radii_pl^4
  11. c (real scalars)
  12. c istat ==> status of the test paricles
  13. c (2d integer array)
  14. c istat(i,1) = 0 ==> active: = 1 not
  15. c istat(i,2) = -1 ==> Danby did not work
  16. c x ==> initial value independent variable
  17. c (real scalar)
  18. c h0 ==> stepsize (real scalar)
  19. c y ==> initial value dependent variables
  20. c (real array)
  21. c eps ==> local truncation error tolerance
  22. c
  23. c Output:
  24. c y ==> final value dependent variables (real array)
  25. c x ==> final value independent variable (real scalar)
  26. c h0 ==> recommended stepsize for the next call (real scalar)
  27. c
  28. c Remarks: Based on Renu's code: mass,j2rp2,j4rp4 and istat are
  29. c just passed on to bs_der
  30. c Authors: Hal Levison
  31. c Date: 5/17/93
  32. c Last revision: 2/24/94
  33. subroutine bs_int(nbod,ntp,mass,j2rp2,j4rp4,istat,x,h0,y,eps)
  34. include '../swift.inc'
  35. include 'bs.inc'
  36. c... Inputs Only:
  37. integer nbod,ntp
  38. real*8 mass(nbod),h0,eps,j2rp2,j4rp4
  39. c... Input & Output
  40. real*8 x,y(N6DBS)
  41. integer istat(NTPMAX,NSTAT)
  42. c... Internals
  43. real*8 tp(NTEMP),dy(N6DBS),d(6),alt(10),lt(10)
  44. integer idiv,i,ii,m,l,m1,k,mmk,i1,i1max,ik,n
  45. real*8 xa,xb,varm,fl,h,hd,flt,eta2,dta,yb,c,b1
  46. real*8 den,dtn,b,var,varma
  47. logical lbreak
  48. data lt/1,2,3,4,6,8,12,16,24,32/
  49. data alt/1.d0,2.d0,3.d0,4.d0,6.d0,8.d0,12.d0,16.d0,24.d0,32.d0/
  50. save lt,alt
  51. c----
  52. c... Executable code
  53. n = 6*(nbod+ntp)
  54. xa=x
  55. call bs_der(ntp,nbod,mass,j2rp2,j4rp4,istat,y,dy)
  56. do i=1,n
  57. ii=12*i
  58. tp(ii-1)=dabs(y(i))
  59. c
  60. if(tp(ii-1).lt.eps) then
  61. tp(ii-1)=eps
  62. endif
  63. c
  64. tp(ii-4)=dy(i)
  65. tp(ii)=y(i)
  66. enddo
  67. do idiv=0,NTRYS
  68. xb=h0+xa
  69. c
  70. c successive extrapolations
  71. c
  72. c do m=1,10
  73. m = 1
  74. lbreak = .true.
  75. do while( (m.le.10) .and. lbreak )
  76. l=lt(m)
  77. fl=alt(m)
  78. varm=0.d0
  79. m1=min0(m-1,6)
  80. c
  81. c calculation of d(k)=(h(m-k)/h(m))**2 for equation (6)
  82. c
  83. if(m1.ne.0) then
  84. do k=1,m1
  85. mmk=m-k
  86. flt=alt(mmk)
  87. d(k)=(fl/flt)**2
  88. enddo
  89. endif
  90. h=h0/fl
  91. hd=0.5d0*h
  92. c
  93. c integration
  94. c
  95. do i=1,n
  96. ii=12*i
  97. tp(ii-3)=tp(ii)
  98. y(i)=tp(ii)+hd*tp(ii-4) ! equation (3b)
  99. enddo
  100. i1max=2*l-1
  101. x=xa
  102. do i1=1,i1max
  103. x=x+hd
  104. call bs_der(ntp,nbod,mass,j2rp2,j4rp4,istat,y,dy)
  105. do i=1,n
  106. ii=12*i
  107. tp(ii-1)=dmax1(tp(ii-1),dabs(y(i)))
  108. eta2=tp(ii-3)+h*dy(i)
  109. tp(ii-3)=y(i)
  110. y(i)=eta2
  111. enddo
  112. enddo
  113. call bs_der(ntp,nbod,mass,j2rp2,j4rp4,istat,y,dy)
  114. do i=1,n
  115. ii=12*i
  116. dta=tp(ii-11)
  117. yb=(tp(ii-3)+y(i)+hd*dy(i))/2.d0 ! equation (3d)
  118. c
  119. c extrapolated values
  120. c
  121. c=yb ! equation (6b)
  122. tp(ii-11)=yb ! equation (6a)
  123. if(m1.ne.0) then
  124. do k=1,m1
  125. b1=d(k)*dta
  126. den=b1-c
  127. dtn=dta
  128. if(den.ne.0.d0) then
  129. b=(c-dta)/den
  130. dtn=c*b ! equation (6c)
  131. c=b1*b ! equation (6d)
  132. endif
  133. ik=ii-11+k
  134. dta=tp(ik)
  135. tp(ik)=dtn ! equation (6c)
  136. yb=yb+dtn ! equation (6f)
  137. enddo
  138. var=dabs(tp(ii-2)-yb)/tp(ii-1)
  139. varm=dmax1(varm,var)
  140. endif
  141. tp(ii-2)=yb
  142. enddo
  143. if(m.gt.3) then
  144. if(varm.le.eps) then ! return results to calling program
  145. x=xb
  146. do i=1,n
  147. ii=12*i
  148. y(i)=tp(ii-2)
  149. enddo
  150. h0=h0*1.5d0*0.6d0**(m-1-m1) ! recommend a new step size
  151. return
  152. endif
  153. if(varm.ge.varma) then ! calculation did not converge
  154. c start again with half the step size
  155. lbreak = .false.
  156. endif
  157. endif
  158. varma=varm
  159. m = m + 1
  160. enddo ! m
  161. h0=h0/2.d0
  162. enddo ! idiv
  163. write(*,*) ' ERROR (b_int): lack of convergence !!!! '
  164. c
  165. end ! bs_int
  166. c-----------------------------------------------------------------------------