def test_run(): three=binary_with_planet( m1=0.6897 | units.MSun,m2=0.20255 | units.MSun,m_planet=0.333 | units.MJupiter, r1=0.6489 | units.RSun,r2=0.22623 | units.RSun,r_planet=0.754 | units.RJupiter, ecc_binary=0.15944,P_binary=41.08| units.day,ecc_planet=0.00685,a_planet=.7048 | units.AU, pangle_planet=0.) convert=nbody_system.nbody_to_si(1|units.MSun,1|units.AU) code=Huayno(convert) code.parameters.inttype_parameter=code.inttypes.SHARED4 code.parameters.timestep_parameter=0.1 # tend=100. | units.yr tend=100. | units.day snapfreq=1 dt=10. | units.day # dt=convert.to_si( 1. | nbody_system.time).in_(units.day) code.particles.add_particles(three) x = AdaptingVectorQuantity() y = AdaptingVectorQuantity() z = AdaptingVectorQuantity() vx = AdaptingVectorQuantity() vy = AdaptingVectorQuantity() vz = AdaptingVectorQuantity() x.append(code.particles.x) y.append(code.particles.y) z.append(code.particles.z) vx.append(code.particles.vx) vy.append(code.particles.vy) vz.append(code.particles.vz) ts=[0.] E0=code.potential_energy+code.kinetic_energy dE=[1.e-14] t=0. | units.day i=0 while(t < tend-dt/2): i+=1 t=t+dt if i%snapfreq==0: print t ts.append(t.value_in(units.day)) code.evolve_model(t) x.append(code.particles.x) y.append(code.particles.y) z.append(code.particles.z) vx.append(code.particles.vx) vy.append(code.particles.vy) vz.append(code.particles.vz) E=code.potential_energy+code.kinetic_energy dE.append(abs(((E-E0)/E0))) code.stop() a,eps,pangle=elements(three.total_mass(), x[:,2], y[:,2], z[:,2], vx[:,2], vy[:,2], vz[:,2]) x=x.value_in(units.AU) y=y.value_in(units.AU) a=a.value_in(units.AU) eps=eps print a[-1],eps[-1],pangle[-1] f=pyplot.figure(figsize=(8,8)) pyplot.plot(x[:,0],y[:,0],'r.') pyplot.plot(x[:,1],y[:,1],'g.') pyplot.plot(x[:,2],y[:,2],'b.') pyplot.xlim(-3,3) pyplot.ylim(-3,3) pyplot.xlabel('AU') pyplot.savefig('three_16b.eps') f=pyplot.figure(figsize=(8,8)) pyplot.semilogy(ts,dE,'g.') pyplot.xlabel('time (day)') pyplot.ylabel('dE/E0') pyplot.savefig('three_16b_eerr.eps') f=pyplot.figure(figsize=(8,8)) pyplot.plot(ts,a,'g.') pyplot.xlabel('time (day)') pyplot.ylabel('a (AU)') pyplot.savefig('three_16b_a.eps') f=pyplot.figure(figsize=(8,8)) pyplot.plot(ts,eps,'g.') pyplot.xlabel('time (day)') pyplot.ylabel('eccentricity') pyplot.savefig('three_16b_ecc.eps') f=pyplot.figure(figsize=(8,8)) pyplot.plot(ts,pangle,'g.') pyplot.xlabel('time (day)') pyplot.ylabel('long. of periapsis') pyplot.savefig('three_16b_pangle.eps')
def main(): dots = Dots() line = Line() f = h5py.File(args.filename, 'r') fig = plt.figure() ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212) for intr in f.values(): etas = [] final_smas_p0_vq = AdaptingVectorQuantity() final_smas_p1_vq = AdaptingVectorQuantity() for sim in intr.values(): etas.append(sim['eta'][0]) final_smas_p0_vq.append(sim['p0/sma'][-1]| retrieve_unit(sim['p0/sma'])) final_smas_p1_vq.append(sim['p1/sma'][-1]| retrieve_unit(sim['p1/sma'])) final_smas_p0 = final_smas_p0_vq.value_in(units.AU) final_smas_p1 = final_smas_p1_vq.value_in(units.AU) ax1.plot(etas, final_smas_p0, marker='o', label=intr.name, picker=5) ax2.plot(etas, final_smas_p1, marker='o', label=intr.name, picker=5) ax1.set_xlabel('eta') ax2.set_xlabel('eta') ax1.set_ylabel('final sma inner [AU]') ax2.set_ylabel('final sma outer [AU]') dset = f.values()[0].values()[0] #first dset available time = quantify_dset(dset['time']).value_in(units.yr) mass = quantify_dset(dset['mass']).value_in(units.MSun) inner_sma0 = quantify_dset(dset['p0/sma']).value_in(units.AU) outer_sma0 = quantify_dset(dset['p1/sma']).value_in(units.AU) inner_sma_final_adiabatic_approx = sma_analytical(inner_sma0[0], 1.244e-5, time[-1], mass[0].sum() ) outer_sma_final_adiabatic_approx = sma_analytical(outer_sma0[0], 1.244e-5, time[-1], mass[0].sum() ) ax1.axhline(inner_sma_final_adiabatic_approx, xmin=0, xmax=1, c='m', label='adiabatic approx') ax1.legend(loc='best') ax2.axhline(outer_sma_final_adiabatic_approx, xmin=0, xmax=1, c='m', label='adiabatic approx') ax2.legend(loc='best') if args.logscale: ax1.set_xscale('log') ax2.set_xscale('log') if args.ylim1: ax1.set_ylim(args.ylim1) if args.ylim2: ax2.set_ylim(args.ylim2) if args.xlim1: ax1.set_xlim(args.xlim1) if args.xlim2: ax2.set_xlim(args.xlim2) def onpick(event): print("artist:{} ind:{}".format(event.artist, event.ind)) print("button: {}".format(event.mouseevent.button)) intr = f[event.artist.get_label()] sim = intr.values()[event.ind] time_vq = quantify_dset(sim['time']) time = time_vq.value_in(units.yr) position_vq = quantify_dset(sim['position']) position = position_vq.value_in(units.AU) CM_position_vq = quantify_dset(sim['CM_position']) CM_position = CM_position_vq.value_in(units.AU) x, y = 0, 1 central_x, central_y = position[:, 0, x] - CM_position[:,x], position[:, 0, y] - CM_position[:,y] inner_x, inner_y = position[:, 1, x] - CM_position[:,x], position[:, 1, y] - CM_position[:,y] outer_x, outer_y = position[:, 2, x] - CM_position[:,x], position[:, 2, y] - CM_position[:,y] mass_vq = quantify_dset(sim['mass']) mass = mass_vq[:,0].value_in(units.MSun) if event.mouseevent.button == 1: mu0 = quantify_dset(sim['mass'])[0].sum() period_vq = quantify_dset(sim['p0/period']) period = period_vq.value_in(units.yr) true_anomaly = sim['p0/true_anomaly'].value argument_of_periapsis = sim['p0/argument_of_periapsis'].value sma_vq = quantify_dset(sim['p0/sma']) sma = sma_vq.value_in(units.AU) sma_an_vq = sma_analytical(sma_vq[0], 1.244e-5|(units.MSun/units.yr), time_vq, mu0) sma_an = sma_an_vq.value_in(units.AU) eccentricity = sim['p0/eccentricity'].value newfig = plt.figure() newax1 = newfig.add_subplot(511) newax2 = newfig.add_subplot(512) newax3 = newfig.add_subplot(513) newax4 = newfig.add_subplot(514) newax5 = newfig.add_subplot(515) newax1.plot(time, sma, label='numerical') newax1.plot(time, sma_an, label='analytical_adiabatic') newax1.set_xlabel('time [yr]') newax1.set_ylabel('sma [AU]') newax1.legend(loc='best') newax2.plot(time, eccentricity) newax2.set_xlabel('time [yr]') newax2.set_ylabel('eccentricity ') newax3.plot(time, true_anomaly) newax3.set_xlabel('time [yr]') newax3.set_ylabel('true anomaly [degrees] ') newax4.plot(time, argument_of_periapsis) newax4.set_xlabel('time [yr]') newax4.set_ylabel('argument of periapsis [degrees] ') newax5.plot(time, period) newax5.set_xlabel('time [yr]') newax5.set_ylabel('period') else: newfig = plt.figure() newax1 = newfig.add_subplot(321) newax2 = newfig.add_subplot(322) newax3 = newfig.add_subplot(323) newax4 = newfig.add_subplot(324) newax5 = newfig.add_subplot(325) newax6 = newfig.add_subplot(326) mass_vq = quantify_dset(sim['mass']) mass = mass_vq.value_in(units.MSun) kinetic_energy = sim['kinetic_energy'].value potential_energy = sim['potential_energy'].value total_energy = sim['total_energy'].value CM_velocity_vq = quantify_dset(sim['CM_velocity']) CM_velocity_mod = CM_velocity_vq.lengths().value_in(units.km/units.hour) walltime = sim['walltime'].value - sim['walltime'][0] newax1.plot(time, mass) newax1.set_ylabel('central mass [MSun]') newax1.set_xlabel('time [yr]') newax2.plot(time, kinetic_energy, label='kinetic', **line.red) newax2.plot(time, potential_energy,label='potential', **line.orange) newax2.plot(time, total_energy, label='total', **line.white) newax2.set_xlabel('time [yr]') newax2.legend() newax3.plot(central_x, central_y, **dots.white) newax3.plot(inner_x, inner_y, **dots.red) newax3.plot(outer_x, outer_y, **dots.yellow) newax3.set_xlabel('x [AU]') newax3.set_ylabel('y [AU]') newax4.plot(CM_position[:, x], CM_position[:, y] ) newax4.set_xlim(-5, 5) newax4.set_xlabel('CM position x [AU]') newax4.set_ylabel('CM position y [AU]') newax5.plot(time, CM_velocity_mod) newax5.set_ylim(20, 30) newax5.set_xlabel('time [yr]') newax5.set_ylabel('CM velocity [km/hour]') newax6.plot(time, walltime) newax6.set_xlabel('time [yr]') newax6.set_ylabel('walltime [s]') newfig.show() fig.canvas.mpl_connect('pick_event', onpick) plt.show()
def main(): dots = Dots() line = Line() f = h5py.File(args.filename, 'r') fig = plt.figure() ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212) for intr in f.values(): timesteps_vq = AdaptingVectorQuantity() final_smas_p0_vq = AdaptingVectorQuantity() final_smas_p1_vq = AdaptingVectorQuantity() for sim in intr.values(): timesteps_vq.append(sim['timestep'][0] | retrieve_unit(sim['timestep'])) final_smas_p0_vq.append(sim['p0/sma'][-1]| retrieve_unit(sim['p0/sma'])) final_smas_p1_vq.append(sim['p1/sma'][-1]| retrieve_unit(sim['p1/sma'])) timesteps = timesteps_vq.value_in(units.yr) final_smas_p0 = final_smas_p0_vq.value_in(units.AU) final_smas_p1 = final_smas_p1_vq.value_in(units.AU) ax1.plot(timesteps, final_smas_p0, marker='o', label=intr.name, picker=5) ax2.plot(timesteps, final_smas_p1, marker='o', label=intr.name, picker=5) ax1.set_xlabel('Mass update interval [yr]') ax2.set_xlabel('Mass update interval [yr]') ax1.set_ylabel('final sma inner [AU]') ax2.set_ylabel('final sma outer [AU]') dset = f.values()[0].values()[0] #first dset available time = quantify_dset(dset['time']).value_in(units.yr) mass = quantify_dset(dset['mass']).value_in(units.MSun) inner_sma0 = quantify_dset(dset['p0/sma']).value_in(units.AU) outer_sma0 = quantify_dset(dset['p1/sma']).value_in(units.AU) inner_sma_final_adiabatic_approx = sma_analytical(inner_sma0[0], 1.244e-5, time[-1], mass[0].sum() ) outer_sma_final_adiabatic_approx = sma_analytical(outer_sma0[0], 1.244e-5, time[-1], mass[0].sum() ) ax1.axhline(inner_sma_final_adiabatic_approx, xmin=0, xmax=1, c='m', label='adiabatic approx') ax1.legend(loc='best') ax2.axhline(outer_sma_final_adiabatic_approx, xmin=0, xmax=1, c='m', label='adiabatic approx') ax2.legend(loc='best') if args.logscale: ax1.set_xscale('log') ax2.set_xscale('log') if args.ylim1: ax1.set_ylim(args.ylim1) if args.ylim2: ax2.set_ylim(args.ylim2) if args.xlim1: ax1.set_xlim(args.xlim1) if args.xlim2: ax2.set_xlim(args.xlim2) def onpick(event): print("artist:{} ind:{}".format(event.artist, event.ind)) print("button: {}".format(event.mouseevent.button)) intr = f[event.artist.get_label()] sim = intr.values()[event.ind] time_vq = quantify_dset(sim['time']) time = time_vq.value_in(units.yr) position_vq = quantify_dset(sim['position']) position = position_vq.value_in(units.AU) CM_position_vq = quantify_dset(sim['CM_position']) CM_position = CM_position_vq.value_in(units.AU) x, y = 0, 1 central_x, central_y = position[:, 0, x] - CM_position[:,x], position[:, 0, y] - CM_position[:,y] inner_x, inner_y = position[:, 1, x] - CM_position[:,x], position[:, 1, y] - CM_position[:,y] outer_x, outer_y = position[:, 2, x] - CM_position[:,x], position[:, 2, y] - CM_position[:,y] mass_vq = quantify_dset(sim['mass']) mass = mass_vq[:,0].value_in(units.MSun) if event.mouseevent.button == 1: mu0 = quantify_dset(sim['mass'])[0].sum() period_vq = quantify_dset(sim['p0/period']) period = period_vq.value_in(units.yr) true_anomaly = sim['p0/true_anomaly'].value argument_of_periapsis = sim['p0/argument_of_periapsis'].value sma_vq = quantify_dset(sim['p0/sma']) sma = sma_vq.value_in(units.AU) sma_an_vq = sma_analytical(sma_vq[0], 1.244e-5|(units.MSun/units.yr), time_vq, mu0) sma_an = sma_an_vq.value_in(units.AU) eccentricity = sim['p0/eccentricity'].value newfig = plt.figure() newax1 = newfig.add_subplot(511) newax2 = newfig.add_subplot(512) newax3 = newfig.add_subplot(513) newax4 = newfig.add_subplot(514) newax5 = newfig.add_subplot(515) newax1.plot(time, sma, label='numerical') newax1.plot(time, sma_an, label='analytical_adiabatic') newax1.set_xlabel('time [yr]') newax1.set_ylabel('sma [AU]') newax1.legend(loc='best') newax2.plot(time, eccentricity) newax2.set_xlabel('time [yr]') newax2.set_ylabel('eccentricity ') newax3.plot(time, true_anomaly) newax3.set_xlabel('time [yr]') newax3.set_ylabel('true anomaly [degrees] ') newax4.plot(time, argument_of_periapsis) newax4.set_xlabel('time [yr]') newax4.set_ylabel('argument of periapsis [degrees] ') newax5.plot(time, period) newax5.set_xlabel('time [yr]') newax5.set_ylabel('period') else: newfig = plt.figure() newax1 = newfig.add_subplot(321) newax2 = newfig.add_subplot(322) newax3 = newfig.add_subplot(323) newax4 = newfig.add_subplot(324) newax5 = newfig.add_subplot(325) newax6 = newfig.add_subplot(326) mass_vq = quantify_dset(sim['mass']) mass = mass_vq.value_in(units.MSun) kinetic_energy = sim['kinetic_energy'].value potential_energy = sim['potential_energy'].value total_energy = sim['total_energy'].value CM_velocity_vq = quantify_dset(sim['CM_velocity']) CM_velocity_mod = CM_velocity_vq.lengths().value_in(units.km/units.hour) walltime = sim['walltime'].value - sim['walltime'][0] newax1.plot(time, mass) newax1.set_ylabel('central mass [MSun]') newax1.set_xlabel('time [yr]') newax2.plot(time, kinetic_energy, label='kinetic', **line.red) newax2.plot(time, potential_energy,label='potential', **line.orange) newax2.plot(time, total_energy, label='total', **line.white) newax2.set_xlabel('time [yr]') newax2.legend() newax3.plot(central_x, central_y, **dots.white) newax3.plot(inner_x, inner_y, **dots.red) newax3.plot(outer_x, outer_y, **dots.yellow) newax3.set_xlabel('x [AU]') newax3.set_ylabel('y [AU]') newax4.plot(CM_position[:, x], CM_position[:, y] ) newax4.set_xlim(-5, 5) newax4.set_xlabel('CM position x [AU]') newax4.set_ylabel('CM position y [AU]') newax5.plot(time, CM_velocity_mod) newax5.set_ylim(20, 30) newax5.set_xlabel('time [yr]') newax5.set_ylabel('CM velocity [km/hour]') newax6.plot(time, walltime) newax6.set_xlabel('time [yr]') newax6.set_ylabel('walltime [s]') newfig.show() fig.canvas.mpl_connect('pick_event', onpick) plt.show()
def test_run(): three = binary_with_planet(m1=0.6897 | units.MSun, m2=0.20255 | units.MSun, m_planet=0.333 | units.MJupiter, r1=0.6489 | units.RSun, r2=0.22623 | units.RSun, r_planet=0.754 | units.RJupiter, ecc_binary=0.15944, P_binary=41.08 | units.day, ecc_planet=0.00685, a_planet=.7048 | units.AU, pangle_planet=0.) convert = nbody_system.nbody_to_si(1 | units.MSun, 1 | units.AU) code = Huayno(convert) code.parameters.inttype_parameter = code.inttypes.SHARED4 code.parameters.timestep_parameter = 0.1 # tend=100. | units.yr tend = 100. | units.day snapfreq = 1 dt = 10. | units.day # dt=convert.to_si( 1. | nbody_system.time).in_(units.day) code.particles.add_particles(three) x = AdaptingVectorQuantity() y = AdaptingVectorQuantity() z = AdaptingVectorQuantity() vx = AdaptingVectorQuantity() vy = AdaptingVectorQuantity() vz = AdaptingVectorQuantity() x.append(code.particles.x) y.append(code.particles.y) z.append(code.particles.z) vx.append(code.particles.vx) vy.append(code.particles.vy) vz.append(code.particles.vz) ts = [0.] E0 = code.potential_energy + code.kinetic_energy dE = [1.e-14] t = 0. | units.day i = 0 while (t < tend - dt / 2): i += 1 t = t + dt if i % snapfreq == 0: print t ts.append(t.value_in(units.day)) code.evolve_model(t) x.append(code.particles.x) y.append(code.particles.y) z.append(code.particles.z) vx.append(code.particles.vx) vy.append(code.particles.vy) vz.append(code.particles.vz) E = code.potential_energy + code.kinetic_energy dE.append(abs(((E - E0) / E0))) code.stop() a, eps, pangle = elements(three.total_mass(), x[:, 2], y[:, 2], z[:, 2], vx[:, 2], vy[:, 2], vz[:, 2]) x = x.value_in(units.AU) y = y.value_in(units.AU) a = a.value_in(units.AU) eps = eps print a[-1], eps[-1], pangle[-1] f = pyplot.figure(figsize=(8, 8)) pyplot.plot(x[:, 0], y[:, 0], 'r.') pyplot.plot(x[:, 1], y[:, 1], 'g.') pyplot.plot(x[:, 2], y[:, 2], 'b.') pyplot.xlim(-3, 3) pyplot.ylim(-3, 3) pyplot.xlabel('AU') pyplot.savefig('three_16b.eps') f = pyplot.figure(figsize=(8, 8)) pyplot.semilogy(ts, dE, 'g.') pyplot.xlabel('time (day)') pyplot.ylabel('dE/E0') pyplot.savefig('three_16b_eerr.eps') f = pyplot.figure(figsize=(8, 8)) pyplot.plot(ts, a, 'g.') pyplot.xlabel('time (day)') pyplot.ylabel('a (AU)') pyplot.savefig('three_16b_a.eps') f = pyplot.figure(figsize=(8, 8)) pyplot.plot(ts, eps, 'g.') pyplot.xlabel('time (day)') pyplot.ylabel('eccentricity') pyplot.savefig('three_16b_ecc.eps') f = pyplot.figure(figsize=(8, 8)) pyplot.plot(ts, pangle, 'g.') pyplot.xlabel('time (day)') pyplot.ylabel('long. of periapsis') pyplot.savefig('three_16b_pangle.eps')