portyanikhin / PyFluids

Simple, full-featured, lightweight CoolProp wrapper for Python
https://pypi.org/project/pyfluids
MIT License
51 stars 2 forks source link

Need to add the ability to specify the phase for fluids and mixtures #21

Closed ATKuom closed 1 year ago

ATKuom commented 1 year ago

Sorry if it is a silly question but I want to create a flue gas mixture to use in my simulation. I have tried using mixture method to preserve their interactions but I was getting a ValueError: One stationary point (not good) for T=812.95,p=1e+06,z=[ 0.655479138479, 0.103344269713, 0.0232768701104, 0.217899721698 ] ... def exhaust(): exhaust_mass_flow = 68.75 exhaust_inlet_T = 539.8 exhaust_inlet_P = 10e5 flue_gas = Mixture( [ FluidsList.Nitrogen, FluidsList.Oxygen, FluidsList.CarbonDioxide, FluidsList.Water, ], [75.3, 15.53, 05.05, 04.12], ) exhaust_inlet = flue_gas.with_state( Input.temperature(exhaust_inlet_T), Input.pressure(exhaust_inlet_P) ) exhaust_inlet_h = exhaust_inlet.enthalpy print(exhaust_inlet_h) ... I have checked the methods part in the documents but could not see if I am not defining the mixture enough. I can use them as pure forms then mixed them manually for their thermophysical properties. However, I fear it would not be a good estimation for heating or cooling. ... nitrogen = Fluid(FluidsList.Nitrogen).with_state( Input.pressure(P), Input.temperature(T) ) oxygen = Fluid(FluidsList.Oxygen).with_state( Input.pressure(P), Input.temperature(T) ) water = Fluid(FluidsList.Water).with_state(Input.pressure(P), Input.temperature(T)) carbon_dioxide = Fluid(FluidsList.CarbonDioxide).with_state( Input.pressure(P), Input.temperature(T) ) h = ( nitrogen.enthalpy * 0.753

portyanikhin commented 1 year ago

Hello, @ATKuom!

What you are facing is an internal CoolProp error. Unfortunately, I can't influence it in any way.

Apparently, the equations of state of this mixture, embedded in CoolProp, get out of control with the input data you specify (or do not extend to this range of values).

You can try to create an issue in the CoolProp repository, but I recommend that you rewrite this example using pure CoolProp to make it easier for developers to understand it.

If we consider your second example (which does not raise an exception), then I don't think this is a bad idea. You simply view your mixture as an ideal mixture of gases. Of course, this will give a slight inaccuracy compared to using the equations of state of a real mixture of gases. But if CoolProp developers won't help you solve this problem, then I think your solution deserves attention.

I hope I helped you at least a little. Thank you for such a high assessment of my work. I would appreciate it if you put a star on PyFluids.

ATKuom commented 1 year ago

I have a further question if you do not mind. Is there a way to impose phase in pyfluids right now? I have seen the solution of the problem in coolprop in both high-level and low-level interface. Basically you have to impose that the mixture in gas phase. I am leaving the examples down below. < import CoolProp.CoolProp as CP K = 273.15 a = CP.PropsSI( "H", "P|gas", 101325, "T", 1169.38 + K, "Nitrogen[0.7643]&Oxygen[0.1382]&Water[0.0650]&CarbonDioxide[0.0325]", ) AS = CP.AbstractState("HEOS", "Nitrogen&Oxygen&CO2&Water") AS.specify_phase(CP.iphase_gas) AS.set_mole_fractions([0.7643, 0.1382, 0.065, 0.0325]) AS.update(CP.PT_INPUTS, 101325, 300) AS.rhomolar()

second example from the forum "Variable mixture composition in CoolProp" thread.

portyanikhin commented 1 year ago

At the moment, I have not provided for such an opportunity. I will implement this in the next version. Thank you for the offer!