Example #1
0
def drawLoadchart(P0, T0, H):
    H = Formula.ftToM(H)

    # loadchart
    plot = Plot.DiscreteGraph(-50, 40, 0.15, 0.40)

    # calculation
    def toAndDrho(tz, h):
        to = Formula.temperature(tz, h)
        ap = Formula.atmosPressure(P0, tz, h)
        f = lambda t: Formula.densOfDryAir(t, ap)
        return (to, f(to) - f(100.0))

    for i in range(0, 8):
        h = Formula.ftToM(i * 3000.0)
        line = [toAndDrho(ot, h) for ot in map(lambda t: t * 10.0, range(-1, 5))]
        plot.append(Plot.Line(line, [1.0, i * 0.08, i * 0.08]))

    for ot in map(lambda t: 15.0 + t * 10.0, range(-2, 3)):
        line = [toAndDrho(ot, h) for h in map(lambda i: Formula.ftToM(i * 3000.0), range(0, 8))]
        plot.append(Plot.Line(line, [0.3, 0.3, 0.8]))

    end_t, end_rho = toAndDrho(T0, H)
    line = (
        [(T0, 0.15)]
        + [toAndDrho(T0, H) for h in map(lambda i: Formula.ftToM(i * 3000.0), range(0, int(h / 3000.0) + 1))]
        + [(end_t, end_rho), (-50.0, end_rho)]
    )
    plot.append(Plot.Line(line, [0.3, 1.0, 0.5]))

    # draw
    graph = plot.make()

    glLineWidth(0.1)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    glPushMatrix()

    glEnable(GL_TEXTURE_2D)
    chars_texture.bind()
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

    glColor3f(0.8, 0.8, 0.8)
    #    graph.drawTitle (chars, "LOAD CHART", 0.1)
    graph.drawLabel(chars, 0.05, "OUTER TEMPERATURE", "BUOYANT FORCE")
    graph.drawAxis2(chars, 0.05, 10.0, "%.0f", 0.05, "%.2f")
    glDisable(GL_TEXTURE_2D)

    graph.draw()
    glColor3f(0.2, 0.2, 0.2)
    graph.drawGrid2(10.0, 0.05)

    glPopMatrix()
Example #2
0
def checkSat(filename):
    formula = Formula.Formula(filename)
    literal = []
    a = DPLL.DPLL(literal, formula.cnfArray)


    return a
Example #3
0
 def get_temperature_now(self, height_rocket, height_layer_below):
     """
     Calculates the temperature at the height the rocket currently is in
     :param height_rocket: Height of the rocket above the planets surface (Double)
     :param height_layer_below: Accumulated height of the atmospheric layers beneath the current layer (Double)
     :return: Temperature at the current height in the layer (Double) [K]
     """
     return Formula.temperature(self.temp_low, self.temp_gradient,
                                height_layer_below, height_rocket)
Example #4
0
 def get_density_now(self, height_rocket, height_layer_below):
     """
     Calculates the density of the medium at the height the rocket is currently in
     :param height_rocket: Height of the rocket above the planets surface (Double)
     :param height_layer_below: Accumulated height of the atmospheric layers beneath the current layer (Double)
     :return: Density of the medium the rocket is in at a given height (Double) [kg/m^3]
     """
     temperature_now = self.get_temperature_now(height_rocket,
                                                height_layer_below)
     pressure_now = self.get_pressure_now(height_rocket, height_layer_below)
     return Formula.density(pressure_now, temperature_now)
