def test_rotation_matrix_2d(self): self.assertTrue(np.equal(cde.rotation_matrix_2d(0.0), np.array([[1, 0], [0, 1]])).all) self.assertTrue(np.equal(cde.rotation_matrix_2d(np.pi), np.array([[-1, 0], [0, -1]])).all) r2o2 = 1.0 / np.sqrt(2.0) self.assertTrue( np.equal(cde.rotation_matrix_2d(-np.pi/4), np.array([[r2o2, r2o2], [-r2o2, r2o2]])).all)
def test_rotation_matrix_2d(self): self.assertTrue( np.equal(cde.rotation_matrix_2d(0.0), np.array([[1, 0], [0, 1]])).all) self.assertTrue( np.equal(cde.rotation_matrix_2d(np.pi), np.array([[-1, 0], [0, -1]])).all) r2o2 = 1.0 / np.sqrt(2.0) self.assertTrue( np.equal(cde.rotation_matrix_2d(-np.pi / 4), np.array([[r2o2, r2o2], [-r2o2, r2o2]])).all)
def test_orbital_step_time_simple(self): earth_vel = cde.earth_omega * cde.AU start_coords_1 = np.array([[cde.AU, 0.0], [0.0, earth_vel]]).T dt = cde.year / 360 #let's go forward one degree! one_deg = 2 * np.pi / 360. rot_coords = np.dot(cde.rotation_matrix_2d(one_deg), start_coords_1) final_coords = cde.orbital_step_time_simple(start_coords_1, dt) diff_coords = (rot_coords - final_coords) / rot_coords diff_coords_max = np.sqrt( max(np.dot(diff_coords[:,0], diff_coords[:,0]), np.dot(diff_coords[:,1], diff_coords[:,1]))) #Check to see if it's off by not more than a linear amount self.assertTrue(diff_coords_max < 1.0 / 360.0)
def test_orbital_step_time_simple(self): earth_vel = cde.earth_omega * cde.AU start_coords_1 = np.array([[cde.AU, 0.0], [0.0, earth_vel]]).T dt = cde.year / 360 #let's go forward one degree! one_deg = 2 * np.pi / 360. rot_coords = np.dot(cde.rotation_matrix_2d(one_deg), start_coords_1) final_coords = cde.orbital_step_time_simple(start_coords_1, dt) diff_coords = (rot_coords - final_coords) / rot_coords diff_coords_max = np.sqrt( max(np.dot(diff_coords[:, 0], diff_coords[:, 0]), np.dot(diff_coords[:, 1], diff_coords[:, 1]))) #Check to see if it's off by not more than a linear amount self.assertTrue(diff_coords_max < 1.0 / 360.0)
def test_rk4_stepper(self): earth_vel = cde.earth_omega * cde.AU start_coords_1 = np.array([[cde.AU, 0.0], [0.0, earth_vel]]).T dt = cde.year / 360 #let's go forward one degree! one_deg = 2 * np.pi / 360. rot_coords_1 = np.dot(cde.rotation_matrix_2d(one_deg), start_coords_1) int_coords = cde.rk4_stepper(start_coords_1, .5 * dt) final_coords = cde.rk4_stepper(int_coords, .5 * dt) final_coords_2 = cde.rk4_stepper(start_coords_1, dt) log_diff_coords = (rot_coords_1 - final_coords_2) / rot_coords_1 pos_err = np.sqrt(np.dot(log_diff_coords[:,0], log_diff_coords[:,0])) vel_err = np.sqrt(np.dot(log_diff_coords[:,1], log_diff_coords[:,1])) max_err = max(pos_err, vel_err) #Good to within a part in a billion self.assertTrue(max_err < 1.0 * 10 ** -9)
def test_rk4_stepper(self): earth_vel = cde.earth_omega * cde.AU start_coords_1 = np.array([[cde.AU, 0.0], [0.0, earth_vel]]).T dt = cde.year / 360 #let's go forward one degree! one_deg = 2 * np.pi / 360. rot_coords_1 = np.dot(cde.rotation_matrix_2d(one_deg), start_coords_1) int_coords = cde.rk4_stepper(start_coords_1, .5 * dt) final_coords = cde.rk4_stepper(int_coords, .5 * dt) final_coords_2 = cde.rk4_stepper(start_coords_1, dt) log_diff_coords = (rot_coords_1 - final_coords_2) / rot_coords_1 pos_err = np.sqrt(np.dot(log_diff_coords[:, 0], log_diff_coords[:, 0])) vel_err = np.sqrt(np.dot(log_diff_coords[:, 1], log_diff_coords[:, 1])) max_err = max(pos_err, vel_err) #Good to within a part in a billion self.assertTrue(max_err < 1.0 * 10**-9)