def flight_simulation( ): #While loop runs until rocket velocity is less than 10 feet/s while (True): #Calculates atmospheric density at altitude x and passes density to RK4 fxn. rho = compDensity(x) #Calculates mDot and thrust as tank pressure drops (if applicable) and altitude changes n_thrust, n_mdot = compThrust2(thrust, m_dot, (initial_mass * pr_ratio) , propellant_mass) #Calculates Cd as a fx of mach number K = compTemp(x) mach = compMach(v,K) n_cd = waveDrag(Cd,mach) #RK4 function to solve rocket differential equation. Returns v(t) approximated using Runge-Kutta 4th order method v = RK4(t,v, mass, final_mass, n_cd, n_thrust, n_mdot, gravity, area, step_size, rho) #Computes current displacement using reimen sum x = x + ((current_velocity + v)/2 * step_size) if (v > 10) or (t < 10): if (n_thrust > 0): mass = mass - n_mdot * step_size propellant_mass = propellant_mass - n_mdot * step_size bo_time = t bo_velocity = v bo_thrust = n_thrust bo_mdot = n_mdot bo_alt = x if(max_dynamic_pressure < (.5 * rho * v**2)): max_dynamic_pressure = (.5 * rho * v**2) #Thrust is off, but propellant is still being drained by the tank pressue fluid (if applicable, such as blowdown system) elif (n_thrust == 0 and n_mdot != 0): mass = mass - n_mdot * step_size propellant_mass = propellant_mass - n_mdot * step_size else: #Leave this for clarity, though redundant mass = mass x_graph = np.append(x_graph, x) v_graph = np.append(v_graph, v) current_velocity = v #steps the while loop forward in time t = t + step_size t_graph = np.append(t_graph,t) else: break
def flight_simulation(self): gravity = 32.174 # ft / s^2 step_size = .01 #initialize rocket data from __init__ thrust = self.thrust m_dot = self.m_dot area = self.area cd = self.cd pr_ratio = self.pr_ratio initial_mass = self.initial_mass propellant_mass = self.propellant_mass final_mass = self.final_mass mass = initial_mass #Initializes a bunch of stuff locally x_graph = np.array([0]) v_graph = np.array([0]) t_graph = np.array([0]) #Generally, do not change these. Describes initial conditions and #initializes the variables t=0 v=0 x = 0 rho=0 bo_time = 0 bo_velocity = 0 current_velocity = 0 max_q = 0 max_q_velocity = 0 max_q_altitude = 0 max_q_acceleration = 0 #While loop runs until rocket velocity is less than 10 feet/s while (x >= 0): #Calculates atmospheric density at altitude x and passes density to RK4 fxn. rho = compDensity(x) #Calculates mDot and thrust as tank pressure drops (if applicable) and altitude changes n_thrust, n_mdot = compThrust2(thrust, m_dot, (initial_mass * pr_ratio), propellant_mass) #Calculates Cd as a fx of mach number K = compTemp(x) mach = compMach(v,K) n_cd = waveDrag(cd,mach) #RK4 function to solve rocket differential equation. Returns v(t) approximated using Runge-Kutta 4th order method v = RK4(t,v, mass, final_mass, n_cd, n_thrust, n_mdot, gravity, area, step_size, rho) #Computes current displacement using reimen sum x = x + ((current_velocity + v)/2 * step_size) if (n_thrust > 0): mass = mass - n_mdot * step_size propellant_mass = propellant_mass - n_mdot * step_size #Get burnout bo_time = t bo_velocity = v bo_thrust = n_thrust bo_mdot = n_mdot bo_alt = x bo_mass = mass bo_accel = (thrust/mass)/32.2 - ((area * n_cd * .5 * rho * v**2)/mass)/32.2 - 1 bo_mdot = n_mdot temp_max_q = n_cd * rho * 1/2 * v**2 if (max_q < temp_max_q): max_q = temp_max_q max_q_velocity = v max_q_altitude = x max_q_time = t #using the time and step size to find slope of velocity graph if(np.size(v_graph) > 3 ): max_q_acceleration = (v_graph[int(np.floor(t/step_size))] - v_graph[int(np.floor(t/step_size)-1)])/step_size #Thrust is off, but propellant is still being drained by the tank pressue fluid (if applicable, such as blowdown system) elif (n_thrust == 0 and n_mdot != 0): mass = mass - n_mdot * step_size propellant_mass = propellant_mass - n_mdot * step_size else: #Leave this for clarity, though redundant mass = mass x_graph = np.append(x_graph, x) v_graph = np.append(v_graph, v) current_velocity = v #steps the while loop forward in time t = t + step_size t_graph = np.append(t_graph,t) #returns a tuple containing vectors containing displacement, velocity and time, maximum velocity, burnouttime, and max altitude return x_graph, v_graph, t_graph, bo_velocity, bo_time, np.max(x_graph), bo_alt, bo_mass, t_graph[np.argmax(x_graph)], bo_accel, bo_mdot, max_q, max_q_velocity, max_q_altitude, max_q_acceleration, max_q_time
print('\nTHRUST TESTED: ' +str(thrust)) #Establishes mDot from thrust, gravity and isp mDot = thrust/(gravity * isp) print(thrust) print('Starting mDot: ' + str(mDot)) while (True): #Calculates atmospheric density at altitude x and passes density to RK4 fxn. rho = compDensity(x) #Calculates mDot and thrust as tank pressure drops nThrust, nMdot = compThrust2(thrust, mDot, (initialMass * prRatio) , propellantMass) #Calculates Cd as a fx of mach number K = compTemp(x) mach = compMach(v,K) nCd = waveDrag(Cd,mach) #RK4 fxn v = RK4(t,v, mass, finalMass, nCd, nThrust, nMdot, gravity, Area, stepSize, rho) # Greater than 30 so that program will terminate when velocity is trivial # or t<10 to make sure loop does not break when object is first accelerating if (v > 30) or (t < 10): if (nThrust > 0 and (mass > finalMass)): mass = mass - nMdot * stepSize propellantMass = propellantMass - nMdot * stepSize burnOutTime = t burnOutVelocity = v thrustAtBO = nThrust nMdotAtBO = nMdot