コード例 #1
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
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)
コード例 #2
0
def construct_network(path):
    r"""
    Create TESPy network from the data provided in the netw.csv-file.

    Parameters
    ----------
    path : str
        Base-path to stored network data.

    Returns
    -------
    nw : tespy.networks.networks.network
        TESPy network object.
    """
    # read network .csv-file
    with open(path + 'network.json', 'r') as f:
        data = json.loads(f.read())

    # construct fluid list
    fluid_list = [
        backend + '::' + fluid for fluid, backend in data['fluids'].items()
    ]

    # delete fluids from data
    del data['fluids']

    # create network object with its properties
    nw = network(fluids=fluid_list, **data)

    return nw
コード例 #3
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)
コード例 #4
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')
コード例 #5
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
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')
コード例 #6
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
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()
コード例 #7
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
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()
コード例 #8
0
ファイル: network_tests.py プロジェクト: FranziPl/tespy
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)
コード例 #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)
コード例 #10
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
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()
コード例 #11
0
ファイル: network_reader.py プロジェクト: kyleniemeyer/tespy
def construct_network(path):
    r"""
    Create TESPy network from the data provided in the netw.csv-file.

    Parameters
    ----------
    path : str
        Base-path to stored network data.

    Returns
    -------
    nw : tespy.networks.network
        TESPy network object.
    """
    # read network .csv-file
    netw = pd.read_csv(path + 'netw.csv',
                       sep=';',
                       decimal='.',
                       converters={'fluids': ast.literal_eval})
    f_list = netw['fluids'][0]

    kwargs = {}
    kwargs['m_unit'] = netw['m_unit'][0]
    kwargs['p_unit'] = netw['p_unit'][0]
    kwargs['p_range'] = [netw['p_min'][0], netw['p_max'][0]]
    kwargs['h_unit'] = netw['h_unit'][0]
    kwargs['h_range'] = [netw['h_min'][0], netw['h_max'][0]]
    kwargs['T_unit'] = netw['T_unit'][0]
    kwargs['T_range'] = [netw['T_min'][0], netw['T_max'][0]]

    # create network object with its properties
    nw = network(fluids=f_list, **kwargs)

    return nw
コード例 #12
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
 def setup(self):
     self.nw = network(['water', 'air'])
     self.comp = combustion.combustion_engine('combustion engine')
     self.pipe = piping.pipe('pipe')
     self.conn = connection(self.comp, 'out1', self.pipe, 'in1')
     self.bus = bus('mybus')
     self.sub = subsystems.subsystem('MySub')
コード例 #13
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
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')
コード例 #14
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
 def test_missing_water_in_network(self):
     """
     Test missing hydrogen in network fluids with water electrolyzer.
     """
     self.nw = network(['O2', 'H2'])
     self.setup_electrolyzer_network()
     self.nw.solve('design')
コード例 #15
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)
コード例 #16
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)
コード例 #17
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
 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)
コード例 #18
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')
コード例 #19
0
ファイル: heat_exchanger_tests.py プロジェクト: cboysen/tespy
    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')
コード例 #20
0
ファイル: network_tests.py プロジェクト: FranziPl/tespy
    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)
