-
Notifications
You must be signed in to change notification settings - Fork 374
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 C balance and FPE errors #6235
Fix C balance and FPE errors #6235
Conversation
@glemieux Here is a PR to fix the balance checking issues. I did get DIFF for Let me know if how I implemented the new balance checking makes sense to you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of the fates gridcell balance checks looks good to me. Thanks!
After doing a test merge I obtained FILLDIFF for the |
Quick update:
|
What is the diff with? A baseline from the previous code or is it a diff within a test like an ERS test? |
Not baseline diff (though that is also there but makes sense to me). It fails the COMP_base_rest portion of ERP test (same thing with the ERS version I made for debugging). |
Try a REP test. |
REP passes just fine. I'm going to double check that each variable for carbon balance is read/written to the restart file, and maybe a longer simulation will reveal diff's accruing in other fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have minor stylistic code change requests for this PR.
@@ -624,7 +621,7 @@ subroutine ColPBalanceCheck(bounds, & | |||
! set time steps | |||
dt = dtime_mod | |||
kyr = year_curr; kmo = mon_curr; kda = day_curr; mcsec = secs_curr; | |||
|
|||
!nstep = nstep_mod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete this line.
grc_coutputs => grc_cf%coutputs , & ! Output: [real(r8) (:) ] (gC/m2/s) column-level C outputs | ||
beg_totpftc => grc_cs%beg_totpftc , & ! Input: [real(r8) (:)] (gC/m2) patch-level carbon aggregated to column level, incl veg and cpool | ||
beg_cwdc => grc_cs%beg_cwdc , & ! Input: [real(r8) (:)] (gC/m2) total column coarse woody debris carbon | ||
beg_totsomc => grc_cs%beg_totsomc , & ! Input: [real(r8) (:)] (gC/m2) total column soil organic matter carbon | ||
beg_totlitc => grc_cs%beg_totlitc , & ! Input: [real(r8) (:)] (gC/m2) total column litter carbon | ||
beg_totprodc => grc_cs%beg_totprodc , & ! Input: [real(r8) (:)] (gC/m2) total column wood product carbon | ||
beg_ctrunc => grc_cs%beg_ctrunc , & ! Input: [real(r8) (:)] (gC/m2) total column truncation carbon sink | ||
beg_cropseedc_deficit => grc_cs%beg_cropseedc_deficit & ! Input: [real(r8) (:)] (gC/m2) column carbon pool for seeding new growth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove an extra whitespace after => grc_cs%
to be => grc_cs%
|
||
if(use_fates) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a whitespace if (use_fates)
dt = real( get_step_size(), r8 ) | ||
nstep = get_nstep() | ||
|
||
do g = bounds%begg, bounds%endg | ||
grc_cinputs(g) = grc_gpp(g) + grc_dwt_seedc_to_leaf(g) + grc_dwt_seedc_to_deadstem(g) | ||
|
||
if(.not. use_fates) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly add a whitespace.
! calculate the P:PET for each month | ||
p2ETo(p,kmo) = xp(p,kmo)/ETo(p,kmo) | ||
if( abs(ETo(p,kmo)) > 0._r8) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- please add whitespace
- Shouldn't there also be code corresponding to an
else
condition?
this%er(i) = value_column !! Grid Balance Error | ||
this%som_c_leached(i) = value_column !! Grid Balance Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please remove the !! Grid Balance Error
status: Adjusting the history output interval did allow the test to pass the restart comparison but that's not a real solution. Scheduled meeting with FATES devs to go over the logic for balance checking with FATES enabled. |
@peterdschwartz what is the status of this PR? |
@rljacob I met with @glemieux a couple of weeks ago. He mentioned a possible time-step dependent part of FATES that could be the cause, but I think he's been busy with the FATES api update and our follow up meeting with @thorntonpe was cancelled due to lab holiday. Today, I'll try increasing the history output to be every timestep and see if that provides any useful information. |
Update: Increasing output freq finally showed a new diff in a field. Looking into it further, it appears that the vertical transport tendency terms for carbon are not added to the corresponding leaching term due to some issue 5 years ago (according to git blame atleast), but it is for nitrogen and phosphorus. Hopefully the straightforward solution works here.
|
@peterdschwartz can you point me to the line of code with the git blame that you noted earlier, please? |
@glemieux This Code block is what I was referring to. The transport tendency is not added to carbon leached pool even though the corresponding terms are added for Nitrogen and Phosphorus. More experimenting showed that bypassing the SoilLittVertTransp calculation, the restart failure goes away. For FATES, the |
Waiting to see about FATES side of this PR. |
Since there's a previous fates related issue linked above with the same errors, I'm going to just clean the branch up for the other issues and follow the review comments. The other issue can be used to the issue. |
Sorry for the delay in trying to address the fates-side of this. Just to clarify, you're saying your going to move forwards towards integration @peterdschwartz? If so, that sounds good to me. |
Corrected GridCBalanceCheck to use absolute value for error. Adjusted col_cf_setvalues to fix undetected C imbalances -- Still error with FATES
…n input to col_cf%litfall Added more output when an carbon imbalance is detected. Column Carbon balance is now checked with FATES active.
Adjusted whitespaces and comments.
cac574e
to
e6097d2
Compare
@glemieux Yes, and now I know how to how to reliably reproduce the issue, we can use #6125 to track progress. I will share a branch with the changes to do it. @bishtgautam I have rebased the branch and addressed your comments. There's potentially a couple of different ways to handle the e3sm_developer came back [BfB] with the exception of one FATES test that will FAIL restart comparison for the time being. |
if ( abs(ETo(p,kmo)) > 0._r8) then | ||
p2ETo(p,kmo) = xp(p,kmo)/ETo(p,kmo) | ||
else ! P:PET is undefined. | ||
! Setting to a fill value ( 'spval' ) would | ||
! require nested if statements due to | ||
! the weighting of previous years (i.e., p2ETo and prev_p2ETo_bar ) | ||
! So, set to zero for simplicity. | ||
p2ETo(p,kmo) = 0._r8 | ||
end if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterdschwartz This looks good to me. Thanks for the comment explaining the logic.
This is ready to merge. |
) Carbon balance was never checked correctly and let through negative values. Initialization of Ecosystem variables needed to be re-adjusted, and balance checking for FATES needed to be changed, which causes round-off differences in CMASS_BALANCE_ERROR for fate_cold_allvars test. Also included divide-by-zero check in PhenologyMod.F90 to fix fpe in debug mode. [non-BFB] for one FATES test. Fixes #6120 Fixes #6203 Fixes #6177
Carbon balance was never checked correctly and let through negative values.
Initialization of Ecosystem variables needed to be re-adjusted, and balance checking for FATES needed to be changed, which causes round-off differences in
CMASS_BALANCE_ERROR
forfate_cold_allvars
test.Also included divide-by-zero check in PhenologyMod.F90 to fix fpe in debug mode.
[non-BFB] for one FATES test.
Fixes #6120
Fixes #6203
Fixes #6177