-
Notifications
You must be signed in to change notification settings - Fork 114
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
Grass cohorts causing Floating-point exception at log() operations, several places #340
Comments
It is unclear to me whether the FPE is caused by log or the exponential. Maybe it's worth adding some debugging if statements to understand what is causing the crash. For example, right after this line if (mdbh < tiny_num) then
write(unit=*,fmt='(a)') ' Zero DBH found!'
write(unit=*,fmt='(a,1x,i6)') 'PFT = ', ipft
write(unit=*,fmt='(a,1x,es12.5)') 'Actual DBH = ', dbh
write(unit=*,fmt='(a,1x,es12.5)') 'Critical DBH = ', dbh_crit(ipft)
write(unit=*,fmt='(a,1x,es12.5)') 'b1Ht = ', b1Ht(ipft)
write(unit=*,fmt='(a,1x,es12.5)') 'b2Ht = ', b2Ht(ipft)
call fatal_error('Invalid DBH','dbh2h','allometry.f90')
end if (You will need to add If the run continues to crash and does not print the error message, then it's likely that the exponential is the culprit, not the log. In this case, you modify the lnexp = b1Ht(ipft) + b2Ht(ipft) * log(mdbh)
if (lnexp >= lnexp_min .and. lnexp <= lnexp_max) then
dbh2h = exp(lnexp)
else
write(unit=*,fmt='(a)') ' FPE when computing height!'
write(unit=*,fmt='(a,1x,i6)') 'PFT = ', ipft
write(unit=*,fmt='(a,1x,es12.5)') 'Actual DBH = ', dbh
write(unit=*,fmt='(a,1x,es12.5)') 'Critical DBH = ', dbh_crit(ipft)
write(unit=*,fmt='(a,1x,es12.5)') 'DBH used = ', mdbh
write(unit=*,fmt='(a,1x,es12.5)') 'b1Ht = ', b1Ht(ipft)
write(unit=*,fmt='(a,1x,es12.5)') 'b2Ht = ', b2Ht(ipft)
call fatal_error('Dangerous exponential','dbh2h','allometry.f90')
end if In general, I would advise against adding |
👍 print statements. Tentatively, I think it's the log. When I put in the hack I described, things "worked", as in that line didn't cause an error, and the run ran longer. Looking at the monthly file pre-allometry-crash: DBH by cohort: 1.70492851734161, 1.70492851734161 0.953645884990692, 0.350115686655045 |
Sorry it took me so long to circle back! Yep, it's the log().
|
I put some print statements into the bl2dbh() function, that I think is generating the dbh values. Seems like I get the FPE when leaf biomass drops to zero:
|
Seems like there just needs to be a check for Not sure if that would mess up a carbon balance term somewhere. Theoretically though, it makes sense that grasses might not have the biomass to grow taller every day. |
Second theory: Could the grass phenology cases be being referred to incorrectly? |
If I run with the phenology scheme set to -1 I do not get the errors above. I was running phenology 1 before. |
Are you using the |
Yeah IGRASS = 1 |
I'll try a phenology = 1 and a IGRASS = 0 run |
Yes! If I run with |
UPDATE: I have encountered several places where a a log() statement of a pft-based number casues a numerical error. Below in the allometry is the first time I encountered it. I have been substituting
log(value)
forlog(max(value, 0.001))
when I encounter them.I am assuming what is happening is that as new grass cohorts are being made, they are being made smaller and smaller as the system reaches its asymptote, and eventually something becomes negative.
How many decimals after 0 make sense? I want something that is bigger than ED2's numeric errors, but small enough that it won't throw stuff off. Is there a standard way people have set these bounds?
Is there a check for cohort size that I'm missing that would prevent these numerical issues entirely? I assume that if some of of these variables are becoming negative, it means that somewhere earlier in the code the cohort shouldn't have been made in the first place. Certainly don't want my
max()
statements to let the model keep adding cohorts indefinitely.I have encountered this issue:
Slightly different version
First version of this issue
Runs will successfully grow grasses for a handful of months, but will eventually fail will a floating point exception error (See below) at this line:
dbh2h = exp (b1Ht(ipft) + b2Ht(ipft) * log(mdbh) )
ED2 will run the above line with problems several times before failing on it.
The text was updated successfully, but these errors were encountered: