Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rbf interpolation stencils improvement #709

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
310612a
fix imports in geometry.py
halungge Nov 14, 2024
4ddfc19
setting up empty factory
halungge Nov 14, 2024
f56134e
add xfail for stencils that need embedded backend
halungge Nov 14, 2024
dfd321c
register first fields (WIP)
halungge Nov 14, 2024
3a00e64
Merge branch 'main' into interpolation_fields_factory
halungge Nov 19, 2024
8788bbb
add first field to interpolation factory,
halungge Nov 19, 2024
f1aab49
FieldOperator provider WIP
halungge Nov 21, 2024
f7423e0
simplify field_source protocol
halungge Nov 25, 2024
cb1565f
pre-commit
halungge Nov 25, 2024
c9a76e7
xfail test for in that must be run on embedded
halungge Nov 25, 2024
7cc9ea5
add composite source
halungge Nov 26, 2024
6e05d08
read cell normal orientation
halungge Nov 26, 2024
e327e47
add geofac_rot, geofac_div, and missing geometry fields (not computed)
halungge Nov 26, 2024
042e8e5
add convenience functions for
halungge Nov 26, 2024
91742e3
Merge branch 'import_array_ns_in_fieldallocation' into interpolation_…
halungge Nov 26, 2024
3ce3657
merge main
halungge Nov 28, 2024
54abef8
merge main
halungge Nov 29, 2024
2df1e38
add c_lin_e computation (numpy) to interpolation_factory.py
halungge Dec 2, 2024
12ebc30
register geofac_n2s, workaround composite source
halungge Dec 2, 2024
8e065b1
make domain simple sequence of dims in NumpyFieldProvider
halungge Dec 2, 2024
32029da
register geofac_grdiv (WIP)
halungge Dec 3, 2024
00f4756
improve and fix doc string in factory
halungge Dec 3, 2024
db9fc0d
fix import in grid_test/utils.py
halungge Dec 3, 2024
d5b0c28
Merge branch 'main' into interpolation_fields_factory
halungge Dec 3, 2024
f6c32a4
fix import of grid_file constant
halungge Dec 3, 2024
d16d759
add geofac_grg
halungge Dec 3, 2024
db7c6b9
merge main
halungge Dec 4, 2024
faa19a2
merge interpolation_factory
halungge Dec 5, 2024
144e342
fix errors from merge of interpolation factory
halungge Dec 5, 2024
b1d1be8
rbf (WIP 1)
halungge Dec 10, 2024
010f144
fixing geofac_grg (WIP 2)
halungge Dec 12, 2024
2422e16
merge main
halungge Jan 14, 2025
5181415
merge main
halungge Jan 17, 2025
d7aab60
add cartesian coordinates of cell centers
halungge Jan 22, 2025
a83c89b
reduce rbf_vec_coeff to field sizes
halungge Jan 22, 2025
fb21d73
rbf testing/debug
halungge Jan 22, 2025
6f49afd
Merge branch 'main' into rbf_interpolation_stencils_improvement
halungge Jan 22, 2025
1d3aa5c
rbf testing/debug WIP
halungge Jan 22, 2025
f07c7e5
merge main
halungge Apr 4, 2025
7c4db74
remove duplicate test
halungge Apr 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,10 @@ def _validate(self):
raise NotImplementedError("divdamp_order can only be 24")

if self.divdamp_type == DivergenceDampingType.TWO_DIMENSIONAL:
raise NotImplementedError("`DivergenceDampingType.TWO_DIMENSIONAL` (2) is not yet implemented")
raise NotImplementedError(
"`DivergenceDampingType.TWO_DIMENSIONAL` (2) is not yet implemented"
)


