From d0c17033dcc48bbb74761380f55f890e8f29263d Mon Sep 17 00:00:00 2001 From: Oliver Elbert Date: Wed, 21 Aug 2024 14:27:23 -0400 Subject: [PATCH] Support for pbl scheme (#66) This PR adds features needed for the ported PBL scheme. Adding relevant namelist switches, Including a few useful physics constants and some infrastructure for bool fields and 4d fields --- ndsl/constants.py | 5 ++++- ndsl/dsl/typing.py | 9 +++++++++ ndsl/namelist.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/ndsl/constants.py b/ndsl/constants.py index d0b512b5..0f7d55da 100644 --- a/ndsl/constants.py +++ b/ndsl/constants.py @@ -128,6 +128,7 @@ class ConstantVersions(Enum): CV_VAP = 3.0 * RVGAS # Heat capacity of water vapor at constant volume ZVIR = RVGAS / RDGAS - 1 # con_fvirt in Fortran physics C_ICE = 1972.0 # Heat capacity of ice at -15 degrees Celsius +C_ICE_0 = 2106.0 # Heat capacity of ice at 0 degrees Celsius C_LIQ = 4.1855e3 # Heat capacity of water at 15 degrees Celsius CP_VAP = 4.0 * RVGAS # Heat capacity of water vapor at constant pressure TICE = 273.16 # Freezing temperature @@ -136,6 +137,7 @@ class ConstantVersions(Enum): D2ICE = DC_VAP + DC_ICE # Isobaric heating / cooling LI0 = HLF - DC_ICE * TICE EPS = RDGAS / RVGAS +EPSM1 = EPS - 1.0 LV0 = ( HLV - DC_VAP * TICE ) # 3.13905782e6, evaporation latent heat coefficient at 0 degrees Kelvin @@ -145,7 +147,8 @@ class ConstantVersions(Enum): LI2 = ( LV0 + LI00 ) # 2.86799816e6, sublimation latent heat coefficient at 0 degrees Kelvin -E00 = 611.21 # Saturation vapor pressure at 0 degrees Celsius +E00 = 611.21 # Saturation vapor pressure at 0 degrees Celsius (Pa) +PSAT = 610.78 # Saturation vapor pressure at H2O 3pt (Pa) T_WFR = TICE - 40.0 # homogeneous freezing temperature TICE0 = TICE - 0.01 T_MIN = 178.0 # Minimum temperature to freeze-dry all water vapor diff --git a/ndsl/dsl/typing.py b/ndsl/dsl/typing.py index d85ee30f..5eab76ef 100644 --- a/ndsl/dsl/typing.py +++ b/ndsl/dsl/typing.py @@ -63,10 +63,19 @@ def global_set_floating_point_precision(): IntFieldIJ = Field[gtscript.IJ, Int] IntFieldK = Field[gtscript.K, Int] BoolField = Field[gtscript.IJK, Bool] +BoolFieldIJ = Field[gtscript.IJ, Bool] Index3D = Tuple[int, int, int] +def set_4d_field_size(n, dtype): + """ + Defines a 4D field with a given size and type + The extra data dimension is not parallel + """ + return Field[gtscript.IJK, (dtype, (n,))] + + def cast_to_index3d(val: Tuple[int, ...]) -> Index3D: if len(val) != 3: raise ValueError(f"expected 3d index, received {val}") diff --git a/ndsl/namelist.py b/ndsl/namelist.py index 71a1f1ca..205954ca 100644 --- a/ndsl/namelist.py +++ b/ndsl/namelist.py @@ -111,6 +111,22 @@ class NamelistDefaults: tice = 273.16 # set tice = 165. to turn off ice - phase phys (kessler emulator) alin = 842.0 # "a" in lin1983 clin = 4.8 # "c" in lin 1983, 4.8 -- > 6. (to ehance ql -- > qs) + isatmedmf = 0 # which version of satmedmfvdif to use + dspheat = False # flag for tke dissipative heating + xkzm_h = 1.0 # background vertical diffusion for heat q over ocean + xkzm_m = 1.0 # background vertical diffusion for momentum over ocean + xkzm_hl = 1.0 # background vertical diffusion for heat q over land + xkzm_ml = 1.0 # background vertical diffusion for momentum over land + xkzm_hi = 1.0 # background vertical diffusion for heat q over ice + xkzm_mi = 1.0 # background vertical diffusion for momentum over ice + xkzm_s = 1.0 # sigma threshold for background mom. diffusion + xkzm_lim = 0.01 # background vertical diffusion limit + xkzminv = 0.15 # diffusivity in inversion layers + xkgdx = 25.0e3 # background vertical diffusion threshold + rlmn = 30.0 # lower-limter on asymtotic mixing length in satmedmfdiff + rlmx = 300.0 # upper-limter on asymtotic mixing length in satmedmfdiff + do_dk_hb19 = False # flag for using hb19 background diff formula in satmedmfdiff + cap_k0_land = False # flag for applying limter on background diff in inversion layer over land in satmedmfdiff @classmethod def as_dict(cls): @@ -293,6 +309,22 @@ class Namelist: tice: float = NamelistDefaults.tice alin: float = NamelistDefaults.alin clin: float = NamelistDefaults.clin + isatmedmf: int = NamelistDefaults.isatmedmf + dspheat: bool = NamelistDefaults.dspheat + xkzm_h: float = NamelistDefaults.xkzm_h + xkzm_m: float = NamelistDefaults.xkzm_m + xkzm_hl: float = NamelistDefaults.xkzm_hl + xkzm_ml: float = NamelistDefaults.xkzm_ml + xkzm_hi: float = NamelistDefaults.xkzm_hi + xkzm_mi: float = NamelistDefaults.xkzm_mi + xkzm_s: float = NamelistDefaults.xkzm_s + xkzm_lim: float = NamelistDefaults.xkzm_lim + xkzminv: float = NamelistDefaults.xkzminv + xkgdx: float = NamelistDefaults.xkgdx + rlmn: float = NamelistDefaults.rlmn + rlmx: float = NamelistDefaults.rlmx + do_dk_hb19: bool = NamelistDefaults.do_dk_hb19 + cap_k0_land: bool = NamelistDefaults.cap_k0_land # c0s_shal: Any # c1_shal: Any # cal_pre: Any