Skip to content

Added model/atmosphere/subgrid_scale_physics/muphys Microphysics #742

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

Open
wants to merge 100 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
d05258e
First attempt at a where-based ice deposition field_operator
fomics Nov 22, 2024
dce7442
Two more field operators
fomics Nov 22, 2024
c9e48a9
Added return field
fomics Nov 22, 2024
4d5c6e0
Another transition
fomics Nov 22, 2024
30a7a70
First attempt at a unit test
fomics Nov 25, 2024
b2cfa01
fixes
edopao Nov 25, 2024
6c6f253
Changed to builtin power function
fomics Nov 25, 2024
f81583e
after talking to Nikki
fomics Nov 25, 2024
11b260c
small edits
nfarabullini Nov 25, 2024
92214a7
initial code for rbd fields
nfarabullini Nov 26, 2024
a42a2e5
edits
nfarabullini Nov 26, 2024
3f8d550
Pass constants as arguments
fomics Nov 26, 2024
ec078db
cleanup from wrong push
nfarabullini Nov 26, 2024
363ee61
left-over cleanup
nfarabullini Nov 26, 2024
a059c5a
Support for cloud_to_graupel
fomics Nov 26, 2024
8a97568
First attempt cloud_x_ice
fomics Nov 26, 2024
a4de3c1
Still not verifying
fomics Nov 26, 2024
1a5b5ac
cloud_x_ice verifies
fomics Nov 26, 2024
cc6dade
Added numerous transition stencils and there unit tests; currently on…
fomics Nov 27, 2024
5fa374e
Added almost all other transitions
fomics Dec 9, 2024
b5f2fd6
Minor correction
fomics Dec 9, 2024
6557e99
Final kernels
fomics Dec 10, 2024
7fe6409
About half of the properties; first draft
fomics Dec 11, 2024
894eb9a
Additions of properties and some thermodynamics stencils
fomics Dec 17, 2024
e31723f
Added internal energy stencils and tests, but both are still failing
fomics Dec 17, 2024
de4c20d
Six thermodynamic kernels, all passing
fomics Jan 7, 2025
8d8e13b
minor corrections
fomics Jan 7, 2025
5be3611
one more stencil and the start of saturation adjustment
fomics Jan 7, 2025
92ee96c
added saturation_adjustment -- currently it hangs
fomics Jan 8, 2025
24b4860
field_operator refactoring
nfarabullini Jan 8, 2025
4c42fd0
scalars in _newton_raphson now ta.wpfloat
fomics Jan 9, 2025
32a6540
Now testing all 3 output fields
fomics Jan 10, 2025
5755e26
First attempt at reforming saturation_adjustment2
fomics Jan 13, 2025
ebfb83e
saturation_adjustment2 now validating
fomics Jan 15, 2025
20fe09e
First attempt at the precip scan_operator
fomics Jan 17, 2025
46b6e53
Added much more detail, second scan_operator
fomics Jan 20, 2025
3b34c3e
Back to original saturation_adjustment version, runs fast with --back…
fomics Jan 21, 2025
2d24924
First version with graupel driver -- now debugging implementations/gr…
fomics Jan 21, 2025
1a2a990
Cleaning up old directory names
fomics Jan 22, 2025
96a2a48
Changing to CellKField, debugging graupel
fomics Jan 22, 2025
4528435
All thermo routines now in thermo.py
fomics Jan 22, 2025
37e7f15
Restructured all transitions into transitions.py -- removed core/tran…
fomics Jan 22, 2025
a33d9eb
Now trying to integrate properties.py
fomics Jan 23, 2025
dc02b7f
Trying to get fall_speed_scalar to pass
fomics Jan 24, 2025
ec03f20
some edits
nfarabullini Jan 24, 2025
ffe42c8
some edit
nfarabullini Jan 24, 2025
9bf6c6d
Minor
fomics Jan 24, 2025
abd7906
Slowly debugging graupel.py
fomics Jan 24, 2025
1c04a6c
New tests all passing except for test_vel_scale_factor_snow.py
fomics Jan 27, 2025
5feaff2
Adjusted to new name
fomics Jan 27, 2025
a2719b8
Cleaned up tests; graupel.py to a point where it almost compiles
fomics Jan 29, 2025
640ccf4
First attempt to actually call graupel_run
fomics Jan 29, 2025
ec6d1bb
Started to transition to FrozenNamespace
fomics Jan 29, 2025
d4e4695
Removed constants-as-arguments from properties and transitions
fomics Jan 31, 2025
0451f75
Removed unneeded directories
fomics Jan 31, 2025
d744610
Removed constants-as-arguments from thermo
fomics Jan 31, 2025
b29849f
Removed most of constants passed as arguments
fomics Feb 3, 2025
8b4a477
Removed errant #
fomics Feb 3, 2025
8198ee1
Added lrain = True
fomics Feb 3, 2025
6992340
Added p_sig variable
vectorflux Feb 4, 2025
f54c0dc
Adding support for offset arrays.
vectorflux Feb 4, 2025
3628f7e
Deleting
vectorflux Feb 4, 2025
b38b159
Updated to latest main
vectorflux Feb 4, 2025
ccbc0f5
Removed vertical index array "vert" again. It runs but fails.
vectorflux Feb 4, 2025
29a23da
Revamped all tests for latest rebase on top of main with data_alloc; …
fomics Feb 7, 2025
58693b0
Now debugging -- dq are all zero
fomics Feb 7, 2025
774b062
Corrected dqdt_X calculation. Now more sensible values, but not yet …
fomics Feb 7, 2025
2f89532
Corrected two constants
fomics Feb 11, 2025
4645acf
Corrections to two stencils -- modified where statements
fomics Feb 14, 2025
000d1b7
Corrections for failing tests
fomics Feb 14, 2025
50e269b
More accurately depicts C++ code. dqdt_i/s/g are still wrong
fomics Feb 14, 2025
6b2c5ec
Moved mask to appropriate position; fixed m_ice -> x_ice bug; now ext…
fomics Feb 14, 2025
d39b0ac
Activated LOOP3 (precipitation effects) -- all sorts of NaN
fomics Feb 17, 2025
92353bb
Now running _precipitation_effects and outputting pflx, surface preci…
fomics Feb 18, 2025
cdd8635
Minor improvements to reduce round-off errors
fomics Feb 19, 2025
2f35bd6
result instead of mask.
fomics Feb 19, 2025
86eabb4
Minor correction for corner case.
fomics Feb 19, 2025
393a9e9
Formatting to avoid line overruns.
fomics Feb 19, 2025
bb8592a
Minor mistake in ice_mass. Now zero diffs if !lrain
fomics Feb 19, 2025
6f30528
Reactivated _precipitation_effects. Now there are roundoff differenc…
fomics Feb 20, 2025
1c67492
Revised parentheses to properly copy C++ algorithm
fomics Feb 21, 2025
8dfaadb
Several bug fixes; added qsat_rho_tmelt, upgrade to 0.0.6, mini.nc ha…
fomics Feb 26, 2025
524d351
Removed unneeded variables; added unit test
fomics Feb 26, 2025
f5195e7
Merge branch 'main' into muphys_next
fomics Feb 27, 2025
10f6321
Required changes for 0.0.6
fomics Feb 27, 2025
cd8c2ea
Changed naming scheme to avoid identical program name and output vari…
fomics Feb 28, 2025
f31b589
use number for output rather than snow_number
fomics Feb 28, 2025
ea31e74
This version has roundoff differences with muphys-cpp for the dbg.nc …
fomics Feb 28, 2025
1fe5a58
activated muphys
fomics Mar 3, 2025
28b1347
GT4Py line commented out to provide metrics from havogt
fomics Mar 3, 2025
5ba2038
Changes for Santis
fomics Apr 1, 2025
b097f7a
Trying again to merge in main
fomics Apr 2, 2025
3199380
Changed concat_where to new arguments
fomics Apr 2, 2025
10cae58
Changed name to avoid possible collision with Field version of same r…
fomics Apr 2, 2025
34d0c91
Removed uv.lock
fomics May 12, 2025
b25fee3
Merge in icon4py.git:main of today
fomics May 12, 2025
e43b7df
Remerge with latest main
fomics May 13, 2025
cbfd9c1
Removed pytests of scalar quantities (not properly supported); change…
fomics May 13, 2025
a648864
Merge branch 'muphys_008015f4' of github.com:C2SM/icon4py into muphys…
fomics May 13, 2025
3a50836
Merge remote-tracking branch 'origin/main' into muphys_008015f4
fomics May 21, 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
31 changes: 31 additions & 0 deletions model/atmosphere/subgrid_scale_physics/muphys/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ICON4Py - ICON inspired code in Python and GT4Py