class NonHydrostaticParams:
"""Calculates derived quantities depending on the NonHydrostaticConfig."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def reference(
normal_wind_advective_tendency_cp = normal_wind_advective_tendency.copy()
k = np.arange(nlev)

upward_vorticity_at_vertices = mo_math_divrot_rot_vertex_ri_dsl_numpy(connectivities, vn, geofac_rot)
upward_vorticity_at_vertices = mo_math_divrot_rot_vertex_ri_dsl_numpy(
connectivities, vn, geofac_rot
)

normal_wind_advective_tendency = compute_advective_normal_wind_tendency_numpy(
connectivities,
Expand All @@ -79,7 +81,7 @@ def reference(
vn_on_half_levels,
ddqz_z_full_e,
)

condition = (np.maximum(3, nrdmax - 2) - 1 <= k) & (k < nlev - 4)
normal_wind_advective_tendency_extra_diffu = (
add_extra_diffusion_for_normal_wind_tendency_approaching_cfl_numpy(
Expand Down
28 changes: 28 additions & 0 deletions model/common/src/icon4py/model/common/grid/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,34 @@ def _register_computed_fields(self):
pairs=(("u_cell_1", "u_cell_2"), ("v_cell_1", "v_cell_2")),
)
self.register_provider(tangent_cell_wrapper)
cartesian_edge_centers = factory.FieldOperatorProvider(
func=math_helpers.geographical_to_cartesian_on_edges.with_backend(self.backend),
domain=(dims.EdgeDim,),
fields={
attrs.EDGE_CENTER_X: attrs.EDGE_CENTER_X,
attrs.EDGE_CENTER_Y: attrs.EDGE_CENTER_Y,
attrs.EDGE_CENTER_Z: attrs.EDGE_CENTER_Z,
},
deps={
"lat": attrs.EDGE_LAT,
"lon": attrs.EDGE_LON,
},
)
self.register_provider(cartesian_edge_centers)
cartesian_cell_centers = factory.FieldOperatorProvider(
func=math_helpers.geographical_to_cartesian_on_cells.with_backend(self.backend),
domain=(dims.CellDim,),
fields={
attrs.CELL_CENTER_X: attrs.CELL_CENTER_X,
attrs.CELL_CENTER_Y: attrs.CELL_CENTER_Y,
attrs.CELL_CENTER_Z: attrs.CELL_CENTER_Z,
},
deps={
"lat": attrs.CELL_LAT,
"lon": attrs.CELL_LON,
},
)
self.register_provider(cartesian_cell_centers)

def _inverse_field_provider(self, field_name: str):
meta = attrs.metadata_for_inverse(attrs.attrs[field_name])
Expand Down
57 changes: 57 additions & 0 deletions model/common/src/icon4py/model/common/grid/geometry_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

CELL_LON: Final[str] = "grid_longitude_of_cell_center"
CELL_LAT: Final[str] = "grid_latitude_of_cell_center"
CELL_CENTER_X: Final[str] = "x_component_of_cell_center"
CELL_CENTER_Y: Final[str] = "y_component_of_cell_center"

CELL_CENTER_Z: Final[str] = "z_component_of_cell_center"

CELL_AREA: Final[str] = "cell_area"
EDGE_AREA: Final[str] = "edge_area"
DUAL_AREA: Final[str] = "dual_area"
Expand Down Expand Up @@ -62,6 +67,10 @@
EDGE_NORMAL_VERTEX_V: Final[str] = "northward_component_of_edge_normal_on_vertex"
EDGE_NORMAL_CELL_U: Final[str] = "eastward_component_of_edge_normal_on_cell"
EDGE_NORMAL_CELL_V: Final[str] = "northward_component_of_edge_normal_on_cell"
EDGE_CENTER_X: Final[str] = "x_coordinate_of_edge_center"
EDGE_CENTER_Y: Final[str] = "y_coordinate_of_edge_center"
EDGE_CENTER_Z: Final[str] = "z_coordinate_of_edge_center"


attrs: dict[str, model.FieldMetaData] = {
CELL_LAT: dict(
Expand Down Expand Up @@ -169,6 +178,30 @@
icon_var_name="t_grid_cells%area",
dtype=ta.wpfloat,
),
CELL_CENTER_X: dict(
standard_name=CELL_CENTER_X,
long_name="x component of cell center",
units="",
dims=(dims.CellDim,),
icon_var_name="t_grid_cells%%cartesian_center%x(1)",
dtype=ta.wpfloat,
),
CELL_CENTER_Y: dict(
standard_name=CELL_CENTER_Y,
long_name="y-component of cell center",
units="",
dims=(dims.CellDim,),
icon_var_name="t_grid_cells%%cartesian_center%x(2)",
dtype=ta.wpfloat,
),
CELL_CENTER_Z: dict(
standard_name=CELL_CENTER_Z,
long_name="z-component of cell center",
units="",
dims=(dims.CellDim,),
icon_var_name="t_grid_cells%%cartesian_center%x(3)",
dtype=ta.wpfloat,
),
DUAL_AREA: dict(
standard_name=DUAL_AREA,
long_name="area of the dual grid cell (hexagon cell)",
Expand Down Expand Up @@ -345,6 +378,30 @@
icon_var_name="ptr_patch%edges%dual_normal%v2",
dtype=ta.wpfloat,
),
EDGE_CENTER_X: dict(
standard_name=EDGE_CENTER_X,
long_name="x component of cartesian coordinates of edge centers",
units="1",
dims=(dims.EdgeDim,),
icon_var_name="t_grid_edges%cartesian_center%x(1)",
dtype=ta.wpfloat,
),
EDGE_CENTER_Y: dict(
standard_name=EDGE_CENTER_Y,
long_name="x component of cartesian coordinates of edge centers",
units="1",
dims=(dims.EdgeDim,),
icon_var_name="t_grid_edges%cartesian_center%x(2)",
dtype=ta.wpfloat,
),
EDGE_CENTER_Z: dict(
standard_name=EDGE_CENTER_Z,
long_name="z component of cartesian coordinates of edge centers",
units="1",
dims=(dims.EdgeDim,),
icon_var_name="t_grid_edges%cartesian_center%x(3)",
dtype=ta.wpfloat,
),
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from icon4py.model.common import dimension as dims, field_type_aliases as fa, type_alias as ta
from icon4py.model.common.dimension import E2C, E2C2V, E2V, EdgeDim
from icon4py.model.common.math.helpers import (
arc_length,
arc_length_on_edges,
cross_product_on_edges,
geographical_to_cartesian_on_edges,
geographical_to_cartesian_on_vertex,
Expand Down Expand Up @@ -362,7 +362,7 @@ def cell_center_arc_distance(
x0, y0, z0 = geographical_to_cartesian_on_edges(lat_neighbor_0, lon_neighbor_0)
x1, y1, z1 = geographical_to_cartesian_on_edges(lat_neighbor_1, lon_neighbor_1)
# (xi, yi, zi) are normalized by construction
arc = arc_length(x0, x1, y0, y1, z0, z1, radius)
arc = arc_length_on_edges(x0, x1, y0, y1, z0, z1, radius)
return arc


Expand Down Expand Up @@ -406,7 +406,7 @@ def arc_distance_of_far_edges_in_diamond(
z3 = z(E2C2V[3])
# (xi, yi, zi) are normalized by construction

far_vertex_vertex_length = arc_length(x2, x3, y2, y3, z2, z3, radius)
far_vertex_vertex_length = arc_length_on_edges(x2, x3, y2, y3, z2, z3, radius)
return far_vertex_vertex_length


Expand Down Expand Up @@ -440,7 +440,7 @@ def edge_length(
z1 = z(E2V[1])
# (xi, yi, zi) are normalized by construction

length = arc_length(x0, x1, y0, y1, z0, z1, radius)
length = arc_length_on_edges(x0, x1, y0, y1, z0, z1, radius)
return length


Expand Down
Loading