Guest User

Starfire Kickstarter Calculations

a guest
Feb 18th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ! Starfire kickstarter claculations (suborbital space cannon)
  2. !   Does simulation of trajectory including air resistance
  3. !   Assumes gun fired directly up
  4. !   Does not include wind
  5. !   Several specific cases inputed  &  mass vs. altitude table produced
  6. !  
  7. ! This calculates full version of calculations outlined here:
  8. !   http://space.stackexchange.com/questions/3667/could-any-existing-gun-reach-the-karman-line
  9. !  
  10. ! rk4 approach inspired by
  11. ! http://www.mathworks.com/matlabcentral/fileexchange/2181-numerical-methods-using-matlab-2e/content/edition2/matlab/chap_9/rk4.m
  12. !
  13. ! Pressure/density equation:
  14. !  P(r) = P0 exp(H' (1/r - 1/r0) )
  15. !   H' = r0^2 / H
  16. !   H = 8.6 km     or maybe    7.4 km  ...depends on temperature
  17. !   r0 = 6,378.1 km
  18.  
  19. module problem_values
  20.   implicit none
  21.   real, parameter :: Hchar = 7.4, &
  22.                     & r0 = 6378.1, &
  23.                     & pi = 3.14159265359, &
  24.                     & tube_length = 13.716, & ! 45 feet
  25. !                     & tube_length = 19.812, & ! 65 feet
  26.                     & tube_diam = 0.2032, & ! 8 inches
  27.                     & tube_P = 4.13685e8 ! Pascals
  28.  
  29.   ! case specific
  30.   real :: v0, diam, mass, Cd, area, rho0
  31.   logical :: toprint
  32.  
  33. end module problem_values
  34.  
  35. program rk4_shell
  36.   use problem_values
  37.   implicit none
  38.   integer, parameter :: N = 2
  39.   real, dimension(2) :: xp_temp, x_temp, x0
  40.   interface
  41.     function x_prime(x,t)
  42.       implicit none
  43.       real, dimension(2) :: x_prime
  44.       real, dimension(2), intent(in) :: x
  45.       real, intent(in) :: t
  46.     end function
  47.   end interface
  48.  
  49.   toprint = .false.  ! turn back on to print the trajectory to file
  50.                      ! but comment out the cases you don't want, only prints once
  51.  
  52.   write(*,*) '     General calculations: '
  53.   write(*,*) ' maximum KE with tube = ',(tube_diam/2.)**2*tube_length*tube_P,' J '
  54.   write(*,*) '     = ',(tube_diam/2.)**2*tube_length*tube_P/(1.e6),' MJ '
  55.   write(*,*) ' '
  56.  
  57.   !  case-specific data
  58.  
  59.   ! tank gun data
  60.   v0 = 1750.0
  61.   diam = 0.12
  62.   mass = 21.0
  63.   Cd = 0.47
  64.   rho0 = 1.3
  65.              
  66.   ! starfire basic      
  67.   v0 = 7010.0
  68.   diam = 0.2032
  69.   mass = 34.05
  70.   Cd = 0.47
  71.   rho0 = 1.0
  72.  
  73.   ! starfire with revised missile shape, high altitude
  74.   v0 = 1500.
  75.   diam = 0.2032 / 2.
  76.   mass = 65.9 ! (2 inches)^2*Pi*(8000 kg/m^3)*(40 inches)
  77.   Cd = 0.75
  78.   rho0 = 0.447*1.3
  79.       ! image is 38 px high, 596 long, aspect ratio of 13
  80.      
  81.   ! maximum allowable mass
  82.   mass = 163.5
  83.   diam = 0.2032
  84.   Cd = 0.5
  85.  
  86.   ! generous Cd value
  87.   rho0 = 1.3
  88.   Cd = 0.1
  89.  
  90.   write(*,*) '    Parameters: '
  91.   write(*,*) ' mass            = ',mass,' kg'
  92.   write(*,*) ' muzzle velocity = ',v0,' m/s'
  93.   write(*,*) ' tube diameter   = ',diam,' meters '
  94.   write(*,*) ' drag coefficient= ',Cd,' unitless '
  95.   write(*,*) ' air density     = ',rho0,' kg/m3 '
  96.   write(*,*) ' altitude        = ',-log(rho0/1.3)*Hchar + 228.,' m'
  97.   write(*,*) ' '
  98.  
  99.   area = (diam/2.)**2*pi  
  100.  
  101.   x0(1) = 0.   ! state vector
  102.   x0(2) = v0
  103.   ! composed of  ( position , velocity )
  104.  
  105.   write(*,'(a)',advance='no') '  Maximum altitude (km) = '
  106.   call rk4(x_prime,N,0.,1000.,x0,10000,x_temp)
  107.   write(*,*) ' '
  108.   write(*,*) ' '
  109.  
  110.   write(*,*) '  Iteration on mass values with calculated muzzle velocity '
  111.   diam = 0.2032
  112.   rho0 = 1.3
  113.   Cd = 0.3
  114.  
  115.   mass = 5.0
  116.   write(*,*) ' '
  117.   write(*,*) '     M         v0       max_height '
  118.   do
  119.     v0 = sqrt( 2. * (tube_diam/2.)**2*tube_length*tube_P / mass )
  120.     x0(1) = 0.   ! state vector
  121.     x0(2) = v0
  122.     write(*,'(2F15.5)',advance='no') mass, v0
  123.     call rk4(x_prime,N,0.,1000.,x0,10000,x_temp)
  124.     if (mass > 1000.) exit
  125.     mass = mass * 1.2
  126.   end do
  127.  
  128.  
  129. end program rk4_shell
  130.  
  131. function x_prime(x,t)
  132.   use problem_values
  133.   implicit none
  134.   real, dimension(2) :: x_prime
  135.   real, dimension(2), intent(in) :: x
  136.   real, intent(in) :: t
  137.   real :: Hp, rho
  138.  
  139.   Hp = r0**2 / Hchar
  140.   rho = rho0*exp(Hp*(1/(r0+x(1)/1000.)-1/r0))  ! equation for density with height
  141.   !   otherwise, rho = rho0 * exp( -h/H )
  142. !   write(*,*) ' (h,rho) ',x(1),rho
  143.  
  144.   x_prime(1) = x(2)
  145.   x_prime(2) = -0.5*Cd*x(2)*abs(x(2))*area*rho / mass - 9.8
  146.  
  147. end function x_prime
  148.  
  149. subroutine rk4(f,n,a,b,x0,m,x)
  150.   use problem_values
  151.   implicit none
  152.   integer, intent(in) :: n,m   ! n dim of vector,  m steps to use
  153.   interface
  154.     function f(x,t)
  155.       implicit none
  156.       real, dimension(2) :: f
  157.       real, dimension(2), intent(in) :: x
  158.       real, intent(in) :: t
  159.     end function
  160.   end interface
  161.   real, intent(in) :: a,b
  162.   real, dimension(2), intent(in) :: x0
  163.   real, dimension(2), intent(out) :: x
  164.   real :: h, t, h_max
  165.   integer :: j
  166.   real, dimension(n) :: k1,k2,k3,k4
  167.  
  168.   h = (b-a)/m
  169.   h_max = h
  170.   t = a
  171.   x = x0
  172.   if (toprint) then
  173.     open( unit = 29 , file= "trajectory.dat" , status = "replace" )
  174.     write(29,*) '   altitude     velocity'
  175.   end if
  176.   do j = 1, m
  177.     if (toprint) then
  178.       if (mod(j,10)==0) then
  179.         write(29,*) x
  180.       end if
  181.     end if
  182.     k1 = h*f(x,t)
  183.     k2 = h*f(x+k1/2.,t+h/2.)
  184.     k3 = h*f(x+k2/2.,t+h/2.)
  185.     k4 = h*f(x+k3,t+h)
  186.     t = t + h
  187.     x = x + (k1+2*k2+2*k3+k4)/6.
  188.     if (x(1) > h_max) h_max = x(1)
  189.     if (x(1) < 0.) exit
  190.   end do
  191. !   write(*,*) ' '
  192. !   write(*,*) ' max_h ',h_max,' m'
  193. !   write(*,*) '       ',h_max/1000.,' km '
  194.   write(*,*) h_max/1000.
  195.   if (toprint) close(29)
  196.  
  197.  
  198. end subroutine rk4
Advertisement
Add Comment
Please, Sign In to add comment