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

Issue calculating molar fractions of every component out the biphase zone for a custom fluid modelled with AbstractState #2308

Open
vins1996 opened this issue Oct 20, 2023 · 5 comments

Comments

@vins1996
Copy link

vins1996 commented Oct 20, 2023

Description

I am currently using Coolprop library on a python code. For my research I modeled a fluid with the function AbstractState, which is a gas refrigerant mixture (nitrogen, methane, ethane and propane). When calculting the molar fractions of every single component out of the biphase zone with the function fluidname.mole_fractions_liquid() or fluidname.mole_fractions_vapor(), the code returns values different from zero for both.

Expected behavior:
I expect that in vapor zone, molar fractions of the liquid part of the fluid is returned with zero value

Actual behavior:
In my case the value is not zero and neither is negligible.

Versions

CoolProp Version: 6.5.0
Operating System and Version: [WSL with ubunthu 22.04.2 LTS]
Access Method: [Python3]

Additional Information

@ibell
Copy link
Contributor

ibell commented Oct 22, 2023 via email

@vins1996
Copy link
Author

vins1996 commented Nov 2, 2023

Here you are the code I am talking about:

here i define the mixture using low level intrerface

AS = cp.AbstractState('HEOS', 'Nitrogen&Methane&Ethane&Propane')

here I set the molar composition

AS.set_mole_fractions([0.10, 0.34, 0.41, 0.15])

here is a vector of temperatures (in °C) which are assumed by the mixture in a heat exchanger:

Tmedia=[-18.79070798  -22.37212394  -25.9535399   -29.53495586  -33.11637181
  -36.69778777  -40.27920373  -43.86061969  -47.44203565  -51.02345161
  -54.60486757  -58.18628352  -61.76769948  -65.34911544  -68.9305314
  -72.51194736  -76.09336332  -79.67477928  -83.25619524  -86.83761119
  -90.41902715  -94.00044311  -97.58185907 -101.16327503 -104.74469099
 -108.32610695 -111.9075229  -115.48893886 -119.07035482 -122.65177078
 -126.23318674 -129.8146027  -133.39601866 -136.97743462 -140.55885057
 -144.14026653 -147.72168249 -151.30309845 -154.88451441 -158.46593037]

here I create a matrix containing all the molar fractions for every single component of the mixture for both the liquid fraction and the vapor fraction

fmol=zeros((40,8))
for i in range(len(Tmedia)):
 AS.update(cp.PT_INPUTS,1.5e5,Tmedia[i]+273.15)
     fmol[i,:4]=AS.mole_fractions_vapor()
     fmol[i,-4:]=AS.mole_fractions_liquid()

after this calculation the liquid fraction results to be different from zero even if the thermodynamical working point is located in the vapor zone (should return 0).

@ibell
Copy link
Contributor

ibell commented Nov 3, 2023

I rewrote in Python:

import CoolProp.CoolProp as CP 

AS = CP.AbstractState('HEOS', 'Nitrogen&Methane&Ethane&Propane')
AS.set_mole_fractions([0.10, 0.34, 0.41, 0.15])
AS.build_phase_envelope("")
Tmedia=[-18.79070798,  -22.37212394,  -25.9535399,   -29.53495586,  -33.11637181,
  -36.69778777,  -40.27920373,  -43.86061969,  -47.44203565,  -51.02345161,
  -54.60486757,  -58.18628352,  -61.76769948,  -65.34911544,  -68.9305314,
  -72.51194736,  -76.09336332,  -79.67477928,  -83.25619524,  -86.83761119,
  -90.41902715,  -94.00044311,  -97.58185907, -101.16327503, -104.74469099,
 -108.32610695, -111.9075229,  -115.48893886, -119.07035482, -122.65177078,
 -126.23318674, -129.8146027,  -133.39601866, -136.97743462, -140.55885057,
 -144.14026653, -147.72168249, -151.30309845, -154.88451441, -158.46593037]

for i in range(len(Tmedia)):
    AS.update(CP.PT_INPUTS, 1.5e5, Tmedia[i]+273.15)
    print(AS.Q(), AS.mole_fractions_vapor(), AS.mole_fractions_liquid())

yielding

