Example #1
0
class GetMassTest(unittest.TestCase):
    def test_GetMassZero(self):
        self.planet = Planet(0.0, 6000.0, (0.0, 0.0))
        self.assertEqual(self.planet.get_mass(), 0.0)

    def test_GetMassNonZero(self):
        self.planet = Planet(100000000.0, 6000.0, (0.0, 0.0))
        self.assertEqual(self.planet.get_mass(), 100000000.0)

    def test_GetMassFalseNonZero(self):
        self.planet = Planet(6000.0, 100000000.0, (0.0, 0.0))
        self.assertNotEqual(self.planet.get_mass(), 131231.0)
Example #2
0
class GetRadiusTest(unittest.TestCase):
    def test_GetRadiusZero(self):
        self.planet = Planet(0.0, 0.0, (0.0, 0.0))
        self.assertEqual(self.planet.get_radius(), 0.0)

    def test_GetRadiusNonZero(self):
        self.planet = Planet(0.0, 6000.0, (0.0, 0.0))
        self.assertEqual(self.planet.get_radius(), 6000.0)

    def test_GetRadiusFalseNonZero(self):
        self.planet = Planet(0.0, 6000.0, (0.0, 0.0))
        self.assertNotEqual(self.planet.get_radius(), 0.0)
Example #3
0
class GetPosTest(unittest.TestCase):
    def test_GetPosZero(self):
        self.planet = Planet(0.0, 0.0, (0.0, 0.0))
        self.assertEqual(self.planet.get_pos(), (0.0, 0.0))

    def test_GetPosPositive(self):
        self.planet = Planet(0.0, 0.0, (60.0, 40.6))
        self.assertEqual(self.planet.get_pos(), (60.0, 40.6))

    def test_GetPosNegtive(self):
        self.planet = Planet(0.0, 0.0, (-30.3, -20.0))
        self.assertEqual(self.planet.get_pos(), (-30.3, -20.0))

    def test_GetPosFalseNonZero(self):
        self.planet = Planet(0.0, 0.0, (60.2, 40.0))
        self.assertNotEqual(self.planet.get_pos(), (-20.0, 30.0))
Example #4
0
def create_planets():
    n_planets = int(1.1 * (random.random() + 1))

    for i in range(n_planets):
        index = random.randrange(0, len(sprites.planets))
        planet_pos=pos()
        planet=Planet(planet_pos,sprites.planets[index])
        create_ships(planet)
Example #5
0
def firsttime():
    global player_team
    planet=Planet(complex(0,0),sprites.AquaPlanet)
    planetteam=Team()
    for i in range(random.randrange(1,5)):
        ship=AiShip(planet,sprites.GreenShip)
        ship.weapon=weapons[0](ship)
        planetteam.register(ship)

    player=PlayerShip(coords((40,40)))
    player.weapon=weapons[1](player)
    guardian=AiShip(player,sprites.OrangeShip)
    guardian.weapon=weapons[0](guardian)
    player_team=Team(player,guardian)
