Fix Chamber temperature range, implement load from files

This commit is contained in:
Yeongdo Park 2022-12-15 09:57:41 +09:00
parent 44cfbd8c49
commit 5c2225fc7f

View file

@ -43,9 +43,15 @@ class CombustionChamber:
def solve (self, ):
""" Iteratively solve for outlet temperature that balance with heat loss to walls """
meanTwall = (self.Twall0 + self.Twall1) / 2
T_low = meanTwall - (self.T0 - meanTwall)
try:
f_found = optimize.root_scalar(self.energy_balance_equation,
bracket=[max(self.Twall0, self.Twall1), self.T0])
bracket=[T_low, self.T0])
self.T1 = f_found.root
except ValueError:
self.T1 = meanTwall
return f_found.root
@ -218,7 +224,20 @@ def wall_solve_wrapper(t_range, wall):
class Battery:
def __init__ (self, name, size, heat_program, charge_program, burned_gas_state, hv):
def load_state(self):
with open('gas.history', 'rb') as gas_history_file:
self.gas_t_history = pickle.load(gas_history_file)
with open('wall.history', 'rb') as wall_history_file:
self.wall_t_history = pickle.load(wall_history_file)
with open('coke.history', 'rb') as coke_history_file:
self.product = pickle.load(coke_history_file)
with open('oven.state', 'rb') as coke_state_file:
self.processing = pickle.load(coke_state_file)
def __init__ (self, name, size, heat_program, charge_program, burned_gas_state, hv, init_from_file=False):
self.name = name # Battery name
self.size = size # Size of battery, number of ovens
self.heat_program = heat_program # Heat program or schedule object
@ -273,6 +292,32 @@ class Battery:
start_indices = [1, 3, 5, 2, 4]
self.oven_idx_order = np.concatenate([np.array(range(i0 - 1, self.size, 5)) for i0 in start_indices])
if init_from_file:
print("Initializaton from file")
self.load_state()
latest_chamber = self.gas_t_history[-1]
latest_wall = self.wall_t_history[-1]
# Last Record Time
self.t = latest_chamber[0]
self.t_last = self.processing[-1].t_charge
# Recover Chamber State
for chmbr, T1 in zip(self.chambers, latest_chamber[1]):
chmbr.T1 = T1
(wl.T_chamber, wl.T_internal.data, wl.T_oven, wu.T_oven, wu.T_internal.data, wu.T_chamber)
# Recover Wall State
for wl, wu, wallT in zip(self.walls_0, self.walls_1, latest_wall[1]):
wl.T_chamber, wl.T_internal.data, wl.T_oven, wu.T_oven, wu.T_internal.data, wu.T_chamber = wallT
# Recover Oven State
for coal in self.processing:
self.ovens[coal.idx_oven].content = coal
else:
print("Initializaton Start")
# 정상 상태 만들기: 모든 문에 n_cycle 회 장입
n_cycle = 3 # 모든 문 장입 반복 횟수
period_over_dt = 6. # period/dt, 장입 간격 / 초기화 time step 크기
@ -338,7 +383,7 @@ class Battery:
wall_lower.update_bc(T_oven=T_oven)
wall_upper.update_bc(T_oven=T_oven)
with Pool(16) as pool:
with Pool(32) as pool:
wall_sln = pool.starmap(wall_solve_wrapper, [((dt*60*60), w) for w in self.walls_0+self.walls_1])
# wall_lower.solve(dt * 60 * 60) # convert hours to seconds
@ -550,8 +595,10 @@ if __name__ == "__main__":
charging_plan = ChargeSchedule( 81, 9, 9, 1e-12, 24+13, 3, 1e-12 )
n_doors = 66
bat3A = Battery("3A", n_doors, heating_plan, charging_plan, gas_in_state, hv)
load_state = False
bat3A = Battery("3A", n_doors, heating_plan, charging_plan, gas_in_state, hv, init_from_file=load_state)
if not load_state:
with open('gas.history', 'wb') as gas_history_file:
pickle.dump(bat3A.gas_t_history, gas_history_file)