-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tank_operation #3
Comments
information of vessel. Calling the Class for operation. -- coding: utf-8 --""" @author: 252914 class Cargo_tank():
|
-- coding: utf-8 --""" @author: 252914 -- coding: utf-8 --"""
""" import os, numpy as np from scipy import integrateimport pickle RP = REFPROPFunctionLibrary(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만 나누어야 함. df1 = pd.read_pickle('Pipetable.p')def Heat_transfer(Supply_condition, Init_cond, P_mode, T_ins, T_ins_ave, Ins_node, dt, T_wall):
for i in range (0,12/3600+t_step,t_step):def Supply_condition(Comp_name, Mode_operation, Input_prop, Input1, Input2, Mass_supply, Calculation): 0 'Inerting', 1'Inerting_N', 2'Gassing-up', 3'Cool-down', 4'Cool-down_N', 5'Warm-up', 6'Warm-up_N', 7'Aeration', 8'Hold']
def Properties(Comp_name, Comp_value, Input_prop, input1, input2):
def Init_condition(Comp_name, Comp_init, P_init, Filling, Step, LastStep, Target):
(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)
def Unitconv_nominal(Comp_name, Comp, P, T, iflag, Value): # iflag 0: Nominal flowrate, 1: Volumetric flowrate, 2 : Mass flowrate
def BOG_calculation(Tank_volume, Filling_Ratio, BOR, Comp_name, Comp_LNG, U, Area, T_vap, T_atm): # methane, LNG, Revised_BOR
def BOR_check(BOG, Comp_name, Comp_init, P_init, Filling, Step, LastStep, Target, Mode_list, Sim_time):Init_cond = Init_condition(Comp_name, Comp_init, P_init, Filling, Step, LastStep, Target)Operation = Mode_list[6]Supply = Supply_condition(Comp_name, Operation, "PT", 0.11, 60, 0, Sim_time)Hold = Heat_transfer(Supply, Init_cond, 0, T_ins, T_ins_ave, Ins_node, dt)Exhaust = Hold[0][9]
''''''''''''''''''''''''''' Comp_init = np.array([0.0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])Pure_methane = 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 Volume = Tank.Vol_tank # m3 FR = Tank.FR M_ins = Tank.M_ins # kg Cond_ins = Tank.Cond_ins # kJ/h/m/C ht_NG = Tank.ht_NG # kJ/h/m2/C U = Tank.U Qmass = 0.1 # initial value funcion 에 기입Step = 0.2 direction = 0''''''''''''''''''''''''''' x2_axis = [] filenames = [] ############################################################## Input_prop = 'PT', 'PH' 등등Init_cond = Init_condition(Comp_name, Comp_init, P_init, Filling, Step, LastStep, Target) T_vap = Init_cond[4][1] Mass_tank = Volume * Init_cond[2][2] ''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''' #Ins Outer temp. Insulation secondary barrier 위치 정하기Ins_sec = Tank.sec Insulation 초기온도 조건if T_ins_step == 0: def simpson(array, n): # simpson's rule
T_ins_ave = simpson(T_ins,n) dt_ins = 0 diffusivity = Cond_ins / (Cp_ins * D_ins) """"""""""""""""""""""" Supply_condition(Comp_name, Mode_operation, Input_prop, Input1, Input2, Mass_supply, Calculation):Zero = Supply_condition(Comp_name, Operation, "PQmass", 0.13, 0, Mass_supply, Calculation) Check = BOG_calculation(Volume, FR, BOR, Comp_name, Comp_init, U, Surface, T_vap, T_atm) return BOG_methane, BOG_LNG, Revised_BORHold = Heat_transfer(Zero, Init_cond, 1, T_ins, T_ins_ave, Ins_node, dt, T_wall)"""""""""""""""""""""""추출 하기"""""""""""""""""""""""##pd.set_option('display.float_format', '{:,.4f}'.format) 다 안먹힘## pd.options.display.float_format = '{:.4f}'.format## df.style.set_precision(4) # DataFrameProp_col_name = ['Time', 'Tank Pressure', 'T_vap', 'T_wall', 'Density', 'Enthalpy', 'Mass_tank','Phase', 'Qmass', 'Mass_exhaust', 'Vol_exhaust', 'Amount_supply']Ins_col_name = np.round(Ins_node.astype(np.float64),4) # Node 소수점이 4개 고정위해서 float64로 변환Ins_col_name = Ins_col_name.tolist()Ins_col_name.append('Ins_ave')Ins_col_name.append('Ins_secondary')df = pd.DataFrame(Hold[0], columns = Prop_col_name)###Time 열 분리Index_time = df['Time']df_unit = pd.DataFrame({'Time': ['hr'],'Tank Pressure': ['MPaA'], 'T_vap': ['C'], 'T_wall': ['C'], 'Density': ['kg/m3'], 'Enthalpy': ['kJ/kg'],'Mass_tank': ['kg'], 'Phase': ['-'], 'Qmass': ['-'], 'Mass_exhaust': ['kg/hr'], 'Vol_exhaust': ['m3/hr'],'Amount_supply': ['kg']},index=['Units'])df = pd.concat([df_unit, df])df.set_index('Time', inplace = True)df_ins = pd.DataFrame(Hold[1], columns = Ins_col_name, index = Index_time)df_ins.style.set_precision(4) # DataFramedf_comp = pd.DataFrame(np.round(Hold[2],4), columns = Comp_name_index, index = Index_time)"""""""""""""""""""""""출력 하기"""""""""""""""""""""""address = 'C:\Python_code\04_Tank model\Tank_result\'df.to_csv(address+'Prop.csv', header = True, index= True)df_comp.to_csv(address+'Comp.csv', header = True, index= True)df_ins.to_csv(address+'Insulation.csv', header = True, index= True)GIF 만들기duration_rate = 0.01 # 속도frames_plot = []for plotname in plotnames:if plotname.endswith(".png"):# print(plotname)frames_plot.append(imageio.imread(plotname))exportname = "Plot.gif"imageio.mimsave(exportname, frames_plot, format='GIF', duration=duration_rate, loop=1) # loop = 0 무한대for plotname in set(plotnames):os.remove(plotname) |
-- coding: utf-8 --
"""
22. 06. 27
"""
import os, numpy as np
import math
import imageio
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
import Tank_information as T
import time
Tank = T.Cargo_tank()
seconds = 3
while seconds > 0:
print("Check Model :", seconds, "sec")
time.sleep(0.5)
seconds = seconds - 1
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')
def Heat_transfer(Supply_condition, Init_cond, P_mode, T_ins, T_ins_ave, Ins_node, dt):
for i in range (0,12/3600+t_step,t_step):
def Supply_condition(Comp_name, Mode_operation, Input_prop, Input1, Input2, Mass_supply, Calculation):
0 'Inerting', 1'Inerting_N', 2'Gassing-up', 3'Cool-down', 4'Cool-down_N', 5'Warm-up', 6'Warm-up_N', 7'Aeration', 8'Hold']
def Properties(Comp_name, Comp_value, Input_prop, input1, input2):
Prop = []
Value = []
def Init_condition(Comp_name, Comp_init, P_init, Filling, Step, LastStep, Target):
def Unitconv_nominal(Comp_name, Comp, P, T, iflag, Value): # iflag 0: Nominal flowrate, 1: Volumetric flowrate, 2 : Mass flowrate
def BOG_calculation(Tank_volume, Filling_Ratio, BOR, Comp_name, Comp_LNG): # methane, LNG, Revised_BOR
Vol = Tank_volume
d_methane = RP.REFPROPdll("Methane", "PQmass", "D", SI, 1, 0, P_init, 0, [1.0]).Output[0]
LH_methane = RP.REFPROPdll("Methane", "PQmass", "Heatvapz_P", SI, 1, 0, P_init, 0, [1.0]).Output[0]
def BOR_check(BOG, Comp_name, Comp_init, P_init, Filling, Step, LastStep, Target, Mode_list, Sim_time):
Init_cond = Init_condition(Comp_name, Comp_init, P_init, Filling, Step, LastStep, Target)
Operation = Mode_list[6]
Supply = Supply_condition(Comp_name, Operation, "PT", 0.11, 60, 0, Sim_time)
Hold = Heat_transfer(Supply, Init_cond, 0, T_ins, T_ins_ave, Ins_node, dt)
Exhaust = Hold[0][9]
'''''''''''''''''''''''''''
Initial Condition
'''''''''''''''''''''''''''
Comp_name = "Nitrogen;Methane;Ethane;Propane;Butane;Isobutane;Pentane;Isopentane;Oxygen;CO2;Water"
Comp_name_index = np.array(Comp_name.replace(';',' ').split())
Comp_init = np.array([1.0, 0.0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) # pure N2
Comp_init = np.array([0.0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Pure_methane = 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
Comp_init = np.array([0.751, 0.0, 0, 0, 0, 0, 0, 0, 0.2319, 0.0152, 0.0019]) # Air
T_atm = 25 # C
P_init = 0.126325 # Mpa
T_set_vapor = -160
Volume = Tank.Vol_tank # m3
Surface = Tank.Area_tank # m2
Filling = 0 # %
FR = Tank.FR
BOR = Tank.BOR
'''''''''''''''''''''''''''''
Insulation information
'''''''''''''''''''''''''''''
M_wall = Tank.M_wall # kg
Cp_wall = Tank.Cp_wall # kJ/kg/C
Cond_wall = Tank.Cond_wall # kJ/h/m/C
Wall_thick = Tank.Wall_thick # mm
M_ins = Tank.M_ins # kg
Cp_ins = Tank.Cp_ins # kJ/kg/C
D_ins = Tank.D_ins # kg/m3
Cond_ins = Tank.Cond_ins # kJ/h/m/C
Ins_thick = Tank.Ins_thick # mm
ht_NG = Tank.ht_NG # kJ/h/m2/C
ht_atm = Tank.ht_atm # kJ/h/m2/C
U = Tank.U
'''''''''''''''''''''''''''
Equilibrium Mode
'''''''''''''''''''''''''''
Qmass = 0.1 # initial value funcion 에 기입
Step = 0.2
LastStep = 0.0000000000001
Target = 0.001
direction = 0
'''''''''''''''''''''''''''
Plot
'''''''''''''''''''''''''''
x_axis = []
y_axis = []
y_axis2 = []
y_axis3 = []
y_axis4 = [] # sec barrier
x2_axis = []
y2_axis = []
filenames = []
plotnames = []
##############################################################
####################### Definition ###########################
##############################################################
Input_prop = 'PT', 'PH' 등등
Init_cond = Init_condition(Comp_name, Comp_init, P_init, Filling, Step, LastStep, Target)
T_vap = Init_cond[4][1]
T_lng = Init_cond[2][1]
T_liq = Init_cond[3][1]
T_wall = T_vap
Mass_tank = Volume * Init_cond[2][2]
Mass_vap = Mass_tank * Init_cond[2][6]
Mass_liq = Mass_tank - Mass_vap
'''''''''''''''''''''''''''
Select Mode
'''''''''''''''''''''''''''
Mode_list = ['Inerting', 'Inerting_N', 'Gassing-up', 'Cool-down', 'Cool-down_N', 'Warm-up', 'Warm-up_N', 'Aeration', 'Hold']
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/100,Ins_interval) # Insulation 각 위치
T2 = (T_wall + (ht_atm * Ins_thick/1000/Cond_ins)T_atm) / (1+(ht_atmIns_thick /1000/Cond_ins))
#Ins Outer temp.
T_ins_step = (T2 - T_wall) / (Ins_thick/1000/Ins_interval) # ins del_T
T_ins = np.zeros(n+1)
Insulation secondary barrier 위치 정하기
Ins_sec = Tank.sec
if np.any(Ins_node == Ins_sec) == True: # Insulation node 와 secondary barrier 가 같은경우,
loc_sec = np.where(Ins_node == Ins_sec)[0][0] #Insulation location
loc_sec_1 = np.where(Ins_node == Ins_sec)[0][0]
# T_ins_sec = (T_ins[loc_sec] + T_ins[loc_sec_1]) / 2
else: # 다를 경우는, 근처 2개 값의 평균값을 사용
nearest = Ins_node.flat[np.abs(Ins_node - Ins_sec).argmin()]
if nearest > Ins_sec:
Ins_sec_1 = Ins_sec - 0.01
elif nearest < Tank.sec:
Ins_sec_1 = Ins_sec + 0.01
nearest_1 = Ins_node.flat[np.abs(Ins_node - Ins_sec_1).argmin()]
loc_sec = np.where(Ins_node == nearest)[0][0]
loc_sec_1 = np.where(Ins_node == nearest_1)[0][0]
# T_ins_sec = (T_ins[loc_sec] + T_ins[loc_sec_1]) / 2
Insulation 초기온도 조건
if T_ins_step == 0:
T_ins = np.full(n+1, T_wall)
else:
T_ins = np.linspace(T_wall, T2, n+1)
def simpson(array, n): # simpson's rule
integration = array[0] + array[-1]
T_ins_ave = simpson(T_ins,n)
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
Prop = Properties(Comp_name, Comp_init, "PT", 0.12, 0)
"""""""""""""""""""""""
Calculation
"""""""""""""""""""""""
Supply 조건 지정.
Input_prop = "PQmass" # 2가지 고르기 (input에서)
Input1 = 0.106 # MPaA Input 1 값
Input2 = 0 # Input 2 값
simulation = 120 # hours
dt = 0.01 # hour
Calculation = round(simulation / dt)
### BOR check 하는 function 만들기
BOG = BOG_calculation(Volume, FR, BOR, Comp_name, Pure_methane)[0]
BOG_check = BOR_check(BOG, Comp_name, Comp_init, P_init, FR, Step, LastStep, Target, Mode_list, 30)
Mass_supply = 5000 ## 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[4]
Supply_condition(Comp_name, Mode_operation, Input_prop, Input1, Input2, Mass_supply, Calculation):
Supply = Supply_condition(Comp_name, Operation, "PQmass", 0.2, 0, Mass_supply, Calculation) # CD
Supply = Supply_condition(Comp_name, Operation, "PT", 0.12, 40, Mass_supply, Calculation) # WU
Supply = Supply_condition(Comp_name, Operation, "PT", 0.15, 20, Mass_supply, Calculation) # Inert
Unitconv_nominal(Comp_name, Comp_init, 0.1, 40, 2, 4000) # Supply 유량 계산위한 def
def Unitconv_nominal(Comp_name, Comp, P, T, iflag, Value):
def Heat_transfer(Supply_condition, Init_cond, P_mode, T_ins, T_ins_ave, Ins_node, dt):
Cooldown = Heat_transfer(Supply, Init_cond, 0, T_ins, T_ins_ave, Ins_node, dt)
Op_inert = Heat_transfer(Supply, Init_cond, 0, T_ins, T_ins_ave, Ins_node, dt)
Warmup = Heat_transfer(Supply, Init_cond, 0, T_ins, T_ins_ave, Ins_node, dt)
Hold = Heat_transfer(Supply, Init_cond, 1, T_ins, T_ins_ave, Ins_node, dt)
BOR = Heat_transfer(Supply, Init_cond, 0, T_ins, T_ins_ave, Ins_node, dt)
CHS 와 연계를 위해서 Tank info. 와 mode 같은것들은 다른걸로 빼는건 어떨지??
기존 계산값에서 이어서 계산할수 있는 def 도 만들기
BOR check 하는 것 만들기...
"""""""""""""""""""""""
추출 하기
"""""""""""""""""""""""
##pd.set_option('display.float_format', '{:,.4f}'.format) 다 안먹힘
pd.options.display.float_format = '{:.4f}'.format
df.style.set_precision(4) # DataFrame
Prop_col_name = ['Time', 'Tank Pressure', 'T_vap', 'T_wall', 'Density', 'Enthalpy', 'Mass_tank',
'Phase', 'Qmass', 'Mass_exhaust', 'Vol_exhaust', 'Amount_spray']
Ins_col_name = np.round(Ins_node.astype(np.float64),4) # Node 소수점이 4개 고정위해서 float64로 변환
Ins_col_name = Ins_col_name.tolist()
Ins_col_name.append('Ins_ave')
Ins_col_name.append('Ins_secondary')
df = pd.DataFrame(Cooldown[0], columns = Prop_col_name)
###Time 열 분리
Index_time = df['Time']
df_unit = pd.DataFrame({'Time': ['hr'],'Tank Pressure': ['MPaA'], 'T_vap': ['C'], 'T_wall': ['C'], 'Density': ['kg/m3'], 'Enthalpy': ['kJ/kg'],
'Mass_tank': ['kg'], 'Phase': ['-'], 'Qmass': ['-'], 'Mass_exhaust': ['kg/hr'], 'Vol_exhaust': ['m3/hr'],
'Amount_supply': ['kg']},index=['Units'])
df = pd.concat([df_unit, df])
df.set_index('Time', inplace = True)
df_ins = pd.DataFrame(Warmup[1], columns = Ins_col_name, index = Index_time)
df_ins.style.set_precision(4) # DataFrame
df_comp = pd.DataFrame(np.round(Warmup[2],4), columns = Comp_name_index, index = Index_time)
"""""""""""""""""""""""
출력 하기
"""""""""""""""""""""""
address = 'C:\Python_code\04_Tank model\Tank_result\'
df.to_csv(address+'Prop.csv', header = True, index= True)
df_comp.to_csv(address+'Comp.csv', header = True, index= True)
df_ins.to_csv(address+'Insulation.csv', header = True, index= True)
GIF 만들기
duration_rate = 0.01 # 속도
frames_plot = []
for plotname in plotnames:
if plotname.endswith(".png"):
# print(plotname)
frames_plot.append(imageio.imread(plotname))
exportname = "Plot.gif"
imageio.mimsave(exportname, frames_plot, format='GIF', duration=duration_rate, loop=1) # loop = 0 무한대
for plotname in set(plotnames):
os.remove(plotname)
The text was updated successfully, but these errors were encountered: