def midpoint(dt, tfinal): particles, marr = fn.init_2body(0) etot0 = fn.e_tot(particles, marr) time = 0 x_and_v = [] while time < tfinal: acc = fn.forces(particles, marr) particles_mid = np.zeros((pars.Np, 2, 3)) particles_mid[:, 0, :] = particles[:, 0, :] + particles[:, 1, :] * dt / 2 particles_mid[:, 1, :] = particles[:, 1, :] + acc * dt / 2 amid = fn.forces(particles_mid, marr) particles[:, 0, :] += particles_mid[:, 1, :] * dt particles[:, 1, :] += amid * dt x_and_v.append(particles.tolist()) time += dt etot1 = fn.e_tot(particles, marr) e_error = (etot1 - etot0) / etot0 return x_and_v, e_error
def leapfrog(dt, tfinal, tau, drag=False, init_e=0.0): save_file = open( "object_time_x,v,m_dt=" + str(dt) + "_tfinal=" + str(tfinal) + "_tau=" + str(tau) + ".csv", "w") particles, marr = fn.init_2body(init_e) etot0 = fn.e_tot(particles, marr) eccentricity = [] semi_major_axis = [] x_and_v = [] vkep_list = [] time_list = [] time = 0 while time < tfinal: if drag: acc, v_kep, v_r = fn.forces_total(particles, marr, tau) else: acc = fn.forces(particles, marr) v_kep = [] particles[:, 1, :] += acc * dt / 2 particles[:, 0, :] += particles[:, 1, :] * dt if drag: acc, v_kep, v_r = fn.forces_total(particles, marr, tau, v_r=v_r) else: acc = fn.forces(particles, marr) particles[:, 1, :] += acc * dt / 2 x_and_v.append(particles.tolist()) # print 'next' ecc, a = fn.get_orbital_elements(particles, marr) for i in [0, 1]: np.savetxt(save_file,np.c_[i, time, particles[i,0,0], particles[i,0,1], particles[i,0,2], \ particles[i,1,0], particles[i,1,1], particles[i,1,2], marr[i], v_kep], delimiter=',', fmt='%.10e') # eccentricity.append(np.sqrt(sum(ecc)**2)) # semi_major_axis.append(a) # vkep_list.append(v_kep) # time_list.append(time) time += dt if a < 0.15: break
def leapfrog(dt, tfinal): particles, marr = fn.init_2body(0) etot0 = fn.e_tot(particles, marr) time = 0 while time < tfinal: acc = fn.forces(particles, marr) particles[:, 1, :] += acc * dt / 2 particles[:, 0, :] += particles[:, 1, :] * dt acc = fn.forces(particles, marr) particles[:, 1, :] += acc * dt / 2 x_and_v.append(particles.tolist()) time += dt etot1 = fn.e_tot(particles, marr) e_error = (etot1 - etot0) / etot0 return x_and_v, e_error
def leapfrog_drag(dt, tfinal): particles, marr = fn.init_2body(0) etot0 = fn.e_tot(particles, marr) time = 0 while time < tfinal: acc = fn.forces(particles, marr)[0] particles[0, 1, :] += acc * dt / 2 particles[0, 0, :] += particles[0, 1, :] * dt acc = fn.forces(particles, marr)[0] particles[0, 1, :] += acc * dt / 2 grav = fn.forces(particles, marr)[1] drag = fn.forces_migration(particles, marr) acc = grav + drag particles[1, 1, :] += acc * dt / 2 particles[1, 0, :] += particles[1, 1, :] * dt grav = fn.forces(particles, marr)[1] drag = fn.forces_migration(particles, marr) acc = grav + drag * 1e1 particles[1, 1, :] += acc * dt / 2 eccentricity, semi_major_axis = fn.get_orbital_elements( particles, marr) eccentricity_save.append(eccentricity.tolist()) semi_major_axis_save.append(semi_major_axis.tolist()) x_and_v.append(particles.tolist()) time += dt etot1 = fn.e_tot(particles, marr) e_error = (etot1 - etot0) / etot0 return x_and_v, e_error, eccentricity_save, semi_major_axis_save