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

Implementation of irrigation stream file #2102

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
53 changes: 52 additions & 1 deletion bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,11 @@ sub process_namelist_inline_logic {
# namelist group: soil_moisture_streams #
##########################################
setup_logic_soilm_streams($opts, $nl_flags, $definition, $defaults, $nl, $physv);

##########################################
# namelist group: irrigation_streams #
##########################################
setup_logic_irrig_streams($opts, $nl_flags, $definition, $defaults, $nl, $physv);

##################################
# namelist group: bgc_shared
Expand Down Expand Up @@ -3837,6 +3842,52 @@ sub setup_logic_soilm_streams {

#-------------------------------------------------------------------------------

sub setup_logic_irrig_streams {
my ($opts, $nl_flags, $definition, $defaults, $nl, $physv) = @_;
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_irrigation_streams');
if ( &value_is_true( $nl->get_value('use_irrigation_streams') ) ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'irrig_tintalgo',
'hgrid'=>$nl_flags->{'res'} );
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'irrig_offset',
'hgrid'=>$nl_flags->{'res'} );
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_year_first_irrig', 'phys'=>$nl_flags->{'phys'},
'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_year_last_irrig', 'phys'=>$nl_flags->{'phys'},
'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
# Set align year, if first and last years are different
if ( $nl->get_value('stream_year_first_irrig') !=
$nl->get_value('stream_year_last_irrig') ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl,
'model_year_align_irrig', 'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
}
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_fldfilename_irrig', 'phys'=>$nl_flags->{'phys'},
'hgrid'=>$nl_flags->{'res'} );
if ( ($opts->{'use_case'} =~ /_transient$/) &&
(remove_leading_and_trailing_quotes($nl->get_value("irrig_tintalgo")) eq "linear") ) {
$log->warning("For a transient case, irrigation streams, should NOT use irrig_tintalgo='linear'" .
" since vegetated areas could go from missing to not missing or vice versa" );
}
} else {
if ( defined($nl->get_value('stream_year_first_irrig')) ||
defined($nl->get_value('model_year_align_irrig')) ||
defined($nl->get_value('stream_fldfilename_irrig')) ||
defined($nl->get_value('irrig_tintalgo')) ||
defined($nl->get_value('irrig_offset')) ||
defined($nl->get_value('stream_year_last_irrig')) ) {
$log->fatal_error("One of the irrig streams namelist items (stream_year_first_irrig, " .
" model_year_align_irrig, stream_fldfilename_irrig, stream_fldfilename_irrig)" .
" soilm_tintalgo irrig_offset" .
" is defined, but use_irrigation_streams option NOT set to true");
}
}

}

#-------------------------------------------------------------------------------

