Skip to content

Commit d92fcf6

Browse files
authored
Merge pull request #638 from billsacks/water_tracers
Add water tracers ### Description of changes Core changes needed to add water tracers in CESM, for the sake of water isotopes and other purposes. Major pieces of this include: - XML and config variables for defining water tracers - Addition of all necessary water tracers in esmFldsExchange_cesm_mod and fd_cesm.yaml. These use an ungridded dimension for water tracers. - Calls to a routine to check that test tracers maintain their initial ratios. This ensures that tracers are being treated the same as their bulk counterparts (in terms of mapping, merging, etc.). - Addition of water tracer fields in med_test_comps, so this tracer infrastructure can be verified in an X compset test - Various other changes to some of the med_test_comps to better exercise CMEPS functionality, especially for the lnd -> glc mapping; also added some fields from GLC and to ROF in med_test_comps: Fgrg_rofi and Fgrg_rofl Some pieces are not yet implemented: - Including water tracers in the custom lnd->rof mapping - Including water tracers/isotopes in atm-ocn flux calculations - Including water tracers in the budget tables (med_diag_mod) Depends on ESCOMP/CESM_share#82 ### Specific notes Contributors other than yourself, if any: CMEPS Issues Fixed (include github issue #): - Resolves #583 (though this turned out to be much more extensive than simply reviewing and updating what had been in place before) - Resolves #601 Are changes expected to change answers? (specify if bfb, different at roundoff, more substantial) Changes answers for X compsets (due to some changed counter logic and maybe other things); should be bit-for-bit for all other compsets Any User Interface Changes (namelist or namelist defaults changes)? Adds xml and config variables controlling water tracers ### Testing performed In the context of cesm3_0_alpha08o, with this branch along with ESCOMP/CESM_share#82, ran CESM prealpha tests on derecho and izumi, and aux_glc tests on derecho, all with baseline comparisons. All failures also failed in the baseline except for `SMS_D_Ln9_P1536x1.ne0CONUSne30x8_ne0CONUSne30x8_mt12.FHIST.derecho_intel.cam-outfrq9s` (which seemed to fail due to ESCOMP/CTSM#3772, which is a sporadic issue), and all baseline comparisons passed. (Note: full testing was done before final commits addressing review points; only minimal additional testing was done after those final commits.)
2 parents a0343bc + 9e59f75 commit d92fcf6

40 files changed

Lines changed: 2350 additions & 775 deletions

cesm/driver/esm.F90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ subroutine InitAttributes(driver, rc)
401401
use shr_wv_sat_mod , only : shr_wv_sat_make_tables, ShrWVSatTableSpec
402402
use shr_wv_sat_mod , only : shr_wv_sat_get_scheme_idx, shr_wv_sat_valid_idx
403403
use glc_elevclass_mod, only : glc_elevclass_init
404+
use shr_wtracers_mod , only : shr_wtracers_init
404405
!use shr_scam_mod , only : shr_scam_checkSurface
405406

406407
! input/output variables
@@ -544,6 +545,13 @@ subroutine InitAttributes(driver, rc)
544545
call shr_wv_sat_make_tables(liquid_spec, ice_spec, mixed_spec)
545546
end if
546547

548+
!----------------------------------------------------------
549+
! Initialize water tracer info
550+
!----------------------------------------------------------
551+
552+
call shr_wtracers_init(driver, maintask, rc)
553+
if (chkerr(rc,__LINE__,u_FILE_u)) return
554+
547555
end subroutine InitAttributes
548556

549557
!================================================================================

cesm/share_wrappers/wtracers_mod.F90

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@ module wtracers_mod
44
! This module wraps shr_wtracers_mod from the CESM_share repository to avoid direct
55
! dependencies on this share code from CMEPS.
66
!
7+
! It is acceptable for CESM-specific CMEPS code (e.g., in the cesm directory) to call
8+
! directly into shr_wtracers_mod, but CMEPS code shared between CESM and other modeling
9+
! systems (e.g., UFS) should go through this module.
10+
!
711
! See also the version of wtracers_mod in the ufs directory for when we do not have
812
! access to the CESM_share library.
913
!-----------------------------------------------------------------------------
1014

11-
use shr_wtracers_mod, only : wtracers_is_wtracer_field => shr_wtracers_is_wtracer_field
15+
use shr_wtracers_mod, only : wtracers_present => shr_wtracers_present
16+
use shr_wtracers_mod, only : wtracers_get_num_tracers => shr_wtracers_get_num_tracers
17+
use shr_wtracers_mod, only : wtracers_is_wtracer_field => shr_wtracers_is_wtracer_field
18+
use shr_wtracers_mod, only : wtracers_get_bulk_fieldname => shr_wtracers_get_bulk_fieldname
19+
use shr_wtracers_mod, only : wtracers_check_tracer_ratios => shr_wtracers_check_tracer_ratios
20+
use shr_wtracers_mod, only : WTRACERS_SUFFIX
1221

