class PowerPlant(): def __init__(self): self.nw = Network(fluids=['BICUBIC::water'], p_unit='bar', T_unit='C', h_unit='kJ / kg', iterinfo=False) # components # main cycle eco = HeatExchangerSimple('economizer') eva = HeatExchangerSimple('evaporator') sup = HeatExchangerSimple('superheater') cc = CycleCloser('cycle closer') hpt = Turbine('high pressure turbine') sp1 = Splitter('splitter 1', num_out=2) mpt = Turbine('mid pressure turbine') sp2 = Splitter('splitter 2', num_out=2) lpt = Turbine('low pressure turbine') con = Condenser('condenser') pu1 = Pump('feed water pump') fwh1 = Condenser('feed water preheater 1') fwh2 = Condenser('feed water preheater 2') dsh = Desuperheater('desuperheater') me2 = Merge('merge2', num_in=2) pu2 = Pump('feed water pump 2') pu3 = Pump('feed water pump 3') me = Merge('merge', num_in=2) # cooling water cwi = Source('cooling water source') cwo = Sink('cooling water sink') # connections # main cycle cc_hpt = Connection(cc, 'out1', hpt, 'in1', label='feed steam') hpt_sp1 = Connection(hpt, 'out1', sp1, 'in1', label='extraction1') sp1_mpt = Connection(sp1, 'out1', mpt, 'in1', state='g') mpt_sp2 = Connection(mpt, 'out1', sp2, 'in1', label='extraction2') sp2_lpt = Connection(sp2, 'out1', lpt, 'in1') lpt_con = Connection(lpt, 'out1', con, 'in1') con_pu1 = Connection(con, 'out1', pu1, 'in1') pu1_fwh1 = Connection(pu1, 'out1', fwh1, 'in2') fwh1_me = Connection(fwh1, 'out2', me, 'in1', state='l') me_fwh2 = Connection(me, 'out1', fwh2, 'in2', state='l') fwh2_dsh = Connection(fwh2, 'out2', dsh, 'in2', state='l') dsh_me2 = Connection(dsh, 'out2', me2, 'in1') me2_eco = Connection(me2, 'out1', eco, 'in1', state='l') eco_eva = Connection(eco, 'out1', eva, 'in1') eva_sup = Connection(eva, 'out1', sup, 'in1') sup_cc = Connection(sup, 'out1', cc, 'in1') self.nw.add_conns(cc_hpt, hpt_sp1, sp1_mpt, mpt_sp2, sp2_lpt, lpt_con, con_pu1, pu1_fwh1, fwh1_me, me_fwh2, fwh2_dsh, dsh_me2, me2_eco, eco_eva, eva_sup, sup_cc) # cooling water cwi_con = Connection(cwi, 'out1', con, 'in2') con_cwo = Connection(con, 'out2', cwo, 'in1') self.nw.add_conns(cwi_con, con_cwo) # preheating sp1_dsh = Connection(sp1, 'out2', dsh, 'in1') dsh_fwh2 = Connection(dsh, 'out1', fwh2, 'in1') fwh2_pu2 = Connection(fwh2, 'out1', pu2, 'in1') pu2_me2 = Connection(pu2, 'out1', me2, 'in2') sp2_fwh1 = Connection(sp2, 'out2', fwh1, 'in1') fwh1_pu3 = Connection(fwh1, 'out1', pu3, 'in1') pu3_me = Connection(pu3, 'out1', me, 'in2') self.nw.add_conns(sp1_dsh, dsh_fwh2, fwh2_pu2, pu2_me2, sp2_fwh1, fwh1_pu3, pu3_me) # busses # power bus self.power = Bus('power') self.power.add_comps({ 'comp': hpt, 'char': -1 }, { 'comp': mpt, 'char': -1 }, { 'comp': lpt, 'char': -1 }, { 'comp': pu1, 'char': -1 }, { 'comp': pu2, 'char': -1 }, { 'comp': pu3, 'char': -1 }) # heating bus self.heat = Bus('heat') self.heat.add_comps({ 'comp': eco, 'char': 1 }, { 'comp': eva, 'char': 1 }, { 'comp': sup, 'char': 1 }) self.nw.add_busses(self.power, self.heat) # parametrization # components hpt.set_attr(eta_s=0.9) mpt.set_attr(eta_s=0.9) lpt.set_attr(eta_s=0.9) pu1.set_attr(eta_s=0.8) pu2.set_attr(eta_s=0.8) pu3.set_attr(eta_s=0.8) eco.set_attr(pr=0.99) eva.set_attr(pr=0.99) sup.set_attr(pr=0.99) con.set_attr(pr1=1, pr2=0.99, ttd_u=5) fwh1.set_attr(pr1=1, pr2=0.99, ttd_u=5) fwh2.set_attr(pr1=1, pr2=0.99, ttd_u=5) dsh.set_attr(pr1=0.99, pr2=0.99) # connections eco_eva.set_attr(x=0) eva_sup.set_attr(x=1) cc_hpt.set_attr(m=200, T=650, p=100, fluid={'water': 1}) hpt_sp1.set_attr(p=20) mpt_sp2.set_attr(p=3) lpt_con.set_attr(p=0.05) cwi_con.set_attr(T=20, p=10, fluid={'water': 1}) # test run self.nw.solve('design') document_model(self.nw) def calculate_efficiency(self, x): # set extraction pressure self.nw.get_conn('extraction1').set_attr(p=x[0]) self.nw.get_conn('extraction2').set_attr(p=x[1]) self.nw.solve('design') for cp in self.nw.comps['object']: if isinstance(cp, Condenser) or isinstance(cp, Desuperheater): if cp.Q.val > 0: return np.nan elif isinstance(cp, Pump): if cp.P.val < 0: return np.nan elif isinstance(cp, Turbine): if cp.P.val > 0: return np.nan if self.nw.res[-1] > 1e-3 or self.nw.lin_dep: return np.nan else: return self.nw.busses['power'].P.val / self.nw.busses['heat'].P.val
class TestSEGS: def setup(self): """ Full model validation of SEGS model in TESPy vs. EBSILON. Find original models at https://github.com/fwitte/SEGS_exergy. """ # specification of ambient state self.pamb = 1.013 self.Tamb = 25 # setting up network self.nw = Network(fluids=['water', 'INCOMP::TVP1', 'air']) self.nw.set_attr(T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s', s_unit="kJ / kgK") # components definition air_in = Source('Ambient air source', fkt_group='CW') air_out = Sink('Ambient air sink', fkt_group='CW') closer_pt = CycleCloser('Cycle closer pt', fkt_group='SF') pt = ParabolicTrough('Parabolic trough', fkt_group='SF') ptpump = Pump('HTF pump', fkt_group='SF') closer = CycleCloser('Cycle closer power cycle', fkt_group='SG') eco = HeatExchanger('Economizer', fkt_group='SG') eva = HeatExchanger('Evaporator', fkt_group='SG') sup = HeatExchanger('Superheater', fkt_group='SG') drum = Drum('Drum', fkt_group='SG') reh = HeatExchanger('Reheater', fkt_group='RH') hpt1 = Turbine('HP turbine 1', fkt_group='HPT') hpt2 = Turbine('HP turbine 2', fkt_group='HPT') lpt1 = Turbine('LP turbine 1', fkt_group='LPT') lpt2 = Turbine('LP turbine 2', fkt_group='LPT') lpt3 = Turbine('LP turbine 3', fkt_group='LPT') lpt4 = Turbine('LP turbine 4', fkt_group='LPT') lpt5 = Turbine('LP turbine 5', fkt_group='LPT') cond = Condenser('Condenser', fkt_group='CW') condpump = Pump('Condenser pump', fkt_group='CW') fwt = Merge('Feedwater tank', num_in=3, fkt_group='LPP') fwp = Pump('Feedwater pump', fkt_group='FWP') cwp = Pump('Cooling water pump', fkt_group='CW') closer_cw = CycleCloser('Cycle closer cw', fkt_group='CW') ct = HeatExchanger('Cooling tower', fkt_group='CW') fan = Compressor('Cooling tower fan', fkt_group='CW') sp1 = Splitter('Splitter 1', fkt_group='HPT') sp2 = Splitter('Splitter 2', fkt_group='HPT') sp3 = Splitter('Splitter 3', fkt_group='LPT') sp4 = Splitter('Splitter 4', fkt_group='LPT') sp5 = Splitter('Splitter 5', fkt_group='LPT') sp6 = Splitter('Splitter 6', fkt_group='LPT') sp7 = Splitter('Splitter 7', fkt_group='SF') m1 = Merge('Merge 1', fkt_group='CW') m2 = Merge('Merge 2', fkt_group='HPP') m3 = Merge('Merge 3', fkt_group='LPP') m4 = Merge('Merge 4', fkt_group='LPP') m5 = Merge('Merge 5', fkt_group='SF') v1 = Valve('Valve 1', fkt_group='HPP') v2 = Valve('Valve 2', fkt_group='HPP') v3 = Valve('Valve 3', fkt_group='LPP') v4 = Valve('Valve 4', fkt_group='LPP') v5 = Valve('Valve 5', fkt_group='LPP') hppre1 = Condenser('High pressure preheater 1', fkt_group='HPP') hppre2 = Condenser('High pressure preheater 2', fkt_group='HPP') hppre1_sub = HeatExchanger('High pressure preheater 1 subcooling', fkt_group='HPP') hppre2_sub = HeatExchanger('High pressure preheater 2 subcooling', fkt_group='HPP') lppre1 = Condenser('Low pressure preheater 1', fkt_group='LPP') lppre2 = Condenser('Low pressure preheater 2', fkt_group='LPP') lppre3 = Condenser('Low pressure preheater 3', fkt_group='LPP') lppre1_sub = HeatExchanger('Low pressure preheater 1 subcooling', fkt_group='LPP') lppre2_sub = HeatExchanger('Low pressure preheater 2 subcooling', fkt_group='LPP') lppre3_sub = HeatExchanger('Low pressure preheater 3 subcooling', fkt_group='LPP') # connections definition # power cycle c1 = Connection(sup, 'out2', closer, 'in1', label='1') c2 = Connection(closer, 'out1', hpt1, 'in1', label='2') c3 = Connection(hpt1, 'out1', sp1, 'in1', label='3') c4 = Connection(sp1, 'out1', hpt2, 'in1', label='4') c5 = Connection(hpt2, 'out1', sp2, 'in1', label='5') c6 = Connection(sp2, 'out1', reh, 'in2', label='6') c7 = Connection(reh, 'out2', lpt1, 'in1', label='7') c8 = Connection(lpt1, 'out1', sp3, 'in1', label='8') c9 = Connection(sp3, 'out1', lpt2, 'in1', label='9') c10 = Connection(lpt2, 'out1', sp4, 'in1', label='10') c11 = Connection(sp4, 'out1', lpt3, 'in1', label='11') c12 = Connection(lpt3, 'out1', sp5, 'in1', label='12') c13 = Connection(sp5, 'out1', lpt4, 'in1', label='13') c14 = Connection(lpt4, 'out1', sp6, 'in1', label='14') c15 = Connection(sp6, 'out1', lpt5, 'in1', label='15') c16 = Connection(lpt5, 'out1', m1, 'in1', label='16') c17 = Connection(m1, 'out1', cond, 'in1', label='17') c18 = Connection(cond, 'out1', condpump, 'in1', label='18') c19 = Connection(condpump, 'out1', lppre1, 'in2', label='19') # c19 = Connection(condpump, 'out1', lppre1_sub, 'in2', label='19') # c20 = Connection(lppre1_sub, 'out2', lppre1, 'in2', label='20') c21 = Connection(lppre1, 'out2', lppre2, 'in2', label='21') # c21 = Connection(lppre1, 'out2', lppre2_sub, 'in2', label='21') # c22 = Connection(lppre2_sub, 'out2', lppre2, 'in2', label='22') c23 = Connection(lppre2, 'out2', lppre3, 'in2', label='23') # c23 = Connection(lppre2, 'out2', lppre3_sub, 'in2', label='23') # c24 = Connection(lppre3_sub, 'out2', lppre3, 'in2', label='24') c25 = Connection(lppre3, 'out2', fwt, 'in1', label='25') c26 = Connection(fwt, 'out1', fwp, 'in1', label='26') c27 = Connection(fwp, 'out1', hppre1, 'in2', label='27') c29 = Connection(hppre1, 'out2', hppre2, 'in2', label='29') c31 = Connection(hppre2, 'out2', eco, 'in2', label='31') c36 = Connection(sp1, 'out2', hppre2, 'in1', label='36') c37 = Connection(hppre2, 'out1', v1, 'in1', label='37') c39 = Connection(v1, 'out1', m2, 'in2', label='39') c40 = Connection(sp2, 'out2', m2, 'in1', label='40') c41 = Connection(m2, 'out1', hppre1, 'in1', label='41') c42 = Connection(hppre1, 'out1', v2, 'in1', label='42') c44 = Connection(v2, 'out1', fwt, 'in2', label='44') c45 = Connection(sp3, 'out2', fwt, 'in3', label='45') c46 = Connection(sp4, 'out2', lppre3, 'in1', label='46') c47 = Connection(lppre3, 'out1', v3, 'in1', label='47') # c47 = Connection(lppre3, 'out1', lppre3_sub, 'in1', label='47') # c48 = Connection(lppre3_sub, 'out1', v3, 'in1', label='48') c49 = Connection(v3, 'out1', m3, 'in1', label='49') c50 = Connection(sp5, 'out2', m3, 'in2', label='50') c51 = Connection(m3, 'out1', lppre2, 'in1', label='51') c52 = Connection(lppre2, 'out1', v4, 'in1', label='52') # c52 = Connection(lppre2, 'out1', lppre2_sub, 'in1', label='52') # c53 = Connection(lppre2_sub, 'out1', v4, 'in1', label='53') c54 = Connection(v4, 'out1', m4, 'in2', label='54') c55 = Connection(sp6, 'out2', m4, 'in1', label='55') c56 = Connection(m4, 'out1', lppre1, 'in1', label='56') c57 = Connection(lppre1, 'out1', v5, 'in1', label='57') # c57 = Connection(lppre1, 'out1', lppre1_sub, 'in1', label='57') # c58 = Connection(lppre1_sub, 'out1', v5, 'in1', label='58') c59 = Connection(v5, 'out1', m1, 'in2', label='59') # components from subsystem c32 = Connection(eco, 'out2', drum, 'in1', label='32') c33 = Connection(drum, 'out1', eva, 'in2', label='33') c34 = Connection(eva, 'out2', drum, 'in2', label='34') c35 = Connection(drum, 'out2', sup, 'in2', label='35') c73 = Connection(sup, 'out1', eva, 'in1', label='73') c74 = Connection(eva, 'out1', eco, 'in1', label='74') # cooling water c60 = Connection(cond, 'out2', closer_cw, 'in1', label='60') c61 = Connection(closer_cw, 'out1', ct, 'in1', label='61') c62 = Connection(ct, 'out1', cwp, 'in1', label='62') c63 = Connection(cwp, 'out1', cond, 'in2', label='63') # cooling tower c64 = Connection(air_in, 'out1', fan, 'in1', label='64') c65 = Connection(fan, 'out1', ct, 'in2', label='65') c66 = Connection(ct, 'out2', air_out, 'in1', label='66') # parabolic trough cycle c70 = Connection(pt, 'out1', closer_pt, 'in1', label='67') c71 = Connection(closer_pt, 'out1', sp7, 'in1', label='71') c72 = Connection(sp7, 'out1', sup, 'in1', label='72') c75 = Connection(eco, 'out1', m5, 'in1', label='75') c76 = Connection(sp7, 'out2', reh, 'in1', label='76') c77 = Connection(reh, 'out1', m5, 'in2', label='77') c78 = Connection(m5, 'out1', ptpump, 'in1', label='78') c79 = Connection(ptpump, 'out1', pt, 'in1', label='79') # add connections to network self.nw.add_conns(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c21, c23, c25, c26, c27, c29, c31, c32, c33, c34, c35, c36, c37, c39, c40, c41, c42, c44, c45, c46, c47, c49, c50, c51, c52, c54, c55, c56, c57, c59, c60, c61, c62, c63, c64, c65, c66, c70, c71, c72, c73, c74, c75, c76, c77, c78, c79) # power bus power = Bus('total output power') power.add_comps({ 'comp': hpt1, 'char': 0.97, 'base': 'component' }, { 'comp': hpt2, 'char': 0.97, 'base': 'component' }, { 'comp': lpt1, 'char': 0.97, 'base': 'component' }, { 'comp': lpt2, 'char': 0.97, 'base': 'component' }, { 'comp': lpt3, 'char': 0.97, 'base': 'component' }, { 'comp': lpt4, 'char': 0.97, 'base': 'component' }, { 'comp': lpt5, 'char': 0.97, 'base': 'component' }, { 'comp': fwp, 'char': 0.95, 'base': 'bus' }, { 'comp': condpump, 'char': 0.95, 'base': 'bus' }, { 'comp': ptpump, 'char': 0.95, 'base': 'bus' }, { 'comp': cwp, 'char': 0.95, 'base': 'bus' }, { 'comp': fan, 'char': 0.95, 'base': 'bus' }) heat_input_bus = Bus('heat input') heat_input_bus.add_comps({'comp': pt, 'base': 'bus'}) exergy_loss_bus = Bus('exergy loss') exergy_loss_bus.add_comps({ 'comp': air_in, 'base': 'bus' }, {'comp': air_out}) self.nw.add_busses(power, heat_input_bus, exergy_loss_bus) # component parameters pt.set_attr(doc=0.95, aoi=0, Tamb=25, A='var', eta_opt=0.73, c_1=0.00496, c_2=0.000691, E=1000, iam_1=1, iam_2=1) ptpump.set_attr(eta_s=0.6) eco.set_attr() eva.set_attr(ttd_l=5) sup.set_attr() hpt1.set_attr(eta_s=0.8376) hpt2.set_attr(eta_s=0.8463) lpt1.set_attr(eta_s=0.8623) lpt2.set_attr(eta_s=0.917) lpt3.set_attr(eta_s=0.9352) lpt4.set_attr(eta_s=0.88) lpt5.set_attr(eta_s=0.6445) cond.set_attr(pr1=1, pr2=0.9, ttd_u=5) condpump.set_attr(eta_s=0.7) fwp.set_attr(eta_s=0.7) cwp.set_attr(eta_s=0.7) ct.set_attr(pr1=0.95) fan.set_attr(eta_s=0.6) lppre1.set_attr(pr1=1, ttd_u=5) lppre2.set_attr(pr1=1, ttd_u=5) lppre3.set_attr(pr1=1, ttd_u=5) hppre1.set_attr(pr1=1, ttd_u=5) hppre2.set_attr(pr1=1, ttd_u=5) lppre1_sub.set_attr(pr1=1, pr2=1, ttd_l=10) lppre2_sub.set_attr(pr1=1, pr2=1, ttd_l=10) lppre3_sub.set_attr(pr1=1, pr2=1, ttd_l=10) hppre1_sub.set_attr(pr1=1, pr2=1, ttd_l=10) hppre2_sub.set_attr(pr1=1, pr2=1, ttd_l=10) # connection parameters # parabolic trough cycle c70.set_attr(fluid={'TVP1': 1, 'water': 0, 'air': 0}, T=390, p=23.304) c76.set_attr(m=Ref(c70, 0.1284, 0)) c73.set_attr(p=22.753) c74.set_attr(p=21.167) c78.set_attr(p=20.34) c79.set_attr(p=41.024) # cooling water c62.set_attr(fluid={ 'TVP1': 0, 'water': 1, 'air': 0 }, T=30, p=self.pamb) # cooling tower c64.set_attr(fluid={ 'water': 0, 'TVP1': 0, 'air': 1 }, p=self.pamb, T=self.Tamb) c65.set_attr(p=self.pamb + 0.0005) c66.set_attr(p=self.pamb, T=30) # power cycle c32.set_attr(Td_bp=-2) c34.set_attr(x=0.5) c1.set_attr(fluid={'water': 1, 'TVP1': 0, 'air': 0}, p=100, T=371) # steam generator pressure values c31.set_attr(p=103.56) c35.set_attr(p=103.42) # turbine pressure values c3.set_attr(p=33.61, m=38.969) c5.set_attr(p=18.58) c7.set_attr(p=17.1, T=371) c8.set_attr(p=7.98) c10.set_attr(p=2.73) c12.set_attr(p=0.96) c14.set_attr(p=0.29) # preheater pressure values c19.set_attr(p=14.755, state='l') c21.set_attr(p=9.9975, state='l') c23.set_attr(p=8.7012, state='l') c25.set_attr(state='l') c27.set_attr(p=125) c29.set_attr(p=112) # condensation c16.set_attr(p=0.08) # feedwater tank c26.set_attr(x=0) # a stable solution is generated for parts of the network self.nw.solve(mode='design') self.nw.del_conns(c19, c21, c23, c27, c29, c37, c42, c47, c52, c57) c19 = Connection(condpump, 'out1', lppre1_sub, 'in2', label='19') c20 = Connection(lppre1_sub, 'out2', lppre1, 'in2', label='20') c21 = Connection(lppre1, 'out2', lppre2_sub, 'in2', label='21') c22 = Connection(lppre2_sub, 'out2', lppre2, 'in2', label='22') c23 = Connection(lppre2, 'out2', lppre3_sub, 'in2', label='23') c24 = Connection(lppre3_sub, 'out2', lppre3, 'in2', label='24') c27 = Connection(fwp, 'out1', hppre1_sub, 'in2', label='27') c28 = Connection(hppre1_sub, 'out2', hppre1, 'in2', label='28') c29 = Connection(hppre1, 'out2', hppre2_sub, 'in2', label='29') c30 = Connection(hppre2_sub, 'out2', hppre2, 'in2', label='30') c37 = Connection(hppre2, 'out1', hppre2_sub, 'in1', label='37') c38 = Connection(hppre2_sub, 'out1', v1, 'in1', label='38') c42 = Connection(hppre1, 'out1', hppre1_sub, 'in1', label='42') c43 = Connection(hppre1_sub, 'out1', v2, 'in1', label='43') c47 = Connection(lppre3, 'out1', lppre3_sub, 'in1', label='47') c48 = Connection(lppre3_sub, 'out1', v3, 'in1', label='48') c52 = Connection(lppre2, 'out1', lppre2_sub, 'in1', label='52') c53 = Connection(lppre2_sub, 'out1', v4, 'in1', label='53') c57 = Connection(lppre1, 'out1', lppre1_sub, 'in1', label='57') c58 = Connection(lppre1_sub, 'out1', v5, 'in1', label='58') self.nw.add_conns(c19, c20, c21, c22, c23, c24, c27, c28, c29, c30, c37, c38, c42, c43, c47, c48, c52, c53, c57, c58) # specification of missing parameters c19.set_attr(p=14.755) c21.set_attr(p=9.9975, state='l') c23.set_attr(p=8.7012, state='l') c27.set_attr(p=125) c29.set_attr(p=112) # solve final state self.nw.solve(mode='design') def test_model(self): """Test the thermodynamic model.""" power_ebsilon = -31.769 power_tespy = round(self.nw.busses['total output power'].P.val / 1e6, 3) msg = ('The total power calculated (' + str(power_tespy) + ') does not ' 'match the power calculated with the EBSILON model (' + str(power_ebsilon) + ').') assert power_tespy == power_ebsilon, msg T_c79_ebsilon = 296.254 T_c79_tespy = round(self.nw.get_conn('79').T.val, 3) msg = ('The temperature at connection 79 calculated (' + str(T_c79_tespy) + ') does not match the temperature calculated ' 'with the EBSILON model (' + str(T_c79_ebsilon) + ').') assert T_c79_tespy == T_c79_ebsilon, msg def test_exergy_analysis(self): """Test the exergy analysis results.""" # carry out exergy analysis ean = ExergyAnalysis(self.nw, E_P=[self.nw.busses['total output power']], E_F=[self.nw.busses['heat input']], E_L=[self.nw.busses['exergy loss']]) ean.analyse(pamb=self.pamb, Tamb=self.Tamb) # generate Grassmann diagram links, nodes = ean.generate_plotly_sankey_input() # check if exergy product value in links is equal to total power # output position = links['target'].index(nodes.index('E_P')) power_links = round(links['value'][position], 0) power_bus = round(-self.nw.busses['total output power'].P.val, 0) msg = ('The exergy product value in the links (' + str(power_links) + ') must be equal to the power on the respective bus (' + str(power_bus) + ').') assert power_links == power_bus, msg
class TestCompressedAirOut: def setup(self): """Set up air compressed air turbine.""" self.Tamb = 20 self.pamb = 1 fluids = ['Air'] # turbine part self.nw = Network(fluids=fluids) self.nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg') # components cas = Source('compressed air storage') reheater = HeatExchangerSimple('reheating') turb = Turbine('turbine') amb = Sink('air outlet') # power ouput bus self.power_out = Bus('power output') self.power_out.add_comps({'comp': turb, 'char': 1}) # compressed air bus self.cas_out = Bus('exergy in') self.cas_out.add_comps({ 'comp': cas, 'base': 'bus' }, { 'comp': reheater, 'base': 'bus' }) # exergy loss bus self.ex_loss = Bus('exergy loss') self.ex_loss.add_comps({'comp': amb, 'base': 'component'}) self.nw.add_busses(self.power_out, self.cas_out) # create connections cas_reheater = Connection(cas, 'out1', reheater, 'in1') reheater_turb = Connection(reheater, 'out1', turb, 'in1') turb_amb = Connection(turb, 'out1', amb, 'in1', label='outlet') self.nw.add_conns(cas_reheater, reheater_turb, turb_amb) # component parameters turb.set_attr(eta_s=1) reheater.set_attr(pr=1) # connection parameters cas_reheater.set_attr(m=2, T=self.Tamb, p=10, fluid={'Air': 1}) reheater_turb.set_attr() turb_amb.set_attr(p=self.pamb, T=self.Tamb) # solve network self.nw.solve('design') convergence_check(self.nw.lin_dep) def test_exergy_analysis_bus_conversion(self): """Test exergy analysis at product exergy with T < Tamb.""" ean = ExergyAnalysis(self.nw, E_P=[self.power_out], E_F=[self.cas_out], E_L=[self.ex_loss]) ean.analyse(pamb=self.pamb, Tamb=self.Tamb) exergy_balance = (ean.network_data.E_F - ean.network_data.E_P - ean.network_data.E_L - ean.network_data.E_D) msg = ('Exergy balance must be closed (residual value smaller than ' + str(err**0.5) + ') for this test but is ' + str(round(abs(exergy_balance), 4)) + '.') assert abs(exergy_balance) <= err**0.5, msg msg = ('Exergy efficiency must be equal to 1.0 for this test but is ' + str(round(ean.network_data.epsilon, 4)) + '.') assert round(ean.network_data.epsilon, 4) == 1, msg c = self.nw.get_conn('outlet') c.set_attr(T=self.Tamb - 20) self.nw.solve('design') convergence_check(self.nw.lin_dep) ean.analyse(pamb=self.pamb, Tamb=self.Tamb) msg = ( 'Exergy destruction must be equal to 0.0 for this test but is ' + str(round(ean.network_data.E_D, 4)) + '.') assert round(ean.network_data.E_D, 4) == 0, msg msg = ('Exergy loss must be equal to ' + str(round(c.Ex_physical, 4)) + ' for this test but is ' + str(round(ean.network_data.E_L, 4)) + '.') assert round(ean.network_data.E_L, 4) == round(c.Ex_physical, 4), msg
class PowerPlant(): def __init__(self, working_fluid): """Set up model.""" 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 self.geo_mass_flow = 200 geo_steam_share = 0.1 self.T_brine_in = 140 # ambient parameters self.T_amb = 5 self.p_amb = 0.6 # main components geo_steam = Source('geosteam source') geo_brine = Source('geobrine source') geo_reinjection = Sink('re-injection') air_in = Source('air source') air_out = Sink('air sink') air_fan = Compressor('air fan') air_cond = Condenser('condenser') orc_cc = CycleCloser('orc cycle closer') evap_splitter = Splitter('splitter evaporation') evap_merge = Merge('merge evaporation') evap_steam = Condenser('geosteam evaporator') evap_brine = HeatExchanger('geobrine evaporator') dr = Drum('drum') geo_merge = Merge('merge brine') pre = HeatExchanger('preheater') feed_working_fluid_pump = Pump('feed pump') tur = Turbine('turbine') ihe = HeatExchanger('internal heat exchanger') # busses net_power = Bus('net power output') net_power.add_comps( {'comp': tur, 'char': 0.97}, {'comp': feed_working_fluid_pump, 'char': 0.97, 'base': 'bus'}, {'comp': air_fan, 'char': 0.97, 'base': 'bus'} ) ORC_power_bus = Bus('cycle gross power output') ORC_power_bus.add_comps( {'comp': tur}, {'comp': feed_working_fluid_pump} ) geothermal_bus = Bus('thermal input') geothermal_bus.add_comps( {'comp': pre, 'char': -1}, {'comp': evap_brine, 'char': -1}, {'comp': evap_steam, 'char': -1} ) self.nw.add_busses(net_power, ORC_power_bus, geothermal_bus) # turbine to condenser c1 = Connection(orc_cc, 'out1', tur, 'in1', label='1') c2 = Connection(tur, 'out1', ihe, 'in1', label='2') c3 = Connection(ihe, 'out1', air_cond, 'in1', label='3') self.nw.add_conns(c1, c2, c3) # condenser to steam generator c4 = Connection(air_cond, 'out1', feed_working_fluid_pump, 'in1', label='4') c5 = Connection(feed_working_fluid_pump, 'out1', ihe, 'in2', label='5') self.nw.add_conns(c4, c5) # steam generator c6 = Connection(ihe, 'out2', pre, 'in2', label='6') c7 = Connection(pre, 'out2', dr, 'in1', label='7') c8 = Connection(dr, 'out1', evap_splitter, 'in1', label='8') c9 = Connection(evap_splitter, 'out2', evap_steam, 'in2', label='9') c10 = Connection(evap_steam, 'out2', evap_merge, 'in2', label='10') c11 = Connection(evap_splitter, 'out1', evap_brine, 'in2', label='11') c12 = Connection(evap_brine, 'out2', evap_merge, 'in1', label='12') c13 = Connection(evap_merge, 'out1', dr, 'in2', label='13') c0 = Connection(dr, 'out2', orc_cc, 'in1', label='0') self.nw.add_conns(c6, c7, c8, c11, c9, c12, c10, c13, c0) # condenser cold side c20 = Connection(air_in, 'out1', air_fan, 'in1', label='20') c21 = Connection(air_fan, 'out1', air_cond, 'in2', label='21') c22 = Connection(air_cond, 'out2', air_out, 'in1', label='22') self.nw.add_conns(c20, c21, c22) # geo source c30 = Connection(geo_steam, 'out1', evap_steam, 'in1', label='30') c31 = Connection(evap_steam, 'out1', geo_merge, 'in1', label='31') c32 = Connection(geo_brine, 'out1', geo_merge, 'in2', label='32') c33 = Connection(geo_merge, 'out1', evap_brine, 'in1', label='33') self.nw.add_conns(c30, c31, c32, c33) c34 = Connection(evap_brine, 'out1', pre, 'in1', label='34') c35 = Connection(pre, 'out1', geo_reinjection, 'in1', label='35') self.nw.add_conns(c34, c35) # generate a set of stable starting values of every working fluid # fluid settings c6.set_attr(fluid={self.working_fluid: 1.0, 'air': 0.0, 'water': 0.0}) c20.set_attr(fluid={self.working_fluid: 0.0, 'air': 1.0, 'water': 0.0}) c30.set_attr(fluid={self.working_fluid: 0.0, 'air': 0.0, 'water': 1.0}) c32.set_attr(fluid={self.working_fluid: 0.0, 'air': 0.0, 'water': 1.0}) # connection parameters p0 = PSI('P', 'T', self.T_brine_in + 273.15, 'Q', 1, self.working_fluid) c1.set_attr(p0=p0 / 1e5) ws_stable_h0 = ( PSI('H', 'T', self.T_amb + 273.15, 'Q', 1, self.working_fluid) + 0.5 * ( PSI('H', 'T', self.T_brine_in + 273.15, 'Q', 1, self.working_fluid) - PSI('H', 'T', self.T_amb + 273.15, 'Q', 1, self.working_fluid) ) ) / 1e3 c2.set_attr(h=ws_stable_h0) p0 = PSI('P', 'T', self.T_amb + 273.15, 'Q', 1, self.working_fluid) c3.set_attr(Td_bp=5, design=['Td_bp'], p0=p0 / 1e5) c5.set_attr(h=Ref(c4, 1, 1)) # steam generator c30.set_attr( m=self.geo_mass_flow * geo_steam_share, T=self.T_brine_in, x=1, p0=5) c32.set_attr( m=self.geo_mass_flow * (1 - geo_steam_share), T=self.T_brine_in, x=0) c13.set_attr() c12.set_attr(x=0.5) c10.set_attr(x=0.5, design=['x']) c34.set_attr(h=Ref(c33, 1, -50)) c7.set_attr(Td_bp=-2) # main condenser c20.set_attr(p=self.p_amb, T=self.T_amb) c22.set_attr(T=self.T_amb + 15, p=self.p_amb) # component parameters # condensing ihe.set_attr(pr1=0.98, pr2=0.98) air_cond.set_attr(pr1=1, pr2=0.995, ttd_u=10) air_fan.set_attr(eta_s=0.6) # steam generator evap_brine.set_attr(pr1=0.98, ttd_l=8) pre.set_attr(pr1=0.98, pr2=0.98) self.nw.set_attr(iterinfo=False) self.nw.solve('design') self.nw.save('stable_' + self.working_fluid) # specify actual parameters tur.set_attr(eta_s=0.9) feed_working_fluid_pump.set_attr(eta_s=0.75) c2.set_attr(h=None) c5.set_attr(h=None) c34.set_attr(h=None, T=Ref(c33, 1, -10)) self.nw.solve('design') c22.set_attr(T=None) c3.set_attr(Td_bp=None) self.ude_IHE_size = UserDefinedEquation( label='ihe deshuperheat ratio', func=desuperheat, deriv=desuperheat_deriv, latex={ 'equation': r'0 = h_3 - h_2 - x_\mathrm{IHE} \cdot \left(h_3 -' r'h\left(p_2, T_5 + \Delta T_\mathrm{t,u,min} \right)' r'\right)'}, conns=[ self.nw.get_conn('2'), self.nw.get_conn('3'), self.nw.get_conn('5')], params={'distance': 0.0, 'ttd_min': 2} ) if self.nw.lin_dep or self.nw.res[-1] > 1e-3: msg = 'No stable solution found.' raise TESPyNetworkError(msg) print( 'Generated stable starting values for working fluid ' + self.working_fluid + '.') def run_simulation( self, p_before_tur=None, Q_ihe=None, Q_brine_ev=None, T_before_tur=None, T_reinjection=None, brine_evap_Td=None, dT_air=None, IHE_sizing=None, geo_steam_share=None): """Run simulation on specified parameter set.""" self.nw.get_comp('internal heat exchanger').set_attr(Q=Q_ihe) self.nw.get_conn('1').set_attr(p=p_before_tur, T=T_before_tur) self.nw.get_conn('35').set_attr(T=T_reinjection) self.nw.get_comp('geobrine evaporator').set_attr(Q=Q_brine_ev) if geo_steam_share is not None: self.nw.get_conn('30').set_attr( m=self.geo_mass_flow * geo_steam_share) self.nw.get_conn('32').set_attr( m=self.geo_mass_flow * (1 - geo_steam_share)) if brine_evap_Td is not None: self.nw.get_conn('34').set_attr( T=Ref(self.nw.get_conn('33'), 1, brine_evap_Td)) else: self.nw.get_conn('34').set_attr(T=None) if dT_air is not None: self.nw.get_conn('22').set_attr(T=Ref(self.nw.get_conn('21'), 1, dT_air)) else: self.nw.get_conn('22').set_attr(T=None) if IHE_sizing is None: if self.ude_IHE_size in self.nw.user_defined_eq.values(): self.nw.del_ude(self.ude_IHE_size) self.nw.get_comp('internal heat exchanger').set_attr(pr1=0.98, pr2=0.98) else: if self.ude_IHE_size not in self.nw.user_defined_eq.values(): self.nw.add_ude(self.ude_IHE_size) self.ude_IHE_size.params['distance'] = IHE_sizing if IHE_sizing == 0: self.nw.get_comp('internal heat exchanger').set_attr(pr1=1, pr2=1) else: self.nw.get_comp('internal heat exchanger').set_attr(pr1=0.98, pr2=0.98) try: self.nw.solve('design') # self.nw.print_results() except ValueError: self.nw.res = [1] pass def check_simulation(self, value): """Check if simulation converged.""" if self.nw.lin_dep or self.nw.res[-1] > 1e-3: self.nw.solve( 'design', init_path='stable_' + self.working_fluid, init_only=True) return np.nan else: for cp in self.nw.comps['object']: if isinstance(cp, HeatExchanger): if cp.Q.val > 0: print(cp.label) return np.nan elif cp.kA.val <= 0 or (np.isnan(cp.kA.val) and cp.Q.val != 0): print(cp.label) return np.nan return value def get_power(self): """Calculate ORC gross power (main cycle only).""" return self.check_simulation(self.nw.busses['cycle gross power output'].P.val) def get_net_power(self): """Calculate net power.""" return self.check_simulation(self.nw.busses['net power output'].P.val) def get_thermal_efficiency(self): """Calculate thermal efficiency.""" return self.check_simulation( -self.nw.busses['cycle gross power output'].P.val / self.nw.busses['thermal input'].P.val) def get_net_efficiency(self): """Calculate net efficiency.""" return self.check_simulation( -self.nw.busses['net power output'].P.val / self.nw.busses['thermal input'].P.val) def get_geosteam_share(self): """Return a geosteam share.""" return self.check_simulation( self.nw.get_conn('geosteam').m.val_SI / self.geo_mass_flow) def get_connection_param(self, conn, param): """Return a connection parameter.""" return self.check_simulation( self.nw.get_conn(conn).get_attr(param).val) def get_component_param(self, comp, param): """Return a component parameter.""" return self.check_simulation( self.nw.get_comp(comp).get_attr(param).val) def get_misc_param(self, param): """Get non component or connection parameters.""" if param == 'gross power output': return self.get_power() elif param == 'net power output': return self.get_net_power() elif param == 'thermal efficiency': return self.get_thermal_efficiency() elif param == 'net efficiency': return self.get_net_efficiency() elif param == 'IHE sizing factor': return self.ude_IHE_size.params['distance'] def get_objective_func(self, objective): """Return corresponding objective function.""" if objective == 'net power output': return self.get_net_power elif objective == 'gross power output': return self.get_power else: msg = ( 'Please specify valid objective function: "net power output" ' 'or "gross power output".') raise ValueError(msg)
class TestClausiusRankine: def setup(self): """Set up clausis rankine cycle with turbine driven feed water pump.""" self.Tamb = 20 self.pamb = 1 fluids = ['water'] self.nw = Network(fluids=fluids) self.nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg') # create components splitter1 = Splitter('splitter 1') merge1 = Merge('merge 1') turb = Turbine('turbine') fwp_turb = Turbine('feed water pump turbine') condenser = HeatExchangerSimple('condenser') fwp = Pump('pump') steam_generator = HeatExchangerSimple('steam generator') cycle_close = CycleCloser('cycle closer') # create busses # power output bus self.power = Bus('power_output') self.power.add_comps({'comp': turb, 'char': 1}) # turbine driven feed water pump internal bus self.fwp_power = Bus('feed water pump power', P=0) self.fwp_power.add_comps({ 'comp': fwp_turb, 'char': 1 }, { 'comp': fwp, 'char': 1, 'base': 'bus' }) # heat input bus self.heat = Bus('heat_input') self.heat.add_comps({'comp': steam_generator, 'base': 'bus'}) self.nw.add_busses(self.power, self.fwp_power, self.heat) # create connections fs_in = Connection(cycle_close, 'out1', splitter1, 'in1', label='fs') fs_fwpt = Connection(splitter1, 'out1', fwp_turb, 'in1') fs_t = Connection(splitter1, 'out2', turb, 'in1') fwpt_ws = Connection(fwp_turb, 'out1', merge1, 'in1') t_ws = Connection(turb, 'out1', merge1, 'in2') ws = Connection(merge1, 'out1', condenser, 'in1') cond = Connection(condenser, 'out1', fwp, 'in1', label='cond') fw = Connection(fwp, 'out1', steam_generator, 'in1', label='fw') fs_out = Connection(steam_generator, 'out1', cycle_close, 'in1') self.nw.add_conns(fs_in, fs_fwpt, fs_t, fwpt_ws, t_ws, ws, cond, fw, fs_out) # component parameters turb.set_attr(eta_s=1) fwp_turb.set_attr(eta_s=1) condenser.set_attr(pr=1) fwp.set_attr(eta_s=1) steam_generator.set_attr(pr=1) # connection parameters fs_in.set_attr(m=10, p=120, T=600, fluid={'water': 1}) cond.set_attr(T=self.Tamb, x=0) # solve network self.nw.solve('design') convergence_check(self.nw.lin_dep) def test_exergy_analysis_perfect_cycle(self): """Test exergy analysis in the perfect clausius rankine cycle.""" ean = ExergyAnalysis(self.nw, E_P=[self.power], E_F=[self.heat], internal_busses=[self.fwp_power]) ean.analyse(pamb=self.pamb, Tamb=self.Tamb) msg = ('Exergy destruction of this network must be 0 (smaller than ' + str(err**0.5) + ') for this test but is ' + str(round(abs(ean.network_data.E_D), 4)) + ' .') assert abs(ean.network_data.E_D) <= err**0.5, msg msg = ('Exergy efficiency of this network must be 1 for this test but ' 'is ' + str(round(ean.network_data.epsilon, 4)) + ' .') assert round(ean.network_data.epsilon, 4) == 1, msg exergy_balance = (ean.network_data.E_F - ean.network_data.E_P - ean.network_data.E_L - ean.network_data.E_D) msg = ('Exergy balance must be closed (residual value smaller than ' + str(err**0.5) + ') for this test but is ' + str(round(abs(exergy_balance), 4)) + ' .') assert abs(exergy_balance) <= err**0.5, msg msg = ( 'Fuel exergy and product exergy must be identical for this test. ' 'Fuel exergy value: ' + str(round(ean.network_data.E_F, 4)) + '. Product exergy value: ' + str(round(ean.network_data.E_P, 4)) + '.') delta = round(abs(ean.network_data.E_F - ean.network_data.E_P), 4) assert delta < err**0.5, msg def test_exergy_analysis_plotting_data(self): """Test exergy analysis plotting.""" self.nw.get_comp('steam generator').set_attr(pr=0.9) self.nw.get_comp('turbine').set_attr(eta_s=0.9) self.nw.get_comp('feed water pump turbine').set_attr(eta_s=0.85) self.nw.get_comp('pump').set_attr(eta_s=0.75) self.nw.get_conn('cond').set_attr(T=self.Tamb + 3) # specify efficiency values for the internal bus and power bus self.nw.del_busses(self.fwp_power, self.power) self.fwp_power = Bus('feed water pump power', P=0) self.fwp_power.add_comps( { 'comp': self.nw.get_comp('feed water pump turbine'), 'char': 0.99 }, { 'comp': self.nw.get_comp('pump'), 'char': 0.98, 'base': 'bus' }) self.power = Bus('power_output') self.power.add_comps({ 'comp': self.nw.get_comp('turbine'), 'char': 0.98 }) self.nw.add_busses(self.fwp_power, self.power) # solve network self.nw.solve('design') convergence_check(self.nw.lin_dep) ean = ExergyAnalysis(self.nw, E_P=[self.power], E_F=[self.heat], internal_busses=[self.fwp_power]) ean.analyse(pamb=self.pamb, Tamb=self.Tamb) exergy_balance = (ean.network_data.E_F - ean.network_data.E_P - ean.network_data.E_L - ean.network_data.E_D) msg = ('Exergy balance must be closed (residual value smaller than ' + str(err**0.5) + ') for this test but is ' + str(round(abs(exergy_balance), 4)) + ' .') assert abs(exergy_balance) <= err**0.5, msg nodes = [ 'E_F', 'steam generator', 'splitter 1', 'feed water pump turbine', 'turbine', 'merge 1', 'condenser', 'pump', 'E_D', 'E_P' ] links, nodes = ean.generate_plotly_sankey_input(node_order=nodes) # checksum for targets and source checksum = sum(links['target'] + links['source']) msg = ('The checksum of all target and source values in the link lists' 'must be 148, but is ' + str(checksum) + '.') assert 148 == checksum, msg def test_exergy_analysis_violated_balance(self): """Test exergy analysis with violated balance.""" # specify efficiency values for the internal bus self.nw.del_busses(self.fwp_power) self.fwp_power = Bus('feed water pump power', P=0) self.fwp_power.add_comps( { 'comp': self.nw.get_comp('feed water pump turbine'), 'char': 0.99 }, { 'comp': self.nw.get_comp('pump'), 'char': 0.98, 'base': 'bus' }) self.nw.add_busses(self.fwp_power) self.nw.solve('design') convergence_check(self.nw.lin_dep) # miss out on internal bus in exergy_analysis ean = ExergyAnalysis(self.nw, E_P=[self.power], E_F=[self.heat]) ean.analyse(pamb=self.pamb, Tamb=self.Tamb) exergy_balance = (ean.network_data.E_F - ean.network_data.E_P - ean.network_data.E_L - ean.network_data.E_D) msg = ('Exergy balance must be violated for this test (larger than ' + str(err**0.5) + ') but is ' + str(round(abs(exergy_balance), 4)) + ' .') assert abs(exergy_balance) > err**0.5, msg def test_exergy_analysis_bus_conversion(self): """Test exergy analysis bus conversion factors.""" # specify efficiency values for the internal bus self.nw.del_busses(self.fwp_power) self.fwp_power = Bus('feed water pump power', P=0) self.fwp_power.add_comps( { 'comp': self.nw.get_comp('feed water pump turbine'), 'char': 0.99 }, { 'comp': self.nw.get_comp('pump'), 'char': 0.98, 'base': 'bus' }) self.nw.add_busses(self.fwp_power) self.nw.solve('design') convergence_check(self.nw.lin_dep) # no exergy losses in this case ean = ExergyAnalysis(self.nw, E_P=[self.power], E_F=[self.heat], internal_busses=[self.fwp_power]) ean.analyse(pamb=self.pamb, Tamb=self.Tamb) label = 'pump' eps = ean.bus_data.loc[label, 'epsilon'] msg = ('Pump exergy efficiency must be 0.98 but is ' + str(round(eps, 4)) + ' .') assert round(eps, 4) == 0.98, msg label = 'feed water pump turbine' eps = ean.bus_data.loc[label, 'epsilon'] msg = ( 'Feed water pump turbine exergy efficiency must be 0.99 but is ' + str(round(eps, 4)) + ' .') assert round(eps, 4) == 0.99, msg def test_exergy_analysis_missing_E_F_E_P_information(self): """Test exergy analysis errors with missing information.""" with raises(TESPyNetworkError): ExergyAnalysis(self.nw, E_P=[self.power], E_F=[]) with raises(TESPyNetworkError): ExergyAnalysis(self.nw, E_P=[], E_F=[self.heat]) def test_exergy_analysis_component_on_two_busses(self): """Test exergy analysis errors with components on more than one bus.""" with raises(TESPyNetworkError): ean = ExergyAnalysis(self.nw, E_P=[self.power], E_F=[self.heat, self.power]) ean.analyse(pamb=self.pamb, Tamb=self.Tamb)
class TestReactors: def setup(self): """Set up network for electrolyzer tests.""" self.nw = Network(['O2', 'H2', 'H2O'], T_unit='C', p_unit='bar') self.instance = WaterElectrolyzer('electrolyzer') fw = Source('feed water') cw_in = Source('cooling water') o2 = Sink('oxygen sink') h2 = Sink('hydrogen sink') cw_out = Sink('cooling water sink') self.instance.set_attr(pr=0.99, eta=1) cw_el = Connection(cw_in, 'out1', self.instance, 'in1', fluid={ 'H2O': 1, 'H2': 0, 'O2': 0 }, T=20, p=1) el_cw = Connection(self.instance, 'out1', cw_out, 'in1', T=45) self.nw.add_conns(cw_el, el_cw) fw_el = Connection(fw, 'out1', self.instance, 'in2', label='h2o') el_o2 = Connection(self.instance, 'out2', o2, 'in1') el_h2 = Connection(self.instance, 'out3', h2, 'in1', label='h2') self.nw.add_conns(fw_el, el_o2, el_h2) def test_WaterElectrolyzer(self): """Test component properties of water electrolyzer.""" # check bus function: # power output on component and bus must be indentical self.nw.get_conn('h2o').set_attr(T=25, p=1) self.nw.get_conn('h2').set_attr(T=25) power = Bus('power') power.add_comps({'comp': self.instance, 'param': 'P', 'base': 'bus'}) power.set_attr(P=2.5e6) self.nw.add_busses(power) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of power must be ' + str(power.P.val) + ', is ' + str(self.instance.P.val) + '.') assert round(power.P.val, 1) == round(self.instance.P.val), msg # effieciency was set to 100 % with inlet and outlet states of the # reaction educts and products beeing identical to reference state # therefore Q must be equal to 0 msg = ('Value of heat output must be 0.0, is ' + str(self.instance.Q.val) + '.') assert round(self.instance.Q.val, 4) == 0.0, msg # reset power, change efficiency value and specify heat bus value power.set_attr(P=np.nan) self.nw.get_conn('h2o').set_attr(T=25, p=1) self.nw.get_conn('h2').set_attr(T=50) self.instance.set_attr(eta=0.8) # check bus function: # heat output on component and bus must be indentical heat = Bus('heat') heat.add_comps({'comp': self.instance, 'param': 'Q'}) heat.set_attr(P=-8e5) self.nw.add_busses(heat) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of heat flow must be ' + str(heat.P.val) + ', is ' + str(self.instance.Q.val) + '.') assert round(heat.P.val, 1) == round(self.instance.Q.val), msg self.nw.save('tmp') # check bus function: # heat output on component and bus must identical (offdesign test) Q = heat.P.val * 0.9 heat.set_attr(P=Q) self.nw.solve('offdesign', design_path='tmp') convergence_check(self.nw.lin_dep) msg = ('Value of heat flow must be ' + str(Q) + ', is ' + str(self.instance.Q.val) + '.') assert round(Q, 1) == round(self.instance.Q.val), msg # delete both busses again self.nw.del_busses(heat, power) # test efficiency vs. specific energy consumption self.nw.get_conn('h2').set_attr(m=0.1) self.instance.set_attr(eta=0.9, e='var') self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of efficiency must be ' + str(self.instance.eta.val) + ', is ' + str(self.instance.e0 / self.instance.e.val) + '.') eta = round(self.instance.eta.val, 2) eta_calc = round(self.instance.e0 / self.instance.e.val, 2) assert eta == eta_calc, msg # test efficiency value > 1, Q must be larger than 0 e = 130e6 self.instance.set_attr(e=np.nan, eta=np.nan) self.instance.set_attr(e=e) self.nw.solve('design') convergence_check(self.nw.lin_dep) # test efficiency msg = ('Value of efficiency must be ' + str(self.instance.e0 / e) + ', is ' + str(self.instance.eta.val) + '.') eta = round(self.instance.e0 / e, 2) eta_calc = round(self.instance.eta.val, 2) assert eta == eta_calc, msg # test Q msg = ('Value of heat must be larger than zero, is ' + str(self.instance.Q.val) + '.') assert self.instance.Q.val > 0, msg # test specific energy consumption e = 150e6 self.instance.set_attr(e=np.nan, eta=np.nan) self.instance.set_attr(e=e) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of specific energy consumption e must be ' + str(e) + ', is ' + str(self.instance.e.val) + '.') assert round(e, 1) == round(self.instance.e.val, 1), msg # test cooling loop pressure ratio, zeta as variable value pr = 0.95 self.instance.set_attr(pr=pr, e=None, eta=None, zeta='var', P=2e7, design=['pr']) self.nw.solve('design') shutil.rmtree('./tmp', ignore_errors=True) self.nw.save('tmp') convergence_check(self.nw.lin_dep) msg = ('Value of pressure ratio must be ' + str(pr) + ', is ' + str(self.instance.pr.val) + '.') assert round(pr, 2) == round(self.instance.pr.val, 2), msg # use zeta as offdesign parameter, at design point pressure # ratio must not change self.instance.set_attr(zeta=np.nan, offdesign=['zeta']) self.nw.solve('offdesign', design_path='tmp') convergence_check(self.nw.lin_dep) msg = ('Value of pressure ratio must be ' + str(pr) + ', is ' + str(self.instance.pr.val) + '.') assert round(pr, 2) == round(self.instance.pr.val, 2), msg # test heat output specification in offdesign mode Q = self.instance.Q.val * 0.9 self.instance.set_attr(Q=Q, P=np.nan) self.nw.solve('offdesign', design_path='tmp') convergence_check(self.nw.lin_dep) msg = ('Value of heat must be ' + str(Q) + ', is ' + str(self.instance.Q.val) + '.') assert round(Q, 0) == round(self.instance.Q.val, 0), msg shutil.rmtree('./tmp', ignore_errors=True)
class TestGasturbine: def setup_CombustionChamber_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]) # %% components amb = Source('ambient') sf = Source('fuel') cc = CombustionChamber('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 setup_CombustionChamberStoich_model(self): """Set up the model using the stoichimetric combustion chamber.""" # %% network setup fluid_list = ['myAir', 'myFuel', 'myFuel_fg'] self.nw2 = 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 = CombustionChamberStoich('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.nw2.add_conns(amb_cp, cp_cc, sf_cc, cc_gt, gt_fg) # %% component parameters cc.set_attr(fuel={ 'CH4': 0.96, 'CO2': 0.04 }, air={ 'Ar': 0.0129, 'N2': 0.7553, 'CO2': 0.0004, 'O2': 0.2314 }, fuel_alias='myFuel', air_alias='myAir', 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={ 'myAir': 1, 'myFuel': 0, 'myFuel_fg': 0 }) sf_cc.set_attr(T=20, fluid={'myAir': 0, 'myFuel': 1, 'myFuel_fg': 0}) gt_fg.set_attr(p=1) # %% solving self.nw2.solve(mode='design') def test_models(self): """Tests the results of both gas turbine models.""" self.setup_CombustionChamber_model() self.setup_CombustionChamberStoich_model() m1 = round(self.nw1.get_conn('flue gas after cc').m.val, 6) m2 = round(self.nw2.get_conn('flue gas after cc').m.val, 6) msg = ('The outlet mass flow of the combustion chamber model is ' + str(m1) + ' while the outlet mass flow of the combustion chamber ' 'stoich model is ' + str(m2) + '. Both values should match.') assert m1 == m2, msg T1 = self.nw1.get_conn('flue gas after cc').T.val_SI T2 = self.nw2.get_conn('flue gas after cc').T.val_SI d_rel = abs(T2 - T1) / T1 msg = ('The relative deviation in temperature after combustion is ' + str(d_rel) + ' with a maximum allowed value of 1e-3.') assert d_rel <= 1e-3, msg T1 = self.nw1.get_conn('flue gas after gt').T.val_SI T2 = self.nw2.get_conn('flue gas after gt').T.val_SI d_rel = abs(T2 - T1) / T1 msg = ('The relative deviation in temperature after the turbine is ' + str(d_rel) + ' with a maximum allowed value of 1e-3.') assert d_rel <= 1e-3, msg shutil.rmtree('LUT', ignore_errors=True)
class TestExpansion: def setup(self): self.Tamb = 20 self.pamb = 1 fluids = ['Air'] # turbine part self.nw = Network(fluids=fluids) self.nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg') # components so = Source('inlet') tu = Turbine('compressor') si = Sink('outlet') # fuel exergy bus self.exergy_fuel = Bus('fuel exergy') self.exergy_fuel.add_comps({'comp': si}, {'comp': so, 'base': 'bus'}) # product exergy bus self.exergy_prod = Bus('product exergy') self.exergy_prod.add_comps({'comp': tu, 'char': 0.9}) # create connections c1 = Connection(so, 'out1', tu, 'in1', '1') c2 = Connection(tu, 'out1', si, 'in1', '2') self.nw.add_conns(c1, c2) # component parameters tu.set_attr(eta_s=0.85, pr=1 / 5) # connection parameters c1.set_attr(m=2, p=10, fluid={'Air': 1}) c2.set_attr(T=self.Tamb) # solve network self.nw.solve('design') def test_larger_T0(self): self.nw.get_conn('2').set_attr(T=self.Tamb + 10) self.nw.solve('design') self.run_analysis() def test_T0_cross(self): self.nw.get_conn('2').set_attr(T=self.Tamb - 30) self.nw.solve('design') self.run_analysis() def test_smaller_T0(self): self.nw.get_conn('1').set_attr(T=self.Tamb - 10) self.nw.get_conn('2').set_attr(T=None) self.nw.solve('design') self.run_analysis() def run_analysis(self): ean = ExergyAnalysis(self.nw, E_P=[self.exergy_prod], E_F=[self.exergy_fuel]) ean.analyse(pamb=self.pamb, Tamb=self.Tamb) exergy_balance = (ean.network_data.E_F - ean.network_data.E_P - ean.network_data.E_L - ean.network_data.E_D) msg = ('Exergy balance must be closed (residual value smaller than ' + str(err**0.5) + ') for this test but is ' + str(round(abs(exergy_balance), 4)) + '.') assert abs(exergy_balance) <= err**0.5, msg E_D_agg = ean.aggregation_data['E_D'].sum() E_D_nw = ean.network_data.loc['E_D'] msg = ('The exergy destruction of the aggregated components and ' 'respective busses (' + str(round(E_D_agg)) + ') must be equal to ' 'the exergy destruction of the network (' + str(round(E_D_nw)) + ').') assert E_D_agg == E_D_nw, msg
class TestBusses: 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]) # %% components amb = Source('ambient') sf = Source('fuel') cc = CombustionChamber('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 = CharLine(x=x, y=y) self.motor_comp_based = CharLine(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 = CharLine(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') def test_model(self): """Test the bus functionalities in a gas turbine model.""" tpo = self.nw.busses['total power output'] ti = self.nw.busses['thermal input'] cpi = self.nw.busses['compressor power input'] cpibb = self.nw.busses['compressor power input bus based'] cp = self.nw.get_comp('compressor') gt = self.nw.get_comp('turbine') cc = self.nw.get_comp('combustion') # test results of design case eta_cpi = round(1 / cp.calc_bus_efficiency(cpi), 6) eta_cp_tpo = round(cp.calc_bus_efficiency(tpo), 6) msg = ('The efficiency value of the compressor on the bus ' + tpo.label + ' (' + str(eta_cp_tpo) + ') must be identical to the efficiency ' 'on the bus ' + cpi.label + ' (' + str(eta_cpi) + ').') assert eta_cp_tpo == eta_cpi, msg P_cp_tpo = cp.calc_bus_value(tpo) eta_cp_tpo = cp.calc_bus_efficiency(tpo) P_cp = round(P_cp_tpo * eta_cp_tpo, 0) msg = ('The compressor power must be ' + str(round(cp.P.val, 0)) + ' on ' 'the bus ' + tpo.label + ' but is ' + str(P_cp) + ').') assert round(cp.P.val, 0) == P_cp, msg P_cp_tpo = round( cp.calc_bus_value(tpo) * cp.calc_bus_efficiency(tpo), 0) P_cp_cpi = round( cp.calc_bus_value(cpi) / cp.calc_bus_efficiency(cpi), 0) P_cp_cpibb = round( cp.calc_bus_value(cpibb) * cp.calc_bus_efficiency(cpibb), 0) msg = ( 'The busses\' component power value for the compressor on bus ' + tpo.label + ' (' + str(P_cp_tpo) + ') must be equal to the ' 'component power on all other busses. Bus ' + cpi.label + ' (' + str(P_cp_cpi) + ') and bus ' + cpibb.label + ' (' + str(P_cp_cpibb) + ').') assert P_cp_tpo == P_cp_cpi and P_cp_tpo == P_cp_cpibb, msg eta_gt_tpo = gt.calc_bus_efficiency(tpo) msg = ('The efficiency value of the turbine on the bus ' + tpo.label + ' (' + str(eta_gt_tpo) + ') must be equal to 0.975.') assert eta_gt_tpo == 0.975, msg eta_ti = cc.calc_bus_efficiency(ti) msg = ('The efficiency value of the combustion chamber on the bus ' + ti.label + ' (' + str(eta_ti) + ') must be equal to 1.0.') assert eta_ti == 1.0, msg # test partload for bus functions # first test in identical conditions self.nw.get_conn('ambient air flow').set_attr(m=None) P_design = cpibb.P.val cpibb.set_attr(P=P_design) self.nw.solve('offdesign', design_path='tmp') eta_cpi = round(1 / cp.calc_bus_efficiency(cpi), 6) eta_cp_tpo = round(cp.calc_bus_efficiency(tpo), 6) msg = ('The efficiency value of the compressor on the bus ' + tpo.label + ' (' + str(eta_cp_tpo) + ') must be identical to the efficiency ' 'on the bus ' + cpi.label + ' (' + str(eta_cpi) + ').') assert eta_cp_tpo == eta_cpi, msg eta_gt_tpo = gt.calc_bus_efficiency(tpo) msg = ('The efficiency value of the turbine on the bus ' + tpo.label + ' (' + str(eta_gt_tpo) + ') must be equal to 0.975.') assert eta_gt_tpo == 0.975, msg P_cp_tpo = round( cp.calc_bus_value(tpo) * cp.calc_bus_efficiency(tpo), 0) P_cp_cpi = round( cp.calc_bus_value(cpi) / cp.calc_bus_efficiency(cpi), 0) P_cp_cpibb = round( cp.calc_bus_value(cpibb) * cp.calc_bus_efficiency(cpibb), 0) msg = ( 'The busses\' component power value for the compressor on bus ' + tpo.label + ' (' + str(P_cp_tpo) + ') must be equal to the ' 'component power on all other busses. Bus ' + cpi.label + ' (' + str(P_cp_cpi) + ') and bus ' + cpibb.label + ' (' + str(P_cp_cpibb) + ').') assert P_cp_tpo == P_cp_cpi and P_cp_tpo == P_cp_cpibb, msg # 60 % load load = 0.6 cpibb.set_attr(P=P_design * load) self.nw.solve('offdesign', design_path='tmp') eta_cp_tpo = round(cp.calc_bus_efficiency(tpo), 6) eta_cp_char = self.motor_bus_based.evaluate(load) msg = ('The efficiency value of the compressor on the bus ' + tpo.label + ' (' + str(eta_cp_tpo) + ') must be identical to the efficiency ' 'on the characteristic line (' + str(eta_cp_char) + ').') assert eta_cp_tpo == eta_cp_char, msg load_frac = round( cp.calc_bus_value(tpo) / tpo.comps.loc[cp, 'P_ref'], 6) msg = ('The load fraction value of the compressor on the bus ' + tpo.label + ' (' + str(load_frac) + ') must be identical to the ' 'load fraction value on the bus ' + cpibb.label + ' (' + str(load) + ').') assert load == load_frac, msg eta_cpi = round(1 / cp.calc_bus_efficiency(cpi), 6) eta_cp_tpo = round(cp.calc_bus_efficiency(tpo), 6) msg = ('The efficiency value of the compressor on the bus ' + tpo.label + ' (' + str(eta_cp_tpo) + ') must be higher than the efficiency ' 'on the bus ' + cpi.label + ' (' + str(eta_cpi) + ').') assert eta_cp_tpo > eta_cpi, msg P_cp_tpo = round( cp.calc_bus_value(tpo) * cp.calc_bus_efficiency(tpo), 0) P_cp_cpi = round( cp.calc_bus_value(cpi) / cp.calc_bus_efficiency(cpi), 0) P_cp_cpibb = round( cp.calc_bus_value(cpibb) * cp.calc_bus_efficiency(cpibb), 0) msg = ( 'The busses\' component power value for the compressor on bus ' + tpo.label + ' (' + str(P_cp_tpo) + ') must be equal to the ' 'component power on all other busses. Bus ' + cpi.label + ' (' + str(P_cp_cpi) + ') and bus ' + cpibb.label + ' (' + str(P_cp_cpibb) + ').') assert P_cp_tpo == P_cp_cpi and P_cp_tpo == P_cp_cpibb, msg shutil.rmtree('tmp', ignore_errors=True)