Skip to content

Commit d143fc8

Browse files
committed
Merge branch 'lilac_cap'
Add LILAC Add LILAC: The Lightweight Infrastructure for Land-Atmosphere Coupling. This infrastructure consists of two major pieces: (1) A lightweight coupling infrastructure built on top of ESMF that makes it easier for atmosphere models to call CTSM directly, rather than using the hub-and-spoke architecture that is used by CESM. (2) A set of python-based tools for building CTSM and creating its runtime inputs when running in an atmosphere model via LILAC. Although these tools are built on top of cime, details of the create_newcase / case.setup / case.build process are hidden from the user, because many of the aspects of this workflow don't make sense in the LILAC context. So far we have used LILAC to couple CTSM to WRF. There are plans to use the same infrastructure to couple CTSM to other regional atmosphere models. Documentation of LILAC is provided in https://escomp.github.io/ctsm-docs/versions/master/html/lilac/index.html (though there are still some missing sections), as well as in various presentations on the wiki (https://github.com/ESCOMP/CTSM/wiki/Presentations). There have been many contributors besides myself to the development, testing and documentation of LILAC; chief among them being Mariana Vertenstein, Negin Sobhani, Joe Hamman, Sam Levis, Mike Barlage and Dave Lawrence.
2 parents 488860d + cb94fb4 commit d143fc8

File tree

123 files changed

+15355
-491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+15355
-491
lines changed

README.lilac

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
========================================================================
2+
I. Building a CTSM / LILAC library for inclusion in an atmosphere model
3+
========================================================================
4+
5+
1) check out the code (ctsm and lilac are now bundled together) and built as one library
6+
7+
> git clone https://github.com/ESCOMP/ctsm.git
8+
> git checkout lilac_cap
9+
> ./manage_externals/checkout_externals -v
10+
11+
2) set the following environment variables
12+
SRCROOT is where ctsm is checked out
13+
14+
> export SRCROOT=`pwd`
15+
> export CASEDIR=/glade/scratch/$USER/test_lilac
16+
17+
3) build the ctsm/lilac library using a CIME case
18+
19+
> cd $SRCROOT/cime/scripts
20+
> ./create_newcase --case $CASEDIR --compset I2000Clm50SpRsGs --res f45_f45_mg37 --run-unsupported --driver nuopc
21+
> cd $CASEDIR
22+
> ./xmlchange LILAC_MODE=on
23+
> ./xmlchange DEBUG=TRUE
24+
> ./case.setup
25+
> ./case.build --sharedlib-only
26+
27+
========================================================================
28+
II. Building and running the test atmosphere driver
29+
========================================================================
30+
31+
After following the above instructions for building a CTSM / LILAC
32+
library (I), do the following:
33+
34+
1) To build the atm_driver executable on cheyenne (***CTSM_MKFILE IS CRITICAL for the operation of the atm_driver makefile)
35+
36+
> export CTSM_MKFILE=$CASEDIR/bld/ctsm.mk
37+
> cd $SRCROOT/lilac/atm_driver
38+
> $SRCROOT/cime/tools/configure --comp-interface nuopc --macros-format Makefile --clean
39+
> make clean
40+
> source ./.env_mach_specific.sh
41+
> export DEBUG=TRUE
42+
> make COMPILER=intel atm_driver
43+
44+
2) to generate the input namelists
45+
46+
- to customize the generated namelist - edit the file ctsm.cfg (in this directory)
47+
- to create the ctsm namelist FROM THIS DIRECTORY:
48+
49+
> $SRCROOT/lilac_config/buildnml
50+
51+
- this will now create the files lnd_in and clm.input_data_list in this directory
52+
THIS ONLY NEEDS TO BE DONE ONCE
53+
to futher customize the lnd_in (say to adjust the ctsm history output) edit the generated lnd_in in this directory
54+
55+
3) run the atm_driver on cheyenne
56+
57+
> qsub cheyenne.sub
58+
59+
4) compare with latest baselines
60+
61+
use something like this to compare the last clm and last cpl hist files:
62+
63+
> basedir=/glade/p/cgd/tss/ctsm_baselines/lilac_20191202
64+
> cprnc test_lilac.clm2.h0.2000-01-03-00000.nc $basedir/test_lilac.clm2.h0.2000-01-03-00000.nc | tail -30
65+
> cprnc test_lilac.lilac.hi.2000-01-02-81000.nc $basedir/test_lilac.lilac.hi.2000-01-02-81000.nc | tail -30
66+
> cprnc -m test_lilac.atm.h0.0001-01.nc $basedir/test_lilac.atm.h0.0001-01.nc | tail -30
67+
68+
5) if there are differences, and those are intentional, then create new
69+
baselines
70+
71+
copy all *.nc files, plus ctsm.cfg, lilac_in and lnd_in to the
72+
baseline directory
73+
74+
========================================================================
75+
III. Linking the CTSM / LILAC library into another atmosphere model
76+
========================================================================
77+
78+
After following the above instructions for building a CTSM / LILAC
79+
library (I), you should do the following, assuming that the atmosphere
80+
model is built using a makefile:
81+
82+
1) Set some environment variable (e.g., CTSM_MKFILE) to point to the
83+
ctsm.mk file generated in CTSM's bld directory.
84+
85+
2) Modify the atmosphere model's makefile to include the file given by
86+
the environment variable $CTSM_MAKEFILE.
87+
88+
3) In the compilation line for the atmosphere model, add
89+
$(CTSM_INCLUDES)
90+
91+
4) In the link line for the atmosphere model, add $(CTSM_LIBS)
92+
93+
========================================================================
94+
IV. Running CTSM / LILAC from another atmosphere model
95+
========================================================================
96+
97+
After (III), the following steps are needed to stage the inputs needed
98+
for running the atmosphere model
99+
100+
1) Generate the input namelists following the instructions given in part
101+
(II).
102+
103+
2) Copy the following files from $SRCROOT/lilac/atm_driver into the
104+
directory from which the atmosphere model will be run:
105+
106+
- lilac_in
107+
- lnd_in
108+
- lnd_modelio.nml
109+
110+
3) Run the atmosphere model

