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

Divide by zero bug in AbstractConvectionTerm #914

Open
opensourcefan314 opened this issue Mar 30, 2023 · 0 comments
Open

Divide by zero bug in AbstractConvectionTerm #914

opensourcefan314 opened this issue Mar 30, 2023 · 0 comments

Comments

@opensourcefan314
Copy link

AbstractConvectionTerm tries hard to make sure the peclet number is never exactly 0 by replacing hard 0s with +/- 1e20.

However this line can fail to eliminate all zeros:
https://github.com/usnistgov/fipy/blob/master/fipy/terms/abstractConvectionTerm.py#L139
diffCoeff = diffCoeff - (diffCoeff == 0) * geomCoeff / pecletLarge
The problem occurs when an entry of geomCoeff is 0, or is small enough that geomCoeff / pecletLarge underflows.
I'm not sure what the best principled fix would be, but a hacky fix is to follow this line with an additional line
diffCoeff = diffCoeff - (diffCoeff == 0) / pecletLarge

Here is a gist that triggers the divide by 0:
https://gist.github.com/opensourcefan314/c7fa68bf44e069406f617439a9417518

Executing the gist prints this warning:
/fipy/variables/variable.py:1143: RuntimeWarning: invalid value encountered in true_divide
return self._BinaryOperatorVariable(lambda a, b: a / b, other)

In this case, the divide by zero seems harmless, in the sense that it doesn't propagate nans or infs to the solver output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant