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

Incorrect region for certain region 2 temperature/pressure inputs? #16

Open
JBridenbaugh opened this issue Oct 7, 2024 · 5 comments
Open
Assignees

Comments

@JBridenbaugh
Copy link

According to table 18 on page 20 of the IAPWS-IF97 documentation the input values in that table should be in region 2 and should return the expected output values. When I use those input values in this library, I am not seeing the expected output values and the region is being identified as region 1.

Sample Code:

from pyXSteam.XSteam import XSteam
from pyXSteam.XSteam import RegionSelection

steamTable = XSteam(XSteam.UNIT_SYSTEM_BARE)

pressure = 1
temperature = 450

print(f"r: {str(RegionSelection.region_pT(pressure, temperature))}")
print(f"v: {str(round(steamTable.v_pt(pressure, temperature), 11))}")
print(f"h: {str(round(steamTable.h_pt(pressure, temperature), 6))}")
print(f"u: {str(round(steamTable.u_pt(pressure, temperature), 6))}")
print(f"s: {str(round(steamTable.s_pt(pressure, temperature), 8))}")
print(f"cp: {str(round(steamTable.Cp_pt(pressure, temperature), 8))}")
print(f"w: {str(round(steamTable.w_pt(pressure, temperature), 5))}")
print()

pressure = 1
temperature = 440

print(f"r: {str(RegionSelection.region_pT(pressure, temperature))}")
print(f"v: {str(round(steamTable.v_pt(pressure, temperature), 11))}")
print(f"h: {str(round(steamTable.h_pt(pressure, temperature), 6))}")
print(f"u: {str(round(steamTable.u_pt(pressure, temperature), 6))}")
print(f"s: {str(round(steamTable.s_pt(pressure, temperature), 8))}")
print(f"cp: {str(round(steamTable.Cp_pt(pressure, temperature), 8))}")
print(f"w: {str(round(steamTable.w_pt(pressure, temperature), 5))}")
print()

pressure = 1.5
temperature = 450

print(f"r: {str(RegionSelection.region_pT(pressure, temperature))}")
print(f"v: {str(round(steamTable.v_pt(pressure, temperature), 11))}")
print(f"h: {str(round(steamTable.h_pt(pressure, temperature), 6))}")
print(f"u: {str(round(steamTable.u_pt(pressure, temperature), 6))}")
print(f"s: {str(round(steamTable.s_pt(pressure, temperature), 8))}")
print(f"cp: {str(round(steamTable.Cp_pt(pressure, temperature), 8))}")
print(f"w: {str(round(steamTable.w_pt(pressure, temperature), 5))}")
print()

Expected Results:

r: 2
v: 0.192516540
h: 2768.81115
u: 2576.29461
s: 6.56660377
cp: 2.76349265
w: 498.408101

r: 2
v: 0.186212297
h: 2740.15123
u: 2553.93894
s: 6.50218759
cp: 2.98166443
w: 489.363295

r: 2
v: 0.121685206
h: 2721.34539
u: 2538.81758
s: 6.29170440
cp: 3.62795578
w: 481.941819

Actual Results:

r: 1
v: 0.0011231015
h: 749.328482
u: 748.205381
s: 2.10885468
cp: 4.39337721
w: 1400.24334

r: 1
v: 0.0011101036
h: 705.575346
u: 704.465243
s: 2.01053038
cp: 4.35807066
w: 1427.13679

r: 1
v: 0.0011226877
h: 749.58737
u: 747.903338
s: 2.10818233
cp: 4.3912142
w: 1401.85642
@drunsinn
Copy link
Owner

drunsinn commented Oct 8, 2024

Ok, this seems to be a serious error. I will look into the Region select code where it differs from IF97.

Just a heads up; it might take some time since I am quite busy with other stuff at the moment. I hope that is ok for you.

@JBridenbaugh
Copy link
Author

Is it possible that the verification data in table 18 is wrong? I see that the code to determine the region uses equation 30 to get the saturation pressure from the provided temperature. If the provided pressure is greater than the saturation pressure it is region 1 and otherwise it is region 2. I don't see any logic error here so that would seem to make the issue fall on the implementation of equation 30. The only problem is that the data in table 35 used to verify equation 30 all checks out so there doesn't seem to be any error with the implementation of equation 30. All of this to say that it almost seems like the data in table 18 is just wrong.

@drunsinn
Copy link
Owner

I think I identified the problem! Quite simply, the equations from section 6.2 simply aren't there. Tabel 18 is meant to test exactly the metastable vapor region but since there is no code, the tests fail. Looking back at the original Matlab code from Magnus Holmgren, it seems it was never implemented in the first place.
Getting everything implemented from section 6.2 might take some time, especially since I realize how bad the current implementation of pyXSteam is. At least now we know why there are errors in the region. Going by the introduction to IF97, there was some revision to exactly this section so I am not surprised.
Interestingly enough, other online tools also give the wrong/same results as pyXSteam does right now.

@drunsinn drunsinn self-assigned this Oct 13, 2024
@JBridenbaugh
Copy link
Author

That would make sense as to why the values are off, but does that explain why the code returns region 1 rather than region 2? I would expect the code currently to select region 2, but use the standard region 2 equation rather than the metastable vapor region equation. Currently it seems that the region 1 is being selected and the region 1 equation is being used. Thanks for looking into this!

@drunsinn
Copy link
Owner

I had some time to add the equations from chapter 6.2 including the tests. As of now the tests still report an error for the collective precision but it is already below 5.6e-4. There is probably some typo in the coefficients or something but in general they seem to work. If you want, you can check out the branch chap6.2_metastable.

The next step is, as you mentioned, to figure out what is wrong with the region selection code.

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