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

Fixes the annual C budget in ELM #6405

Merged
merged 6 commits into from
May 23, 2024
Merged
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
1 change: 1 addition & 0 deletions cime_config/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"ERS.f19_g16.I1850GSWCNPECACNTBC.elm-eca_f19_g16_I1850GSWCNPECACNTBC",
"ERS.f19_g16.I20TRGSWCNPECACNTBC.elm-eca_f19_g16_I20TRGSWCNPECACNTBC",
"ERS.f19_g16.I20TRGSWCNPRDCTCBC.elm-ctc_f19_g16_I20TRGSWCNPRDCTCBC",
"ERS.r05_r05.ICNPRDCTCBC.elm-cbudget",
)
},

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./xmlchange RUN_STARTDATE=0001-12-28
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
finidat = '$DIN_LOC_ROOT/lnd/clm2/initdata_map/clmi.r05_r05.ICNPRDCTCBC.elm.r.0001-12-28-00000.nc'

24 changes: 6 additions & 18 deletions components/elm/src/biogeochem/CNPBudgetMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,12 @@ subroutine Accum(s_size, budg_fluxN, budg_fluxL, budg_stateL, budg_stateG)
if (sec_prev == 0 .and. day_prev == 1 .and. month_prev == 1) update_state_beg = .true.
if (sec_curr == 0 .and. day_curr == 1 .and. month_curr == 1) update_state_end = .true.
case (p_inf)
if (get_nstep() == 1) update_state_beg = .true.
update_state_end = .true.
end select

! If this is the first time step, update the states for all budget types
if (get_nstep() == 1) update_state_beg = .true.

if (update_state_beg) then
do is = 1, s_size/2 - 1
budg_stateL(is,ip) = budg_stateL(is, p_inst)
Expand Down Expand Up @@ -1134,38 +1136,25 @@ subroutine CBudget_SetBeginningMonthlyStates(bounds, col_cs, grc_cs)
!
! !LOCAL VARIABLES:
integer :: year_prev, month_prev, day_prev, sec_prev
integer :: year_curr, month_curr, day_curr, sec_curr
!-----------------------------------------------------------------------

associate( &
associate( &
begcb => col_cs%begcb , & ! Input : [real(r8) (:) ] carbon mass begining of the time step
endcb => col_cs%endcb , & ! Input : [real(r8) (:) ] carbon mass begining of the time step
tcs_month_beg_grc => grc_cs%tcs_month_beg & ! Output: [real(r8) (:) ] grid-level carbon mass at the begining of a month
)

! Get current and previous dates to determine if a new month started
call get_prev_date(year_curr, month_curr, day_curr, sec_curr);
call get_prev_date(year_prev, month_prev, day_prev, sec_prev)

! If at the beginning of a simulation, save grid-level TCS based on
! 'begcb' from the current time step
if ( day_curr == 1 .and. sec_curr == 0 .and. get_nstep() <= 1 ) then
if ( day_prev == 1 .and. sec_prev == 0 .and. get_nstep() <= 1 ) then
call c2g( bounds, &
begcb(bounds%begc:bounds%endc), &
tcs_month_beg_grc(bounds%begg:bounds%endg), &
c2l_scale_type= 'unity', l2g_scale_type='unity' )
endif

! If multiple steps into a simulation and the last time step was the
! end of a month, save grid-level TCS based on 'endcb' from the last
! time step
if (get_nstep() > 1 .and. day_prev == 1 .and. sec_prev == 0) then
call c2g( bounds, &
endcb(bounds%begc:bounds%endc), &
tcs_month_beg_grc(bounds%begg:bounds%endg), &
c2l_scale_type= 'unity', l2g_scale_type='unity' )
endif

end associate

end subroutine CBudget_SetBeginningMonthlyStates
Expand Down Expand Up @@ -1196,8 +1185,7 @@ subroutine CBudget_SetEndingMonthlyStates(bounds, col_cs, grc_cs)
integer :: year, month, day, sec
!-----------------------------------------------------------------------

associate( &
begcb => col_cs%begcb , & ! Input : [real(r8) (:) ] carbon mass begining of the time step
associate( &
endcb => col_cs%endcb , & ! Input : [real(r8) (:) ] carbon mass begining of the time step
tcs_month_end_grc => grc_cs%tcs_month_end & ! Output: [real(r8) (:) ] grid-level carbon mass at the ending of a month
)
Expand Down
24 changes: 6 additions & 18 deletions components/elm/src/biogeophys/WaterBudgetMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ subroutine WaterBudget_Accum()
if (sec_prev == 0 .and. day_prev == 1 .and. month_prev == 1) update_state_beg = .true.
if (sec_curr == 0 .and. day_curr == 1 .and. month_curr == 1) update_state_end = .true.
case (p_inf)
if (get_nstep() == 1) update_state_beg = .true.
update_state_end = .true.
end select
if (get_nstep() == 1) update_state_beg = .true.

if (update_state_beg) then
nf = s_w_beg ; budg_stateL(nf,ip) = budg_stateL(nf, p_inst)
Expand Down Expand Up @@ -695,36 +695,23 @@ subroutine WaterBudget_SetBeginningMonthlyStates(bounds )
integer :: year_curr, month_curr, day_curr, sec_curr
!-----------------------------------------------------------------------

associate( &
associate( &
begwb => col_ws%begwb , & ! Output: [real(r8) (:) ] water mass begining of the time step
endwb => col_ws%endwb , & ! Output: [real(r8) (:) ] water mass begining of the time step
tws_month_beg_grc => grc_ws%tws_month_beg & ! Output: [real(r8) (:) ] grid-level water mass at the begining of a month
)

! Get current and previous dates to determine if a new month started
call get_prev_date(year_curr, month_curr, day_curr, sec_curr);
call get_prev_date(year_prev, month_prev, day_prev, sec_prev)


! If at the beginning of a simulation, save grid-level TWS based on
! 'begwb' from the current time step
if ( day_curr == 1 .and. sec_curr == 0 .and. get_nstep() <= 1 ) then
if ( day_prev == 1 .and. sec_prev == 0 .and. get_nstep() <= 1 ) then
call c2g( bounds, &
begwb(bounds%begc:bounds%endc), &
tws_month_beg_grc(bounds%begg:bounds%endg), &
c2l_scale_type= 'urbanf', l2g_scale_type='unity' )
endif

! If multiple steps into a simulation and the last time step was the
! end of a month, save grid-level TWS based on 'endwb' from the last
! time step
if ( get_nstep() > 1 .and. day_prev == 1 .and. sec_prev == 0) then
call c2g( bounds, &
endwb(bounds%begc:bounds%endc), &
tws_month_beg_grc(bounds%begg:bounds%endg), &
c2l_scale_type= 'urbanf', l2g_scale_type='unity' )
endif

end associate

end subroutine WaterBudget_SetBeginningMonthlyStates
Expand All @@ -747,13 +734,14 @@ subroutine WaterBudget_SetEndingMonthlyStates(bounds )
integer :: year, mon, day, sec
!-----------------------------------------------------------------------

associate( &
associate( &
endwb => col_ws%endwb , & ! Output: [real(r8) (:) ] water mass at end of the time step
tws_month_end_grc => grc_ws%tws_month_end & ! Output: [real(r8) (:) ] grid-level water mass at the end of a month
)

! If this is the end of a month, save grid-level total water storage
call get_curr_date(year, mon, day, sec);
call get_curr_date(year, mon, day, sec);

if (get_nstep() >= 1 .and. (day == 1 .and. sec == 0)) then
call c2g( bounds, &
endwb(bounds%begc:bounds%endc), &
Expand Down