dssat-csm-os
dssat-csm-os copied to clipboard
Fix divide by zero for SWI
There is an equality check for SW(1) and SAT(1) on line 188, but there is no equality check on line 202. We have run into instances where SAT(1) == SW(1) and the model crashes. This patches it (and verifies the denominator is positive).
Hi @frostbytten!
Could you please send an experimental files as example to reproduce this error?
I need to check if this will patch will not break into other conditions.
Thank you.
Hi @frostbytten
Looking at this without running an experiment I got to this conclusion:
This code is redundant because if SW is less than DUL then SW must be less than SAT. Because SAT is always greater than DUL. You mentioned previously that it runs into issues where SAT == SW. However, this condition will not pass the IF statement above and SWI will be 1.0. Let is assume the IF statement passes, then you triggered a division by zero, because (SAT(1)-SW(1)) will be equal and set to zero for the division.
I assume your issue is somewhere else.
I hope you can have a experiment that we could run too and then we find a fix together!
Thank you.
Chris, I am closing this PR because I made two other PR's related to this issue. It is fixed now. Please check PR #436 Thanks for pointing out this issue. It was issues related to Soil Organic Matter and old way of conditional statements with floating point. Thank you.