diagram_ph/refDLL.py

197 lines
5.4 KiB
Python

from IPM_DLL.simple_refrig_api import Refifc
import numpy as np
import pandas as pd
from enum import Enum
class RefProp(Enum):
"""Enumeration to define property types"""
PT = 1,
PX= 2,
TSX = 3,
TSSH=4,
PH=5,
class RegDllCall(object):
"""
Class to define and handle the DLL calls
:param RERFRIG: Refrigerant type
:type RERFRIG: str
"""
def __init__(self,RERFRIG):
"""Constructor method"""
self.refrig = Refifc(RERFRIG)
def T_px(self,p,x):
"""
Returns temperature given pressure and quality
:param p: Pressure
:type p: float
:param x: Quality
:type x: float
:return: Temperature
:rtype: float
"""
return self.refrig.T_px(p, x)
def H_pT(self,p,t):
"""
Returns enthalpy given pressure and temperature
:param p: Pressure
:type p: float
:param t: Temperature
:type t: float
:return: Enthalpy
:rtype: float
"""
return self.refrig.h_pT(p, t)
def x_ph(self, p, h):
"""
Returns quality given pressure and enthalpy
:param p: Pressure
:type p: float
:param h: Enthalpy
:type h: float
:return: Quality
:rtype: float
"""
return self.x_ph(p, h)
def p_Tx(self, T,x):
"""
Returns pressure given temperature and quality
:param T: Temperature
:type T: float
:param x: Quality
:type x: float
:return: Pressure
:rtype: float
"""
return self.refrig.p_Tx(T, x)
def h_px(self, p, x):
"""
Returns enthalpy given pressure and quality
:param p: Pressure
:type p: float
:param x: Quality
:type x: float
:return: Enthalpy
:rtype: float
"""
return self.refrig.h_px(p, x)
def Ts_ph(self, p, h):
"""
Returns saturation temperature given pressure and enthalpy
:param p: Pressure
:type p: float
:param h: Enthalpy
:type h: float
:return: Saturation temperature
:rtype: float
"""
return self.refrig.Ts_ph(p, h)
def Ts_px(self, p, x):
"""
Returns saturation temperature given pressure and quality
:param p: Pressure
:type p: float
:param x: Quality
:type x: float
:return: Saturation temperature
:rtype: float
"""
return self.refrig.Ts_px(p, x)
def findwhole10number(self,n, m):
"""
Finds whole numbers between two numbers which are multiples of 10
:param n: Starting number
:type n: float
:param m: Ending number
:type m: float
:return: List of numbers
:rtype: list
"""
start = n//10+1
end = m//10+1
return np.arange(start*10, end*10, 10)
def saturation_table(self, temp_start, temp_end, step):
"""
Generates a DataFrame of saturation properties based on temperature range and step.
:param temp_start: Starting temperature
:type temp_start: float
:param temp_end: Ending temperature
:type temp_end: float
:param step: Step size for temperature
:type step: float
:return: DataFrame with saturation properties
:rtype: pd.DataFrame
"""
# Create an array of temperatures based on the range and step
temperatures = np.arange(temp_start, temp_end, step)
# Initialize lists to store data
pressures = []
liquid_densities = []
vapor_densities = []
liquid_enthalpies = []
vapor_enthalpies = []
# Loop through each temperature to calculate properties
for temp in temperatures:
# Get pressure at saturated liquid and vapor
pressure = self.refrig.p_Tx(temp, 0) # Pressure is the same for liquid and vapor at saturation
pressures.append(pressure*1e-3)
# Get liquid and vapor densities
liquid_density = self.refrig.rhosl_px(pressure, 0) # Liquid density
vapor_density = self.refrig.rhosv_px(pressure, 1) # Vapor density
liquid_densities.append(liquid_density)
vapor_densities.append(vapor_density)
# Get liquid and vapor enthalpies
liquid_enthalpy = self.refrig.hsl_px(pressure, 0) # Liquid enthalpy
vapor_enthalpy = self.refrig.hsv_px(pressure, 1) # Vapor enthalpy
liquid_enthalpies.append(liquid_enthalpy*1e-3)
vapor_enthalpies.append(vapor_enthalpy*1e-3)
# Round the values to two decimal places
pressures = [round(p, 2) for p in pressures]
liquid_densities = [round(ld, 2) for ld in liquid_densities]
vapor_densities = [round(vd, 2) for vd in vapor_densities]
liquid_enthalpies = [round(lh, 2) for lh in liquid_enthalpies]
vapor_enthalpies = [round(vh, 2) for vh in vapor_enthalpies]
# Create DataFrame
df = pd.DataFrame({
'Temperature (°C)': temperatures-273.15,
'Pressure (kPa)': pressures,
'Liquid Density (kg/m³)': liquid_densities,
'Vapor Density (kg/m³)': vapor_densities,
'Liquid Enthalpy (kJ/kg)': liquid_enthalpies,
'Vapor Enthalpy (kJ/kg)': vapor_enthalpies
})
return df