usnistgov / REFPROP-wrappers

Wrappers around NIST REFPROP for languages such as Python, MATLAB, etc.
191 stars 126 forks source link

Discrepancy in fluid properties beween refprop.exe and fortran #263

Closed SBordi closed 4 years ago

SBordi commented 4 years ago

Hi, I ran into a problem that might be related to the reference conditions of the fluids, using a FORTRAN subroutine. I tested the use of r134a and of the mixture r410a in the same subroutine and I compared the results obtained in FORTRAN and the results obtained in REFPROP.exe (and also in the excel file with the REFPROP dll implemented). While the results for the fluid r134a are the same in both the programmes, the results for r410a are slightly different. For example, if I give as a input a temperature of T=355.56K and a pressure of P=3.214MPa, with FORTRAN I obtain enthalpy H=472.3049kJ/kg and entropy S=1.9139kJ/(kg K), with REFPROP.exe I obtain H=471.09kJ/kg and S=1.8431kJ/(kg K).

I tried to check the reference conditions, but they seem to be the same. What could be the problem? Thank you.

ianhbell commented 4 years ago

Do you get the same densities for each input? That's the first thing to check since that depends only on the residual part of the EOS.

SBordi commented 4 years ago

Yes, with the same input for temperature and pressure I get the same density in fortran and refprop.exe.

ianhbell commented 4 years ago

Can you please show that result? I would like to see if they are similar, or exactly the same. What if you use molar units? The internal units in REFPROP are always molar, and I wonder if the molar mass of the two calculations are somehow slightly different, resulting in this discrepancy.

SBordi commented 4 years ago

I was checking this, and it seems that it changes in some cases, while in other cases it is exactely the same, but I need to verify this. Then, I actually realized that when I enter the values for Enthalpy and Pressure in refprop.exe, the program automatically changes some decimal values of the inputs (I am referring to Calculate/Specified state point). I will try to verify if I get better results when using Inputs with less decimals and if the problem persists using molar units. I'll keep you updated. Thanks

ianhbell commented 4 years ago

You can also adjust the number of digits in the preferences to something a bit larger (10 maybe?). Given how small the differences are, I could imagine you might be seeing a rounding difference, but it's surprising, so I don't think anything is wrong with REFPROP itself.

SBordi commented 4 years ago

I attached two files: the .txt file contains the fortran program code, while the Excel file contains the results from REFPROP.exe and the fortran program. In the excel the Input values used for the calculations of the properties are highlighted and follow the step order of the fortran program. Maybe the code can be useful to see if I made some mistakes or if something is missing (the discrepancies appear only when using the mixture). results.xlsx program_forum.txt

ianhbell commented 4 years ago

We are all working remotely currently thanks to corona, so it might be a while before we are able to dig into this. I'll start with checking your results in Python.

EricLemmon commented 4 years ago

When you ran the GUI, I assume you went to Substance/Pseudo Pure Fluid and chose R410A. There's a button there labeled uncertainty, but which also gives some additional information. I've pasted it in below.

image

Now look at the image below and the two tables. The top is for the mixture (meaning that it uses the mixture model, not an equation of state developed for just that mixture). Notice that it shows the component names and their compositions. The bottom is for the pseudo-pure fluid. The top one matches what the Fortran gave you, as it should. In general we recommend that you do not use the pseudo-pure fluid equations (which I suspect you did not realize you were doing when you ran the GUI). These are basically for applications that require significant speed improvement, but they do not have the ability to calculate transport properties nor two-phase states, so their use is quite limited.

image

I'll load the documentation on the pseudo-pure fluids here in case you would like additional information:

https://trc.nist.gov/refprop/Documents/Pseudo.pdf

SBordi commented 4 years ago

Thank you very much for your reply, Eric. The steps that I followed for selecting the mixture in the GUI were: Substance/predefined mixture. Then for obtaining the properties, I chose Calculate/Specified State Points. Below, I have pasted the comparison with the pseudo pure fluid properties as you did but, as you can notice, the results from the predefined mixture are different from yours (yours correspond to what I obtained with Fortran). image

In the screenshot, you can also see the version of the GUI I am using.

If I can ask you another question, may you give a look to the code I attached in the previous message and tell me if the procedure I used to call the fluids is correct? Should I only invert the two calls if I need to call the mixture first and then the pure fluid? The fact is that I now need to invert the call to R134a with the call to R410a (that is the first fluid that I need to use), but it seems that, in this way, the call to GETENUM(0,'MASS BASE SI',iUnit,ierr,herr) for obtaining mass basis properties doesn't work properly. Thank you for your time.

EricLemmon commented 4 years ago

Can you send me a personal email so that I can send you the most recent Fortran code for you to test? I'm at eric.lemmon@nist.gov

EricLemmon commented 4 years ago

Sorry for my slow response. I hope my delayed answer is still of use.

I think I have located the problem. I am very confused why this bug has never been found before, it would seem that this would happen to some. Under the Options/Reference State menu on the bottom right is an option for applying the reference state. If you change from Each Pure Component to Currently Defined Mixture, all works as it should. But if you change back then nothing happens. You have to either save your settings and exit the program or pick some other fluid to reset things and then reselect your mixture. The problem is in the GUI, not the Fortran code. I have fixed the GUI, and all matches up with the values you have given above. I still have your email and will send you a link to the new GUI. If you find anything else or have other questions, let us know. If all is working, please post a message here and then close the issue.

SBordi commented 4 years ago

Thank you for your response. I verified this and now I get the right results in the GUI. However, I get the right results by changing the reference state from Currently Defined Mixture to Each Pure Component, not vice versa. Anyway, if you don't have other comments, I can close the issue. Thank you.

EricLemmon commented 4 years ago

That's great! I probably got those two options reversed when I wrote that, but if it is working then I think this problem is solved now and I'm glad you brought it to our attention.

Eric