Esempio n. 1
0
 def simulate(self):
     """
     Runs the simulation and starts the calculations
     """
     # Save time
     time_now = self.data.time[-1] + self.time_delta
     self.data.time.append(time_now)
     # Get the current height the rocket is at
     height_now = Formula.vector_addition(
         self.rocket.get_pos()) - self.planet.get_radius()
     distance_now = Formula.vector_addition(self.rocket.get_pos())
     self.data.heigth_rocket.append(height_now)  # Save current height
     # Get the temperature at the height of the rocket
     temp_low_now = self.atmosphere.get_layer(height_now).get_temp_low()
     temp_gradient_now = self.atmosphere.get_layer(
         height_now).get_temp_gradient()
     index_layer = self.atmosphere.get_layers().index(
         self.atmosphere.get_layer(height_now))
     height_low_now = self.atmosphere.calc_height_below(index_layer)
     temperature_now = Formula.temperature(temp_low_now, temp_gradient_now,
                                           height_low_now, height_now)
     self.data.temperature.append(
         temperature_now)  # Save current temperature
     # Get the pressure at the height of the rocket
     pressure_low_now = self.atmosphere.get_layer(
         height_now).get_pressure_low()
     pressure_now = Formula.pressure(pressure_low_now, temp_gradient_now,
                                     height_now, height_low_now,
                                     temp_low_now)
     self.data.pressure.append(pressure_now)  # Save current pressure
     # Get the current force of gravity the rocket is experiencing
     gravity_now = Formula.gravity(self.planet.get_mass(),
                                   self.rocket.get_mass(), distance_now)
     self.data.gravity.append(gravity_now)
     # Get the thrust the rocket is producing
     current_stage = self.rocket.get_current_stage()
     change_prop_mass = False
     if type(current_stage) == RocketPart:
         thrust_now = current_stage.get_thrust()
     else:
         thrust_now = Formula.thrust(current_stage.get_mass_change(),
                                     current_stage.get_velocity_exhaust(),
                                     current_stage.get_surface_nozzle(),
                                     current_stage.get_pressure_nozzle(),
                                     pressure_now)
         change_prop_mass = True
     self.data.thrust.append(thrust_now)
     # Get the drag the rocket is experiencing
     density_now = Formula.density(pressure_now, temperature_now)
     self.data.density.append(density_now)  # Save density
     velocity_before = Formula.vector_addition(self.rocket.get_velocity())
     drag_coefficient = self.rocket.rocket_parts[0].drag_coefficient_part
     drag_now = np.sign(velocity_before) * Formula.drag(
         density_now, velocity_before, self.rocket.get_surface(),
         drag_coefficient)
     self.data.drag.append(abs(drag_now))  # Save current drag
     # Get forces split in x and y direction
     angle_rocket_now = self.rocket.get_angle()
     self.data.angle_rocket.append(
         angle_rocket_now)  # Save current angle of the rocket
     thrust_now_x = Formula.res_x(thrust_now, angle_rocket_now)
     thrust_now_y = Formula.res_y(thrust_now, angle_rocket_now)
     gravity_now_x = Formula.res_x(gravity_now, angle_rocket_now)
     gravity_now_y = Formula.res_y(gravity_now, angle_rocket_now)
     drag_now_x = Formula.res_x(drag_now, angle_rocket_now)
     drag_now_y = Formula.res_y(drag_now, angle_rocket_now)
     # Get current resulting force and resulting forces in x and y direction
     force_res_now_x = Formula.resulting_force(thrust_now_x, gravity_now_x,
                                               drag_now_x)
     force_res_now_y = Formula.resulting_force(thrust_now_y, gravity_now_y,
                                               drag_now_y)
     force_res_now = Formula.vector_addition(
         [force_res_now_x, force_res_now_y])
     self.data.force_res.append(
         force_res_now_x)  # Save current resulting force
     self.data.force_res_split.append([force_res_now_x, force_res_now_y
                                       ])  # Save split resulting force
     # Get current acceleration
     acceleration_x_now = Formula.acceleration(force_res_now_x,
                                               self.rocket.get_mass())
     acceleration_y_now = Formula.acceleration(force_res_now_y,
                                               self.rocket.get_mass())
     acceleration_now = Formula.vector_addition(
         [force_res_now_x, force_res_now_y])
     self.data.acceleration_rocket.append(
         acceleration_x_now)  # Save current acceleration
     self.rocket.set_acceleration(acceleration_x_now, acceleration_y_now)
     # Change mass of the rocket
     if change_prop_mass:
         mass_propellant_now = current_stage.get_mass_propellant(
         ) - current_stage.get_mass_change() * self.time_delta
         if mass_propellant_now < 0:
             self.rocket.decouple()
         else:
             current_stage.set_mass_propellant(mass_propellant_now)
         self.rocket.set_mass()
     self.data.mass_rocket.append(self.rocket.get_mass())
     # Get current velocity
     velocity_x_now = Formula.velocity(self.rocket.get_velocity()[0],
                                       self.time_delta, acceleration_x_now)
     velocity_y_now = Formula.velocity(self.rocket.get_velocity()[1],
                                       self.time_delta, acceleration_y_now)
     velocity_now = Formula.vector_addition(
         [velocity_x_now, velocity_y_now])
     self.rocket.set_velocity(velocity_x_now, velocity_y_now)
     self.data.velocity_rocket.append(
         velocity_x_now)  # Save velocity of the rocket
     # Get the current position
     way_traveled_x_now = Formula.way(self.time_delta, velocity_x_now,
                                      acceleration_x_now)
     pos_x_now = Formula.position(self.rocket.get_pos()[0],
                                  way_traveled_x_now)
     way_traveled_y_now = Formula.way(self.time_delta, velocity_y_now,
                                      acceleration_y_now)
     pos_y_now = Formula.position(self.rocket.get_pos()[1],
                                  way_traveled_y_now)
     self.data.pos_x_rocket.append(
         pos_x_now)  # Save x position of the rocket
     self.data.pos_y_rocket.append(
         pos_y_now)  # Save y position of the rocket
     self.rocket.set_pos(pos_x_now, pos_y_now)
     # Get distance to planet core
     self.distance = Formula.vector_addition([pos_x_now, pos_y_now])
     print height_now
Esempio n. 2
0
 def test_AccelerationFalseNonZero(self):
     self.assertNotEqual(Formula.acceleration(100.0, 10.0), 23.0)
Esempio n. 3
0
 def test_AccelerationPositive(self):
     self.assertEqual(Formula.acceleration(100.0, 10.0), 10.0)
Esempio n. 4
0
 def test_AccelerationNegative(self):
     self.assertEqual(Formula.acceleration(100.0, -10.0), -10.0)
Esempio n. 5
0
 def test_AccelerationZero(self):
     with self.assertRaises(ZeroDivisionError):
         Formula.acceleration(0.0, 0.0)