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

Possible NaN in successive_substitution #1270

Open
JonWel opened this issue Oct 16, 2016 · 8 comments
Open

Possible NaN in successive_substitution #1270

JonWel opened this issue Oct 16, 2016 · 8 comments

Comments

@JonWel
Copy link
Contributor

JonWel commented Oct 16, 2016

This line has a division by df.
I felt on a specific case where this df is 0, thus change becomes NaN, and a bit later is added to p (or T), which is of course not an ideal output value (in my case, f is also null, thus it goes out of the loop as converged).

The specific case where this happened to me is in fact a pure fluid case (molar fraction = [0,1]), thus maybe this issue can only happen in that case.

If df can only happen to be null when it's a pure fluid, maybe this could be interesting to set a switch to use the pure fluid routine in that case (should be faster than the mixture routine and avoid the issue).

@ibell
Copy link
Contributor

ibell commented Oct 16, 2016

Yes, if df is zero (or very very small), we should stop the iteration. Can you file a PR?

JonWel added a commit to JonWel/CoolProp-f that referenced this issue Oct 17, 2016
JonWel added a commit to JonWel/CoolProp-f that referenced this issue Oct 17, 2016
@ibell ibell closed this as completed in ba0829b Oct 19, 2016
@JonWel
Copy link
Contributor Author

JonWel commented Oct 21, 2016

Seems the case with df < 1e-12 < f can happen:

R134A&R1234YF
Error: df very small (df = 1.46767e-16) in successive_substitution but f is not converged (f = 3.80154e-11 < 1e-12).
Error: df very small (df = -4.17617e-13) in successive_substitution but f is not converged (f = 3.27586e-08 < 1e-12).
Error: df very small (df = 3.55313e-16) in successive_substitution but f is not converged (f = 1.12735e-10 < 1e-12).
R143A&R134A
Error: df very small (df = -2.30305e-14) in successive_substitution but f is not converged (f = 1.03242e-07 < 1e-12).
Error: df very small (df = -2.327e-15) in successive_substitution but f is not converged (f = 6.97791e-08 < 1e-12).
Error: df very small (df = 3.0744e-13) in successive_substitution but f is not converged (f = 8.85959e-07 < 1e-12).

(And I notice the "<" is not correct, should be a ">")

I'll look tomorrow which entries gives this (I suspect it's the same point, triggering this kind of effect on the 3 EOS: HEOS, PR & VTPR).

@JonWel
Copy link
Contributor Author

JonWel commented Oct 22, 2016

Setting a lower threshold for df (like 3e-16) did not seem to help much

@JonWel
Copy link
Contributor Author

JonWel commented Oct 23, 2016

Seeing the temperatures, I suspect it's something happening near the critical point:

PropsSI("P", "Q", 0, "T", 405.16, "PR::n-Butane[0.407]&DME[0.593]")
PropsSI("P", "Q", 0, "T", 356.63, "PR::R125[0.4974]&R134A[0.5026]")
PropsSI("P", "Q", 0, "T", 345.47, "PR::R125[0.2491]&R32[0.7509]")
PropsSI("P", "Q", 0, "T", 363.15, "PR::R32[0.368]&R134A[0.632]")

So it may be interesting to see if there could be something to do in that area to be still able to compute the points, but for now I'll just correct the sign.

JonWel added a commit to JonWel/CoolProp-f that referenced this issue Oct 23, 2016
Also lower a bit the threshold for `df` and add some comments.
ibell pushed a commit that referenced this issue Oct 23, 2016
Also lower a bit the threshold for `df` and add some comments.
@ibell ibell reopened this Oct 25, 2016
@ibell
Copy link
Contributor

ibell commented Oct 25, 2016

I just chuck out the values for the pures when I fit mixtures. You might
want to do the same. There is also this old open issue:
#969 . I started working on
that issue, and it was a real rabbit hole...

On Fri, Oct 21, 2016 at 3:47 PM, JonWel notifications@github.com wrote:

Seems the case with df < 1e-12 < f can happen:

R134A&R1234YF
Error: df very small (df = 1.46767e-16) in successive_substitution but f is not converged (f = 3.80154e-11 < 1e-12).
Error: df very small (df = -4.17617e-13) in successive_substitution but f is not converged (f = 3.27586e-08 < 1e-12).
Error: df very small (df = 3.55313e-16) in successive_substitution but f is not converged (f = 1.12735e-10 < 1e-12).
R143A&R134A
Error: df very small (df = -2.30305e-14) in successive_substitution but f is not converged (f = 1.03242e-07 < 1e-12).
Error: df very small (df = -2.327e-15) in successive_substitution but f is not converged (f = 6.97791e-08 < 1e-12).
Error: df very small (df = 3.0744e-13) in successive_substitution but f is not converged (f = 8.85959e-07 < 1e-12).

(And I notice the "<" is not correct, should be a ">")

I'll look tomorrow which entries gives this (it's possible to be case with
molar fraction = [0,1] or [1,0]).


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#1270 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABxha_6CxnGbI73nA9jcWRqf9DrU2JaYks5q2TL2gaJpZM4KX9fC
.

@JonWel
Copy link
Contributor Author

JonWel commented Oct 25, 2016

You are right that a part of the values concerning pure fluids may not giving any useful information when considering mixtures.
I think the only place I have where this can be of some use is when I do the plot of the deviation toward molar fraction, in that case the pure fluid gives a reference value while still being easily distinguishable from the mixture's values.

To what I saw, the cases with the pure fluids seems to have been solved for me (f was also 0, thus it goes out of the loop as converged instead of giving a NaN. I should however have noted the specific point to check if the value makes sense).

What remains out are points I think are near the critical point, which is an area where there is usually less outputs from CoolProp.
See the 4 PropsSI examples in my previous comment. DME's critical point is at 400K, so the value of 405K for the mixture should not be far from the critical point of that mixture with butane.

@ibell
Copy link
Contributor

ibell commented Nov 1, 2016

Yes, I am running into a lot of problems now with failures of the flash
routines for these mixtures. I guess that shouldn't be too surprising
really, since near the critical region, all kinds of bad things happen.
Have you given further thought to implementing analytic derivatives
everywhere within VTPR? That might help with some of the iteration
problems we are running into.

On Tue, Oct 25, 2016 at 1:14 PM, JonWel notifications@github.com wrote:

You are right that a part of the values concerning pure fluids may not
giving any useful information when considering mixtures.
I think the only place I have where this can be of some use is when I do
the plot of the deviation toward molar fraction, in that case the pure
fluid gives a reference value while still being easily distinguishable from
the mixture's values.

To what I saw, the cases with the pure fluids seems to have been solved
for me (f was also 0, thus it goes out of the loop as converged instead
of giving a NaN. I should however have noted the specific point to check if
the value makes sense).

What remains out are points I think are near the critical point, which is
an area where there is usually less outputs from CoolProp.
See the 4 PropsSI examples in my previous comment. DME's critical point
is at 400K, so the value of 405K for the mixture should not be far from the
critical point of that mixture with butane.


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#1270 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABxhaxrBdX9yBDX2lKMxYoOkUgqWZfTbks5q3lT8gaJpZM4KX9fC
.

@JonWel
Copy link
Contributor Author

JonWel commented Nov 1, 2016

We can also just when df==0, which will, for sure, will not gives worst results than before.
For me 1e-14 is already small enough being only 5 times bigger than the epsilon machine.

I'm looking right now for the analytical derivative.

While I'm at it, I may also have a look at saving some intermediary steps that are sometimes computed more than needed.

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

2 participants