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
BUG: Fix streamplot when velocity component is exactly zero. #1189
BUG: Fix streamplot when velocity component is exactly zero. #1189
Conversation
@tonysyu, I'm sorry, but I really don't like either the original form or the fix. One should not divide by zero. Relying on it to return inf is not good. At the very least, it raises a RuntimeWarning. Depending on the types of the arguments, it could fail completely. The zero-denominator case should be trapped and handled appropriatedly. |
@efiring Yeah, it felt a little flakey to me too, but I was just trying to make a minimal change. Do you think checking for zero and setting the step size to |
@tonysyu, I think your suggestion above is OK. I don't see anything better, offhand. |
I've added the checks to prevent divide-by-zero warnings. I could explicitly check if both values are zero, but like I said, this shouldn't happen. I also made a couple of changes to suppress other warnings. I usually don't like changes that venture beyond the PR's topic, but it seemed minor enough. I can revert these, if necessary. |
@tonysyu Perhaps I'm missing something but I have a potentially silly question. If the velocity field is close to zero, passive tracers (basically streamlines) don't move in the fluid. Is there any reason you're setting the step-size to |
Not a silly question at all: the idea here is that only one of the two ( This routine shouldn't get called if both velocity components are zero, which is why I'm not inclined to add an explicit check for that case. As far as being "close to zero", I'm not sure; were you thinking of some sort of threshold? |
Well, I was more thinking that, in your example of a horizontal flow, you would simply ignore the vertical component. |
That's essentially what happens. The |
BUG: Fix streamplot when velocity component is exactly zero.
By 'stepsize' I meant the Euler step in the Runge Kutta scheme for the odes:
I think we're talking about different things. |
There's definitely a lot of room for misunderstanding since there are 4 step sizes: When you say "we're talking about different things", do you mean that your original suggestion no longer applies? Or am I missing something? |
My suggestion was to enforce that |
When one component of the velocity field is zero, streamplot fails to draw streamlines. Here's a short example of the issue:
Explanation of fix:
Negative and positive steps are treated differently by the code. Before, a zero gradient (
cx
,cy
) was getting treated as a negative step. This resulted in a step size of-inf
; treating zero as a positive step results in a step size of (positive)inf
. Thisinf
value gets filtered out since the integration routine chooses the smaller of the two (dsx
,dsy
) step sizes.