Open JungHulk opened 1 year ago
Module.py
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 7 16:10:55 2022
@author: 252914
"""
import os
import pandas as pd
import numpy as np
import math
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
# from Background_Code import P,T
# Main = Mywindow()
#---------------------------One file 재시도
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
Path = resource_path("source")
Ref_path = resource_path(Path)
RP = REFPROPFunctionLibrary(Path)
RP.SETPATHdll(Path)
SI = RP.GETENUMdll(0,"SI WITH C").iEnum
#--------------------------- One file 용
# BASE_DIR = os.path.dirname(sys.executable)
# Path = BASE_DIR +"\\source"
# # # # os.chdir('source') #item 폴더로 이동
# RP = REFPROPFunctionLibrary(Path)
# RP.SETPATHdll(Path)
# SI = RP.GETENUMdll(0,"SI WITH C").iEnum
#--------------------------- One file 용
os.chdir('source') #item 폴더로 이동
RP = REFPROPFunctionLibrary(os.getcwd())
RP.SETPATHdll(os.getcwd())
SI = RP.GETENUMdll(0,"SI WITH C").iEnum
def Comp_OK_Button(Composition, Comp_value, MSG): # Composition
for n,i in enumerate(Composition):
i.setValidator(
QtGui.QDoubleValidator(
0.0, # bottom
999.0, #top
4, #decimals
notation = QtGui.QDoubleValidator.StandardNotation
)
)
for n,i in enumerate(Composition):
try:
Comp_value[n] = float(i.text())
except ValueError:
MSG = "Input number only"
i.setText(str(0))
Comp_value[n] = float(i.text())
Sum_comp = float(Comp_value.sum())
if (abs(Sum_comp - 1.00) <= 1e-8) == True: # 부동소수점 해결
# MSG = "Composition Setting clear"
MSG = "Please Click OK button"
elif (abs(Sum_comp - 100.00) <= 1e-6) == True:
# MSG = "Composition Setting Clear"
MSG = "Please Click OK button"
elif abs(Sum_comp) == 0:
MSG = "Please input Compositions"
else:
MSG = "Need to normalize"
return Sum_comp, MSG
def Normalize_Button(Composition, Comp_total, Comp_nor_value, MSG): # Composition Normalize Button
for n,i in enumerate(Composition) :
try:
Comp_nor_value[n] = float(i.text())/ Comp_total
MSG = "Normalize complete"
except ZeroDivisionError:
MSG = "Please input Composition"
i.setText("%.4f"%(Comp_nor_value[n]*100)) #소수점 4자리까지 표현
Sum_comp = float(Comp_nor_value.sum())
return Sum_comp, MSG
def Pipe_information(Pipe_info, df1):
# Pipe_info = [float(self.Pipe_ND.currentText()), self.Pipe_schedule.currentText(), self.Pipe_length.text()]
ND = float(Pipe_info[0])
Sch = Pipe_info[1]
try:
Length = float(Pipe_info[2])
except ValueError:
Length = float(0)
ND_inch = str(df1.at[ND,'(NPS)'])
OD = float(np.array(df1.loc[[(ND)],[df1.columns[1]]]))
ID = 0
Sec_area = 0
Volume = 0
Thickness = '-'
Surface_area = math.pi * float(OD) * Length / 1000000 # 표면적
try:
Thickness = df1.at[ND,Sch]
if Thickness == "-":
MSG = "Select schedule again"
else:
MSG = "Done"
ID = float(OD) - 2*float(Thickness) # 내경
Sec_area = math.pi * (ID/2)**2 / 1000000 # 단면적
Volume = Sec_area * float(Length) / 1000 # 배관 내부 부피
except KeyError:
MSG ="Select schedule again"
return ND, Sch, ND_inch, OD, Thickness, Length, ID, Sec_area, Volume, MSG, Surface_area
def Velocity(Flow):
# Flow = [self.Properties_flowrate.text(), self.units_flowrate_list.currentText(), self.Pipe_secarea.text()
# 0 1 2
# self.Properties_density.text()]
# 3
Flowrate = 0
Velocity = 0
try :
Flowrate = float(Flow[0])
# Velocity = Flowrate / float(Flow[2]) / 3600
if Flow[1] == 'm3/h' :
if str(Flow[0]) == '0':
Velocity = 0
MSG_2 = "Please input flowrate"
elif str(Flow[0]) == '':
Velocity = 0
MSG_2 = "Please input flowrate"
else:
Velocity = Flowrate / float(Flow[2]) / 3600
MSG_2 = ' '
if Flow[1] == 'kg/h' :
if str(Flow[3]) == '-':
Velocity = 0
MSG_2 = "Please calculate properties first"
elif str(Flow[3]) =='0':
Velocity = 0
MSG_2 = "Please calculate properties first"
else:
MSG_2 = ' '
Flowrate = float(Flowrate) / float(Flow[3])
Velocity = Flowrate / float(Flow[2]) / 3600
# print (float(self.Properties_density.text()))
except :
MSG_2 = "Please input number only"
# print(Flowrate, Velocity)
return Flowrate, Velocity, MSG_2 #Flowrate 는 volumetric flowrate
def Properties(Comp_name, Comp_value, Input_prop, input1, input2):
Prop_list = "P;T;D;H;M;CP;Phase;Qmass;VIS;TCX;PRANDTL;KV;Heatvapz_P" # VISCOSITY 는 100만 나누어야 함.
Prop_index = np.array(Prop_list.replace(';',' ').split())
Prop = []
Value = []
for k in Prop_index: # "P;T;D;H;M;CP;Phase;Qmass;VIS;TCX;PRANDTL;KV;Heatvapz_P"
r = RP.REFPROPdll(Comp_name, Input_prop , k, SI, 0,0, input1, input2, Comp_value)
Prop.append([k,r.hUnits,r.Output[0]])
Value.append(r.Output[0])
DY = Value[2] * Value[11] / (100**2) # Dynamic viscousity
df_prop = pd.DataFrame(Prop, index = Prop_index, columns=['Prop','Units','Values'])
df_prop = df_prop.drop(['Prop'], axis=1)
df_prop.loc['DV'] = ['kg/m-s', DY]
return Value, df_prop # Value, dataframe
# Pipe: ND, Sch, ND_inch, OD, Thickness, Length, ID, Sec_area, Volume, MSG, Surface_area
# Heat: air_vel, fluid_temp, ins_TCX, INS_thk, pipe_TCX, resuslt
def Pipe_heat(Pipe, Heat, Velocity, Prop_air, Prop_fluid ): # Temp. Press. air vel, Diameter(ins out), Dia. inner, Temp. fluid
Vel_air = Heat[0] # m/s
T_air = Prop_air[1] # Temperature
D_air = Prop_air[2] # Density
TCX_air = Prop_air[9]
Pr_air = Prop_air[10]
Vel_flu = Velocity[1] # m/s
Flowrate = Velocity[0] # m3/h
T_flu = Prop_fluid[1] # Temperature
D_flu = Prop_fluid[2] # Density
TCX_flu = Prop_fluid[9]
Pr_flu = Prop_fluid[10]
Phase_flu = Prop_fluid[6]
H_flu = Prop_fluid[3]
Dia_ins_out = (Pipe[3] + Heat[3]*2) / 1000 # m
Dia_in = Pipe[6] / 1000 # ID
Dia_out = Pipe[3] / 1000 # OD
T_flu = Heat[1] # 유체 온도
Length = Pipe[5] / 1000# 배관 길이
TCX_pipe = Heat[4]
TCX_ins = Heat[2]
Vis_air = Prop_air[8]/1000000 # kg/m-s
Vis_flu = Prop_fluid[8]/1000000 # kg/m-s
Reynolds_air = Vel_air * D_air * Dia_ins_out / Vis_air
Reynolds_flu = Vel_flu * D_flu * Dia_in / Vis_flu
# Reynolds 에 따른 coef 두개2로 나누기. turbul, lami
# fluid 의 convective heat tran_coef 도 추가해야할지 고민.
# print(Pipe)
# print(Heat)
# print(Velocity)
# print(Prop_air)
# print(Prop_fluid)
# try:
# raise ValueError("shit")
Conv_heat_coef_air = (TCX_air/1000 / Dia_ins_out) * (0.3 +\
(0.62 * Reynolds_air**(1/2) * Pr_air**(1/3)*(1+(Reynolds_air/282000)**(5/8))**(4/5)) / \
(1+(0.4/Pr_air)**(2/3))**(1/4))
Conv_heat_coef_flu = (TCX_flu/1000 / Dia_in) * (0.3 +\
(0.62 * Reynolds_flu**(1/2) * Pr_air**(1/3)*(1+(Reynolds_flu/282000)**(5/8))**(4/5)) / \
(1+(0.4/Pr_flu)**(2/3))**(1/4))
Heat_leak_pipe = (2 * 3.14 * Length * (T_air-T_flu)) / ((Dia_ins_out*math.log(Dia_out/Dia_in)/TCX_pipe) +\
(Dia_ins_out * math.log(Dia_ins_out/Dia_out)/TCX_ins) +\
(1/Conv_heat_coef_air/(Dia_ins_out/2)) + (1/Conv_heat_coef_flu/(Dia_in/2))) / 1000
h = H_flu + (Heat_leak_pipe*3600 / (Flowrate*D_flu))
MSG = "Complete"
### 현재는 배관내부가 고정온도로 되어 있어서 배관이 길어지면 유입되는 열량이 엄청남.
## 따라서 배관 후단의 온도는 위의 계산으로는 불가능하며, 시간텀이 들어가서 유량이 흐를때 배출되는 유체의 온도를 계산하는걸로 바꾸어야 함.
# except:
# Conv_heat_coef_air = -99999
# Conv_heat_coef_flu = -99999
# Heat_leak_pipe = -99999
# h = -99999
# MSG = "Please check input values"
print(Heat_leak_pipe)
return Heat_leak_pipe, h, MSG, Conv_heat_coef_air, Conv_heat_coef_flu
def Friction(k_list, No_f, Pipe, Velocity, Properties, Roughness, Height): # k값 list, fitting 개수, Pipe 정보
# Pipe 정보 ND, Sch, ND_inch, OD, Thickness, Length, ID, Sec_area, Volume, MSG, Surface_area
# Prop "P;T;D;H;M;CP;Phase;Qmass;VIS;TCX;PRANDTL;KV;Heatvapz_P"
k = k_list
nof = No_f
Vel = float(Velocity)
fit_total_loss = np.sum(k * nof)
Prop = Properties
head_vel = Vel**2 / 2 / 9.81 # head velocity
# reynolds = (Pipe[6]/1000) * Vel * Prop[2] / (Prop[11]/1000**2)
# pipe_fric_coef = 0.25/(math.log10((Roughness / (3.7 * Pipe[6]))+(5.74 / reynolds**0.9)))**2
# pipe_loss = pipe_fric_coef * Pipe[5]/1000 / (Pipe[6]/1000) * head_vel
try:
reynolds = (Pipe[6]/1000) * Vel * Prop[2] / (Prop[11]/1000**2)
except ZeroDivisionError:
reynolds = 0
try:
pipe_fric_coef = 0.25/(math.log10((Roughness / (3.7 * Pipe[6]))+(5.74 / reynolds**0.9)))**2
except ZeroDivisionError:
pipe_fric_coef = 0
try:
pipe_loss = pipe_fric_coef * Pipe[5]/1000 / (Pipe[6]/1000) * head_vel
except ZeroDivisionError:
pipe_loss = 0
fit_loss = fit_total_loss * head_vel
total_loss_m = Height + pipe_loss + fit_loss
total_loss_pressure = total_loss_m * Prop[2] * 9.81 / 100000 #barg
return fit_total_loss, head_vel, reynolds, pipe_fric_coef, pipe_loss, fit_loss, total_loss_m, total_loss_pressure
UI connector
Pipe_Engineer_rev3.ui -> .py
...
Background.py