usnistgov / REFPROP-wrappers

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

Calculating composition of binary gas mixtures based on p,T,D #543

Closed c-wedler closed 6 months ago

c-wedler commented 1 year ago

Hi,

I try to find a way to calculate the composition of a binary gas mixture at a given temperature, pressure, and density (one phase systems). I tried several configurations with hOut = "xmole", but I could not find a solution. Is it possible to define three input parameters instead of two? Many thanks in advance!

nist-aharvey commented 1 year ago

While I don't know if there is such a function in the interface, I want to point out that the problem as stated is not always well defined. At fixed T and P, the density (either molar or mass) of a binary mixture is not necessarily monotonic with composition. So there could be multiple roots depending on the mixture (although my instinct is that it will be monotonic for a majority of binary mixtures). If you have a case where you know the function is monotonic, you could set up an iterative loop outside of Refprop to solve for the composition (like a bounded secant method with the 2 pure components as endpoints), but of course it would be more convenient if there was a more direct way.

c-wedler commented 1 year ago

Thank you for your valuable comment, Allan! I think there is no function in the interface. I tried to use the DLL, but neither in Matlab nor in Excel/VBA, I found a solution. I considered an outside iterative loop, but I also thought it would be worth asking in GitHub.

Regarding the monotonic behaviour, currently, I am looking at a mixture of CO2 and CH4; later maybe at other mixtures of "simple" molecules (N2, O2). As well as H2, but I assume H2 might be a bit more troublesome due to the isomeric properties.

nist-aharvey commented 1 year ago

If it is in the gas phase and you are looking at MASS density it will pretty much certainly be monotonic for CO2/CH4 and for mixtures with H2 and anything with a significant difference in molecular weight. MOLAR density in the gas phase could easily be non-monotonic, because to a zero-th approximation (ideal gas) it has the same value at a given (T,P) independent of composition so small effects could produce a maximum or minimum.

ianhbell commented 1 year ago

REFPROP only allows you to provide two thermodynamic variables, not three. So if you need to solve for a composition, you need to do it yourself. In your case, you can hold temperature and density constant, and adjust a composition until you get the right pressure.

ianhbell commented 1 year ago

If you need to do phase equilibria, you can see an approach in: https://www.sciencedirect.com/science/article/pii/S014070071730381X

c-wedler commented 1 year ago

Ok, thanks a lot for clarifying!