1322
implicit none
1423
private
1524

16-
public :: wtracers_is_wtracer_field ! return true if the given field name is a water tracer field
25+
public :: wtracers_present ! return true if there are water tracers in this simulation
26+
public :: wtracers_get_num_tracers ! get number of water tracers in this simulation
27+
public :: wtracers_is_wtracer_field ! return true if the given field name is a water tracer field
28+
public :: wtracers_get_bulk_fieldname ! return the name of the equivalent bulk field corresponding to a water tracer field
29+
public :: wtracers_check_tracer_ratios ! check tracer ratios against expectations
30+
31+
public :: WTRACERS_SUFFIX ! suffix for water tracer field names
1732

1833
end module wtracers_mod

cime_config/buildnml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ def _create_drv_namelists(case, infile, confdir, nmlgen, files):
305305
nmlgen.set_value("esp_cpl_dt", value=esp_time)
306306
# End if pause is active
307307

308+
# --------------------------------
309+
# Overwrite: set water tracers
310+
# --------------------------------
311+
_add_water_tracers(case.get_value("WATER_TRACERS"), nmlgen)
312+
308313
# --------------------------------
309314
# Specify input data list file
310315
# --------------------------------
@@ -553,6 +558,44 @@ def _create_drv_namelists(case, infile, confdir, nmlgen, files):
553558
nmlgen.write_output_file(drv_flds_in)
554559

555560

561+
###############################################################################
562+
def _add_water_tracers(water_tracers_xml, nmlgen):
563+
###############################################################################
564+
565+
if not water_tracers_xml.strip():
566+
water_tracers = []
567+
else:
568+
water_tracers = water_tracers_xml.split(":")
569+
tracer_names = []
570+
tracer_species = []
571+
tracer_initial_ratios = []
572+
573+
for tracer in water_tracers:
574+
# Each item in the list consists of a name and then, optionally, a '%' followed by
575+
# the isotope species for this tracer. For standard water tracers (i.e., tracers
576+
# of bulk water), the list item will only contain the name (without a '%').
577+
expect(
578+
tracer.count("%") <= 1,
579+
f"Invalid WATER_TRACERS element, '{tracer}': Each element of WATER_TRACERS must contain at most 1 '%' separator",
580+
)
581+
parts = tracer.split("%")
582+
tracer_names.append(parts[0])
583+
if len(parts) > 1:
584+
tracer_species.append(parts[1])
585+
# We could check the validity of the species name here (confirming that it's
586+
# one of the handled species), but that would lead to this allowed list being
587+
# replicated in multiple places (here as well as in the Fortran), which would
588+
# make it more difficult to add new species later. So we're deferring this
589+
# check to runtime.
590+
else:
591+
tracer_species.append("-")
592+
tracer_initial_ratios.append("1.0")
593+
594+
nmlgen.add_default("water_tracer_names", ":".join(tracer_names))
595+
nmlgen.add_default("water_tracer_species", ":".join(tracer_species))
596+
nmlgen.add_default("water_tracer_initial_ratios", ":".join(tracer_initial_ratios))
597+
598+
556599
###############################################################################
557600
def _create_runseq(case, coupling_times, valid_comps):
558601
###############################################################################

cime_config/config_component_cesm.xml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@
501501
</entry>
502502

503503
<!-- ===================================================================== -->
504-
<!-- averaged history frequencies -->
504+
<!-- controls over various other options -->
505505
<!-- ===================================================================== -->
506506

507507
<entry id="BUDGETS">
@@ -581,5 +581,30 @@
581581
<desc>Freezing point calculation for salt water.</desc>
582582
</entry>
583583

584+
<entry id="WATER_TRACERS">
585+
<type>char</type>
586+
<default_value></default_value>
587+
<group>run_coupling</group>
588+
<file>env_run.xml</file>
589+
<desc>
590+
Colon-delimited list of water tracers enabled in this run.
591+
592+
Each item in the list consists of a name and then, optionally, a '%' followed by the
593+
isotope species for this tracer. For standard water tracers (i.e., tracers of bulk
594+
water), the list item will only contain the name (without a '%'). The name can be
595+
anything; if an isotope species is specified, it must match one of the implemented
596+
water isotopes: H218O, H217O or HDO. By convention, a tracer that is the full
597+
quantity of a given isotope will have a name that is identical to the species (e.g.,
598+
H218O:H218O).
599+
600+
For example, this list could be:
601+
MyRegularTracer:HDO%HDO:H218O%H218O:SomeOtherTracer:MyHdoTracer%HDO:YetAnotherTracer
602+
603+
This specifies three standard (bulk water) tracers (MyRegularTracer, SomeOtherTracer
604+
and YetAnotherTracer), two isotopes (HDO and H218O), and a tracer that is a subset
605+
of HDO (MyHdoTracer). (Note that the ordering in the list is not important.)
606+
</desc>
607+
</entry>
608+
584609

