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_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 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(['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_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_network_11(self, instance): """ Set up network for components with one inlet and one outlet. """ c1 = con.connection(self.source, 'out1', instance, 'in1') c2 = con.connection(instance, 'out1', self.sink, 'in1') self.nw.add_conns(c1, c2) return c1, c2
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_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 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_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.')
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_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_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 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_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_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_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 test_network_network_consistency_inlets(): nw = nwk.network(['water']) merge = cmp.merge('merge') sink = cmp.sink('label') a = con.connection(merge, 'out1', sink, 'in1') nw.add_conns(a) nw.check_network()
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_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 test_missing_bus_param_deriv(self): """ Test missing bus parameter in bus derivatives for cogeneration unit. """ self.comp.num_vars = 2 self.comp.inl = [con.connection(self.comp, 'out1', cmp.sink('sink'), 'in1')] self.comp.inl[0].fluid = hlp.dc_flu(val={'water': 1}) self.comp.bus_deriv(self.bus.comps.loc[self.comp])
def construct_conns(c, *args): r""" Creates TESPy connection from data in the .csv-file and specifies its parameters. Parameters ---------- c : pandas.core.series.Series Connection information from .csv-file. args[0] : pandas.core.frame.DataFrame DataFrame containing all created components. Returns ------- conn : tespy.connections.connection TESPy connection object. """ # create connection conn = con.connection(args[0].instance[c.s], c.s_id, args[0].instance[c.t], c.t_id) kwargs = {} # read basic properties for key in ['design', 'offdesign']: if key in c: kwargs[key] = c[key] # read fluid properties for key in ['m', 'p', 'h', 'T', 'x', 'v']: if key in c: dc = hlp.dc_prop(val=c[key], val0=c[key + '0'], val_set=c[key + '_set'], unit=c[key + '_unit'], unit_set=c[key + '_unit_set'], ref=None, ref_set=c[key + '_ref_set']) kwargs[key] = dc # read fluid vector val = {} val0 = {} val_set = {} for key in args[1].fluids: if key in c: val[key] = c[key] val0[key] = c[key + '0'] val_set[key] = c[key + '_set'] kwargs['fluid'] = hlp.dc_flu(val=val, val0=val0, val_set=val_set, balance=c['balance']) # write properties to connection and return connection object conn.set_attr(**kwargs) return conn
def construct_conns(c, *args): """ creates TESPy component from class name provided in the .csv-file and specifies its parameters :param c: connection information :type c: pandas.core.series.Series :returns: instance (*tespy.components.component*) - TESPy component object **additional arguments in args** - args[0]: comps (*pandas.core.frame.DataFrame*) - DataFrame containing all created components """ # create connection conn = con.connection(args[0].instance[c.s], c.s_id, args[0].instance[c.t], c.t_id) kwargs = {} # read basic properties for key in ['design', 'offdesign']: if key in c: kwargs[key] = c[key] # read fluid properties for key in ['m', 'p', 'h', 'T', 'x']: if key in c: dc = hlp.dc_prop(val=c[key], val0=c[key + '0'], val_set=c[key + '_set'], unit=c[key + '_unit'], unit_set=c[key + '_unit_set'], ref=None, ref_set=c[key + '_ref_set']) kwargs[key] = dc # read fluid vector val = {} val0 = {} val_set = {} for key in args[1].fluids: if key in c: val[key] = c[key] val0[key] = c[key + '0'] val_set[key] = c[key + '_set'] kwargs['fluid'] = hlp.dc_flu(val=val, val0=val0, val_set=val_set, balance=c['balance']) # write properties to connection and return connection object conn.set_attr(**kwargs) return conn
def test_network_missing_connection_in_init_path(self): """ Test debug message for missing connection in init_path. """ IF = cmp.subsys_interface('IF') a = con.connection(self.source, 'out1', self.sink, 'in1') self.nw.add_conns(a) self.nw.solve('design', init_only=True) self.nw.save('tmp') msg = ('After the network check, the .checked-property must be True.') eq_(self.nw.checked, True, msg) self.nw.del_conns(a) a = con.connection(self.source, 'out1', IF, 'in1') b = con.connection(IF, 'out1', self.sink, 'in1') self.nw.add_conns(a, b) self.nw.solve('design', init_path='tmp', init_only=True) msg = ('After the network check, the .checked-property must be True.') eq_(self.nw.checked, True, msg) shutil.rmtree('./tmp', ignore_errors=True)
def create_conns(self): self.conns = [] self.conns += [ con.connection(self.inlet, 'out1', self.splitter, 'in1') ] self.conns += [con.connection(self.merge, 'out1', self.outlet, 'in1')] for i in range(self.num_branch): j = str(i + 1) k = str(i + 2) self.conns += [ con.connection(self.splitter, 'out' + j, self.outlet, 'in' + k) ] self.conns += [ con.connection(self.inlet, 'out' + k, self.valve[i], 'in1') ] self.conns += [ con.connection(self.valve[i], 'out1', self.merge, 'in' + j) ]
def test_network_delete_conns(self): """ Test deleting a network's connection. """ a = con.connection(self.source, 'out1', self.sink, 'in1') self.nw.add_conns(a) self.nw.check_network() msg = ('After the network check, the .checked-property must be True.') eq_(self.nw.checked, True, msg) self.nw.del_conns(a) msg = ('A connection has been deleted, the network consistency check ' 'must be repeated (.checked-property must be False).') eq_(self.nw.checked, False, msg)
rp = cmp.pump('recirculation pump') cons = cmp.heat_exchanger_simple('consumer') # evaporator system ves = cmp.vessel('vessel') dr = cmp.drum('drum') ev = cmp.heat_exchanger('evaporator') su = cmp.heat_exchanger('superheater') pu = cmp.pump('pump evaporator') # %% connections # consumer system c_in_cd = con.connection(c_in, 'out1', cd, 'in1') cb_rp = con.connection(cb, 'out1', rp, 'in1') rp_cd = con.connection(rp, 'out1', cd, 'in2') cd_cons = con.connection(cd, 'out2', cons, 'in1') cons_cf = con.connection(cons, 'out1', cf, 'in1') nw.add_conns(c_in_cd, cb_rp, rp_cd, cd_cons, cons_cf) # connection condenser - evaporator system cd_ves = con.connection(cd, 'out1', ves, 'in1') nw.add_conns(cd_ves) # evaporator system
# 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') nw.add_conns(fs_in, fs, ext, ext_v, v_pre, ext_turb) # preheater and condenser ext_cond = con.connection(preheater, 'out1', valve, 'in1') cond_ws = con.connection(valve, 'out1', merge, 'in2') turb_ws = con.connection(turbine_lp, 'out1', merge, 'in1') ws = con.connection(merge, 'out1', condenser, 'in1') nw.add_conns(ext_cond, cond_ws, turb_ws, ws) # feed water