def test_compressor_missing_char_parameter(): """Compressor with invalid parameter for eta_s_char function.""" nw = network(['CH4']) so = basics.source('source') si = basics.sink('sink') instance = turbomachinery.compressor('compressor') c1 = connection(so, 'out1', instance, 'in1') c2 = connection(instance, 'out1', si, 'in1') nw.add_conns(c1, c2) instance.set_attr(eta_s_char=dc_cc( func=char_line([0, 1], [1, 2]), is_set=True, param=None)) nw.solve('design', init_only=True) with raises(ValueError): instance.eta_s_char_func()
def setup_combustion_chamber_model(self): """Set up the model using the combustion chamber.""" # %% network setup fluid_list = ['Ar', 'N2', 'O2', 'CO2', 'CH4', 'H2O'] self.nw1 = network( fluids=fluid_list, p_unit='bar', T_unit='C', p_range=[0.5, 20], T_range=[10, 2000]) # %% components amb = source('ambient') sf = source('fuel') cc = combustion_chamber('combustion') cp = compressor('compressor') gt = turbine('turbine') fg = sink('flue gas outlet') # %% connections amb_cp = connection(amb, 'out1', cp, 'in1') cp_cc = connection(cp, 'out1', cc, 'in1') sf_cc = connection(sf, 'out1', cc, 'in2') cc_gt = connection(cc, 'out1', gt, 'in1', label='flue gas after cc') gt_fg = connection(gt, 'out1', fg, 'in1', label='flue gas after gt') self.nw1.add_conns(amb_cp, cp_cc, sf_cc, cc_gt, gt_fg) # %% component parameters cc.set_attr(lamb=3) cp.set_attr(eta_s=0.9, pr=15) gt.set_attr(eta_s=0.9) # %% connection parameters amb_cp.set_attr( T=20, p=1, m=100, fluid={'Ar': 0.0129, 'N2': 0.7553, 'H2O': 0, 'CH4': 0, 'CO2': 0.0004, 'O2': 0.2314}) sf_cc.set_attr( T=20, fluid={'CO2': 0.04, 'Ar': 0, 'N2': 0, 'O2': 0, 'H2O': 0, 'CH4': 0.96}) gt_fg.set_attr(p=1) # %% solving mode = 'design' self.nw1.solve(mode=mode)
def test_network_reader_deleted_chars(self): """Test import of network with missing characteristics.""" self.setup_network_tests() comp = turbomachinery.compressor('compressor') a = connection(self.source, 'out1', comp, 'in1') b = connection(comp, 'out1', self.sink, 'in1') self.nw.add_conns(a, b) self.nw.solve('design', init_only=True) self.nw.save('tmp') # # remove char_line and char_map folders os.unlink('tmp/components/char_line.csv') os.unlink('tmp/components/char_map.csv') # import network with missing files imported_nwk = load_network('tmp') imported_nwk.solve('design', init_only=True) msg = ('If the network import was successful the network check ' 'should have been successful, too, but it is not.') assert imported_nwk.checked is True, msg shutil.rmtree('./tmp', ignore_errors=True)
def test_compressor(self): """Test component properties of compressors.""" instance = compressor('compressor') self.setup_network(instance) # compress NH3, other fluids in network are for turbine, pump, ... fl = {'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'NH3': 1} self.c1.set_attr(fluid=fl, v=1, p=5, T=100) self.c2.set_attr(p=7) instance.set_attr(eta_s=0.8) self.nw.solve('design') self.nw.save('tmp') # test isentropic efficiency value eta_s_d = ((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_d) + ', is ' + str(instance.eta_s.val) + '.') eq_(round(eta_s_d, 3), round(instance.eta_s.val, 3), msg) # trigger invalid value for isentropic efficiency instance.set_attr(eta_s=1.1) self.nw.solve('design') # test calculated value 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_(round(eta_s, 3), round(instance.eta_s.val, 3), msg) # remove pressure at outlet, use characteristic map for pressure # rise calculation self.c2.set_attr(p=np.nan) instance.set_attr(char_map=dc_cm(func=ldc('compressor', 'char_map', 'DEFAULT', compressor_map), is_set=True), eta_s=np.nan) # offdesign test, efficiency value should be at design value self.nw.solve('offdesign', design_path='tmp') msg = ('Value of isentropic efficiency (' + str(instance.eta_s.val) + ') must be identical to design case (' + str(eta_s) + ').') eq_(round(eta_s_d, 2), round(instance.eta_s.val, 2), msg) # move to highest available speedline, mass flow below lowest value # at that line self.c1.set_attr(v=np.nan, m=self.c1.m.val * 0.8, T=30) self.nw.solve('offdesign', design_path='tmp') # should be value eta_s = eta_s_d * instance.char_map.func.z2[6, 0] msg = ('Value of isentropic efficiency (' + str(instance.eta_s.val) + ') must be at (' + str(round(eta_s, 4)) + ').') eq_(round(eta_s, 4), round(instance.eta_s.val, 4), msg) # going below lowest available speedline, above highest mass flow at # that line self.c1.set_attr(T=300) self.nw.solve('offdesign', design_path='tmp', init_path='tmp') # should be value eta_s = eta_s_d * instance.char_map.func.z2[0, 9] msg = ('Value of isentropic efficiency (' + str(instance.eta_s.val) + ') must be at (' + str(round(eta_s, 4)) + ').') eq_(round(eta_s, 4), round(instance.eta_s.val, 4), msg) # back to design properties, test eta_s_char self.c2.set_attr(p=7) self.c1.set_attr(v=1, T=100, m=np.nan) # test parameter specification for eta_s_char with unset char map instance.set_attr(eta_s_char=dc_cc(func=ldc('compressor', 'eta_s_char', 'DEFAULT', char_line), is_set=True, param='m')) instance.char_map.is_set = False self.nw.solve('offdesign', design_path='tmp') msg = ('Value of isentropic efficiency must be ' + str(eta_s_d) + ', is ' + str(instance.eta_s.val) + '.') eq_(round(eta_s_d, 3), round(instance.eta_s.val, 3), msg) # move up in volumetric flow self.c1.set_attr(v=1.5) self.nw.solve('offdesign', design_path='tmp') eta_s = round( eta_s_d * instance.eta_s_char.func.evaluate( self.c1.m.val_SI / self.c1.m.design), 3) msg = ('Value of isentropic efficiency must be ' + str(eta_s) + ', is ' + str(round(instance.eta_s.val, 3)) + '.') eq_(eta_s, round(instance.eta_s.val, 3), msg) # test parameter specification for pr instance.eta_s_char.set_attr(param='pr') self.c1.set_attr(v=1) self.c2.set_attr(p=7.5) self.nw.solve('offdesign', design_path='tmp') expr = (self.c2.p.val_SI * self.c1.p.design / (self.c2.p.design * self.c1.p.val_SI)) eta_s = round(eta_s_d * instance.eta_s_char.func.evaluate(expr), 3) msg = ('Value of isentropic efficiency must be ' + str(eta_s) + ', is ' + str(round(instance.eta_s.val, 3)) + '.') eq_(eta_s, round(instance.eta_s.val, 3), msg) shutil.rmtree('./tmp', ignore_errors=True)
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 setup(self): """Set up the model.""" # %% network setup fluid_list = ['Ar', 'N2', 'O2', 'CO2', 'CH4', 'H2O'] self.nw = network(fluids=fluid_list, p_unit='bar', T_unit='C', p_range=[0.5, 20], T_range=[10, 2000]) # %% components amb = source('ambient') sf = source('fuel') cc = combustion_chamber('combustion') cp = compressor('compressor') gt = turbine('turbine') fg = sink('flue gas outlet') # %% connections amb_cp = connection(amb, 'out1', cp, 'in1', label='ambient air flow') cp_cc = connection(cp, 'out1', cc, 'in1') sf_cc = connection(sf, 'out1', cc, 'in2') cc_gt = connection(cc, 'out1', gt, 'in1') gt_fg = connection(gt, 'out1', fg, 'in1') self.nw.add_conns(amb_cp, cp_cc, sf_cc, cc_gt, gt_fg) # %% component parameters cc.set_attr(lamb=3) cp.set_attr(eta_s=0.9, pr=15) gt.set_attr(eta_s=0.9) # %% connection parameters amb_cp.set_attr(T=20, p=1, m=100, fluid={ 'Ar': 0.0129, 'N2': 0.7553, 'H2O': 0, 'CH4': 0, 'CO2': 0.0004, 'O2': 0.2314 }) sf_cc.set_attr(T=20, fluid={ 'CO2': 0.04, 'Ar': 0, 'N2': 0, 'O2': 0, 'H2O': 0, 'CH4': 0.96 }) gt_fg.set_attr(p=1) # motor efficiency x = np.array([ 0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2, 10 ]) y = np.array([ 0.01, 0.3148, 0.5346, 0.6843, 0.7835, 0.8477, 0.8885, 0.9145, 0.9318, 0.9443, 0.9546, 0.9638, 0.9724, 0.9806, 0.9878, 0.9938, 0.9982, 0.999, 0.9995, 0.9999, 1, 0.9977, 0.9947, 0.9909, 0.9853, 0.9644 ]) * 0.975 self.motor_bus_based = char_line(x=x, y=y) self.motor_comp_based = char_line(x=x, y=1 / y) # generator efficiency x = np.array([ 0.100, 0.345, 0.359, 0.383, 0.410, 0.432, 0.451, 0.504, 0.541, 0.600, 0.684, 0.805, 1.000, 1.700, 10 ]) y = np.array([ 0.976, 0.989, 0.990, 0.991, 0.992, 0.993, 0.994, 0.995, 0.996, 0.997, 0.998, 0.999, 1.000, 0.999, 0.99 ]) * 0.975 self.generator = char_line(x=x, y=y) power_bus_total = bus('total power output') power_bus_total.add_comps( { 'comp': cp, 'char': self.motor_bus_based, 'base': 'bus' }, { 'comp': gt, 'char': self.generator }) thermal_input = bus('thermal input') thermal_input.add_comps({'comp': cc}) compressor_power_comp = bus('compressor power input') compressor_power_comp.add_comps({ 'comp': cp, 'char': self.motor_comp_based }) compressor_power_bus = bus('compressor power input bus based') compressor_power_bus.add_comps({ 'comp': cp, 'char': self.motor_bus_based, 'base': 'bus' }) self.nw.add_busses(power_bus_total, thermal_input, compressor_power_comp, compressor_power_bus) # %% solving self.nw.solve('design') self.nw.save('tmp')
Q_N = abs(float(input('Gib die Nennwaermeleistung in MW ein: '))) * -1e6 # %% network fluid_list = ['Ar', 'N2', 'O2', 'CO2', 'CH4', 'H2O'] nw = 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 = compressor('compressor') comp_fuel = compressor('fuel compressor') c_c = combustion_chamber('combustion') g_turb = turbine('gas turbine') CH4 = source('fuel source') air = source('ambient air') # waste heat recovery suph = heat_exchanger('superheater') evap = heat_exchanger('evaporator') drum = drum('drum') eco = heat_exchanger('economizer') ch = sink('chimney') # steam turbine part