From e5b3901654678f77e7ffafa25eaf78326807283b Mon Sep 17 00:00:00 2001 From: Kaya Unalmis Date: Wed, 5 Apr 2023 00:56:26 -0500 Subject: [PATCH] Remove code that modulos custom grid nodes --- desc/grid.py | 3 +-- desc/plotting.py | 2 +- tests/test_examples.py | 8 ++++---- tests/test_grid.py | 6 +++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/desc/grid.py b/desc/grid.py index de1bc7c750..543d5685b9 100644 --- a/desc/grid.py +++ b/desc/grid.py @@ -199,8 +199,7 @@ def _create_nodes(self, nodes): """ nodes = np.atleast_2d(nodes).reshape((-1, 3)).astype(float) - nodes[nodes[:, 1] > 2 * np.pi, 1] %= 2 * np.pi - nodes[nodes[:, 2] > 2 * np.pi / self.NFP, 2] %= 2 * np.pi / self.NFP + # Note: do not modulo nodes by 2pi or 2pi/NFP. spacing = ( # make weights sum to 4pi^2 np.ones_like(nodes) * np.array([1, 2 * np.pi, 2 * np.pi]) / nodes.shape[0] ) diff --git a/desc/plotting.py b/desc/plotting.py index 3381009dc1..bcfda442a6 100644 --- a/desc/plotting.py +++ b/desc/plotting.py @@ -1410,7 +1410,7 @@ def plot_surfaces(eq, rho=8, theta=8, zeta=None, ax=None, return_data=False, **k } if plot_theta: # Note: theta* (also known as vartheta) is the poloidal straight field-line - # anlge in PEST-like flux coordinates + # angle in PEST-like flux coordinates t_grid = _get_grid(**grid_kwargs) v_grid = Grid(eq.compute_theta_coords(t_grid.nodes)) rows = np.floor(np.sqrt(nzeta)).astype(int) diff --git a/tests/test_examples.py b/tests/test_examples.py index d9f5bac45b..c993699706 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -112,7 +112,7 @@ def test_precise_QH_results(precise_QH): eq2 = EquilibriaFamily.load(load_from=str(precise_QH["output_path"]))[-1] rho_err, theta_err = area_difference_desc(eq1, eq2) np.testing.assert_allclose(rho_err, 0, atol=1e-2) - np.testing.assert_allclose(theta_err, 0, atol=3e-2) + np.testing.assert_allclose(theta_err, 0, atol=1e-2) @pytest.mark.regression @@ -123,7 +123,7 @@ def test_HELIOTRON_vac2_results(HELIOTRON_vac, HELIOTRON_vac2): eq2 = EquilibriaFamily.load(load_from=str(HELIOTRON_vac2["desc_h5_path"]))[-1] rho_err, theta_err = area_difference_desc(eq1, eq2) np.testing.assert_allclose(rho_err[:, 3:], 0, atol=1e-2) - np.testing.assert_allclose(theta_err, 0, atol=0.003) + np.testing.assert_allclose(theta_err, 0, atol=1e-4) curr1 = eq1.get_profile("current") curr2 = eq2.get_profile("current") iota1 = eq1.get_profile("iota") @@ -369,7 +369,7 @@ def test_ATF_results(tmpdir_factory): eqf = load(output_dir.join("ATF.h5")) rho_err, theta_err = area_difference_desc(eq0, eqf[-1]) np.testing.assert_allclose(rho_err[:, 4:], 0, atol=4e-2) - np.testing.assert_allclose(theta_err, 0, atol=0.03) + np.testing.assert_allclose(theta_err, 0, atol=5e-4) @pytest.mark.regression @@ -402,7 +402,7 @@ def test_ESTELL_results(tmpdir_factory): eqf = load(output_dir.join("ESTELL.h5")) rho_err, theta_err = area_difference_desc(eq0, eqf[-1]) np.testing.assert_allclose(rho_err[:, 3:], 0, atol=5e-2) - np.testing.assert_allclose(theta_err, 0, atol=1e-3) + np.testing.assert_allclose(theta_err, 0, atol=1e-4) @pytest.mark.regression diff --git a/tests/test_grid.py b/tests/test_grid.py index 93cce3b9f9..05b932b566 100644 --- a/tests/test_grid.py +++ b/tests/test_grid.py @@ -775,11 +775,11 @@ def test(grid, midpoint_rule=False): dr[1:-1] = (r_unique[2:] - r_unique[:-2]) / 2 dr[-1] = 1 - (r_unique[-2] + r_unique[-1]) / 2 else: - dr = np.ones(grid.num_rho) / grid.num_rho + dr = 1 / grid.num_rho expected_integral = np.sum(dr * compress(grid, function_of_rho)) true_integral = np.log(1.35 / 0.35) - midpoint_rule_error_bound = max(dr) ** 2 / 24 * (2 / 0.35**3) - right_riemann_error_bound = dr[0] * (1 / 0.35 - 1 / 1.35) + midpoint_rule_error_bound = np.max(dr) ** 2 / 24 * (2 / 0.35**3) + right_riemann_error_bound = dr * (1 / 0.35 - 1 / 1.35) np.testing.assert_allclose( expected_integral, true_integral,