From acf09849ccbf6e1f3f4eade1ad959a7fb055ee0b Mon Sep 17 00:00:00 2001 From: Bill Sacks Date: Thu, 3 Sep 2020 12:05:49 -0600 Subject: [PATCH] Reset lake baselines in branch or continue run, too I went back and forth about whether we should do this, but I actually feel that it's best if we do reset the lake baselines in a branch or continue run, if using an older restart file. If we didn't do this, we'd want to add some logic for writing out the issue-fixed metadata for any further restart files written from these runs, to note that this issue isn't actually fixed yet on these restart files. --- src/dyn_subgrid/dynConsBiogeophysMod.F90 | 19 +------ src/main/clm_initializeMod.F90 | 71 +++++++++++++----------- 2 files changed, 41 insertions(+), 49 deletions(-) diff --git a/src/dyn_subgrid/dynConsBiogeophysMod.F90 b/src/dyn_subgrid/dynConsBiogeophysMod.F90 index e3b25b1322..089715233d 100644 --- a/src/dyn_subgrid/dynConsBiogeophysMod.F90 +++ b/src/dyn_subgrid/dynConsBiogeophysMod.F90 @@ -12,8 +12,6 @@ module dynConsBiogeophysMod use shr_kind_mod , only : r8 => shr_kind_r8 use shr_log_mod , only : errMsg => shr_log_errMsg use decompMod , only : bounds_type - use spmdMod , only : masterproc - use clm_varctl , only : iulog use UrbanParamsType , only : urbanparams_type use EnergyFluxType , only : energyflux_type use SoilHydrologyType , only : soilhydrology_type @@ -69,7 +67,7 @@ module dynConsBiogeophysMod subroutine dyn_hwcontent_set_baselines(bounds, num_icemecc, filter_icemecc, & num_lakec, filter_lakec, & urbanparams_inst, soilstate_inst, lakestate_inst, water_inst, temperature_inst, & - reset_all_baselines, reset_lake_baselines, print_resets) + reset_all_baselines, reset_lake_baselines) ! ! !DESCRIPTION: ! Set start-of-run baseline values for heat and water content in some columns. @@ -125,9 +123,6 @@ subroutine dyn_hwcontent_set_baselines(bounds, num_icemecc, filter_icemecc, & ! for lakes on older initial conditions files. logical, intent(in) :: reset_lake_baselines - ! Whether to print information about the reset flags - logical, intent(in) :: print_resets - ! ! !LOCAL VARIABLES: integer :: i @@ -136,18 +131,6 @@ subroutine dyn_hwcontent_set_baselines(bounds, num_icemecc, filter_icemecc, & character(len=*), parameter :: subname = 'dyn_hwcontent_set_baselines' !----------------------------------------------------------------------- - if (masterproc .and. print_resets) then - if (reset_all_baselines) then - write(iulog,*) ' ' - write(iulog,*) 'Resetting dynbal baselines for all columns' - write(iulog,*) ' ' - else if (reset_lake_baselines) then - write(iulog,*) ' ' - write(iulog,*) 'Resetting dynbal baselines for lake columns' - write(iulog,*) ' ' - end if - end if - ! Note that we include inactive points in the following. This could be important if ! an inactive point later becomes active, so that we have an appropriate baseline ! value for that point. diff --git a/src/main/clm_initializeMod.F90 b/src/main/clm_initializeMod.F90 index b8f5d0aa95..771b88e5da 100644 --- a/src/main/clm_initializeMod.F90 +++ b/src/main/clm_initializeMod.F90 @@ -339,6 +339,7 @@ subroutine initialize2( ) logical :: lexist integer :: closelatidx,closelonidx real(r8) :: closelat,closelon + logical :: reset_dynbal_baselines_all_columns logical :: reset_dynbal_baselines_lake_columns integer :: begp, endp integer :: begc, endc @@ -494,10 +495,7 @@ subroutine initialize2( ) urbanparams_inst, soilstate_inst, lakestate_inst, water_inst, temperature_inst, & reset_all_baselines = .true., & ! reset_lake_baselines is irrelevant since reset_all_baselines is true - reset_lake_baselines = .false., & - ! no need to print information about these resets for this initial resetting, - ! which is always done - print_resets = .false.) + reset_lake_baselines = .false.) end do ! ------------------------------------------------------------------------ @@ -582,12 +580,6 @@ subroutine initialize2( ) end if call restFile_read(bounds_proc, fnamer, glc_behavior, & reset_dynbal_baselines_lake_columns = reset_dynbal_baselines_lake_columns) - ! But for a continue or branch run, it seems safest to NOT reset lake dynbal - ! baselines. In nearly all cases, this will be irrelevant, because the restart - ! file will have been a recent one, where reset_dynbal_baselines_lake_columns - ! should be false already. - reset_dynbal_baselines_lake_columns = .false. - end if ! ------------------------------------------------------------------------ @@ -629,31 +621,48 @@ subroutine initialize2( ) ! interpolated restart file, if applicable). ! ------------------------------------------------------------------------ - if (nsrest == nsrStartup) then - - !$OMP PARALLEL DO PRIVATE (nc, bounds_clump) - do nc = 1,nclumps - call get_clump_bounds(nc, bounds_clump) - - call dyn_hwcontent_set_baselines(bounds_clump, & - filter_inactive_and_active(nc)%num_icemecc, & - filter_inactive_and_active(nc)%icemecc, & - filter_inactive_and_active(nc)%num_lakec, & - filter_inactive_and_active(nc)%lakec, & - urbanparams_inst, soilstate_inst, lakestate_inst, & - water_inst, temperature_inst, & - reset_all_baselines = get_reset_dynbal_baselines(), & - reset_lake_baselines = reset_dynbal_baselines_lake_columns, & - print_resets = .true.) - end do - else if (nsrest == nsrBranch) then - if (get_reset_dynbal_baselines()) then + reset_dynbal_baselines_all_columns = get_reset_dynbal_baselines() + if (nsrest == nsrBranch) then + if (reset_dynbal_baselines_all_columns) then call endrun(msg='ERROR clm_initializeMod: '//& 'Cannot set reset_dynbal_baselines in a branch run') end if + else if (nsrest == nsrContinue) then + ! It's okay for the reset_dynbal_baselines flag to remain set in a continue + ! run, but we'll ignore it. (This way, the user doesn't have to change their + ! namelist file for the continue run.) + reset_dynbal_baselines_all_columns = .false. + end if + ! Note that we will still honor reset_dynbal_baselines_lake_columns even in a branch + ! or continue run: even in these runs, we want to reset those baselines if they are + ! wrong on the restart file. + + if (masterproc) then + if (reset_dynbal_baselines_all_columns) then + write(iulog,*) ' ' + write(iulog,*) 'Resetting dynbal baselines for all columns' + write(iulog,*) ' ' + else if (reset_dynbal_baselines_lake_columns) then + write(iulog,*) ' ' + write(iulog,*) 'Resetting dynbal baselines for lake columns' + write(iulog,*) ' ' + end if end if - ! nsrContinue not explicitly handled: it's okay for reset_dynbal_baselines to - ! remain set in a continue run, but it has no effect + + !$OMP PARALLEL DO PRIVATE (nc, bounds_clump) + do nc = 1,nclumps + call get_clump_bounds(nc, bounds_clump) + + call dyn_hwcontent_set_baselines(bounds_clump, & + filter_inactive_and_active(nc)%num_icemecc, & + filter_inactive_and_active(nc)%icemecc, & + filter_inactive_and_active(nc)%num_lakec, & + filter_inactive_and_active(nc)%lakec, & + urbanparams_inst, soilstate_inst, lakestate_inst, & + water_inst, temperature_inst, & + reset_all_baselines = reset_dynbal_baselines_all_columns, & + reset_lake_baselines = reset_dynbal_baselines_lake_columns) + end do ! ------------------------------------------------------------------------ ! Initialize nitrogen deposition