def power_plant_layout(self): """ Power plant layout calculation to determine power plant design point using nominal power input/output and nominal pressure as inputs. """ msg = 'Starting power plant layout calculation, compressor part.' logging.debug(msg) # charging self.tespy_charge.busses[self.power_bus_charge].set_attr( P=self.power_nominal_charge) self.tespy_charge.connections[self.pressure_conn_charge].set_attr( p=self.pressure_nominal_charge, m=ref(self.tespy_charge.connections[self.massflow_conn_charge], 1 / self.num_wells, 0)) self.tespy_charge.connections[self.massflow_conn_charge].set_attr( m=np.nan) self.tespy_charge.components[self.pipe_charge].set_attr( L=self.min_well_depth) self.tespy_charge.solve('design') self.tespy_charge.save(self.wdir + self.sc + '_charge_design') self.m_nom_charge = self.tespy_charge.connections[ self.massflow_conn_charge].m.val_SI self.m_min_charge = self.m_nom_charge * self.massflow_min_rel self.m_max_charge = self.m_nom_charge * self.massflow_max_rel msg = 'Nominal mass flow for charging is ' + str( self.m_nom_charge) + ' at nominal power ' + str( self.power_nominal_charge) + ' and nominal pressure ' + str( self.pressure_nominal_charge) + '.' logging.debug(msg) msg = 'Starting power plant layout calculation, turbine part.' logging.debug(msg) # discharging self.tespy_discharge.busses[self.power_bus_discharge].set_attr( P=self.power_nominal_discharge) self.tespy_discharge.connections[ self.pressure_conn_discharge].set_attr( p=self.pressure_nominal_discharge, m=ref( self.tespy_discharge.connections[ self.massflow_conn_discharge], 1 / self.num_wells, 0)) self.tespy_discharge.connections[ self.massflow_conn_discharge].set_attr(m=np.nan) self.tespy_charge.components[self.pipe_discharge].set_attr( L=self.min_well_depth) self.tespy_discharge.solve('design') self.tespy_discharge.save(self.wdir + self.sc + '_discharge_design') self.m_nom_discharge = self.tespy_discharge.connections[ self.massflow_conn_discharge].m.val_SI self.m_min_discharge = self.m_nom_discharge * self.massflow_min_rel self.m_max_discharge = self.m_nom_discharge * self.massflow_max_rel msg = 'Nominal mass flow for discharging is ' + str( self.m_nom_discharge) + ' at nominal power ' + str( self.power_nominal_discharge) + ' and nominal pressure ' + str( self.pressure_nominal_discharge) + '.' logging.debug(msg)
def define_connections_pipe_fork_back(df_pipe_fork, df_fork_pipe, k, pb, fork_pipe_b1): df_pipe_fork_nextnext = pd.merge(df_pipe_fork, df_fork_pipe, left_on='ID', right_on='ID_previous', how="outer") df_pipe_fork_nextnext = df_pipe_fork_nextnext[[ "ID_x", "ID_previous_x", "ID_next_x", "ID_next_y" ]] df_pipe_fork_nextnext = df_pipe_fork_nextnext.rename( columns={ "ID_x": "ID", "ID_previous_x": "ID_previous", "ID_next_x": "ID_next", "ID_next_y": "ID_next_next" }) df_pipe_fork_nextnext = df_pipe_fork_nextnext.iloc[::2, :] pipe_fork_b = {} for index, row in df_pipe_fork_nextnext.iterrows(): pipe_fork_b[row["ID"]] = connection( k[row["ID"]].comps["merge"], "out1", pb[row["ID"]], "in1", p=ref(fork_pipe_b1[row["ID_next_next"]], 1, -5e4)) return pipe_fork_b
def conns_set_ref(c, *args): r""" Set references on connections as specified in connection data. Parameters ---------- c : pandas.core.series.Series Connection information from .csv-file. args[0] : pandas.core.frame.DataFrame DataFrame containing all created connections. Returns ------- instance : tespy.connections.ref TESPy reference object. """ for col in ['m', 'p', 'h', 'T']: # search for referenced connections if isinstance(c[col + '_ref'], str): # create reference object instance = args[0].instance[c[col + '_ref'] == args[0]['id']].values[0] # write to connection properties c['instance'].get_attr(col).ref = ref(instance, c[col + '_ref_f'], c[col + '_ref_d'])
def test_set_attr_errors(): """Test errors of set_attr methods.""" nw = network(['water', 'air']) comb = combustion.combustion_engine('combustion engine') pipeline = piping.pipe('pipeline') conn = connection(comb, 'out1', pipeline, 'in1') mybus = bus('mybus') # ValueErrors set_attr_ValueError(comb, offdesign=['Q']) set_attr_ValueError(conn, offdesign=['f']) set_attr_ValueError(nw, m_unit='kg') set_attr_ValueError(nw, h_unit='kg') set_attr_ValueError(nw, p_unit='kg') set_attr_ValueError(nw, T_unit='kg') set_attr_ValueError(nw, v_unit='kg') set_attr_ValueError(conn, state=5) # TypeErrors set_attr_TypeError(comb, P=[5]) set_attr_TypeError(comb, tiP_char=7) set_attr_TypeError(comb, design='f') set_attr_TypeError(comb, lamb=dc_cc()) set_attr_TypeError(comb, design_path=7) set_attr_TypeError(comb, local_design=5) set_attr_TypeError(comb, local_offdesign=5) set_attr_TypeError(pipeline, hydro_group=5) set_attr_TypeError(comb, printout=5) set_attr_TypeError(conn, design='h') set_attr_TypeError(conn, fluid_balance=1) set_attr_TypeError(conn, h0=[4]) set_attr_TypeError(conn, fluid=5) set_attr_TypeError(conn, design_path=5) set_attr_TypeError(conn, local_design=5) set_attr_TypeError(conn, local_offdesign=5) set_attr_TypeError(conn, printout=5) set_attr_TypeError(conn, label=5) set_attr_TypeError(conn, state='f') set_attr_TypeError(nw, m_range=5) set_attr_TypeError(nw, p_range=5) set_attr_TypeError(nw, h_range=5) set_attr_TypeError(nw, iterinfo=5) set_attr_TypeError(mybus, P='some value') set_attr_TypeError(mybus, printout=5) # KeyErrors set_attr_KeyError(dc_cc(), x=7) set_attr_KeyError(comb, wow=5) set_attr_KeyError(conn, jey=5) set_attr_KeyError(mybus, power_output=100000) # NotImplementedError set_attr_NotImplementedError(conn, Td_bp=ref(conn, 1, 0))
def define_connections_user_pipe(end_pipes, pb, cons, pipe_user): user_pipe = {} for index, row in end_pipes.iterrows(): user_pipe[int(row["USER_ID"])] = connection(cons[row["USER_ID"]], "out1", pb[row["ID"]], "in1", p=ref( pipe_user[row["ID"]], 1, row["p_drop"])) return user_pipe
def test_get_attr_errors(): """Test errors of get_attr methods.""" nw = network(['water', 'air']) comb = combustion.combustion_engine('combustion engine') pipeline = piping.pipe('pipeline') conn = connection(comb, 'out1', pipeline, 'in1') mybus = bus('mybus') sub = subsystems.subsystem('MySub') get_attr_KeyError(comb, 'wow') get_attr_KeyError(conn, 'key') get_attr_KeyError(mybus, 'components') get_attr_KeyError(nw, 'missing') get_attr_KeyError(ref(conn, 1, 0), 'comp') get_attr_KeyError(sub, 'test') get_attr_KeyError(char_line(), 'test') get_attr_KeyError(data_container(), 'somekey') get_attr_KeyError(char_map(), 'Stuff')
def power_plant_layout(self): """ Power plant layout calculation to determine power plant design point using nominal power input/output and nominal pressure as inputs. """ msg = 'Starting power plant layout calculation.' logging.debug(msg) for mode in ['charge', 'discharge']: model = getattr(self, mode) pressure_conn = model.connections[getattr(self, 'pressure_conn_' + mode)] massflow_conn = model.connections[getattr(self, 'massflow_conn_' + mode)] power_bus = model.busses[getattr(self, 'power_bus_' + mode)] power_bus.set_attr(P=getattr(self, 'power_nominal_' + mode)) pressure_conn.set_attr( p=getattr(self, 'pressure_nominal_' + mode), m=ref(massflow_conn, 1 / self.num_wells, 0) ) massflow_conn.set_attr(m=np.nan) model.components[getattr(self, 'pipe_' + mode)].set_attr( L=self.min_well_depth ) model.solve('design') model.save(self.wdir + self.sc + '_' + mode + '_design') m_nom = massflow_conn.m.val_SI setattr(self, 'm_nom_' + mode, m_nom) setattr(self, 'm_min_' + mode, m_nom * self.massflow_min_rel) setattr(self, 'm_max_' + mode, m_nom * self.massflow_max_rel) msg = ( 'Nominal mass flow for ' + mode + ' is ' + str(m_nom) + ' at nominal power ' + str(getattr(self, 'power_nominal_' + mode)) + ' and nominal ' + 'pressure ' + str(getattr(self, 'pressure_nominal_' + mode)) + '.' ) logging.debug(msg) msg = 'Finished power plant layout calculation.' logging.debug(msg)
cp1.set_attr(eta_s=0.85, design=['eta_s'], offdesign=['eta_s_char']) cp2.set_attr(eta_s=0.9, pr=3, design=['eta_s'], offdesign=['eta_s_char']) ic.set_attr(pr1=0.99, pr2=0.999, design=['pr1', 'pr2'], offdesign=['zeta1', 'zeta2', 'kA']) # %% connection parametrization # condenser system c_in_cd.set_attr(fluid={'air': 0, 'NH3': 1, 'water': 0}) cb_dhp.set_attr(T=60, p=10, fluid={'air': 0, 'NH3': 0, 'water': 1}) cd_cons.set_attr(T=90) cons_cf.set_attr(h=ref(cb_dhp, 1, 0), p=ref(cb_dhp, 1, 0)) # evaporator system cold side erp_ev.set_attr(m=ref(ves_dr, 1.25, 0), p0=5) su_cp1.set_attr(p0=5, h0=1700) # evaporator system hot side # fan blows at constant rate amb_fan.set_attr(T=12, p=1, fluid={ 'air': 1, 'NH3': 0, 'water': 0
def create_ref_TypeError(self, params): ref(params[0], params[1], params[2])
def setup(self): # %% network self.nw = network(fluids=['water', 'NH3'], T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s') # %% components # sources & sinks c_in = source('coolant in') cb = source('consumer back flow') cf = sink('consumer feed flow') amb_in = source('source ambient') amb_out = sink('sink ambient') ic_in = source('source intercool') ic_out = sink('sink intercool') c_out = sink('coolant out') # consumer system cd = heat_exchanger('condenser') rp = pump('recirculation pump') cons = heat_exchanger_simple('consumer') # evaporator system va = valve('valve') dr = drum('drum') ev = heat_exchanger('evaporator') su = heat_exchanger('superheater') pu = pump('pump evaporator') # compressor-system cp1 = compressor('compressor 1') cp2 = compressor('compressor 2') he = heat_exchanger('intercooler') # busses self.power = bus('total compressor power') self.power.add_comps({'c': cp1}, {'c': cp2}) self.heat = bus('total delivered heat') self.heat.add_comps({'c': cd, 'char': -1}) self.nw.add_busses(self.power, self.heat) # %% connections # consumer system c_in_cd = connection(c_in, 'out1', cd, 'in1') cb_rp = connection(cb, 'out1', rp, 'in1') rp_cd = connection(rp, 'out1', cd, 'in2') self.cd_cons = connection(cd, 'out2', cons, 'in1') cons_cf = connection(cons, 'out1', cf, 'in1') self.nw.add_conns(c_in_cd, cb_rp, rp_cd, self.cd_cons, cons_cf) # connection condenser - evaporator system cd_va = connection(cd, 'out1', va, 'in1') self.nw.add_conns(cd_va) # evaporator system va_dr = connection(va, 'out1', dr, 'in1') dr_pu = connection(dr, 'out1', pu, 'in1') pu_ev = connection(pu, 'out1', ev, 'in2') ev_dr = connection(ev, 'out2', dr, 'in2') dr_su = connection(dr, 'out2', su, 'in2') self.nw.add_conns(va_dr, dr_pu, pu_ev, ev_dr, dr_su) self.amb_in_su = connection(amb_in, 'out1', su, 'in1') su_ev = connection(su, 'out1', ev, 'in1') ev_amb_out = connection(ev, 'out1', amb_out, 'in1') self.nw.add_conns(self.amb_in_su, su_ev, ev_amb_out) # connection evaporator system - compressor system su_cp1 = connection(su, 'out2', cp1, 'in1') self.nw.add_conns(su_cp1) # compressor-system cp1_he = connection(cp1, 'out1', he, 'in1') he_cp2 = connection(he, 'out1', cp2, 'in1') cp2_c_out = connection(cp2, 'out1', c_out, 'in1') ic_in_he = connection(ic_in, 'out1', he, 'in2') he_ic_out = connection(he, 'out2', ic_out, 'in1') self.nw.add_conns(cp1_he, he_cp2, ic_in_he, he_ic_out, cp2_c_out) # %% component parametrization # condenser system x = np.array([ 0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625, 0.6375, 0.7125, 0.7875, 0.9, 0.9875, 1, 1.0625, 1.125, 1.175, 1.2125, 1.2375, 1.25 ]) y = np.array([ 0.0076, 0.1390, 0.2731, 0.4003, 0.5185, 0.6263, 0.7224, 0.8056, 0.8754, 0.9312, 0.9729, 1.0006, 1.0203, 1.0158, 1.0051, 1.0000, 0.9746, 0.9289, 0.8832, 0.8376, 0.7843, 0.7614 ]) rp.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'], eta_s_char=dc_cc(func=char_line(x, y), param='m')) cons.set_attr(pr=1, design=['pr'], offdesign=['zeta']) # evaporator system x = np.linspace(0, 2.5, 26) y = np.array([ 0.000, 0.164, 0.283, 0.389, 0.488, 0.581, 0.670, 0.756, 0.840, 0.921, 1.000, 1.078, 1.154, 1.228, 1.302, 1.374, 1.446, 1.516, 1.585, 1.654, 1.722, 1.789, 1.855, 1.921, 1.986, 2.051 ]) kA_char1 = dc_cc(func=char_line(x, y), param='m') x = np.array([ 0.0100, 0.0400, 0.0700, 0.1100, 0.1500, 0.2000, 0.2500, 0.3000, 0.3500, 0.4000, 0.4500, 0.5000, 0.5500, 0.6000, 0.6500, 0.7000, 0.7500, 0.8000, 0.8500, 0.9000, 0.9500, 1.0000, 1.5000, 2.0000 ]) y = np.array([ 0.0185, 0.0751, 0.1336, 0.2147, 0.2997, 0.4118, 0.5310, 0.6582, 0.7942, 0.9400, 0.9883, 0.9913, 0.9936, 0.9953, 0.9966, 0.9975, 0.9983, 0.9988, 0.9992, 0.9996, 0.9998, 1.0000, 1.0008, 1.0014 ]) kA_char2 = dc_cc(func=char_line(x, y), param='m') ev.set_attr(pr1=1, pr2=.999, ttd_l=5, design=['ttd_l'], offdesign=['kA'], kA_char1=kA_char1, kA_char2=kA_char2) # no kA modification for hot side! x = np.array([0, 1]) y = np.array([1, 1]) kA_char1 = dc_cc(func=char_line(x, y), param='m') # characteristic line for superheater kA x = np.array( [0, 0.045, 0.136, 0.244, 0.43, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2]) y = np.array( [0, 0.037, 0.112, 0.207, 0.5, 0.8, 0.85, 0.9, 0.95, 1, 1.04, 1.07]) kA_char2 = dc_cc(func=char_line(x, y), param='m') su.set_attr(kA_char1=kA_char1, kA_char2=kA_char2, offdesign=['zeta1', 'zeta2', 'kA']) x = np.array([ 0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625, 0.6375, 0.7125, 0.7875, 0.9, 0.9875, 1, 1.0625, 1.125, 1.175, 1.2125, 1.2375, 1.25 ]) y = np.array([ 0.0076, 0.1390, 0.2731, 0.4003, 0.5185, 0.6263, 0.7224, 0.8056, 0.8754, 0.9312, 0.9729, 1.0006, 1.0203, 1.0158, 1.0051, 1.0000, 0.9746, 0.9289, 0.8832, 0.8376, 0.7843, 0.7614 ]) pu.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'], eta_s_char=dc_cc(func=char_line(x, y), param='m')) # compressor system x = np.array([0, 0.4, 1, 1.2]) y = np.array([0.5, 0.9, 1, 1.1]) cp1.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'], eta_s_char=dc_cc(func=char_line(x, y), param='m')) cp2.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'], eta_s_char=dc_cc(func=char_line(x, y), param='m')) # characteristic line for intercooler kA x = np.linspace(0, 2.5, 26) y = np.array([ 0.0000, 0.2455, 0.3747, 0.4798, 0.5718, 0.6552, 0.7323, 0.8045, 0.8727, 0.9378, 1.0000, 1.0599, 1.1176, 1.1736, 1.2278, 1.2806, 1.3320, 1.3822, 1.4313, 1.4792, 1.5263, 1.5724, 1.6176, 1.6621, 1.7058, 1.7488 ]) # x = np.array([0, 1]) # y = np.array([1, 1]) kA_char1 = dc_cc(func=char_line(x, y), param='m') x = np.linspace(0, 2.5, 26) y = np.array([ 0.000, 0.164, 0.283, 0.389, 0.488, 0.581, 0.670, 0.756, 0.840, 0.921, 1.000, 1.078, 1.154, 1.228, 1.302, 1.374, 1.446, 1.516, 1.585, 1.654, 1.722, 1.789, 1.855, 1.921, 1.986, 2.051 ]) # x = np.array([0, 1]) # y = np.array([1, 1]) kA_char2 = dc_cc(func=char_line(x, y), param='m') he.set_attr(kA_char1=kA_char1, kA_char2=kA_char2, offdesign=['zeta1', 'zeta2', 'kA']) # characteristic line for condenser kA x = np.linspace(0, 2.5, 26) y = np.array([ 0.0000, 0.2455, 0.3747, 0.4798, 0.5718, 0.6552, 0.7323, 0.8045, 0.8727, 0.9378, 1.0000, 1.0599, 1.1176, 1.1736, 1.2278, 1.2806, 1.3320, 1.3822, 1.4313, 1.4792, 1.5263, 1.5724, 1.6176, 1.6621, 1.7058, 1.7488 ]) kA_char1 = dc_cc(func=char_line(x, y), param='m') x = np.linspace(0, 2.5, 26) y = np.array([ 0.000, 0.164, 0.283, 0.389, 0.488, 0.581, 0.670, 0.756, 0.840, 0.921, 1.000, 1.078, 1.154, 1.228, 1.302, 1.374, 1.446, 1.516, 1.585, 1.654, 1.722, 1.789, 1.855, 1.921, 1.986, 2.051 ]) kA_char2 = dc_cc(func=char_line(x, y), param='m') cd.set_attr(kA_char1=kA_char1, kA_char2=kA_char2, pr2=0.9998, design=['pr2'], offdesign=['zeta2', 'kA']) # %% connection parametrization # condenser system c_in_cd.set_attr(fluid={'water': 0, 'NH3': 1}, p=60) rp_cd.set_attr(T=60, fluid={'water': 1, 'NH3': 0}, p=10) self.cd_cons.set_attr(T=105) cons_cf.set_attr(h=ref(cb_rp, 1, 0), p=ref(cb_rp, 1, 0)) cd_va.set_attr(p=ref(c_in_cd, 1, -1000), Td_bp=-5, h0=500, design=['Td_bp']) # evaporator system cold side pu_ev.set_attr(m=ref(va_dr, 10, 0), p0=5) dr_su.set_attr(p0=5, T=5) su_cp1.set_attr(p=ref(dr_su, 1, -5000), Td_bp=5, h0=1700, design=['Td_bp', 'p']) # evaporator system hot side self.amb_in_su.set_attr(m=20, T=12, p=1, fluid={'water': 1, 'NH3': 0}) su_ev.set_attr(p=ref(self.amb_in_su, 1, -100), design=['p']) ev_amb_out.set_attr() # compressor-system cp1_he.set_attr(p=15) he_cp2.set_attr(T=40, p=ref(cp1_he, 1, -1000), design=['T', 'p']) ic_in_he.set_attr(p=1, T=20, m=5, fluid={'water': 1, 'NH3': 0}) he_ic_out.set_attr(p=ref(ic_in_he, 1, -200), design=['p']) cp2_c_out.set_attr(p=ref(c_in_cd, 1, 0), h=ref(c_in_cd, 1, 0))
def test_pump(self): """Test component properties of pumps.""" instance = pump('pump') self.setup_network(instance) fl = {'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 1, 'NH3': 0} self.c1.set_attr(fluid=fl, v=1, p=5, T=50) self.c2.set_attr(p=7) instance.set_attr(eta_s=1) self.nw.solve('design') # test calculated value for efficiency eta_s = ((instance.h_os('') - self.c1.h.val_SI) / (self.c2.h.val_SI - self.c1.h.val_SI)) msg = ('Value of isentropic efficiency must be ' + str(eta_s) + ', is ' + str(instance.eta_s.val) + '.') eq_(eta_s, instance.eta_s.val, msg) # isentropic efficiency of 1 means inlet and outlet entropy are # identical s1 = round(s_mix_ph(self.c1.to_flow()), 4) s2 = round(s_mix_ph(self.c2.to_flow()), 4) msg = ('Value of entropy must be identical for inlet (' + str(s1) + ') and outlet (' + str(s2) + ') at 100 % isentropic efficiency.') eq_(s1, s2, msg) # specify realistic value for efficiency, outlet pressure from flow # char eta_s_d = 0.8 instance.set_attr(eta_s=eta_s_d) self.nw.solve('design') self.nw.save('tmp') self.c2.set_attr(p=np.nan) # flow char (pressure rise vs. volumetric flow) x = [0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4] y = np.array([14, 13.5, 12.5, 11, 9, 6.5, 3.5, 0]) * 1e5 char = dc_cc(func=char_line(x, y), is_set=True) # apply flow char and eta_s char instance.set_attr(flow_char=char, eta_s=np.nan, eta_s_char=dc_cc(func=ldc('pump', 'eta_s_char', 'DEFAULT', char_line), is_set=True)) self.nw.solve('offdesign', design_path='tmp') # value for difference pressure dp = 650000.0 msg = ('Value of pressure rise must be ' + str(dp) + ', is ' + str(self.c2.p.val_SI - self.c1.p.val_SI) + '.') eq_(round(self.c2.p.val_SI - self.c1.p.val_SI, 0), dp, msg) # test ohter volumetric flow on flow char self.c1.set_attr(v=0.9) self.nw.solve('offdesign', design_path='tmp') dp = 775000.0 msg = ('Value of pressure rise must be ' + str(dp) + ', is ' + str(self.c2.p.val_SI - self.c1.p.val_SI) + '.') eq_(self.c2.p.val_SI - self.c1.p.val_SI, dp, msg) # test value of isentropic efficiency eta_s = round( eta_s_d * instance.eta_s_char.func.evaluate( self.c1.v.val_SI / self.c1.v.design), 3) msg = ('Value of isentropic efficiency must be ' + str(eta_s) + ', is ' + str(instance.eta_s.val) + '.') eq_(eta_s, round(instance.eta_s.val, 3), msg) instance.eta_s_char.is_set = False # test boundaries of characteristic line: # lower boundary self.c2.set_attr(T=ref(self.c1, 0, 20)) self.c1.set_attr(v=-0.1) self.nw.solve('design') msg = ('Value of power must be ' + str(14e5) + ', is ' + str(self.c2.p.val_SI - self.c1.p.val_SI) + '.') eq_(self.c2.p.val_SI - self.c1.p.val_SI, 14e5, msg) # upper boundary self.c1.set_attr(v=1.5) self.nw.solve('design') msg = ('Value of power must be ' + str(0) + ', is ' + str(self.c2.p.val_SI - self.c1.p.val_SI) + '.') eq_(self.c2.p.val_SI - self.c1.p.val_SI, 0, msg) shutil.rmtree('./tmp', ignore_errors=True)
fluid={ 'Ar': 0, 'N2': 0, 'H2O': 0, 'CH4': 1, 'CO2': 0, 'O2': 0 }) compressor_gtp.combustion_chamber.set_attr(h0=659.83) combustion_chamber.gas_turbine.set_attr(T=1500) gas_turbine.steam_generator_gas.set_attr(p=1) steam_generator_gas.rauchgas.set_attr(T=150) # Connections Steam fs_source.steam_generator_gas.set_attr(T=ref(pump.fs_sink, 1, 0), fluid={ 'Ar': 0, 'N2': 0, 'H2O': 1, 'CH4': 0, 'CO2': 0, 'O2': 0 }) steam_generator_gas.hp_turbine.set_attr(T=600, p=100, design=['p']) hp_turbine.splitter_1.set_attr(p=3, design=['p']) lp_turbine.merge.set_attr(p=0.04) pump.fs_sink.set_attr(p=ref(fs_source.steam_generator_gas, 1, 0)) # Connections Cooling Water cw_source.condenser_stp.set_attr(T=20,
dT_feed = 100 dT_return = 200 # return temperatures of consumers for sub in [h1, ia, sc, h2, h3, h4]: for i in range(sub.num_consumer): sub.conns['cova_' + str(i)].set_attr(T=52) # temperature differences over subsystem pipes if isinstance(sub, lc): for i in range(sub.num_consumer - 1): # feed dT_feed_ref = ref(sub.conns['spfe_' + str(i)], 1, -sub.comps['feed_' + str(i)].L.val / dT_feed) # return if i == sub.num_consumer - 1: dT_return_ref = ref( sub.conns['mere_' + str(i + 1)], 1, -sub.comps['return_' + str(i)].L.val / dT_return) else: dT_return_ref = ref( sub.conns['cova_' + str(i + 1)], 1, -sub.comps['return_' + str(i)].L.val / dT_return) if i == sub.num_consumer - 2: sub.conns['spco_' + str(i + 1)].set_attr(T=dT_feed_ref, design=['T']) else: sub.conns['fesp_' + str(i + 1)].set_attr(T=dT_feed_ref,
# gas turbine c_in.set_attr(T=20, p=1, m=250, fluid={ 'Ar': 0.0129, 'N2': 0.7553, 'H2O': 0, 'CH4': 0, 'CO2': 0.0004, 'O2': 0.2314 }, design=['m']) gt_in.set_attr(T=1200) gt_out.set_attr(p0=1) fuel.set_attr(T=ref(c_in, 1, 0), h0=800, fluid={ 'CO2': 0.04, 'Ar': 0, 'N2': 0, 'O2': 0, 'H2O': 0, 'CH4': 0.96 }) # waste heat recovery eco_dh.set_attr(T=290, design=['T'], p0=1) dh_ch.set_attr(T=100, design=['T'], p=1) # steam turbine
#dp = np.array([11, 11]) * 1e5 #char = hlp.dc_cc(x=v, y=dp, is_set=True) #pump.set_attr(eta_s=0.85, flow_char=char, design=['eta_s_char']) pump.set_attr(pr=14.75, eta_s=0.9) ihe.set_attr(pr1=0.849056603, pr2=0.957627118) condenser.set_attr(pr1=0.8889, pr2=1) turbine.set_attr(pr=0.098148148, eta_s=0.85, design=['eta_s', 'pr']) p_and_e.set_attr(pr1=1, pr2=0.955752212) # parametrization of connections turbine_wf_in.set_attr(T=T_before_turbine, fluid={ 'water': 0, 'Isopentane': 1, 'Air': 0 }) p_and_e_wf_in.set_attr(T=ref(ihe_wf_out, 1, 0), p=ref(ihe_wf_out, 1, 0), m=ref(ihe_wf_out, 1, 0), fluid={ 'water': 0, 'Isopentane': 1, 'Air': 0 }) p_and_e_wf_out.set_attr(T=ref(turbine_wf_in, 1, 0), state='g') pump_ihe.set_attr(p=p_after_pump) # air cooling connections ca_in.set_attr(T=T_air, p=p_air, m=mass_flow_rate_air, fluid={ 'water': 0,
def set_conns(self): if self.circ_num_set: self.conns[3].set_attr(m=ref(self.conns[-1], self.circ_num, 0)) else: self.conns[3].set_attr(m=np.nan)
ihe_cond_2.set_attr() cond_pu_2.set_attr() pu_ihe_2.set_attr() ihe_val_2.set_attr() val_mer_2.set_attr() # parametrization of connections (preheater and evaporator) wf_in_spl.set_attr(Td_bp=2.3, h0=500, p=p_before_turbines, fluid={ 'water': 0, 'Isopentane': 1, 'Air': 0 }) spl_turb_2.set_attr(m=ref(wf_in_spl, 0.5, 0)) evap_preh.set_attr(T=80) # air cooling connections ca_in_1.set_attr(T=T_air, p=p_air, m=mass_flow_rate_air / 2, fluid={ 'water': 0, 'Isopentane': 0, 'Air': 1 }) ca_out_1.set_attr(T=T_air + 15) ca_in_2.set_attr(T=T_air, p=p_air,
# %% connection parameters # gas turbine c_in.set_attr(T=20, p=1, fluid={ 'Ar': 0.0129, 'N2': 0.7553, 'H2O': 0, 'CH4': 0, 'CO2': 0.0004, 'O2': 0.2314 }) # gt_in.set_attr(T=1315) # gt_out.set_attr(p=1.05) fuel_comp.set_attr(p=ref(c_in, 1, 0), T=ref(c_in, 1, 0), h0=800, fluid={ 'CO2': 0.04, 'Ar': 0, 'N2': 0, 'O2': 0, 'H2O': 0, 'CH4': 0.96 }) # waste heat recovery eco_ch.set_attr(T=142, design=['T'], p=1.02) # steam turbine
steam_generator.exhaust_gas.set_attr(p=1, T=150) # steam turbine part fs_source.steam_generator.set_attr(p=100, T=35, fluid={ 'Ar': 0, 'N2': 0, 'H2O': 1, 'CH4': 0, 'CO2': 0, 'O2': 0 }) steam_generator.steam_turbine.set_attr(T=500) dh_heat_exchanger.pump.set_attr(x=0) pump.fs_sink.set_attr(p=ref(fs_source.steam_generator, 1, 0)) # district heating part dh_source.dh_heat_exchanger.set_attr(T=t_dh_in, p=10, fluid={ 'Ar': 0, 'N2': 0, 'H2O': 1, 'CH4': 0, 'CO2': 0, 'O2': 0 }) dh_heat_exchanger.dh_sink.set_attr(T=t_dh_out) # %% Busses
def set_attr(self): r""" # %% set the attribution of the heat pump :return: heat output of the heat pump """ HeatPump.cd.set_attr(pr1=0.99, pr2=0.99, ttd_u=15, design=['pr2', 'ttd_u'], offdesign=['zeta2', 'kA']) HeatPump.dhp.set_attr(eta_s=self.eff, design=['eta_s'], offdesign=['eta_s_char']) HeatPump.cons.set_attr(pr=0.99, design=['pr'], offdesign=['zeta']) # water pump HeatPump.pu.set_attr(eta_s=self.eff, design=['eta_s'], offdesign=['eta_s_char']) # evaporator system kA_char1 = ldc('heat exchanger', 'kA_char1', 'DEFAULT', char_line) kA_char2 = ldc('heat exchanger', 'kA_char2', 'EVAPORATING FLUID', char_line) HeatPump.ev.set_attr(pr1=0.98, pr2=0.99, ttd_l=5, kA_char1=kA_char1, kA_char2=kA_char2, design=['pr1', 'ttd_l'], offdesign=['zeta1', 'kA']) HeatPump.su.set_attr(pr1=0.98, pr2=0.99, ttd_u=2, design=['pr1', 'pr2', 'ttd_u'], offdesign=['zeta1', 'zeta2', 'kA']) HeatPump.erp.set_attr(eta_s=self.eff, design=['eta_s'], offdesign=['eta_s_char']) # compressor system HeatPump.cp1.set_attr(eta_s=self.eff, design=['eta_s'], offdesign=['eta_s_char']) HeatPump.cp2.set_attr(eta_s=self.eff, pr=3, design=['eta_s'], offdesign=['eta_s_char']) HeatPump.ic.set_attr(pr1=0.99, pr2=0.98, design=['pr1', 'pr2'], offdesign=['zeta1', 'zeta2', 'kA']) # %% connection parametrization # condenser system HeatPump.c_in_cd.set_attr(fluid={'air': 0, 'NH3': 1, 'water': 0}) HeatPump.cb_dhp.set_attr(T=20, p=10, fluid={ 'air': 0, 'NH3': 0, 'water': 1 }) HeatPump.cd_cons.set_attr(T=self.Temp) HeatPump.cons_cf.set_attr(h=ref(HeatPump.cb_dhp, 1, 0), p=ref(HeatPump.cb_dhp, 1, 0)) # evaporator system cold side HeatPump.erp_ev.set_attr(m=ref(HeatPump.ves_dr, 1.25, 0), p0=5) HeatPump.su_cp1.set_attr(p0=5, h0=1700) # evaporator system hot side # pumping at constant rate in partload HeatPump.amb_p.set_attr(T=12, p=2, fluid={ 'air': 0, 'NH3': 0, 'water': 1 }, offdesign=['v']) HeatPump.sp_su.set_attr(offdesign=['v']) HeatPump.ev_amb_out.set_attr(p=2, T=9, design=['T']) # compressor-system HeatPump.he_cp2.set_attr(Td_bp=5, p0=20, design=['Td_bp']) HeatPump.ic_out.set_attr(T=15, design=['T']) # %% key paramter HeatPump.cons.set_attr(Q=self.q)
def test_set_attr_errors(self): # labels = [5, 'Label,', 'Labe;l', 'Label.'] for l in labels: self.cmp_instanciation_ValueError(l) # ValueErrors self.set_attr_ValueError(self.comp, offdesign=['Q']) self.set_attr_ValueError(self.conn, offdesign=['f']) self.set_attr_ValueError(self.conn, state='f') self.set_attr_ValueError(self.nw, m_unit='kg') self.set_attr_ValueError(self.nw, h_unit='kg') self.set_attr_ValueError(self.nw, p_unit='kg') self.set_attr_ValueError(self.nw, T_unit='kg') self.set_attr_ValueError(self.nw, v_unit='kg') self.create_connection_ValueError('source') self.create_connection_ValueError('target') # TypeErrors self.set_attr_TypeError(self.comp, P=[5]) self.set_attr_TypeError(self.comp, tiP_char=None) self.set_attr_TypeError(self.comp, design='f') self.set_attr_TypeError(self.comp, design_path=7) self.set_attr_TypeError(self.comp, local_design=5) self.set_attr_TypeError(self.comp, local_offdesign=5) self.set_attr_TypeError(self.pipe, hydro_group=5) self.set_attr_TypeError(self.comp, printout=5) self.set_attr_TypeError(self.conn, design='h') self.set_attr_TypeError(self.conn, fluid_balance=1) self.set_attr_TypeError(self.conn, h0=[4]) self.set_attr_TypeError(self.conn, fluid=5) self.set_attr_TypeError(self.conn, state=5) self.set_attr_TypeError(self.conn, design_path=5) self.set_attr_TypeError(self.conn, local_design=5) self.set_attr_TypeError(self.conn, local_offdesign=5) self.set_attr_TypeError(self.conn, printout=5) self.set_attr_TypeError(self.nw, m_range=5) self.set_attr_TypeError(self.nw, p_range=5) self.set_attr_TypeError(self.nw, h_range=5) self.set_attr_TypeError(self.nw, T_range=5) self.set_attr_TypeError(self.nw, iterinfo=5) self.set_attr_TypeError(self.bus, P='some value') self.set_attr_TypeError(self.bus, printout=5) self.bus_add_comps_TypeError({'c': self.conn}) self.bus_add_comps_TypeError({'f': self.comp}) self.bus_add_comps_TypeError({'c': self.comp, 'char': 'Hi'}) self.bus_add_comps_TypeError({'c': self.comp, 'p': 5}) self.bus_add_comps_TypeError({'c': self.comp, 'P_ref': 'what'}) self.create_ref_TypeError([self.conn, 7, 'hi']) self.create_ref_TypeError([self.conn, 'hi', 0]) self.create_ref_TypeError([self.comp, 1, 0]) # KeyErrors self.set_attr_KeyError(self.comp, wow=5) self.set_attr_KeyError(self.conn, jey=5) self.set_attr_KeyError(self.bus, power_output=100000) self.get_attr_KeyError(self.comp, 'wow') self.get_attr_KeyError(self.conn, 'key') self.get_attr_KeyError(self.bus, 'components') self.get_attr_KeyError(self.nw, 'missing') self.get_attr_KeyError(ref(self.conn, 1, 0), 'comp') self.get_attr_KeyError(self.sub, 'test') self.get_attr_KeyError(char_line(), 'test') self.get_attr_KeyError(data_container(), 'somekey')
def create_ref_TypeError(params): with raises(TypeError): ref(params[0], params[1], params[2])
he.set_attr(pr1=0.98, pr2=0.98, design=['pr1', 'pr2'], offdesign=['zeta1', 'zeta2', 'kA']) # %% connection parametrization # condenser system c_in_cd.set_attr(fluid={'water': 0, 'NH3': 1}) close_rp.set_attr(T=60, p=10, fluid={'water': 1, 'NH3': 0}) cd_cons.set_attr(T=90) # evaporator system cold side pu_ev.set_attr(m=ref(va_dr, 0.75, 0), p0=5) su_cp1.set_attr(p0=5, h0=1700) # evaporator system hot side amb_in_su.set_attr(T=12, p=1, fluid={'water': 1, 'NH3': 0}) ev_amb_out.set_attr(T=9) he_cp2.set_attr(T=40, p0=10) ic_in_he.set_attr(p=5, T=20, fluid={'water': 1, 'NH3': 0}) he_ic_out.set_attr(T=30, design=['T']) # %% key paramter cons.set_attr(Q=-230e3)
cons.set_attr(D=2, L=0.1, ks=0.00001) # busses heat = bus('consumer heat demand') heat.add_comps({'c': cons, 'p': 'P'}) btes.add_busses(heat) # consumer heat demand heat.set_attr(P=-3000) # W ## connection parametrization # system inlet inflow_head = 2 # bar fc_pu.set_attr(p=inflow_head, m=0.6, fluid={'water': 1}) # for BHEs: # Tout: bhe1_mg.set_attr(T=303.15) bhe2_mg.set_attr(T=303.15) bhe3_mg.set_attr(T=303.15) # imposed boundary condition: ensure all heat from BHEs are consumed on 'consumer' pu_sp.set_attr(h=ref(cons_fc, 1, 0)) # %% solve btes.solve('design') #btes.print_results() # %% save to csv: btes.save('tespy_nw', structure=True)
def __init__(self, working_fluid): self.working_fluid = working_fluid fluids = ['water', self.working_fluid, 'air'] self.nw = network(fluids=fluids) self.nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg') # geo parameters geo_mass_flow = 210 geo_steam_share = 0.1 T_brine_in = 144.8 T_reinjection = 70.8 # ambient parameters T_amb = 0 p_amb = 1 # main components geo_steam = source('steam source') geo_brine = source('brine source') geo_reinjection = sink('reinjection well') air_in = source('ambient air source') air_out = sink('ambient air sink') air_cond = condenser('main condenser') orc_cc = cycle_closer('orc cycle closer') evap_steam = condenser('steam evaporator') evap_splitter = splitter('splitter evaporation') evap_merge = merge('merge evaporation') evap_steam = condenser('steam evaporator') geo_steam_pump = pump('geosteam condensate pump') evap_brine = heat_exchanger('brine evaporator') dr = drum('drum') eco = heat_exchanger('economiser') feed_water_pump = pump('feed water pump') geo_merge = merge('brine merge') tur = turbine('turbine') ls_valve = valve('live steam valve') ihe = heat_exchanger('internal heat exchanger') # busses power_bus = bus('power output') power_bus.add_comps({ 'c': tur, 'char': -1 }, { 'c': feed_water_pump, 'char': -1 }, { 'c': geo_steam_pump, 'char': -1 }) geothermal_bus = bus('thermal input') geothermal_bus.add_comps({ 'c': eco, 'char': -1 }, { 'c': evap_brine, 'char': -1 }, { 'c': evap_steam, 'char': -1 }) self.nw.add_busses(power_bus, geothermal_bus) # turbine to condenser ls_in = connection(orc_cc, 'out1', ls_valve, 'in1') lsv_tur = connection(ls_valve, 'out1', tur, 'in1') tur_ihe = connection(tur, 'out1', ihe, 'in1') ihe_cond = connection(ihe, 'out1', air_cond, 'in1') self.nw.add_conns(ls_in, lsv_tur, tur_ihe, ihe_cond) # condenser to steam generator cond_fwp = connection(air_cond, 'out1', feed_water_pump, 'in1') fwp_ihe = connection(feed_water_pump, 'out1', ihe, 'in2') self.nw.add_conns(cond_fwp, fwp_ihe) # steam generator ihe_eco = connection(ihe, 'out2', eco, 'in2') eco_dr = connection(eco, 'out2', dr, 'in1') dr_esp = connection(dr, 'out1', evap_splitter, 'in1') esp_eb = connection(evap_splitter, 'out1', evap_brine, 'in2') esp_es = connection(evap_splitter, 'out2', evap_steam, 'in2') eb_em = connection(evap_brine, 'out2', evap_merge, 'in1') es_em = connection(evap_steam, 'out2', evap_merge, 'in2') em_dr = connection(evap_merge, 'out1', dr, 'in2') ls_out = connection(dr, 'out2', orc_cc, 'in1') self.nw.add_conns(ihe_eco, eco_dr, dr_esp, esp_eb, esp_es, eb_em, es_em, em_dr, ls_out) # air cold side air_cold = connection(air_in, 'out1', air_cond, 'in2') air_hot = connection(air_cond, 'out2', air_out, 'in1') self.nw.add_conns(air_cold, air_hot) # geo source gs_es = connection(geo_steam, 'out1', evap_steam, 'in1', label='geosteam') es_gsp = connection(evap_steam, 'out1', geo_steam_pump, 'in1') gsp_gm = connection(geo_steam_pump, 'out1', geo_merge, 'in1') gb_eb = connection(geo_brine, 'out1', evap_brine, 'in1', label='geobrine') eb_gm = connection(evap_brine, 'out1', geo_merge, 'in2') self.nw.add_conns(gs_es, es_gsp, gsp_gm, gb_eb, eb_gm) gm_eco = connection(geo_merge, 'out1', eco, 'in1') eco_gr = connection(eco, 'out1', geo_reinjection, 'in1', label='reinjection') self.nw.add_conns(gm_eco, eco_gr) # fluid settings ihe_eco.set_attr(fluid={self.working_fluid: 1, 'air': 0, 'water': 0}) air_cold.set_attr(fluid={self.working_fluid: 0, 'air': 1, 'water': 0}) gs_es.set_attr(fluid={self.working_fluid: 0, 'air': 0, 'water': 1}) gb_eb.set_attr(fluid={self.working_fluid: 0, 'air': 0, 'water': 1}) # connection parameters ls_stable_p0 = PSI('P', 'T', T_brine_in + 273.15, 'Q', 1, self.working_fluid) / 1e5 lsv_tur.set_attr(p0=ls_stable_p0) ws_stable_h0 = ( PSI('H', 'T', T_amb + 273.15, 'Q', 1, self.working_fluid) + 0.5 * (PSI('H', 'T', T_brine_in + 273.15, 'Q', 1, self.working_fluid) - PSI('H', 'T', T_amb + 273.15, 'Q', 1, self.working_fluid))) / 1e3 tur_ihe.set_attr(h=ws_stable_h0) ihe_cond.set_attr( Td_bp=2, design=['Td_bp'], p0=PSI('P', 'T', T_amb + 273.15, 'Q', 1, self.working_fluid) / 1e5) fwp_ihe.set_attr(h=ref(cond_fwp, 1, 1e3)) # steam generator gs_es.set_attr(m=geo_mass_flow * geo_steam_share, T=T_brine_in, x=1, p0=5) gb_eb.set_attr(m=geo_mass_flow * (1 - geo_steam_share), T=T_brine_in, x=0) em_dr.set_attr() eb_em.set_attr(x=0.5) es_em.set_attr(x=0.5, design=['x']) eb_gm.set_attr(T=T_brine_in - 20) eco_dr.set_attr(Td_bp=-2) # main condenser air_cold.set_attr(p=p_amb, T=T_amb) air_hot.set_attr(T=15) # component parameters # turbines tur.set_attr(design=['eta_s'], offdesign=['cone', 'eta_s_char']) ls_valve.set_attr(pr=1, design=['pr']) # condensing ihe.set_attr(pr1=1, pr2=1, offdesign=['kA_char']) air_cond.set_attr(pr1=1, pr2=1, ttd_u=10, design=['ttd_u'], offdesign=['kA_char']) feed_water_pump.set_attr(design=['eta_s'], offdesign=['eta_s_char']) # steam generator evap_steam.set_attr( pr1=0.99, offdesign=['kA_char']) # no pr2 due to drum pressure balance evap_brine.set_attr( pr1=1, ttd_l=10, offdesign=['kA_char']) # no pr2 due to drum pressure balance eco.set_attr(pr1=1, pr2=1) geo_steam_pump.set_attr(eta_s=0.75, design=['eta_s'], offdesign=['eta_s_char']) self.nw.set_attr(iterinfo=False) self.nw.solve('design') self.nw.print_results() tur.set_attr(eta_s=0.9) feed_water_pump.set_attr(eta_s=0.75) tur_ihe.set_attr(h=None) fwp_ihe.set_attr(h=None) eb_gm.set_attr(T=None)
cond.set_attr(pr1=0.99, pr2=0.98, design=['pr2'], offdesign=['zeta2', 'kA_char']) pu.set_attr(eta_s=0.75, design=['eta_s'], offdesign=['eta_s_char']) # %% connection parameters # gas turbine c_in.set_attr( T=20, p=1, m=250, fluid={ 'Ar': 0.0129, 'N2': 0.7553, 'H2O': 0, 'CH4': 0, 'CO2': 0.0004, 'O2': 0.2314 }, design=['m'] ) gt_in.set_attr(T=1200) gt_out.set_attr(p0=1) fuel.set_attr( T=ref(c_in, 1, 0), h0=800, fluid={ 'CO2': 0.04, 'Ar': 0, 'N2': 0, 'O2': 0, 'H2O': 0, 'CH4': 0.96 } ) # waste heat recovery eco_dh.set_attr(T=290, design=['T'], p0=1) dh_ch.set_attr(T=100, design=['T'], p=1) # steam turbine evap_drum.set_attr(m=ref(drum_suph, 4, 0)) suph_ls.set_attr( p=100, T=550, fluid={ 'CO2': 0, 'Ar': 0, 'N2': 0, 'O2': 0, 'H2O': 1, 'CH4': 0 }, design=['p', 'T'] )