Copyright (c) 2022-2024, ETH Zurich and MeteoSwiss
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 changes: 9 additions & 0 deletions model/atmosphere/subgrid_scale_physics/muphys/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# icon4py-atmosphere-physics-muphys

## Description

Port of the 1-moment 'muphys' microphysics scheme of Bjorn Stevens to gt4py.

## Installation instructions

Check the `README.md` at the root of the `model` folder for installation instructions.
139 changes: 139 additions & 0 deletions model/atmosphere/subgrid_scale_physics/muphys/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=61.0", "wheel>=0.40.0"]

[project]
authors = [
{email = "[email protected]"},
{name = "ETH Zurich"}
]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: POSIX",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering :: Atmospheric Science",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Physics"
]
dependencies = [
"gt4py>=1.0.1",
"icon4py-common>=0.0.6"
]
description = "ICON subgrid scale muphys parameterization."
dynamic = ['version']
license = {file = "LICENSE"}
name = "icon4py-atmosphere-muphys"
readme = "README.md"
requires-python = ">=3.10"

[project.urls]
repository = "https://github.com/C2SM/icon4py"

[tool.coverage]

[tool.coverage.html]
directory = 'tests/_reports/coverage_html'

[tool.coverage.paths]
source = ['src/icon4py/model/']

