def setup(self): self.nw = nwk.network(['water', 'air']) self.comp = cmp.cogeneration_unit('cogeneration unit') self.pipe = cmp.pipe('pipe') self.conn = con.connection(self.comp, 'out1', self.pipe, 'in1') self.bus = con.bus('mybus') self.sub = subsys.subsystem('MySub')
def test_cogeneration_unit(self): """ Test component properties of cogeneration unit. """ amb = cmp.source('ambient') sf = cmp.source('fuel') fg = cmp.sink('flue gas outlet') cw_in1 = cmp.source('cooling water inlet1') cw_in2 = cmp.source('cooling water inlet2') cw_out1 = cmp.sink('cooling water outlet1') cw_out2 = cmp.sink('cooling water outlet2') chp = cmp.cogeneration_unit('cogeneration unit', fuel='CH4') amb_comb = con.connection(amb, 'out1', chp, 'in3') sf_comb = con.connection(sf, 'out1', chp, 'in4') comb_fg = con.connection(chp, 'out3', fg, 'in1') self.nw.add_conns(sf_comb, amb_comb, comb_fg) cw1_chp1 = con.connection(cw_in1, 'out1', chp, 'in1') cw2_chp2 = con.connection(cw_in2, 'out1', chp, 'in2') self.nw.add_conns(cw1_chp1, cw2_chp2) chp1_cw = con.connection(chp, 'out1', cw_out1, 'in1') chp2_cw = con.connection(chp, 'out2', cw_out2, 'in1') self.nw.add_conns(chp1_cw, chp2_cw) air = { 'N2': 0.7556, 'O2': 0.2315, 'Ar': 0.0129, 'INCOMP::DowQ': 0, 'H2O': 0, 'NH3': 0, 'CO2': 0, 'CH4': 0 } fuel = { 'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'H2O': 0, 'NH3': 0, 'CO2': 0.04, 'CH4': 0.96 } water1 = { 'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'H2O': 1, 'NH3': 0, 'CO2': 0, 'CH4': 0 } water2 = { 'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'H2O': 1, 'NH3': 0, 'CO2': 0, 'CH4': 0 } chp.set_attr(fuel='CH4', pr1=0.99, pr2=0.99, lamb=1.2, design=['pr1', 'pr2'], offdesign=['zeta1', 'zeta2']) amb_comb.set_attr(p=5, T=30, fluid=air) sf_comb.set_attr(T=30, fluid=fuel) cw1_chp1.set_attr(p=3, T=60, m=50, fluid=water1) cw2_chp2.set_attr(p=3, T=80, m=50, fluid=water2) TI = con.bus('thermal input') Q1 = con.bus('heat output 1') Q2 = con.bus('heat output 2') Q = con.bus('heat output') Qloss = con.bus('thermal heat loss') TI.add_comps({'c': chp, 'p': 'TI'}) Q1.add_comps({'c': chp, 'p': 'Q1'}) Q2.add_comps({'c': chp, 'p': 'Q2'}) Q.add_comps({'c': chp, 'p': 'Q'}) Qloss.add_comps({'c': chp, 'p': 'Qloss'}) self.nw.add_busses(TI, Q1, Q2, Q, Qloss) ti = 1e6 TI.set_attr(P=ti) # design point self.nw.solve('design') self.nw.save('tmp') self.nw.solve('offdesign', init_path='tmp', design_path='tmp') eq_( round(TI.P.val, 1), round(chp.ti.val, 1), 'Value of thermal input must be ' + str(TI.P.val) + ', is ' + str(chp.ti.val) + '.') # ti via component TI.set_attr(P=np.nan) chp.set_attr(ti=ti) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') eq_( round(ti, 1), round(chp.ti.val, 1), 'Value of thermal input must be ' + str(ti) + ', is ' + str(chp.ti.val) + '.') chp.set_attr(ti=np.nan) # Q1 via bus Q1.set_attr(P=chp.Q1.val) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') eq_( round(ti, 1), round(chp.ti.val, 1), 'Value of thermal input must be ' + str(ti) + ', is ' + str(chp.ti.val) + '.') heat1 = chp1_cw.m.val_SI * (chp1_cw.h.val_SI - cw1_chp1.h.val_SI) eq_( round(heat1, 1), round(chp.Q1.val, 1), 'Value of thermal input must be ' + str(heat1) + ', is ' + str(chp.Q1.val) + '.') Q1.set_attr(P=np.nan) # Q2 via bus Q2.set_attr(P=1.2 * chp.Q2.val) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') # due to characteristic function Q1 is equal to Q2 for this cogeneration unit heat1 = chp1_cw.m.val_SI * (chp1_cw.h.val_SI - cw1_chp1.h.val_SI) eq_( round(heat1, 1), round(chp.Q2.val, 1), 'Value of heat output 2 must be ' + str(heat1) + ', is ' + str(chp.Q2.val) + '.') # Q2 via component Q2.set_attr(P=np.nan) chp.set_attr(Q2=heat1) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') heat1 = chp1_cw.m.val_SI * (chp1_cw.h.val_SI - cw1_chp1.h.val_SI) eq_( round(heat1, 1), round(chp.Q2.val, 1), 'Value of heat output 2 must be ' + str(heat1) + ', is ' + str(chp.Q2.val) + '.') # Q via bus chp.set_attr(Q2=np.nan) Q.set_attr(P=1.5 * chp.Q1.val) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') eq_( round(Q.P.val, 1), round(2 * chp.Q2.val, 1), 'Value of total heat output (' + str(Q.P.val) + ') must be twice as much as value of heat output 2 (' + str(chp.Q2.val) + ').') # Qloss via bus Q.set_attr(P=np.nan) Qloss.set_attr(P=1e5) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') eq_( round(Qloss.P.val, 1), round(chp.Qloss.val, 1), 'Value of heat loss must be ' + str(Qloss.P.val) + ', is ' + str(chp.Qloss.val) + '.') shutil.rmtree('./tmp', ignore_errors=True)
def setup(self): self.nw = nwk.network(['water', 'air']) self.comp = cmp.cogeneration_unit('cogeneration unit') self.bus = con.bus('power') self.bus.add_comps({'c': self.comp, 'p': 'Param'})
def cmp_instanciation_ValueError(self, label): cmp.cogeneration_unit(label)
# %% components # sinks & sources amb = cmp.source('ambient') sf = cmp.source('fuel') fg = cmp.sink('flue gas outlet') cw_in1 = cmp.source('cooling water inlet1') cw_in2 = cmp.source('cooling water inlet2') cw_out1 = cmp.sink('cooling water outlet1') cw_out2 = cmp.sink('cooling water outlet2') split = cmp.splitter('splitter') merge = cmp.merge('merge') # combustion chamber chp = cmp.cogeneration_unit(label='cogeneration unit') # %% connections amb_comb = con.connection(amb, 'out1', chp, 'in3') sf_comb = con.connection(sf, 'out1', chp, 'in4') comb_fg = con.connection(chp, 'out3', fg, 'in1') nw.add_conns(sf_comb, amb_comb, comb_fg) cw1_chp1 = con.connection(cw_in1, 'out1', chp, 'in1') cw2_chp2 = con.connection(cw_in2, 'out1', chp, 'in2') nw.add_conns(cw1_chp1, cw2_chp2) chp1_cw = con.connection(chp, 'out1', cw_out1, 'in1')