def setup(self): """ Set up network for electrolyzer tests. """ self.nw = network(['O2', 'H2', 'H2O'], T_unit='C', p_unit='bar') self.instance = water_electrolyzer('electrolyzer') fw = source('feed water') cw_in = source('cooling water') o2 = sink('oxygen sink') h2 = sink('hydrogen sink') cw_out = sink('cooling water sink') self.instance.set_attr(pr_c=0.99) cw_el = connection(cw_in, 'out1', self.instance, 'in1', fluid={ 'H2O': 1, 'H2': 0, 'O2': 0 }, T=20, p=1) el_cw = connection(self.instance, 'out1', cw_out, 'in1', T=45) self.nw.add_conns(cw_el, el_cw) fw_el = connection(fw, 'out1', self.instance, 'in2', m=0.1, T=20, p=10) el_o2 = connection(self.instance, 'out2', o2, 'in1') el_h2 = connection(self.instance, 'out3', h2, 'in1', T=50) self.nw.add_conns(fw_el, el_o2, el_h2)
def test_connection_error_source(self): source = basics.source('source') sink1 = basics.sink('sink1') sink2 = basics.sink('sink2') a = connection(source, 'out1', sink1, 'in1') b = connection(source, 'out1', sink2, 'in1') self.nw.add_conns(a, b) with raises(TESPyNetworkError): self.nw.check_network()
def test_network_connection_error_source(): nw = network(['water']) source = basics.source('source') sink1 = basics.sink('sink1') sink2 = basics.sink('sink2') a = connection(source, 'out1', sink1, 'in1') b = connection(source, 'out1', sink2, 'in1') nw.add_conns(a, b) nw.check_network()
def test_duplicate_connection_labels(self): source1 = basics.source('source1') source2 = basics.source('source2') sink1 = basics.sink('sink1') sink2 = basics.sink('sink2') a = connection(source1, 'out1', sink1, 'in1', label='myconn') b = connection(source2, 'out1', sink2, 'in1', label='myconn') with raises(ValueError): self.nw.add_conns(a, b)
def test_network_network_consistency_inlets(): nw = network(['water']) merge = nodes.merge('merge') sink = basics.sink('label') a = connection(merge, 'out1', sink, 'in1') nw.add_conns(a) nw.check_network()
def test_network_instanciation_no_fluids(): nw = network([]) so = basics.source('source') si = basics.sink('sink') conn = connection(so, 'out1', si, 'in1') nw.add_conns(conn) nw.solve('design', init_only=True)
def test_network_component_labels(): nw = network(['water']) source = basics.source('label') sink = basics.sink('label') a = connection(source, 'out1', sink, 'in1') nw.add_conns(a) nw.check_network()
def test_network_mode(): nw = network(['water']) source = basics.source('source') sink = basics.sink('sink') a = connection(source, 'out1', sink, 'in1') nw.add_conns(a) nw.solve('ofdesign')
def setup(self): self.nw = network(['H2O', 'N2', 'O2', 'Ar', 'CO2', 'CH4'], T_unit='C', p_unit='bar', v_unit='m3 / s') self.fuel = source('fuel') self.air = source('ambient air') self.fg = sink('flue gas')
def setup_piping_network(self, instance): self.nw = network(['CH4'], T_unit='C', p_unit='bar') self.source = source('source') self.sink = sink('sink') self.c1 = connection(self.source, 'out1', instance, 'in1') self.c2 = connection(instance, 'out1', self.sink, 'in1') self.nw.add_conns(self.c1, self.c2)
def test_network_underdetermination(): nw = network(['water']) source = basics.source('source') sink = basics.sink('sink') a = connection(source, 'out1', sink, 'in1', m=1) nw.add_conns(a) nw.solve('design')
def setup_combustion_engine_network(self, instance): self.cw1_in = source('cooling water 1 source') self.cw2_in = source('cooling water 2 source') self.cw1_out = sink('cooling water 1 sink') self.cw2_out = sink('cooling water 2 sink') self.c1 = connection(self.air, 'out1', instance, 'in3') self.c2 = connection(self.fuel, 'out1', instance, 'in4') self.c3 = connection(instance, 'out3', self.fg, 'in1') self.c4 = connection(self.cw1_in, 'out1', instance, 'in1') self.c5 = connection(self.cw2_in, 'out1', instance, 'in2') self.c6 = connection(instance, 'out1', self.cw1_out, 'in1') self.c7 = connection(instance, 'out2', self.cw2_out, 'in1') self.nw.add_conns(self.c1, self.c2, self.c3, self.c4, self.c5, self.c6, self.c7)
def test_consistency_inlets(self): merge = nodes.merge('merge') sink = basics.sink('label') a = connection(merge, 'out1', sink, 'in1') self.nw.add_conns(a) with raises(TESPyNetworkError): self.nw.check_network()
def test_bad_mode_specification(self): source = basics.source('source') sink = basics.sink('sink') a = connection(source, 'out1', sink, 'in1') self.nw.add_conns(a) with raises(ValueError): self.nw.solve('ofdesign')
def test_underdetermination(self): source = basics.source('source') sink = basics.sink('sink') a = connection(source, 'out1', sink, 'in1', m=1) self.nw.add_conns(a) with raises(TESPyNetworkError): self.nw.solve('design')
def test_missing_offdesign_path(self): source = basics.source('source') sink = basics.sink('sink') a = connection(source, 'out1', sink, 'in1') self.nw.add_conns(a) with raises(TESPyNetworkError): self.nw.solve('offdesign')
def test_component_label_duplicates(self): source = basics.source('label') sink = basics.sink('label') a = connection(source, 'out1', sink, 'in1') self.nw.add_conns(a) with raises(TESPyNetworkError): self.nw.check_network()
def test_network_missing_data_in_individual_design_case_file(): """ Test for missing data in individual design case files. """ nw = network(['water']) source = basics.source('source') pipe = piping.pipe('pipe', Q=0, pr=0.95, design=['pr'], offdesign=['zeta']) sink = basics.sink('sink') a = connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=293.15, fluid={'water': 1}) b = 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') offdesign_TESPyNetworkError(nw, design_path='tmp', init_only=True) shutil.rmtree('./tmp', ignore_errors=True) shutil.rmtree('./tmp2', ignore_errors=True)
def setup_combustion_chamber_stoich_error_tests(self): self.nw = network(['fuel', 'fuel_fg', 'Air'], p_range=[1e4, 1e6]) label = 'combustion chamber' self.instance = combustion.combustion_chamber_stoich(label) c1 = connection(basics.source('air'), 'out1', self.instance, 'in1') c2 = connection(basics.source('fuel'), 'out1', self.instance, 'in2') c3 = connection(self.instance, 'out1', basics.sink('flue gas'), 'in1') self.nw.add_conns(c1, c2, c3)
def setup(self): self.nw = network(['H2O', 'Ar'], T_unit='C', p_unit='bar', v_unit='m3 / s') self.inl1 = source('inlet 1') self.outl1 = sink('outlet 1')
def test_network_overdetermination(): nw = network(['water']) source = basics.source('source') sink = basics.sink('sink') a = 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 = network(['TESPy::fuel', 'TESPy::fuel_fg', 'Air']) label = 'combustion chamber' self.instance = combustion.combustion_chamber_stoich(label) c1 = connection(basics.source('air'), 'out1', self.instance, 'in1') c2 = connection(basics.source('fuel'), 'out1', self.instance, 'in2') c3 = connection(self.instance, 'out1', basics.sink('flue gas'), 'in1') self.nw.add_conns(c1, c2, c3)
def setup_network(self, instance): self.nw = network(['INCOMP::DowQ', 'NH3', 'N2', 'O2', 'Ar'], T_unit='C', p_unit='bar', v_unit='m3 / s') self.source = source('source') self.sink = sink('sink') self.c1 = connection(self.source, 'out1', instance, 'in1') self.c2 = connection(instance, 'out1', self.sink, 'in1') self.nw.add_conns(self.c1, self.c2)
def setup_network_individual_offdesign(self): """ Set up network for individual offdesign tests. """ self.nw = network(['H2O'], T_unit='C', p_unit='bar', v_unit='m3 / s') so = basics.source('source') sp = nodes.splitter('splitter', num_out=2) self.pump1 = turbomachinery.pump('pump 1') self.sc1 = heat_exchangers.solar_collector('collector field 1') v1 = piping.valve('valve1') self.pump2 = turbomachinery.pump('pump 2') self.sc2 = heat_exchangers.solar_collector('collector field 2') v2 = piping.valve('valve2') me = nodes.merge('merge', num_in=2) si = basics.sink('sink') self.pump1.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char']) self.pump2.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char']) self.sc1.set_attr(pr=0.95, lkf_lin=3.33, lkf_quad=0.011, A=1252, E=700, Tamb=20, eta_opt=0.92, design=['pr'], offdesign=['zeta']) self.sc2.set_attr(pr=0.95, lkf_lin=3.5, lkf_quad=0.011, A=700, E=800, Tamb=20, eta_opt=0.92, design=['pr'], offdesign=['zeta']) fl = {'H2O': 1} inlet = connection(so, 'out1', sp, 'in1', T=50, p=3, fluid=fl) outlet = connection(me, 'out1', si, 'in1', p=3) self.sp_p1 = connection(sp, 'out1', self.pump1, 'in1') self.p1_sc1 = connection(self.pump1, 'out1', self.sc1, 'in1') self.sc1_v1 = connection(self.sc1, 'out1', v1, 'in1', p=3.1, T=90) v1_me = connection(v1, 'out1', me, 'in1') self.sp_p2 = connection(sp, 'out2', self.pump2, 'in1') self.p2_sc2 = connection(self.pump2, 'out1', self.sc2, 'in1') self.sc2_v2 = connection(self.sc2, 'out1', v2, 'in1', p=3.1, m=0.1) v2_me = connection(v2, 'out1', me, 'in2') self.nw.add_conns(inlet, outlet, self.sp_p1, self.p1_sc1, self.sc1_v1, v1_me, self.sp_p2, self.p2_sc2, self.sc2_v2, v2_me)
def test_missing_bus_param_deriv(self): """ Test missing bus parameter in bus derivatives for cogeneration unit. """ self.instance.num_vars = 2 self.instance.inl = [connection(self.instance, 'out1', basics.sink('sink'), 'in1')] self.instance.inl[0].fluid = dc_flu(val={'water': 1}) self.instance.bus_deriv(self.bus.comps.loc[self.instance])
def test_network_connection_error_target(): nw = network(['water']) source1 = basics.source('source1') source2 = basics.source('source2') sink = basics.sink('sink') a = connection(source1, 'out1', sink, 'in1') b = connection(source2, 'out1', sink, 'in1') nw.add_conns(a, b) nw.check_network()
def test_connection_error_target(self): source1 = basics.source('source1') source2 = basics.source('source2') sink = basics.sink('sink') a = connection(source1, 'out1', sink, 'in1') b = connection(source2, 'out1', sink, 'in1') self.nw.add_conns(a, b) with raises(TESPyNetworkError): self.nw.check_network()
def test_network_linear_dependency(): nw = network(['water']) source = basics.source('source') sink = basics.sink('sink') a = connection(source, 'out1', sink, 'in1', m=1, p=1e5, h=1e6, x=1) nw.add_conns(a) nw.solve('design') msg = ('This test must result in a linear dependency of the jacobian ' 'matrix.') eq_(nw.lin_dep, True, msg)
def test_combustion_chamber_missing_fuel(): """Test no fuel in network.""" nw = network(['H2O', 'N2', 'O2', 'Ar', 'CO2']) instance = combustion.combustion_chamber('combustion chamber') c1 = connection(basics.source('air'), 'out1', instance, 'in1') c2 = connection(basics.source('fuel'), 'out1', instance, 'in2') c3 = connection(instance, 'out1', basics.sink('flue gas'), 'in1') nw.add_conns(c1, c2, c3) with raises(TESPyComponentError): nw.solve('design', init_only=True)
def setup_electrolyzer_network(self): """Set up network for electrolyzer tests.""" self.instance = reactors.water_electrolyzer('electrolyzer') fw = basics.source('feed water') cw_in = basics.source('cooling water') o2 = basics.sink('oxygen sink') h2 = basics.sink('hydrogen sink') cw_out = basics.sink('cooling water sink') cw_el = connection(cw_in, 'out1', self.instance, 'in1') el_cw = connection(self.instance, 'out1', cw_out, 'in1') self.nw.add_conns(cw_el, el_cw) fw_el = connection(fw, 'out1', self.instance, 'in2') el_o2 = connection(self.instance, 'out2', o2, 'in1') el_h2 = connection(self.instance, 'out3', h2, 'in1') self.nw.add_conns(fw_el, el_o2, el_h2)