def test_euler(self):
     """Test used to check that Euler's method works appropiatley.
     """
     planetA = CelestialBody("B",1,1,1,"Planet",1,10000,"blue")
     star = CelestialBody("A",1,1,1,"Star",0,10000,"blue")
     planetB = CelestialBody("B",1,2,1,"Planet",1,10000,"blue")
     planetB.position = np.array([-1.0,0.0])
     planetB.velocity = np.array([0.0,-planetA.velocity[1]])
     system = SolarSystem(3600,1000,Options.NORMAL_RUN,"CelestialObjects")
     system.celestial_bodies = [star,planetA,planetB]
     system.update_initial_acceleration()
     for i in range(100):
         system.update_euler()
     self.assertEqual(0.0,star.acceleration[0])
     self.assertEqual(0.0,star.acceleration[1])
Beispiel #2
0
 def energy_graph_comparisson(updates):
     """Function used to generate a comparison graph between Euler's method and Beeman's
     to show conservation (or not conservation) of energy in both methods
     """
     system = SolarSystem(3600, 10.175 * 10**3, Options.NORMAL_RUN,
                          "CelestialObjects")
     energy_1 = [system.get_energy()]
     system2 = SolarSystem(3600, 10.175 * 10**3, Options.NORMAL_RUN,
                           "CelestialObjects")
     energy_2 = [system2.get_energy()]
     iterate = updates
     iterations = [i * 3600 for i in range(iterate + 1)]
     for i in range(iterate):
         energy_1.append(system.update_beeman())
         energy_2.append(system2.update_euler())
     plt.xlabel('time(s)')
     plt.ylabel('Energy [J]')
     plt.plot(iterations, energy_1, iterations, energy_2)
     plt.show()