Example #1
0
    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')
Example #2
0
    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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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()
Example #7
0
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()
Example #8
0
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)
Example #9
0
 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)
Example #10
0
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)
Example #11
0
 def test_consistency_outlets(self):
     source = basics.source('source')
     splitter = nodes.splitter('splitter')
     a = connection(source, 'out1', splitter, 'in1')
     self.nw.add_conns(a)
     with raises(TESPyNetworkError):
         self.nw.check_network()
Example #12
0
 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')
Example #13
0
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')
Example #14
0
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')
Example #15
0
    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)
Example #16
0
def test_network_network_consistency_outlets():
    nw = network(['water', 'air'])
    source = basics.source('source')
    splitter = nodes.splitter('splitter')
    a = connection(source, 'out1', splitter, 'in1')
    nw.add_conns(a)
    nw.check_network()
Example #17
0
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()
Example #18
0
 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')
Example #19
0
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)
Example #20
0
 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')
Example #21
0
 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()
Example #22
0
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')
Example #23
0
 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)
Example #24
0
    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')
Example #25
0
    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)
Example #26
0
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()
Example #27
0
 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()
Example #28
0
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)
Example #29
0
    def setup_combustion_chamber_model(self):
        """Set up the model using the combustion chamber."""
        # %% network setup
        fluid_list = ['Ar', 'N2', 'O2', 'CO2', 'CH4', 'H2O']
        self.nw1 = 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('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.nw1.add_conns(amb_cp, cp_cc, sf_cc, cc_gt, gt_fg)

        # %% component parameters
        cc.set_attr(lamb=3)
        cp.set_attr(eta_s=0.9, pr=15)
        gt.set_attr(eta_s=0.9)

        # %% connection parameters
        amb_cp.set_attr(
            T=20, p=1, m=100,
            fluid={'Ar': 0.0129, 'N2': 0.7553, 'H2O': 0, 'CH4': 0,
                   'CO2': 0.0004, 'O2': 0.2314})
        sf_cc.set_attr(
            T=20, fluid={'CO2': 0.04, 'Ar': 0, 'N2': 0,
                         'O2': 0, 'H2O': 0, 'CH4': 0.96})
        gt_fg.set_attr(p=1)

        # %% solving
        mode = 'design'
        self.nw1.solve(mode=mode)
Example #30
0
    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)