Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_compressor_missing_char_parameter():
"""Compressor with invalid parameter for eta_s_char function."""
nw = network(['CH4'])
so = basics.source('source')
si = basics.sink('sink')
instance = turbomachinery.compressor('compressor')
c1 = connection(so, 'out1', instance, 'in1')
c2 = connection(instance, 'out1', si, 'in1')
nw.add_conns(c1, c2)
instance.set_attr(eta_s_char=dc_cc(func=char_line([0, 1], [1, 2]),
is_set=True, param=None))
nw.solve('design', init_only=True)
with raises(ValueError):
instance.eta_s_char_func()
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 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)
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_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(self):
self.nw = network(['water', 'Isopentane'], T_unit='C', p_unit='bar',
h_unit='kJ / kg')
self.inl1 = source('inlet 1')
self.outl1 = sink('outlet 1')
self.inl2 = source('inlet 2')
self.outl2 = sink('outlet 2')
self.inl3 = source('inlet 3')
self.outl3 = sink('outlet 3')
self.instance = orc_evaporator('orc evaporator')
self.c1 = connection(self.inl1, 'out1', self.instance, 'in1')
self.c2 = connection(self.instance, 'out1', self.outl1, 'in1')
self.c3 = connection(self.inl2, 'out1', self.instance, 'in2')
self.c4 = connection(self.instance, 'out2', self.outl2, 'in1')
self.c5 = connection(self.inl3, 'out1', self.instance, 'in3')
self.c6 = connection(self.instance, 'out3', self.outl3, 'in1')
self.nw.add_conns(self.c1, self.c2, self.c3,
self.c4, self.c5, self.c6)
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_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)
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)
with pytest.raises(TESPyNetworkError):
nw.solve('design')
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()