From 4dbbca9342c857cb3b9f8f2d9e440499fc164f6f Mon Sep 17 00:00:00 2001 From: Magdalena Date: Thu, 11 Apr 2024 17:31:51 +0200 Subject: [PATCH] =?UTF-8?q?fix=20the=20order=20of=20the=20origin=20to=20be?= =?UTF-8?q?=20in=20first=20place=20to=20match=20ICON=20index=20=E2=80=A6?= =?UTF-8?q?=20(#439)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix the order of the origin to be in first place to match ICON index ordering in coefficients * pre-commit --- .../icon4py/model/common/grid/grid_manager.py | 4 ++-- .../tests/grid_tests/test_grid_manager.py | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/model/common/src/icon4py/model/common/grid/grid_manager.py b/model/common/src/icon4py/model/common/grid/grid_manager.py index 79e567b8c0..6b4db3e51e 100644 --- a/model/common/src/icon4py/model/common/grid/grid_manager.py +++ b/model/common/src/icon4py/model/common/grid/grid_manager.py @@ -373,13 +373,13 @@ def _from_grid_dataset(self, dataset: Dataset, on_gpu: bool, limited_area=True) e2c2v = self._construct_diamond_vertices(e2v, c2v, e2c) e2c2e = self._construct_diamond_edges(e2c, c2e) - e2c2e0 = np.column_stack((e2c2e, np.asarray(range(e2c2e.shape[0])))) + e2c2e0 = np.column_stack((np.asarray(range(e2c2e.shape[0])), e2c2e)) v2c = self._get_index_field(reader, GridFile.OffsetName.V2C) v2e = self._get_index_field(reader, GridFile.OffsetName.V2E) v2e2v = self._get_index_field(reader, GridFile.OffsetName.V2E2V) c2e2c = self._get_index_field(reader, GridFile.OffsetName.C2E2C) - c2e2c0 = np.column_stack((c2e2c, (np.asarray(range(c2e2c.shape[0]))))) + c2e2c0 = np.column_stack((np.asarray(range(c2e2c.shape[0])), c2e2c)) ( start_indices, end_indices, diff --git a/model/common/tests/grid_tests/test_grid_manager.py b/model/common/tests/grid_tests/test_grid_manager.py index 098b2c767c..6e80133759 100644 --- a/model/common/tests/grid_tests/test_grid_manager.py +++ b/model/common/tests/grid_tests/test_grid_manager.py @@ -497,6 +497,23 @@ def test_gridmanager_eval_c2e2c(caplog, grid_savepoint, grid_file): ) +@pytest.mark.datatest +@pytest.mark.with_netcdf +@pytest.mark.parametrize( + "grid_file, experiment", + [(REGIONAL_EXPERIMENT, REGIONAL_EXPERIMENT), (R02B04_GLOBAL, GLOBAL_EXPERIMENT)], +) +def test_gridmanager_eval_c2e2cO(caplog, grid_savepoint, grid_file): + caplog.set_level(logging.DEBUG) + file = resolve_file_from_gridfile_name(grid_file) + grid = init_grid_manager(file).get_grid() + serialized_grid = grid_savepoint.construct_icon_grid(on_gpu=False) + assert np.allclose( + grid.get_offset_provider("C2E2CO").table, + serialized_grid.get_offset_provider("C2E2CO").table, + ) + + # e2c2e (e2c2eo) - diamond: exists in serial, simple_mesh @pytest.mark.datatest @pytest.mark.with_netcdf @@ -508,15 +525,19 @@ def test_gridmanager_eval_e2c2e(caplog, grid_savepoint, grid_file): caplog.set_level(logging.DEBUG) file = resolve_file_from_gridfile_name(grid_file) grid = init_grid_manager(file).get_grid() - serialized_e2c2e = grid_savepoint.e2c2e()[0 : grid.num_cells, :] + serialized_grid = grid_savepoint.construct_icon_grid(on_gpu=False) + serialized_e2c2e = serialized_grid.get_offset_provider("E2C2E").table + serialized_e2c2eO = serialized_grid.get_offset_provider("E2C2EO").table assert_invalid_indices(serialized_e2c2e, grid_file) e2c2e_table = grid.get_offset_provider("E2C2E").table + e2c2e0_table = grid.get_offset_provider("E2C2EO").table assert_invalid_indices(e2c2e_table, grid_file) # ICON calculates diamond edges only from rl_start = 2 (lateral_boundary(EdgeDim) + 1 for # boundaries all values are INVALID even though the half diamond exists (see mo_model_domimp_setup.f90 ll 163ff.) assert_unless_invalid(e2c2e_table, serialized_e2c2e) + assert_unless_invalid(e2c2e0_table, serialized_e2c2eO) def assert_unless_invalid(table, serialized_ref):