def __init__(self): with open("/etc/omnik-pvoutput/config.ini") as f: configFile = f.read() config = ConfigParser.RawConfigParser(allow_no_value=True) config.readfp(io.BytesIO(configFile)) self.solarSystems = {} for section in config.sections(): solarSystem = SolarSystem(config, section) self.solarSystems[solarSystem.getSerialNumber()] = solarSystem
def Ex3h(n, T, planet_names, save_plot=False): """ n : Integration points T : Time to run the simulation. planet_names : Import of wanted planets (and/or Sun) """ #n = int(1e5) planets = SolarSystem(planet_names) Np = len(planets.mass) # Nr. of planets init_pos = planets.initPos init_vel = planets.initVel masses = planets.mass # Using the class solver = Solver(masses, init_pos, init_vel, Np, T, n) pos_V, vel_V, t_V = solver.solve(method="Verlet", SunInMotion=True) # Plot orbits for i in range(Np): plt.plot(pos_V[0, :, i], pos_V[1, :, i], label="%s" % planet_names[i]) plt.plot(pos_V[0, 0, i], pos_V[1, 0, i], "kx", label="Init. pos. %s" % planet_names[i]) # Make figure Figure_noSunPlot(title="Solar system. Over %g years \n Verlet method" % (T)) if save_plot == True: plt.savefig("Results/3h_solar_system_nrPlanets_%g.png" % Np) plt.show()
def __init__(self): self.solar_systems = [] names = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] for name in names: x = random.randint(0, 10) y = random.randint(0, 10) coord = [x, y] self.solar_systems.append(SolarSystem(name, coord, random.choice(list(TechLevel)), random.choice(list(Resources))))
def __init__(self, parent=None): max_slider_days = 5000 QtWidgets.QWidget.__init__(self, parent) startButton = QtWidgets.QPushButton('Start') startButton.resize(100, 30) startButton.clicked.connect(self.startButtonEvent) stopButton = QtWidgets.QPushButton('Stop') stopButton.resize(50, 60) stopButton.clicked.connect(self.stopButtonEvent) self.solar_system = SolarSystem() self.lcd = QtWidgets.QLCDNumber(7) h_layout = QtWidgets.QHBoxLayout() h_layout.addWidget(startButton) h_layout.addWidget(stopButton) h_layout.addWidget(self.lcd) buttons_box = QtWidgets.QWidget() buttons_box.setLayout(h_layout) buttons_box.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) vLayout = QtWidgets.QVBoxLayout() vLayout.addWidget(buttons_box) self.slider = QtWidgets.QSlider(QtCore.Qt.Horizontal) self.slider.setRange(0, max_slider_days) self.slider.setValue(0) self.slider.valueChanged.connect(self.slider_value_changed) vLayout.addWidget(self.slider) self.scale_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal) self.scale_slider.setRange(500000, 20000000) self.scale_slider.setValue(7479894.5) self.scale_slider.valueChanged.connect(self.scale_slider_value_changed) vLayout.addWidget(self.scale_slider) self.tick_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal) self.tick_slider.setRange(1, 200) self.tick_slider.setValue(10) self.tick_slider.valueChanged.connect(self.tick_slider_value_changed) vLayout.addWidget(self.tick_slider) vLayout.addWidget(self.solar_system) vLayout.setStretch(0, 0) self.setLayout(vLayout) self.timer = QtCore.QTimer() self.timer.timeout.connect(self.increment_day) self.setWindowTitle('SpaceByte') self.setWindowIcon(QtGui.QIcon('sun.gif'))
def test_system(theta: float) -> int: rocket = Rocket.saturn_v( Stage(123000 - 36135, 123000, last_dur, 165 * 1000000 / last_dur)) rocket.velocity = np.array((-460, 0)) rocket.theta = 2 * np.pi * theta / 360 earth = Body(5.97e24, 12756e3 / 2, (0, 0), (0, 0), (0.0, 0.0, 7.292115053925690e-05)) ss = SolarSystem(dt / 10.0, tol) ss.add_body(earth) ss.add_body(rocket) t = 0 while rocket.dist(earth) < earth.radius * 1.1: try: ss.step(dt) t += dt if t >= 56540: return 0 # orbit except ZeroDivisionError: return -1 # crash into earth return 1 # escape from earth
def Ex3g(n, T, m=1, save_plot=False): """ n : Integration points T : Time to run the simulation. m : Factor to change Jupiter mass """ planet_names = ["Earth", "Jupiter"] planets = SolarSystem(planet_names) Np = len(planets.mass) # Nr. of planets init_pos = planets.initPos init_vel = planets.initVel masses = planets.mass for M in range(len(m)): masses_ = [masses[0], masses[1] * m[M]] # Using the class solver2 = Solver(masses_, init_pos, init_vel, Np, T, n) pos_V, vel_V, t_V = solver2.solve(method="Verlet") # Plot orbits for i in range(Np): plt.plot(pos_V[0, :, i], pos_V[1, :, i], label="%s" % planet_names[i]) plt.plot(pos_V[0, 0, i], pos_V[1, 0, i], "kx", label="Init. pos. %s" % planet_names[i]) # Make figure Figure( title="Solar system. Over %g years \n Verlet method. $M_J$=$M_J$*%g" % (T, m[M])) if save_plot == True: plt.savefig("Results/3g_E_J_Sun_system_m%g.png" % m[M]) plt.show()
def test_system(theta: float) -> int: earth = Body(5.97e24, 12756e3 / 2, (0, 0), (0, 0), (0.0, 0.0, 7.292115053925690e-05)) rocket = Rocket.saturn_v(Stage(13500, 13500 + 36135, 0, 0)) rocket.theta = 2 * np.pi * theta / 360 rocket.velocity = np.array((-earth.speed_at_surface(), 0.0)) ss = SolarSystem(dt / 10.0, 1e-14) ss.add_body(earth) ss.add_body(rocket) while True: try: ss.step(dt) if rocket.t >= 25000: return 0 # orbit except ValueError: # crash into earth # probably not the best metric to use, but simple and it works pretty well if rocket.t < 3000: return -1 else: return 1
for file in files: if file.lower() == 'sectors.yaml': sectorFolders.append(root + '\\' + file) if file.lower() == 'playfield.yaml': playfieldFolders.append(root + '\\' + file) # Playfield.reportHeader() # for item in playfieldFolders: # parsePlanet(item) inp = 'F:\\games\\Steam\\steamapps\\common\\Empyrion - Galactic Survival\\Content\\Scenarios\\BanditsGalaxy\\Sectors\\Sectors.yaml' oup = 'F:\\games\\Steam\\steamapps\\common\\Empyrion - Galactic Survival\\Saves\\Games\\NewGame\\Sectors\\Sectors.yaml' # inp ='F:\\games\\Steam\\steamapps\\common\\Empyrion - Galactic Survival\\Content\\Scenarios\\BanditsGalaxy\\Sectors\\sectors.yaml' # oup = 'F:\\games\\Steam\\steamapps\\common\\Empyrion - Galactic Survival\\Saves\\Games\\NewGame\\Sectors\\sectors.yaml' sector = SolarSystem.parseSector(inp, planets) print(len(sector.sectors), 'planets') sector.makeMiniSystems(5) sector.write(oup) # for item in sectorFolders: # sector = SolarSystem.parseSector(item, planets) # print(len(sector.sectors), 'planets') # # # move the planets around based on their difficulity # # make several rings with 1-2 transitions between each ring # # sector.makeWeb() # # worldName = item.split('\\')[-3] # sector.write(worldName+'-Sectors.yaml')
satuP = np.array([-2.580001580880525e6, -1.505400238426360e9, 2.626833272809756e7])*1e3 satuV = np.array([9.138489314514731, -5.582877461640032e-2, -3.621731460402276e-1])*1e3 satuMass = 5.6834e26 uranP = np.array([2.654345091181264e9, 1.348937047690948e9, -2.935949538735342e7])*1e3 uranV = np.array([-3.126735892308242, 5.744067162096605, 6.201136228633741e-2])*1e3 uranMass = 86.813e24 neptP = np.array([4.288847528038050e9, -1.291632934435426e9, -7.224898808883280e7])*1e3 neptV = np.array([1.540804358197982, 5.228231198331880, -1.438864540842557e-1])*1e3 neptMass = 102.413e24 sunP = np.array([0,0,0])*1e3 sunV = np.array([0,0,0])*1e3 sunMass = 1988500e24 Neptune = Particle(neptP,neptV,np.array([0,0,0]),'Neptune',neptMass) Uranus = Particle(uranP,uranV,np.array([0,0,0]),'Uranus',uranMass) Saturn = Particle(satuP,satuV,np.array([0,0,0]),'Saturn',satuMass) Jupiter = Particle(jupiP,jupiV,np.array([0,0,0]),'Jupiter',jupiMass) Mars = Particle(marsP,marsV,np.array([0,0,0]),'Mars',marsMass) Moon = Particle(moonP,moonV,np.array([0,0,0]),'Moon',moonMass) Venus = Particle(venuP,venuV,np.array([0,0,0]),'Venus',venuMass) Earth = Particle(eartP,eartV,np.array([0,0,0]),'Earth',eartMass) Mercury = Particle(mercP,mercV,np.array([0,0,0]),'Mercury',mercMass) Sun = Particle(np.array([0,0,0]),np.array([0,0,0]),np.array([0,0,0]),'Sun',sunMass) # Ordered this way because the colours are nice Planets = [Earth,Sun,Venus,Mars,Mercury,Jupiter,Moon,Saturn,Uranus,Neptune] run = SolarSystem(Planets,12000,0,31536,3) run.calculation()
def add(self, sysID): self.map[sysID] = SolarSystem(sysID) return self
import time import numpy as np from matplotlib import animation from matplotlib.collections import PatchCollection from matplotlib.patches import Circle from Body import Body, G from SolarSystem import SolarSystem import matplotlib.pyplot as plot dt = 24 * 60 * 60 * 1. / 60 ss = SolarSystem(dt / 10.0, 1e-10) # Some calculations to keep barycenter roughly at center m = 5.97e24 # Earth mass n = 0.073e24 # Moon mass d = 4.84e8 # Earth moon distance re = d * n / (m + n) # Earth barycenter distance rm = d - re # Moon barycenter distance vm = np.sqrt(G * (m + n) / rm) # Moon orbital velocity around barycenter ve = vm * n / m # Earth orbital velocity around barycenter moon = Body(n, 3475e3 / 2, (rm, 0.0), (0.0, vm), (0.0, 0.0, 2.6617e-06)) earth = Body(m, 12756e3 / 2, (-re, 0.0), (0.0, -ve), (0.0, 0.0, 7.29212e-05)) # Earth moon ss.add_body(moon) # The Moon ss.add_body(earth) # The Earth
import numpy as np from matplotlib import animation from matplotlib.collections import PatchCollection from matplotlib.patches import Circle from Body import Body, G from Rocket import Rocket from SolarSystem import SolarSystem import matplotlib.pyplot as plot from Stage import Stage dt = 24 * 60 * 1. / 60 ss = SolarSystem(dt / 10.0, 1e-10) # Some calculations to keep barycenter roughly at center m = 5.97e24 # Earth mass n = 0.073e24 # Moon mass d = 4.84e8 # Earth moon distance re = d * n / (m + n) # Earth barycenter distance rm = d - re # Moon barycenter distance vm = np.sqrt(G * (m + n) / rm) # Moon orbital velocity around barycenter ve = vm * n / m # Earth orbital velocity around barycenter moon = Body(n, 3475e3 / 2, (rm, 0.0), (0.0, vm), (0.0, 0.0, 2.6617e-06)) earth = Body(m, 12756e3 / 2, (-re, 0.0), (0.0, -ve), (0.0, 0.0, 7.29212e-05)) burn_angle = 2 * np.pi * 225 / 360 # 225 for free return trajectory, 224 for crash into moon
plt.plot(pos_V[0, time_index, 0], pos_V[1, time_index, 0], 'mx', label='Last min.') plt.title('The orbit of Mercury for 100 years', fontsize=15) Figure(title='The orbit of Mercury for 100 years') if save_plot == True: plt.savefig('Results/Mercury/new4_T[%g]_n[%g]_plot.png' % (T, n)) plt.show() planet_names_ = ['Earth', 'Jupiter'] planets_ = SolarSystem(planet_names_) yr = 365 * 24 * 60 * 60 # [s] M_Sun = 1.989 * 10**30 # [kg] M_E = planets_.mass[0] # [kg] M_J = planets_.mass[1] # [kg] AU = 149597870691 # [m] GMJ = 4 * np.pi * (M_J / M_Sun) # [AU^3/yr^2] (G*M_J, Astro units,) GM = 4 * np.pi**2 # [AU^3/yr^2] ( G*M_sun, Astro units,) n = int(1e4) # integration points if __name__ == '__main__':
def main(): pygame.init() screen = pygame.display.set_mode(size) mediumFont = pygame.font.Font("OpenSans-Regular.ttf", 28) largeFont = pygame.font.Font("OpenSans-Regular.ttf", 40) solarSystem = None days = 0 newDraw = True while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() screen.fill(BodyColor.Black.value) typeButtons = {} offset = 1 for sType in StarType: typeButtons[sType] = pygame.Rect(offset *(width / 7), (height * 0.9), width / 8, 50) buttonText = mediumFont.render(sType.name, True, BodyColor.Black.value) buttonRect = buttonText.get_rect() buttonRect.center = typeButtons[sType].center pygame.draw.rect(screen,BodyColor.White.value, typeButtons[sType]) screen.blit(buttonText, buttonRect) offset += 1 #create a border to deliniate the buttons lineStart = (0, height*0.87) lineEnd = (width, height*0.87) pygame.draw.line(screen,BodyColor.White.value, lineStart, lineEnd) # Check if button is clicked click, _, _ = pygame.mouse.get_pressed() if click == 1: mouse = pygame.mouse.get_pos() for sType in StarType: if typeButtons[sType].collidepoint(mouse): if solarSystem: days = 0 del solarSystem newDraw = True solarSystem = SolarSystem(sType) solarSystem.autoPopulate() # Let user choose a starting Star. if solarSystem is None: # Draw title title = largeFont.render("Select a Star to Begin", True, BodyColor.White.value) titleRect = title.get_rect() titleRect.center = ((width / 2), 50) screen.blit(title, titleRect) else: title = largeFont.render(f"Solar System in motion... T+{days} days", True, BodyColor.White.value) titleRect = title.get_rect() titleRect.center = ((width / 2), 50) screen.blit(title, titleRect) solarSystem.update() days = days + 1 drawBodies(solarSystem, screen, newDraw) newDraw = False pygame.display.update() pygame.display.flip() pygame.time.delay(10)
def main(): p1 = Planet(0, 0, 0.0, 0, 1, 'sun') p2 = Planet(1, 0, 0, 2 * np.pi, 3e-6, 'earth') # p3 = Planet(5.2,0,0,2*np.pi/np.sqrt(5.2),1,'jupiter') # p4 = Planet(1.52, 0,0, 2*np.pi/np.sqrt(1.52), 3.3e-7,'mars') # p5 = Planet(0.72, 0,0, 2*np.pi/np.sqrt(0.72), 2.4e-6,'Venus') # p6 = Planet (9.54, 0,0, 2*np.pi/np.sqrt(9.54), 2.75e-4,'Saturn') # p7 = Planet(0.3075 , 0,0, 12.44, 1.65e-7,'Mercury') # p8 = Planet(19.19, 0,0, 2*np.pi/np.sqrt(19.19) , 4.4e-5,'Uranus') # p9 = Planet(30.06, 0,0, 2*np.pi/np.sqrt(30.06), 5.15e-5,'Neptun') # p10 = Planet(39.53, 0,0, 2*np.pi/np.sqrt(39.53), 6.55e-9,'Pluto') S = SolarSystem() S.add_planet(p2) # S.add_planet(p3) # S.add_planet(p3) # S.add_planet(p4) # S.add_planet(p5) # S.add_planet(p6) # S.add_planet(p7) # S.add_planet(p8) # S.add_planet(p9) # S.add_planet(p10) # S.add_planet(p1) x_earth, y_earth = S.euler(p2, 0.0001, 1E5) x_sun, y_sun = S.euler(p1, 0.0001, 1E5) # x_jupiter,y_jupiter = S.Velocity_verlet(p3,0.001,1E4) # x_mars,y_mars = S.Velocity_verlet(p4,0.01,1E4) # x_Venus,y_Venus = S.Velocity_verlet(p5,0.01,1E4) # x_Saturn,y_Saturn = S.Velocity_verlet(p6,0.01,1E4) # x_Mercury,y_Mercury = S.Velocity_verlet(p7,0.01,1E5) # x_Uranus,y_Uranus = S.Velocity_verlet(p8,0.01,1E5) # x_Neptun,y_Neptun = S.Velocity_verlet(p9,0.01,1E5) # x_Pluto,y_Pluto = S.Velocity_verlet(p10,0.01,1E5) plt.plot(x_earth, y_earth, label='Earth') # plt.plot(x_sun,y_sun,label = 'Sun') # plt.plot(x_jupiter,y_jupiter,label = 'Jupiter') # plt.plot(x_mars,y_mars,label ="Mars") # plt.plot(x_Venus,y_Venus,label ="Venus") # plt.plot(x_Saturn,y_Saturn,label='Saturn') # plt.plot(x_Mercury,y_Mercury,label='Mercury') # plt.plot(x_Uranus,y_Uranus,label='Uranus') # plt.plot(x_Neptun,y_Neptun ,label='Neptun') # plt.plot(x_Pluto,y_Pluto ,label='Pluto') # plt.legend() # plt.show() plt.plot(x_earth, y_earth) csfont = {'fontname': 'Times New Roman'} plt.rcParams.update({'font.size': 18}) plt.xlabel('x[AU]', **csfont) plt.ylabel('y[AU]', **csfont) # plt.title('Earth-Sun System,Euler-Cromer[dt=0.0001]',**csfont) # plt.plot(x_earth,y_earth,'g') # y = y_earth # plt.title(r'Three body System with Jupiter_mass = 1e- AU',**csfont) # print(y) # plt.plot(x_earth1,y_earth1,label='V = $2.4\pi$') # plt.plot(x_earth2,y_earth2,label='V = $2.6\pi$') # plt.plot(x_earth3,y_earth3,label='V = $2.8\pi$') # plt.plot(x_earth4,y_earth4,label='V = $2.83\pi$') # plt.legend() #plt.plot(x_sun,y_sun) #plt.plot(x_jupiter , y_jupiter) # plt.plot(x_mars,y_mars) # plt.show() # --total_energy total = S.total_energy(p1, p2) # --angular momentum angular_momentum = S.angular_momentum(p2, 0.01, 1E6) # --prehelion precsition """
def Ex3i(planet_names, n=1e4, T=100, slice_n=3000, save_plot=False): """The orbit of Mercury with relativistic precision""" n = int(n) last_n = int(slice_n) if n < slice_n: print('slice_n must <= than n') sys.exit() planets = SolarSystem(planet_names, PrintTable=True) M_M = planets.mass Np = len(planets.mass) # Nr. of planets masses = planets.mass init_pos = np.array([[0.3075, 0]]) # [AU] init_vel = np.array([[0, 12.44]]) # [AU/yr] init_pos = np.transpose(init_pos) init_vel = np.transpose(init_vel) solver = Solver(masses, init_pos, init_vel, Np, T, n) pos_V, vel_V, t_V = solver.solver_relativistic(beta=2) distances_all = np.linalg.norm(pos_V, axis=0) min_dist = np.min(distances_all) max_dist = np.max(distances_all) distances = distances_all[-last_n:] # last_n distances index_minimum = find_last_min(distances) time_index = (len(pos_V[0, :, 0]) - len(pos_V[0, -last_n:, 0])) + index_minimum if distances[index_minimum] != distances_all[time_index]: print('%f != %f'\ %(distances[index_minimum], distances_all[time_index])) sys.exit() # we discovered we first used (x,y), not (y,x) # but the result is the same, just different direction angle_t0 = np.arctan2(pos_V[1, 0, 0], pos_V[0, 0, 0]) # angle at t=0 (pi/2) angle_t100 = np.arctan(pos_V[1, time_index, 0] / pos_V[0, time_index, 0]) # angle at t=100 yrs angle_t0_per_year = np.abs(angle_t0) / 100 angle_t100_per_year = np.abs(angle_t100) / 100 delta_rad = (angle_t0_per_year - angle_t100_per_year) arc_seconds = np.rad2deg(delta_rad) * 60 * 60 with open('Results/Mercury/new4_T[%g]_n[%g]_.txt' % (T, n), 'w') as f: f.write('\nthe perihelion position: (%f, %f) \n'\ %(pos_V[0,time_index,0],pos_V[1,time_index,0])) f.write('\nt = 0 yrs, theta = %f \n' % (angle_t0)) f.write('t = 100 yrs, theta = %f \n' % (angle_t100)) f.write('\ntheta per year = %f \n' % (angle_t0 / 100)) f.write('theta per year = %f \n' % (angle_t100 / 100)) f.write('\ndelta rad = %f \n' % delta_rad) f.write('\narc seconds = %f \n' % arc_seconds) out_data = open('Results/Mercury/new4_T[%g]_n[%g]_.txt' % (T, n)).read() print(out_data) plt.plot(pos_V[0, :, 0], pos_V[1, :, 0], label='Mercury') plt.plot(pos_V[0, 0, 0], pos_V[1, 0, 0], 'rx', label='Init. pos.') plt.plot(pos_V[0, -1, 0], pos_V[1, -1, 0], 'kx', label='Last pos.') plt.plot(pos_V[0, time_index, 0], pos_V[1, time_index, 0], 'mx', label='Last min.') plt.title('The orbit of Mercury for 100 years', fontsize=15) Figure(title='The orbit of Mercury for 100 years') if save_plot == True: plt.savefig('Results/Mercury/new4_T[%g]_n[%g]_plot.png' % (T, n)) plt.show()
algorithm="EULER") mass_mars = (constants.GM_mars / UPPER_G).value position_mars = [0, 0, 0] velocity_mars = [0, 0, 0] mars = Particle(position_mars, velocity_mars, np.array([0, 0, 0]), name='Mars', mass=mass_mars, algorithm="EULER") the_planets = [mars, massless] #test for gravitational acceleration on surface of a planet, acceleration = SolarSystem(the_planets).update_gravitational_acceleration() print(acceleration) #this part is for plotting 3D plots to test the maximum and minimum Data = np.load("/Users/annabellecarver/Desktop/Common/MasslessTest3D.npy", allow_pickle=True) Data_T = Data.T fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(111, projection='3d') from mpl_toolkits.mplot3d import Axes3D for i in range(len(Data[0][1].the_planets)): x_i = [q.the_planets[i].position[0] for q in Data_T[1]] y_i = [q.the_planets[i].position[1] for q in Data_T[1]]
from Rocket import Rocket from Body import Body from SolarSystem import SolarSystem from Stage import Stage rocket = Rocket.saturn_v( Stage(123000 - 36135, 123000, 165, 165 * 1000000 / 165)) rocket.theta = 2 * np.pi * 0 / 360 rocket.velocity = np.array((-460.0, 0.0)) earth = Body(5.97e24, 12756e3 / 2, (0, 0), (0, 0), (0.0, 0.0, 7.292115053925690e-05)) dt = 24 * 1. / 60 ss = SolarSystem(dt / 10.0, 1e-14) ss.add_body(earth) ss.add_body(rocket) # Visualization fig = plot.figure() axes = fig.add_subplot(111, aspect='equal', autoscale_on=True, xlim=(-1e7, 1e7), ylim=(-1e7, 1e7)) body_count = len(ss.bodies) earth_circle = Circle(earth.coord, earth.radius,
def createAndAnimate(): ss = SolarSystem(2, 2) sun = Sun("SUN", 10) ss.addSun(sun) m = Planet("Mercury", 1000, 0.2, 1, 0, 2, "orange") ss.addPlanet(m) e = Planet("Earth", 5000, 0.3, 1.3, 0, 2, "blue") ss.addPlanet(e) ma = Planet("Mars", 9000, 0.5, 1.2, 0, 1.63, "red") ss.addPlanet(ma) p = Planet("Pluto", 500, 0.9, .5, 0, .5, "gray") ss.addPlanet(p) # a = Planet("Asteroid", 500, 1.0, 0, .75, "cyan") # ss.addPlanet(a) numCycles = 10000 for i in range(numCycles): ss.movePlanets() # while True: # ss.movePlanets() # # You can add functionality to break away from the loop given some condition # # use the keyword break # break ss.freeze()
def fromIDSet(self, IDSet): ret = self() ret.map = {sysID: SolarSystem(sysID) for sysID in IDSet} return ret
from SolarSystem import SolarSystem if __name__ == "__main__": solar_system = SolarSystem("solar-system-data", 20000, satelite=True) solar_system.run(animation=True, energy_graph=True, orbital_periods=True) print("Time taken for satellite to reach Mars: ", solar_system.sat_time)
def filter(self, lamExp): ret = SolarSystemArray() for solarSysID in self.map: if lamExp(SolarSystem(solarSysID)) == True: ret.add(solarSysID) return ret
# note that the planets I can use are: sun, mercury, venus, earth, moon, mars, jupiter, saturn, uranus, neptune, pluto. to change the planets involved simply copy and paste more in! the_planets = [sun, mercury, venus, earth, moon, mars, jupiter, saturn, uranus, neptune, pluto] #to change the approximation used change the method of each planet to EULER, EULERCROMER OR VERLET Data = [] delta_t = 10000 time = 0 #To get different time steps change delta_t to smaller or bigger and to change the range do that in each graph formation. #To get different graph outputs then simply make the others into docstrings. #THIS IS THE CODE FOR DOING THE SOLAR SYSTEM PLOTS shortcut = SolarSystem(the_planets) for n in range(0, 10000): shortcut.position_velocity(delta_t) if (n % 100==0): item = [shortcut.time, copy.deepcopy(shortcut)] Data.append(item) np.save("/Users/annabellecarver/Desktop/Common/Unitmass", Data, allow_pickle=True) #THIS IS FOR FINDING THE ANGULAR MOMENTUM GRAPHS for i in range(0, 100000): AM = SolarSystem(the_planets).total_angular_momentum(delta_t) time += delta_t