Esempio n. 1
0
 def get_variables(self):
     return {
         'P': dc_cp(
             min_val=0, num_eq=1,
             deriv=self.energy_balance_deriv,
             func=self.energy_balance_func,
             latex=self.energy_balance_func_doc),
         'eta_s': dc_cp(
             min_val=0, max_val=1, num_eq=1,
             deriv=self.eta_s_deriv,
             func=self.eta_s_func, latex=self.eta_s_func_doc),
         'eta_s_char': dc_cc(
             param='m', num_eq=1,
             deriv=self.eta_s_char_deriv,
             func=self.eta_s_char_func, latex=self.eta_s_char_func_doc),
         'pr': dc_cp(
             min_val=1, num_eq=1,
             deriv=self.pr_deriv,
             func=self.pr_func, func_params={'pr': 'pr'},
             latex=self.pr_func_doc),
         'igva': dc_cp(min_val=-90, max_val=90, d=1e-3, val=0),
         'char_map_eta_s': dc_cm(),
         'char_map_eta_s_group': dc_gcp(
             elements=['char_map_eta_s', 'igva'], num_eq=1,
             latex=self.char_map_eta_s_func_doc,
             func=self.char_map_eta_s_func,
             deriv=self.char_map_eta_s_deriv),
         'char_map_pr': dc_cm(),
         'char_map_pr_group': dc_gcp(
             elements=['char_map_pr', 'igva'],
             deriv=self.char_map_pr_deriv, num_eq=1,
             func=self.char_map_pr_func, latex=self.char_map_pr_func_doc)
     }
Esempio n. 2
0
def construct_comps(c, *args):
    r"""
    Create TESPy component from class name and set parameters.

    Parameters
    ----------
    c : pandas.core.series.Series
        Component information from .csv-file.

    args[0] : pandas.core.frame.DataFrame
        DataFrame containing the data of characteristic lines.

    args[1] : pandas.core.frame.DataFrame
        DataFrame containing the data of characteristic maps.

    Returns
    -------
    instance : tespy.components.components.component
        TESPy component object.
    """
    target_class = comp_target_classes[c.cp]
    instance = target_class(c.label)
    kwargs = {}

    # basic properties
    for key in [
            'design', 'offdesign', 'design_path', 'local_design',
            'local_offdesign'
    ]:
        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 +
                           ' at component ' + c.label + '.')
                    logging.warning(msg)

                kwargs[key] = dc_cc(is_set=c[key + '_set'],
                                    param=c[key + '_param'],
                                    func=char)

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

                try:
                    x = list(args[1][values].x.values[0])
                    y = list(args[1][values].y.values[0])
                    z1 = list(args[1][values].z1.values[0])
                    z2 = list(args[1][values].z2.values[0])
                    target_class = map_target_classes[args[1]
                                                      [values].type.values[0]]
                    char = target_class(x=x, y=y, z1=z1, z2=z2)

                except IndexError:
                    char = None
                    msg = ('Could not find x, y, z1 and z2 values for '
                           'characteristic map of component ' + c.label + '!')
                    logging.warning(msg)

                kwargs[key] = dc_cm(is_set=c[key + '_set'],
                                    param=c[key + '_param'],
                                    func=char)

            # grouped component parameters
            elif isinstance(value, dc_gcp):
                kwargs[key] = dc_gcp(method=c[key])

    instance.set_attr(**kwargs)
    return instance
