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_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 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 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 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 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)
with pytest.raises(TESPyNetworkError):
nw.solve('design')
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_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)
with pytest.raises(TESPyNetworkError):
nw.check_network()
def test_combustion_chamber_missing_fuel(self):
"""
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 pytest.raises(TESPyComponentError):
nw.solve('design', init_only=True)
def setup_combustion_chamber_stoich_model(self):
"""Set up the model using the stoichimetric combustion chamber."""
# %% network setup
fluid_list = ['myAir', 'myFuel', 'myFuel_fg']
self.nw2 = network(
fluids=fluid_list, p_unit='bar', T_unit='C',
p_range=[0.5, 20], T_range=[10, 2000])
# %% components
amb = source('ambient')
sf = source('fuel')
cc = combustion_chamber_stoich('combustion')
cp = compressor('compressor')
gt = turbine('turbine')
fg = sink('flue gas outlet')
# %% connections
amb_cp = connection(amb, 'out1', cp, 'in1')
cp_cc = connection(cp, 'out1', cc, 'in1')
sf_cc = connection(sf, 'out1', cc, 'in2')
cc_gt = connection(cc, 'out1', gt, 'in1', label='flue gas after cc')
gt_fg = connection(gt, 'out1', fg, 'in1', label='flue gas after gt')
self.nw2.add_conns(amb_cp, cp_cc, sf_cc, cc_gt, gt_fg)
# %% component parameters
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'],