Skip to content

Commit

Permalink
moved test
Browse files Browse the repository at this point in the history
  • Loading branch information
nfarabullini committed Apr 24, 2024
1 parent 53c5ac6 commit 7928040
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@

import numpy as np
import pytest
from gt4py.next import as_field

from icon4py.model.common.dimension import (
E2CDim,
E2VDim,
EdgeDim,
V2CDim,
V2EDim,
VertexDim,
)
from icon4py.model.common.dimension import E2CDim, E2VDim, EdgeDim, KDim, V2CDim, V2EDim, VertexDim
from icon4py.model.common.grid.horizontal import (
HorizontalMarkerIndex,
_compute_cells2verts,
)
from icon4py.model.common.interpolation.interpolation_fields import (
compute_c_lin_e,
compute_cells_aw_verts,
compute_ddxnt_z_full,
compute_ddxt_z_half_e,
)
from icon4py.model.common.test_utils.datatest_fixtures import ( # noqa: F401 # import fixtures from test_utils package
data_provider,
Expand All @@ -49,6 +46,7 @@
processor_props,
ranked_data_path,
)
from icon4py.model.common.test_utils.helpers import zero_field


@pytest.mark.datatest
Expand Down Expand Up @@ -106,3 +104,63 @@ def test_compute_cells_aw_verts(
)
cells_aw_verts_ref = interpolation_savepoint.c_intp().asnumpy()
assert np.allclose(cells_aw_verts, cells_aw_verts_ref)


@pytest.mark.datatest
def test_compute_ddxt_z_full_e(
grid_savepoint, interpolation_savepoint, icon_grid, metrics_savepoint
):
z_ifc = metrics_savepoint.z_ifc()
tangent_orientation = grid_savepoint.tangent_orientation()
inv_primal_edge_length = grid_savepoint.inverse_primal_edge_lengths()
ddxt_z_full_ref = metrics_savepoint.ddxt_z_full().asnumpy()
horizontal_start_vertex = icon_grid.get_start_index(
VertexDim,
HorizontalMarkerIndex.lateral_boundary(VertexDim) + 1,
)
horizontal_end_vertex = icon_grid.get_end_index(
VertexDim,
HorizontalMarkerIndex.lateral_boundary(VertexDim) - 1,
)
horizontal_start_edge = icon_grid.get_start_index(
EdgeDim,
HorizontalMarkerIndex.lateral_boundary(EdgeDim) + 2,
)
horizontal_end_edge = icon_grid.get_end_index(
EdgeDim,
HorizontalMarkerIndex.lateral_boundary(EdgeDim) - 1,
)
vertical_start = 0
vertical_end = icon_grid.num_levels + 1
cells_aw_verts = interpolation_savepoint.c_intp().asnumpy()
z_ifv = zero_field(icon_grid, VertexDim, KDim, extend={KDim: 1})
_compute_cells2verts(
z_ifc,
as_field((VertexDim, V2CDim), cells_aw_verts),
out=z_ifv,
offset_provider={"V2C": icon_grid.get_offset_provider("V2C")},
domain={
VertexDim: (horizontal_start_vertex, horizontal_end_vertex),
KDim: (vertical_start, vertical_end),
},
)
ddxt_z_half_e = zero_field(icon_grid, EdgeDim, KDim, extend={KDim: 1})
compute_ddxt_z_half_e(
z_ifv=z_ifv,
inv_primal_edge_length=inv_primal_edge_length,
tangent_orientation=tangent_orientation,
ddxt_z_half_e=ddxt_z_half_e,
horizontal_lower=horizontal_start_edge,
horizontal_upper=horizontal_end_edge,
vertical_lower=vertical_start,
vertical_upper=vertical_end,
offset_provider={"E2V": icon_grid.get_offset_provider("E2V")},
)
ddxt_z_full = zero_field(icon_grid, EdgeDim, KDim)
compute_ddxnt_z_full(
z_ddxnt_z_half_e=ddxt_z_half_e,
ddxn_z_full=ddxt_z_full,
offset_provider={"Koff": icon_grid.get_offset_provider("Koff")},
)