585610
</entry_id>

cime_config/namelist_definition_drv.xml

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,6 @@
853853
</desc>
854854
<values>
855855
<value>on</value>
856-
<value COMP_LND="xlnd">off</value>
857856
</values>
858857
</entry>
859858
<entry id="remove_negative_runoff_lnd">
@@ -2537,18 +2536,6 @@
25372536
</values>
25382537
</entry>
25392538

2540-
<entry id="flds_wiso" modify_via_xml="FLDS_WISO">
2541-
<type>logical</type>
2542-
<category>flds</category>
2543-
<group>ALLCOMP_attributes</group>
2544-
<desc>
2545-
Pass water isotopes between components
2546-
</desc>
2547-
<values>
2548-
<value>.false.</value>
2549-
</values>
2550-
</entry>
2551-
25522539
<entry id="flds_r2l_stream_channel_depths">
25532540
<type>logical</type>
25542541
<category>flds</category>
@@ -2599,6 +2586,66 @@
25992586
</values>
26002587
</entry>
26012588

2589+
<entry id="water_tracer_names" modify_via_xml="WATER_TRACERS" skip_default_entry="true">
2590+
<type>char</type>
2591+
<category>water_tracers</category>
2592+
<group>ALLCOMP_attributes</group>
2593+
<desc>
2594+
Colon-delimited list of names of water tracers in this run.
2595+
</desc>
2596+
<values>
2597+
<value></value>
2598+
</values>
2599+
</entry>
2600+
2601+
<entry id="water_tracer_species" modify_via_xml="WATER_TRACERS" skip_default_entry="true">
2602+
<type>char</type>
2603+
<category>water_tracers</category>
2604+
<group>ALLCOMP_attributes</group>
2605+
<desc>
2606+
Colon-delimited list of species of water tracers in this run.
2607+
2608+
Each element in the list corresponds to an element in water_tracer_names. A value of
2609+
'-' for a given element indicates a standard water tracer (i.e., a tracer of bulk
2610+
water).
2611+
</desc>
2612+
<values>
2613+
<value></value>
2614+
</values>
2615+
</entry>
2616+
2617+
<entry id="water_tracer_initial_ratios" skip_default_entry="true">
2618+
<type>char</type>
2619+
<category>water_tracers</category>
2620+
<group>ALLCOMP_attributes</group>
2621+
<desc>
2622+
Colon-delimited list of initial water tracer ratios (as a fraction of total water).
2623+
2624+
Each element in the list corresponds to an element in water_tracer_names.
2625+
2626+
For water isotopes, this ratio is typically set to 1 for numerical reasons; the
2627+
actual isotopic ratios can then be determined via reference to standard global
2628+
ratios.
2629+
</desc>
2630+
<values>
2631+
<value></value>
2632+
</values>
2633+
</entry>
2634+
2635+
<entry id="water_tracers_do_checks">
2636+
<type>logical</type>
2637+
<category>water_tracers</category>
2638+
<group>ALLCOMP_attributes</group>
2639+
<desc>
2640+
Check consistency between water tracer fields and their corresponding bulk fields.
2641+
2642+
This should only be used with artificial tracers that maintain a fixed ratio.
2643+
</desc>
2644+
<values>
2645+
<value>.false.</value>
2646+
</values>
2647+
</entry>
2648+
26022649
<!-- =========================== -->
26032650
<!-- CLOCK Attributes -->
26042651
<!-- =========================== -->

cime_config/testdefs/testlist_drv.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@
247247
</options>
248248
</test>
249249

250+
<test compset="X" grid="f19_g17" name="SMS_D_Ld2" testmods="drv/water_tracers--drv/glc_avg_frequently">
251+
<machines>
252+
<machine name="derecho" compiler="intel" category="aux_cmeps"/>
253+
<machine name="derecho" compiler="intel" category="prealpha"/>
254+
</machines>
255+
<options>
256+
<option name="wallclock"> 00:20:00 </option>
257+
<option name="comment">Test handling of water tracers in CMEPS; includes glc_avg_frequently testmod to exercise the lnd-to-glc mapping.</option>
258+
</options>
259+
</test>
260+
250261
<!-- ======================================= -->
251262
<!-- TG compsets -->
252263
<!-- ======================================= -->
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This testmod turns on more frequent averaging of the fields sent to glc so that the
2+
mapping of these fields can be tested in a run shorter than a year.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./xmlchange GLC_AVG_PERIOD=glc_coupling_period
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This testmod turns on multiple water tracers along with checks to ensure that they
2+
maintain their correct ratio over time. (These checks will only pass if the water tracers
3+
used in the test do not invoke any physics that would cause a change in their ratios.)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./xmlchange WATER_TRACERS=tracer1:tracer2

0 commit comments

Comments
 (0)