Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9715db3
Corrected problems in write_fields, added code for full_muphys
fomics Sep 11, 2025
062e2da
try cse fix for compile-time in saturation adjustment 'loop'
havogt Sep 11, 2025
d3bf31b
merged Fix from Hannes
fomics Sep 15, 2025
a4a90ce
Merge remote-tracking branch 'origin/muphys_bug_fix'
fomics Sep 15, 2025
f4a73ec
For benchmarking only, includes workarounds from Hannes; do not merge
fomics Sep 16, 2025
ff63fbb
Revised integration tests to work with DaCe backends, credit to Edoardo
fomics Sep 16, 2025
d180013
Merge remote-tracking branch 'origin/main' into muphys_bug_fix
fomics Sep 16, 2025
77537ff
rewrite run_full_muphys
edopao Sep 16, 2025
f8c22e5
fix backend arg
edopao Sep 16, 2025
546bb75
remove k_field
edopao Sep 16, 2025
876e81f
remove qti field
edopao Sep 16, 2025
d40b215
fix out fields
edopao Sep 16, 2025
ed1f8a1
Merge remote-tracking branch 'origin/edopao_muphys_benchmarking_dont_…
edopao Sep 16, 2025
8aff981
edit run_graupel_only
edopao Sep 16, 2025
ab9981f
add backend parser
edopao Sep 16, 2025
5a574e6
cleanup
edopao Sep 16, 2025
3752592
Corrected inputs for qse, qie, qge so that qti=1.0746937601645517e-005
fomics Sep 18, 2025
d4432fc
Removed mask_out from saturation_adjustment -- not needed
fomics Sep 30, 2025
d475f0b
Adjustments for performance benefit
fomics Sep 30, 2025
a311d70
Merge branch 'main' into muphys_bug_fix
edopao Oct 23, 2025
d2e80db
Merge branch 'main' into muphys_bug_fix
edopao Nov 5, 2025
e1dd9e4
add static compute domain
edopao Nov 7, 2025
aef59a0
Merge remote-tracking branch 'upstream/main' into muphys_bug_fix
havogt Nov 21, 2025
971aec1
Merge branch 'main' into muphys_bug_fix
edopao Nov 21, 2025
9153482
use backend_like
edopao Nov 21, 2025
fb2763b
Merge branch 'muphys_bug_fix' of github.com:C2SM/icon4py into muphys_…
havogt Nov 21, 2025
798ad60
muphys: Refactor graupel_only driver and add integration test (#958)
havogt Nov 27, 2025
b934921
[draft] Muphys bug fix graupel refactoring hannes (#961)
havogt Dec 5, 2025
213e801
point to gt4py main
havogt Dec 5, 2025
3ff602f
fix module import
edopao Dec 5, 2025
671bd66
Merge remote-tracking branch 'upstream/main' into muphys_bug_fix
havogt Dec 9, 2025
4838d26
undo extra changes
edopao Dec 9, 2025
b959d57
Merge remote-tracking branch 'upstream/main' into muphys_bug_fix
havogt Jan 8, 2026
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 @@ -25,6 +25,7 @@ dependencies = [
# workspace members
"icon4py-common[io]>=0.0.6",
# external dependencies
"numpy>=1.23.3",
"gt4py==1.1.2",
"packaging>=20.0"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ICON4Py - ICON inspired code in Python and GT4Py
#
# Copyright (c) 2022-2024, ETH Zurich and MeteoSwiss
# All rights reserved.
#
# Please, refer to the LICENSE file in the root directory.
# SPDX-License-Identifier: BSD-3-Clause

from typing import NamedTuple

from icon4py.model.common import field_type_aliases as fa, type_alias as ta


class Q(NamedTuple):
v: fa.CellKField[ta.wpfloat] # Specific humidity
c: fa.CellKField[ta.wpfloat] # Specific cloud water content
r: fa.CellKField[ta.wpfloat] # Specific rain water
s: fa.CellKField[ta.wpfloat] # Specific snow water
i: fa.CellKField[ta.wpfloat] # Specific ice water content
g: fa.CellKField[ta.wpfloat] # Specific graupel water content
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# ICON4Py - ICON inspired code in Python and GT4Py
#
# Copyright (c) 2022-2024, ETH Zurich and MeteoSwiss
# All rights reserved.
#
# Please, refer to the LICENSE file in the root directory.
# SPDX-License-Identifier: BSD-3-Clause
import gt4py.next as gtx
from gt4py.next import maximum, where

from icon4py.model.atmosphere.subgrid_scale_physics.muphys.core.common.frozen import g_ct, t_d
from icon4py.model.atmosphere.subgrid_scale_physics.muphys.core.definitions import Q
from icon4py.model.atmosphere.subgrid_scale_physics.muphys.core.thermo import (
_newton_raphson,
_qsat_rho,
)
from icon4py.model.common import dimension as dims, field_type_aliases as fa, type_alias as ta


@gtx.field_operator
def _saturation_adjustment(
te: fa.CellKField[ta.wpfloat], rho: fa.CellKField[ta.wpfloat], q_in: Q
) -> tuple[
fa.CellKField[ta.wpfloat],
fa.CellKField[ta.wpfloat],
fa.CellKField[ta.wpfloat],
]:
"""
Compute the saturation adjustment which revises internal energy and water contents

Args:
Tx: Temperature
rho: Density containing dry air and water constituents
Q: Class with humidity, cloud, rain, snow, ice and graupel water

Result: Tuple containing
- Revised temperature
- Revised specific cloud water content
- Revised specific vapor content
"""
qti = q_in.s + q_in.i + q_in.g
qt = q_in.v + q_in.c + q_in.r + qti
cvc = t_d.cvd * (1.0 - qt) + t_d.clw * q_in.r + g_ct.ci * qti
cv = cvc + t_d.cvv * q_in.v + t_d.clw * q_in.c
ue = cv * te - q_in.c * g_ct.lvc
Tx_hold = ue / (cv + q_in.c * (t_d.cvv - t_d.clw))
qx_hold = _qsat_rho(Tx_hold, rho)

Tx = te
# Newton-Raphson iteration: 6 times the same operations
Tx = _newton_raphson(Tx, rho, q_in.v, q_in.c, cvc, ue)
Tx = _newton_raphson(Tx, rho, q_in.v, q_in.c, cvc, ue)
Tx = _newton_raphson(Tx, rho, q_in.v, q_in.c, cvc, ue)
Tx = _newton_raphson(Tx, rho, q_in.v, q_in.c, cvc, ue)
Tx = _newton_raphson(Tx, rho, q_in.v, q_in.c, cvc, ue)
Tx = _newton_raphson(Tx, rho, q_in.v, q_in.c, cvc, ue)

# At this point we hope Tx has converged
qx = _qsat_rho(Tx, rho)

# Is it possible to unify the where for all three outputs??
mask = q_in.v + q_in.c <= qx_hold
te = where(mask, Tx_hold, Tx)
qce = where(mask, 0.0, maximum(q_in.v + q_in.c - qx, 0.0))
qve = where(mask, q_in.v + q_in.c, qx)

return te, qve, qce


@gtx.program(grid_type=gtx.GridType.UNSTRUCTURED)
def saturation_adjustment(
te: fa.CellKField[ta.wpfloat], # Temperature
rho: fa.CellKField[ta.wpfloat], # Density containing dry air and water constituents
q_in: Q, # Class with humidity, cloud, rain, snow, ice and graupel water
te_out: fa.CellKField[ta.wpfloat], # Temperature
qve_out: fa.CellKField[ta.wpfloat], # Specific humidity
qce_out: fa.CellKField[ta.wpfloat], # Specific cloud water content
horizontal_start: gtx.int32,
horizontal_end: gtx.int32,
vertical_start: gtx.int32,
vertical_end: gtx.int32,
):
_saturation_adjustment(
te,
rho,
q_in,
out=(te_out, qve_out, qce_out),
domain={
dims.CellDim: (horizontal_start, horizontal_end),
dims.KDim: (vertical_start, vertical_end),
},
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Please, refer to the LICENSE file in the root directory.
# SPDX-License-Identifier: BSD-3-Clause
import gt4py.next as gtx
from gt4py.next import exp, maximum, where
from gt4py.next import exp

from icon4py.model.atmosphere.subgrid_scale_physics.muphys.core.common.frozen import g_ct, t_d
from icon4py.model.common import field_type_aliases as fa, type_alias as ta
Expand Down Expand Up @@ -338,78 +338,3 @@ def _newton_raphson(
dux = cv + dqx * (g_ct.lvc + (t_d.cvv - t_d.clw) * Tx)
Tx = Tx - (ux - ue) / dux
return Tx


@gtx.field_operator
def _saturation_adjustment(
te: fa.CellKField[ta.wpfloat],
qve: fa.CellKField[ta.wpfloat],
qce: fa.CellKField[ta.wpfloat],
qre: fa.CellKField[ta.wpfloat],
qti: fa.CellKField[ta.wpfloat],
rho: fa.CellKField[ta.wpfloat],
) -> tuple[
fa.CellKField[ta.wpfloat],
fa.CellKField[ta.wpfloat],
fa.CellKField[ta.wpfloat],
fa.CellKField[bool],
]:
"""
Compute the saturation adjustment which revises internal energy and water contents

Args:
Tx: Temperature
qve: Specific humidity
qce: Specific cloud water content
qre: Specific rain water
qti: Specific mass of all ice species (total-ice)
rho: Density containing dry air and water constituents

Result: Tuple containing
- Revised temperature
- Revised specific cloud water content
- Revised specific vapor content
- Mask specifying where qce+qve less than holding capacity
"""
qt = qve + qce + qre + qti
cvc = t_d.cvd * (1.0 - qt) + t_d.clw * qre + g_ct.ci * qti
cv = cvc + t_d.cvv * qve + t_d.clw * qce
ue = cv * te - qce * g_ct.lvc
Tx_hold = ue / (cv + qce * (t_d.cvv - t_d.clw))
qx_hold = _qsat_rho(Tx_hold, rho)

Tx = te
# Newton-Raphson iteration: 6 times the same operations
Tx = _newton_raphson(Tx, rho, qve, qce, cvc, ue)
Tx = _newton_raphson(Tx, rho, qve, qce, cvc, ue)
Tx = _newton_raphson(Tx, rho, qve, qce, cvc, ue)
Tx = _newton_raphson(Tx, rho, qve, qce, cvc, ue)
Tx = _newton_raphson(Tx, rho, qve, qce, cvc, ue)
Tx = _newton_raphson(Tx, rho, qve, qce, cvc, ue)

# At this point we hope Tx has converged
qx = _qsat_rho(Tx, rho)

# Is it possible to unify the where for all three outputs??
mask = qve + qce <= qx_hold
te = where((qve + qce <= qx_hold), Tx_hold, Tx)
qce = where((qve + qce <= qx_hold), 0.0, maximum(qve + qce - qx, 0.0))
qve = where((qve + qce <= qx_hold), qve + qce, qx)

return te, qve, qce, mask


@gtx.program(grid_type=gtx.GridType.UNSTRUCTURED)
def saturation_adjustment(
te: fa.CellKField[ta.wpfloat], # Temperature
qve: fa.CellKField[ta.wpfloat], # Specific humidity
qce: fa.CellKField[ta.wpfloat], # Specific cloud water content
qre: fa.CellKField[ta.wpfloat], # Specific rain water
qti: fa.CellKField[ta.wpfloat], # Specific mass of all ice species (total-ice)
rho: fa.CellKField[ta.wpfloat], # Density containing dry air and water constituents
te_out: fa.CellKField[ta.wpfloat], # Temperature
qve_out: fa.CellKField[ta.wpfloat], # Specific humidity
qce_out: fa.CellKField[ta.wpfloat], # Specific cloud water content
mask_out: fa.CellKField[bool], # Specific cloud water content
):
_saturation_adjustment(te, qve, qce, qre, qti, rho, out=(te_out, qve_out, qce_out, mask_out))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ICON4Py - ICON inspired code in Python and GT4Py
#
# Copyright (c) 2022-2024, ETH Zurich and MeteoSwiss
# All rights reserved.
#
# Please, refer to the LICENSE file in the root directory.
# SPDX-License-Identifier: BSD-3-Clause
Loading
Loading