def test_compressor(self): """ Test component properties of compressors. """ instance = cmp.compressor('compressor') c1, c2 = self.setup_network_11(instance) fl = {'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'H2O': 0, 'NH3': 1, 'CO2': 0, 'CH4': 0} c1.set_attr(fluid=fl, v=1, p=5, T=100) c2.set_attr(p=7) instance.set_attr(eta_s=0.8) self.nw.solve('design') self.nw.save('tmp') # calculate isentropic efficiency the old fashioned way eta_s_d = (instance.h_os('') - c1.h.val_SI) / (c2.h.val_SI - c1.h.val_SI) eq_(round(eta_s_d, 3), round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(eta_s_d) + ', is ' + str(instance.eta_s.val) + '.') # trigger invalid isentropic efficiency instance.set_attr(eta_s=1.1) self.nw.solve('design') # calculate isentropic efficiency the old fashioned way eta_s = (instance.h_os('') - c1.h.val_SI) / (c2.h.val_SI - c1.h.val_SI) eq_(round(eta_s, 3), round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(eta_s) + ', is ' + str(instance.eta_s.val) + '.') c2.set_attr(p=np.nan) instance.set_attr(char_map=hlp.dc_cm(method='GENERIC', is_set=True), eta_s=np.nan) self.nw.solve('offdesign', design_path='tmp') eta_s = (instance.h_os('') - c1.h.val_SI) / (c2.h.val_SI - c1.h.val_SI) eq_(round(eta_s, 2), round(instance.eta_s.val, 2), 'Value of isentropic efficiency (' + str(instance.eta_s.val) + ') must be identical to design case (' + str(eta_s) + ').') # going above highes available speedline, beneath lowest mass flow at that line c1.set_attr(v=np.nan, m=c1.m.val*0.8, T=30) self.nw.solve('offdesign', design_path='tmp') eq_(round(eta_s * instance.char_map.z2[6, 0], 4), round(instance.eta_s.val, 4), 'Value of isentropic efficiency (' + str(instance.eta_s.val) + ') must be at (' + str(round(eta_s * instance.char_map.z2[6, 0], 4)) + ').') # going below lowest available speedline, above highest mass flow at that line c1.set_attr(T=300) self.nw.solve('offdesign', design_path='tmp') eq_(round(eta_s * instance.char_map.z2[0, 9], 4), round(instance.eta_s.val, 4), 'Value of isentropic efficiency (' + str(instance.eta_s.val) + ') must be at (' + str(round(eta_s * instance.char_map.z2[0, 9], 4)) + ').') # back to design properties, test eta_s_char c2.set_attr(p=7) c1.set_attr(v=1, T=100, m=np.nan) # test param specification m instance.set_attr(eta_s_char=hlp.dc_cc(method='GENERIC', is_set=True, param='m')) instance.char_map.is_set = False self.nw.solve('offdesign', design_path='tmp') eq_(round(eta_s, 3), round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(eta_s) + ', is ' + str(instance.eta_s.val) + '.') c1.set_attr(v=1.5) self.nw.solve('offdesign', design_path='tmp') eq_(0.88, round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(0.88) + ', is ' + str(instance.eta_s.val) + '.') # test param specification pr instance.eta_s_char.set_attr(param='pr') c1.set_attr(v=1) c2.set_attr(p=7.5) self.nw.solve('offdesign', design_path='tmp') eq_(0.829, round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(0.829) + ', is ' + str(instance.eta_s.val) + '.') instance.eta_s_char.set_attr(param=None) # test for missing parameter declaration try: self.nw.solve('offdesign', design_path='tmp') except ValueError: pass shutil.rmtree('./tmp', ignore_errors=True)
m_unit='kg / s') # %% components # sources & sinks c_in = cmp.source('coolant in') cb = cmp.source('consumer back flow') cf = cmp.sink('consumer feed flow') amb = cmp.source('ambient air') amb_out1 = cmp.sink('sink ambient 1') amb_out2 = cmp.sink('sink ambient 2') c_out = cmp.sink('coolant out') # ambient air system sp = cmp.splitter('splitter') fan = cmp.compressor('fan') # consumer system cd = cmp.condenser('condenser') dhp = cmp.pump('district heating pump') cons = cmp.heat_exchanger_simple('consumer') # evaporator system ves = cmp.valve('valve') dr = cmp.drum('drum') ev = cmp.heat_exchanger('evaporator') su = cmp.heat_exchanger('superheater') erp = cmp.pump('evaporator reciculation pump')
from tespy import cmp, con, nwk, hlp # %% network fluid_list = ['Ar', 'N2', 'O2', 'CO2', 'CH4', 'H2O'] nw = nwk.network(fluids=fluid_list, p_unit='bar', T_unit='C', h_unit='kJ / kg', p_range=[1, 10], T_range=[110, 1500], h_range=[500, 4000]) # %% components # gas turbine part comp = cmp.compressor('compressor') c_c = cmp.combustion_chamber('combustion') g_turb = cmp.turbine('gas turbine') CH4 = cmp.source('fuel source') air = cmp.source('ambient air') # waste heat recovery suph = cmp.heat_exchanger('superheater') evap = cmp.heat_exchanger('evaporator') drum = cmp.drum('drum') eco = cmp.heat_exchanger('economizer') dh_whr = cmp.heat_exchanger('waste heat recovery') ch = cmp.sink('chimney') # steam turbine part
def setup(self): # %% network self.nw = nwk.network(fluids=['water', 'NH3'], T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s') # %% components # sources & sinks c_in = cmp.source('coolant in') cb = cmp.source('consumer back flow') cf = cmp.sink('consumer feed flow') amb_in = cmp.source('source ambient') amb_out = cmp.sink('sink ambient') ic_in = cmp.source('source intercool') ic_out = cmp.sink('sink intercool') c_out = cmp.sink('coolant out') # consumer system cd = cmp.heat_exchanger('condenser') rp = cmp.pump('recirculation pump') cons = cmp.heat_exchanger_simple('consumer') # evaporator system va = cmp.valve('valve') dr = cmp.drum('drum') ev = cmp.heat_exchanger('evaporator') su = cmp.heat_exchanger('superheater') pu = cmp.pump('pump evaporator') # compressor-system cp1 = cmp.compressor('compressor 1') cp2 = cmp.compressor('compressor 2') he = cmp.heat_exchanger('intercooler') # busses x = np.array([0, 0.7, 1, 1.3]) y = 1 / np.array([0.8, 0.95, 1, 0.98]) / 0.9583794 motor = cmp_char.characteristics(x=x, y=y) self.power = con.bus('total compressor power') self.power.add_comps({ 'c': cp1, 'char': motor }, { 'c': cp2, 'char': motor }) self.heat = con.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 = con.connection(c_in, 'out1', cd, 'in1') cb_rp = con.connection(cb, 'out1', rp, 'in1') rp_cd = con.connection(rp, 'out1', cd, 'in2') self.cd_cons = con.connection(cd, 'out2', cons, 'in1') cons_cf = con.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 = con.connection(cd, 'out1', va, 'in1') self.nw.add_conns(cd_va) # evaporator system va_dr = con.connection(va, 'out1', dr, 'in1') dr_pu = con.connection(dr, 'out1', pu, 'in1') pu_ev = con.connection(pu, 'out1', ev, 'in2') ev_dr = con.connection(ev, 'out2', dr, 'in2') dr_su = con.connection(dr, 'out2', su, 'in2') self.nw.add_conns(va_dr, dr_pu, pu_ev, ev_dr, dr_su) self.amb_in_su = con.connection(amb_in, 'out1', su, 'in1') su_ev = con.connection(su, 'out1', ev, 'in1') ev_amb_out = con.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 = con.connection(su, 'out2', cp1, 'in1') self.nw.add_conns(su_cp1) # compressor-system cp1_he = con.connection(cp1, 'out1', he, 'in1') he_cp2 = con.connection(he, 'out1', cp2, 'in1') cp2_c_out = con.connection(cp2, 'out1', c_out, 'in1') ic_in_he = con.connection(ic_in, 'out1', he, 'in2') he_ic_out = con.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 rp.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char']) cons.set_attr(pr=1, design=['pr'], offdesign=['zeta']) # evaporator system ev.set_attr(pr1=1, pr2=.999, ttd_l=5, design=['ttd_l'], offdesign=['kA'], kA_char1='EVA_HOT', kA_char2='EVA_COLD') # 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]) su_char = hlp.dc_cc(x=x, y=y, param='m') su.set_attr(kA_char1='default', kA_char2=su_char, offdesign=['zeta1', 'zeta2', 'kA']) pu.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char']) # compressor system cp1.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char']) cp2.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char']) # characteristic line for intercooler kA 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 ]) he_char_cold = hlp.dc_cc(x=x, y=y, param='m') he.set_attr(kA_char1='default', kA_char2=he_char_cold, offdesign=['zeta1', 'zeta2', 'kA']) cd.set_attr(pr2=0.998, design=['pr2'], offdesign=['zeta2', 'kA']) # %% connection parametrization # condenser system c_in_cd.set_attr(fluid={'water': 0, 'NH3': 1}, p=60) cb_rp.set_attr(T=60, p=10, fluid={'water': 1, 'NH3': 0}) self.cd_cons.set_attr(T=105) cons_cf.set_attr(h=con.ref(cb_rp, 1, 0), p=con.ref(cb_rp, 1, 0)) cd_va.set_attr(p=con.ref(c_in_cd, 1, -1000), Td_bp=-5, h0=500, design=['Td_bp']) # evaporator system cold side pu_ev.set_attr(m=con.ref(va_dr, 10, 0), p0=5) dr_su.set_attr(p0=5, T=5) su_cp1.set_attr(p=con.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=con.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=con.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=con.ref(ic_in_he, 1, -200), design=['p']) cp2_c_out.set_attr(p=con.ref(c_in_cd, 1, 0), h=con.ref(c_in_cd, 1, 0))
@author: witte """ from tespy import cmp, con, nwk, hlp, cmp_char, nwkr import numpy as np from matplotlib import pyplot as plt # %% network fluid_list = ['Ar', 'N2', 'O2', 'CO2', 'CH4', 'H2O'] nw = nwk.network(fluids=fluid_list, p_unit='bar', T_unit='C', h_unit='kJ / kg', p_range=[1, 100], T_range=[10, 1500], h_range=[10, 4000]) # %% components # gas turbine part comp = cmp.compressor('compressor') comp_fuel = cmp.compressor('fuel compressor') c_c = cmp.combustion_chamber('combustion') g_turb = cmp.turbine('gas turbine') CH4 = cmp.source('fuel source') air = cmp.source('ambient air') # waste heat recovery suph = cmp.heat_exchanger('superheater') evap = cmp.heat_exchanger('evaporator') drum = cmp.drum('drum') eco = cmp.heat_exchanger('economizer') ch = cmp.sink('chimney') # steam turbine part