nw.add_conns(sf_comb, amb_comb, comb_fg) cw1_chp1 = Connection(cw_in1, 'out1', chp, 'in1') cw2_chp2 = Connection(cw_in2, 'out1', chp, 'in2') nw.add_conns(cw1_chp1, cw2_chp2) chp1_cw = Connection(chp, 'out1', cw_out1, 'in1') chp2_cw = Connection(chp, 'out2', cw_out2, 'in1') nw.add_conns(chp1_cw, chp2_cw) # %% component parameters # set combustion chamber fuel, air to stoichometric air ratio and thermal input chp.set_attr(pr1=0.99, pr2=0.99, P=-10e6, lamb=1.2) # %% connection parameters # air from abient (ambient pressure and temperature), air composition must be # stated component wise. amb_comb.set_attr(p=5, T=30, fluid={ 'Ar': 0.0129, 'N2': 0.7553, 'H2O': 0, 'CH4': 0, 'CO2': 0.0004, 'O2': 0.2314 })
def test_CombustionEngine(self): """Test component properties of combustion engine.""" instance = CombustionEngine('combustion engine') self.setup_CombustionEngine_network(instance) air = { 'N2': 0.7556, 'O2': 0.2315, 'Ar': 0.0129, 'H2O': 0, 'CO2': 0, 'CH4': 0 } fuel = {'N2': 0, 'O2': 0, 'Ar': 0, 'H2O': 0, 'CO2': 0.04, 'CH4': 0.96} water1 = {'N2': 0, 'O2': 0, 'Ar': 0, 'H2O': 1, 'CO2': 0, 'CH4': 0} water2 = {'N2': 0, 'O2': 0, 'Ar': 0, 'H2O': 1, 'CO2': 0, 'CH4': 0} # connection parametrisation instance.set_attr(pr1=0.99, pr2=0.99, lamb=1.0, design=['pr1', 'pr2'], offdesign=['zeta1', 'zeta2']) self.c1.set_attr(p=5, T=30, fluid=air) self.c2.set_attr(T=30, fluid=fuel) self.c4.set_attr(p=3, T=60, m=50, fluid=water1) self.c5.set_attr(p=3, T=80, m=50, fluid=water2) # create busses TI = Bus('thermal input') Q1 = Bus('heat output 1') Q2 = Bus('heat output 2') Q = Bus('heat output') Qloss = Bus('thermal heat loss') TI.add_comps({'comp': instance, 'param': 'TI'}) Q1.add_comps({'comp': instance, 'param': 'Q1'}) Q2.add_comps({'comp': instance, 'param': 'Q2'}) Q.add_comps({'comp': instance, 'param': 'Q'}) Qloss.add_comps({'comp': instance, 'param': 'Qloss'}) self.nw.add_busses(TI, Q1, Q2, Q, Qloss) # test specified thermal input bus value ti = 1e6 TI.set_attr(P=ti) self.nw.solve('design') convergence_check(self.nw.lin_dep) self.nw.save('tmp') # calculate in offdesign mode self.nw.solve('offdesign', init_path='tmp', design_path='tmp') convergence_check(self.nw.lin_dep) msg = ('Value of thermal input must be ' + str(TI.P.val) + ', is ' + str(instance.ti.val) + '.') assert round(TI.P.val, 1) == round(instance.ti.val, 1), msg # test specified thermal input in component TI.set_attr(P=np.nan) instance.set_attr(ti=ti) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') convergence_check(self.nw.lin_dep) msg = ('Value of thermal input must be ' + str(ti) + ', is ' + str(instance.ti.val) + '.') assert round(ti, 1) == round(instance.ti.val, 1), msg instance.set_attr(ti=None) # test specified heat output 1 bus value Q1.set_attr(P=instance.Q1.val) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') convergence_check(self.nw.lin_dep) # heat output is at design point value, thermal input must therefore # not have changed msg = ('Value of thermal input must be ' + str(ti) + ', is ' + str(instance.ti.val) + '.') assert round(ti, 1) == round(instance.ti.val, 1), msg # calculate heat output over cooling loop heat1 = self.c4.m.val_SI * (self.c6.h.val_SI - self.c4.h.val_SI) msg = ('Value of heat output 1 must be ' + str(-heat1) + ', is ' + str(instance.Q1.val) + '.') assert round(heat1, 1) == -round(instance.Q1.val, 1), msg Q1.set_attr(P=np.nan) # test specified heat output 2 bus value Q2.set_attr(P=1.2 * instance.Q2.val) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') convergence_check(self.nw.lin_dep) # calculate heat output over cooling loop heat2 = self.c5.m.val_SI * (self.c7.h.val_SI - self.c5.h.val_SI) msg = ('Value of heat output 2 must be ' + str(-heat2) + ', is ' + str(instance.Q2.val) + '.') assert round(heat2, 1) == -round(instance.Q2.val, 1), msg # test specified heat output 2 in component Q2.set_attr(P=np.nan) instance.set_attr(Q2=-heat2) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') convergence_check(self.nw.lin_dep) heat2 = self.c5.m.val_SI * (self.c7.h.val_SI - self.c5.h.val_SI) msg = ('Value of heat output 2 must be ' + str(-heat2) + ', is ' + str(instance.Q2.val) + '.') assert round(heat2, 1) == -round(instance.Q2.val, 1), msg # test total heat output bus value instance.set_attr(Q2=np.nan) Q.set_attr(P=1.5 * instance.Q1.val) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') convergence_check(self.nw.lin_dep) heat = (self.c4.m.val_SI * (self.c6.h.val_SI - self.c4.h.val_SI) + self.c5.m.val_SI * (self.c7.h.val_SI - self.c5.h.val_SI)) msg = ('Value of total heat output must be ' + str(Q.P.val) + ', is ' + str(-heat) + '.') assert round(Q.P.val, 1) == -round(heat, 1), msg # test specified heat loss bus value Q.set_attr(P=np.nan) Qloss.set_attr(P=-1e5) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') convergence_check(self.nw.lin_dep) msg = ('Value of heat loss must be ' + str(Qloss.P.val) + ', is ' + str(instance.Qloss.val) + '.') assert round(Qloss.P.val, 1) == round(instance.Qloss.val, 1), msg shutil.rmtree('./tmp', ignore_errors=True)
# heat to power x = np.array([0.550, 0.660, 0.770, 0.880, 0.990, 1.100]) y = np.array([0.238, 0.219, 0.203, 0.190, 0.180, 0.173]) Q1_char = dict(char_func=CharLine(x, y)) Q2_char = dict(char_func=CharLine(x, y)) # heat loss to power x = np.array([0.50, 0.7500, 0.90, 1.000, 1.050]) y = np.array([0.32, 0.3067, 0.30, 0.295, 0.293]) Qloss_char = dict(char_func=CharLine(x, y)) # set combustion chamber fuel, air to stoichometric air ratio and thermal input ice.set_attr(pr1=0.98, lamb=1.0, design=['pr1'], offdesign=['zeta1'], tiP_char=tiP_char, Q1_char=Q1_char, Q2_char=Q2_char, Qloss_char=Qloss_char) # flue gas cooler x1 = np.array([ 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5 ]) y1 = 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 ])