def test_CombustionChamber(self): """ Test component properties of combustion chamber. """ instance = CombustionChamber('combustion chamber') self.setup_CombustionChamber_network(instance) # connection parameter specification 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} self.c1.set_attr(fluid=air, p=1, T=30) self.c2.set_attr(fluid=fuel, T=30) self.c3.set_attr(T=1200) # test specified bus value on CombustionChamber (must be equal to ti) b = Bus('thermal input', P=1e6) b.add_comps({'comp': instance}) self.nw.add_busses(b) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of thermal input must be ' + str(b.P.val) + ', is ' + str(instance.ti.val) + '.') assert round(b.P.val, 1) == round(instance.ti.val, 1), msg b.set_attr(P=np.nan) # test specified thermal input for CombustionChamber instance.set_attr(ti=1e6) self.nw.solve('design') convergence_check(self.nw.lin_dep) ti = (self.c2.m.val_SI * self.c2.fluid.val['CH4'] * instance.fuels['CH4']['LHV']) msg = ('Value of thermal input must be ' + str(instance.ti.val) + ', is ' + str(ti) + '.') assert round(ti, 1) == round(instance.ti.val, 1), msg # test specified lamb for CombustionChamber self.c3.set_attr(T=np.nan) instance.set_attr(lamb=1) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of oxygen in flue gas must be 0.0, is ' + str(round(self.c3.fluid.val['O2'], 4)) + '.') assert 0.0 == round(self.c3.fluid.val['O2'], 4), msg
p=5, fluid={ 'CO2': 0, 'Ar': 0, 'N2': 0, 'O2': 0, 'H2O': 1, 'CH4': 0 }) dh_w.set_attr(T=90) # %% nw.solve(mode='design') nw.print_results() nw.save('design_point') document_model(nw, filename='report_design.tex') power.set_attr(P=-100e6) nw.solve(mode='offdesign', init_path='design_point', design_path='design_point') nw.print_results() document_model(nw, filename='report_offdesign.tex') power.set_attr(P=1 / 0.9 * 0.8 * power.P.val) nw.solve(mode='offdesign', design_path='design_point') nw.print_results()
c_in_cd.set_attr(fluid={'NH3': 1, 'H2O': 0}) sys_IF.set_attr(T=60, p=10, fluid={'NH3': 0, 'H2O': 1}) IF_sys.set_attr(T=65) cd_valve.set_attr(Td_bp=-5) # evaporator system cold side pu_ev.set_attr(m=Ref(valve_dr, 4, 0), p0=5) su_cp.set_attr(p0=5, h0=1700, Td_bp=5) # evaporator system hot side sto_IF.set_attr(T=10, p=5, fluid={'NH3': 0, 'H2O': 1}) IF_sto.set_attr(T=5, design=['T']) heat.set_attr(P=1000e3) # %% Calculation nw.solve('design') nw.print_results() save_file = 'hp_discharge' nw.save(save_file) mass_flow_hp = c_in_cd.m.val_SI print('COP_design:', heat.P.val / power.P.val) nw.set_attr(iterinfo=False) # heat.set_attr(P=850e3) for T in np.linspace(25, 5, 21): sto_IF.set_attr(T=T) nw.solve('offdesign', design_path=save_file)
c_in_cd.set_attr(fluid={'NH3': 1, 'H2O': 0}) sys_IF.set_attr(T=55, p=10, fluid={'NH3': 0, 'H2O': 1}) IF_sys.set_attr(T=70) cd_valve.set_attr(Td_bp=-5) # evaporator system cold side pu_ev.set_attr(m=Ref(valve_dr, 4, 0), p0=5) su_cp.set_attr(p0=5, h0=1700, Td_bp=5) # evaporator system hot side sto_IF.set_attr(T=45, p=5, fluid={'NH3': 0, 'H2O': 1}) IF_sto.set_attr(T=30, design=['T']) heat.set_attr(P=3e5) # %% Calculation nw.solve('design') nw.print_results() save_file = 'hp_discharge' nw.save(save_file) mass_flow_hp = c_in_cd.m.val_SI #print('Heat pump mass flow', mass_flow_hp) print('COP_design:', heat.P.val / power.P.val) nw.set_attr(iterinfo=False)
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)
def test_HeatExhangerSimple(self): """Test component properties of simple heat exchanger.""" instance = HeatExchangerSimple('heat exchanger') self.setup_HeatExchangerSimple_network(instance) fl = {'Ar': 0, 'H2O': 1, 'S800': 0} self.c1.set_attr(fluid=fl, m=1, p=10, T=100) # trigger heat exchanger parameter groups instance.set_attr(hydro_group='HW', L=100, ks=100, pr=0.99, Tamb=20) # test grouped parameter settings with missing parameters instance.hydro_group.is_set = True instance.kA_group.is_set = True instance.kA_char_group.is_set = True self.nw.solve('design', init_only=True) msg = ('Hydro group must no be set, if one parameter is missing!') assert instance.hydro_group.is_set is False, msg msg = ('kA group must no be set, if one parameter is missing!') assert instance.kA_group.is_set is False, msg msg = ('kA char group must no be set, if one parameter is missing!') assert instance.kA_char_group.is_set is False, msg # test diameter calculation from specified dimensions (as pipe) # with Hazen-Williams method instance.set_attr(hydro_group='HW', D='var', L=100, ks=100, pr=0.99, Tamb=20) b = Bus('heat', P=-1e5) b.add_comps({'comp': instance}) self.nw.add_busses(b) self.nw.solve('design') convergence_check(self.nw.lin_dep) pr = round(self.c2.p.val_SI / self.c1.p.val_SI, 3) msg = ('Value of pressure ratio must be ' + str(pr) + ', is ' + str(instance.pr.val) + '.') assert pr == round(instance.pr.val, 3), msg # make zeta system variable and use previously calculated diameter # to calculate zeta. The value for zeta must not change zeta = round(instance.zeta.val, 0) instance.set_attr(D=instance.D.val, zeta='var', pr=np.nan) instance.D.is_var = False self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of zeta must be ' + str(zeta) + ', is ' + str(round(instance.zeta.val, 0)) + '.') assert zeta == round(instance.zeta.val, 0), msg # same test with pressure ratio as sytem variable pr = round(instance.pr.val, 3) instance.set_attr(zeta=np.nan, pr='var') self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of pressure ratio must be ' + str(pr) + ', is ' + str(round(instance.pr.val, 3)) + '.') assert pr == round(instance.pr.val, 3), msg # test heat transfer coefficient as variable of the system (ambient # temperature required) instance.set_attr(kA='var', pr=np.nan) b.set_attr(P=-5e4) self.nw.solve('design') convergence_check(self.nw.lin_dep) # due to heat output being half of reference (for Tamb) kA should be # somewhere near to that (actual value is 677) msg = ('Value of heat transfer coefficient must be 677, is ' + str(instance.kA.val) + '.') assert 677 == round(instance.kA.val, 0), msg # test heat transfer as variable of the system instance.set_attr(Q='var', kA=np.nan) Q = -5e4 b.set_attr(P=Q) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of heat transfer must be ' + str(Q) + ', is ' + str(instance.Q.val) + '.') assert Q == round(instance.Q.val, 0), msg
def test_HeatExchanger(self): """Test component properties of heat exchanger.""" instance = HeatExchanger('heat exchanger') self.setup_HeatExchanger_network(instance) # design specification instance.set_attr(pr1=0.98, pr2=0.98, ttd_u=5, design=['pr1', 'pr2', 'ttd_u'], offdesign=['zeta1', 'zeta2', 'kA_char']) self.c1.set_attr(T=120, p=3, fluid={'Ar': 0, 'H2O': 1, 'S800': 0}) self.c2.set_attr(T=70) self.c3.set_attr(T=40, p=5, fluid={'Ar': 1, 'H2O': 0, 'S800': 0}) b = Bus('heat transfer', P=-80e3) b.add_comps({'comp': instance}) self.nw.add_busses(b) self.nw.solve('design') convergence_check(self.nw.lin_dep) self.nw.save('tmp') Q_design = instance.Q.val # test specified kA value instance.set_attr(kA=instance.kA.val * 2 / 3) b.set_attr(P=None) self.nw.solve('design') convergence_check(self.nw.lin_dep) # test heat transfer Q = self.c1.m.val_SI * (self.c2.h.val_SI - self.c1.h.val_SI) msg = ( 'Value of heat flow must be ' + str(round(Q_design * 2 / 3, 0)) + ', is ' + str(round(Q, 0)) + '.') assert round(Q, 1) == round(Q_design * 2 / 3, 1), msg # back to design case instance.set_attr(kA=None) b.set_attr(P=Q_design) self.nw.solve('design') convergence_check(self.nw.lin_dep) # check heat transfer Q = self.c1.m.val_SI * (self.c2.h.val_SI - self.c1.h.val_SI) td_log = ((self.c2.T.val - self.c3.T.val - self.c1.T.val + self.c4.T.val) / np.log((self.c2.T.val - self.c3.T.val) / (self.c1.T.val - self.c4.T.val))) kA = round(-Q / td_log, 0) msg = ('Value of heat transfer must be ' + str(round(Q, 0)) + ', is ' + str(round(instance.Q.val, 0)) + '.') assert round(Q, 0) == round(instance.Q.val, 0), msg # check upper terminal temperature difference msg = ('Value of terminal temperature difference must be ' + str(round(instance.ttd_u.val, 1)) + ', is ' + str(round(self.c1.T.val - self.c4.T.val, 1)) + '.') ttd_u_calc = round(self.c1.T.val - self.c4.T.val, 1) ttd_u = round(instance.ttd_u.val, 1) assert ttd_u_calc == ttd_u, msg # check lower terminal temperature difference self.c2.set_attr(T=np.nan) instance.set_attr(ttd_l=20) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of terminal temperature difference must be ' + str(instance.ttd_l.val) + ', is ' + str(self.c2.T.val - self.c3.T.val) + '.') ttd_l_calc = round(self.c2.T.val - self.c3.T.val, 1) ttd_l = round(instance.ttd_l.val, 1) assert ttd_l_calc == ttd_l, msg # check specified kA value (by offdesign parameter), reset temperatures # to design state self.c2.set_attr(T=70) instance.set_attr(ttd_l=np.nan) self.nw.solve('offdesign', design_path='tmp') convergence_check(self.nw.lin_dep) msg = ('Value of heat flow must be ' + str(instance.Q.val) + ', is ' + str(round(Q, 0)) + '.') assert round(Q, 0) == round(instance.Q.val, 0), msg msg = ('Value of heat transfer coefficient must be ' + str(kA) + ', is ' + str(round(instance.kA.val, 0)) + '.') assert kA == round(instance.kA.val, 0), msg # trigger negative lower terminal temperature difference as result self.c4.set_attr(T=np.nan) self.c2.set_attr(T=30) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of upper terminal temperature differences must be ' 'smaller than zero, is ' + str(round(instance.ttd_l.val, 1)) + '.') assert instance.ttd_l.val < 0, msg # trigger negative upper terminal temperature difference as result self.c4.set_attr(T=100) self.c2.set_attr(h=200e3, T=np.nan) instance.set_attr(pr1=0.98, pr2=0.98, ttd_u=np.nan, design=['pr1', 'pr2']) self.c1.set_attr(h=150e3, T=np.nan) self.c3.set_attr(T=40) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of upper terminal temperature differences must be ' 'smaller than zero, is ' + str(round(instance.ttd_u.val, 1)) + '.') assert instance.ttd_u.val < 0, msg shutil.rmtree('./tmp', ignore_errors=True)
offdesign=['zeta2', 'kA_char']) pu.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char']) steam_generator.set_attr(pr=0.95) # %% parametrization of connections # offdesign calculation: use parameter design for auto deactivation # turbine inlet pressure is deriven by stodolas law, outlet pressure by # characteristic of condenser fs_in.set_attr(p=100, T=500, fluid={'water': 1}, design=['p']) cw_in.set_attr(T=20, p=5, fluid={'water': 1}) cw_out.set_attr(T=30) # total output power as input parameter power.set_attr(P=-10e6) # %% solving # solve the network, print the results to prompt and save nw.solve('design') nw.print_results() nw.save('design') document_model(nw, filename='report_design.tex') # reset power input power.set_attr(P=-9e6) # the design file holds the information on the design case # initialisation from previously design process nw.solve('offdesign', design_path='design')
cons_cf.set_attr(h=Ref(cb_dhp, 1, 0), p=Ref(cb_dhp, 1, 0)) # evaporator system cold side erp_ev.set_attr(m=Ref(va_dr, 1.25, 0), p0=5) dr_cp.set_attr(p0=17, h0=1650) # low temp water system lt_so_pu.set_attr(p=10, T=T_source_vl, fluid={'air': 0, 'NH3': 0, 'water': 1}) # pu_ev.set_attr(offdesign=['v']) ev_lt_si.set_attr(p=10, T=T_source_rl) # %% key paramter heat.set_attr(P=Q_N) # %% Calculation nw.solve('design') nw.print_results() nw.save('hp_water') document_model(nw) cop = abs(heat.P.val) / power.P.val print('COP:', cop) print('P_out:', power.P.val / 1e6) print('Q_out:', heat.P.val / 1e6) cp.eta_s_char.char_func.extrapolate = True
# evaporator system hot side # pumping at constant rate in partload amb_pu.set_attr(T=T_amb, p=1, fluid={'air': 0, 'NH3': 0, 'water': 1}, offdesign=['v']) sp_su.set_attr(offdesign=['v']) ev_amb_out.set_attr(p=1, T=T_amb_out, design=['T']) # compressor-system he_cp2.set_attr(Td_bp=5, p0=20, design=['Td_bp']) ic_out.set_attr(T=10, design=['T']) # %% key paramter heat.set_attr(P=Q_N) # %% Calculation nw.solve('design') nw.print_results() nw.save('hp_water') document_model(nw, 'report_design', draft=False) cp1.eta_s_char.char_func.extrapolate = True cp2.eta_s_char.char_func.extrapolate = True nw.solve('offdesign', design_path='hp_water') # document_model(nw) nw.set_attr(iterinfo=False)
'CO2': 0, 'Ar': 0, 'N2': 0, 'O2': 0, 'H2O': 1, 'CH4': 0 }) cw_o.set_attr(T=30, design=['T'], offdesign=['m']) # %% design case 1: # district heating condeser layout # Q_N=65 heat_out.set_attr(P=Q_N) nw.solve(mode='design', init_path='cet_stable') nw.print_results() nw.save('cet_design_maxQ') gt_power_design = gt_power.P.val print(heat_out.P.val / heat_in.P.val, power.P.val / heat_in.P.val) print(heat_out.P.val, power.P.val, heat_in.P.val) print(gt_power.P.val) # %% design case 2: # maximum gas turbine minimum heat extraction (cet_design_minQ) gt_power.set_attr(P=gt_power_design) heat_out.set_attr(P=-10e6) # local offdesign for district heating condenser cond_dh.set_attr(local_offdesign=True, design_path='cet_design_maxQ')
sg3.set_attr(pr=.99) sg1_sg2.set_attr(x=0) sg2_sg3.set_attr(x=1) # Connections cc_st.set_attr(T=500, p=100, fluid={'H2O': 1}) dh_Source_con.set_attr(T=T_dh_in, p=10, fluid={'H2O': 1}) con_dh_Sink.set_attr(T=T_dh_out) # %% keyparameter con.set_attr(Q=-30e6) # %% solving design mode nw.solve('design') nw.save('bpt') print(power.P.val) # plotting Ts-Diagram results = results() plot_Ts(results) # %% offdesign con.set_attr(Q=np.nan) power.set_attr(P=-10263542) nw.solve('offdesign', init_path='bpt', design_path='bpt') print(power.P.val)
nw.add_busses(heat, heat_sto, power, ti) # %% parameters he.set_attr(pr1=0.98, pr2=0.98, design=['pr1', 'pr2'], offdesign=['zeta1', 'zeta2', 'kA_char']) # %% Schnittstellenparameter hs_he.set_attr(T=90, p=10, fluid={'water': 1}) he_hs.set_attr(T=60, design=['T']) tes_he.set_attr(T=40, p=10, fluid={'water': 1}) he_tes.set_attr(T=75) heat.set_attr(P=1000e3) heat_design = heat.P.val # %% Calculation nw.solve('design') nw.save('he_charge') nw.print_results() # testin lower loads heat.set_attr(P=heat_design / 2) nw.solve('offdesign', design_path='he_charge') # save this for interface initialisation heat.set_attr(P=heat_design / 4) nw.solve('offdesign', design_path='he_charge')
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)
# pressure after turbine inlet valve fs.set_attr(p=100, design=['p']) # pressure extraction steam ext.set_attr(p=10, design=['p']) # staring value for warm feed water fw_w.set_attr(h0=310) # cooling water inlet cw_in.set_attr(T=60, p=10, fluid={'water': 1}) # setting key parameters: # Power of the plant power_bus.set_attr(P=-5e6) # cw_out.set_attr(T=110) # %% solving path = 'chp' nw.solve('design') nw.save(path) nw.print_results() document_model(nw, filename='report_design.tex') power_bus.set_attr(P=None) m_design = fs_in.m.val fs_in.set_attr(m=m_design)