How to use the tespy.tools.data_containers.dc_cc function in tespy

To help you get started, we’ve selected a few tespy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oemof / tespy / tests / test_components / test_turbomachinery.py View on Github external
') at 100 % isentropic efficiency.')
        assert s1 == s2, msg

        # specify realistic value for efficiency, outlet pressure from flow
        # char
        eta_s_d = 0.8
        instance.set_attr(eta_s=eta_s_d)
        self.nw.solve('design')
        convergence_check(self.nw.lin_dep)
        self.nw.save('tmp')
        self.c2.set_attr(p=np.nan)

        # flow char (pressure rise vs. volumetric flow)
        x = [0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]
        y = np.array([14, 13.5, 12.5, 11, 9, 6.5, 3.5, 0]) * 1e5
        char = dc_cc(func=char_line(x, y), is_set=True)
        # apply flow char and eta_s char
        instance.set_attr(flow_char=char, eta_s=np.nan,
                          eta_s_char=dc_cc(func=ldc('pump', 'eta_s_char',
                                                    'DEFAULT', char_line),
                                           is_set=True))
        self.nw.solve('offdesign', design_path='tmp')
        convergence_check(self.nw.lin_dep)

        # value for difference pressure
        dp = 650000.0
        msg = ('Value of pressure rise must be ' + str(dp) + ', is ' +
               str(self.c2.p.val_SI - self.c1.p.val_SI) + '.')
        assert round(self.c2.p.val_SI - self.c1.p.val_SI, 0) == dp, msg

        # test ohter volumetric flow on flow char
        self.c1.set_attr(v=0.9)
github oemof / tespy / tests / error_tests.py View on Github external
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 pytest.raises(ValueError):
        instance.eta_s_char_func()
github oemof / tespy / tests / test_components / test_piping.py View on Github external
# test variable zeta value
        zeta = round(instance.zeta.val, 0)
        instance.set_attr(zeta='var', pr=np.nan)
        self.nw.solve('design')
        convergence_check(self.nw.lin_dep)
        msg = ('Value of dimension independent zeta value must be ' +
               str(zeta) + ', is ' + str(round(instance.zeta.val, 0)) + '.')
        assert zeta == round(instance.zeta.val, 0), msg

        # dp char
        x = np.array([8, 9, 10, 11, 12])
        y = np.array([5, 8, 9, 9.5, 9.6]) * 1e5
        dp_char = char_line(x, y)
        instance.set_attr(zeta=np.nan,
                          dp_char=dc_cc(func=dp_char, is_set=True))
        m = 11
        self.c1.set_attr(m=m)
        self.c2.set_attr(p=np.nan)
        self.nw.solve('design')
        convergence_check(self.nw.lin_dep)
        self.nw.print_results()
        dp = round(-dp_char.evaluate(m), 0)
        dp_act = round(self.c2.p.val_SI - self.c1.p.val_SI)
        msg = ('The pressure drop at the valve should be ' + str(dp) + ' but '
               'is ' + str(dp_act) + '.')
        assert dp == dp_act, msg
github oemof / tespy / tests / error_tests.py View on Github external
self.set_attr_ValueError(self.conn, state='f')

        self.set_attr_ValueError(self.nw, m_unit='kg')
        self.set_attr_ValueError(self.nw, h_unit='kg')
        self.set_attr_ValueError(self.nw, p_unit='kg')
        self.set_attr_ValueError(self.nw, T_unit='kg')
        self.set_attr_ValueError(self.nw, v_unit='kg')

        self.create_connection_ValueError('source')
        self.create_connection_ValueError('target')

        # TypeErrors
        self.set_attr_TypeError(self.comp, P=[5])
        self.set_attr_TypeError(self.comp, tiP_char=None)
        self.set_attr_TypeError(self.comp, design='f')
        self.set_attr_TypeError(self.comp, lamb=dc_cc())
        self.set_attr_TypeError(self.comp, design_path=7)
        self.set_attr_TypeError(self.comp, local_design=5)
        self.set_attr_TypeError(self.comp, local_offdesign=5)
        self.set_attr_TypeError(self.pipe, hydro_group=5)
        self.set_attr_TypeError(self.comp, printout=5)

        self.set_attr_TypeError(self.conn, design='h')
        self.set_attr_TypeError(self.conn, fluid_balance=1)
        self.set_attr_TypeError(self.conn, h0=[4])
        self.set_attr_TypeError(self.conn, fluid=5)
        self.set_attr_TypeError(self.conn, state=5)
        self.set_attr_TypeError(self.conn, design_path=5)
        self.set_attr_TypeError(self.conn, local_design=5)
        self.set_attr_TypeError(self.conn, local_offdesign=5)
        self.set_attr_TypeError(self.conn, printout=5)
