def setup_network_electrolyzer(self, instance): """ Set up network for electrolyzer tests. """ fw = cmp.source('feed water') cw_in = cmp.source('cooling water') o2 = cmp.sink('oxygen sink') h2 = cmp.sink('hydrogen sink') cw_out = cmp.sink('cooling water sink') instance.set_attr(pr_c=0.99) cw_el = con.connection(cw_in, 'out1', instance, 'in1', fluid={ 'H2O': 1, 'H2': 0, 'O2': 0 }, T=20, p=1) el_cw = con.connection(instance, 'out1', cw_out, 'in1', T=45) self.nw.add_conns(cw_el, el_cw) fw_el = con.connection(fw, 'out1', instance, 'in2', m=0.1, T=20, p=10) el_o2 = con.connection(instance, 'out2', o2, 'in1') el_h2 = con.connection(instance, 'out3', h2, 'in1', T=50) self.nw.add_conns(fw_el, el_o2, el_h2)
def setup(self): self.nw = nwk.network(['H2O', 'N2', 'O2', 'Ar', 'CO2', 'H2']) self.comb = cmp.combustion_chamber('combustion chamber') c1 = con.connection(cmp.source('air'), 'out1', self.comb, 'in1') c2 = con.connection(cmp.source('fuel'), 'out1', self.comb, 'in2') c3 = con.connection(self.comb, 'out1', cmp.sink('flue gas'), 'in1') self.nw.add_conns(c1, c2, c3)
def test_condenser(self): """ Test component properties of condenser. """ tesin = cmp.sink('TES in') tesout = cmp.source('TES out') hsin = cmp.sink('Cond in') hsout = cmp.source('Cond out') he = cmp.condenser('condenser') tes_he = con.connection(tesout, 'out1', he, 'in2') he_tes = con.connection(he, 'out2', tesin, 'in1') hs_he = con.connection(hsout, 'out1', he, 'in1') he_hs = con.connection(he, 'out1', hsin, 'in1') self.nw.add_conns(tes_he, he_tes, hs_he, he_hs) # design specification he.set_attr(pr1=0.98, pr2=0.98, ttd_u=5, design=['pr2', 'ttd_u', 'ttd_l'], offdesign=['zeta2', 'kA']) hs_he.set_attr(T=100, p0=0.5, fluid={'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'H2O': 1, 'NH3': 0, 'CO2': 0, 'CH4': 0}) tes_he.set_attr(T=30, p=5, fluid={'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'H2O': 1, 'NH3': 0, 'CO2': 0, 'CH4': 0}) he_tes.set_attr(T=40) he.set_attr(Q=-80e3) self.nw.solve('design') # check heat flow Q = hs_he.m.val_SI * (he_hs.h.val_SI - hs_he.h.val_SI) self.nw.save('tmp') ttd_u = hlp.T_mix_ph([0, hs_he.p.val_SI, hlp.h_mix_pQ(hs_he.to_flow(), 1), hs_he.fluid.val]) - he_tes.T.val_SI p = hs_he.p.val_SI eq_(round(ttd_u, 1), round(he.ttd_u.val, 1), 'Value of terminal temperature difference must be ' + str(he.ttd_u.val) + ', is ' + str(ttd_u) + '.') # check lower terminal temperature difference he.set_attr(ttd_l=20, ttd_u=np.nan) self.nw.solve('design') eq_(round(he_hs.T.val - tes_he.T.val, 1), round(he.ttd_l.val, 1), 'Value of terminal temperature difference must be ' + str(he.ttd_l.val) + ', is ' + str(he_hs.T.val - tes_he.T.val) + '.') # check kA value self.nw.solve('offdesign', design_path='tmp') eq_(round(p, 1), round(hs_he.p.val_SI, 1), 'Value of condensing pressure be ' + str(p) + ', is ' + str(hs_he.p.val_SI) + '.') shutil.rmtree('./tmp', ignore_errors=True)
def setup(self): self.nw = nwk.network(['TESPy::fuel', 'TESPy::fuel_fg', 'Air']) self.comb = cmp.combustion_chamber_stoich('combustion chamber') c1 = con.connection(cmp.source('air'), 'out1', self.comb, 'in1') c2 = con.connection(cmp.source('fuel'), 'out1', self.comb, 'in2') c3 = con.connection(self.comb, 'out1', cmp.sink('flue gas'), 'in1') self.nw.add_conns(c1, c2, c3)
def test_network_connection_error_target(): nw = nwk.network(['water']) source1 = cmp.source('source1') source2 = cmp.source('source2') sink = cmp.sink('sink') a = con.connection(source1, 'out1', sink, 'in1') b = con.connection(source2, 'out1', sink, 'in1') nw.add_conns(a, b) nw.check_network()
def test_combustion_chamber_missing_fuel(self): """ Test no fuel in network. """ nw = nwk.network(['H2O', 'N2', 'O2', 'Ar', 'CO2']) comb = cmp.combustion_chamber('combustion chamber') c1 = con.connection(cmp.source('air'), 'out1', comb, 'in1') c2 = con.connection(cmp.source('fuel'), 'out1', comb, 'in2') c3 = con.connection(comb, 'out1', cmp.sink('flue gas'), 'in1') nw.add_conns(c1, c2, c3) nw.solve('design', init_only=True)
def test_heat_ex(self): """ Test component properties of heat exchanger. """ tesin = cmp.sink('TES in') tesout = cmp.source('TES out') hsin = cmp.sink('HS in') hsout = cmp.source('HS out') he = cmp.heat_exchanger('heat exchanger') tes_he = con.connection(tesout, 'out1', he, 'in2') he_tes = con.connection(he, 'out2', tesin, 'in1') hs_he = con.connection(hsout, 'out1', he, 'in1') he_hs = con.connection(he, 'out1', hsin, 'in1') self.nw.add_conns(tes_he, he_tes, hs_he, he_hs) # design specification he.set_attr(pr1=0.98, pr2=0.98, ttd_u=5, design=['pr1', 'pr2', 'ttd_u'], offdesign=['zeta1', 'zeta2', 'kA']) hs_he.set_attr(T=120, p=3, fluid={'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'H2O': 1, 'NH3': 0, 'CO2': 0, 'CH4': 0}) he_hs.set_attr(T=70) tes_he.set_attr(T=40, p=5, fluid={'N2': 0, 'O2': 0, 'Ar': 1, 'INCOMP::DowQ': 0, 'H2O': 0, 'NH3': 0, 'CO2': 0, 'CH4': 0}) b = con.bus('heat transfer', P=-80e3) b.add_comps({'c': he}) self.nw.add_busses(b) self.nw.solve('design') # check heat flow Q = hs_he.m.val_SI * (he_hs.h.val_SI - hs_he.h.val_SI) self.nw.save('tmp') eq_(round(hs_he.T.val - he_tes.T.val, 1), round(he.ttd_u.val, 1), 'Value of terminal temperature difference must be ' + str(he.ttd_u.val) + ', is ' + str(hs_he.T.val - he_tes.T.val) + '.') # check lower terminal temperature difference he_hs.set_attr(T=np.nan) he.set_attr(ttd_l=20) self.nw.solve('design') eq_(round(he_hs.T.val - tes_he.T.val, 1), round(he.ttd_l.val, 1), 'Value of terminal temperature difference must be ' + str(he.ttd_l.val) + ', is ' + str(he_hs.T.val - tes_he.T.val) + '.') # check kA value self.nw.solve('offdesign', design_path='tmp') eq_(round(Q, 1), round(he.Q.val, 1), 'Value of heat flow must be ' + str(he.Q.val) + ', is ' + str(Q) + '.') # trigger errors for negative terminal temperature differences at given kA-value he.set_attr(ttd_l=np.nan) # ttd_l he_hs.set_attr(T=30) try: self.nw.solve('offdesign', design_path='tmp') except ValueError: pass # ttd_u he_hs.set_attr(T=np.nan) he_tes.set_attr(T=130) try: self.nw.solve('offdesign', design_path='tmp') except ValueError: pass shutil.rmtree('./tmp', ignore_errors=True)
def test_network_instanciation_no_fluids(): nw = nwk.network([]) so = cmp.source('source') si = cmp.sink('sink') conn = con.connection(so, 'out1', si, 'in1') nw.add_conns(conn) nw.solve('design', init_only=True)
def test_network_missing_data_in_individual_design_case_file(): nw = nwk.network(['water']) source = cmp.source('source') pipe = cmp.pipe('pipe', Q=0, pr=0.95, design=['pr'], offdesign=['zeta']) sink = cmp.sink('sink') a = con.connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=293.15, fluid={'water': 1}) b = con.connection(pipe, 'out1', sink, 'in1', design_path='tmp2') nw.add_conns(a, b) nw.solve('design') nw.save('tmp') nw.save('tmp2') inputs = open('./tmp/conn.csv') all_lines = inputs.readlines() all_lines.pop(len(all_lines) - 1) inputs.close() with open('./tmp2/conn.csv', 'w') as out: for line in all_lines: out.write(line.strip() + '\n') try: nw.solve('offdesign', design_path='tmp') except hlp.TESPyNetworkError: pass shutil.rmtree('./tmp', ignore_errors=True) shutil.rmtree('./tmp2', ignore_errors=True)
def test_network_overdetermination(): nw = nwk.network(['water']) source = cmp.source('source') sink = cmp.sink('sink') a = con.connection(source, 'out1', sink, 'in1', m=1, p=1e5, x=1, h=1e6, fluid={'water': 1}, fluid_balance=True) nw.add_conns(a) nw.solve('design')
def test_network_underdetermination(): nw = nwk.network(['water']) source = cmp.source('source') sink = cmp.sink('sink') a = con.connection(source, 'out1', sink, 'in1', m=1) nw.add_conns(a) nw.solve('design')
def test_network_network_consistency_outlets(): nw = nwk.network(['water', 'air']) source = cmp.source('source') splitter = cmp.splitter('splitter') a = con.connection(source, 'out1', splitter, 'in1') nw.add_conns(a) nw.check_network()
def test_network_mode(): nw = nwk.network(['water']) source = cmp.source('source') sink = cmp.sink('sink') a = con.connection(source, 'out1', sink, 'in1') nw.add_conns(a) nw.solve('ofdesign')
def test_network_component_labels(): nw = nwk.network(['water']) source = cmp.source('label') sink = cmp.sink('label') a = con.connection(source, 'out1', sink, 'in1') nw.add_conns(a) nw.check_network()
def setup(self): self.nw = nwk.network( ['INCOMP::DowQ', 'H2O', 'NH3', 'N2', 'O2', 'Ar', 'CO2', 'CH4'], T_unit='C', p_unit='bar', v_unit='m3 / s') self.source = cmp.source('source') self.sink = cmp.sink('sink')
def test_network_linear_dependency(): nw = nwk.network(['water']) source = cmp.source('source') sink = cmp.sink('sink') a = con.connection(source, 'out1', sink, 'in1', m=1, p=1e5, h=1e6, x=1) nw.add_conns(a) nw.solve('design') eq_(nw.lin_dep, True, 'This test must result in a linear dependency of the jacobian matrix.')
def setup_network_21(self, instance): """ Set up network for components with two inlets and one outlet. """ c1 = con.connection(self.source, 'out1', instance, 'in1') c2 = con.connection(cmp.source('fuel'), 'out1', instance, 'in2') c3 = con.connection(instance, 'out1', self.sink, 'in1') self.nw.add_conns(c1, c2, c3) return c1, c2, c3
def test_network_connection_error_source(): nw = nwk.network(['water']) source = cmp.source('source') sink1 = cmp.sink('sink1') sink2 = cmp.sink('sink2') a = con.connection(source, 'out1', sink1, 'in1') b = con.connection(source, 'out1', sink2, 'in1') nw.add_conns(a, b) nw.check_network()
def test_network_no_progress(): nw = nwk.network(['water']) source = cmp.source('source') pipe = cmp.pipe('pipe', pr=1, Q=-100e3) sink = cmp.sink('sink') a = con.connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=280, fluid={'water': 1}) b = con.connection(pipe, 'out1', sink, 'in1') nw.add_conns(a, b) nw.solve('design') eq_(nw.progress, False, 'This test must result in a calculation making no progress, as the pipe\'s outlet enthalpy is below fluid property range.')
def test_network_max_iter(): nw = nwk.network(['water']) source = cmp.source('source') pipe = cmp.pipe('pipe', pr=1, Q=100e3) sink = cmp.sink('sink') a = con.connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=280, fluid={'water': 1}) b = con.connection(pipe, 'out1', sink, 'in1') nw.add_conns(a, b) nw.solve('design', max_iter=2) eq_(nw.max_iter, nw.iter + 1, 'This test must result in the itercount being equal to the max iter statement.')
""" from tespy import con, cmp, nwk import numpy as np from matplotlib import pyplot as plt import pandas as pd # %% network fluid_list = ['H2O'] nw = nwk.network(fluids=fluid_list, p_unit='bar', T_unit='C') # %% components # sinks & sources back = cmp.source('to collector') feed = cmp.sink('from collector') # collector coll = cmp.solar_collector(label='solar thermal collector') # %% connections b_c = con.connection(back, 'out1', coll, 'in1') c_f = con.connection(coll, 'out1', feed, 'in1') nw.add_conns(b_c, c_f) # %% component parameters # set pressure ratio and heat flow, as well as dimensional parameters of
# %% network nw = nwk.network(fluids=['water', 'NH3'], T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s', p_range=[0.1, 100], T_range=[1, 500], h_range=[15, 5000]) # %% components # sources & sinks c_in = cmp.source('coolant in') cb = cmp.source('consumer back flow') cf = cmp.sink('consumer feed flow') ves = cmp.sink('vessel') # consumer system cd = cmp.condenser('condenser') rp = cmp.pump('recirculation pump') cons = cmp.heat_exchanger_simple('consumer') # %% connections # consumer system
p_brine_in = 9.4 T_brine_out = 69.1 # calculation T_before_turbine = PropsSI('T', 'P', p_after_pump*0.957627118*0.955752212*1e5, 'Q', 1, 'Isopentane')-273.15+2.3 # basic network nw = nwk.network(fluids=fluids) nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg') # main components condenser = cmp.condenser('condenser') ihe = cmp.heat_exchanger('internal heat exchanger') pump = cmp.pump('feeding pump') turbine = cmp.turbine('turbine') p_and_e = cmp.heat_exchanger('preheater and evaporator') # cooling air source_ca = cmp.source('cooling air source') sink_ca = cmp.sink('cooling air sink') #brine source_b = cmp.source('brine source') sink_b = cmp.sink('brine sink') # working fluid source_wf_1 = cmp.source('working fluid source before turbine') sink_wf_1 = cmp.sink('working fluid sink from before turbine') source_wf_2 = cmp.source('working fluid source from ihe') sink_wf_2 = cmp.sink('working fluid sink from ihe') # connections # main cycle p_and_e_wf_in = con.connection(source_wf_2, 'out1', p_and_e, 'in2') p_and_e_wf_out = con.connection(p_and_e, 'out2', sink_wf_2, 'in1') turbine_wf_in = con.connection(source_wf_1, 'out1', turbine, 'in1') turbine_ihe = con.connection(turbine, 'out1', ihe, 'in1')
split = cmp.splitter(label='splitter1') turbine_lp = cmp.turbine(label='turbine_lp') # condenser and preheater condenser = cmp.condenser(label='condenser') preheater = cmp.condenser(label='preheater') valve_pre = cmp.valve(label='valve_pre') valve = cmp.valve(label='valve1') merge = cmp.merge(label='merge1') # feed water pump = cmp.pump(label='pump') steam_generator = cmp.heat_exchanger_simple(label='steam generator') # sources and sinks source = cmp.source(label='source') sink = cmp.sink(label='sink') # for cooling water source_cw = cmp.source(label='source_cw') sink_cw = cmp.sink(label='sink_cw') # %% connections # turbine part fs_in = con.connection(source, 'out1', valve_turb, 'in1') fs = con.connection(valve_turb, 'out1', turbine_hp, 'in1') ext = con.connection(turbine_hp, 'out1', split, 'in1') ext_v = con.connection(split, 'out1', valve_pre, 'in1') v_pre = con.connection(valve_pre, 'out1', preheater, 'in1') ext_turb = con.connection(split, 'out2', turbine_lp, 'in1')
import numpy as np import pandas as pd # %% network nw = nwk.network(fluids=['water', 'NH3', 'air'], T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s') # %% components # sources & sinks c_in = cmp.source('coolant in') cb = cmp.source('consumer back flow') cf = cmp.sink('consumer feed flow') amb = cmp.source('ambient air') amb_out1 = cmp.sink('sink ambient 1') amb_out2 = cmp.sink('sink ambient 2') c_out = cmp.sink('coolant out') # ambient air system sp = cmp.splitter('splitter') fan = cmp.compressor('fan') # consumer system cd = cmp.condenser('condenser') dhp = cmp.pump('district heating pump')
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 __init__(self, press_in=0, press_out=0, temp_in=0, temp_out=0, overh=0, enth_in=0, enth_out=0, entr_in=0, entr_out=0, work_fl='', mass_fl=0, pr=0, q_cap=0, heat_cap=0, amb_press_in=0, amb_press_out=0, amb_temp_in=0, amb_temp_out=0, pinch_point=0, amb_enth_in=0, amb_enth_out=0, amb_entr_in=0, amb_entr_out=0, amb_work_fl='', amb_mass_fl=0, amb_pr=0, cycle_name='', use_aspen=False, exer_in=0, exer_out=0, amb_exer_in=0, amb_exer_out=0): super().__init__(press_in, press_out, temp_in, temp_out, enth_in, enth_out, entr_in, entr_out, work_fl, mass_fl, cycle_name) self.q_cap = q_cap self.heat_cap = heat_cap self.pr = pr self.amb_enth_in = amb_enth_in self.amb_enth_out = amb_enth_out self.amb_press_in = amb_press_in self.amb_press_out = amb_press_out self.amb_temp_in = amb_temp_in self.amb_temp_out = amb_temp_out self.amb_entr_in = amb_entr_in self.amb_entr_out = amb_entr_out self.pinch_point = pinch_point self.overh = overh self.amb_work_fl = amb_work_fl self.amb_mass_fl = amb_mass_fl self.amb_pr = amb_pr self.is_model_correct = True self.use_aspen = use_aspen self.exer_in = exer_in self.exer_out = exer_out self.amb_exer_in = amb_exer_in self.amb_exer_out = amb_exer_out # Applying the condenser model using TESPy. Firstly the components and connections must be set, afterwards # the function will set the attributes and TESPy engine will calculate the demanded result. # Setting components: self.amb_inlet = cmp.sink('inlet of ambient') self.amb_outlet = cmp.source('outlet of ambient') self.cycle_inlet = cmp.sink('inlet of cycle') self.cycle_outlet = cmp.source('outlet of cycle') self.evaporator = cmp.heat_exchanger('evaporator') # Setting connections between components: self.amb_evap = con.connection(self.amb_outlet, 'out1', self.evaporator, 'in1') self.evap_amb = con.connection(self.evaporator, 'out1', self.amb_inlet, 'in1') self.cycle_evap = con.connection(self.cycle_outlet, 'out1', self.evaporator, 'in2') self.evap_cycle = con.connection(self.evaporator, 'out2', self.cycle_inlet, 'in1') if self.work_fl == '' or self.amb_work_fl == '': print( "Working fluid or the ambient working fluid hasn't been set, so creating the TESPy network model" "can't be completed.\n") else: # Putting the connections into the network (TESPy): # Because TESPy isn't smart enough and it throws error when the working fluid in the cycle # is the same as the one in ambient, # it is necessary to make a division of initialization of network basic attributes: if self.work_fl == self.amb_work_fl: self.nw = nwk.network(fluids=[self.work_fl], T_unit='K', p_unit='Pa', h_unit='J / kg') else: self.nw = nwk.network(fluids=[self.work_fl, self.amb_work_fl], T_unit='K', p_unit='Pa', h_unit='J / kg') self.nw.set_printoptions(print_level='none') self.nw.add_conns(self.amb_evap, self.evap_amb, self.cycle_evap, self.evap_cycle)
def __init__(self, press_in=0, press_out=0, temp_in=0, temp_out=0, enth_in=0, enth_out=0, entr_in=0, entr_out=0, work_fl='', pr=0, heat_val=0, mass_fl=0, temp_cond=0, overcool=0, amb_press_in=0, amb_press_out=0, amb_temp_in=0, amb_temp_out=0, amb_enth_in=0, amb_enth_out=0, amb_work_fl='', amb_mass_fl=0, amb_pr=0, cycle_name=''): super().__init__(press_in, press_out, temp_in, temp_out, enth_in, enth_out, entr_in, entr_out, work_fl, mass_fl, cycle_name) self.heat_val = heat_val self.pr = pr self.temp_cond = temp_cond self.overcool = overcool if temp_out == 0 and enth_out == 0: self.temp_out = self.temp_cond - self.overcool if self.temp_cond == 0 or self.overcool == 0: print( "Condenser.__init__(): The value of temp_out hasn't been declared. Therefore it was initialized" "as: temp_cond minus overcool. It seems however, that one of these values equals 0." ) self.amb_enth_in = amb_enth_in self.amb_enth_out = amb_enth_out self.amb_press_in = amb_press_in self.amb_press_out = amb_press_out self.amb_temp_in = amb_temp_in self.amb_temp_out = amb_temp_out self.amb_work_fl = amb_work_fl self.amb_mass_fl = amb_mass_fl self.amb_pr = amb_pr # For checking if the values are appropriate in function set_attr_pow_cyc(): self.approved = False # Applying the condenser model using TESPy. Firstly the components and connections must be set, afterwards # the function will set the attributes and TESPy solver will calculate the demanded result. # Setting components: self.amb_inlet = cmp.sink("inlet of ambient") self.amb_outlet = cmp.source("outlet of ambient") self.cycle_inlet = cmp.sink("inlet of cycle") self.cycle_outlet = cmp.source("outlet of cycle") self.condenser = cmp.heat_exchanger("condenser") # Setting connections between components: self.amb_cond = con.connection(self.amb_outlet, 'out1', self.condenser, 'in2') self.cond_amb = con.connection(self.condenser, 'out2', self.amb_inlet, 'in1') self.cycle_cond = con.connection(self.cycle_outlet, 'out1', self.condenser, 'in1') self.cond_cycle = con.connection(self.condenser, 'out1', self.cycle_inlet, 'in1') if self.work_fl == '' or self.amb_work_fl == '': print( "Working fluid or the ambient working fluid hasn't been set, so creating the TESPy network model" "can't be completed.\n") else: # Putting the connections into the network (TESPy): # Because TESPy isn't smart enough and it throws error when the working fluid in the cycle # is the same as the one in ambient, # it is necessary to make a division of initialization of network basic attributes: if self.work_fl == self.amb_work_fl: self.nw = nwk.network(fluids=[self.work_fl], T_unit='K', p_unit='Pa', h_unit='J / kg') else: self.nw = nwk.network(fluids=[self.work_fl, self.amb_work_fl], T_unit='K', p_unit='Pa', h_unit='J / kg') self.nw.set_printoptions(print_level='none') self.nw.add_conns(self.amb_cond, self.cond_amb, self.cycle_cond, self.cond_cycle)
# %% network nw = nwk.network(fluids=['water', 'NH3'], T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s', p_range=[0.1, 100], T_range=[1, 500], h_range=[15, 5000]) # %% components # sources & sinks c_in = cmp.source('coolant in') cb = cmp.source('consumer back flow') cf = cmp.sink('consumer feed flow') amb_in = cmp.source('source ambient') amb_out = cmp.sink('sink ambient') cp1 = cmp.sink('compressor 1') # consumer system cd = cmp.condenser('condenser') rp = cmp.pump('recirculation pump') cons = cmp.heat_exchanger_simple('consumer') # evaporator system
from tespy import nwk, con, cmp, hlp import numpy as np from matplotlib import pyplot as plt nw = nwk.network(['water'], p_unit='bar', T_unit='C', h_unit='kJ / kg') # %% components pipe = cmp.pipe('pipe') pipe2 = cmp.pipe('pipe2') pipe3 = cmp.pipe('pipe3') pipe4 = cmp.pipe('pipe4') pipe5 = cmp.pipe('pipe5') pipe6 = cmp.pipe('pipe6') sink = cmp.sink('sink') source = cmp.source('source') # %% connections a = con.connection(source, 'out1', pipe, 'in1') b = con.connection(pipe, 'out1', pipe2, 'in1') c = con.connection(pipe2, 'out1', pipe3, 'in1') d = con.connection(pipe3, 'out1', pipe4, 'in1') e = con.connection(pipe4, 'out1', pipe5, 'in1') f = con.connection(pipe5, 'out1', pipe6, 'in1') g = con.connection(pipe6, 'out1', sink, 'in1') nw.add_conns(a, b, c, d, e, f, g) # %% connection parameters a.set_attr(h=40, fluid={'water': 1}, p=1, m=10)