[tool.coverage.report]
exclude_lines = [
'raise AssertionError', # Don't complain if tests don't hit defensive assertion code
'raise NotImplementedError', # Don't complain if tests don't hit defensive assertion code
'if 0:', # Don't complain if non-runnable code isn't run
'if __name__ == .__main__.:' # Don't complain if non-runnable code isn't run
]
ignore_errors = true

[tool.coverage.run]
branch = true
parallel = true
source_pkgs = ['muphys']

[tool.mypy]
disallow_incomplete_defs = true
disallow_untyped_defs = true
exclude = [
'^tests/*.py'
]
ignore_missing_imports = false
implicit_reexport = true
install_types = true
non_interactive = true
show_column_numbers = true
show_error_codes = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true

[tool.pytest]

[tool.pytest.ini_options]
addopts = ['-p icon4py.model.testing.pytest_config']
testpaths = 'tests'

[tool.ruff]
extend-exclude = [
'.eggs',
'.gt_cache',
'.ipynb_checkpoints',
'.tox',
'_local_',
'build',
'dist',
'docs',
'_external_src',
'tests/_disabled',
'setup.py'
]
indent-width = 4
line-length = 100
respect-gitignore = true
show-fixes = true
# Assume Python 3.10
target-version = "py310"

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint]
extend-select = ['E', 'F', 'I', 'B', 'A', 'T10', 'ERA', 'NPY', 'RUF']
# # Rules sets:
# E: pycodestyle
# F: Pyflakes
# I: isort
# B: flake8-bugbear
# A: flake8-builtins
# T10: flake8-debugger
# ERA: eradicate
# NPY: NumPy-specific rules
# RUF: Ruff-specific rules
ignore = [
'E501', # Line too long (using Bugbear's B950 warning)
'RUF009' # Do not perform function call in dataclass defaults
]
ignore-init-module-imports = true

[tool.ruff.lint.isort]
combine-as-imports = true
known-first-party = ['icon4py.model']
known-third-party = [
'gt4py'
]
lines-after-imports = 2

[tool.ruff.lint.mccabe]
max-complexity = 15

[tool.setuptools.dynamic]
version = {attr = 'icon4py.model.atmosphere.subgrid_scale_physics.muphys.__init__.__version__'}

[tool.setuptools.package-data]
'icon4py.model.atmosphere.subgrid_scale_physics.muphys' = ['py.typed']
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-r ../../../../base-requirements-dev.txt
-e ../../../common
-e .
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-r ../../../../base-requirements.txt
../../../common
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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 Final

from packaging import version as pkg_version


__all__ = [
"__author__",
"__copyright__",
"__license__",
"__version__",
"__version_info__",
]


__author__: Final = "ETH Zurich, MeteoSwiss and individual contributors"
__copyright__: Final = "Copyright (c) 2022-2024 ETH Zurich and MeteoSwiss"
__license__: Final = "BSD-3-Clause"