github oemof / tespy / tests / test_errors.py View on Github external
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()
github oemof / tespy / tests / error_tests.py View on Github external
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 pytest.raises(ValueError):
        instance.eta_s_char_func()
github oemof / tespy / tests / test_models / test_heat_pump_model.py View on Github external
[0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5,
             0.5625, 0.6375, 0.7125, 0.7875, 0.9, 0.9875, 1, 1.0625, 1.125,
             1.175, 1.2125, 1.2375, 1.25])
        y = np.array(
            [0.0076, 0.1390, 0.2731, 0.4003, 0.5185, 0.6263, 0.7224, 0.8056,
             0.8754, 0.9312, 0.9729, 1.0006, 1.0203, 1.0158, 1.0051, 1.0000,
             0.9746, 0.9289, 0.8832, 0.8376, 0.7843, 0.7614])
        pu.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'],
                    eta_s_char=dc_cc(func=char_line(x, y), param='m'))

        # compressor system
        x = np.array([0, 0.4, 1, 1.2])
        y = np.array([0.5, 0.9, 1, 1.1])

        cp1.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'],
                     eta_s_char=dc_cc(func=char_line(x, y), param='m'))
        cp2.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'],
                     eta_s_char=dc_cc(func=char_line(x, y), param='m'))

        # characteristic line for intercooler kA
        x = np.linspace(0, 2.5, 26)
        y = np.array(
            [0.0000, 0.2455, 0.3747, 0.4798, 0.5718, 0.6552, 0.7323, 0.8045,
             0.8727, 0.9378, 1.0000, 1.0599, 1.1176, 1.1736, 1.2278, 1.2806,
             1.3320, 1.3822, 1.4313, 1.4792, 1.5263, 1.5724, 1.6176, 1.6621,
             1.7058, 1.7488])
        kA_char1 = dc_cc(func=char_line(x, y), param='m')

        x = np.linspace(0, 2.5, 26)
        y = np.array(
            [0.000, 0.164, 0.283, 0.389, 0.488, 0.581, 0.670, 0.756, 0.840,
             0.921, 1.000, 1.078, 1.154, 1.228, 1.302, 1.374, 1.446, 1.516,
github oemof / tespy / src / tespy / components / components.py View on Github external
isinstance(self.get_attr(key), dc_cp)):
                        self.get_attr(key).set_attr(is_set=True, is_var=True)

                    elif isinstance(self.get_attr(key), dc_simple):
                        self.get_attr(key).set_attr(
                            val=kwargs[key], is_set=True)

                    # invalid datatype for keyword
                    else:
                        msg = (
                            'Bad datatype for keyword argument ' + key +
                            ' at ' + self.label + '.')
                        logging.error(msg)
                        raise TypeError(msg)

                elif (isinstance(self.get_attr(key), dc_cc) or
                      isinstance(self.get_attr(key), dc_cm)):
                    # value specification for characteristics
                    if (isinstance(kwargs[key], char_line) or
                            isinstance(kwargs[key], char_map) or
                            isinstance(kwargs[key], compressor_map)):
                        self.get_attr(key).func = kwargs[key]

                    # invalid datatype for keyword
                    else:
                        msg = (
                            'Bad datatype for keyword argument ' + key +
                            ' at ' + self.label + '.')
                        logging.error(msg)
                        raise TypeError(msg)

                elif isinstance(self.get_attr(key), dc_gcp):
github oemof / tespy / src / tespy / networks / network_reader.py View on Github external
if key in c:
            kwargs[key] = c[key]

    for key, value in instance.variables.items():
        if key in c:
            # component parameters
            if isinstance(value, dc_cp):
                kwargs[key] = dc_cp(val=c[key], is_set=c[key + '_set'],
                                    is_var=c[key + '_var'])

            # component parameters
            elif isinstance(value, dc_simple):
                kwargs[key] = dc_simple(val=c[key], is_set=c[key + '_set'])

            # component characteristics
            elif isinstance(value, dc_cc):
                # finding x and y values of the characteristic function
                values = args[0]['id'] == c[key]

                try:
                    x = args[0][values].x.values[0]
                    y = args[0][values].y.values[0]
                    extrapolate = False
                    if 'extrapolate' in args[0].columns:
                        extrapolate = args[0][values].extrapolate.values[0]
                    char = char_line(x=x, y=y, extrapolate=extrapolate)

                except IndexError:

                    char = None
                    msg = ('Could not find x and y values for characteristic '
                           'line, using defaults instead for function ' + key +
github oemof / tespy / tespy / components / reactors.py View on Github external
def attr():
        return {'P': dc_cp(min_val=0),
                'Q': dc_cp(max_val=0),
                'eta': dc_cp(min_val=0, max_val=1),
                'e': dc_cp(),
                'pr_c': dc_cp(max_val=1),
                'zeta': dc_cp(min_val=0),
                'eta_char': dc_cc(),
                'S': dc_simple()}