Example #6
0
def main():
    """
    Declare your planet, atmosphere with its layers, the rocket with its parts, the data object and the time delta here
    and run the simulation
    :return:
    """
    # Setup here
    sim_max_step = 100000  # Maximum time steps the simulation should run
    sim_time_step = 0.1  # [s] Timestep the simulation uses
    earth = Planet(pos_planet=[0.0, 0.0],
                   mass_planet=5.974e+24,
                   radius_planet=12756.32 / 2.0 * 1000)
    earth_radius = earth.get_radius()
    troposphere = Layer(pressure_low=101325.0,
                        width_layer=18000.0,
                        temp_gradient=-0.0065,
                        temp_low=288.15)
    stratosphere = Layer(pressure_low=16901.37,
                         width_layer=32000.0,
                         temp_gradient=0.0031875,
                         temp_low=171.15)
    mesosphere = Layer(pressure_low=1.02,
                       width_layer=30000.0,
                       temp_gradient=-0.003333,
                       temp_low=273.15)
    thermosphere = Layer(pressure_low=0.04,
                         width_layer=420000.0,
                         temp_gradient=-0.000405,
                         temp_low=173.15)
    exosphere = Layer(pressure_low=0.0,
                      width_layer=9999999999.0,
                      temp_gradient=0.0,
                      temp_low=3.0)
    earth_atmosphere = Atmosphere()
    earth_atmosphere.add_layer(troposphere)
    earth_atmosphere.add_layer(stratosphere)
    earth_atmosphere.add_layer(mesosphere)
    earth_atmosphere.add_layer(thermosphere)
    earth_atmosphere.add_layer(exosphere)
    # Set maximum propellant mass
    A150_mass_propellant = 484.8076
    # Calculate A150 one tank:
    sim_flight_name = "A150_OneTank"
    sim_data = Data(
        data_file="./Results_2/{}/Results_Data.csv".format(sim_flight_name))
    sim_data.name = "Einstufig"
    A150_payload = 0.0  # kg moegliche Nutzlast
    A150_nose_cone = RocketPart(mass_part=7.0 + 2.31336 + A150_payload,
                                surface_part=0.1140,
                                drag_coefficient_part=0.27)
    A150_liquid_tank = Tank(mass_part=116.1216,
                            surface_part=0.0,
                            drag_coefficient_part=0.0,
                            mass_propellant=A150_mass_propellant,
                            mass_change_tank=9.394,
                            velocity_exhaust_tank=1417.32,
                            surface_nozzle=0.0275,
                            pressure_nozzle=101325.0)
    A150 = Rocket(pos=[earth_radius, 0.0],
                  velocity=[0.0, 0.0],
                  acceleration=[0.0, 0.0])
    A150_booster = Tank(mass_part=28.1232,
                        surface_part=0.0,
                        drag_coefficient_part=0.0,
                        mass_propellant=117.6074,
                        mass_change_tank=47.1733,
                        velocity_exhaust_tank=1747.6074,
                        surface_nozzle=0.0434,
                        pressure_nozzle=101325.0)
    A150.append_part(A150_nose_cone)
    A150.append_part(A150_liquid_tank)
    A150.append_part(A150_booster)
    A150.set_mass()
    A150.set_surface()
    sim_flight = Flight(sim_time_step, earth, A150, earth_atmosphere, sim_data)
    # Running the simulation
    run_sim(sim_flight, sim_flight_name, sim_max_step, sim_time_step)

    # Calculate A150 two tanks 1
    sim_flight_name = "A150_RefTankA"
    sim_data = Data(
        data_file="./Results_2/{}/Results_Data.csv".format(sim_flight_name))
    sim_data.name = "Stufe 1 leer"
    A150_payload = 0.0  # kg moegliche Nutzlast
    A150_nose_cone = RocketPart(mass_part=7.0 + 2.31336 + A150_payload,
                                surface_part=0.1140,
                                drag_coefficient_part=0.27)
    A150_liquid_tank_one = Tank(mass_part=116.1216,
                                surface_part=0.0,
                                drag_coefficient_part=0.0,
                                mass_propellant=A150_mass_propellant,
                                mass_change_tank=9.394,
                                velocity_exhaust_tank=1417.32,
                                surface_nozzle=0.0275,
                                pressure_nozzle=101325.0)
    A150_liquid_tank_two = Tank(mass_part=116.1216,
                                surface_part=0.0,
                                drag_coefficient_part=0.0,
                                mass_propellant=0,
                                mass_change_tank=9.394,
                                velocity_exhaust_tank=1417.32,
                                surface_nozzle=0.0275,
                                pressure_nozzle=101325.0)
    A150 = Rocket(pos=[earth_radius, 0.0],
                  velocity=[0.0, 0.0],
                  acceleration=[0.0, 0.0])
    A150_booster = Tank(mass_part=28.1232,
                        surface_part=0.0,
                        drag_coefficient_part=0.0,
                        mass_propellant=117.6074,
                        mass_change_tank=47.1733,
                        velocity_exhaust_tank=1747.6074,
                        surface_nozzle=0.0434,
                        pressure_nozzle=101325.0)
    A150.append_part(A150_nose_cone)
    A150.append_part(A150_liquid_tank_one)
    A150.append_part(A150_liquid_tank_two)
    A150.append_part(A150_booster)
    A150.set_mass()
    A150.set_surface()
    sim_flight_a = Flight(sim_time_step, earth, A150, earth_atmosphere,
                          sim_data)
    # Running the simulation
    run_sim(sim_flight_a, sim_flight_name, sim_max_step, sim_time_step)

    # Calculate A150 two tanks 1
    sim_flight_name = "A150_RefTankB"
    sim_data = Data(
        data_file="./Results_2/{}/Results_Data.csv".format(sim_flight_name))
    sim_data.name = "Stufe 2 leer"
    A150_payload = 0.0  # kg moegliche Nutzlast
    A150_nose_cone = RocketPart(mass_part=7.0 + 2.31336 + A150_payload,
                                surface_part=0.1140,
                                drag_coefficient_part=0.27)
    A150_liquid_tank_one = Tank(mass_part=116.1216,
                                surface_part=0.0,
                                drag_coefficient_part=0.0,
                                mass_propellant=0,
                                mass_change_tank=9.394,
                                velocity_exhaust_tank=1417.32,
                                surface_nozzle=0.0275,
                                pressure_nozzle=101325.0)
    A150_liquid_tank_two = Tank(mass_part=116.1216,
                                surface_part=0.0,
                                drag_coefficient_part=0.0,
                                mass_propellant=A150_mass_propellant,
                                mass_change_tank=9.394,
                                velocity_exhaust_tank=1417.32,
                                surface_nozzle=0.0275,
                                pressure_nozzle=101325.0)
    A150 = Rocket(pos=[earth_radius, 0.0],
                  velocity=[0.0, 0.0],
                  acceleration=[0.0, 0.0])
    A150_booster = Tank(mass_part=28.1232,
                        surface_part=0.0,
                        drag_coefficient_part=0.0,
                        mass_propellant=117.6074,
                        mass_change_tank=47.1733,
                        velocity_exhaust_tank=1747.6074,
                        surface_nozzle=0.0434,
                        pressure_nozzle=101325.0)
    A150.append_part(A150_nose_cone)
    A150.append_part(A150_liquid_tank_one)
    A150.append_part(A150_liquid_tank_two)
    A150.append_part(A150_booster)
    A150.set_mass()
    A150.set_surface()
    sim_flight_b = Flight(sim_time_step, earth, A150, earth_atmosphere,
                          sim_data)

    # Running the simulation
    run_sim(sim_flight_b, sim_flight_name, sim_max_step, sim_time_step)

    # Searching for optimal tank setup
    divisor = 2
    count = 0
    sim_opt_max_step = 40

    propellant_step = A150_mass_propellant / sim_opt_max_step
    while count < sim_opt_max_step:
        sim_flight_name = "A150_TankSetup_{0:03d}".format(count)
        sim_data = Data(data_file="./Results_2/{}/Results_Data.csv".format(
            sim_flight_name))
        A150_mass_propellant_tank_one = propellant_step * count
        A150_mass_propellant_tank_two = A150_mass_propellant - propellant_step * count
        sim_data.name = "Stufe 1: {0:.2f} kg Stufe 2: {1:.2f} kg".format(
            A150_mass_propellant_tank_two, A150_mass_propellant_tank_one)
        A150 = Rocket(pos=[earth_radius, 0.0],
                      velocity=[0.0, 0.0],
                      acceleration=[0.0, 0.0])
        A150_liquid_tank_one_split = Tank(
            mass_part=116.1216,
            surface_part=0.0,
            drag_coefficient_part=0.0,
            mass_propellant=A150_mass_propellant_tank_one,
            mass_change_tank=9.394,
            velocity_exhaust_tank=1417.32,
            surface_nozzle=0.0275,
            pressure_nozzle=101325.0)
        A150_liquid_tank_two_split = Tank(
            mass_part=116.1216,
            surface_part=0.0,
            drag_coefficient_part=0.0,
            mass_propellant=A150_mass_propellant_tank_two,
            mass_change_tank=9.394,
            velocity_exhaust_tank=1417.32,
            surface_nozzle=0.0275,
            pressure_nozzle=101325.0)
        A150_booster = Tank(mass_part=28.1232,
                            surface_part=0.0,
                            drag_coefficient_part=0.0,
                            mass_propellant=117.6074,
                            mass_change_tank=47.1733,
                            velocity_exhaust_tank=1747.6074,
                            surface_nozzle=0.0434,
                            pressure_nozzle=101325.0)
        A150.append_part(A150_nose_cone)
        A150.append_part(A150_liquid_tank_one_split)
        A150.append_part(A150_liquid_tank_two_split)
        A150.append_part(A150_booster)
        A150.set_mass()
        A150.set_surface()
        sim_flight_p = Flight(sim_time_step, earth, A150, earth_atmosphere,
                              sim_data)
        # Running the simulation
        run_sim(sim_flight_p, sim_flight_name, sim_max_step, sim_time_step)

        count += 1

    # Calculate A150 one tank, no booster:
    sim_flight_name = "A150_NoBooster"
    sim_data = Data(
        data_file="./Results_2/{}/Results_Data.csv".format(sim_flight_name))
    sim_data.name = "Einstufig ohne Booster"
    A150_payload = 0.0  # kg moegliche Nutzlast
    A150_nose_cone = RocketPart(mass_part=7.0 + 2.31336 + A150_payload,
                                surface_part=0.1140,
                                drag_coefficient_part=0.27)
    A150_liquid_tank = Tank(mass_part=116.1216,
                            surface_part=0.0,
                            drag_coefficient_part=0.0,
                            mass_propellant=A150_mass_propellant,
                            mass_change_tank=9.394,
                            velocity_exhaust_tank=1417.32,
                            surface_nozzle=0.0275,
                            pressure_nozzle=101325.0)
    A150 = Rocket(pos=[earth_radius, 0.0],
                  velocity=[0.0, 0.0],
                  acceleration=[0.0, 0.0])
    A150.append_part(A150_nose_cone)
    A150.append_part(A150_liquid_tank)
    A150.set_mass()
    A150.set_surface()
    sim_flight_nb = Flight(sim_time_step, earth, A150, earth_atmosphere,
                           sim_data)
    # Running the simulation
    run_sim(sim_flight_nb, sim_flight_name, sim_max_step, sim_time_step)

    print "Optimization has ended after {} iterations, Results available".format(
        count - 1)