コード例 #21
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
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()
コード例 #22
0
def test_set_attr_errors():
    """Test errors of set_attr methods."""
    nw = network(['water', 'air'])
    comb = combustion.combustion_engine('combustion engine')
    pipeline = piping.pipe('pipeline')
    conn = connection(comb, 'out1', pipeline, 'in1')
    mybus = bus('mybus')

    # ValueErrors
    set_attr_ValueError(comb, offdesign=['Q'])

    set_attr_ValueError(conn, offdesign=['f'])

    set_attr_ValueError(nw, m_unit='kg')
    set_attr_ValueError(nw, h_unit='kg')
    set_attr_ValueError(nw, p_unit='kg')
    set_attr_ValueError(nw, T_unit='kg')
    set_attr_ValueError(nw, v_unit='kg')
    set_attr_ValueError(conn, state=5)

    # TypeErrors
    set_attr_TypeError(comb, P=[5])
    set_attr_TypeError(comb, tiP_char=7)
    set_attr_TypeError(comb, design='f')
    set_attr_TypeError(comb, lamb=dc_cc())
    set_attr_TypeError(comb, design_path=7)
    set_attr_TypeError(comb, local_design=5)
    set_attr_TypeError(comb, local_offdesign=5)
    set_attr_TypeError(pipeline, hydro_group=5)
    set_attr_TypeError(comb, printout=5)

    set_attr_TypeError(conn, design='h')
    set_attr_TypeError(conn, fluid_balance=1)
    set_attr_TypeError(conn, h0=[4])
    set_attr_TypeError(conn, fluid=5)
    set_attr_TypeError(conn, design_path=5)
    set_attr_TypeError(conn, local_design=5)
    set_attr_TypeError(conn, local_offdesign=5)
    set_attr_TypeError(conn, printout=5)
    set_attr_TypeError(conn, label=5)
    set_attr_TypeError(conn, state='f')

    set_attr_TypeError(nw, m_range=5)
    set_attr_TypeError(nw, p_range=5)
    set_attr_TypeError(nw, h_range=5)
    set_attr_TypeError(nw, iterinfo=5)
    set_attr_TypeError(mybus, P='some value')
    set_attr_TypeError(mybus, printout=5)

    # KeyErrors
    set_attr_KeyError(dc_cc(), x=7)
    set_attr_KeyError(comb, wow=5)
    set_attr_KeyError(conn, jey=5)
    set_attr_KeyError(mybus, power_output=100000)

    # NotImplementedError
    set_attr_NotImplementedError(conn, Td_bp=ref(conn, 1, 0))
コード例 #23
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
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()
コード例 #24
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
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)
コード例 #25
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)
コード例 #26
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
 def test_wrong_bus_param_func(self):
     """
     Test missing/wrong bus parameter specification for water electrolyzer.
     """
     # this test does not need setup, since the function is called without
     # network initialisation
     self.nw = network(['H2O', 'O2', 'H2'])
     self.instance = reactors.water_electrolyzer('electrolyzer')
     some_bus = bus('some_bus')
     param = 'G'
     some_bus.add_comps({'c': self.instance, 'p': param})
     self.instance.bus_func(some_bus.comps.loc[self.instance])
コード例 #27
0
def test_network_no_progress():
    nw = network(['water'])
    source = basics.source('source')
    pipe = piping.pipe('pipe', pr=1, Q=-100e3)
    sink = basics.sink('sink')
    a = connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=280,
                   fluid={'water': 1})
    b = connection(pipe, 'out1', sink, 'in1')
    nw.add_conns(a, b)
    nw.solve('design')
    msg = ('This test must result in a calculation making no progress, as the '
           'pipe\'s outlet enthalpy is below fluid property range.')
    eq_(nw.progress, False, msg)
コード例 #28
0
def test_network_max_iter():
    nw = network(['water'])
    source = basics.source('source')
    pipe = piping.pipe('pipe', pr=1, Q=100e3)
    sink = basics.sink('sink')
    a = connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=280,
                   fluid={'water': 1})
    b = connection(pipe, 'out1', sink, 'in1')
    nw.add_conns(a, b)
    nw.solve('design', max_iter=2)
    msg = ('This test must result in the itercount being equal to the max '
           'iter statement.')
    eq_(nw.max_iter, nw.iter + 1, msg)
コード例 #29
0
def test_turbine_missing_char_parameter():
    """Turbine with invalid parameter for eta_s_char function."""
    nw = network(['CH4'])
    so = basics.source('source')
    si = basics.sink('sink')
    instance = turbomachinery.turbine('turbine')
    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()
コード例 #30
0
ファイル: error_tests.py プロジェクト: FranziPl/tespy
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(method='GENERIC', is_set=True, param=None))
    nw.solve('design', init_only=True)
    instance.eta_s_char_func()