Skip to content

Commit

Permalink
fix the order of the origin to be in first place to match ICON index … (
Browse files Browse the repository at this point in the history
#439)

* fix the order of the origin to be in first place to match ICON index ordering in coefficients

* pre-commit
  • Loading branch information
halungge authored Apr 11, 2024
1 parent 4254dfb commit 7d61b04
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions model/common/src/icon4py/model/common/grid/grid_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 22 additions & 1 deletion model/common/tests/grid_tests/test_grid_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 7d61b04

Please sign in to comment.