How to use the tespy.tools.helpers.TESPyNetworkError 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 / error_tests.py View on Github external
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)
    with pytest.raises(TESPyNetworkError):
        nw.solve('design')
github oemof / tespy / tests / error_tests.py View on Github external
def test_network_bus_duplicate(self):
        with pytest.raises(TESPyNetworkError):
            self.nw.add_busses(self.bus, self.bus)
github oemof / tespy / tespy / networks / networks.py View on Github external
if num_o != comp.num_o:
                msg = (comp.label + ' is missing ' + str(comp.num_o - num_o) +
                       ' outgoing connections. Make sure all outlets are '
                       ' connected and all connections have been added to the '
                       'network.')
                logging.error(msg)
                # raise an error in case network check is unsuccesful
                raise hlp.TESPyNetworkError(msg)
            elif num_i != comp.num_i:
                msg = (comp.label + ' is missing ' + str(comp.num_i - num_i) +
                       ' incoming connections. Make sure all inlets are '
                       ' connected and all connections have been added to the '
                       'network.')
                logging.error(msg)
                # raise an error in case network check is unsuccesful
                raise hlp.TESPyNetworkError(msg)

        # network checked
        self.checked = True
        msg = 'Networkcheck successful.'
        logging.info(msg)
github oemof / tespy / tespy / networks / networks.py View on Github external
c.T.design = ((df.loc[conn_id]['T'] +
                           self.T[df.loc[conn_id].T_unit][0]) *
                          self.T[df.loc[conn_id].T_unit][1])
            c.Td_bp.design = (df.loc[conn_id].Td_bp *
                              self.T[df.loc[conn_id].T_unit][1])
            for fluid in self.fluids:
                c.fluid.design[fluid] = df.loc[conn_id][fluid]
        else:
            # no matches in the connections of the network and the design files
            msg = ('Could not find connection ' + c.s.label + '(' + c.s_id +
                   ') -> ' + c.t.label + '(' + c.t_id + ') in design case. '
                   'Please, make sure no connections have been modified '
                   'or components have been relabeled for your offdesign '
                   'calculation.')
            logging.error(msg)
            raise hlp.TESPyNetworkError(msg)
github oemof / tespy / src / tespy / networks / networks.py View on Github external
- Check offdesign path specification.
        - Set component and connection design point properties.
        - Switch from design/offdesign parameter specification.
        """
        if len(self.conns) == 0:
            msg = (
                'No connections have been added to the network, please make '
                'sure to add your connections with the .add_conns() method.')
            logging.error(msg)
            raise hlp.TESPyNetworkError(msg)

        if len(self.fluids) == 0:
            msg = ('Network has no fluids, please specify a list with fluids '
                   'on network creation.')
            logging.error(msg)
            raise hlp.TESPyNetworkError(msg)

        if self.mode == 'offdesign':
            self.redesign = True
            if self.design_path is None:
                # must provide design_path
                msg = ('Please provide "design_path" for every offdesign '
                       'calculation.')
                logging.error(msg)
                raise hlp.TESPyNetworkError(msg)
            else:
                # load design case
                if self.new_design is True:
                    self.init_offdesign_params()

                self.init_offdesign()
        else:
github oemof / tespy / tespy / networks / networks.py View on Github external
'Please check your network.')
            logging.error(msg)
            raise hlp.TESPyNetworkError(msg)

        dub = self.conns.loc[self.conns.duplicated(['t', 't_id']) == True]
        for c in dub.index:
            sources = ''
            for conns in self.conns[(self.conns.t == c.t) &
                                    (self.conns.t_id == c.t_id)].index:
                sources += conns.s.label + ' (' + conns.s_id + '); '

            msg = ('The target ' + c.t.label + ' (' + c.t_id + ') is attached '
                   'to more than one source: ' + sources[:-2] + '. '
                   'Please check your network.')
            logging.error(msg)
            raise hlp.TESPyNetworkError(msg)
github oemof / tespy / src / tespy / networks / networks.py View on Github external
----------
        b : tespy.connections.bus
            The bus to be checked.
        """
        if isinstance(b, con.bus):
            if len(self.busses) > 0:
                if b in self.busses.values():
                    msg = ('Network contains the bus ' + b.label + ' (' +
                           str(b) + ') already.')
                    logging.error(msg)
                    raise hlp.TESPyNetworkError(msg)
                elif b.label in self.busses.keys():
                    msg = ('Network already has a bus with the name ' +
                           b.label + '.')
                    logging.error(msg)
                    raise hlp.TESPyNetworkError(msg)
                else:
                    return True
            else:
                return True
        else:
            msg = 'Only objects of type bus are allowed in *args.'
            logging.error(msg)
            raise TypeError(msg)
github oemof / tespy / src / tespy / networks / networks.py View on Github external
design point information are read from the .csv-files in the respective
        :code:`design_path`. In this case, the design values are unset, the
        offdesign values set.
        """
        # connections
        for c in self.conns.index:
            # read design point information of connections with
            # local_offdesign activated from their respective design path
            if c.local_offdesign is True:
                if c.design_path is None:
                    msg = (
                        'The parameter local_offdesign is True for the '
                        'connection ' + c.label + ', an individual '
                        'design_path must be specified in this case!')
                    logging.error(msg)
                    raise hlp.TESPyNetworkError(msg)

                # unset design parameters
                for var in c.design:
                    c.get_attr(var).set_attr(val_set=False)
                # set offdesign parameters
                for var in c.offdesign:
                    c.get_attr(var).set_attr(val_set=True)

                # read design point information
                path = hlp.modify_path_os(c.design_path + '/connections.csv')
                msg = (
                    'Reading individual design point information for '
                    'connection ' + c.label + ' from path ' + path + '.')
                logging.debug(msg)
                df = pd.read_csv(path, index_col=0, delimiter=';', decimal='.')
github oemof / tespy / src / tespy / networks / networks.py View on Github external
raise hlp.TESPyNetworkError(msg)

        if len(self.fluids) == 0:
            msg = ('Network has no fluids, please specify a list with fluids '
                   'on network creation.')
            logging.error(msg)
            raise hlp.TESPyNetworkError(msg)

        if self.mode == 'offdesign':
            self.redesign = True
            if self.design_path is None:
                # must provide design_path
                msg = ('Please provide "design_path" for every offdesign '
                       'calculation.')
                logging.error(msg)
                raise hlp.TESPyNetworkError(msg)
            else:
                # load design case
                if self.new_design is True:
                    self.init_offdesign_params()

                self.init_offdesign()
        else:
            # load design case
            self.init_design()

        # generic fluid initialisation
        self.init_fluids()
        # generic fluid property initialisation
        self.init_properties()

        # starting values from init path
github oemof / tespy / src / tespy / networks / networks.py View on Github external
str(self.num_conn_vars * len(self.conns.index)) + '.')
        logging.debug(msg)

        n = self.num_comp_eq + self.num_conn_eq + self.num_bus_eq
        if n > self.num_vars:
            msg = ('You have provided too many parameters: ' +
                   str(self.num_vars) + ' required, ' + str(n) +
                   ' supplied. Aborting calculation!')
            logging.error(msg)
            raise hlp.TESPyNetworkError(msg)
        elif n < self.num_vars:
            msg = ('You have not provided enough parameters: '
                   + str(self.num_vars) + ' required, ' + str(n) +
                   ' supplied. Aborting calculation!')
            logging.error(msg)
            raise hlp.TESPyNetworkError(msg)