コード例 #1
0
ファイル: drum.py プロジェクト: oemof/tespy
    def initialise_target(c, key):
        r"""
        Return a starting value for pressure and enthalpy at inlet.

        Parameters
        ----------
        c : tespy.connections.connection.Connection
            Connection to perform initialisation on.

        key : str
            Fluid property to retrieve.

        Returns
        -------
        val : float
            Starting value for pressure/enthalpy in SI units.

            .. math::

                val = \begin{cases}
                10^6 & \text{key = 'p'}\\
                h\left(p, x=0 \right) & \text{key = 'h' at inlet 1}\\
                h\left(p, x=0.7 \right) & \text{key = 'h' at inlet 2}
                \end{cases}
        """
        if key == 'p':
            return 10e5
        elif key == 'h':
            if c.target_id == 'in1':
                return h_mix_pQ(c.get_flow(), 0)
            else:
                return h_mix_pQ(c.get_flow(), 0.7)
コード例 #2
0
    def initialise_source(self, c, key):
        r"""
        Returns a starting value for pressure and enthalpy at component's
        outlet.

        Parameters
        ----------
        c : tespy.connections.connection
            Connection to perform initialisation on.

        key : str
            Fluid property to retrieve.

        Returns
        -------
        val : float
            Starting value for pressure/enthalpy in SI units.

            .. math::

                val = \begin{cases}
                10^6 & \text{key = 'p'}\\
                h\left(p, x=0 \right) & \text{key = 'h' at outlet 1}\\
                h\left(p, x=1 \right) & \text{key = 'h' at outlet 2}
                \end{cases}
        """
        if key == 'p':
            return 10e5
        elif key == 'h':
            if c.s_id == 'out1':
                return h_mix_pQ(c.to_flow(), 0)
            else:
                return h_mix_pQ(c.to_flow(), 1)
コード例 #3
0
ファイル: droplet_separator.py プロジェクト: oemof/tespy
    def outlet_states_func(self):
        r"""
        Calculate energy balance.

        Returns
        -------
        residual : list
            Residual values of outlet state equations.

            .. math::

                0 = h_{out,1} - h\left(p, x=0 \right)\\
                0 = h_{out,2} - h\left(p, x=1 \right)
        """
        return [
            h_mix_pQ(self.outl[0].get_flow(), 0) - self.outl[0].h.val_SI,
            h_mix_pQ(self.outl[1].get_flow(), 1) - self.outl[1].h.val_SI]
コード例 #4
0
    def equations(self):
        r"""
        Calculates vector vec_res with results of equations for this component.

        Returns
        -------
        vec_res : list
            Vector of residual values.
        """
        vec_res = []

        ######################################################################
        # eqations for fluid balance
        vec_res += self.fluid_func()

        ######################################################################
        # eqations for mass flow balance
        vec_res += self.mass_flow_func()

        ######################################################################
        # eqations for pressure
        p = self.inl[0].p.val_SI
        for c in [self.inl[1]] + self.outl:
            vec_res += [p - c.p.val_SI]

        ######################################################################
        # eqations for enthalpy
        val = 0
        for i in self.inl:
            val += i.m.val_SI * i.h.val_SI
        for o in self.outl:
            val -= o.m.val_SI * o.h.val_SI
        vec_res += [val]

        ######################################################################
        # eqations for staturated fluid state at outlets
        vec_res += [
            h_mix_pQ(self.outl[0].to_flow(), 0) - self.outl[0].h.val_SI
        ]
        vec_res += [
            h_mix_pQ(self.outl[1].to_flow(), 1) - self.outl[1].h.val_SI
        ]

        return vec_res
コード例 #5
0
    def equations(self):
        r"""Calculate vector vec_res with results of equations."""
        k = 0
        ######################################################################
        # eqations for fluid balance
        self.vec_res[k:k + self.num_nw_fluids * 2] = self.fluid_func()
        k += self.num_nw_fluids * 2

        ######################################################################
        # eqations for mass flow balance
        self.vec_res[k] = self.mass_flow_func()
        k += 1

        ######################################################################
        # eqations for pressure
        p = self.inl[0].p.val_SI
        for c in [self.inl[1]] + self.outl:
            self.vec_res[k] = p - c.p.val_SI
            k += 1

        ######################################################################
        # eqations for enthalpy
        val = 0
        for i in self.inl:
            val += i.m.val_SI * i.h.val_SI
        for o in self.outl:
            val -= o.m.val_SI * o.h.val_SI
        self.vec_res[k] = val
        k += 1

        ######################################################################
        # eqations for staturated fluid state at outlets
        self.vec_res[k] = h_mix_pQ(
            self.outl[0].to_flow(), 0) - self.outl[0].h.val_SI
        k += 1
        self.vec_res[k] = h_mix_pQ(
            self.outl[1].to_flow(), 1) - self.outl[1].h.val_SI
        k += 1
