示例#1
0
文件: analyses.py 项目: oemof/tespy
    def analyse(self, pamb, Tamb):
        """Run the exergy analysis.

        Parameters
        ----------
        pamb : float
            Ambient pressure value for analysis, provide value in network's
            pressure unit.

        Tamb : float
            Ambient temperature value for analysis, provide value in network's
            temperature unit.
        """
        pamb_SI = hlp.convert_to_SI('p', pamb, self.nw.p_unit)
        Tamb_SI = hlp.convert_to_SI('T', Tamb, self.nw.T_unit)

        # reset data
        self.component_data = pd.DataFrame(
            columns=['E_F', 'E_P', 'E_D', 'epsilon', 'group'], dtype='float64')
        self.bus_data = self.component_data.copy()
        self.connection_data = pd.DataFrame(
            columns=['e_PH', 'e_T', 'e_M', 'E_PH', 'E_T', 'E_M'],
            dtype='float64')
        self.network_data = pd.Series(index=['E_F', 'E_P', 'E_D', 'E_L'],
                                      dtype='float64')
        self.network_data[:] = 0

        # physical exergy of connections
        for conn in self.nw.conns['object']:
            conn.get_physical_exergy(pamb_SI, Tamb_SI)
            self.connection_data.loc[conn.label] = [
                conn.ex_physical, conn.ex_therm, conn.ex_mech,
                conn.Ex_physical, conn.Ex_therm, conn.Ex_mech
            ]

        self.sankey_data = {}
        for label in self.reserved_fkt_groups:
            self.sankey_data[label] = pd.DataFrame(columns=['value', 'cat'],
                                                   dtype='object')

        # exergy balance of components
        for cp in self.nw.comps['object']:
            # save component information
            cp.exergy_balance(Tamb_SI)
            if not hasattr(cp, 'fkt_group'):
                cp.fkt_group = cp.label
            self.component_data.loc[cp.label] = [
                cp.E_F, cp.E_P, cp.E_D, cp.epsilon, cp.fkt_group
            ]

            if cp.fkt_group in self.reserved_fkt_groups:
                msg = (
                    'The labels ' + ', '.join(self.reserved_fkt_groups) + ' '
                    'cannot be used by components (if no group was assigned) '
                    'or component groups in the exergy analysis. Found '
                    'component/group with name ' + cp.fkt_group + '.')
                raise ValueError(msg)
            elif cp.fkt_group not in self.sankey_data:
                self.sankey_data[cp.fkt_group] = pd.DataFrame(
                    columns=['value', 'cat'], dtype='object')

            self.evaluate_busses(cp)

        self.network_data.loc['E_D'] = (self.component_data['E_D'].sum() +
                                        self.bus_data['E_D'].sum())
        self.network_data.loc['E_F'] = abs(self.network_data.loc['E_F'])
        self.network_data.loc['E_P'] = abs(self.network_data.loc['E_P'])
        self.network_data.loc['epsilon'] = (self.network_data.loc['E_P'] /
                                            self.network_data.loc['E_F'])

        # calculate exergy destruction ratios for components/busses
        E_F = self.network_data.loc['E_F']
        E_D = self.network_data.loc['E_D']
        self.component_data['y_Dk'] = self.component_data['E_D'] / E_F
        self.component_data['y*_Dk'] = self.component_data['E_D'] / E_D
        self.bus_data['y_Dk'] = self.bus_data['E_D'] / E_F
        self.bus_data['y*_Dk'] = self.bus_data['E_D'] / E_D

        residual = abs(self.network_data.loc['E_F'] -
                       self.network_data.loc['E_P'] -
                       self.network_data.loc['E_D'] -
                       self.network_data.loc['E_L'])

        if residual >= err**0.5:
            msg = (
                'The exergy balance of your network is not closed (residual '
                'value is ' + str(round(residual, 6)) + ', but should be '
                'smaller than ' + str(err**0.5) + '), you should check the '
                'component and network exergy data and check, if network is '
                'properly setup for the exergy analysis.')
            logging.error(msg)

        self.create_group_data()
示例#2
0
    def comp_init(self, nw):
        Component.comp_init(self, nw, num_eq=len(nw.fluids) + 1)

        self.Tamb.val_SI = convert_to_SI('T', self.Tamb.val, nw.T_unit)