Skip to content

Commit 4839805

Browse files
committed
undo fusing of _set_theta_v_and_exner_on_surface_level
1 parent e8c5f26 commit 4839805

1 file changed

Lines changed: 59 additions & 83 deletions

File tree

model/atmosphere/dycore/src/icon4py/model/atmosphere/dycore/stencils/compute_cell_diagnostics_for_dycore.py

Lines changed: 59 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ def _calculate_pressure_buoyancy_acceleration_at_cells_on_half_levels(
6868

6969
@gtx.field_operator
7070
def _compute_perturbed_quantities_and_interpolation(
71-
time_extrapolation_parameter_for_exner: fa.CellKField[ta.vpfloat],
72-
current_exner: fa.CellKField[ta.wpfloat],
73-
reference_exner_at_cells_on_model_levels: fa.CellKField[ta.vpfloat],
7471
current_rho: fa.CellKField[ta.wpfloat],
7572
reference_rho_at_cells_on_model_levels: fa.CellKField[ta.wpfloat],
7673
current_theta_v: fa.CellKField[ta.wpfloat],
@@ -83,6 +80,7 @@ def _compute_perturbed_quantities_and_interpolation(
8380
pressure_buoyancy_acceleration_at_cells_on_half_levels: fa.CellKField[ta.vpfloat],
8481
rho_at_cells_on_half_levels: fa.CellKField[ta.wpfloat],
8582
exner_at_cells_on_half_levels: fa.CellKField[ta.vpfloat],
83+
temporal_extrapolation_of_perturbed_exner: fa.CellKField[ta.vpfloat],
8684
theta_v_at_cells_on_half_levels: fa.CellKField[ta.wpfloat],
8785
igradp_method: gtx.int32,
8886
nflatlev: gtx.int32,
@@ -95,18 +93,7 @@ def _compute_perturbed_quantities_and_interpolation(
9593
fa.CellKField[ta.wpfloat],
9694
fa.CellKField[ta.wpfloat],
9795
fa.CellKField[ta.wpfloat],
98-
fa.CellKField[ta.wpfloat],
9996
]:
100-
(
101-
temporal_extrapolation_of_perturbed_exner,
102-
perturbed_exner_at_cells_on_model_levels,
103-
) = _extrapolate_temporally_exner_pressure(
104-
exner_exfac=time_extrapolation_parameter_for_exner,
105-
exner=current_exner,
106-
exner_ref_mc=reference_exner_at_cells_on_model_levels,
107-
exner_pr=perturbed_exner_at_cells_on_model_levels,
108-
)
109-
11097
exner_at_cells_on_half_levels = (
11198
concat_where(
11299
maximum(1, nflatlev) <= dims.KDim,
@@ -177,32 +164,6 @@ def _compute_perturbed_quantities_and_interpolation(
177164
perturbed_theta_v_at_cells_on_half_levels,
178165
theta_v_at_cells_on_half_levels,
179166
pressure_buoyancy_acceleration_at_cells_on_half_levels,
180-
temporal_extrapolation_of_perturbed_exner,
181-
)
182-
183-
184-
@gtx.field_operator
185-
def _set_theta_v_and_exner_on_surface_level(
186-
temporal_extrapolation_of_perturbed_exner: fa.CellKField[vpfloat],
187-
wgtfacq_c: fa.CellKField[vpfloat],
188-
perturbed_theta_v_at_cells_on_model_levels: fa.CellKField[vpfloat],
189-
reference_theta_at_cells_on_half_levels: fa.CellKField[vpfloat],
190-
) -> tuple[fa.CellKField[vpfloat], fa.CellKField[wpfloat], fa.CellKField[vpfloat]]:
191-
perturbed_theta_v_at_cells_on_half_levels = _interpolate_to_surface(
192-
wgtfacq_c=wgtfacq_c, interpolant=perturbed_theta_v_at_cells_on_model_levels
193-
)
194-
theta_v_at_cells_on_half_levels = (
195-
reference_theta_at_cells_on_half_levels + perturbed_theta_v_at_cells_on_half_levels
196-
)
197-
198-
exner_at_cells_on_half_levels = _interpolate_to_surface(
199-
wgtfacq_c=wgtfacq_c, interpolant=temporal_extrapolation_of_perturbed_exner
200-
)
201-
202-
return (
203-
perturbed_theta_v_at_cells_on_half_levels,
204-
astype(theta_v_at_cells_on_half_levels, wpfloat),
205-
exner_at_cells_on_half_levels,
206167
)
207168

208169

@@ -216,43 +177,16 @@ def _compute_first_and_second_vertical_derivative_of_exner(
216177
d2dexdz2_fac1_mc: fa.CellKField[vpfloat],
217178
d2dexdz2_fac2_mc: fa.CellKField[vpfloat],
218179
perturbed_theta_v_at_cells_on_model_levels: fa.CellKField[vpfloat],
219-
temporal_extrapolation_of_perturbed_exner: fa.CellKField[vpfloat],
220-
wgtfacq_c: fa.CellKField[vpfloat],
221-
reference_theta_at_cells_on_half_levels: fa.CellKField[vpfloat],
222-
theta_v_at_cells_on_half_levels: fa.CellKField[vpfloat],
223180
igradp_method: gtx.int32,
224181
nflatlev: gtx.int32,
225182
nflat_gradp: gtx.int32,
226-
surface_level: gtx.int32,
227183
) -> tuple[
228184
fa.CellKField[vpfloat],
229185
fa.CellKField[vpfloat],
230-
fa.CellKField[vpfloat],
231-
fa.CellKField[vpfloat],
232-
fa.CellKField[vpfloat],
233186
]:
234-
(
235-
perturbed_theta_v_at_cells_on_half_levels,
236-
theta_v_at_cells_on_half_levels,
237-
exner_at_cells_on_half_levels,
238-
) = concat_where(
239-
dims.KDim >= surface_level - 1,
240-
_set_theta_v_and_exner_on_surface_level(
241-
temporal_extrapolation_of_perturbed_exner=temporal_extrapolation_of_perturbed_exner,
242-
wgtfacq_c=wgtfacq_c,
243-
perturbed_theta_v_at_cells_on_model_levels=perturbed_theta_v_at_cells_on_model_levels,
244-
reference_theta_at_cells_on_half_levels=reference_theta_at_cells_on_half_levels,
245-
),
246-
(
247-
perturbed_theta_v_at_cells_on_half_levels,
248-
theta_v_at_cells_on_half_levels,
249-
exner_at_cells_on_half_levels,
250-
),
251-
)
252-
253187
ddz_of_temporal_extrapolation_of_perturbed_exner_on_model_levels = (
254188
concat_where(
255-
(nflatlev <= dims.KDim) & (dims.KDim < surface_level - 1),
189+
nflatlev <= dims.KDim,
256190
_compute_first_vertical_derivative_at_cells(
257191
exner_at_cells_on_half_levels, inv_ddqz_z_full
258192
),
@@ -264,7 +198,7 @@ def _compute_first_and_second_vertical_derivative_of_exner(
264198

265199
d2dz2_of_temporal_extrapolation_of_perturbed_exner_on_model_levels = (
266200
concat_where(
267-
(nflat_gradp <= dims.KDim) & (dims.KDim < surface_level - 1),
201+
nflat_gradp <= dims.KDim,
268202
-vpfloat("0.5")
269203
* (
270204
(
@@ -283,8 +217,30 @@ def _compute_first_and_second_vertical_derivative_of_exner(
283217
return (
284218
ddz_of_temporal_extrapolation_of_perturbed_exner_on_model_levels,
285219
d2dz2_of_temporal_extrapolation_of_perturbed_exner_on_model_levels,
220+
)
221+
222+
223+
@gtx.field_operator
224+
def _set_theta_v_and_exner_on_surface_level(
225+
temporal_extrapolation_of_perturbed_exner: fa.CellKField[vpfloat],
226+
wgtfacq_c: fa.CellKField[vpfloat],
227+
perturbed_theta_v_at_cells_on_model_levels: fa.CellKField[vpfloat],
228+
reference_theta_at_cells_on_half_levels: fa.CellKField[vpfloat],
229+
) -> tuple[fa.CellKField[vpfloat], fa.CellKField[wpfloat], fa.CellKField[vpfloat]]:
230+
perturbed_theta_v_at_cells_on_half_levels = _interpolate_to_surface(
231+
wgtfacq_c=wgtfacq_c, interpolant=perturbed_theta_v_at_cells_on_model_levels
232+
)
233+
theta_v_at_cells_on_half_levels = (
234+
reference_theta_at_cells_on_half_levels + perturbed_theta_v_at_cells_on_half_levels
235+
)
236+
237+
exner_at_cells_on_half_levels = _interpolate_to_surface(
238+
wgtfacq_c=wgtfacq_c, interpolant=temporal_extrapolation_of_perturbed_exner
239+
)
240+
241+
return (
286242
perturbed_theta_v_at_cells_on_half_levels,
287-
theta_v_at_cells_on_half_levels,
243+
astype(theta_v_at_cells_on_half_levels, wpfloat),
288244
exner_at_cells_on_half_levels,
289245
)
290246

@@ -388,10 +344,22 @@ def compute_perturbed_quantities_and_interpolation(
388344
- d2dz2_of_temporal_extrapolation_of_perturbed_exner_on_model_levels
389345
"""
390346

347+
_extrapolate_temporally_exner_pressure(
348+
exner_exfac=time_extrapolation_parameter_for_exner,
349+
exner=current_exner,
350+
exner_ref_mc=reference_exner_at_cells_on_model_levels,
351+
exner_pr=perturbed_exner_at_cells_on_model_levels,
352+
out=(
353+
temporal_extrapolation_of_perturbed_exner,
354+
perturbed_exner_at_cells_on_model_levels,
355+
),
356+
domain={
357+
dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo),
358+
dims.KDim: (model_top, surface_level - 1),
359+
},
360+
)
361+
391362
_compute_perturbed_quantities_and_interpolation(
392-
time_extrapolation_parameter_for_exner=time_extrapolation_parameter_for_exner,
393-
current_exner=current_exner,
394-
reference_exner_at_cells_on_model_levels=reference_exner_at_cells_on_model_levels,
395363
current_rho=current_rho,
396364
reference_rho_at_cells_on_model_levels=reference_rho_at_cells_on_model_levels,
397365
current_theta_v=current_theta_v,
@@ -404,6 +372,7 @@ def compute_perturbed_quantities_and_interpolation(
404372
pressure_buoyancy_acceleration_at_cells_on_half_levels=pressure_buoyancy_acceleration_at_cells_on_half_levels,
405373
rho_at_cells_on_half_levels=rho_at_cells_on_half_levels,
406374
exner_at_cells_on_half_levels=exner_at_cells_on_half_levels,
375+
temporal_extrapolation_of_perturbed_exner=temporal_extrapolation_of_perturbed_exner,
407376
theta_v_at_cells_on_half_levels=theta_v_at_cells_on_half_levels,
408377
igradp_method=igradp_method,
409378
nflatlev=nflatlev,
@@ -416,14 +385,29 @@ def compute_perturbed_quantities_and_interpolation(
416385
perturbed_theta_v_at_cells_on_half_levels,
417386
theta_v_at_cells_on_half_levels,
418387
pressure_buoyancy_acceleration_at_cells_on_half_levels,
419-
temporal_extrapolation_of_perturbed_exner,
420388
),
421389
domain={
422390
dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo),
423391
dims.KDim: (model_top, surface_level - 1),
424392
},
425393
)
426394

395+
_set_theta_v_and_exner_on_surface_level(
396+
temporal_extrapolation_of_perturbed_exner=temporal_extrapolation_of_perturbed_exner,
397+
wgtfacq_c=wgtfacq_c,
398+
perturbed_theta_v_at_cells_on_model_levels=perturbed_theta_v_at_cells_on_model_levels,
399+
reference_theta_at_cells_on_half_levels=reference_theta_at_cells_on_half_levels,
400+
out=(
401+
perturbed_theta_v_at_cells_on_half_levels,
402+
theta_v_at_cells_on_half_levels,
403+
exner_at_cells_on_half_levels,
404+
),
405+
domain={
406+
dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo),
407+
dims.KDim: (surface_level - 1, surface_level),
408+
},
409+
)
410+
427411
_compute_first_and_second_vertical_derivative_of_exner(
428412
exner_at_cells_on_half_levels=exner_at_cells_on_half_levels,
429413
inv_ddqz_z_full=inv_ddqz_z_full,
@@ -433,24 +417,16 @@ def compute_perturbed_quantities_and_interpolation(
433417
d2dexdz2_fac1_mc=d2dexdz2_fac1_mc,
434418
d2dexdz2_fac2_mc=d2dexdz2_fac2_mc,
435419
perturbed_theta_v_at_cells_on_model_levels=perturbed_theta_v_at_cells_on_model_levels,
436-
temporal_extrapolation_of_perturbed_exner=temporal_extrapolation_of_perturbed_exner,
437-
wgtfacq_c=wgtfacq_c,
438-
reference_theta_at_cells_on_half_levels=reference_theta_at_cells_on_half_levels,
439-
theta_v_at_cells_on_half_levels=theta_v_at_cells_on_half_levels,
440420
igradp_method=igradp_method,
441421
nflatlev=nflatlev,
442422
nflat_gradp=nflat_gradp,
443-
surface_level=surface_level,
444423
out=(
445424
ddz_of_temporal_extrapolation_of_perturbed_exner_on_model_levels,
446425
d2dz2_of_temporal_extrapolation_of_perturbed_exner_on_model_levels,
447-
perturbed_theta_v_at_cells_on_half_levels,
448-
theta_v_at_cells_on_half_levels,
449-
exner_at_cells_on_half_levels,
450426
),
451427
domain={
452428
dims.CellDim: (start_cell_lateral_boundary_level_3, end_cell_halo),
453-
dims.KDim: (model_top, surface_level),
429+
dims.KDim: (model_top, surface_level - 1),
454430
},
455431
)
456432

0 commit comments

Comments
 (0)