Ejemplo n.º 1
0
 def test_one_spherical_volume_element(self):
     r = 1.
     r0 = 0.
     theta = pi / 2
     theta0 = 0
     diffs = (1., 1., 1.)
     self.assertAlmostEqual(
         sp.calculate_spherical_volume_element(r, theta, diffs), 1.)
     self.assertAlmostEqual(
         sp.calculate_spherical_volume_element(r0, theta, diffs), 0.)
     self.assertAlmostEqual(
         sp.calculate_spherical_volume_element(r, theta0, diffs), 0.)
Ejemplo n.º 2
0
 def test_grid_spherical_volume_element(self):
     r = (0., 1.)
     theta = (0., pi / 2)
     r, theta = np.meshgrid(r, theta, indexing='ij')
     diffs = (np.ones_like(r), np.ones_like(r), np.ones_like(r))
     volume = np.array([[0., 0.], [0., 1.]])
     calc_volume = sp.calculate_spherical_volume_element(r, theta, diffs)
     self.assertTrue(np.array_equal(np.round(calc_volume, 7), volume))
Ejemplo n.º 3
0
    def test_spherical_grid_volume_unequal_length_arrays(self):
        grid = gr.SphericalGrid((r_short, t, p))
        dr, dt, dp = 0.1 * np.ones_like(r_short), 0.05 * pi * np.ones_like(
            t), 0.1 * pi * np.ones_like(p)
        dr[0] = 0.5 * dr[0]
        dr[-1] = 0.5 * dr[-1]
        dt[0] = 0.5 * dt[0]
        dt[-1] = 0.5 * dt[-1]
        dp[0] = 0.5 * dp[0]
        dp[-1] = 0.5 * dp[-1]
        drg, dtg, dpg = np.meshgrid(dr, dt, dp, indexing='ij')
        rg, tg, pg = np.meshgrid(r_short, t, p, indexing='ij')
        v_e = sp.calculate_spherical_volume_element(rg, tg, (drg, dtg, dpg))

        # Round For float equality check
        v_e = np.round(v_e, 7)
        v_c = np.round(grid.volume, 7)
        self.assertTrue(np.array_equal(v_e, v_c))
Ejemplo n.º 4
0
 def test_spherical_grid_init(self):
     r_array = (1., 0.5, 0.0)
     theta_array = (0.0, pi / 2)
     phi_array = (0.0, pi / 2)
     correct_grid = sp.spherical_to_cartesian_mesh(
         (r_array, theta_array, phi_array))
     r = correct_grid[0]
     theta = correct_grid[1]
     diffs = (np.ones_like(r), np.ones_like(r), np.ones_like(r))
     correct_volume = sp.calculate_spherical_volume_element(r, theta, diffs)
     grid_object = gr.SphericalGrid((r_array, theta_array, phi_array))
     calculated_grid = grid_object.grid
     calculated_volume = grid_object.volume
     for correct, calculated in zip(correct_grid, calculated_grid):
         self.assertTrue(np.array_equal(correct, calculated))
     self.assertTrue(
         np.array_equal(np.round(calculated_volume, 7),
                        np.round(correct_volume, 7)))
Ejemplo n.º 5
0
 def calculate_volume(self):
     differentials = calculate_differentials(self.coordinates)
     diff_grid = np.meshgrid(*differentials, indexing='ij')
     return sp.calculate_spherical_volume_element(self.mesh[0],
                                                  self.mesh[1], diff_grid)