Open JungHulk opened 2 years ago
( (ht_air surface_area) (T_vap - T_pri) + ht_NG surface_area (T_coffer - T2)) dt - Mass_ins Cp_ins T_ins_var) / (Mass_pri Cp_pri)
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;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
`# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
"""
22. 03. 17
"""
import os, numpy as np
import math
import matplotlib.pyplot as plt
from win32com.client import Dispatch
import pandas as pd
import numpy as np
# from scipy import integrate
import pickle
import csv
import openpyxl
import sys
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary
import scipy.integrate as int
RP = REFPROPFunctionLibrary(os.environ['RPPREFIX'])
RP.SETPATHdll(os.environ['RPPREFIX'])
SI = RP.GETENUMdll(0,"SI WITH C").iEnum
# Property = "P;T;D;H;M;CP;Phase;Qmass"
# Prop_list = "P;T;D;H;M;CP;Phase;Qmass;VIS;TCX;PRANDTL;KV;Heatvapz_P"
# Property_total = "T;P;D;H;CP;Phase;Qmass;"
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())
# df1 = pd.read_pickle('Pipetable.p')
'''''''''''''''''''''''''''
Initial Condition
'''''''''''''''''''''''''''
Comp_name = "Nitrogen;Methane;Ethane;Propane;Butane;Isobutane;Pentane;Isopentane;Oxygen;CO2;Water"
Comp_init = np.array([0.0, 100.0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
T_atm = 45 # C
P_init = 0.11 # Mpa
Volume = 14012 # m3
Surface = 3365 # m2
Filling = 98 # %
Vol_liq = Volume * Filling/100
Vol_vap = Volume - Vol_liq
'''''''''''''''''''''''''''
Equilibrium Mode
'''''''''''''''''''''''''''
Qmass = 0.00010902809999999928 # initial value
Step = 0.01
LastStep = 0.000000000001
Target = 0
direction = 0
D_tank = RP.REFPROPdll(Comp_name,"PQmass","D",SI,0,0,P_init,Qmass,Comp_init).Output[0]
D_liq = RP.REFPROPdll(Comp_name,"PQmass","Dliq",SI,0,0,P_init,Qmass,Comp_init).Output[0]
D_vap = RP.REFPROPdll(Comp_name,"PQmass","Dvap",SI,0,0,P_init,Qmass,Comp_init).Output[0]
Mass_tank = Volume * D_tank
Mass_liq = Vol_liq * D_liq
Mass_vap = Vol_vap * D_vap
Mass_conv = Mass_tank - Mass_liq - Mass_vap # 질량보존 확인항
if Mass_conv < Target:
direction = 1
else:
direction = -1
if Mass_conv == Target:
sys.exit(0) # sys.exit(0) 프로그램 정상 종료, (1) 강제 종료
if Filling == 0:
# Qmass = 1
T_vap = T_atm
T_lng = T_atm
T_liq = T_atm
T_wall = T_atm
T_ins = T_atm
# Filling 이 0일때 property, compostion 계산하는 항 만들기.
else:
for i in range(1,10000,1):
Qmass = Qmass + Step * direction
if Mass_conv < Target:
if direction == 1:
if Step > LastStep:
Step = Step / 10
direction = direction * -1
# else:
# exit()
else:
if direction == -1:
if Step > LastStep:
Step = Step / 10
direction = direction * -1
# else:
# exit()
if Step < LastStep:
break
D_tank = RP.REFPROPdll(Comp_name,"PQmass","D",SI,0,0,P_init,Qmass,Comp_init).Output[0]
D_liq = RP.REFPROPdll(Comp_name,"PQmass","Dliq",SI,0,0,P_init,Qmass,Comp_init).Output[0]
D_vap = RP.REFPROPdll(Comp_name,"PQmass","Dvap",SI,0,0,P_init,Qmass,Comp_init).Output[0]
Mass_tank = Volume * D_tank
Mass_liq = Vol_liq * D_liq
Mass_vap = Vol_vap * D_vap
# pri``nt (Mass_tank, Mass_liq, Mass_vap, D_liq, D_tank, D_vap)
Mass_conv = Mass_tank-Mass_liq-Mass_vap
# print (Qmass)
Comp_liq_mole = np.array(RP.REFPROPdll(Comp_name,"PQmass","xmoleliq",SI,0,0,P_init,Qmass,Comp_init).Output[0:Comp_name.count(';')])
Comp_vap_mole = np.array(RP.REFPROPdll(Comp_name,"PQmass","xmolevap",SI,0,0,P_init,Qmass,Comp_init).Output[0:Comp_name.count(';')])
Pro_lng_mole = np.array(RP.REFPROPdll(Comp_name,"PQmass",Prop_list,SI,0,0,P_init,0,Comp_init).Output[0:Prop_list.count(';')])
Pro_liq_mole = np.array(RP.REFPROPdll(Comp_name,"Pliq",Prop_list,SI,0,0,P_init,0,Comp_liq_mole).Output[0:Prop_list.count(';')])
Pro_vap_mole = np.array(RP.REFPROPdll(Comp_name,"Pvap",Prop_list,SI,0,0,P_init,0,Comp_vap_mole).Output[0:Prop_list.count(';')])
T_vap = Pro_vap_mole[0]
T_wall = T_vap # 초기 조건
ht_NG = 20.93 # kJ/h/m2/C
ht_atm = 10.47 # kJ/h/m2/C
'''''''''''''''''''''''''''
Select Mode
'''''''''''''''''''''''''''
Mode_list = ['Inerting', 'Inerting_N', 'Gassing-up', 'Cool-down', 'Cool-down_N', 'Warm-up', 'Warm-up_N', 'Aeration']
Mode_pressure = "Constant" # Constant, Variable
'''''''''''''''''''''''''''
Insulation information
'''''''''''''''''''''''''''
M_wall = 383849 # kg
Cp_wall = 0.46 # kJ/kg/C
T_wall = Pro_lng_mole[0] # C
M_ins = 1891303 # kg
Cp_ins = 1.07 # kJ/kg/C
D_ins = 190 # kg/m3
Cond_ins = 0.0963 # kJ/h/m/C
Ins_thick = 270 # mm
'''''''''''''''''''''''''''''''''''''''
Insulation Initial condition
'''''''''''''''''''''''''''''''''''''''
n = 12 # Insulation node 수
len_interval = Ins_thick/1000 / n # Node 별 거리
T2 = (T_wall + (ht_atm * Ins_thick/1000/Cond_ins)*T_atm) / (1+(ht_atm*Ins_thick /1000/Cond_ins))
#Ins Outer temp.
T_ins_step = (T2 - T_wall) / (Ins_thick/1000/len_interval) # ins del_T
# step_node = np.arange(start = 0, stop = Ins_thick/1000 + 0.0000001, step = Ins_thick/n/1000)
T_ins = np.zeros((1,n+1))
# Insulation 초기온도 조건
if T_ins_step == 0:
T_ins = np.full((1,n+1), T_ins)
else:
T_ins = np.linspace(T_wall, T2, n+1)
T_ins = T_ins.T
# df_Tins = pd.DataFrame(T_ins, columns =step_node) # Column을 step_node 로
#df_ins = df_ins.rename(columns=df_ins.iloc[0]) # 첫 행을 columns name 으로
dt_ins = 0
diffusivity = Cond_ins / (Cp_ins * D_ins)
# 제공 초기조건
Input_prop = "PQmass" # 2가지 고르기 (input에서)
Input1 = 0.2 # MPaA Input 1 값
Input2 = 0 # Input 2 값
# Supply 조건 지정.
# ### BOR check 하는 function 만들기
time = 12 # hours
t_step = 0.01 # hour
def Properties(Comp_name, Comp_value, Input_prop, input1, input2):
Prop = []
Value = []
for k in Prop_index: # P;T;D;H;M;CP;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
# Mode_list = ['Inerting', 'Inerting_N', 'Gassing-up', 'Cool-down', 'Cool-down_N', 'Warm-up', 'Warm-up_N', 'Aeration']
def Supply_condition(Comp_name, Mode_operation, Input_prop, Input1, Input2):
if Mode_operation == Mode_list[0]:
Comp_supply = np.array([85.0, 0, 0, 0, 0, 0, 0, 0, 1, 14, 0])
elif Mode_operation == Mode_list[1] or Mode_operation == Mode_list[4] or Mode_operation == Mode_list[6]:
Comp_supply = np.array([100.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
elif Mode_operation == Mode_list[2] or Mode_operation == Mode_list[3] or Mode_operation == Mode_list[5]:
Comp_supply = Comp_init
else: # Aeration
Comp_supply = np.array([78.0, 0, 0, 0, 0, 0, 0, 0, 21, 1, 0])
Value = Properties(Comp_name, Comp_supply, Input_prop, Input1, Input2)[0]
return Comp_supply, Value
#### 우선 압력 고정일 때,
## Mass_supply 를 dt 에 대한 배열로 입력하는것도 고려해보기
def Heat_transfer(Comp_tank, Comp_supply, Mass_supply, P_mode):
dh = (-1 * (Mass_supply * (h - h_supply) + ht_NG * Surface * (T_vap - T_wall)) * dt) / Mass_tank
dT_wall = ((ht_NG * Surface * (T_vap - T_wall) + ht_atm * Surface_area * (T_atm - T2)) * dt - M_ins * Cp_ins* T_ins_var) / (M_wall * Cp_wall)
h = h + dh
T_wall = T_wall + dT_wall
Mass_exhaust_init = 100 # 100 kg/h
# 아래 항을 mole 로 바로 계산할 수 있으면 좋을텐데? Comp_init 은 mass base
# Comp = (Comp_init * Tank_mass + Comp_supply * Mass_supply * dt) / (Tank_mass)
Comp = list(map(lambda x, y: (x * Mass_tank + y * Mass_supply * dt) / (Mass_tank + Mass_supply*dt), Comp, Comp_supply))
# 압력항에 대한 것도 같이 넣어줘야 할것 같음.
if P_mode == 0: # 0: Const, 1: Various
d = RP.REFPROPdll(Comp_name, "PH" , "D", SI, 0,0, P_init, h, Comp).Output[0]
else:
d = D_tank
# Mass_conv = Mass_supply * dt + Mass_tank - Mass_exhaust
Mass_tank = Volume * d
# for i in len()
# ins_T[i] = Thermal diffusivity x dt / Interval length * (ins 거리0 - ins 거리2) + (1- 2 x (Thermal diffusivity x dt / Interval length **2)) x Ins 거리 1
# for i in range (0,12/3600+t_step,t_step):
Supply = Supply_condition(Comp_name, Mode_list[1], Input_prop, Input1, Input2)
Prop = Properties(Comp_name, Comp_init, "PT", 0.12, 0)
`
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
"""
22. 06. 27
"""
import os, numpy as np
import math
import matplotlib.pyplot as plt
from win32com.client import Dispatch
import pandas as pd
import numpy as np
# from scipy import integrate
import pickle
import csv
import openpyxl
import sys
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary
from scipy import integrate
RP = REFPROPFunctionLibrary(os.environ['RPPREFIX'])
RP.SETPATHdll(os.environ['RPPREFIX'])
SI = RP.GETENUMdll(0,"SI WITH C").iEnum
# Property = "P;T;D;H;M;CP;Phase;Qmass"
# Prop_list = "P;T;D;H;M;CP;Phase;Qmass;VIS;TCX;PRANDTL;KV;Heatvapz_P"
# Property_total = "T;P;D;H;CP;Phase;Qmass;"
Prop_list = "P;T;D;H;M;CP;Qmass;VIS;TCX;PRANDTL;KV;Heatvapz_P;Phase;" # VISCOSITY 는 100만 나누어야 함.
Prop_index = np.array(Prop_list.replace(';',' ').split())
# df1 = pd.read_pickle('Pipetable.p')
'''''''''''''''''''''''''''
Initial Condition
'''''''''''''''''''''''''''
Comp_name = "Nitrogen;Methane;Ethane;Propane;Butane;Isobutane;Pentane;Isopentane;Oxygen;CO2;Water"
Comp_init = np.array([0.0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
# Comp_init = np.array([0.0079, 0.9205, 0.0547, 0.0133, 0.0037, 0, 0, 0, 0, 0]) # Mass base
T_atm = 40 # C
P_init = 0.13 # Mpa
T_set_vapor = 40
Volume = 18000 # m3
Surface = 4200 # m2
Filling = 0 # %
Vol_liq = Volume * Filling/100
Vol_vap = Volume - Vol_liq
'''''''''''''''''''''''''''''
Insulation information
'''''''''''''''''''''''''''''
M_wall = 60205 # kg
Cp_wall = 0.35 # kJ/kg/C
# T_wall = T_vap # 초기 조건
M_ins = 424071 # kg
Cp_ins = 1.07 # kJ/kg/C
D_ins = 118 # kg/m3
Cond_ins = 0.08 # kJ/h/m/C
Ins_thick = 400 # mm
ht_NG = 37.46 # kJ/h/m2/C
ht_atm = 16.8 # kJ/h/m2/C
'''''''''''''''''''''''''''
Equilibrium Mode
'''''''''''''''''''''''''''
# Qmass = 0.1 # initial value funcion 에 기입
Step = 0.01
LastStep = 0.000000000001
Target = 0.001
# direction = 0
'''''''''''''''''''''''''''
Plot
'''''''''''''''''''''''''''
x_axis = []
y_axis = []
y_axis2 = []
y_axis3 = []
##############################################################
####################### Definition ###########################
##############################################################
# Mode_list = ['Inerting', 'Inerting_N', 'Gassing-up', 'Cool-down', 'Cool-down_N', 'Warm-up', 'Warm-up_N', 'Aeration']
# Input_prop = 'PT', 'PH' 등등
def Supply_condition(Comp_name, Mode_operation, Input_prop, Input1, Input2, Mass_supply, Calculation):
if Mode_operation == Mode_list[0]:
Comp_supply = np.array([0.85, 0, 0, 0, 0, 0, 0, 0, 0.01, 0.14, 0])
elif Mode_operation == Mode_list[1] or Mode_operation == Mode_list[4] or Mode_operation == Mode_list[6]:
Comp_supply = np.array([1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
elif Mode_operation == Mode_list[2] or Mode_operation == Mode_list[3] or Mode_operation == Mode_list[5]:
Comp_supply = Comp_init
else: # Aeration
Comp_supply = np.array([0.78, 0, 0, 0, 0, 0, 0, 0, 0.21, 0.01, 0])
Value = Properties(Comp_name, Comp_supply, Input_prop, Input1, Input2)[0]
Volume_supply = Mass_supply / Value[2]
## Supply ramp-up
Cal_time = Calculation
Supply_mass = np.full(Cal_time, Mass_supply)
for i in range (11):
if i < 6:
Supply_mass[i] = 1/(10-i) * Mass_supply
else:
Supply_mass[i] = (i-5) / 5 * Mass_supply
return Comp_supply, Value, Supply_mass, Volume_supply, Mode_operation
def Properties(Comp_name, Comp_value, Input_prop, input1, input2):
Prop = []
Value = []
for k in Prop_index: # P;T;D;H;M;CP;Qmass;VIS;TCX;PRANDTL;KV;Heatvapz_P;Phase;
r = RP.REFPROPdll(Comp_name, Input_prop, k, SI, 1, 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
def Init_condition(Comp_name, Comp_init, P_init, Surface, Filling, Vol_liq, Vol_vap, Step, LastStep, Target):
Qmass = 0.1 # Initial Qmass
direction = 0 # Try and Error Initial direction
D_tank = RP.REFPROPdll(Comp_name,"PQmass","D",SI,1,0,P_init,Qmass,Comp_init).Output[0]
D_liq = RP.REFPROPdll(Comp_name,"PQmass","Dliq",SI,1,0,P_init,Qmass,Comp_init).Output[0]
D_vap = RP.REFPROPdll(Comp_name,"PQmass","Dvap",SI,1,0,P_init,Qmass,Comp_init).Output[0]
# (hFld, hIn, hOut, iUnits, iMass, iFlag, a, b, z, Output, hUnits, iUCode, x, y, x3, q, ierr, herr, hFld_length, hIn_length, hOut_length, hUnits_length, herr_length)
Mass_tank = Volume * D_tank
Mass_liq = Vol_liq * D_liq
Mass_vap = Vol_vap * D_vap
Mass_conv = Mass_tank - Mass_liq - Mass_vap # 질량보존 확인항
if Mass_conv < Target:
direction = 1
else:
direction = -1
if Mass_conv == Target:
sys.exit(0) # sys.exit(0) 프로그램 정상 종료, (1) 강제 종료
if Filling == 0:
Comp_liq_mass = np.array(RP.REFPROPdll(Comp_name,"PT","xmassliq",SI,1,0,P_init,T_set_vapor,Comp_init).Output[0:Comp_name.count(';')])
Comp_vap_mass = np.array(RP.REFPROPdll(Comp_name,"PT","xmassvap",SI,1,0,P_init,T_set_vapor,Comp_init).Output[0:Comp_name.count(';')])
Pro_init_mass = np.array(Properties(Comp_name, Comp_init, "PT", P_init, T_set_vapor)[0])
Pro_liq_mass = Pro_init_mass
Pro_vap_mass = Pro_init_mass
Phase = RP.REFPROPdll(Comp_name,"PT","Phase",SI,1,0,P_init,T_set_vapor,Comp_init).hUnits
else:
for i in range(1,10000,1):
Qmass = Qmass + Step * direction
if Mass_conv < Target:
### Qmass 가 음수가 되는 경우 피하기 위한 함수
if Qmass < 0:
if direction == -1:
if Step > LastStep:
Step = Step / 10
direction = 1
##############################################
elif direction == 1:
if Step > LastStep:
Step = Step / 10
direction = direction * -1
else:
if direction == -1:
if Step > LastStep:
Step = Step / 10
direction = direction * -1
if Step < LastStep:
break
# print(Qmass, Mass_conv, D_tank, D_liq, D_vap)
D_tank = RP.REFPROPdll(Comp_name,"PQmass","D",SI,1,0,P_init,Qmass,Comp_init).Output[0]
D_liq = RP.REFPROPdll(Comp_name,"PQmass","Dliq",SI,1,0,P_init,Qmass,Comp_init).Output[0]
D_vap = RP.REFPROPdll(Comp_name,"PQmass","Dvap",SI,1,0,P_init,Qmass,Comp_init).Output[0]
Mass_tank = Volume * D_tank
Mass_liq = Vol_liq * D_liq
Mass_vap = Vol_vap * D_vap
Mass_conv = Mass_tank-Mass_liq-Mass_vap
Comp_liq_mass = np.array(RP.REFPROPdll(Comp_name,"PQmass","xmassliq",SI,1,0,P_init,Qmass,Comp_init).Output[0:Comp_name.count(';')])
Comp_vap_mass = np.array(RP.REFPROPdll(Comp_name,"PQmass","xmassvap",SI,1,0,P_init,Qmass,Comp_init).Output[0:Comp_name.count(';')])
Pro_init_mass = np.array(Properties(Comp_name, Comp_init, "PQmass", P_init, Qmass)[0])
Pro_liq_mass = np.array(Properties(Comp_name, Comp_liq_mass, "PQmass", P_init, 0)[0])
Pro_vap_mass = np.array(Properties(Comp_name, Comp_vap_mass, "PQmass", P_init, 1)[0])
Phase = RP.REFPROPdll(Comp_name,"PQmass","Phase",SI,1,0,P_init,Qmass,Comp_init).hUnits
return Comp_liq_mass, Comp_vap_mass, Pro_init_mass, Pro_liq_mass, Pro_vap_mass, Phase
T_vap = Init_condition(Comp_name, Comp_init, P_init, Surface, Filling, Vol_liq, Vol_vap, Step, LastStep, Target)[4][1]
T_lng = Init_condition(Comp_name, Comp_init, P_init, Surface, Filling, Vol_liq, Vol_vap, Step, LastStep, Target)[2][1]
T_liq = Init_condition(Comp_name, Comp_init, P_init, Surface, Filling, Vol_liq, Vol_vap, Step, LastStep, Target)[3][1]
T_wall = T_vap
Mass_tank = Volume * Init_condition(Comp_name, Comp_init, P_init, Surface, Filling, Vol_liq, Vol_vap, Step, LastStep, Target)[2][2]
Mass_liq = Volume * Init_condition(Comp_name, Comp_init, P_init, Surface, Filling, Vol_liq, Vol_vap, Step, LastStep, Target)[3][2]
Mass_vap = Volume * Init_condition(Comp_name, Comp_init, P_init, Surface, Filling, Vol_liq, Vol_vap, Step, LastStep, Target)[4][2]
'''''''''''''''''''''''''''
Select Mode
'''''''''''''''''''''''''''
Mode_list = ['Inerting', 'Inerting_N', 'Gassing-up', 'Cool-down', 'Cool-down_N', 'Warm-up', 'Warm-up_N', 'Aeration']
Mode_pressure = "Constant" # Constant, Variable
'''''''''''''''''''''''''''''''''''''''
Insulation Initial condition
'''''''''''''''''''''''''''''''''''''''
n = 12 # Insulation node 수
Ins_interval = Ins_thick/1000 / n # Node 별 거리
Ins_node = np.arange(0,Ins_thick/1000+Ins_interval,Ins_interval) # Insulation 각 위치
T2 = (T_wall + (ht_atm * Ins_thick/1000/Cond_ins)*T_atm) / (1+(ht_atm*Ins_thick /1000/Cond_ins))
#Ins Outer temp.
T_ins_step = (T2 - T_wall) / (Ins_thick/1000/Ins_interval) # ins del_T
# step_node = np.arange(start = 0, stop = Ins_thick/1000 + 0.0000001, step = Ins_thick/n/1000)
T_ins = np.zeros(n+1)
# Insulation 초기온도 조건
if T_ins_step == 0:
T_ins = np.full(n+1, T_wall)
else:
T_ins = np.linspace(T_wall, T2, n+1)
# T_ins = T_ins.T
def simpson(array, n): # simpson's rule
integration = array[0] + array[-1]
for i in range(1,n):
if i%2 ==0:
integration = integration + 2*array[i]
else:
integration = integration + 4*array[i]
integration = integration / (len(array)-1) /3
return integration
T_ins_ave = simpson(T_ins,n)
# df_Tins = pd.DataFrame(T_ins, columns =step_node) # Column을 step_node 로
#df_ins = df_ins.rename(columns=df_ins.iloc[0]) # 첫 행을 columns name 으로
dt_ins = 0
diffusivity = Cond_ins / (Cp_ins * D_ins)
## 제어기? 혹은 기준설정 후 자동으로 종료되게 만들기
# def Operation_criteria(Mode_list, Operation, Temperature, Composition):
# ### [0] Inerting
# ### [1] Inerting_N
# ### [2] Gassing-up
# ### [3] Cool-down
# ### [4] Cool-down_N
# ### [5] Warm-up
# ### [6] Warm-up_N
# ### [7] Aeration
# Operation = Mode_list
# if Operation.find("Cool") is not -1:
# if Temperature < -140:
# break
# elif Operation.find("Inert") is not -1:
# if Composition < 0.02:
# break
def Heat_transfer(Supply_condition, Init_cond, P_mode, T_ins, T_ins_ave, Ins_node):
#################### Initial Calculation condition
Init_cond = Init_condition(Comp_name, Comp_init, P_init, Surface, Filling, Vol_liq, Vol_vap, Step, LastStep, Target)
T_vap = Init_cond[4][1]
h = Init_cond[4][3]
d = Init_cond[4][2]
Phase = Init_cond[5]
Qmass = Init_cond[2][6]
Comp = Comp_init
Comp_liq = Init_cond[0]
Comp_vap = Init_cond[1]
Supply = Supply_condition
T_wall = T_vap
Mass_tank = Volume * Init_cond[2][2]
T_ins_var = 0
T_ins = T_ins
Ins_node = Ins_node
T_ins_temp = np.zeros(len(T_ins))
################### Data save #############################################
T_ins_table = np.append(T_ins,T_ins_ave)
# print(T_ins_table)
Prop_table = np.array([P_init, T_vap, T_wall, d, h, Mass_tank, Phase, Qmass])
Comp_table = np.array([Comp_init, Comp_liq, Comp_vap])
# print(Comp_table)
for i in range (Calculation):
# if Operation == "Cool-down":
# if T_vap < -140:
# break
# elif Operation == "Cool-down":
dh = (-1 * (Supply[2][i] * (h - Supply[1][3]) + ht_NG * Surface * (T_vap - T_wall)) * dt) / Mass_tank
dT_wall = ((ht_NG * Surface * (T_vap - T_wall) + ht_atm * Surface * (T_atm - T2)) * dt - M_ins * Cp_ins* T_ins_var) / (M_wall * Cp_wall)
# h = float(int((h + dh)*1000)/1000)
h = h + dh
T_wall = T_wall + dT_wall
Mass_exhaust_init = 100 # 100 kg/h
# 아래 항을 mole 로 바로 계산할 수 있으면 좋을텐데? Comp_init 은 mass base
# Comp = (Comp_init * Tank_mass + Comp_supply * Mass_supply * dt) / (Tank_mass)
Comp = list(map(lambda x, y: (x * Mass_tank + y * Supply[2][i] * dt) / (Mass_tank + Supply[2][i]*dt), Comp, Supply[0]))
# Comp = np.array(Comp)
# 압력항에 대한 것도 같이 넣어줘야 할것 같음.
if P_mode == 0: # 0: Const, 1: Various
d = RP.REFPROPdll(Comp_name, "PH" , "D", SI, 1, 0, P_init, h, Comp).Output[0]
Mass_tank = Volume * d
P = P_init
else:
Mass_tank = Mass_tank + Supply[2][i]*dt
d = Mass_tank / Volume
P = RP.REFPROPdll(Comp_name, "DH" , "P", SI, 1, 0, d, h, Comp).Output[0]
# Prop = Properties(Comp_name, Comp, "DH", d, h)[0]
# Prop = np.array(RP.REFPROPdll(Comp_name,"DH",Prop_list,SI,1,0,d,h,Comp).Output[0:Prop_list.count(';')])
T_vap = np.array(RP.REFPROPdll(Comp_name,"DH","T",SI,1,0,d,h,Comp).Output[0])
Qmass = np.array(RP.REFPROPdll(Comp_name,"DH","Qmass",SI,1,0,d,h,Comp).Output[0])
Phase = np.array(RP.REFPROPdll(Comp_name,"DH","Phase",SI,1,0,d,h,Comp).hUnits)
print(i*dt, dh, T_vap, T_wall)
Comp_liq_mass = np.array(RP.REFPROPdll(Comp_name,"DH","xmassliq",SI,1,0,P_init,Qmass,Comp).Output[0:Comp_name.count(';')])
Comp_vap_mass = np.array(RP.REFPROPdll(Comp_name,"DH","xmassvap",SI,1,0,P_init,Qmass,Comp).Output[0:Comp_name.count(';')])
Comp_table = np.vstack([Comp_table, [Comp, Comp_liq, Comp_vap]])
# Prop_table = np.array([P, Prop[1], d, h, T_wall, Mass_tank, Comp])
for j in range (len(T_ins)-2):
k = j+1
T_ins_temp[0] = T_wall
T_ins_temp[k] = diffusivity * dt / Ins_interval**2 * (T_ins[j] + T_ins[j+2]) + (1- 2* (diffusivity * dt / Ins_interval**2)) * T_ins[j+1]
T_ins_temp[len(T_ins)-1] = Cond_ins/ ht_atm * (T_ins[len(T_ins)-2] - T_ins[len(T_ins)-1]) / (Ins_node[len(T_ins)-1] - Ins_node[len(T_ins)-2]) + T_atm
T_ins_temp_ave = simpson(T_ins_temp,len(T_ins)-1)
T_ins_temp_table = np.append(T_ins_temp, T_ins_temp_ave)
T_ins_table = np.vstack([T_ins_table, T_ins_temp_table]) # Time step 별 Insul node 별 테이블화
# Prop_table = np.array([P_init, T_vap, T_wall, d, h, Mass_tank, Phase, Qmass])
Prop_tank = np.array([P, T_vap, T_wall, d, h, Mass_tank, Phase, Qmass])
Prop_table = np.vstack([Prop_table, Prop_tank])
T_ins_var = T_ins_temp_ave - T_ins_ave
# print(T_ins_temp_ave, T_ins_ave, T_ins_var)
T_ins = T_ins_temp
T_ins_ave = T_ins_temp_ave
################################ Plot ###########################################
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot()
x_axis.append(i * dt)
y_axis.append(T_vap)
y_axis2.append(T_wall)
y_axis3.append(T_ins_ave)
ax.plot(x_axis,y_axis, color = 'b', linewidth = 4.0)
ax.plot(x_axis,y_axis2, color = 'r', linewidth = 4.0)
ax.plot(x_axis,y_axis3, color = 'green', linewidth = 4.0)
ax.patch.set_facecolor('#c6d9f1') # axes 배경색
# plt.setp(line, color = 'b', linewidth = 4.0)
plt.xlabel('Time (hr)', size=15)
plt.ylabel('Temperature (C)', size=15)
# plt.rc('axes', labelsize = 70)
plt.xlim(0,)
plt.ylim(-180,40)
plt.grid(True)
plt.show()
return Prop_table, T_ins_table, Comp_table
# Exhaust vapor 계산하기
# Mass_conv = Mass_supply * dt + Mass_tank - Mass_exhaust
# for i in (len(T_ins)-1):
# k = i+1
# T_ins_temp[i] = T_wall
# T_ins_temp[k] = diffusivity * dt / Ins_interval**2 * (T_ins[i] + T_ins[i+2]) + (1- 2* (diffusivity * dt / Ins_interval**2)) * T_ins[i+1]
# for i in range (0,12/3600+t_step,t_step):
# Prop = Properties(Comp_name, Comp_init, "PT", 0.12, 0)
"""""""""""""""""""""""
Calculation
"""""""""""""""""""""""
# Supply 조건 지정.
Input_prop = "PQmass" # 2가지 고르기 (input에서)
Input1 = 0.2 # MPaA Input 1 값
Input2 = 0 # Input 2 값
# ### BOR check 하는 function 만들기
time = 17 # hours
dt = 0.05 # hour
Calculation = round(time / dt)
Mass_supply = 2800 ## kg/h
# time_range = np.arange(dt, time + dt, dt)
#### 우선 압력 고정일 때,
## Mass_supply 를 dt 에 대한 배열로 입력하는것도 고려해보기
### Mode_list = ['Inerting', 'Inerting_N', 'Gassing-up', 'Cool-down', 'Cool-down_N', 'Warm-up', 'Warm-up_N', 'Aeration']
Operation = Mode_list[3]
Supply = Supply_condition(Comp_name, Operation, "PQmass", 0.128, 0, Mass_supply, Calculation)
Init_cond = Init_condition(Comp_name, Comp_init, P_init, Surface, Filling, Vol_liq, Vol_vap, Step, LastStep, Target)
# Heat_transfer(Supply_condition, Init_cond, Mass_supply, P_mode, T_ins, T_ins_ave, Ins_node):
## 계산 Heat_transfer(Supply, Init_cond, 0, T_ins, T_ins_ave, Ins_node)
Cooldown = Heat_transfer(Supply, Init_cond, 0, T_ins, T_ins_ave, Ins_node)
-- coding: utf-8 --
""" Spyder Editor
This is a temporary script file. """