-
Notifications
You must be signed in to change notification settings - Fork 13
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
physics and dycore share constants #51
Conversation
rheacangeo
commented
Dec 8, 2021
•
edited
Loading
edited
- Move fv3core.util.global_constants and fv3gfs-physics.global_constants to pace.util.constants
- physics and dycore overlapping constants consolidated -- mainly duplication of constants in saturation adjustment and microphysics removed, and both use pace.util.constants instead
- physics constants made upper case
- physics constants that come from the namelist are added as externals to microphysics stencil, and added to the NamelistDefaults and Namelist class (still in fv3core, but will presumably move up). Physics may need a PhysicsConfig to build from this, but using a full Namelist object should work.
- moved a couple of Microphysics call time constants to the stencil externals as well
- Microphysics-only constants (verified in fortran they only show up in the gfdl microphysics scheme) are moved in the microphysics_functions.py -- they are easy to move back into pace.util.constants if that is preferred
…ics namelist defaults to the _config
… into stencil externals rather than constants
…variables externals
…nly constants into microphysics
…o shared-constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
fv3core/fv3core/_config.py
Outdated
@@ -64,6 +64,50 @@ class NamelistDefaults: | |||
nf_omega = 1 | |||
fv_sg_adj = -1 | |||
n_sponge = 1 | |||
# all below added for physics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it's going to be very easy for someone to add a non-physics value below, so you might want to consider removing the comment.
# all below added for physics | |
# all below are for physics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k thanks, I'll remove the comment
launch jenkins |
launch jenkins |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for going through this! I think there's just one namelist variable that should be a boolean, and that should be it for this PR.
qi_gen, | ||
qi_lim, | ||
): | ||
from __externals__ import t_sub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find!
VCONS = 6.6280504 | ||
VCONG = 87.2382675 | ||
NORMS = 942477796.076938 | ||
NORMG = 5026548245.74367 | ||
|
||
# Fall velocity constants | ||
VCONR = 2503.23638966667 | ||
NORMR = 25132741228.7183 | ||
THR = 1.0e-8 | ||
THI = 1.0e-8 # Cloud ice threshold for terminal fall | ||
THG = 1.0e-8 | ||
THS = 1.0e-8 | ||
AA = -4.14122e-5 | ||
BB = -0.00538922 | ||
CC = -0.0516344 | ||
DD_FS = 0.00216078 | ||
EE = 1.9714 | ||
VR_MIN = 1.0e-3 # Minimum fall speed for rain | ||
VF_MIN = 1.0e-5 # Minimum fall speed for cloud ice, snow, graupel | ||
|
||
P_MIN = 100.0 # Minimum pressure (Pascal) for mp to operate | ||
|
||
DT_FR = 8.0 # Homogeneous freezing of all cloud water at t_wfr - dt_fr | ||
# minimum temperature water can exist (moore & molinero nov. 2011, nature) | ||
# DT_FR can be considered as the error bar | ||
|
||
|
||
SFCRHO = 1.2 # Surface air density | ||
RHOS = 1.0e2 # snow density | ||
RHOG = 4.0e2 # graupel density | ||
RHOR = 1.0e3 # density of rain water, lin83 | ||
DZ_MIN_FLIP = 1.0e-2 # Use for correcting flipped height | ||
QCMIN = 1.0e-12 # Minimum value for cloud condensation | ||
QRMIN = 1.0e-8 # Minimum value for rain water | ||
QVMIN = 1.0e-20 # Minimum value for water vapor (treated as zero) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for consolidating these!
|
||
# Ice | ||
if constants.const_vi == 1: | ||
if const_vi: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't realize you could pass boolean as externals
|
||
else: | ||
|
||
tc = tk - constants.tice | ||
tc = tk - tice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is the different tice
from T_ICE
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's very weird. in fortran it is tice vs t_ice
) | ||
vti = vi0 * exp(log_10 * vti) * 0.8 | ||
vti = min(constants.vi_max, max(constants.vf_min, vti)) | ||
vti = min(vi_max, max(VF_MIN, vti)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that one is set in namelist but the others are just constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it should be in the namelist? it wasn't in the fortran, but seems like it would make sense to
* exp(0.0625 * log(qs * den / constants.norms)) | ||
) | ||
vts = min(constants.vs_max, max(constants.vf_min, vts)) | ||
vts = vs_fac * VCONS * rhof * exp(0.0625 * log(qs * den / NORMS)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's interesting to me that everything is a constant/variable but then they put 0.0625
fv3core/fv3core/_config.py
Outdated
do_sedi_w: bool = NamelistDefaults.do_sedi_w | ||
fast_sat_adj: bool = NamelistDefaults.fast_sat_adj | ||
fix_negative: bool = NamelistDefaults.fix_negative | ||
irain_f: float = NamelistDefaults.irain_f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should be a boolean too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that one is set to a integer in fortran (though the name sounds like it should be a float haha)
@@ -653,7 +667,7 @@ def warm_rain( | |||
|
|||
# Auto-conversion assuming linear subgrid vertical distribution of | |||
# cloud water following lin et al. 1994, mwr | |||
if constants.irain_f != 0: | |||
if irain_f != 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think people have namelists with this as 0 or 1
@@ -794,7 +808,7 @@ def sedimentation( | |||
|
|||
with interval(0, 1): | |||
|
|||
if tz > constants.tice: | |||
if tz > tice: | |||
stop_k = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we cannot have temporary boolean right? Is this something that we should support when we add typed temporaries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can, it'll just be a 3d boolean
): | ||
zt = zt[0, 0, -1] - constants.dz_min | ||
if (vi_fac >= 1.0e-5) and (no_fall[0, 0, -1] == 0) and (zt >= zt[0, 0, -1]): | ||
zt = zt[0, 0, -1] - functions.DZ_MIN_FLIP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is okay because DZ_MIN_FLIP
is just a constant used inside microphysics functions. But I was confused in the first place that this is a function. This is optional - but maybe we should change the import package as name to something other than functions
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is also true that constants are all caps, so this should also fine as it is