-1.0 [0.45434177472808807, 0.49317856069139204, 0.049386240075564594, 0.0030934245049553223] [0.0020130329221854917, 0.021438144457052107, 0.31131159597432506, 0.6652372266464375]
-1.0 [0.46001734666758287, 0.4901082069593564, 0.0470092972623885, 0.002865149110672272] [0.0018601235710119862, 0.02018282078659565, 0.3059848746997857, 0.6719721809426067]
-1.0 [0.465823831410134, 0.4868564190176921, 0.04467252991643447, 0.0026472196557393783] [0.0017144616855057865, 0.01896297274564123, 0.300522264208323, 0.67880030136053]
-1.0 [0.4717654795779386, 0.48341666136400385, 0.04237825503391542, 0.002439604024142194] [0.0015760073202686139, 0.017779543620301513, 0.29492326468232166, 0.6857211843771083]
-1.0 [0.4778467166169197, 0.4797822458102901, 0.040128787954832844, 0.002242249617957157] [0.001444705983171144, 0.01663342708379805, 0.2891876542635091, 0.6927342126695217]
-1.0 [0.48407214818631156, 0.47594633553913834, 0.037926433484704855, 0.002055082789845298] [0.0013204883047829837, 0.015525460884764454, 0.2833155185640384, 0.6998385322464141]
-1.0 [0.4904465647630684, 0.47190195054432854, 0.035773476323100906, 0.0018780083695021292] [0.001203269780262814, 0.0144564203673973, 0.2773072824481505, 0.7070330274041894]
-1.0 [0.49697494558569205, 0.4676419744686009, 0.03367217066031787, 0.001710909285389272] [0.0010929505853116415, 0.013427011794055858, 0.2711637438354136, 0.714316293785219]
-1.0 [0.5036624614248884, 0.46315916324235307, 0.03162472902999363, 0.0015536463027649313] [0.0009894154808608663, 0.012437865560460747, 0.26488610982202937, 0.7216866091366491]
-1.0 [0.5105144759716602, 0.4584461557603618, 0.029633310380452173, 0.0014060578875257782] [0.0008925338134504599, 0.011489529333897248, 0.25847603506330347, 0.7291419017893488]
-1.0 [0.5175365454552538, 0.45349548695470027, 0.027700007380718768, 0.0012679602093271123] [0.0008021596207973062, 0.010582461176092134, 0.2519356624470503, 0.7366797167560601]
-1.0 [0.10161644746993083, 0.3432669036055692, 0.4080192762459511, 0.1470973726785488] [0.0004981951197854633, 0.011027749695796264, 0.260784062730767, 0.7276899924536513]
-1.0 [0.10171589038090094, 0.3434820718482371, 0.4078952932655483, 0.14690674450531369] [0.0004212752514287991, 0.009816301615999522, 0.25127079742775993, 0.7384916257048117]
-1.0 [0.10182365988544284, 0.34371706807381586, 0.40776024771949815, 0.1466990243212431] [0.0003539928309961918, 0.008697526141914162, 0.24161597769043822, 0.7493325033366514]
0.9761944217413094 [0.10243063499350868, 0.34808558548673685, 0.4138542699966456, 0.13562950952310895] [0.00032747194637273796, 0.008436129485068857, 0.251948776598346, 0.7392876219702122]
0.9205117988505396 [0.10860467287645142, 0.36853979473111814, 0.4197260257075198, 0.10312950668491065] [0.00035376235255928025, 0.009495492853762303, 0.29736795890649526, 0.6927827858871832]
0.8702297177724977 [0.11485509820131738, 0.38910547553003233, 0.41930448974899714, 0.07673493651965312] [0.0003828274138878004, 0.010702370021052428, 0.347604790719635, 0.6413100118454246]
0.822168652065024 [0.12153925037215099, 0.41091725861574385, 0.411792858212605, 0.05575063279950015] [0.00041651394362203183, 0.012124715925653623, 0.4017109895780378, 0.5857477805526864]
0.7739293855268291 [0.12907740230182121, 0.4352697061573261, 0.3961210099195253, 0.03953188162132734] [0.00045700438324506205, 0.013855599479247157, 0.45751305616661436, 0.5281743399708935]
0.7243424231540061 [0.13786363160542917, 0.4632997468926155, 0.37139519271471894, 0.02744142878723636] [0.0005063531380070098, 0.01600726725462901, 0.5114412221004786, 0.47204515750688547]
0.6741581578587473 [0.14805984930756366, 0.4953016050916502, 0.33785134757110985, 0.01878719802967631] [0.0005655114589436769, 0.018685308123447725, 0.5592735507196873, 0.4214756296979212]
0.6258652947985432 [0.15940011184686242, 0.530123818051014, 0.29767131336810426, 0.012804756734019292] [0.0006335131692991331, 0.021954540569328163, 0.597907170775938, 0.3795047754854348]
0.5821634399611 [0.17126502024435972, 0.5654860004530987, 0.2545047393965067, 0.008744239906034837] [0.0007079524923749583, 0.02583511809125726, 0.6266482623608677, 0.34680866705550023]
0.5445037278259022 [0.1829957305956052, 0.5990435630859868, 0.2119701138328319, 0.005990592485576127] [0.0007864466241420595, 0.030337898245275653, 0.6467260163898331, 0.32214963874074914]
0.5129317313685917 [0.1941340890897772, 0.6291448907053774, 0.17261342700535023, 0.004107593199495193] [0.0008676717743536145, 0.035502378709617206, 0.6599910914102913, 0.30363885810573793]
0.48667890019118515 [0.20447117808208526, 0.6549314784107835, 0.13778906310560868, 0.0028082804015226856] [0.0009515692343768734, 0.04141555491241387, 0.6680813831298509, 0.2895514927233584]
0.4646940338671682 [0.21399926723604942, 0.6761211436729186, 0.10797262256156091, 0.0019069665294710525] [0.0010391983019102282, 0.04821902059531557, 0.6721847677686467, 0.2785570133341277]
0.44590857153943503 [0.22285563464611818, 0.6927641337111449, 0.08309866497709888, 0.0012815666656380202] [0.0011326253577426618, 0.05611506571568465, 0.6730719938394331, 0.2696803150871397]
0.4293187586306165 [0.2312887660346355, 0.7050582366538153, 0.06280338249444276, 0.0008496148171063718] [0.001234990941215635, 0.06537650296304713, 0.6711866811519069, 0.2622018249438303]
0.41397939566243175 [0.23965140285128267, 0.7132169622187334, 0.04657768982117516, 0.0005539451088088448] [0.0013508175674305783, 0.07636105731030243, 0.6667200403641876, 0.25556808475807935]
0.39895983074741587 [0.24842197168605876, 0.7173643348365281, 0.03385954023045804, 0.00035415324695507733] [0.0014866620871195081, 0.08952886145015304, 0.6596588058698029, 0.24932567059292454]
0.3832829707968213 [0.2582622218248915, 0.7174277897945155, 0.024088633116025784, 0.0002213552645672374] [0.0016523417604306751, 0.10545799210441197, 0.6498138910438372, 0.24307577509132006]
0.36585735987918216 [0.2701307536109966, 0.7129961907548947, 0.01673822619775356, 0.00013482943635518158] [0.0018632106707645044, 0.12484402251919216, 0.6368458055215362, 0.2364469612885071]
0.3454219065449148 [0.28548992461977346, 0.7030975351486389, 0.011332779146897927, 7.976108468982914e-05] [0.0021444300098769206, 0.14844719012737606, 0.620317666649156, 0.229090713213591]
0.32057274902664207 [0.3066568370198605, 0.6858409589541282, 0.0074565447097921095, 4.5659316219173396e-05] [0.0025388894874239544, 0.17689848152875645, 0.5998428948585077, 0.22071973412531187]      
0.28993301442986685 [0.3372728615595546, 0.6579459098670399, 0.004756024967636913, 2.5203605768680063e-05] [0.0031204446500296464, 0.21018128339330008, 0.5754629014516932, 0.21123537050497712]
0.25372789119069195 [0.3823490715590437, 0.6147000325890455, 0.0029375154597073632, 1.3380392203370914e-05] [0.0040077939920893195, 0.24660829173949225, 0.5483919049505801, 0.20099200931783828]
0.21479463911825858 [0.44602417476091205, 0.5522091167611195, 0.00175988026243907, 6.828215529303881e-06] [0.005350342129092476, 0.2819534189702045, 0.5216678847338828, 0.1910283541668203]
0.1787170943651267 [0.5262445745555555, 0.47272590220751953, 0.0010261711933448913, 3.352043579927159e-06] [0.007252433758889394, 0.3111198566697566, 0.49898958377986813, 0.1826381257914859]
0.14955156009771148 [0.6134149980110895, 0.38600065460175054, 0.0005827659283976946, 1.581458762274184e-06] [0.009719199113264411, 0.33191107397553965, 0.4819934476632059, 0.17637627924798996]

which is weird. When Q < 0 or Q >1 the liquid and vapor mole fractions should not be defined. I don't know what is going on there.

@vins1996
Copy link
Author

vins1996 commented Nov 4, 2023

I think a bug affects coolprop in this case. Also the fact that the vapor quality is given less than zero is not phisically realistic. Anyway making the calculations with fluidprop the vapor quality is always zero and the molar fractions for the liquid fractions are defined but calculated equal to zero. For this reason I would like to use fluidprop on python but it's not so esasy

@ibell
Copy link
Contributor

ibell commented Nov 4, 2023

I recommend to plot the isopleth of the phase envelope along with your T,p points to better understand where your state points are. The value of Q is only meaningful if in [0,1], otherwise it is only very roughly providing guidance.

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