sub setup_logic_lai_streams {
my ($opts, $nl_flags, $definition, $defaults, $nl) = @_;

Expand Down Expand Up @@ -4263,7 +4314,7 @@ sub write_output_files {
# CLM component
my @groups;
@groups = qw(clm_inparm ndepdyn_nml popd_streams urbantv_streams light_streams
soil_moisture_streams lai_streams atm2lnd_inparm lnd2atm_inparm clm_canopyhydrology_inparm cnphenology
soil_moisture_streams irrigation_streams lai_streams atm2lnd_inparm lnd2atm_inparm clm_canopyhydrology_inparm cnphenology
clm_soilhydrology_inparm dynamic_subgrid cnvegcarbonstate
finidat_consistency_checks dynpft_consistency_checks
clm_initinterp_inparm century_soilbgcdecompcascade
Expand Down
13 changes: 13 additions & 0 deletions bld/namelist_files/namelist_defaults_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,19 @@ use_crop=".true.">lnd/clm2/surfdata_map/ctsm5.1.dev052/landuse.timeseries_mpasa1
<soilm_tintalgo>linear</soilm_tintalgo>
<soilm_offset >0</soilm_offset>

<!-- Irrigation streams namelist defaults -->
<!-- This is if you want to prescribe the irrigation from input datasets rather than model it -->
<use_irrigation_streams>.false.</use_irrigation_streams>
<stream_year_first_irrig >1850</stream_year_first_irrig>
<stream_year_last_irrig >1850</stream_year_last_irrig>
<model_year_align_irrig >1850</model_year_align_irrig>

<stream_fldfilename_irrig hgrid="0.9x1.25">lnd/clm2/prescribed_data/LFMIP-pdLC-SST.H2OSOI.0.9x1.25.20levsoi.natveg.1980-2014.MONS_climo.c190716.nc</stream_fldfilename_irrig>
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • stream_fldfilename_irrig default should be removed, as it points to a soil moisture file. Alternatively, you could provide a file to use. (I'll need that file anyway for testing, but we may not want to provide that as a default dataset.)


<irrig_mapalgo>nn</irrig_mapalgo>
Copy link
Collaborator

@samsrabin samsrabin Aug 16, 2023

Choose a reason for hiding this comment

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

  • irrig_mapalgo appears in XML files but not Fortran or CLMBuildNamelist.pm. Add code to handle it.

<irrig_tintalgo>nearest</irrig_tintalgo>
Copy link
Collaborator

@samsrabin samsrabin Aug 16, 2023

Choose a reason for hiding this comment

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

  • irrig_tintalgo and irrig_mapalgo must always be nearest/nn for categorical variables like irrig_method_patch, for which interpolation isn't meaningful. Options to fix:
  • Remove these as something that can be changed
  • Silently use nearest/nn to affect categorical variables
  • Fail if something other than nearest/nn is used but categorical variables are read from the streams file

Copy link
Collaborator

Choose a reason for hiding this comment

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

From conversation with @swensosc: For now, I will leave irrig_tintalgo and irrig_mapalgo as namelist parameters, but only allow nearest/nn. This will provide the framework for eventually adding other options if users request them.

<irrig_offset >0</irrig_offset>

<!-- LAI streams namelist defaults -->
<use_lai_streams >.false.</use_lai_streams>
<stream_year_first_lai >2001</stream_year_first_lai>
Expand Down
49 changes: 49 additions & 0 deletions bld/namelist_files/namelist_definition_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,55 @@ If true, will ignore the prescribed soilm data for that point and let the model
prescribed data.
</entry>

<!-- ============================================================ -->
<!-- irrigation stream -->
<!-- ============================================================ -->

<!-- Prescribed irrigation -->
<entry id="use_irrigation_streams" type="logical" category="physics"
group="clm_inparm" valid_values="" value=".false.">
Toggle to turn on use of input prescribed irrigation streams rather than have CLM prognose it (EXPERIMENTAL)
</entry>

<entry id="stream_year_first_irrig" type="integer" category="datasets"
group="irrigation_streams" valid_values="" >
First year to loop over for prescribed soil moisture streams data
</entry>

<entry id="stream_year_last_irrig" type="integer" category="datasets"
group="irrigation_streams" valid_values="" >
Last year to loop over for prescribed irrigation streams data
</entry>

<entry id="model_year_align_irrig" type="integer" category="datasets"
group="irrigation_streams" valid_values="" >
Simulation year that aligns with stream_year_first_irrig value
</entry>

<entry id="stream_fldfilename_irrig" type="char*256(30)" category="datasets"
input_pathname="abs" group="irrigation_streams" valid_values="" >
Filename of input stream data for prescribed irrigation streams data
</entry>

<entry id="irrig_tintalgo" type="char*256" category="datasets"
group="irrigation_streams" valid_values="linear,nearest,lower,upper" >
Time interpolation method to use for prescribed irrigation streams data
</entry>

<entry id="irrig_offset" type="integer" category="datasets"
group="irrigation_streams" >
Offset in time coordinate for irrigation streams (sec)
</entry>

<entry id="irrig_mapalgo" type="char*256" category="datasets"
group="irrig_streams" valid_values="bilinear,nn,spval,copy" >
Mapping method from irrigation input file to the model resolution
bilinear = bilinear interpolation
nn = nearest neighbor
spval = set to special value
copy = copy using the same indices
</entry>

<!-- ======================================================================================== -->
<!-- lai_streams streams Namelist (when phys = CLM4_5) -->
<!-- ======================================================================================== -->
Expand Down
13 changes: 8 additions & 5 deletions src/biogeophys/HydrologyNoDrainageMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ subroutine CalcAndWithdrawIrrigationFluxes(bounds, &
num_soilp, filter_soilp, &
soilhydrology_inst, soilstate_inst, &
irrigation_inst, &
water_inst)
water_inst, soil_water_retention_curve)
!
! !DESCRIPTION:
! Calculates irrigation withdrawal fluxes and withdraws from groundwater
!
! !USES:
use SoilHydrologyMod , only : WithdrawGroundwaterIrrigation
use SoilHydrologyMod , only : WithdrawGroundwaterIrrigation
use SoilWaterRetentionCurveMod , only : soil_water_retention_curve_type
!
! !ARGUMENTS:
type(bounds_type) , intent(in) :: bounds
Expand All @@ -70,6 +71,7 @@ subroutine CalcAndWithdrawIrrigationFluxes(bounds, &
type(soilstate_type) , intent(in) :: soilstate_inst
type(irrigation_type) , intent(inout) :: irrigation_inst
type(water_type) , intent(inout) :: water_inst
class(soil_water_retention_curve_type), intent(in) :: soil_water_retention_curve
!
! !LOCAL VARIABLES:
integer :: i ! tracer index
Expand All @@ -81,7 +83,7 @@ subroutine CalcAndWithdrawIrrigationFluxes(bounds, &
call irrigation_inst%CalcIrrigationFluxes(bounds, num_soilc, &
filter_soilc, num_soilp, filter_soilp, &
soilhydrology_inst, soilstate_inst, &
water_inst)
water_inst, soil_water_retention_curve)

! Remove groundwater irrigation
if (irrigation_inst%UseGroundwaterIrrigation()) then
Expand Down Expand Up @@ -141,7 +143,7 @@ subroutine HydrologyNoDrainage(bounds, &
atm2lnd_inst, soilstate_inst, energyflux_inst, temperature_inst, &
water_inst, &
soilhydrology_inst, saturated_excess_runoff_inst, infiltration_excess_runoff_inst, &
aerosol_inst, canopystate_inst, scf_method, soil_water_retention_curve, topo_inst)
aerosol_inst, canopystate_inst, scf_method, soil_water_retention_curve, topo_inst, irrigation_inst)
!
! !DESCRIPTION:
! This is the main subroutine to execute the calculation of soil/snow
Expand Down Expand Up @@ -182,6 +184,7 @@ subroutine HydrologyNoDrainage(bounds, &
integer , intent(inout) :: filter_nosnowc(:) ! column filter for non-snow points
type(hlm_fates_interface_type), intent(inout) :: clm_fates
type(atm2lnd_type) , intent(in) :: atm2lnd_inst
type(irrigation_type) , intent(in) :: irrigation_inst
type(soilstate_type) , intent(inout) :: soilstate_inst
type(energyflux_type) , intent(in) :: energyflux_inst
type(temperature_type) , intent(inout) :: temperature_inst
Expand Down Expand Up @@ -323,7 +326,7 @@ subroutine HydrologyNoDrainage(bounds, &
call UpdateH2osfc(bounds, num_hydrologyc, filter_hydrologyc, &
infiltration_excess_runoff_inst, &
energyflux_inst, soilhydrology_inst, &
b_waterflux_inst, b_waterstate_inst, b_waterdiagnostic_inst)
b_waterflux_inst, b_waterstate_inst, b_waterdiagnostic_inst, irrigation_inst)

call Infiltration(bounds, num_hydrologyc, filter_hydrologyc, &
b_waterflux_inst)
Expand Down
Loading