Example #1
0
 def test_rotation_matrix_3d(self):
     z_rot_vec = np.array([0, 0, 1])
     z_rot_theta = np.pi / 4
     trans_matrix = cde.rotation_matrix_3d(z_rot_vec, z_rot_theta)
     vec_to_rotate = np.array([1, 0, 0])
     r2 = np.sqrt(2.0)
     self.assertTrue(
         np.equal(trans_matrix.dot(vec_to_rotate), [1 / r2, 1 / r2, 0]).all)
     x_rot_vec = np.array([1, 0, 0])
     x_rot_theta = np.pi / 4
     trans_matrix = cde.rotation_matrix_3d(x_rot_vec, x_rot_theta)
     vec_to_rotate = np.array([0, 0, 1])
     self.assertTrue(
         np.equal(trans_matrix.dot(vec_to_rotate),
                  [0, -1 / r2, 1 / r2]).all)
     rot_vec = np.array([1, 1, 1])
     rot_theta = np.pi * 2 / 3
     trans_matrix = cde.rotation_matrix_3d(rot_vec, rot_theta)
     vec_to_rotate = np.array([0, 0, 1])
     try:
         goo = cde.rotation_matrix_3d(np.array([0, 0, 0]), np.pi / 3)
         self.assertTrue(False)
     except:
         self.assertTrue(True)
     self.assertTrue(
         np.equal(trans_matrix.dot(vec_to_rotate), [1, 0, 0]).all)
	def test_rotation_matrix_3d(self):
		z_rot_vec = np.array([0, 0, 1])
		z_rot_theta = np.pi / 4
		trans_matrix = cde.rotation_matrix_3d(z_rot_vec, z_rot_theta)
		vec_to_rotate = np.array([1, 0, 0])
		r2 = np.sqrt(2.0)
		self.assertTrue(np.equal(trans_matrix.dot(vec_to_rotate), 
			[1 / r2, 1 / r2, 0]).all)
		x_rot_vec = np.array([1, 0, 0])
		x_rot_theta = np.pi / 4
		trans_matrix = cde.rotation_matrix_3d(x_rot_vec, x_rot_theta)
		vec_to_rotate = np.array([0, 0, 1])
		self.assertTrue(np.equal(trans_matrix.dot(vec_to_rotate), 
			[0, - 1 / r2, 1 / r2]).all)
		rot_vec = np.array([1, 1, 1])
		rot_theta = np.pi * 2 / 3
		trans_matrix = cde.rotation_matrix_3d(rot_vec, rot_theta)
		vec_to_rotate = np.array([0, 0, 1])
		try:
			goo = cde.rotation_matrix_3d(np.array([0,0,0]), np.pi/3)
			self.assertTrue(False)
		except:
			self.assertTrue(True)
		self.assertTrue(np.equal(trans_matrix.dot(vec_to_rotate), 
			[1, 0, 0]).all)
	def test_rk4_stepper(self):
		earth_vel = cde.earth_omega * cde.AU
		start_coords_1 = np.array([[cde.AU, 0.0, 0.0], 
			[0.0, earth_vel, 0.0]]).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_3d(
			np.array([0, 0, 1.0]), 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)
		rot_mags = np.array([rot_coords_1[:,0].dot(rot_coords_1[:,0]), 
			rot_coords_1[:,1].dot(rot_coords_1[:,1])])
		log_diff_coords = (rot_coords_1 - final_coords_2) / rot_mags
		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)
	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], 
			[0.0, earth_vel, 0.0]]).T
		dt = cde.year / 360  #let's go forward one degree!
		one_deg = 2 * np.pi / 360.
		rot_coords = np.dot(cde.rotation_matrix_3d(
			np.array([0, 0, 1.0]), one_deg), start_coords_1)
		final_coords = cde.orbital_step_time_simple(start_coords_1, dt)
		final_mags = np.array([final_coords[:,0].dot(final_coords[:,0]), 
			final_coords[:,1].dot(final_coords[:,1])])
		diff_coords = (rot_coords - final_coords) / final_mags
		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)
Example #5
0
 def test_rk4_stepper(self):
     earth_vel = cde.earth_omega * cde.AU
     start_coords_1 = np.array([[cde.AU, 0.0, 0.0], [0.0, earth_vel,
                                                     0.0]]).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_3d(np.array([0, 0, 1.0]), 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)
     rot_mags = np.array([
         rot_coords_1[:, 0].dot(rot_coords_1[:, 0]),
         rot_coords_1[:, 1].dot(rot_coords_1[:, 1])
     ])
     log_diff_coords = (rot_coords_1 - final_coords_2) / rot_mags
     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)
Example #6
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], [0.0, earth_vel,
                                                     0.0]]).T
     dt = cde.year / 360  #let's go forward one degree!
     one_deg = 2 * np.pi / 360.
     rot_coords = np.dot(
         cde.rotation_matrix_3d(np.array([0, 0, 1.0]), one_deg),
         start_coords_1)
     final_coords = cde.orbital_step_time_simple(start_coords_1, dt)
     final_mags = np.array([
         final_coords[:, 0].dot(final_coords[:, 0]),
         final_coords[:, 1].dot(final_coords[:, 1])
     ])
     diff_coords = (rot_coords - final_coords) / final_mags
     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)