def save_data_for_prediction(self, pred, act_time_in_h, ambient_temp, G): # Martin's code qHeat = self.V_2 * utils.rho_fluid_water(self.t24, self.p_atm, 1) * (self.t25 - self.t24) qDHW = self.V_1 * utils.rho_fluid_water(self.t22, self.p_atm, 1) * (self.t21 - self.t22) q_write = pred.run_to_save_data(act_time_in_h+2, qHeat + qDHW, ambient_temp) G.write('{:10.5f} {:10.5f} {:10.5f}\n'.format(act_time_in_h, qHeat + qDHW, ambient_temp))
def control_internal_2(self, chp, kessel, actual_time, m4, H): # controls - turn all off when the tank is fully loaded #if(str(type(self.t2))!="<class 'float'>"): #print('actual_time = {}; t2 = {}; t3 = {}'.format(actual_time, self.t2, self.t3)) if((self.t2 > 45.0) or (self.t3 > 60.0)): if(chp.get_status() == 1): wyn = chp.turn_off(actual_time) self.t26 = wyn[2] self.t27 = wyn[1] m3 = wyn[3] self.V_3 = m3 / utils.rho_fluid_water(self.t26, self.p_atm, 1) # in m3/s = kg/s / kg/m3 if(kessel.get_status() == 1): wyn = kessel.turn_off(actual_time) self.t28 = wyn[2] self.t29 = wyn[1] m4 = wyn[3] self.V_4 = m4 / utils.rho_fluid_water(self.t28, self.p_atm, 1) # in m3/s = kg/s / kg/m3 #print('t2>45||t3>60, turn OFF, chp = {}, kessel = {}'.format(chp.get_status(),kessel.get_status())) # controls - turn the gas heater off when the tank is more than half loaded if(self.t7 > 45.0): if(kessel.get_status() == 1): wyn = kessel.turn_off(actual_time) self.t28 = wyn[2] self.t29 = wyn[1] m4 = wyn[3] self.V_4 = m4 / utils.rho_fluid_water(self.t28, self.p_atm, 1) # in m3/s = kg/s / kg/m3 #print('t7>45, turn OFF, chp = {}, kessel = {}'.format(chp.get_status(),kessel.get_status())) # .............................................................. # # # storage tank #tank.calc_dhw_heat_exchange(time_step_in_s, t_in_dw , t_out_dw, mstr_dhw) # controls - turn the chp unit and heater if the temperature of domestic hot water is too low if self.t21 < 45.0: if chp.get_status(): wyn = kessel.turn_on(actual_time) if (wyn[0] == False): H.write('Could not turn gas boiler on at time = {}. Time left to the next turn on = {} s. t21 < 45\n'.format(actual_time,wyn[4].seconds)) #print('Could not turn gas boiler on at time = {}. Time left to the next turn on = {} s. t21 < 45'.format(actual_time,wyn[4].seconds)) self.t28 = wyn[2] self.t29 = wyn[1] m4 = wyn[3] self.V_4 = m4 / utils.rho_fluid_water(self.t29, self.p_atm, 1) # in m3/s = kg/s / kg/m3 else: wyn = chp.turn_on(actual_time) self.t26 = wyn[2] self.t27 = wyn[1] m3 = wyn[3] if (wyn[0] == False): H.write('Could not turn CHP on at time = {}. Time left to the next turn on = {} s. t21 < 45\n'.format(actual_time,wyn[4].seconds)) #print('Could not turn CHP on at time = {}. Time left to the next turn on = {} s. t21 < 45'.format(actual_time,wyn[4].seconds)) self.V_3 = m3 / utils.rho_fluid_water(self.t26, self.p_atm, 1) # in m3/s = kg/s / kg/m3 #print('t21<45, turn ON, chp = {}, kessel = {}'.format(chp.get_status(),kessel.get_status())) elif self.t21 > 85.0: print('alarm dhw too hot t = {}'.format(self.t21))
def rhocalc(self, temp): """ returns the density in kg/m3 """ if(self.extro): patm = 0.1 * 1.01325 # in MPa return utils.rho_fluid_water(temp, patm, 1) else: return self.rho
def get_heat_consumption_from_crate(cursor, start_time, horizont_in_h, pred, time_step_in_s): """ # gets data from crate db # calculates from it the heat flows needed by Martin's function # and passes them as result """ # q_th_dhw = 0.0 q_th_hk = 0.0 t_a_avg = 0.0 n_avg = 0 p_in_MPa = utils.get_pressure_in_MPa() calc_opt = utils.get_calc_option() # cursor.execute("SELECT time_index,t30_ambientairtemperature,t21_domestichotwater,t22_domesticcoldwater,v01_colddrinkingwater,t25_supply_heatingcircuit,t24_return_heatingcircuit,v02_heatingcircuit FROM mtopeniot.etrvk") result = cursor.fetchone() while result != None: timestamp = datetime.utcfromtimestamp(float(result[0]*0.001)) actual_time = start_time if((timestamp >= start_time) and (timestamp < (start_time + timedelta(hours=horizont_in_h)))): # ambient ar temperature t30_ambientairtemperature = result[1] # heat consumption for domestic hot water - get the data t21_domestichotwater = result[2] t22_domesticcoldwater = result[3] v01_colddrinkingwater = result[4] cp_dhw = utils.cp_fluid_water(0.5 * (t22_domesticcoldwater + t21_domestichotwater), p_in_MPa, calc_opt) rho_dhw = utils.rho_fluid_water(t22_domesticcoldwater, p_in_MPa, 1) # kg/m3 * m3/s * J/kg/K * K * s = J q_dhw = rho_dhw * v01_colddrinkingwater * cp_dhw * (t21_domestichotwater - t22_domesticcoldwater) * time_step_in_s # heat consumption for heating system - get the data t25_supply_heatingcircuit = result[5] t24_return_heatingcircuit = result[6] v02_heatingcircuit = result[7] cp_hk = utils.cp_fluid_water(0.5 * (t24_return_heatingcircuit + t25_supply_heatingcircuit), p_in_MPa, calc_opt) rho_hk = utils.rho_fluid_water(t24_return_heatingcircuit, p_in_MPa, 1) # kg/m3 * m3/s * J/kg/K * K * s = J q_hk = rho_hk * v02_heatingcircuit * cp_hk * (t25_supply_heatingcircuit - t24_return_heatingcircuit) * time_step_in_s # aggregate the data in the needed resolution t_act = actual_time.hour # t_act - actual time in hours q_act = (q_dhw + q_hk)/time_step_in_s # q_act - actual heat load of the system in W t_e_act = t30_ambientairtemperature # t_e_act - ambient air temperature in grad Celcius # add aggregated data to the data structure for predict_thermal.py pred.run_to_save_data(t_act,q_act,t_e_act)
def get_volume_flow_at_output(self): return self.get_mass_flow() / utils.rho_fluid_water( self.output_temperature, self.p_atm, 1) # in m3/s
def one_iteration_step(self, tsm, tank, chp, kessel, cvalve, heizkurve, t_a, el_heat_status, actual_time, H): """ one iteration step of the whole RVK system """ #print('\n chp = {}; kessel = {}; t2 = {}; t3 = {}'.format(chp.get_status(), kessel.get_status(), self.t2, self.t3)) # combined heat and power unit - link outputs wyn = chp.get_chp() #self.t27 = wyn[1] # tin in °C = self.t1 = wyn[t1] self.t26 = wyn[2] # tout in °C = chp.get_out_temp = wyn[2] m3 = wyn[3] # mstr in kg/s self.V_3 = m3 / utils.rho_fluid_water(self.t26, self.p_atm, 1) # volume flow incoming to chp from tank V_chp = chp.get_volume_flow_at_output() # volume flow outoming from chp into tank # combined heat and power unit - link inputs chp.set_inp_temp(self.t27) # temperature incoming from tank to chp # .............................................................. # gas boiler - link outputs wyn = kessel.get_kessel() #self.t29 = wyn[1] # tin in °C - incoming into gas heater self.t28 = wyn[2] # tout in °C - outcoming from gas heater m4 = wyn[3] # mstr in kg/s - incoming into gas heater self.V_4 = kessel.get_volume_flow_at_input() V_kessel = kessel.get_volume_flow_at_output() # gas boiler - link inputs kessel.set_inp_temp(self.t29) #kessel.calc_mass_flow() # .............................................................. # at first no delay - just linking chp and heater # delay due to the seuence of commands ie equal to the Timestep length self.t27 = self.t1 self.t29 = self.t1 # .............................................................. # heating circuit self.t23 = self.t20 # no delay assumed #print('t20 = {}; t23 = {}'.format(self.t20, self.t23)) self.t25 = heizkurve.get_supply_temperature(t_a) self.t24 = heizkurve.get_return_temperature(t_a) heizkurve.calc_volume_flow() ### (m23, m25, m4) = self.control_internal_1(heizkurve, kessel, chp, cvalve, t_a, actual_time, m4, H) m_bypass = m25 - m23 rho23 = utils.rho_fluid_water(self.t23, self.p_atm, 1) V_23 = m23 / rho23 # in m3/s = kg/s / kg/m3 #print('V_23 = {}; m23 = {}; rho23 = {}; t23 = {}'.format(V_23,m23, rho23, self.t23)) m24 = m23 rho24 = utils.rho_fluid_water(self.t24, self.p_atm, 1) V_24 = m24 / rho24 # demand for domestic hot water m22 = self.V_1 * utils.rho_fluid_water(self.t22, self.p_atm, 1) # in kg/s = m3/s * kg/m3 m22 = 0.01 # kg/s # .............................................................. t_ambient = 15.0 # storage tank - calculation tank.calculate_storage_tank_obj(tsm, # time step manager self.t23, # hk_inp_temp V_23, # hk_inp_volfl_m3s self.t24, # hk_out_temp self.t27, # chp_inp_temp self.t26, # chp_out_temp self.V_3, # chp_inp_volfl_m3s self.t29, # gb_inp_temp self.t28, # gp_out_temp self.V_4, # gb_inp_volfl_m3s self.t22, # dhw_inp_temp self.t21, # dhw_out_temp self.V_1, # dhw_inp_volfl_m3s el_heat_status, # el_heat_status actual_time, # time in the timestamp format t_ambient) # ambient temperature of the tank - defines heat losses to the outside self.t21 = tank.get_temp_dhw() #self.t27 = #self.t29 = #self.t23 = # storage tank - linking [self.t1, self.t2, self.t3, self.t4, self.t5, self.t6, self.t7, self.t8, self.t9, self.t10, self.t11, self.t12, self.t13, self.t14, self.t15, self.t16, self.t17, self.t18, self.t19, self.t20] = tank.output_temperatures() # .............................................................. self.control_internal_2(chp, kessel, actual_time, m4, H) # .............................................................. heizwert_in_MJ_per_kg = 50.0 # kg/m3 N ~CH4 gas_density = 0.79 # kg/m3 N ~Erdgas Z_boiler = kessel.get_gas_mstr(heizwert_in_MJ_per_kg) / gas_density self.Z_2 = chp.get_gas_mstr(heizwert_in_MJ_per_kg) / gas_density self.Z_1 = self.Z_2 + Z_boiler self.Wh1 = -1.0 * chp.get_el_prod() self.Wh2 = tank.get_el_heater_consumption() self.Wh3 = self.Wh1 + self.Wh2
def control_internal_1(self, heizkurve, kessel, chp, cvalve, t_a, actual_time, m4, H): if(t_a<=15.0): # heating period heizkurve.turn_on(t_a) else: heizkurve.turn_off() self.V_2 = heizkurve.get_volume_flow() # .............................................................. # mass flow m25 = utils.rho_fluid_water(self.t24, self.p_atm, 1) * self.V_2 # mass flow in heating circuit in kg/s #print('time = {}; type t23 = {}; type t25 = {}'.format(actual_time, type(self.t23), type(self.t25))) if(t_a<=15.0): # heating period #self.t25 = heizkurve.get2_supply_temperature(t_a) if self.t23 < self.t25: # temp in storage is too low to heat the building´ self.too_cold = 1 self.t24 = max(self.t24 - (self.t25 - self.t23),self.t22) # return temperature from the heating system self.t25 = self.t23 # supply temperature to the heating system is too low if chp.get_status() == 1 and self.t15 < self.t25: # storage is almost empty even though the chp is already running wyn = kessel.turn_on(actual_time) # turn the gas boiler on if (wyn[0] == False): H.write('Could not turn gas boiler on at time = {}. Time left to the next turn on = {} s. t23 < t25\n'.format(actual_time,wyn[4].seconds)) #print('Could not turn gas boiler on at time = {}. Time left to the next turn on = {} s. t23 < t25'.format(actual_time,wyn[4].seconds)) #print('t28 = {}; wyn[2] = {}'.format(self.t28,wyn[2])) self.t28 = wyn[2] #self.t29 = wyn[1] kessel.set_inp_temp(self.t29) m4 = wyn[3] if(wyn[0] == False): print('ERROR 2 at time = {}'.format(actual_time)) self.V_4 = m4 / utils.rho_fluid_water(self.t29, self.p_atm, 1) # in m3/s = kg/s / kg/m3 else: wyn = chp.turn_on(actual_time) # turn the chp unit on if (wyn[0] == False): H.write('Could not turn CHP unit on at time = {}. Time left to the next turn on = {} s. t23 < t25\n'.format(actual_time,wyn[4].seconds)) #print('Could not turn CHP unit on at time = {}. Time left to the next turn on = {} s. t23 < t25'.format(actual_time,wyn[4].seconds)) #print('TOO COLD, chp is off, t26 = {}; wyn[2] = {}; stat chp = {}; stat boiler = {}'.format(self.t26,wyn[2],chp.get_status(),kessel.get_status())) self.t26 = wyn[2] #self.t27 = wyn[1] chp.set_inp_temp(self.t27) # temperature incoming from tank to chp m3 = wyn[3] if (wyn[0] == False): print('ERROR 1 at time = {}'.format(actual_time)) self.V_3 = m3 / utils.rho_fluid_water(self.t26, self.p_atm, 1) # in m3/s = kg/s / kg/m3 #print('t23<t25, turn ON, chp = {}, kessel = {}'.format(chp.get_status(),kessel.get_status())) m23 = m25 cvalve.set_hub(1.0) else: self.too_cold = 0 cp25 = utils.cp_fluid_water(self.t25, self.p_atm, 1) cp24 = utils.cp_fluid_water(self.t24, self.p_atm, 1) cp23 = utils.cp_fluid_water(self.t23, self.p_atm, 1) # m23 + m_bypass = m25 ==> m_bypass = m25 - m23 # t23 * cp23 * m23 + t24 * cp24 * m_bypass = t25 * cp25 * m25 # t23 * cp23 * m23 + t24 * cp24 * (m25 - m23) = t25 * cp25 * m25 # m23 * (t23 * cp23 - t24 * cp24) = m25 * (t25 * cp25 - t24 * cp24) m23 = m25 * (self.t25 * cp25 - self.t24 * cp24) / (self.t23 * cp23 - self.t24 * cp24) # m_bypass = m25 * (1.0 - cvalve.get_hub) # mass flow in bypass in kg/s if(m25!=0.0): cvalve.set_hub(m23 / m25) # t25 = (t23 * cp23 + m_bypass * cp24) / (m25 * cp24) else: # no heating needed self.too_cold = 0 m23 = 0.0 m25 = 0.0 self.V_2 = 0.0 return (m23, m25, m4)
def get_volume_flow_at_output(self): return self.mass_flow / utils.rho_fluid_water(self.get_out_temp(), self.p_atm, 1) # in m3/s
def calc_volume_flow(self): self.volume_flow = self.get_design_mass_flow() / utils.rho_fluid_water( self.get_avg_hk_temperature(self.design_ambient_temp), self.p_atm, 1) # m3/s = kg/s / kg/m3