Example #7
0
 def __init__(self,
              name="Sol system",
              size=500,
              max_planets=3,
              gamma=20,
              scale=1,
              max_time=100,
              symmetry=0):
     self.name = name
     self.size = size
     self.max_planets = max_planets
     self.planets = []
     self.gamma = gamma
     self.scale = scale
     self.max_time = max_time
     self.collisions = 0
     if not symmetry:
         # TODO add frame of reference
         self.add_planets(
             Planet(name="Sôl", mass=2500, color="yellow", fix=False),
             Planet(name="Mercury",
                    mass=1.5,
                    velocity=[0, 20],
                    position=[100, 0],
                    color="grey"),
             Planet(name="Venus",
                    mass=1.85,
                    velocity=[0, -15],
                    position=[-150, 0]),
             Planet(name="Terra",
                    mass=2,
                    velocity=[-10, 0],
                    position=[0, 290],
                    color="blue"),
             Planet(name="Mars",
                    mass=1.2,
                    velocity=[15, 0],
                    position=[0, -290],
                    color="orange"),
             Planet(name="Iuppiter",
                    mass=200,
                    velocity=[5, -5],
                    position=[-300, -290],
                    color="brown"),
             Planet(name="Saturnus",
                    mass=150,
                    velocity=[-5, 5],
                    position=[300, 290],
                    color="Yellow",
                    ring=25),
             Comet("Halley's Comet",
                   mass=0,
                   velocity=[4, 4],
                   position=[300, -290],
                   color="light blue"),
             Planet(name="Saturnus",
                    mass=150,
                    velocity=[0, 20],
                    position=[500, -500],
                    color="Yellow"))
     else:
         self.add_planets(
             Planet(name="Sol", mass=1000, color="yellow", fix=True))
         for i in range(max_planets - 1):
             self.add_planets(
                 Planet(name=i,
                        mass=0,
                        velocity=self.point_velocity(
                            sqrt((10 * gamma * self.planets[0].mass) /
                                 symmetry), i, max_planets - 1),
                        position=self.point(symmetry, i, max_planets - 1),
                        color="white"))
