GithubHelp home page GithubHelp logo

portyanikhin / pyfluids Goto Github PK

View Code? Open in Web Editor NEW
46.0 2.0 2.0 898 KB

A simple, full-featured, lightweight CoolProp wrapper for Python

Home Page: https://pypi.org/project/pyfluids

License: MIT License

Python 100.00%
coolprop fluids humid mixtures air properties thermodynamics thermophysical

pyfluids's People

Contributors

dependabot[bot] avatar portyanikhin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyfluids's Issues

Citing Pyfluids?

I would like to Cite Pyfluids for some research I'm doing. What would be your preferred method of citation?

An error occurred while calculating the gas mixture

from pyfluids import Mixture, Fluid, FluidsList, Input

mix = Mixture([FluidsList.Methane,FluidsList.Hydrogen],[60, 40]).with_state(Input.pressure(200e+03), Input.temperature(30),)
print(mix.specific_heat)
print(mix.compressibility)

ValueError: One stationary point (not good) for T=303.15,p=200000,z=[ 0.228681059385, 0.771318940615 ]

Unnecessarily stringent checks and exceptions on many operations

Many of the operations in this library throw an exception for what should be normal use cases.

For example, the .compression_to_pressure function refuses to accept an isentropic efficiency of 0% or 100%, both of which are extremely common choices when analyzing problems or just testing things in general.

(Additionally, it takes input as a percent instead of a floating point number, defying the convention of most other "fractional" inputs used in other libraries.)

This is not just limited to the compression_to_pressure function. The .cooling_to_temperature and other functions all throw exceptions whenever there is no change to the pressure - something that again is extremely common in analysis (for example, I am writing a Linde cycle simulator, and for the first pass through the exchanger there is no change in temperature).

I would strongly recommend combining many of these functions and allowing for a wider range of input values. For example, both cooling and heating to temperature could be merged to a "change_temperature" or "heat_to_temperature" function, which automatically cools or heats as needed. Likewise, the compression and expansion functions could be combined, and the isenthalpic_expansion_to_pressure folded in for an efficiency of 0% to the regular compression functions.

If this is something you consider a good idea, I can go ahead and submit a PR for these changes. It would greatly improve the usability of the library.

The necessary temperature unit is Kelvin.

Could you offer the option of using Kelvin as the temperature unit for both the input and all output properties?

I have added a sample code.

from pyfluids import Fluid, FluidsList, Input

def celsius_to_kelvin(temp_c):
return temp_c + 273.15

def kelvin_to_celsius(temp_k):
return temp_k - 273.15

def fluid_properties(fluid, pressure, temperature_k):
temperature_c = kelvin_to_celsius(temperature_k)
fluid_instance = Fluid(fluid).with_state(Input.pressure(pressure), Input.temperature(temperature_c))

properties = {
    "compressibility": fluid_instance.compressibility,
    "conductivity": fluid_instance.conductivity,
    "critical_pressure": fluid_instance.critical_pressure,
    "critical_temperature": celsius_to_kelvin(fluid_instance.critical_temperature),
    "density": fluid_instance.density,
    "dynamic_viscosity": fluid_instance.dynamic_viscosity,
    "enthalpy": fluid_instance.enthalpy,
    "entropy": fluid_instance.entropy,
    "internal_energy": fluid_instance.internal_energy,
    "kinematic_viscosity": fluid_instance.kinematic_viscosity,
    "max_pressure": fluid_instance.max_pressure,
    "max_temperature": celsius_to_kelvin(fluid_instance.max_temperature),
    "min_pressure": fluid_instance.min_pressure,
    "min_temperature": celsius_to_kelvin(fluid_instance.min_temperature),
    "molar_mass": fluid_instance.molar_mass,
    "phase": fluid_instance.phase,
    "prandtl": fluid_instance.prandtl,
    "pressure": fluid_instance.pressure,
    "quality": fluid_instance.quality,
    "sound_speed": fluid_instance.sound_speed,
    "specific_heat": fluid_instance.specific_heat,
    "surface_tension": fluid_instance.surface_tension,
    "temperature": celsius_to_kelvin(fluid_instance.temperature),
    "triple_pressure": fluid_instance.triple_pressure,
    "triple_temperature": celsius_to_kelvin(fluid_instance.triple_temperature),
}

return properties

selected_fluid = FluidsList.Nitrogen
pressure = 100e3
temperature_k = -20 + 273.15 # Convert -20°C to Kelvin

properties = fluid_properties(selected_fluid, pressure, temperature_k)
print(properties)

Config File

Hi! I am new to python programming and am struggling to use a config file to switch system units.

`from CoolProp.Plots.SimpleCycles import StateContainer
import matplotlib.transforms as mtransforms
import configparser

from pyfluids import Fluid, FluidsList, Input
config = configparser.ConfigParser().read(r'pyfluids.ini')

state_LPOUT = Fluid(FluidsList.CarbonDioxide).with_state(Input.pressure(df.LPOUT_P_SI.mean()),Input.density(df.LPOUT_rho_SI.mean()))`

This is not complete code, but my reading of the config file does not change the unit system as observed in

print(state_LPOUT.as_dict())

Can you create an example or point me in the right direction?

Thank you!

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

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
+ oxygen.enthalpy * 0.1553
+ carbon_dioxide.enthalpy * 0.0505
+ water.enthalpy * 0.0412
...
Sorry if it is wrong place to post but I could not see another way to contact you to ask. Thank you for your wrapper. It is such a gift to newcomers like me.

[Feature Request] vectorized P & T input and/or soft-fail error handling.

For use of a specific fluid property, I currently do the following:

def calc_density(P,T,water: Fluid): 
    try:
        water.update(Input.pressure(P * 1e9), Input.temperature(T-273.15))
     except:
        return np.nan
     return water.density

This allows me to both vectorize calculation of the property across a P-T grid, and fill the result with nan's should the query lie outside of the database bounds. However, for large (200x200) P-T grids, this operation can be quite slow, probably because of the try/except block. I can see two possible ways to improve code execution:

  • propagate nan's in a manner which simply return nan if any of the input is invalid.

  • allow implicit vectorization of numpy arrays P & T data over the internal coolprop calls.

I'm not sure how this would work behind the scenes, its possible it might break the OOP structure to implement these fixes.
Considering im currently getting runtimes of a few minutes to 30min or more, I figure id bring it up anyways.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.