コード例 #6
0
    def saturated_gas_func(self):
        r"""
        Calculate hot side outlet state.

        Returns
        -------
        residual : float
            Residual value of equation

            .. math::

                0 = h_{out,1} - h\left(p_{out,1}, x=1 \right)
        """
        return self.outl[0].h.val_SI - h_mix_pQ(self.outl[0].get_flow(), 1)
コード例 #7
0
    def overheating_func(self):
        r"""
        Equation for cold side outlet state.

        Returns
        -------
        residual : float
            Residual value of equation.

            .. math::

                0=h_{out,3} -h\left(p_{out,3}, x=1 \right)

        Note
        ----
        This equation is applied in case overheating is False!
        """
        return self.outl[2].h.val_SI - h_mix_pQ(self.outl[2].get_flow(), 1)
コード例 #8
0
    def subcooling_func(self):
        r"""
        Equation for steam side outlet state.

        Returns
        -------
        residual : float
            Residual value of equation.

            .. math::

                0=h_{out,1} -h\left(p_{out,1}, x=0 \right)

        Note
        ----
        This equation is applied in case subcooling is False!
        """
        return self.outl[0].h.val_SI - h_mix_pQ(self.outl[0].get_flow(), 0)
コード例 #9
0
ファイル: customs.py プロジェクト: soni-roca/tespy
    def equations(self):
        r"""Calculate residual vector with results of equations."""
        k = 0

        ######################################################################
        # equations for fluid balance
        self.residual[k:k + self.num_nw_fluids * 3] = self.fluid_func()
        k += self.num_nw_fluids * 3

        ######################################################################
        # equations for mass flow balance
        self.residual[k:k + 3] = self.mass_flow_func()
        k += 3

        ######################################################################
        # equations for energy balance
        self.residual[k] = self.energy_func()
        k += 1

        ######################################################################
        # equations for specified heat transfer
        if self.Q.is_set:
            self.residual[k] = (
                self.inl[2].m.val_SI *
                (self.outl[2].h.val_SI - self.inl[2].h.val_SI) - self.Q.val)
            k += 1

        ######################################################################
        # equations for specified pressure ratio at hot side 1
        if self.pr1.is_set:
            self.residual[k] = (self.pr1.val * self.inl[0].p.val_SI -
                                self.outl[0].p.val_SI)
            k += 1

        ######################################################################
        # equations for specified pressure ratio at hot side 2
        if self.pr2.is_set:
            self.residual[k] = (self.pr2.val * self.inl[1].p.val_SI -
                                self.outl[1].p.val_SI)
            k += 1

        ######################################################################
        # equations for specified pressure ratio at cold side
        if self.pr3.is_set:
            self.residual[k] = (self.pr3.val * self.inl[2].p.val_SI -
                                self.outl[2].p.val_SI)
            k += 1

        ######################################################################
        # equations for specified zeta at hot side 1
        if self.zeta1.is_set:
            self.residual[k] = self.zeta_func(zeta='zeta1',
                                              inconn=0,
                                              outconn=0)
            k += 1

        ######################################################################
        # equations for specified zeta at hot side 2
        if self.zeta2.is_set:
            self.residual[k] = self.zeta_func(zeta='zeta2',
                                              inconn=1,
                                              outconn=1)
            k += 1

        ######################################################################
        # equations for specified zeta at cold side
        if self.zeta3.is_set:
            self.residual[k] = self.zeta_func(zeta='zeta3',
                                              inconn=2,
                                              outconn=2)
            k += 1

        ######################################################################
        # equation for saturated liquid at hot side 1 outlet
        if self.subcooling.val is False:
            o1 = self.outl[0].to_flow()
            self.residual[k] = o1[2] - h_mix_pQ(o1, 0)
            k += 1

        ######################################################################
        # equation for saturated gas at cold side outlet
        if self.overheating.val is False:
            o3 = self.outl[2].to_flow()
            self.residual[k] = o3[2] - h_mix_pQ(o3, 1)
            k += 1
コード例 #10
0
def test_h_mix_pQ_on_mixtures():
    with raises(ValueError):
        h_mix_pQ([0, 0, 0, {'O2': 0.24, 'N2': 0.76}], 0.75)