def main():
    #delta_t (in Days) for simulations
    delta_t = np.longdouble(1.0) / (24.0 * 60.0 * 60.0)

    ship = Craft(delta_t, x=35786, y=1, z=1, v_x=0, v_y=4.5, v_z=0, mass=12)

    #Initialize Simulation
    simulationStart = Time('2015-09-10T00:00:00')
    simulationEnd = Time('2015-10-10T00:00:00')

    if not os.path.isfile('de430.bsp'):
        raise ValueError('de430.bsp was not found!')
    kernel = SPK.open('de430.bsp')
    #marsKernel = SPK.open('mar097.bsp')

    if simulationType == 1:
        planets = [  #Planet(kernel, 0, 0, np.longdouble(1.989*10**30)),
            Planet(kernel, 199, 199, np.longdouble(3.285 * 10**23)),
            Planet(kernel, 399, 399, np.longdouble(5.972 * 10**24))
        ]

    if simulationType == 2:
        planets = [  #Planet(kernel, 10, 10, np.longdouble(1.989*10**30)),
            Planet(kernel, 299, 299, np.longdouble(4.867 * 10**24)),
            Planet(kernel, 399, 399, np.longdouble(5.972 * 10**24))
        ]

    if simulationType == 3:
        planets = [  #Planet(kernel, 10, 10, np.longdouble(1.989*10**30)),
            Planet(kernel, 399, 399, np.longdouble(5.972 * 10**24)),
            Planet(kernel, 301, 399, np.longdouble(7.34767309 * 10**22))
        ]

    if simulationType == 4:
        planets = [  #Planet(kernel, 10, 10, np.longdouble(1.989*10**30)),
            Planet(kernel, 399, 399, np.longdouble(5.972 * 10**24)),
            Planet(kernel, 499, 499, np.longdouble(6.39 * 10**23))
        ]

    if simulationType == 5:
        planets = [  #Planet(kernel, 10, 10, np.longdouble(1.989*10**30)),
            Planet(kernel, 399, 399, np.longdouble(5.972 * 10**24)),
            Planet(kernel, 399, 399, np.longdouble(1.898 * 10**27))
        ]

    if simulationType == 6:
        planets = [  #Planet(kernel, 10, 10, np.longdouble(1.989*10**30)),
            Planet(kernel, 399, 399, np.longdouble(5.972 * 10**24)),
            Planet(kernel, 399, 399, np.longdouble(1.024 * 10**26))
        ]

    if simulationType == 7:
        planets = [  #Planet(kernel, 10, 10, np.longdouble(1.989*10**30)),
            Planet(kernel, 399, 399, np.longdouble(5.972 * 10**24)),
            Planet(kernel, 399, 399, np.longdouble(5.683 * 10**26))
        ]

    if simulationType == 8:
        planets = [  #Planet(kernel, 10, 10, np.longdouble(1.989*10**30)),
            Planet(kernel, 399, 399, np.longdouble(5.972 * 10**24)),
            Planet(kernel, 399, 399, np.longdouble(8.681 * 10**25))
        ]

    #else
    #planets = [Planet(kernel, 399, 399, np.longdouble(5972198600000000000000000)), Planet(null)]

    runSimulation(simulationStart.jd, simulationEnd.jd, delta_t, ship, planets)
    plot(ship, [planets[1]])