bld/CLMBuildNamelist.pm

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use File::Basename qw(dirname);
3535
use English;
3636
use Getopt::Long;
3737
use IO::File;
38-
use File::Glob ':glob';
38+
use File::Glob ':bsd_glob';
3939

4040
#-------------------------------------------------------------------------------
4141
#
@@ -189,7 +189,6 @@ OPTIONS
189189
form \$CASEDIR/user_nl_clm/user_nl_clm_????)
190190
-inputdata "filepath" Writes out a list containing pathnames for required input datasets in
191191
file specified.
192-
-l_ncpl "LND_NCPL" Number of CLM coupling time-steps in a day.
193192
-lnd_tuning_mode "value" Use the parameters tuned for the given configuration (CLM version and atmospheric forcing)
194193
-mask "landmask" Type of land-mask (default, navy, gx3v5, gx1v5 etc.)
195194
"-mask list" to list valid land masks.
@@ -255,7 +254,6 @@ sub process_commandline {
255254
help => 0,
256255
glc_nec => "default",
257256
light_res => "default",
258-
l_ncpl => undef,
259257
lnd_tuning_mode => "default",
260258
lnd_frac => undef,
261259
dir => "$cwd",
@@ -307,7 +305,6 @@ sub process_commandline {
307305
"infile=s" => \$opts{'infile'},
308306
"lnd_frac=s" => \$opts{'lnd_frac'},
309307
"lnd_tuning_mode=s" => \$opts{'lnd_tuning_mode'},
310-
"l_ncpl=i" => \$opts{'l_ncpl'},
311308
"inputdata=s" => \$opts{'inputdata'},
312309
"mask=s" => \$opts{'mask'},
313310
"namelist=s" => \$opts{'namelist'},
@@ -477,7 +474,7 @@ sub read_envxml_case_files {
477474
my %envxml = ();
478475
if ( defined($opts->{'envxml_dir'}) ) {
479476
(-d $opts->{'envxml_dir'}) or $log->fatal_error( "envxml_dir is not a directory" );
480-
my @files = glob( $opts->{'envxml_dir'}."/env_*xml" );
477+
my @files = bsd_glob( $opts->{'envxml_dir'}."/env_*xml" );
481478
($#files >= 0) or $log->fatal_error( "there are no env_*xml files in the envxml_dir" );
482479
foreach my $file (@files) {
483480
$log->verbose_message( "Open env.xml file: $file" );
@@ -1394,9 +1391,6 @@ sub process_namelist_commandline_clm_usr_name {
13941391
$nvars++;
13951392
}
13961393
}
1397-
if ( $nvars == 0 ) {
1398-
$log->message("setting clm_usr_name -- but did NOT find any user datasets: $opts->{'clm_usr_name'}", $opts);
1399-
}
14001394
# Go through all variables and expand any XML env settings in them
14011395
expand_xml_variables_in_namelist( $nl_usrfile, $envxml_ref );
14021396
# Merge input values into namelist. Previously specified values have higher precedence
@@ -1438,7 +1432,7 @@ sub process_namelist_commandline_use_case {
14381432
my $val = $uc_defaults->get_value($var, \%settings );
14391433

14401434
if ( defined($val) ) {
1441-
$log->message("CLM adding use_case $opts->{'use_case'} defaults for var '$var' with val '$val'");
1435+
$log->verbose_message("CLM adding use_case $opts->{'use_case'} defaults for var '$var' with val '$val'");
14421436

14431437
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl_usecase, $var, 'val'=>$val);
14441438
}
@@ -1486,7 +1480,6 @@ sub process_namelist_inline_logic {
14861480
setup_logic_co2_type($opts, $nl_flags, $definition, $defaults, $nl);
14871481
setup_logic_irrigate($opts, $nl_flags, $definition, $defaults, $nl);
14881482
setup_logic_start_type($opts, $nl_flags, $nl);
1489-
setup_logic_delta_time($opts, $nl_flags, $definition, $defaults, $nl);
14901483
setup_logic_decomp_performance($opts, $nl_flags, $definition, $defaults, $nl);
14911484
setup_logic_snow($opts, $nl_flags, $definition, $defaults, $nl);
14921485
setup_logic_glacier($opts, $nl_flags, $definition, $defaults, $nl, $envxml_ref);
@@ -1862,28 +1855,6 @@ sub setup_logic_start_type {
18621855

18631856
#-------------------------------------------------------------------------------
18641857

1865-
sub setup_logic_delta_time {
1866-
my ($opts, $nl_flags, $definition, $defaults, $nl) = @_;
1867-
1868-
if ( defined($opts->{'l_ncpl'}) ) {
1869-
my $l_ncpl = $opts->{'l_ncpl'};
1870-
if ( $l_ncpl <= 0 ) {
1871-
$log->fatal_error("bad value for -l_ncpl option.");
1872-
}
1873-
my $val = ( 3600 * 24 ) / $l_ncpl;
1874-
my $dtime = $nl->get_value('dtime');
1875-
if ( ! defined($dtime) ) {
1876-
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'dtime', 'val'=>$val);
1877-
} elsif ( $dtime ne $val ) {
1878-
$log->fatal_error("can NOT set both -l_ncpl option (via LND_NCPL env variable) AND dtime namelist variable.");
1879-
}
1880-
} else {
1881-
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'dtime', 'hgrid'=>$nl_flags->{'res'});
1882-
}
1883-
}
1884-
1885-
#-------------------------------------------------------------------------------
1886-
18871858
sub setup_logic_decomp_performance {
18881859
my ($opts, $nl_flags, $definition, $defaults, $nl) = @_;
18891860

@@ -4203,7 +4174,7 @@ sub validate_options {
42034174
# create the @expect array by listing the files in $use_case_dir
42044175
# and strip off the ".xml" part of the filename
42054176
@expect = ();
4206-
my @files = glob("$opts->{'use_case_dir'}/*.xml");
4177+
my @files = bsd_glob("$opts->{'use_case_dir'}/*.xml");
42074178
foreach my $file (@files) {
42084179
$file =~ m{.*/(.*)\.xml};
42094180
&check_use_case_name( $1 );
@@ -4217,7 +4188,7 @@ sub validate_options {
42174188
} else {
42184189
print "Use cases are:...\n\n";
42194190
my @ucases;
4220-
foreach my $file( sort( glob($opts->{'use_case_dir'}."/*.xml") ) ) {
4191+
foreach my $file( sort( bsd_glob($opts->{'use_case_dir'}."/*.xml") ) ) {
42214192
my $use_case;
42224193
if ( $file =~ /\/([^\/]+)\.xml$/ ) {
42234194
&check_use_case_name( $1 );

bld/namelist_files/namelist_defaults_ctsm.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ attributes from the config_cache.xml file (with keys converted to upper-case).
1919

2020
<sim_year>2000</sim_year>
2121

22-
<!-- Default time step -->
23-
<dtime>1800</dtime>
24-
2522
<!-- CO2 volume mixing ratio -->
2623
<co2_ppmv sim_year="1000" >379.0</co2_ppmv>
2724
<co2_ppmv sim_year="2000" >379.0</co2_ppmv>

bld/namelist_files/namelist_definition_ctsm.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,6 @@ The maximum value to use for zeta under stable conditions
619619
baseline proportion of nitrogen allocated for electron transport (J)
620620
</entry>
621621

622-
<entry id="dtime" type="real" category="clm_physics"
623-
group="clm_inparm" valid_values="">
624-
Time step (seconds)
625-
</entry>
626-
627622
<entry id="use_fates" type="logical" category="physics"
628623
group="clm_inparm" valid_values="" value=".false.">
629624
Toggle to turn on the FATES model

bld/unit_testers/build-namelist_test.pl

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ sub make_config_cache {
138138
#
139139
# Figure out number of tests that will run
140140
#
141-
my $ntests = 842;
141+
my $ntests = 834;
142142
if ( defined($opts{'compare'}) ) {
143-
$ntests += 510;
143+
$ntests += 507;
144144
}
145145
plan( tests=>$ntests );
146146

@@ -287,15 +287,15 @@ sub make_config_cache {
287287
&make_config_cache($phys);
288288

289289
print "\n===============================================================================\n";
290-
print "Test configuration, structure, irrigate, verbose, clm_demand, ssp_rcp, test, sim_year, use_case, l_ncpl\n";
290+
print "Test configuration, structure, irrigate, verbose, clm_demand, ssp_rcp, test, sim_year, use_case\n";
291291
print "=================================================================================\n";
292292

293-
# configuration, structure, irrigate, verbose, clm_demand, ssp_rcp, test, sim_year, use_case, l_ncpl
293+
# configuration, structure, irrigate, verbose, clm_demand, ssp_rcp, test, sim_year, use_case
294294
my $startfile = "clmrun.clm2.r.1964-05-27-00000.nc";
295295
foreach my $options ( "-configuration nwp",
296296
"-structure fast",
297297
"-namelist '&a irrigate=.true./'", "-verbose", "-ssp_rcp SSP1-2.6", "-test", "-sim_year 1850",
298-
"-use_case 1850_control", "-l_ncpl 1",
298+
"-use_case 1850_control",
299299
"-clm_start_type startup", "-namelist '&a irrigate=.false./' -crop -bgc bgc",
300300
"-envxml_dir . -infile myuser_nl_clm",
301301
"-ignore_ic_date -clm_start_type branch -namelist '&a nrevsn=\"thing.nc\"/' -bgc bgc -crop",
@@ -309,10 +309,7 @@ sub make_config_cache {
309309
$cfiles->checkfilesexist( "$options", $mode );
310310
$cfiles->shownmldiff( "default", $mode );
311311
my $finidat = `grep finidat lnd_in`;
312-
if ( $options eq "-l_ncpl 1" ) {
313-
my $dtime = `grep dtime lnd_in`;
314-
like( $dtime, "/ 86400\$/", "$options" );
315-
} elsif ( $options =~ /myuser_nl_clm/ ) {
312+
if ( $options =~ /myuser_nl_clm/ ) {
316313
my $fsurdat = `grep fsurdat lnd_in`;
317314
like( $fsurdat, "/MYDINLOCROOT/lnd/clm2/PTCLMmydatafiles/1x1pt_US-UMB/surfdata_1x1pt_US-UMB_simyr2000_clm4_5_c131122.nc/", "$options" );
318315
}
@@ -391,21 +388,6 @@ sub make_config_cache {
391388
GLC_TWO_WAY_COUPLING=>"FALSE",
392389
phys=>"clm5_0",
393390
},
394-
"l_ncpl is zero" =>{ options=>"-l_ncpl 0 -envxml_dir .",
395-
namelst=>"",
396-
GLC_TWO_WAY_COUPLING=>"FALSE",
397-
phys=>"clm5_0",
398-
},
399-
"l_ncpl not integer" =>{ options=>"-l_ncpl 1.0 -envxml_dir .",
400-
namelst=>"",
401-
GLC_TWO_WAY_COUPLING=>"FALSE",
402-
phys=>"clm5_0",
403-
},
404-
"both l_ncpl and dtime" =>{ options=>"-l_ncpl 24 -envxml_dir .",
405-
namelst=>"dtime=1800",
406-
GLC_TWO_WAY_COUPLING=>"FALSE",
407-
phys=>"clm5_0",
408-
},
409391
"use_crop without -crop" =>{ options=>" -envxml_dir .",
410392
namelst=>"use_crop=.true.",
411393
GLC_TWO_WAY_COUPLING=>"FALSE",

0 commit comments

Comments
 (0)