Skip to content

Commit 28cca19

Browse files
Merge remote-tracking branch 'romanc/dsl/fix/microphysics' into dsl/fix/microphysics
2 parents 62457f5 + d5e0733 commit 28cca19

8 files changed

Lines changed: 67 additions & 43 deletions

File tree

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/pyMoist/convection/GF_2020/setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,11 @@ def __init__(
12851285
},
12861286
)
12871287

1288+
# Dev NOTE: this is an orchestration workaround. Direct call to
1289+
# `self.saturation_tables.X` fails closure capture for
1290+
# argument reconstruction at call time
1291+
self._esx = self.saturation_tables.esx
1292+
12881293
def __call__(
12891294
self,
12901295
state: GF2020State,
@@ -1325,7 +1330,7 @@ def __call__(
13251330
area=state.area,
13261331
modified_area=locals.derived_state.modified_area,
13271332
convection_fraction=state.convection_fraction,
1328-
esx=self.saturation_tables.esx,
1333+
esx=self._esx,
13291334
)
13301335

13311336
if state.seed_convection is not None:

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/pyMoist/microphysics/GFDL_1M/GFDL_1M.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def __init__(
116116
quantity_factory=quantity_factory,
117117
config=config,
118118
saturation_tables=saturation_tables,
119-
update_tendencies=self._update_tendencies,
120119
)
121120

122121
def __call__(

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/pyMoist/microphysics/GFDL_1M/driver/ice_cloud.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ def update_precip_total(
18511851
driver_sublimation: FloatField,
18521852
):
18531853
"""
1854-
ensure information is passed back to the rest of the model
1854+
Ensure information is passed back to the rest of the model.
18551855
"""
18561856
with computation(PARALLEL), interval(...):
18571857
sublimation = sublimation + driver_sublimation
@@ -1960,6 +1960,14 @@ def __init__(
19601960
compute_dims=[I_DIM, J_DIM, K_DIM],
19611961
)
19621962

1963+
# Dev NOTE: this is an orchestration workaround. Direct call to
1964+
# `self.saturation_tables.X` fails closure capture for
1965+
# argument reconstruction at call time
1966+
self._table2 = self.saturation_tables._table2
1967+
self._table3 = self.saturation_tables._table3
1968+
self._des2 = self.saturation_tables._des2
1969+
self._des3 = self.saturation_tables._des3
1970+
19631971
def __call__(
19641972
self,
19651973
t: FloatField,
@@ -2032,10 +2040,10 @@ def __call__(
20322040
ccn,
20332041
convection_fraction,
20342042
surface_type,
2035-
self.saturation_tables.table2,
2036-
self.saturation_tables.table3,
2037-
self.saturation_tables.des2,
2038-
self.saturation_tables.des3,
2043+
self._table2,
2044+
self._table3,
2045+
self._des2,
2046+
self._des3,
20392047
)
20402048

20412049
self._update_output(

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/pyMoist/microphysics/GFDL_1M/driver/warm_rain.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,18 @@ def __init__(
800800
compute_dims=[I_DIM, J_DIM, K_DIM],
801801
)
802802

803+
# Dev NOTE: this is an orchestration workaround. Direct call to
804+
# `self.saturation_tables.X` fails closure capture for
805+
# argument reconstruction at call time
806+
self._table1 = (self.saturation_tables.table1,)
807+
self._table2 = (self.saturation_tables.table2,)
808+
self._table3 = (self.saturation_tables.table3,)
809+
self._table4 = (self.saturation_tables.table4,)
810+
self._des1 = (self.saturation_tables.des1,)
811+
self._des2 = (self.saturation_tables.des2,)
812+
self._des3 = (self.saturation_tables.des3,)
813+
self._des4 = (self.saturation_tables.des4,)
814+
803815
def __call__(
804816
self,
805817
t: FloatField,
@@ -898,14 +910,14 @@ def __call__(
898910
z_interface=self._locals.z_interface,
899911
dmass=self._locals.dmass,
900912
precip_fall=self._locals.precip_fall,
901-
table1=self.saturation_tables.table1,
902-
table2=self.saturation_tables.table2,
903-
table3=self.saturation_tables.table3,
904-
table4=self.saturation_tables.table4,
905-
des1=self.saturation_tables.des1,
906-
des2=self.saturation_tables.des2,
907-
des3=self.saturation_tables.des3,
908-
des4=self.saturation_tables.des4,
913+
table1=self._table1,
914+
table2=self._table2,
915+
table3=self._table3,
916+
table4=self._table4,
917+
des1=self._des1,
918+
des2=self._des2,
919+
des3=self._des3,
920+
des4=self._des4,
909921
)
910922

911923
if not self.config.USE_PPM:
@@ -937,14 +949,14 @@ def __call__(
937949
w=w,
938950
rh_limited=rh_limited,
939951
dmass=self._locals.dmass,
940-
table1=self.saturation_tables.table1,
941-
table2=self.saturation_tables.table2,
942-
table3=self.saturation_tables.table3,
943-
table4=self.saturation_tables.table4,
944-
des1=self.saturation_tables.des1,
945-
des2=self.saturation_tables.des2,
946-
des3=self.saturation_tables.des3,
947-
des4=self.saturation_tables.des4,
952+
table1=self._table1,
953+
table2=self._table2,
954+
table3=self._table3,
955+
table4=self._table4,
956+
des1=self._des1,
957+
des2=self._des2,
958+
des3=self._des3,
959+
des4=self._des4,
948960
)
949961

950962
self._update_outputs(

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/pyMoist/microphysics/GFDL_1M/finalize.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pyMoist.constants import MAPL_CP, MAPL_GRAV
88
from pyMoist.microphysics.GFDL_1M.config import GFDL1MConfig
99
from pyMoist.microphysics.GFDL_1M.radiation_coupling import GFDL1MRadiationCoupling
10+
from pyMoist.microphysics.GFDL_1M.shared_stencils import update_tendencies
1011
from pyMoist.saturation_tables import GlobalTable_saturation_tables, SaturationVaporPressureTable, saturation_specific_humidity
1112
from pyMoist.shared.redistribute_clouds import redistribute_clouds
1213

@@ -220,14 +221,12 @@ def __init__(
220221
quantity_factory: QuantityFactory,
221222
config: GFDL1MConfig,
222223
saturation_tables: SaturationVaporPressureTable,
223-
update_tendencies,
224224
):
225225
# init NDSLRuntime
226226
super().__init__(stencil_factory)
227227

228228
# make the config, pre-build stencil, and saturation tables visible at runtime
229229
self.config = config
230-
self.update_tendencies = update_tendencies
231230
self.saturation_tables = saturation_tables
232231

233232
# construct stencils
@@ -268,6 +267,14 @@ def __init__(
268267
compute_dims=[I_DIM, J_DIM, K_DIM],
269268
)
270269

270+
self._update_tendencies = stencil_factory.from_dims_halo(
271+
func=update_tendencies,
272+
compute_dims=[I_DIM, J_DIM, K_DIM],
273+
externals={
274+
"DT_MOIST": config.DT_MOIST,
275+
},
276+
)
277+
271278
self._update_rainwater_source = stencil_factory.from_dims_halo(
272279
func=update_rainwater_source,
273280
compute_dims=[I_DIM, J_DIM, K_DIM],
@@ -501,7 +508,7 @@ def __call__(
501508
liquid_radius=cloud_particle_effective_radius_liquid,
502509
)
503510

504-
self.update_tendencies(
511+
self._update_tendencies(
505512
u=u,
506513
v=v,
507514
t=t,

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/pyMoist/microphysics/GFDL_1M/radiation_coupling.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ def __init__(
7777
if config.DO_QA:
7878
ndsl_log.log("[Radiation Coupling] DO_QA option implemented, but untested. " "Running untested code... proceed with caution")
7979

80+
# Dev NOTE: this is an orchestration workaround. Direct call to
81+
# `self.saturation_tables.X` fails closure capture for
82+
# argument reconstruction at call time
83+
self._esx = self.saturation_tables.esx
84+
8085
def __call__(
8186
self,
8287
t: Quantity,
@@ -178,5 +183,5 @@ def __call__(
178183
pressure=local_p_mb,
179184
vapor=mixing_ratio_vapor,
180185
humidity=relative_humidity_after_pdf,
181-
esx=self.saturation_tables.esx,
186+
esx=self._esx,
182187
)

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/pyMoist/microphysics/GFDL_1M/setup.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,12 @@ def compute_estimated_inversion_strength(
215215
lower_tropospheric_stability (FloatFieldIJ)
216216
estimated_inversion_strength (FloatFieldIJ)
217217
"""
218-
with computation(FORWARD), interval(0, 1):
219-
from __externals__ import k_end
220-
221-
lower_tropospheric_stability = th700 - th.at(K=k_end)
218+
with computation(FORWARD), interval(-1, None):
219+
lower_tropospheric_stability = th700 - th
222220
lcl_height = layer_height_above_surface.at(K=lcl_level - 1)
223221

224222
# Simplified single adiabat eq4 of https://doi.org/10.1175/JCLI3988.1
225-
t850 = 0.5 * (t.at(K=k_end) + t700)
223+
t850 = 0.5 * (t + t700)
226224
qs850, _ = saturation_specific_humidity(t=t850, p=100.0 * 850.0, esx=esx)
227225
gamma850 = (1.0 + (MAPL_ALHL * qs850 / (MAPL_RGAS * t850))) / (1.0 + (MAPL_ALHL * MAPL_ALHL * qs850 / (MAPL_CP * MAPL_RVAP * t850 * t850)))
228226
gamma850 = MAPL_GRAV / MAPL_CP * (1.0 - gamma850)
@@ -528,7 +526,7 @@ def __call__(
528526
mass=local_mass,
529527
mass_inverse=local_mass_inverse,
530528
t=t,
531-
esx=self.saturation_tables.esx,
529+
esx=self._esx,
532530
sat=local_saturation_specific_humidity,
533531
dsat=local_dsaturation_specific_humidity,
534532
u=u,

GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/tests/translate_tests/microphysics/GFDL_1M/translate_GFDL_1M_Finalize.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
from f90nml import Namelist
22
from ndsl import StencilFactory
3-
from ndsl.constants import I_DIM, J_DIM, K_DIM
43
from ndsl.stencils.testing.grid import Grid
54
from ndsl.stencils.testing.savepoint import DataLoader
65
from ndsl.stencils.testing.translate import TranslateFortranData2Py
76

87
from pyMoist.microphysics.GFDL_1M.config import GFDL1MConfig
98
from pyMoist.microphysics.GFDL_1M.finalize import GFDL1MFinalize
109
from pyMoist.microphysics.GFDL_1M.locals import GFDL1MLocals
11-
from pyMoist.microphysics.GFDL_1M.shared_stencils import update_tendencies
1210
from pyMoist.microphysics.GFDL_1M.state import GFDL1MState
1311
from pyMoist.saturation_tables.tables.main import SaturationVaporPressureTable
1412

@@ -146,19 +144,11 @@ def compute(self, inputs):
146144
state.tendencies.dvdt_micro.field[:] = inputs["dvdt_micro"]
147145
state.tendencies.dtdt_micro.field[:] = inputs["dtdt_micro"]
148146

149-
# construct test stencil
150-
_update_tendencies = self.stencil_factory.from_dims_halo(
151-
func=update_tendencies,
152-
compute_dims=[I_DIM, J_DIM, K_DIM],
153-
externals={"DT_MOIST": config.DT_MOIST},
154-
)
155-
156147
code = GFDL1MFinalize(
157148
stencil_factory=self.stencil_factory,
158149
quantity_factory=self.quantity_factory,
159150
config=config,
160151
saturation_tables=saturation_tables,
161-
update_tendencies=_update_tendencies,
162152
)
163153
code(
164154
t=state.t,

0 commit comments

Comments
 (0)