Skip to content
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

Merged
merged 22 commits into from
Dec 10, 2021
Merged

physics and dycore share constants #51

merged 22 commits into from
Dec 10, 2021

Conversation

rheacangeo
Copy link
Contributor

@rheacangeo rheacangeo commented Dec 8, 2021

  • 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

@rheacangeo rheacangeo changed the base branch from feature/move-gt4py-pace-dsl to main December 8, 2021 17:45
@rheacangeo rheacangeo changed the base branch from main to feature/move-gt4py-pace-dsl December 8, 2021 21:32
Copy link
Collaborator

@mcgibbon mcgibbon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@@ -64,6 +64,50 @@ class NamelistDefaults:
nf_omega = 1
fv_sg_adj = -1
n_sponge = 1
# all below added for physics
Copy link
Collaborator

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.

Suggested change
# all below added for physics
# all below are for physics

Copy link
Contributor Author

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

@rheacangeo
Copy link
Contributor Author

launch jenkins

@rheacangeo
Copy link
Contributor Author

launch jenkins

Copy link
Collaborator

@elynnwu elynnwu left a 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

Comment on lines +8 to +42
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)
Copy link
Collaborator

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:
Copy link
Collaborator

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
Copy link
Collaborator

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...

Copy link
Contributor Author

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))
Copy link
Collaborator

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

Copy link
Contributor Author

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))
Copy link
Collaborator

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

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
Copy link
Collaborator

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

Copy link
Contributor Author

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to boolean

Copy link
Contributor Author

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
Copy link
Collaborator

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?

Copy link
Contributor Author

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
Copy link
Collaborator

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?

Copy link
Collaborator

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

Base automatically changed from feature/move-gt4py-pace-dsl to main December 10, 2021 00:02
@rheacangeo rheacangeo enabled auto-merge (squash) December 10, 2021 00:44
@rheacangeo rheacangeo merged commit 2b2e9ae into main Dec 10, 2021
@rheacangeo rheacangeo deleted the shared-constants branch December 10, 2021 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants