예제 #1
0
    def __init__(self, label, **kwargs):

        self.comps = pd.DataFrame(columns=['param', 'P_ref', 'char'])

        self.label = label
        self.P = dc_cp(val=np.nan, val_set=False)
        self.char = cmp_char.characteristics(x=np.array([0, 1, 2, 3]),
                                             y=np.array([1, 1, 1, 1]))

        self.set_attr(**kwargs)
예제 #2
0
    def __init__(self, label, P=np.nan):

        self.comps = pd.DataFrame(columns=['param', 'P_ref', 'char'])

        self.label = label
        self.P = dc_cp(val=np.nan, val_set=False)
        self.char = cmp_char.characteristics(x=np.array([0, 1, 2, 3]),
                                             y=np.array([1, 1, 1, 1]))

        self.set_attr(P=P)

        msg = 'Created bus ' + self.label + '.'
        logging.debug(msg)
예제 #3
0
    def add_comps(self, *args):
        r"""
        Add components to a bus.

        Parameters
        ----------
        c : dict
            Dictionary containing the component information to be added to the bus.
            These information are described in the notes!

        Note
        ----
        Keys for the dictionary c:

        - c (tespy.components.components.component): Component you want to add to the bus.
        - p (str): Bus parameter, optional.

            - You do not need to provide a parameter, if the component only has one
              option for the bus (turbomachines, heat exchangers, combustion
              chamber).
            - For instance, you do neet do provide a parameter, if you want to add
              a cogeneration unit ('Q', 'Q1', 'Q2', 'TI', 'P', 'Qloss').

        - char (float/tespy.components.characteristics.characteristics):
          Characteristic function for this components share to the bus value, optional.

            - If you do not provide a characteristic line at all, TESPy assumes a
              constant factor of 1.
            - If you provide a numeric value instead of a characteristic line,
              TESPy takes this numeric value as a constant factor.
            - Provide a TESPy.characteristic (cmp_char), if you want the factor
              to follow a characteristic line.

        - P_ref (float): Energy flow specification for reference case, :math:`P \text{/W}`, optional.
        """
        for c in args:
            if isinstance(c, dict):
                if 'c' in c.keys():
                    if isinstance(c['c'], cmp.component):
                        self.comps.loc[c['c']] = [None, np.nan, self.char]
                    else:
                        msg = ('Keyword c must hold a TESPy component.')
                        logging.error(msg)
                        raise TypeError(msg)
                else:
                    msg = ('You must provide the component c.')
                    logging.error(msg)
                    raise TypeError(msg)

                for k, v in c.items():
                    if k == 'p':
                        if isinstance(v, str) or v is None:
                            self.comps.loc[c['c']]['param'] = v
                        else:
                            msg = ('Parameter p must be a string.')
                            logging.error(msg)
                            raise TypeError(msg)

                    elif k == 'char':
                        if isinstance(v, cmp_char.characteristics):
                            self.comps.loc[c['c']]['char'] = v
                        elif (isinstance(v, float)
                              or isinstance(v, np.float64)
                              or isinstance(v, np.int64)
                              or isinstance(v, int)):
                            x = np.array([0, 1, 2, 3])
                            y = np.array([1, 1, 1, 1]) * v
                            self.comps.loc[c['c']]['char'] = (
                                cmp_char.characteristics(x=x, y=y))
                        else:
                            msg = (
                                'Char must be a number or a TESPy characteristics.'
                            )
                            logging.error(msg)
                            raise TypeError(msg)

                    elif k == 'P_ref':
                        if (v is None or isinstance(v, float)
                                or isinstance(v, np.float64)
                                or isinstance(v, np.int64)
                                or isinstance(v, int)):
                            self.comps.loc[c['c']]['P_ref'] = v
                        else:
                            msg = ('Reference value must be numeric.')
                            logging.error(msg)
                            raise TypeError(msg)
            else:
                msg = (
                    'Provide arguments as dicts. See the documentation of bus.add_comps() for more information.'
                )
                logging.error(msg)
                raise TESPyConnectionError(msg)

            msg = 'Added component ' + c[
                'c'].label + ' to bus ' + self.label + '.'
            logging.debug(msg)
예제 #4
0
    def add_comps(self, *args):
        """
        adds components to a bus

        ci are dicts containing a TESPy component object
        as well as a parameter (P, Q, Q1, TI, ...) and a characteristic line
        char (cmp_char):

        {'c': TESPy component object, 'p': parameter as String,
        'char': TESPy characteristics object}

        **The parameter and characteristic line are optional!!**

        **parameter specfication**
        - You do not need to provide a parameter, if the component only has one
          option for the bus (turbomachines, heat exchangers, combustion
          chamber).
        - For instance, you do neet do provide a parameter, if you want to add
          a cogeneration unit ('Q1', 'Q2', 'TI', 'P').

         **characteristic line specification**
        - If you do not provide a characteristic line at all, TESPy assumes a
          constant factor of 1.
        - If you provide a numeric value instead of a characteristic line,
          TESPy takes this numeric value as a constant factor.
        - Provide a TESPy.characteristic (cmp_char), if you want the factor
          to follow a characteristic line.

        :param args: lists ci containing necessary data for the bus
        :type args: list
        :returns: no return value
        """
        for c in args:
            if isinstance(c, dict):
                if 'c' in c.keys():
                    if isinstance(c['c'], cmp.component):
                        self.comps.loc[c['c']] = [None, np.nan, self.char]
                    else:
                        msg = ('c must be a TESPy component.')
                        raise TypeError(msg)
                else:
                        msg = ('You must provide the component c.')
                        raise TypeError(msg)

                for k, v in c.items():
                    if k == 'p':
                        if isinstance(v, str) or v is None:
                            self.comps.loc[c['c']]['param'] = v
                        else:
                            msg = ('Parameter p must be a String.')
                            raise TypeError(msg)

                    elif k == 'char':
                        if isinstance(v, cmp_char.characteristics):
                            self.comps.loc[c['c']]['char'] = v
                        elif (isinstance(v, float) or
                              isinstance(v, np.float64) or
                              isinstance(v, int)):
                            x = np.array([0, 1, 2, 3])
                            y = np.array([1, 1, 1, 1]) * v
                            self.comps.loc[c['c']]['char'] = (
                                    cmp_char.characteristics(x=x, y=y))
                        else:
                            msg = ('Char must be a number or a TESPy '
                                   'characteristics.')
                            raise TypeError(msg)

                    elif k == 'P_ref':
                        if (v is None or isinstance(v, float) or
                                isinstance(v, np.float64) or
                                isinstance(v, int)):
                            self.comps.loc[c['c']]['P_ref'] = v
                        else:
                            msg = ('Char must be a number or a TESPy '
                                   'characteristics.')
                            raise TypeError(msg)
            else:
                msg = ('Provide arguments as dicts. See the documentation of '
                       'bus.add_comps() for more information.')
                raise MyConnectionError(msg)