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

Fix handling of finidat with cold starts #2870

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2588,12 +2588,9 @@ sub setup_logic_initial_conditions {
my $finidat = $nl->get_value($var);
$nl_flags->{'excess_ice_on_finidat'} = "unknown";
if ( $nl_flags->{'clm_start_type'} =~ /cold/ ) {
if (defined $finidat ) {
$log->warning("setting $var (either explicitly in your user_nl_clm or by doing a hybrid or branch RUN_TYPE)\n is incomptable with using a cold start" .
if (defined $finidat && !&value_is_true(($nl->get_value('use_fates')))) {
$log->fatal_error("setting $var (either explicitly in your user_nl_clm or by doing a hybrid or branch RUN_TYPE)\n is incompatible with using a cold start" .
" (by setting CLM_FORCE_COLDSTART=on)." );
$log->warning("Overridding input $var file with one specifying that this is a cold start from arbitrary initial conditions." );
my $group = $definition->get_group_name($var);
$nl->set_variable_value($group, $var, "' '" );
}
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl,
$var, 'val'=>"' '", 'no_abspath'=>1);
Expand Down
54 changes: 50 additions & 4 deletions bld/unit_testers/build-namelist_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1318,10 +1318,6 @@ sub cat_and_create_namelistinfile {

my %warntest = (
# Warnings without the -ignore_warnings option given
"coldwfinidat" =>{ options=>"-envxml_dir . -clm_start_type cold",
namelst=>"finidat = 'testfile.nc'",
phys=>"clm5_0",
},
"bgcspin_w_suplnitro" =>{ options=>"-envxml_dir . -bgc bgc -clm_accelerated_spinup on",
namelst=>"suplnitro='ALL'",
phys=>"clm5_0",
Expand Down Expand Up @@ -1402,6 +1398,56 @@ sub cat_and_create_namelistinfile {
system( "cat $tempfile" );
}

print "\n===============================================================================\n";
ekluzek marked this conversation as resolved.
Show resolved Hide resolved
print "Ensure cold starts with finidat are handled properly \n";
print "=================================================================================\n";

my %coldwfinidat = (
"bgc" => { options=>"-envxml_dir . -clm_start_type cold",
namelst=>"finidat = 'testfile.nc'",
phys=>"clm5_0",
expected_fail=>1,
},
"fates" => { options=>"-envxml_dir . -clm_start_type cold -bgc fates -no-megan",
namelst=>"finidat = 'testfile.nc', use_fates = .true.",
phys=>"clm5_0",
expected_fail=>0,
},
);
my $finidat;
foreach my $key ( keys(%coldwfinidat) ) {
print( "$key\n" );

my $var;
foreach $var ( "phys" , "options", "namelst", "expected_fail" ) {
if ( not exists $coldwfinidat{$key}{$var} ) {
die "ERROR: Subkey $var does not exist for coldwfinidat $key\nERROR:Check if you spelled $var correctly\n"
}
}

&make_config_cache($coldwfinidat{$key}{"phys"});
my $options = $coldwfinidat{$key}{"options"};
my $namelist = $coldwfinidat{$key}{"namelst"};
my $expected_fail = $coldwfinidat{$key}{"expected_fail"};
my %settings;
&make_env_run( %settings );

# Should fail if expected to, pass otherwise
eval{ system( "$bldnml $options -namelist \"&clmexp $namelist /\" > $tempfile 2>&1 " ); };
is( $? eq 0, $expected_fail eq 0, "coldwfinidat $key run");

if ( $expected_fail ) {
# Now run with -ignore_warnings and make sure it still doesn't work
$options .= " -ignore_warnings";
eval{ system( "$bldnml $options -namelist \"&clmexp $namelist /\" > $tempfile 2>&1 " ); };
isnt( $?, 0, "coldwfinidat $key run -ignore_warnings" );
} else {
# Check that finidat was correctly set
$finidat = `grep finidat lnd_in`;
ok ( $finidat =~ "testfile.nc", "coldwfinidat $key finidat? $finidat" );
}
}

#
# Loop over all physics versions
#
Expand Down
Loading