Esempio n. 3
0
    def test_compressor(self):
        """Test component properties of compressors."""
        instance = compressor('compressor')
        self.setup_network(instance)

        # compress NH3, other fluids in network are for turbine, pump, ...
        fl = {'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'NH3': 1}
        self.c1.set_attr(fluid=fl, v=1, p=5, T=100)
        self.c2.set_attr(p=7)
        instance.set_attr(eta_s=0.8)
        self.nw.solve('design')
        self.nw.save('tmp')

        # test isentropic efficiency value
        eta_s_d = ((instance.h_os('') - self.c1.h.val_SI) /
                   (self.c2.h.val_SI - self.c1.h.val_SI))
        msg = ('Value of isentropic efficiency must be ' + str(eta_s_d) +
               ', is ' + str(instance.eta_s.val) + '.')
        eq_(round(eta_s_d, 3), round(instance.eta_s.val, 3), msg)

        # trigger invalid value for isentropic efficiency
        instance.set_attr(eta_s=1.1)
        self.nw.solve('design')

        # test calculated value
        eta_s = ((instance.h_os('') - self.c1.h.val_SI) /
                 (self.c2.h.val_SI - self.c1.h.val_SI))
        msg = ('Value of isentropic efficiency must be ' + str(eta_s) +
               ', is ' + str(instance.eta_s.val) + '.')
        eq_(round(eta_s, 3), round(instance.eta_s.val, 3), msg)

        # remove pressure at outlet, use characteristic map for pressure
        # rise calculation
        self.c2.set_attr(p=np.nan)
        instance.set_attr(char_map=dc_cm(func=ldc('compressor', 'char_map',
                                                  'DEFAULT', compressor_map),
                                         is_set=True),
                          eta_s=np.nan)

        # offdesign test, efficiency value should be at design value
        self.nw.solve('offdesign', design_path='tmp')
        msg = ('Value of isentropic efficiency (' + str(instance.eta_s.val) +
               ') must be identical to design case (' + str(eta_s) + ').')
        eq_(round(eta_s_d, 2), round(instance.eta_s.val, 2), msg)

        # move to highest available speedline, mass flow below lowest value
        # at that line
        self.c1.set_attr(v=np.nan, m=self.c1.m.val * 0.8, T=30)
        self.nw.solve('offdesign', design_path='tmp')
        # should be value
        eta_s = eta_s_d * instance.char_map.func.z2[6, 0]
        msg = ('Value of isentropic efficiency (' + str(instance.eta_s.val) +
               ') must be at (' + str(round(eta_s, 4)) + ').')
        eq_(round(eta_s, 4), round(instance.eta_s.val, 4), msg)

        # going below lowest available speedline, above highest mass flow at
        # that line
        self.c1.set_attr(T=300)
        self.nw.solve('offdesign', design_path='tmp', init_path='tmp')
        # should be value
        eta_s = eta_s_d * instance.char_map.func.z2[0, 9]
        msg = ('Value of isentropic efficiency (' + str(instance.eta_s.val) +
               ') must be at (' + str(round(eta_s, 4)) + ').')
        eq_(round(eta_s, 4), round(instance.eta_s.val, 4), msg)

        # back to design properties, test eta_s_char
        self.c2.set_attr(p=7)
        self.c1.set_attr(v=1, T=100, m=np.nan)

        # test parameter specification for eta_s_char with unset char map
        instance.set_attr(eta_s_char=dc_cc(func=ldc('compressor', 'eta_s_char',
                                                    'DEFAULT', char_line),
                                           is_set=True,
                                           param='m'))
        instance.char_map.is_set = False
        self.nw.solve('offdesign', design_path='tmp')
        msg = ('Value of isentropic efficiency must be ' + str(eta_s_d) +
               ', is ' + str(instance.eta_s.val) + '.')
        eq_(round(eta_s_d, 3), round(instance.eta_s.val, 3), msg)

        # move up in volumetric flow
        self.c1.set_attr(v=1.5)
        self.nw.solve('offdesign', design_path='tmp')
        eta_s = round(
            eta_s_d * instance.eta_s_char.func.evaluate(
                self.c1.m.val_SI / self.c1.m.design), 3)
        msg = ('Value of isentropic efficiency must be ' + str(eta_s) +
               ', is ' + str(round(instance.eta_s.val, 3)) + '.')
        eq_(eta_s, round(instance.eta_s.val, 3), msg)

        # test parameter specification for pr
        instance.eta_s_char.set_attr(param='pr')
        self.c1.set_attr(v=1)
        self.c2.set_attr(p=7.5)
        self.nw.solve('offdesign', design_path='tmp')
        expr = (self.c2.p.val_SI * self.c1.p.design /
                (self.c2.p.design * self.c1.p.val_SI))
        eta_s = round(eta_s_d * instance.eta_s_char.func.evaluate(expr), 3)
        msg = ('Value of isentropic efficiency must be ' + str(eta_s) +
               ', is ' + str(round(instance.eta_s.val, 3)) + '.')
        eq_(eta_s, round(instance.eta_s.val, 3), msg)

        shutil.rmtree('./tmp', ignore_errors=True)