Example #5
0
def run_sim(sim_flight, flight_name, max_step, sim_time_step):
    """Runs the simulation for one flight, with all setup and tear down operations
    :param flight: Flight object, that will be simulated (Flight)
    :param flight_name: Name of the flight (String)
    :param max_step: Maximum iterations in on simulation (Integer)
    :param sim_time_step: Time delta for each simulation step (Integer)
    """
    current_step = 0
    sim_flight.data.pos_x_rocket.append(sim_flight.rocket.get_pos()[0])
    sim_flight.data.pos_y_rocket.append(sim_flight.rocket.get_pos()[1])
    sim_flight.data.velocity_rocket.append(sim_flight.rocket.get_velocity()[0])
    sim_flight.data.acceleration_rocket.append(
        sim_flight.rocket.get_acceleration()[0])
    sim_flight.data.mass_rocket.append(sim_flight.rocket.get_mass())
    sim_flight.data.angle_rocket.append(sim_flight.rocket.get_angle())
    sim_flight.data.gravity.append(
        Formula.gravity(sim_flight.planet.get_mass(),
                        sim_flight.rocket.get_mass(),
                        sim_flight.planet.radius_planet))
    sim_flight.data.force_res.append(-1 * sim_flight.data.gravity[0])
    sim_flight.data.temperature.append(
        sim_flight.atmosphere.get_layer(0.0).get_temp_low())
    sim_flight.data.pressure.append(
        sim_flight.atmosphere.get_layer(0.0).get_pressure_low())
    sim_flight.data.density.append(
        sim_flight.atmosphere.get_layer(0).get_density_now(0.0, 0.0))
    print "Simulation starting"
    while sim_flight.get_distance() >= sim_flight.planet.get_radius(
    ) and current_step <= max_step:
        sim_flight.simulate()
        current_step += 1
    #Setting end point data
    sim_flight.data.time.append(sim_flight.data.time[-1] + sim_time_step)
    sim_flight.data.heigth_rocket.append(0.0)
    sim_flight.data.pos_x_rocket.append(sim_flight.planet.get_radius())
    sim_flight.data.pos_y_rocket.append(0.0)
    sim_flight.data.velocity_rocket.append(0.0)
    sim_flight.data.acceleration_rocket.append(0.0)
    sim_flight.data.mass_rocket.append(
        sim_flight.rocket.rocket_parts[-1].get_mass())
    sim_flight.data.angle_rocket.append(0.0)
    sim_flight.data.thrust.append(0.0)
    sim_flight.data.drag.append(0.0)
    sim_flight.data.gravity.append(sim_flight.data.gravity[0])
    sim_flight.data.force_res.append(sim_flight.data.gravity[0])
    sim_flight.data.force_res_split.append([sim_flight.data.gravity[0], 0.0])
    sim_flight.data.temperature.append(sim_flight.data.temperature[0])
    sim_flight.data.pressure.append(sim_flight.data.pressure[0])
    sim_flight.data.density.append(sim_flight.data.density[0])
    print "Simulation ended! Last Step: " + str(current_step)
    if not os.path.exists("./Results_2/{}".format(flight_name)):
        os.makedirs("./Results_2/{}".format(flight_name))
    sim_flight.data.write_csv()
    print "Saved to CSV! In Folder {}".format(flight_name)
Example #6
0
def createTree():
    formula = Formula.Formula()
    formula.str = rawGlobal[0]
    rawGlobal.pop(0)
    if (formula.str in ['*', '+', ')']):
        formula.left = createTree()
        formula.right = createTree()
    elif (formula.str == '-'):
        formula.left = createTree()
        formula.right = None
    else:  #(formula.str.isdigit()):
        formula.left = None
        formula.right = None
    return formula
Example #7
0
 def __init__(self, time_delta, planet, rocket, atmosphere, data):
     """
     Setup of a flight with it's parameters
     :param time_delta: Size of the time step the simulation use
     :param planet: Planet the flight will take place
     :param rocket: Rocket the flight will use
     :param atmosphere: Atmosphere of the planet
     :param data: Data object gained values will be saved in.
     :return:
     """
     self.time_delta = time_delta
     self.planet = planet
     self.rocket = rocket
     self.atmosphere = atmosphere
     self.data = data
     self.distance = Formula.vector_addition(self.rocket.get_pos())
Example #8
0
 def test_TemperatureFalseNonZero(self):
     self.assertNotEqual(Formula.temperature(12.0, 3.0, 0.0, -100), 300.0)