__version__: Final = "0.0.6"
__version_info__: Final = pkg_version.parse(__version__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
class thermodyn:
# Thermodynamic constants for the dry and moist atmosphere

# Dry air
rd = 287.04 # [J/K/kg] gas constant
cpd = 1004.64 # [J/K/kg] specific heat at constant pressure
cvd = cpd - rd # [J/K/kg] specific heat at constant volume
con_m = 1.50E-5 # [m^2/s] kinematic viscosity of dry air
con_h = 2.20E-5 # [m^2/s] scalar conductivity of dry air
con0_h = 2.40e-2 # [J/m/s/K] thermal conductivity of dry air
eta0d = 1.717e-5 # [N*s/m2] dyn viscosity of dry air at tmelt

# H2O
# gas
rv = 461.51 # [J/K/kg] gas constant for water vapor
cpv = 1869.46 # [J/K/kg] specific heat at constant pressure
cvv = cpv - rv # [J/K/kg] specific heat at constant volume
dv0 = 2.22e-5 # [m^2/s] diff coeff of H2O vapor in dry air at tmelt
# liquid / water
rhoh2o = 1000.0 # [kg/m3] density of liquid water
# solid / ice
rhoice = 916.7 # [kg/m3] density of pure ice

cv_i = 2000.0

# phase changes
alv = 2.5008e6 # [J/kg] latent heat for vaporisation
als = 2.8345e6 # [J/kg] latent heat for sublimation
alf = als - alv # [J/kg] latent heat for fusion
tmelt = 273.15 # [K] melting temperature of ice/snow
t3 = 273.16 # [K] Triple point of water at 611hPa

# Auxiliary constants
rdv = rd / rv # [ ]
vtmpc1 = rv / rd - 1.0 # [ ]
vtmpc2 = cpv / cpd - 1.0 # [ ]
rcpv = cpd / cpv - 1.0 # [ ]
alvdcp = alv / cpd # [K]
alsdcp = als / cpd # [K]
rcpd = 1.0 / cpd # [K*kg/J]
rcvd = 1.0 / cvd # [K*kg/J]
rcpl = 3.1733 # cp_d / cp_l - 1

clw = (rcpl + 1.0) * cpd # specific heat capacity of liquid water
cv_v = (rcpv + 1.0) * cpd - rv

class graupel_ct:
rho_00 = 1.225 # reference air density
q1 = 8.e-6
qmin = 1.0e-15 # threshold for computation
ams = 0.069 # Formfactor in the mass-size relation of snow particles
bms = 2.0 # Exponent in the mass-size relation of snow particles
v0s = 25.0 # prefactor in snow fall speed
v1s = 0.5 # Exponent in the terminal velocity for snow
m0_ice = 1.0e-12 # initial crystal mass for cloud ice nucleation
ci = 2108.0 # specific heat of ice
tx = 3339.5
tfrz_het1 = thermodyn.tmelt - 6.0 # temperature for het. freezing of cloud water with supersat
tfrz_het2 = thermodyn.tmelt - 25.0 # temperature for het. freezing of cloud water
tfrz_hom = thermodyn.tmelt - 37.0 # temperature for hom. freezing of cloud water
lvc = thermodyn.alv - (thermodyn.cpv - thermodyn.clw) * thermodyn.tmelt # invariant part of vaporization enthalpy
lsc = thermodyn.als - (thermodyn.cpv - ci) * thermodyn.tmelt # invariant part of vaporization enthalpy

class idx:
nx = 6 # number of water species
np = 4 # number of precipitating water species
lqr = 0 # index for rain
lqi = 1 # index for ice
lqs = 2 # index for snow
lqg = 3 # index for graupel
lqc = 4 # index for cloud
lqv = 5 # index for vapor

qx_ind = [lqv, lqc, lqr, lqs, lqi, lqg]
qp_ind = [lqr, lqi, lqs, lqg]

lrain = True # switch for disabling rain
lcold = True # switch for disabling freezing processes

prefactor_r = 14.58
exponent_r = 0.111
offset_r = 1.0e-12
prefactor_i = 1.25
exponent_i = 0.160
offset_i = 1.0e-12
prefactor_s = 57.80
exponent_s = 0.5
offset_s = 1.0e-12
prefactor_g = 12.24
exponent_g = 0.217
offset_g = 1.0e-08

params = [
[14.58, 0.111, 1.0e-12],
[1.25, 0.160, 1.0e-12],
[57.80, 0.5 / 3.0, 1.0e-12],
[12.24, 0.217, 1.0e-08]
]

cloud_num = 200.00e+06 # cloud droplet number concentration (from gscp_data.f90)

ZERO = 0.0
Loading
Loading