dssat-csm-os icon indicating copy to clipboard operation
dssat-csm-os copied to clipboard

Fix divide by zero for SWI

Open frostbytten opened this issue 1 year ago • 2 comments

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).

frostbytten avatar Nov 30 '23 18:11 frostbytten

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.

fabiooliveira72 avatar Dec 04 '23 00:12 fabiooliveira72

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.

fabiooliveira72 avatar Dec 12 '23 16:12 fabiooliveira72

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.

fabiooliveira72 avatar Sep 06 '24 20:09 fabiooliveira72