Example #9
0
 def test_GetMassZero(self):
     self.planet = Planet(0.0, 6000.0, (0.0, 0.0))
     self.assertEqual(self.planet.get_mass(), 0.0)
Example #10
0
 def test_GetPosFalseNonZero(self):
     self.planet = Planet(0.0, 0.0, (60.2, 40.0))
     self.assertNotEqual(self.planet.get_pos(), (-20.0, 30.0))
Example #11
0
 def test_GetPosNegtive(self):
     self.planet = Planet(0.0, 0.0, (-30.3, -20.0))
     self.assertEqual(self.planet.get_pos(), (-30.3, -20.0))
Example #12
0
 def test_GetPosPositive(self):
     self.planet = Planet(0.0, 0.0, (60.0, 40.6))
     self.assertEqual(self.planet.get_pos(), (60.0, 40.6))
Example #13
0
 def test_GetPosZero(self):
     self.planet = Planet(0.0, 0.0, (0.0, 0.0))
     self.assertEqual(self.planet.get_pos(), (0.0, 0.0))
Example #14
0
 def test_GetRadiusFalseNonZero(self):
     self.planet = Planet(0.0, 6000.0, (0.0, 0.0))
     self.assertNotEqual(self.planet.get_radius(), 0.0)
Example #15
0
 def test_GetRadiusZero(self):
     self.planet = Planet(0.0, 0.0, (0.0, 0.0))
     self.assertEqual(self.planet.get_radius(), 0.0)
Example #16
0
 def test_GetMassFalseNonZero(self):
     self.planet = Planet(6000.0, 100000000.0, (0.0, 0.0))
     self.assertNotEqual(self.planet.get_mass(), 131231.0)