Example #9
0
 def test_TemperatureNegative(self):
     self.assertEqual(Formula.temperature(12.0, -3.0, 0.0, 100.0), -288.0)
Example #10
0
 def test_ThrustZero(self):
     self.assertEqual(Formula.thrust(0.0, 0.0, 0.0, 0.0, 0.0), 0.0)
Example #11
0
 def test_DragPositive(self):
     self.assertEqual(Formula.drag(10.0, 12.0, 15.0, 10.0), 108000.0)
Example #12
0
 def test_DensityNegative(self):
     self.assertEqual(Formula.density(10.0, -10.0), -0.0034832812124127974)
Example #13
0
 def test_VectorAdditionPositive(self):
     self.assertEqual(Formula.vector_addition([14.2, 78.8]),
                      80.06922005365108)
Example #14
0
 def test_GravityFalseNonZero(self):
     self.assertNotEqual(Formula.gravity(10.0, 12.0, 15.0), 10.0)
Example #15
0
 def test_PressureZero(self):
     with self.assertRaises(ZeroDivisionError):
         Formula.pressure(0.0, 0.0, 0.0, 0.0, 0.0)
Example #16
0
 def test_GravityPositve(self):
     self.assertEqual(Formula.gravity(10.0, 12.0, 15.0),
                      3.559509333333333e-10)
Example #17
0
 def test_GravityNegative(self):
     with self.assertRaises(ValueError):
         Formula.gravity(-10.0, 12.0, 15.0)
Example #18
0
 def test_GravityZero(self):
     with self.assertRaises(ZeroDivisionError):
         Formula.gravity(0.0, 0.0, 0.0)
Example #19
0
 def test_DragFalseNonZero(self):
     self.assertNotEqual(Formula.drag(10.0, 12.0, 15.0, 10.0), 15.0)
Example #20
0
 def test_DragNegativeSquare(self):
     self.assertEqual(Formula.drag(10.0, -12.0, 15.0, 10.0), 108000.0)
Example #21
0
 def test_DensityZero(self):
     with self.assertRaises(ZeroDivisionError):
         Formula.density(0.0, 0.0)
Example #22
0
 def __lt__(self, other):
     max_self = max(self.data.pos_rocket)
     max_other = max(other.data.pos_rocket)
     return Formula.vector_addition(max_self) < Formula.vector_addition(
         max_other)
Example #23
0
 def test_DensityPositive(self):
     self.assertEqual(Formula.density(10.0, 10.0), 0.0034832812124127974)
Example #24
0
 def test_VectorAdditionNegative(self):
     self.assertEqual(Formula.vector_addition([-16.4, -62.5]),
                      64.61586492495476)
Example #25
0
 def test_DensityFalseNonZero(self):
     self.assertNotEqual(Formula.density(10.0, 10.0), 33.0)
Example #26
0
 def test_TemperatureZero(self):
     self.assertEqual(Formula.temperature(0.0, 0.0, 0.0, 0.0), 0.0)
Example #27
0
 def toAndDrho(tz, h):
     to = Formula.temperature(tz, h)
     ap = Formula.atmosPressure(P0, tz, h)
     f = lambda t: Formula.densOfDryAir(t, ap)
     return (to, f(to) - f(100.0))
Example #28
0
 def test_TemperaturePositive(self):
     self.assertEqual(Formula.temperature(12.0, 3.0, 0.0, 100.0), 312.0)
Example #29
0
 def testPressureNegative(self):
     self.assertEqual(Formula.pressure(-1013.25, 0.0065, 100.0, 0.0, 24.0),
                      -877.0988519626972)
Example #30
0
 def test_VectorAdditionFalseNonZero(self):
     self.assertNotEqual(Formula.vector_addition([23.2, 29.2]),
                         80.06922005365108)
Example #31
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
Example #32
0
 def testPressureFalseNonZero(self):
     self.assertNotEqual(
         Formula.pressure(-1013.25, 0.0065, 100.0, 0.0, 24.0), -87.098852)