-
Notifications
You must be signed in to change notification settings - Fork 8
Combine compute_perturbed_quantities_and_interpolation further #896
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
base: main
Are you sure you want to change the base?
Changes from 141 commits
a460d50
84abc04
50e8365
ad8d449
aacd35b
d042c98
ba94c10
4571a34
3dcdd34
367ba1f
c4b33c3
bdc3296
5836fbf
7d041d5
a30e5da
ca2f4f2
36f5583
510dfae
3824293
1c899eb
937128b
c1bfd1c
02d031f
bddb09d
48c9b08
4ea9499
70e1720
1479e80
cf730e8
47d647a
3289b38
f3921e7
6368b76
9fd8a3f
1f88e8f
123b25b
ab89a17
66855eb
d39c9f1
4d3a6d6
8ad81e4
1129847
c6de2d1
9f1b6a6
3207b99
171ffd7
2728bfd
a1cb8f0
ffb002d
29718d6
8b1bd03
205c1cb
a879762
070dc87
34d5a76
18e3817
c525572
f1cfa28
7225d41
534d31d
6ee0419
442555b
da6c9eb
33149f3
6030243
01d87c3
62ff36c
f49b74b
c755cd8
f1a627d
1e092ba
28d695a
9cd760a
ad34020
2481f55
efa6df4
217333f
3dc8b0e
db94055
7cd8f81
706335a
7e57d03
8df6296
420fe3a
d018cae
7a13046
05968bb
eb720fe
f0e6f53
36f54e8
e8c1065
94021c0
4407d5c
0e26652
565e350
05a7fbe
e96911c
6c3eccb
2eb5876
d1c6a9e
4d6e2d0
6e60f81
7923021
edd7e4f
4239768
90bba1b
dec905e
726b458
a7fe7b9
fa9d58e
e6d04ee
96ea219
e4b0ea9
07d74e8
879a35d
4adfa21
c96773e
b8e07bf
7ce3f5e
c018408
de1220c
9fe3ce4
12f1a19
84163b1
d04db94
6705666
8368286
8d9bb39
ac05bdf
fe38b17
9b308a1
3ff33cf
45bdaff
d05ccf2
1d88f3c
1ecd4c1
2a7a46e
7f8a6e0
e8c5f26
83315ec
b3f471f
33ebde4
02f4c70
c9ba07d
a912450
924e774
73921e7
05a535e
07d5b72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
| from typing import Final | ||
|
|
||
| import gt4py.next as gtx | ||
| from gt4py.next import astype, broadcast, maximum | ||
| from gt4py.next import astype, maximum | ||
| from gt4py.next.experimental import concat_where | ||
|
|
||
| from icon4py.model.atmosphere.dycore.dycore_states import HorizontalPressureDiscretizationType | ||
|
|
@@ -32,12 +32,6 @@ | |
| from icon4py.model.atmosphere.dycore.stencils.extrapolate_temporally_exner_pressure import ( | ||
| _extrapolate_temporally_exner_pressure, | ||
| ) | ||
| from icon4py.model.atmosphere.dycore.stencils.init_cell_kdim_field_with_zero_wp import ( | ||
| _init_cell_kdim_field_with_zero_wp, | ||
| ) | ||
| from icon4py.model.atmosphere.dycore.stencils.init_two_cell_kdim_fields_with_zero_vp import ( | ||
| _init_two_cell_kdim_fields_with_zero_vp, | ||
| ) | ||
| from icon4py.model.atmosphere.dycore.stencils.interpolate_to_surface import _interpolate_to_surface | ||
| from icon4py.model.common import dimension as dims, field_type_aliases as fa, type_alias as ta | ||
| from icon4py.model.common.dimension import Koff | ||
|
|
@@ -74,6 +68,9 @@ def _calculate_pressure_buoyancy_acceleration_at_cells_on_half_levels( | |
|
|
||
| @gtx.field_operator | ||
| def _compute_perturbed_quantities_and_interpolation( | ||
| time_extrapolation_parameter_for_exner: fa.CellKField[ta.vpfloat], | ||
| current_exner: fa.CellKField[ta.wpfloat], | ||
| reference_exner_at_cells_on_model_levels: fa.CellKField[ta.vpfloat], | ||
| current_rho: fa.CellKField[ta.wpfloat], | ||
| reference_rho_at_cells_on_model_levels: fa.CellKField[ta.wpfloat], | ||
| current_theta_v: fa.CellKField[ta.wpfloat], | ||
|
|
@@ -86,27 +83,41 @@ def _compute_perturbed_quantities_and_interpolation( | |
| pressure_buoyancy_acceleration_at_cells_on_half_levels: fa.CellKField[ta.vpfloat], | ||
| rho_at_cells_on_half_levels: fa.CellKField[ta.wpfloat], | ||
| exner_at_cells_on_half_levels: fa.CellKField[ta.vpfloat], | ||
| temporal_extrapolation_of_perturbed_exner: fa.CellKField[ta.vpfloat], | ||
| theta_v_at_cells_on_half_levels: fa.CellKField[ta.wpfloat], | ||
| wgtfacq_c: fa.CellKField[ta.vpfloat], | ||
| reference_theta_at_cells_on_half_levels: fa.CellKField[ta.vpfloat], | ||
| igradp_method: gtx.int32, | ||
| nflatlev: gtx.int32, | ||
| surface_level: gtx.int32, | ||
| ) -> tuple[ | ||
| fa.CellKField[ta.vpfloat], | ||
| fa.CellKField[ta.vpfloat], | ||
| fa.CellKField[ta.vpfloat], | ||
| fa.CellKField[ta.wpfloat], | ||
| fa.CellKField[ta.wpfloat], | ||
| fa.CellKField[ta.vpfloat], | ||
| fa.CellKField[ta.vpfloat], | ||
| fa.CellKField[ta.wpfloat], | ||
| fa.CellKField[ta.wpfloat], | ||
| fa.CellKField[ta.wpfloat], | ||
| fa.CellKField[ta.wpfloat], | ||
| fa.CellKField[ta.wpfloat], | ||
| ]: | ||
| ( | ||
| temporal_extrapolation_of_perturbed_exner, | ||
| perturbed_exner_at_cells_on_model_levels, | ||
| ) = _extrapolate_temporally_exner_pressure( | ||
| exner_exfac=time_extrapolation_parameter_for_exner, | ||
| exner=current_exner, | ||
| exner_ref_mc=reference_exner_at_cells_on_model_levels, | ||
| exner_pr=perturbed_exner_at_cells_on_model_levels, | ||
| ) | ||
|
|
||
| exner_at_cells_on_half_levels = ( | ||
| concat_where( | ||
| (maximum(1, nflatlev) <= dims.KDim), | ||
| dims.KDim < surface_level - 1, | ||
| _interpolate_cell_field_to_half_levels_vp( | ||
| wgtfac_c=wgtfac_c, interpolant=temporal_extrapolation_of_perturbed_exner | ||
| ), | ||
| exner_at_cells_on_half_levels, | ||
| _interpolate_to_surface( | ||
| wgtfacq_c=wgtfacq_c, interpolant=temporal_extrapolation_of_perturbed_exner | ||
| ), | ||
| ) | ||
|
Comment on lines
108
to
116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be a named operator (it's repeated below). What should be its name?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we shouldn't change this name
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apologies, let me rephrase: it is my personal opinion that this |
||
| if igradp_method == horzpres_discr_type.TAYLOR_HYDRO | ||
| else exner_at_cells_on_half_levels | ||
|
|
@@ -131,19 +142,22 @@ def _compute_perturbed_quantities_and_interpolation( | |
| wgtfac_c_wp = astype(wgtfac_c, wpfloat) | ||
|
|
||
| perturbed_theta_v_at_cells_on_half_levels = concat_where( | ||
| dims.KDim >= 1, | ||
| dims.KDim < surface_level - 1, | ||
| _interpolate_cell_field_to_half_levels_vp( | ||
| wgtfac_c=wgtfac_c, interpolant=perturbed_theta_v_at_cells_on_model_levels | ||
| ), | ||
| broadcast(0.0, (dims.CellDim, dims.KDim)), | ||
| _interpolate_to_surface( | ||
| wgtfacq_c=wgtfacq_c, interpolant=perturbed_theta_v_at_cells_on_model_levels | ||
| ), | ||
| ) | ||
|
Comment on lines
135
to
143
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the same operator again
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, we keep the same name |
||
|
|
||
| theta_v_at_cells_on_half_levels = concat_where( | ||
| dims.KDim >= 1, | ||
| dims.KDim < surface_level - 1, | ||
| _interpolate_cell_field_to_half_levels_wp( | ||
| wgtfac_c=wgtfac_c_wp, interpolant=current_theta_v | ||
| ), | ||
| theta_v_at_cells_on_half_levels, | ||
| reference_theta_at_cells_on_half_levels + perturbed_theta_v_at_cells_on_half_levels, | ||
| # theta_v_at_cells_on_half_levels, | ||
| ) | ||
|
|
||
| ddqz_z_half_wp = astype(ddqz_z_half, wpfloat) | ||
|
|
@@ -170,30 +184,31 @@ def _compute_perturbed_quantities_and_interpolation( | |
| perturbed_theta_v_at_cells_on_half_levels, | ||
| theta_v_at_cells_on_half_levels, | ||
| pressure_buoyancy_acceleration_at_cells_on_half_levels, | ||
| temporal_extrapolation_of_perturbed_exner, | ||
| ) | ||
|
|
||
|
|
||
| @gtx.field_operator | ||
| def _surface_computations( | ||
| wgtfacq_c: fa.CellKField[ta.wpfloat], | ||
| exner_at_cells_on_half_levels: fa.CellKField[ta.vpfloat], | ||
| igradp_method: gtx.int32, | ||
| ) -> tuple[ | ||
| fa.CellKField[ta.vpfloat], | ||
| fa.CellKField[ta.vpfloat], | ||
| ]: | ||
| temporal_extrapolation_of_perturbed_exner = _init_cell_kdim_field_with_zero_wp() | ||
| def _set_theta_v_and_exner_on_surface_level( | ||
| temporal_extrapolation_of_perturbed_exner: fa.CellKField[vpfloat], | ||
| wgtfacq_c: fa.CellKField[vpfloat], | ||
| perturbed_theta_v_at_cells_on_model_levels: fa.CellKField[vpfloat], | ||
| reference_theta_at_cells_on_half_levels: fa.CellKField[vpfloat], | ||
| ) -> tuple[fa.CellKField[vpfloat], fa.CellKField[wpfloat], fa.CellKField[vpfloat]]: | ||
| perturbed_theta_v_at_cells_on_half_levels = _interpolate_to_surface( | ||
| wgtfacq_c=wgtfacq_c, interpolant=perturbed_theta_v_at_cells_on_model_levels | ||
| ) | ||
| theta_v_at_cells_on_half_levels = ( | ||
| reference_theta_at_cells_on_half_levels + perturbed_theta_v_at_cells_on_half_levels | ||
| ) | ||
|
|
||
| exner_at_cells_on_half_levels = ( | ||
| _interpolate_to_surface( | ||
| wgtfacq_c=wgtfacq_c, interpolant=temporal_extrapolation_of_perturbed_exner | ||
| ) | ||
| if igradp_method == horzpres_discr_type.TAYLOR_HYDRO | ||
| else exner_at_cells_on_half_levels | ||
| exner_at_cells_on_half_levels = _interpolate_to_surface( | ||
| wgtfacq_c=wgtfacq_c, interpolant=temporal_extrapolation_of_perturbed_exner | ||
| ) | ||
|
|
||
| return ( | ||
| temporal_extrapolation_of_perturbed_exner, | ||
| perturbed_theta_v_at_cells_on_half_levels, | ||
| astype(theta_v_at_cells_on_half_levels, wpfloat), | ||
| exner_at_cells_on_half_levels, | ||
| ) | ||
|
|
||
|
|
@@ -217,7 +232,7 @@ def _compute_first_and_second_vertical_derivative_of_exner( | |
| ]: | ||
| ddz_of_temporal_extrapolation_of_perturbed_exner_on_model_levels = ( | ||
| concat_where( | ||
| (nflatlev <= dims.KDim), | ||
| nflatlev <= dims.KDim, | ||
| _compute_first_vertical_derivative_at_cells( | ||
| exner_at_cells_on_half_levels, inv_ddqz_z_full | ||
| ), | ||
|
|
@@ -229,7 +244,7 @@ def _compute_first_and_second_vertical_derivative_of_exner( | |
|
|
||
| d2dz2_of_temporal_extrapolation_of_perturbed_exner_on_model_levels = ( | ||
| concat_where( | ||
| (nflat_gradp <= dims.KDim), | ||
| nflat_gradp <= dims.KDim, | ||
| -vpfloat("0.5") | ||
| * ( | ||
| ( | ||
|
|
@@ -251,31 +266,6 @@ def _compute_first_and_second_vertical_derivative_of_exner( | |
| ) | ||
|
|
||
|
|
||
| @gtx.field_operator | ||
| def _set_theta_v_and_exner_on_surface_level( | ||
| temporal_extrapolation_of_perturbed_exner: fa.CellKField[vpfloat], | ||
| wgtfacq_c: fa.CellKField[vpfloat], | ||
| perturbed_theta_v_at_cells_on_model_levels: fa.CellKField[vpfloat], | ||
| reference_theta_at_cells_on_half_levels: fa.CellKField[vpfloat], | ||
| ) -> tuple[fa.CellKField[vpfloat], fa.CellKField[wpfloat], fa.CellKField[vpfloat]]: | ||
| perturbed_theta_v_at_cells_on_half_levels = _interpolate_to_surface( | ||
| wgtfacq_c=wgtfacq_c, interpolant=perturbed_theta_v_at_cells_on_model_levels | ||
| ) | ||
| theta_v_at_cells_on_half_levels = ( | ||
| reference_theta_at_cells_on_half_levels + perturbed_theta_v_at_cells_on_half_levels | ||
| ) | ||
|
|
||
| exner_at_cells_on_half_levels = _interpolate_to_surface( | ||
| wgtfacq_c=wgtfacq_c, interpolant=temporal_extrapolation_of_perturbed_exner | ||
| ) | ||
|
|
||
| return ( | ||
| perturbed_theta_v_at_cells_on_half_levels, | ||
| astype(theta_v_at_cells_on_half_levels, wpfloat), | ||
| exner_at_cells_on_half_levels, | ||
| ) | ||
|
|
||
|
|
||
| @gtx.program(grid_type=gtx.GridType.UNSTRUCTURED) | ||
| def compute_perturbed_quantities_and_interpolation( | ||
| temporal_extrapolation_of_perturbed_exner: fa.CellKField[ta.vpfloat], | ||
|
|
@@ -374,41 +364,11 @@ def compute_perturbed_quantities_and_interpolation( | |
| - ddz_of_temporal_extrapolation_of_perturbed_exner_on_model_level | ||
| - d2dz2_of_temporal_extrapolation_of_perturbed_exner_on_model_levels | ||
| """ | ||
| _init_two_cell_kdim_fields_with_zero_vp( | ||
| out=(perturbed_rho_at_cells_on_model_levels, perturbed_theta_v_at_cells_on_model_levels), | ||
| domain={ | ||
| dims.CellDim: (start_cell_lateral_boundary, start_cell_lateral_boundary_level_3), | ||
| dims.KDim: (model_top, surface_level - 1), | ||
| }, | ||
| ) | ||
|
|
||
nfarabullini marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _extrapolate_temporally_exner_pressure( | ||
| exner_exfac=time_extrapolation_parameter_for_exner, | ||
| exner=current_exner, | ||
| exner_ref_mc=reference_exner_at_cells_on_model_levels, | ||
| exner_pr=perturbed_exner_at_cells_on_model_levels, | ||
| out=(temporal_extrapolation_of_perturbed_exner, perturbed_exner_at_cells_on_model_levels), | ||
| domain={ | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (model_top, surface_level - 1), | ||
| }, | ||
| ) | ||
|
|
||
| _surface_computations( | ||
| wgtfacq_c=wgtfacq_c, | ||
| exner_at_cells_on_half_levels=exner_at_cells_on_half_levels, | ||
| igradp_method=igradp_method, | ||
| out=( | ||
| temporal_extrapolation_of_perturbed_exner, | ||
| exner_at_cells_on_half_levels, | ||
| ), | ||
| domain={ | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (surface_level - 1, surface_level), | ||
| }, | ||
| ) | ||
|
|
||
| _compute_perturbed_quantities_and_interpolation( | ||
nfarabullini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| time_extrapolation_parameter_for_exner=time_extrapolation_parameter_for_exner, | ||
| current_exner=current_exner, | ||
| reference_exner_at_cells_on_model_levels=reference_exner_at_cells_on_model_levels, | ||
| current_rho=current_rho, | ||
| reference_rho_at_cells_on_model_levels=reference_rho_at_cells_on_model_levels, | ||
| current_theta_v=current_theta_v, | ||
|
|
@@ -421,10 +381,11 @@ def compute_perturbed_quantities_and_interpolation( | |
| pressure_buoyancy_acceleration_at_cells_on_half_levels=pressure_buoyancy_acceleration_at_cells_on_half_levels, | ||
| rho_at_cells_on_half_levels=rho_at_cells_on_half_levels, | ||
| exner_at_cells_on_half_levels=exner_at_cells_on_half_levels, | ||
| temporal_extrapolation_of_perturbed_exner=temporal_extrapolation_of_perturbed_exner, | ||
| theta_v_at_cells_on_half_levels=theta_v_at_cells_on_half_levels, | ||
| wgtfacq_c=wgtfacq_c, | ||
| reference_theta_at_cells_on_half_levels=reference_theta_at_cells_on_half_levels, | ||
| igradp_method=igradp_method, | ||
| nflatlev=nflatlev, | ||
| surface_level=surface_level, | ||
| out=( | ||
| perturbed_rho_at_cells_on_model_levels, | ||
| perturbed_theta_v_at_cells_on_model_levels, | ||
|
|
@@ -434,27 +395,46 @@ def compute_perturbed_quantities_and_interpolation( | |
| perturbed_theta_v_at_cells_on_half_levels, | ||
| theta_v_at_cells_on_half_levels, | ||
| pressure_buoyancy_acceleration_at_cells_on_half_levels, | ||
| temporal_extrapolation_of_perturbed_exner, | ||
| ), | ||
| domain={ | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (model_top, surface_level - 1), | ||
| }, | ||
| ) | ||
|
|
||
| _set_theta_v_and_exner_on_surface_level( | ||
| temporal_extrapolation_of_perturbed_exner=temporal_extrapolation_of_perturbed_exner, | ||
| wgtfacq_c=wgtfacq_c, | ||
| perturbed_theta_v_at_cells_on_model_levels=perturbed_theta_v_at_cells_on_model_levels, | ||
| reference_theta_at_cells_on_half_levels=reference_theta_at_cells_on_half_levels, | ||
| out=( | ||
| perturbed_theta_v_at_cells_on_half_levels, | ||
| theta_v_at_cells_on_half_levels, | ||
| exner_at_cells_on_half_levels, | ||
| domain=( | ||
| { | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (model_top, surface_level - 1), | ||
| }, | ||
| { | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (model_top, surface_level - 1), | ||
| }, | ||
| { | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (model_top, surface_level - 1), | ||
| }, | ||
| { | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (model_top, surface_level - 1), | ||
| }, | ||
| { | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (maximum(1, nflatlev), surface_level), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be interesting to explore if we should actually define all fields that don't start at 0 aka model_top on a smaller domain. Is this field ever read < nflatlev? Similar are the fields that are computed from 1 ever used at level 0?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a priority, we can do this in another PR |
||
| }, | ||
| { | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (1, surface_level), | ||
| }, | ||
| { | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (1, surface_level), | ||
| }, | ||
| { | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (model_top, surface_level - 1), | ||
| }, | ||
| { | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (model_top, surface_level - 1), | ||
| }, | ||
| ), | ||
| domain={ | ||
| dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo), | ||
| dims.KDim: (surface_level - 1, surface_level), | ||
| }, | ||
| ) | ||
|
|
||
| _compute_first_and_second_vertical_derivative_of_exner( | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.