assert np.allclose(ddxt_z_full.asnumpy(), ddxt_z_full_ref)
64 changes: 1 addition & 63 deletions model/common/tests/metric_tests/test_metric_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
from gt4py.next.ffront.fbuiltins import int32

from icon4py.model.common import constants
from icon4py.model.common.dimension import CellDim, EdgeDim, KDim, V2CDim, VertexDim
from icon4py.model.common.dimension import CellDim, EdgeDim, KDim
from icon4py.model.common.grid.horizontal import (
HorizontalMarkerIndex,
_compute_cells2verts,
compute_cells2edges,
)
from icon4py.model.common.interpolation.interpolation_fields import (
compute_ddxnt_z_full,
compute_ddxt_z_half_e,
)
from icon4py.model.common.metrics.metric_fields import (
compute_coeff_dwdz,
Expand Down Expand Up @@ -331,63 +329,3 @@ def test_compute_ddxn_z_full_e(
)

assert np.allclose(ddxn_z_full.asnumpy(), ddxn_z_full_ref)


@pytest.mark.datatest
def test_compute_ddxt_z_full_e(
grid_savepoint, interpolation_savepoint, icon_grid, metrics_savepoint
):
z_ifc = metrics_savepoint.z_ifc()
tangent_orientation = grid_savepoint.tangent_orientation()
inv_primal_edge_length = grid_savepoint.inverse_primal_edge_lengths()
ddxt_z_full_ref = metrics_savepoint.ddxt_z_full().asnumpy()
horizontal_start_vertex = icon_grid.get_start_index(
VertexDim,
HorizontalMarkerIndex.lateral_boundary(VertexDim) + 1,
)
horizontal_end_vertex = icon_grid.get_end_index(
VertexDim,
HorizontalMarkerIndex.lateral_boundary(VertexDim) - 1,
)
horizontal_start_edge = icon_grid.get_start_index(
EdgeDim,
HorizontalMarkerIndex.lateral_boundary(EdgeDim) + 2,
)
horizontal_end_edge = icon_grid.get_end_index(
EdgeDim,
HorizontalMarkerIndex.lateral_boundary(EdgeDim) - 1,
)
vertical_start = 0
vertical_end = icon_grid.num_levels + 1
cells_aw_verts = interpolation_savepoint.c_intp().asnumpy()
z_ifv = zero_field(icon_grid, VertexDim, KDim, extend={KDim: 1})
_compute_cells2verts(
z_ifc,
as_field((VertexDim, V2CDim), cells_aw_verts),
out=z_ifv,
offset_provider={"V2C": icon_grid.get_offset_provider("V2C")},
domain={
VertexDim: (horizontal_start_vertex, horizontal_end_vertex),
KDim: (vertical_start, vertical_end),
},
)
ddxt_z_half_e = zero_field(icon_grid, EdgeDim, KDim, extend={KDim: 1})
compute_ddxt_z_half_e(
z_ifv=z_ifv,
inv_primal_edge_length=inv_primal_edge_length,
tangent_orientation=tangent_orientation,
ddxt_z_half_e=ddxt_z_half_e,
horizontal_lower=horizontal_start_edge,
horizontal_upper=horizontal_end_edge,
vertical_lower=vertical_start,
vertical_upper=vertical_end,
offset_provider={"E2V": icon_grid.get_offset_provider("E2V")},
)
ddxt_z_full = zero_field(icon_grid, EdgeDim, KDim)
compute_ddxnt_z_full(
z_ddxnt_z_half_e=ddxt_z_half_e,
ddxn_z_full=ddxt_z_full,
offset_provider={"Koff": icon_grid.get_offset_provider("Koff")},
)

assert np.allclose(ddxt_z_full.asnumpy(), ddxt_z_full_ref)

0 comments on commit 7928040

Please sign in to comment.