Skip to content

Commit

Permalink
BalanceCheckMod: re-intr. skip_steps for soil energy balance check
Browse files Browse the repository at this point in the history
1) Most important: Re-introduced the check for skipping the soil
energy balance check.

2) Style changes that had diverged from CLM5
  • Loading branch information
jjokella committed Feb 12, 2025
1 parent c9f3348 commit bf204c0
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/clm5/biogeophys/BalanceCheckMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ subroutine BalanceCheck( bounds, &
! error = abs(precipitation - change of water storage - evaporation - runoff)
!
! !USES:
use clm_varcon , only : spval
use clm_time_manager , only : get_step_size, get_nstep
use clm_time_manager , only : get_nstep_since_startup_or_lastDA_restart_or_pause
use CanopyStateType , only : canopystate_type
use SurfaceAlbedoType , only : surfalb_type
use clm_varcon , only : spval
use clm_time_manager , only : get_step_size, get_nstep
use clm_time_manager , only : get_nstep_since_startup_or_lastDA_restart_or_pause
use CanopyStateType , only : canopystate_type
use SurfaceAlbedoType , only : surfalb_type
use subgridAveMod
!
! !ARGUMENTS:
Expand Down Expand Up @@ -227,7 +227,6 @@ subroutine BalanceCheck( bounds, &
errh2osno => waterstate_inst%errh2osno_col , & ! Output: [real(r8) (:) ] error in h2osno (kg m-2)
endwb => waterstate_inst%endwb_col , & ! Output: [real(r8) (:) ] water mass end of the time step
total_plant_stored_h2o_col => waterstate_inst%total_plant_stored_h2o_col, & ! Input: [real(r8) (:) ] water mass in plant tissues (kg m-2)

qflx_rootsoi_col => waterflux_inst%qflx_rootsoi_col , & ! Input [real(r8) (:) ] water loss in soil layers to root uptake (mm H2O/s)
! (ie transpiration demand, often = transpiration)
qflx_rain_grnd_col => waterflux_inst%qflx_rain_grnd_col , & ! Input: [real(r8) (:) ] rain on ground after interception (mm H2O/s) [+]
Expand Down Expand Up @@ -261,6 +260,7 @@ subroutine BalanceCheck( bounds, &
qflx_ice_dynbal => waterflux_inst%qflx_ice_dynbal_grc , & ! Input: [real(r8) (:) ] ice runoff due to dynamic land cover change (mm H2O /s)
snow_sources => waterflux_inst%snow_sources_col , & ! Output: [real(r8) (:) ] snow sources (mm H2O /s)
snow_sinks => waterflux_inst%snow_sinks_col , & ! Output: [real(r8) (:) ] snow sinks (mm H2O /s)

qflx_irrig => irrigation_inst%qflx_irrig_col , & ! Input: [real(r8) (:) ] irrigation flux (mm H2O /s)

qflx_glcice_dyn_water_flux => glacier_smb_inst%qflx_glcice_dyn_water_flux_col, & ! Input: [real(r8) (:)] water flux needed for balance check due to glc_dyn_runoff_routing (mm H2O/s) (positive means addition of water to the system)
Expand Down Expand Up @@ -346,6 +346,7 @@ subroutine BalanceCheck( bounds, &
- qflx_ice_runoff_xs(c) &
- qflx_snwcp_discarded_liq(c) &
- qflx_snwcp_discarded_ice(c)) * dtime

else

errh2o(c) = 0.0_r8
Expand All @@ -355,12 +356,11 @@ subroutine BalanceCheck( bounds, &
end do

found = .false.

do c = bounds%begc, bounds%endc
if (abs(errh2o(c)) > 1.e-9_r8) then
found = .true.
indexc = c
end if
if (abs(errh2o(c)) > 1.e-9_r8) then
found = .true.
indexc = c
end if
end do

if ( found ) then
Expand Down Expand Up @@ -406,12 +406,12 @@ subroutine BalanceCheck( bounds, &
! TODO: Balance errors must be fixed for fully coupled model (ICON-eCLM-ParFlow)
write(iulog,*)'Ignoring water balance error...'
#else
write(iulog,*)'clm model is stopping - error is greater than 1e-5 (mm)'
write(iulog,*)'clm model is stopping'
call endrun(decomp_index=indexc, clmlevel=namec, msg=errmsg(sourcefile, __LINE__))
#endif
else if (abs(errh2o(indexc)) > 1.e-5_r8 .and. (DAnstep > skip_steps) ) then


write(iulog,*)'clm model is stopping - error is greater than 1e-5 (mm)'
write(iulog,*)'nstep = ',nstep
write(iulog,*)'errh2o = ',errh2o(indexc)
write(iulog,*)'forc_rain = ',forc_rain_col(indexc)*dtime
Expand Down Expand Up @@ -441,7 +441,7 @@ subroutine BalanceCheck( bounds, &
! TODO: Balance errors must be fixed for fully coupled model (ICON-eCLM-ParFlow)
write(iulog,*)'Ignoring water balance error...'
#else
write(iulog,*)'clm model is stopping - error is greater than 1e-5 (mm)'
write(iulog,*)'clm model is stopping'
call endrun(decomp_index=indexc, clmlevel=namec, msg=errmsg(sourcefile, __LINE__))
#endif
end if
Expand Down Expand Up @@ -690,6 +690,7 @@ subroutine BalanceCheck( bounds, &
end if

! Soil energy balance check

found = .false.
do c = bounds%begc,bounds%endc
if (col%active(c)) then
Expand All @@ -707,8 +708,10 @@ subroutine BalanceCheck( bounds, &
! TODO: Balance errors must be fixed for fully coupled model (ICON-eCLM-ParFlow)
write(iulog,*)'Ignoring soil balance error...'
#else
write(iulog,*)'clm model is stopping - error is greater than 1e-5 (mm)'
call endrun(decomp_index=indexc, clmlevel=namec, msg=errmsg(sourcefile, __LINE__))
if (abs(errsoi_col(indexc)) > 1.e-4_r8 .and. (DAnstep > skip_steps) ) then
write(iulog,*)'clm model is stopping'
call endrun(decomp_index=indexc, clmlevel=namec, msg=errmsg(sourcefile, __LINE__))
end if
#endif
end if

Expand Down

0 comments on commit bf204c0

Please sign in to comment.