def __init__(self):
     
     
     self.rEarth = vector.Vector(1,0,0)
     self.vEarth = vector.Vector(0,2*math.pi,0)
     self.rMars = vector.Vector(1.5,0,0)
     self.vMars = vector.Vector(0,2*math.pi/math.sqrt(1.5),0)
     self.max_steps = 10000
     self. solver = Solver.RK4(0.01)
     self.physics = Physics.CentralGravity(self.solver,G=4*math.pi**2,M=1)
Exemple #2
0
    def run(self):
        '''Orbits'''
        for v0 in self.v0_list:
            for dt in self.dt_list:
                r = vector.Vector(self.AU, 0, 0)  #starting position in AU
                v = vector.Vector(0, v0, 0)
                earth = Body.GravBody(1, r, v)
                solver = Solver.RK4(dt)
                physics = Physics.CentralGravity(solver, G=4 * math.pi**2,
                                                 M=1)  # M is 1 solar mass
                sim = Simulation.OrbitSim(self.stop, physics, earth)
                time, bodies = sim.get_results()

                y = [b[0].position.y for b in bodies]
                x = [b[0].position.x for b in bodies]
                energy = physics.energy(bodies)
                errors = self.error(energy)

                if v0 == math.pi * 2:
                    plt.figure(1)
                    plt.plot(x, y, '.')
                    plt.title("Circular Orbits of Earth Around Sun")
                    plt.ylabel("Position in y [AU]")
                    plt.xlabel("Position in x [AU]")
                    plt.legend(["dt=0.003", "dt=0.002", "dt=0.001"])

                    plt.figure(2)
                    plt.plot(time, errors)
                    plt.title("Error in Energy vs Time")
                    plt.ylabel("Percent Error")
                    plt.xlabel("Time [Years]")
                    plt.legend(["dt=0.003", "dt=0.002", "dt=0.001"])

                else:
                    plt.figure(3)
                    plt.plot(x, y, '.')
                    plt.title("Elliptical Orbits of Earth Around Sun")
                    plt.ylabel("Position in y [AU]")
                    plt.xlabel("Position in x [AU]")
                    plt.legend(["dt=0.003", "dt=0.002", "dt=0.001"])

                    plt.figure(4)
                    plt.plot(time, errors)
                    plt.title("Error in Energy vs Time")
                    plt.ylabel("Percent Error")
                    plt.xlabel("Time [Years]")
                    plt.legend(["dt=0.003", "dt=0.002", "dt=0.001"])
        """Kepler"""
        r_list = [0.9, 1, 1.1]
        v_list = [2 * math.pi, 2 * 0.9 * math.pi, 2 * 1.1 * math.pi]
        for r in r_list:
            for v in v_list:
                r0 = vector.Vector(r, 0, 0)
                v0 = vector.Vector(0, v, 0)
                earth = Body.GravBody(1, r0, v0)
                solver = Solver.RK4(0.001)
                physics = Physics.CentralGravity(solver, G=4 * math.pi**2,
                                                 M=1)  # M is 1 solar mass
                sim = Simulation.OrbitSim(self.stop, physics, earth)
                time, bodies = sim.get_results()
                a = sim.semimajor_axis()
                p = sim.period()
                plt.figure(5)
                plt.plot(a, p, '.')
        plt.figure(5)
        a = np.arange(0, 2, 0.001)
        p = a**(3. / 2.)
        plt.plot(a, p)
        plt.title("Semi Major Axis vs Period")
        plt.ylabel("Orbital Period [Years]")
        plt.xlabel("Semi Major Axis [AU]")