Exemple #1
0
    def calculo(self, st):
        self.x = unidades.Dimensionless(st.x)
        self.region = st.region
        self.phase = self.getphase(phase=st.phase)
        self.name = st.name
        self.synonim = st.synonim
        self.CAS = st.CAS

        self.T = unidades.Temperature(st.T)
        self.P = unidades.Pressure(st.P, "MPa")
        self.Tr = unidades.Dimensionless(st.Tr)
        self.Pr = unidades.Dimensionless(st.Pr)
        self.v = unidades.SpecificVolume(st.v)
        self.rho = unidades.Density(st.rho)

        cp0 = {}
        cp0["v"] = st.v0
        cp0["h"] = st.h0 * 1000
        cp0["s"] = st.s0 * 1000
        cp0["cp"] = st.cp0 * 1000
        cp0["cv"] = st.cv0 * 1000
        cp0["w"] = st.w0
        self._cp0(cp0)

        self.Liquido = ThermoWater()
        self.Gas = ThermoWater()
        if self.x == 0:
            # only liquid phase
            self.fill(self, st.Liquid)
            self.fill(self.Liquido, st.Liquid)
            self.sigma = unidades.Tension(st.sigma)
            self.Hvap = unidades.Enthalpy(None)
            self.Svap = unidades.SpecificHeat(None)

        elif self.x == 1:
            # only vapor phase
            self.fill(self, st.Vapor)
            self.fill(self.Gas, st.Vapor)
            self.Hvap = unidades.Enthalpy(None)
            self.Svap = unidades.SpecificHeat(None)

        else:
            # two phases
            self.fill(self.Liquido, st.Liquid)
            self.sigma = unidades.Tension(st.sigma)
            self.fill(self.Gas, st.Vapor)

            self.h = unidades.Enthalpy(st.h)
            self.s = unidades.SpecificHeat(st.s)
            self.u = unidades.SpecificHeat(st.u)
            self.a = unidades.Enthalpy(st.a)
            self.g = unidades.Enthalpy(st.g)

            self.cv = unidades.SpecificHeat(None)
            self.cp = unidades.SpecificHeat(None)
            self.cp_cv = unidades.Dimensionless(None)
            self.w = unidades.Speed(None)

            self.Hvap = unidades.Enthalpy(st.Hvap, "kJkg")
            self.Svap = unidades.SpecificHeat(st.Svap, "kJkgK")
Exemple #2
0
    def _cp0(self, flash):
        "Set ideal properties to state"""
        cp0 = refprop.therm0(flash["t"], flash["D"], flash["x"])
        self.v0 = unidades.SpecificVolume(self.R*self.T/self.P.kPa)
        self.rho0 = unidades.Density(1/self.v0)
        self.P0 = unidades.Pressure(cp0["p"], "kPa")
        self.P_Pideal = unidades.Pressure(self.P-self.P0)

        self.h0 = unidades.Enthalpy(cp0["h"]/self.M, "kJkg")
        self.u0 = unidades.Enthalpy(cp0["e"]/self.M, "kJkg")
        self.s0 = unidades.SpecificHeat(cp0["s"]/self.M, "kJkgK")
        self.a0 = unidades.Enthalpy(cp0["A"]/self.M, "kJkg")
        self.g0 = unidades.Enthalpy(cp0["G"]/self.M, "kJkg")
        self.w0 = unidades.Speed(cp0["w"])

        cp0 = refprop.therm0(float(self.T), self.rho0/self.M, flash["x"])
        self.cp0 = unidades.SpecificHeat(cp0["cp"]/self.M, "kJkgK")
        self.cv0 = unidades.SpecificHeat(cp0["cv"]/self.M, "kJkgK")
        self.cp0_cv = unidades.Dimensionless(self.cp0/self.cv0)
        self.gamma0 = self.cp0_cv

        self.rhoM0 = unidades.MolarDensity(self.rho0/self.M)
        self.hM0 = unidades.MolarEnthalpy(self.h0*self.M)
        self.uM0 = unidades.MolarEnthalpy(self.u0*self.M)
        self.sM0 = unidades.MolarSpecificHeat(self.s0*self.M)
        self.aM0 = unidades.MolarEnthalpy(self.a0*self.M)
        self.gM0 = unidades.MolarEnthalpy(self.g0*self.M)
        self.cpM0 = unidades.MolarSpecificHeat(self.cp0*self.M)
        self.cvM0 = unidades.MolarSpecificHeat(self.cv0*self.M)
Exemple #3
0
 def readStatefromJSON(self, fluid):
     ThermoAdvanced.readStatefromJSON(self, fluid)
     if fluid:
         self.virialD = unidades.Dimensionless(fluid["virialD"])
         self.virialBa = unidades.SpecificVolume(fluid["virialBa"])
         self.virialCa = unidades.SpecificVolume_square(fluid["virialCa"])
         self.dCdt = unidades.Dimensionless(fluid["dCdt"])
         self.dCdt2 = unidades.Dimensionless(fluid["dCdt2"])
         self.dBdt = unidades.Dimensionless(fluid["dBdt"])
Exemple #4
0
    def fill(self, fase, estado):
        fase._bool = True
        fase.M = self.M
        fase.rho = unidades.Density(estado.rho)
        fase.v = unidades.SpecificVolume(estado.v)
        fase.Z = unidades.Dimensionless(self.P * estado.v / R / 1000 * self.M /
                                        self.T)

        fase.h = unidades.Enthalpy(estado.h)
        fase.s = unidades.SpecificHeat(estado.s)
        fase.u = unidades.Enthalpy(estado.u)
        fase.a = unidades.Enthalpy(fase.u - self.T * fase.s)
        fase.g = unidades.Enthalpy(fase.h - self.T * fase.s)
        fi = exp((fase.g - self.g0) / 1000 / R * self.M / self.T)
        fase.fi = [unidades.Pressure(fi)]
        fase.f = [unidades.Pressure(self.P * f) for f in fase.fi]

        fase.cv = unidades.SpecificHeat(estado.cv)
        fase.cp = unidades.SpecificHeat(estado.cp)
        fase.cp_cv = unidades.Dimensionless(fase.cp / fase.cv)
        fase.gamma = fase.cp_cv
        fase.w = unidades.Speed(estado.w)

        fase.rhoM = unidades.MolarDensity(fase.rho / self.M)
        fase.hM = unidades.MolarEnthalpy(fase.h * self.M)
        fase.sM = unidades.MolarSpecificHeat(fase.s * self.M)
        fase.uM = unidades.MolarEnthalpy(fase.u * self.M)
        fase.aM = unidades.MolarEnthalpy(fase.a * self.M)
        fase.gM = unidades.MolarEnthalpy(fase.g * self.M)
        fase.cvM = unidades.MolarSpecificHeat(fase.cv * self.M)
        fase.cpM = unidades.MolarSpecificHeat(fase.cp * self.M)

        fase.mu = unidades.Viscosity(estado.mu)
        fase.nu = unidades.Diffusivity(fase.mu / fase.rho)
        fase.k = unidades.ThermalConductivity(estado.k)
        fase.alfa = unidades.Diffusivity(fase.k / fase.rho / fase.cp)
        fase.epsilon = unidades.Dimensionless(
            iapws._Dielectric(estado.rho, self.T))
        fase.Prandt = unidades.Dimensionless(estado.mu * estado.cp / estado.k)
        fase.n = unidades.Dimensionless(
            iapws._Refractive(fase.rho, self.T, self.kwargs["l"]))

        fase.alfav = unidades.InvTemperature(estado.deriv("Tpv") / fase.v)
        fase.kappa = unidades.InvPressure(-estado.deriv("pTv") / fase.v)
        fase.kappas = unidades.InvPressure(
            -1 / fase.v * self.derivative("v", "P", "s", fase))

        fase.joule = unidades.TemperaturePressure(estado.deriv("Tph"))
        fase.deltat = unidades.EnthalpyPressure(estado.deriv("pTh"))

        fase.alfap = unidades.Density(fase.alfav / self.P / fase.kappa)
        fase.betap = unidades.Density(-1 / self.P * estado.deriv("vTp"))
        fase.fraccion = [1]
        fase.fraccion_masica = [1]
Exemple #5
0
    def fill(self, fase, estado):
        fase.M = self.M
        fase.rho = unidades.Density(estado.rho)
        fase.v = unidades.SpecificVolume(estado.v)
        fase.Z = unidades.Dimensionless(self.P*estado.v/R/1000*self.M/self.T)

        fase.h = unidades.Enthalpy(estado.h)
        fase.s = unidades.SpecificHeat(estado.s)
        fase.u = unidades.Enthalpy(estado.u)
        fase.a = unidades.Enthalpy(fase.u-self.T*fase.s)
        fase.g = unidades.Enthalpy(fase.h-self.T*fase.s)

        fase.cv = unidades.SpecificHeat(estado.cv)
        fase.cp = unidades.SpecificHeat(estado.cp)
        fase.cp_cv = unidades.Dimensionless(fase.cp/fase.cv)
        fase.w = unidades.Speed(estado.w)

        fase.mu = unidades.Viscosity(estado.mu)
        fase.k = unidades.ThermalConductivity(estado.k)
        fase.nu = unidades.Diffusivity(fase.mu/fase.rho)
        fase.dielec = unidades.Dimensionless(iapws._Dielectric(estado.rho, self.T))
        fase.Prandt = unidades.Dimensionless(estado.mu*estado.cp/estado.k)

#            fase.joule=unidades.TemperaturePressure(self.Liquido["hjt"], "KkPa")
#        fase.xkappa=unidades.InvPressure(DerivTerms("IsothermalCompressibility", self.T, fase.rho, self.name), "kPa")
#        fase.alfav=unidades.InvTemperature(-estado.PFC.drhodT_constp()/estado.rho)

        cp0 = iapws.prop0(self.T, self.P)
        fase.v0 = unidades.SpecificVolume(cp0.v)
        fase.h0 = unidades.Enthalpy(cp0.h)
        fase.u0 = unidades.Enthalpy(fase.h0-self.P*1000*fase.v0)
        fase.s0 = unidades.SpecificHeat(cp0.s)
        fase.a0 = unidades.Enthalpy(fase.u0-self.T*fase.s0)
        fase.g0 = unidades.Enthalpy(fase.h0-self.T*fase.s0)
        fase.cp0 = unidades.SpecificHeat(cp0.cp)
        fase.cv0 = unidades.SpecificHeat(cp0.cv)
        fase.cp0_cv = unidades.Dimensionless(fase.cp0/fase.cv0)
        fase.w0 = cp0.w
#        fase.gamma0 = cp0.gamma
        fase.f = unidades.Pressure(self.P*exp((fase.g-fase.g0)/R/self.T))
Exemple #6
0
    def fill(self, fase, st):
        """Fill phase properties"""
        fase._bool = True
        fase.M = self.M
        fase.v = unidades.SpecificVolume(st.v)
        fase.rho = unidades.Density(st.rho)
        fase.Z = unidades.Dimensionless(st.Z)

        fase.h = unidades.Enthalpy(st.h, "kJkg")
        fase.s = unidades.SpecificHeat(st.s, "kJkgK")
        fase.u = unidades.Enthalpy(st.u, "kJkg")
        fase.a = unidades.Enthalpy(st.a, "kJkg")
        fase.g = unidades.Enthalpy(st.g, "kJkg")
        fase.fi = [unidades.Dimensionless(st.fi)]
        fase.f = [unidades.Pressure(st.f, "MPa")]

        fase.cv = unidades.SpecificHeat(st.cv, "kJkgK")
        fase.cp = unidades.SpecificHeat(st.cp, "kJkgK")
        fase.cp_cv = unidades.Dimensionless(st.cp_cv)
        fase.gamma = fase.cp_cv
        fase.w = unidades.Speed(st.w)

        fase.rhoM = unidades.MolarDensity(fase.rho / self.M)
        fase.hM = unidades.MolarEnthalpy(fase.h * self.M)
        fase.sM = unidades.MolarSpecificHeat(fase.s * self.M)
        fase.uM = unidades.MolarEnthalpy(fase.u * self.M)
        fase.aM = unidades.MolarEnthalpy(fase.a * self.M)
        fase.gM = unidades.MolarEnthalpy(fase.g * self.M)
        fase.cvM = unidades.MolarSpecificHeat(fase.cv * self.M)
        fase.cpM = unidades.MolarSpecificHeat(fase.cp * self.M)

        fase.alfav = unidades.InvTemperature(st.alfav)
        fase.kappa = unidades.InvPressure(st.xkappa, "MPa")
        fase.kappas = unidades.InvPressure(st.kappas, "MPa")

        fase.mu = unidades.Viscosity(st.mu)
        fase.nu = unidades.Diffusivity(st.nu)
        fase.k = unidades.ThermalConductivity(st.k)
        fase.alfa = unidades.Diffusivity(st.alfa)
        fase.epsilon = unidades.Dimensionless(st.epsilon)
        fase.Prandt = unidades.Dimensionless(st.Prandt)
        fase.n = unidades.Dimensionless(st.n)

        fase.joule = unidades.TemperaturePressure(st.joule)
        fase.deltat = unidades.EnthalpyPressure(st.deltat)

        fase.betap = unidades.Density(st.betap)
        fase.alfap = unidades.Density(st.alfap)
        fase.fraccion = [1]
        fase.fraccion_masica = [1]
Exemple #7
0
    def calculo(self):
        func = [freesteam.steam_pT, freesteam.steam_ph, freesteam.steam_ps,
                freesteam.steam_pv, freesteam.steam_Ts, freesteam.steam_Tx][self._thermo]
        fluido = func(self.var1, self.var2)

        self.M = unidades.Dimensionless(mEoS.H2O.M)
        self.Pc = unidades.Pressure(freesteam.PCRIT)
        self.Tc = unidades.Temperature(freesteam.TCRIT)
        self.rhoc = unidades.Density(freesteam.RHOCRIT*self.M)
        self.Tt = mEoS.H2O.Tt
        self.Tb = mEoS.H2O.Tb
        self.f_accent = unidades.Dimensionless(mEoS.H2O.f_acent)
        self.momentoDipolar = mEoS.H2O.momentoDipolar

        self.phase = self.getphase(fluido)
        self.x = unidades.Dimensionless(fluido.x)
        self.name = mEoS.H2O.name
        self.synonim = mEoS.H2O.synonym
        self.CAS = mEoS.H2O.CASNumber

        self.T = unidades.Temperature(fluido.T)
        self.P = unidades.Pressure(fluido.p)
        self.rho = unidades.Density(fluido.rho)
        self.v = unidades.SpecificVolume(1./self.rho)

        self.Liquido = Fluid()
        self.Gas = Fluid()
        if self.x < 1:
            # Liquid phase
            liquido = freesteam.steam_Tx(fluido.T, 0.)
            self.fill(self.Liquido, liquido)
            self.Liquido.epsilon = unidades.Tension(iapws._Tension(self.T))
        if self.x > 0:
            vapor = freesteam.steam_Tx(fluido.T, 1.)
            self.fill(self.Gas, vapor)

        if self.x in (0, 1):
            self.fill(self, fluido)
        else:
            self.h = unidades.Enthalpy(self.x*self.Vapor.h+(1-self.x)*self.Liquido.h)
            self.s = unidades.SpecificHeat(self.x*self.Vapor.s+(1-self.x)*self.Liquido.s)
            self.u = unidades.SpecificHeat(self.x*self.Vapor.u+(1-self.x)*self.Liquido.u)
            self.a = unidades.Enthalpy(self.x*self.Vapor.a+(1-self.x)*self.Liquido.a)
            self.g = unidades.Enthalpy(self.x*self.Vapor.g+(1-self.x)*self.Liquido.g)

            self.cv = unidades.SpecificHeat(None)
            self.cp = unidades.SpecificHeat(None)
            self.cp_cv = unidades.Dimensionless(None)
            self.w = unidades.Speed(None)
Exemple #8
0
 def calculo(self):
     tdp, tdb, twb, P, Pvs, Pv, ws, w, HR, v, h = self._lib()
     self.tdp = unidades.Temperature(tdp)
     self.tdb = unidades.Temperature(tdb)
     self.twb = unidades.Temperature(twb)
     self.P = unidades.Pressure(P)
     self.Pvs = unidades.Pressure(Pvs)
     self.Pv = unidades.Pressure(Pv)
     self.ws = unidades.Dimensionless(ws, txt="kgw/kgda")
     self.w = unidades.Dimensionless(w, txt="kgw/kgda")
     self.HR = unidades.Dimensionless(HR, txt="%")
     self.mu = unidades.Dimensionless(w/ws*100)
     self.v = unidades.SpecificVolume(v)
     self.rho = unidades.Density(1/v)
     self.h = unidades.Enthalpy(h, "kJkg")
     self.Xa = 1/(1+self.w/0.62198)
     self.Xw = 1-self.Xa
Exemple #9
0
def _v(P, Tdb, W):
    """
    Calculate the specific volume of a humid air as a perfect gas, v, as
    explain in [1]_, pag 1.8, Eq 28

    Parameters
    ------------
    P : float
        Pressure, [Pa]
    Tdb: float
       Dry bulb temperature, [K]
    W : float
       Humidity ratio, [kgw/kgda]

    Returns
    -------
    v : float
       Specific volume, [m³/kgda]
    """
    # Pressure in kPa
    P_kpa = P/1000
    v = 0.287042*Tdb*(1+1.607858*W)/P_kpa
    return unidades.SpecificVolume(v)
Exemple #10
0
    def _cp0(self):
        "Set ideal properties to state" ""
        self.v0 = unidades.SpecificVolume(None)
        self.rho0 = unidades.Density(None)
        self.h0 = unidades.Enthalpy(None)
        self.u0 = unidades.Enthalpy(None)
        self.s0 = unidades.SpecificHeat(None)
        self.a0 = unidades.Enthalpy(None)
        self.g0 = unidades.Enthalpy(None)

        self.cp0 = unidades.SpecificHeat(None)
        self.cv0 = unidades.SpecificHeat(None)
        self.cp0_cv = unidades.Dimensionless(None)
        self.w0 = unidades.Speed(None)
        self.gamma0 = self.cp0_cv

        self.rhoM0 = unidades.MolarDensity(None)
        self.hM0 = unidades.MolarEnthalpy(None)
        self.uM0 = unidades.MolarEnthalpy(None)
        self.sM0 = unidades.MolarSpecificHeat(None)
        self.aM0 = unidades.MolarEnthalpy(None)
        self.gM0 = unidades.MolarEnthalpy(None)
        self.cpM0 = unidades.MolarSpecificHeat(None)
        self.cvM0 = unidades.MolarSpecificHeat(None)
Exemple #11
0
 def readStatefromJSON(self, fluid):
     Thermo.readStatefromJSON(self, fluid)
     if fluid:
         self.betas = unidades.TemperaturePressure(fluid["betas"])
         self.Gruneisen = unidades.Dimensionless(fluid["Gruneisen"])
         self.virialB = unidades.SpecificVolume(fluid["virialB"])
         self.virialC = unidades.SpecificVolume_square(fluid["virialC"])
         self.dpdT_rho = unidades.PressureTemperature(fluid["dpdT_rho"])
         self.dpdrho_T = unidades.PressureDensity(fluid["dpdrho_T"])
         self.drhodT_P = unidades.DensityTemperature(fluid["drhodT_P"])
         self.drhodP_T = unidades.DensityPressure(fluid["drhodP_T"])
         self.dhdT_rho = unidades.SpecificHeat(fluid["dhdT_rho"])
         self.dhdP_T = unidades.EnthalpyPressure(fluid["dhdP_T"])
         self.dhdT_P = unidades.SpecificHeat(fluid["dhdT_P"])
         self.dhdrho_T = unidades.EnthalpyDensity(fluid["dhdrho_T"])
         self.dhdP_rho = unidades.EnthalpyPressure(fluid["dhdP_rho"])
         self.kt = unidades.Dimensionless(fluid["kt"])
         self.ks = unidades.InvPressure(fluid["ks"])
         self.Ks = unidades.Pressure(fluid["Ks"])
         self.Kt = unidades.Pressure(fluid["Kt"])
         self.IntP = unidades.Pressure(fluid["IntP"])
         self.invT = unidades.InvTemperature(fluid["invT"])
         self.hInput = unidades.Enthalpy(fluid["hInput"])
         self.epsilon = unidades.Dimensionless(fluid["epsilon"])
Exemple #12
0
    def _cp0(self, cp0):
        "Set ideal properties to state" ""
        self.v0 = unidades.SpecificVolume(cp0["v"])
        self.rho0 = unidades.Density(1. / cp0["v"])
        self.h0 = unidades.Enthalpy(cp0["h"])
        self.u0 = unidades.Enthalpy(self.h0 - self.P * self.v0)
        self.s0 = unidades.SpecificHeat(cp0["s"])
        self.a0 = unidades.Enthalpy(self.u0 - self.T * self.s0)
        self.g0 = unidades.Enthalpy(self.h0 - self.T * self.s0)

        self.cp0 = unidades.SpecificHeat(cp0["cp"])
        self.cv0 = unidades.SpecificHeat(cp0["cv"])
        self.cp0_cv = unidades.Dimensionless(self.cp0 / self.cv0)
        self.w0 = unidades.Speed(cp0["w"])
        self.gamma0 = self.cp0_cv

        self.rhoM0 = unidades.MolarDensity(self.rho0 / self.M)
        self.hM0 = unidades.MolarEnthalpy(self.h0 * self.M)
        self.uM0 = unidades.MolarEnthalpy(self.u0 * self.M)
        self.sM0 = unidades.MolarSpecificHeat(self.s0 * self.M)
        self.aM0 = unidades.MolarEnthalpy(self.a0 * self.M)
        self.gM0 = unidades.MolarEnthalpy(self.g0 * self.M)
        self.cpM0 = unidades.MolarSpecificHeat(self.cp0 * self.M)
        self.cvM0 = unidades.MolarSpecificHeat(self.cv0 * self.M)
Exemple #13
0
    def calculo(self):
        T = self.kwargs["T"]
        rho = self.kwargs["rho"]
        P = self.kwargs["P"]
        v = self.kwargs["v"]
        h = self.kwargs["h"]
        s = self.kwargs["s"]
        u = self.kwargs["u"]
        x = self.kwargs["x"]

        self.comp = []
        for i in self.kwargs["componente"]:
            c = self.componentes[i](eq="GERG", **self.kwargs)
            self.comp.append(c)
        self.id = self.kwargs["componente"]
        self.xi = self.kwargs["fraccion"]

        # Critic properties for mixture,
        # eq. 7.9, 7.10 pag.125, Tabla 7.10 pag 136
        bt = self.Prop_c["beta_t"]
        bv = self.Prop_c["beta_v"]
        gt = self.Prop_c["gamma_t"]
        gv = self.Prop_c["gamma_v"]
        c_T = zeros((len(self.comp), len(self.comp)))
        c_rho = zeros((len(self.comp), len(self.comp)))
        for i, cmpi in enumerate(self.comp):
            for j, cmpj in enumerate(self.comp):
                c_T[i, j] = 2*bt[i][j]*gt[i][j]*(cmpi.Tc*cmpj.Tc)**0.5
                c_rho[i, j] = 2*bv[i][j]*gv[i][j]/8. * \
                    (1./cmpi.rhoc**(1./3)+1./cmpj.rhoc**(1./3))**3

        f_T = zeros((len(self.comp), len(self.comp)))
        f_rho = zeros((len(self.comp), len(self.comp)))
        dFT_ik = zeros((len(self.comp), len(self.comp)))
        dFT_ki = zeros((len(self.comp), len(self.comp)))
        dFrho_ik = zeros((len(self.comp), len(self.comp)))
        dFrho_ki = zeros((len(self.comp), len(self.comp)))
        for i, x_i in enumerate(self.xi):
            for j, x_j in enumerate(self.xi):
                f_T[i, j] = x_i*x_j*(x_i+x_j)/(bt[i][j]**2*x_i+x_j)
                f_rho[i, j] = x_i*x_j*(x_i+x_j)/(bv[i][j]**2*x_i+x_j)
                dFT_ik[i, j] = x_j*(x_j+x_i)/(bt[i][j]**2*x_i+x_j) + \
                    x_j*x_i/(bt[i][j]**2*x_i+x_j) * \
                    (1-bt[i][j]**2*(x_j+x_i)/(bt[i][j]**2*x_i+x_j))
                dFrho_ik[i, j] = x_j*(x_j+x_i)/(bv[i][j]**2*x_i+x_j) + \
                    x_j*x_i/(bv[i][j]**2*x_i+x_j) * \
                    (1-bv[i][j]**2*(x_j+x_i)/(bv[i][j]**2*x_i+x_j))
                dFT_ki[j, i] = x_j*(x_j+x_i)/(bt[i][j]**2*x_j+x_i)+x_j*x_i / \
                    (bt[i][j]**2*x_j+x_i)*(1-(x_j+x_i)/(bt[i][j]**2*x_j+x_i))
                dFrho_ki[j, i] = x_j*(x_j+x_i)/(bv[i][j]**2*x_j+x_i)+x_j*x_i /\
                    (bv[i][j]**2*x_j+x_i)*(1-(x_j+x_i)/(bv[i][j]**2*x_j+x_i))

        sumai_v = sumaij_v = sumai_T = sumaij_T = m = 0
        for i, componentei in enumerate(self.comp):
            sumai_v += self.xi[i]**2/componentei.rhoc
            sumai_T += self.xi[i]**2*componentei.Tc
            m += self.xi[i]*componentei.M
            for j, componentej in enumerate(self.comp):
                if j > i:
                    sumaij_v += c_rho[i, j]*f_rho[i, j]
                    sumaij_T += c_T[i, j]*f_T[i, j]

        self.rhoc = unidades.Density(1./(sumai_v+sumaij_v))
        self.Tc = unidades.Temperature(sumai_T+sumaij_T)
        self.M = m  # g/mol
        self.R = unidades.SpecificHeat(R/self.M, "kJkgK")

        Tcxi = rhocxi = []
        for i, componentei in enumerate(self.comp):
            sumav1 = sumat1 = 0
            for k in range(i):
                sumav1 += c_rho[k, i]*dFrho_ki[k, i]
                sumat1 += c_T[k, i]*dFT_ki[k, i]
            sumav2 = sumat2 = 0
            for k in range(i+1, len(self.xi)):
                sumav2 += c_rho[i, k]*dFrho_ik[i, k]
                sumat2 += c_T[i, k]*dFT_ik[i, k]

            Tcxi.append(2*self.xi[i]*componentei.Tc+sumat1+sumat2)
            rhocxi.append(2*self.xi[i]/componentei.rhoc+sumav1+sumav2)
        self.Tcxi = Tcxi
        self.rhocxi = rhocxi

        if v and not rho:
            rho = 1./v

        if T and x is not None:
            pass
        else:
            if T and P:
                rhoo = 2.
                rho = fsolve(lambda rho: self._solve(rho, T)["P"]-P*1e6, rhoo)
            elif T and rho:
                pass
            elif T and h is not None:
                rho = fsolve(lambda rho: self._solve(rho, T)["h"]-h, 200)
            elif T and s is not None:
                rho = fsolve(lambda rho: self._solve(rho, T)["s"]-s, 200)
            elif T and u is not None:
                rho = fsolve(lambda rho: self._solve(rho, T)["u"]-u, 200)
            elif P and rho:
                T = fsolve(lambda T: self._solve(rho, T)["P"]-P*1e6, 600)
            elif P and h is not None:
                rho, T = fsolve(lambda par: (
                    self._solve(par[0], par[1])["P"]-P*1e6, self._solve(
                        par[0], par[1])["h"]-h), [200, 600])
            elif P and s is not None:
                rho, T = fsolve(lambda par: (
                    self._solve(par[0], par[1])["P"]-P*1e6, self._solve(
                        par[0], par[1])["s"]-s), [200, 600])
            elif P and u is not None:
                rho, T = fsolve(lambda par: (
                    self._solve(par[0], par[1])["P"]-P*1e6, self._solve(
                        par[0], par[1])["u"]-u), [200, 600])
            elif rho and h is not None:
                T = fsolve(lambda T: self._solve(rho, T)["h"]-h, 600)
            elif rho and s is not None:
                T = fsolve(lambda T: self._solve(rho, T)["s"]-s, 600)
            elif rho and u is not None:
                T = fsolve(lambda T: self._solve(rho, T)["u"]-u, 600)
            elif h is not None and s is not None:
                rho, T = fsolve(lambda par: (
                    self._solve(par[0], par[1])["h"]-h, self._solve(
                        par[0], par[1])["s"]-s), [200, 600])
            elif h is not None and u is not None:
                rho, T = fsolve(lambda par: (
                    self._solve(par[0], par[1])["h"]-h, self._solve(
                        par[0], par[1])["u"]-u), [200, 600])
            elif s is not None and u is not None:
                rho, T = fsolve(lambda par: (
                    self._solve(par[0], par[1])["s"]-s, self._solve(
                        par[0], par[1])["u"]-u), [200, 600])
            else:
                raise IOError

        fio, fiot, fiott, fiod, fiodd, fiodt, fir, firt, firtt, fird, firdd,\
            firdt, firdtt, nfioni, nfirni = self._eq(rho, T)

        # Tabla 7.1 pag 127
        tau = self.Tc/T
        delta = rho/self.rhoc

        self.T = unidades.Temperature(T)
        self.rho = unidades.Density(rho)
        self.v = unidades.SpecificVolume(1./rho)
        self.P = unidades.Pressure((1+delta*fird)*self.R.JkgK*T*rho)
        self.Z = 1+delta*fird
        self.s = unidades.SpecificHeat(self.R.kJkgK*(tau*(fiot+firt)-fio-fir))
        self.u = unidades.Enthalpy(self.R*T*tau*(fiot+firt))
        self.h = unidades.Enthalpy(self.R*T*(1+tau*(fiot+firt)+delta*fird))
        self.cp = unidades.SpecificHeat(self.R*(
            -tau**2*(fiott+firtt)+(1+delta*fird-delta*tau*firdt)**2 /
            (1+2*delta*fird+delta**2*firdd)))
        self.cv = unidades.SpecificHeat(-self.R*tau**2*(fiott+firtt))
        self.g = unidades.Enthalpy(self.R*T*(1+fio+fir+delta*fird))
        self.w = unidades.Speed((self.R*T*(
            1+2*delta*fird+delta**2*firdd-(1+delta*fird-delta*tau*firdt)**2 /
            tau**2/(fiott+firtt)))**0.5)

        f, FI = self.fug(rho, T, nfirni)
        Ki, xi, yi, Q = self.flash()
        self.x = unidades.Dimensionless(Q)
        self.xl = xi
        self.xv = yi
        if self.kwargs["mezcla"]:
            self.Pc = self.kwargs["mezcla"].Pc
        self.Liquido = ThermoAdvanced()
        self.Gas = ThermoAdvanced()
Exemple #14
0
    def calculo(self):
        refprop.setup(self.kwargs["ref"], self.kwargs["fluido"])

        m = refprop.wmol(self.kwargs["fraccionMolar"])["wmix"]
        self.M = unidades.Dimensionless(m)
        crit = refprop.critp(self.kwargs["fraccionMolar"])
        self.Pc = unidades.Pressure(crit["pcrit"], "kPa")
        self.Tc = unidades.Temperature(crit["tcrit"])
        self.rhoc = unidades.Density(crit["Dcrit"] * self.M)

        args = self.args()
        flash = refprop.flsh(*args)
        self.phase, self.x = self.getphase(flash)
        self.T = unidades.Temperature(flash["t"])
        self.P = unidades.Pressure(flash["p"], "kPa")
        self.rho = unidades.Density(flash["D"] * self.M)
        self.v = unidades.SpecificVolume(1. / self.rho)
        name = refprop.name(flash["nc"])
        info = refprop.info(flash["nc"])
        if flash["nc"] == 1:
            self.name = name["hname"]
            self.synonim = name["hn80"]
            self.CAS = name["hcas"]

            self.Tt = unidades.Temperature(info["ttrp"])
            self.Tb = unidades.Temperature(info["tnbpt"])
            self.f_accent = unidades.Dimensionless(info["acf"])
            self.momentoDipolar = unidades.DipoleMoment(info["dip"], "Debye")

        self.Liquido = Fluid()
        self.Vapor = Fluid()
        if self.x < 1.:  # Hay fase liquida
            liquido_thermo = refprop.therm2(flash["t"], flash["Dliq"],
                                            flash["xliq"])
            liquido_mol = refprop.wmol(flash["xliq"])
            try:
                liquido_transport = refprop.trnprp(flash["t"], flash["Dliq"],
                                                   flash["xliq"])
            except refprop.RefpropError as e:
                print e
                liquido_transport = None
            liquido_dielec = refprop.dielec(flash["t"], flash["Dliq"],
                                            flash["xliq"])
            liquido_thermo0 = refprop.therm0(flash["t"], flash["Dliq"],
                                             flash["xliq"])
            self.fill(self.Liquido, flash, liquido_thermo, liquido_mol,
                      liquido_transport, liquido_dielec, liquido_thermo0)

        if self.x > 0.:  # Hay fase vapor
            vapor_thermo = refprop.therm2(flash["t"], flash["Dvap"],
                                          flash["xvap"])
            vapor_mol = refprop.wmol(flash["xvap"])
            try:
                vapor_transport = refprop.trnprp(flash["t"], flash["Dvap"],
                                                 flash["xvap"])
            except refprop.RefpropError as e:
                print e
                vapor_transport = None
            vapor_dielec = refprop.dielec(flash["t"], flash["Dvap"],
                                          flash["xvap"])
            vapor_thermo0 = refprop.therm0(flash["t"], flash["Dvap"],
                                           flash["xvap"])
            self.fill(self.Vapor, flash, vapor_thermo, vapor_mol,
                      vapor_transport, vapor_dielec, vapor_thermo0)

#        crit = multiRP.mRP[u'process'](target=multiRP.critp, args=(self.kwargs["fraccionMolar"], setup, multiRP.mRP))
#        mol = multiRP.mRP[u'process'](target=multiRP.wmol, args=(self.kwargs["fraccionMolar"], setup, multiRP.mRP))
#        processlist = [crit, mol]
#        multiRP.run_mRP(processlist)
#        self.Pc=unidades.Pressure(multiRP.mRP[u'result'][processlist[0].name]["pcrit"], "kPa")
#        self.Tc=unidades.Temperature(multiRP.mRP[u'result'][processlist[0].name]["tcrit"])
#        self.rhoc=unidades.Density(multiRP.mRP[u'result'][processlist[0].name]["Dcrit"]*self.M)

#        args=self.args()
#        flash = multiRP.mRP[u'process'](target=multiRP.flsh, args=args, kwargs={u'prop': setup, u'mRP': multiRP.mRP})
#        name = multiRP.mRP[u'process'](target=multiRP.name, args=(1, setup, multiRP.mRP))
#        info = multiRP.mRP[u'process'](target=multiRP.info, args=(1, setup, multiRP.mRP))
#        processlist = [flash, name, info]
#        multiRP.run_mRP(processlist)
#        flash=multiRP.mRP[u'result'][processlist[0].name]
#        self.phase, self.x=self.getphase(flash)
#        self.nc=flash["nc"]
#        self.fraccion=self.kwargs["fraccionMolar"]
#        if flash["nc"] ==1:
#            self.name=multiRP.mRP[u'result'][processlist[1].name]["hname"]
#            self.synonim=multiRP.mRP[u'result'][processlist[1].name]["hn80"]
#            self.CAS=multiRP.mRP[u'result'][processlist[1].name]["hcas"]
#
#            self.Tt=unidades.Temperature(multiRP.mRP[u'result'][processlist[2].name]["ttrp"])
#            self.Tb=unidades.Temperature(multiRP.mRP[u'result'][processlist[2].name]["tnbpt"])
#            self.f_accent=unidades.Dimensionless(multiRP.mRP[u'result'][processlist[2].name]["acf"])
#            self.momentoDipolar=unidades.DipoleMoment(multiRP.mRP[u'result'][processlist[2].name]["dip"], "Debye")
#            self.Rgas=unidades.SpecificHeat(multiRP.mRP[u'result'][processlist[2].name]["Rgas"]/self.M)
#        else:
#            self.Rgas=unidades.SpecificHeat(refprop.rmix2(self.kwargs["fraccionMolar"])["Rgas"]/self.M)

#        self.T=unidades.Temperature(flash["t"])
#        self.P=unidades.Pressure(flash["p"], "kPa")
#        self.rho=unidades.Density(flash["D"]*self.M)
#        self.v=unidades.SpecificVolume(1./self.rho)

#        self.Liquido=Fluid()
#        self.Vapor=Fluid()
#        if self.x<1.: #Hay fase liquida
#            liquido_thermo = multiRP.mRP[u'process'](target=multiRP.therm2, args=(flash["t"], flash["Dliq"], flash["xliq"]), kwargs={u'prop': setup, u'mRP': multiRP.mRP})
#            liquido_mol = multiRP.mRP[u'process'](target=multiRP.wmol, args=(flash["xliq"], setup, multiRP.mRP))
#            liquido_transport = multiRP.mRP[u'process'](target=multiRP.trnprp, args=(flash["t"], flash["Dliq"], flash["xliq"]), kwargs={u'prop': setup, u'mRP': multiRP.mRP})
#            liquido_dielec = multiRP.mRP[u'process'](target=multiRP.dielec, args=(flash["t"], flash["Dliq"], flash["xliq"]), kwargs={u'prop': setup, u'mRP': multiRP.mRP})
#            liquido_thermo0 = multiRP.mRP[u'process'](target=multiRP.therm0, args=(flash["t"], flash["Dliq"], flash["xliq"]), kwargs={u'prop': setup, u'mRP': multiRP.mRP})
#            processlist = [liquido_thermo, liquido_mol, liquido_transport, liquido_dielec, liquido_thermo0]
#            try:
#                multiRP.run_mRP(processlist)
#                transport=multiRP.mRP[u'result'][processlist[2].name]
#            except refprop.RefpropError as e:
#                print e
#                transport=None
#            self.fill(self.Liquido, flash, multiRP.mRP[u'result'][processlist[0].name], multiRP.mRP[u'result'][processlist[1].name],
#                transport, multiRP.mRP[u'result'][processlist[3].name], multiRP.mRP[u'result'][processlist[4].name])

#        if self.x>0.: #Hay fase vapor
#            vapor_thermo = multiRP.mRP[u'process'](target=multiRP.therm2, args=(flash["t"], flash["Dvap"], flash["xvap"]), kwargs={u'prop': setup, u'mRP': multiRP.mRP})
#            vapor_mol = multiRP.mRP[u'process'](target=multiRP.wmol, args=(flash["xvap"], setup, multiRP.mRP))
#            vapor_transport = multiRP.mRP[u'process'](target=multiRP.trnprp, args=(flash["t"], flash["Dvap"], flash["xvap"]), kwargs={u'prop': setup, u'mRP': multiRP.mRP})
#            vapor_dielec = multiRP.mRP[u'process'](target=multiRP.dielec, args=(flash["t"], flash["Dvap"], flash["xvap"]), kwargs={u'prop': setup, u'mRP': multiRP.mRP})
#            vapor_thermo0 = multiRP.mRP[u'process'](target=multiRP.therm0, args=(flash["t"], flash["Dvap"], flash["xvap"]), kwargs={u'prop': setup, u'mRP': multiRP.mRP})
#            processlist = [vapor_thermo, vapor_mol, vapor_transport, vapor_dielec, vapor_thermo0]
#            try:
#                multiRP.run_mRP(processlist)
#                transport=multiRP.mRP[u'result'][processlist[2].name]
#            except refprop.RefpropError as e:
#                print e
#                transport=None
#
#            self.fill(self.Vapor, flash, multiRP.mRP[u'result'][processlist[0].name], multiRP.mRP[u'result'][processlist[1].name],
#                transport, multiRP.mRP[u'result'][processlist[3].name], multiRP.mRP[u'result'][processlist[4].name])

        self.h = unidades.Enthalpy(self.x * self.Vapor.h +
                                   (1 - self.x) * self.Liquido.h)
        self.s = unidades.SpecificHeat(self.x * self.Vapor.s +
                                       (1 - self.x) * self.Liquido.s)
        self.cp = unidades.SpecificHeat(self.x * self.Vapor.cp +
                                        (1 - self.x) * self.Liquido.cp)
        self.cp0 = unidades.SpecificHeat(self.x * self.Vapor.cp0 +
                                         (1 - self.x) * self.Liquido.cp0)
        self.cv = unidades.SpecificHeat(self.x * self.Vapor.cv +
                                        (1 - self.x) * self.Liquido.cv)

        self.cp_cv = unidades.Dimensionless(self.cp / self.cv)
        self.cp0_cv = unidades.Dimensionless(self.cp0 / self.cv)

        if self.T <= self.Tc:
            surten = refprop.surten(flash["t"], flash["Dliq"], flash["Dvap"],
                                    flash["xliq"], flash["xvap"])
            self.surten = unidades.Tension(surten["sigma"])
        else:
            self.surten = unidades.Tension(None)
Exemple #15
0
    def plot(self):
        """Plot chart"""
        Preferences = ConfigParser()
        Preferences.read(config.conf_dir + "pychemqtrc")

        self.diagrama2D.axes2D.clear()
        self.diagrama2D.config()
        filename = config.conf_dir + "%s_%i.pkl" % (
            PsychroState().__class__.__name__, self.inputs.P.value)
        if os.path.isfile(filename):
            with open(filename, "r") as archivo:
                data = cPickle.load(archivo)
                self.status.setText(
                    QtGui.QApplication.translate("pychemqt",
                                                 "Loading cached data..."))
                QtGui.QApplication.processEvents()
        else:
            self.progressBar.setVisible(True)
            self.status.setText(
                QtGui.QApplication.translate(
                    "pychemqt", "Calculating data, be patient..."))
            QtGui.QApplication.processEvents()
            data = PsychroState.calculatePlot(self)
            cPickle.dump(data, open(filename, "w"))
            self.progressBar.setVisible(False)
        self.status.setText(
            QtGui.QApplication.translate("pychemqt", "Plotting..."))
        QtGui.QApplication.processEvents()

        tmax = unidades.Temperature(Preferences.getfloat(
            "Psychr", "isotdbEnd"))

        t = [unidades.Temperature(ti).config() for ti in data["t"]]
        Hs = data["Hs"]
        format = {}
        format["ls"] = Preferences.get("Psychr", "saturationlineStyle")
        format["lw"] = Preferences.getfloat("Psychr", "saturationlineWidth")
        format["color"] = Preferences.get("Psychr", "saturationColor")
        format["marker"] = Preferences.get("Psychr", "saturationmarker")
        format["markersize"] = 3
        self.diagrama2D.plot(t, Hs, **format)

        format = {}
        format["ls"] = Preferences.get("Psychr", "isotdblineStyle")
        format["lw"] = Preferences.getfloat("Psychr", "isotdblineWidth")
        format["color"] = Preferences.get("Psychr", "isotdbColor")
        format["marker"] = Preferences.get("Psychr", "isotdbmarker")
        format["markersize"] = 3
        for i, T in enumerate(t):
            self.diagrama2D.plot([T, T], [0, Hs[i]], **format)

        H = data["H"]
        th = data["th"]
        format = {}
        format["ls"] = Preferences.get("Psychr", "isowlineStyle")
        format["lw"] = Preferences.getfloat("Psychr", "isowlineWidth")
        format["color"] = Preferences.get("Psychr", "isowColor")
        format["marker"] = Preferences.get("Psychr", "isowmarker")
        format["markersize"] = 3
        for i, H in enumerate(H):
            self.diagrama2D.plot([th[i], tmax.config()], [H, H], **format)

        format = {}
        format["ls"] = Preferences.get("Psychr", "isohrlineStyle")
        format["lw"] = Preferences.getfloat("Psychr", "isohrlineWidth")
        format["color"] = Preferences.get("Psychr", "isohrColor")
        format["marker"] = Preferences.get("Psychr", "isohrmarker")
        format["markersize"] = 3
        for Hr, H0 in data["Hr"].iteritems():
            self.diagrama2D.plot(t, H0, **format)
            self.drawlabel("isohr", Preferences, t, H0, Hr, "%")

        format = {}
        format["ls"] = Preferences.get("Psychr", "isotwblineStyle")
        format["lw"] = Preferences.getfloat("Psychr", "isotwblineWidth")
        format["color"] = Preferences.get("Psychr", "isotwbColor")
        format["marker"] = Preferences.get("Psychr", "isotwbmarker")
        format["markersize"] = 3
        for T, (H, Tw) in data["Twb"].iteritems():
            self.diagrama2D.plot(Tw, H, **format)
            value = unidades.Temperature(T).config()
            txt = unidades.Temperature.text()
            self.drawlabel("isotwb", Preferences, Tw, H, value, txt)

        format = {}
        format["ls"] = Preferences.get("Psychr", "isochorlineStyle")
        format["lw"] = Preferences.getfloat("Psychr", "isochorlineWidth")
        format["color"] = Preferences.get("Psychr", "isochorColor")
        format["marker"] = Preferences.get("Psychr", "isochormarker")
        format["markersize"] = 3
        for v, (Td, H) in data["v"].iteritems():
            self.diagrama2D.plot(Td, H, **format)
            value = unidades.SpecificVolume(v).config()
            txt = unidades.SpecificVolume.text()
            self.drawlabel("isochor", Preferences, Td, H, value, txt)

        self.diagrama2D.draw()
        self.status.setText(
            QtGui.QApplication.translate("pychemqt", "Using") + " " +
            PsychroState().__class__.__name__[3:])
Exemple #16
0
    def fill(self, fase, estado):
        fase._bool = True
        fase.M = unidades.Dimensionless(estado.molar_mass()*1000)
        fase.rho = unidades.Density(estado.rhomass())
        fase.v = unidades.SpecificVolume(1./fase.rho)
        fase.Z = unidades.Dimensionless(estado.keyed_output(CP.iZ))

        fase.h = unidades.Enthalpy(estado.hmass())
        fase.s = unidades.SpecificHeat(estado.smass())
        fase.u = unidades.Enthalpy(estado.umass())
        fase.a = unidades.Enthalpy(fase.u-self.T*fase.s)
        fase.g = unidades.Enthalpy(fase.h-self.T*fase.s)
        if self._multicomponent:
            fase.fi = []
            fase.f = []
            for i in range(len(self.kwargs["ids"])):
                fase.fi.append(unidades.Dimensionless(
                    estado.fugacity_coefficient(i)))
                fase.f.append(unidades.Pressure(estado.fugacity(i)))
        else:
            fase.fi = [unidades.Dimensionless(
                exp(estado.alphar()+estado.delta()*estado.dalphar_dDelta() -
                    log(1+estado.delta()*estado.dalphar_dDelta())))]
            fase.f = [unidades.Pressure(self.P*f) for f in fase.fi]

        fase.cv = unidades.SpecificHeat(estado.cvmass())
        fase.cp = unidades.SpecificHeat(estado.cpmass())
        fase.cp_cv = unidades.Dimensionless(fase.cp/fase.cv)
        fase.gamma = fase.cp_cv
        fase.w = unidades.Speed(estado.speed_sound())

        fase.rhoM = unidades.MolarDensity(estado.rhomolar(), "molm3")
        fase.hM = unidades.MolarEnthalpy(estado.hmolar(), "Jmol")
        fase.sM = unidades.MolarSpecificHeat(estado.smolar(), "JmolK")
        fase.uM = unidades.MolarEnthalpy(estado.umolar(), "Jmol")
        fase.aM = unidades.MolarEnthalpy(fase.a*self.M)
        fase.gM = unidades.MolarEnthalpy(fase.g*self.M)
        fase.cvM = unidades.MolarSpecificHeat(estado.cvmolar(), "JmolK")
        fase.cpM = unidades.MolarSpecificHeat(estado.cpmolar(), "JmolK")

        fase.joule = unidades.TemperaturePressure(
            estado.first_partial_deriv(CP.iT, CP.iP, CP.iHmass))
        fase.Gruneisen = unidades.Dimensionless(
            fase.v/fase.cv*estado.first_partial_deriv(CP.iP, CP.iT, CP.iDmass))
        fase.alfav = unidades.InvTemperature(
            estado.isobaric_expansion_coefficient())
        fase.kappa = unidades.InvPressure(estado.isothermal_compressibility())
        fase.kappas = unidades.InvPressure(
            -1/fase.v*self.derivative("v", "P", "s", fase))
        fase.alfap = unidades.Density(fase.alfav/self.P/fase.kappa)
        fase.betap = unidades.Density(
            -1/self.P*self.derivative("P", "v", "T", fase))
        fase.betas = unidades.TemperaturePressure(
            estado.first_partial_deriv(CP.iT, CP.iP, CP.iSmass))

        fase.kt = unidades.Dimensionless(
            fase.rho/self.P*estado.first_partial_deriv(
                CP.iP, CP.iDmass, CP.iT))
        fase.Ks = unidades.Pressure(
            fase.rho*estado.first_partial_deriv(CP.iP, CP.iDmass, CP.iSmass))
        fase.Kt = unidades.Pressure(
            fase.rho*estado.first_partial_deriv(CP.iP, CP.iDmass, CP.iT))
        fase.ks = unidades.Dimensionless(
            fase.rho/self.P*estado.first_partial_deriv(
                CP.iP, CP.iDmass, CP.iSmass))
        fase.dhdT_rho = unidades.SpecificHeat(
            estado.first_partial_deriv(CP.iHmass, CP.iT, CP.iDmass))
        fase.dhdT_P = unidades.SpecificHeat(
            estado.first_partial_deriv(CP.iHmass, CP.iT, CP.iP))
        fase.dhdP_T = unidades.EnthalpyPressure(
            estado.first_partial_deriv(CP.iHmass, CP.iP, CP.iT))  # deltat
        fase.deltat = fase.dhdP_T
        fase.dhdP_rho = unidades.EnthalpyPressure(
            estado.first_partial_deriv(CP.iHmass, CP.iP, CP.iDmass))
        fase.dhdrho_T = unidades.EnthalpyDensity(
            estado.first_partial_deriv(CP.iHmass, CP.iDmass, CP.iT))
        fase.dhdrho_P = unidades.EnthalpyDensity(
            estado.first_partial_deriv(CP.iHmass, CP.iDmass, CP.iP))
        fase.dpdT_rho = unidades.PressureTemperature(
            estado.first_partial_deriv(CP.iP, CP.iT, CP.iDmass))
        fase.dpdrho_T = unidades.PressureDensity(
            estado.first_partial_deriv(CP.iP, CP.iDmass, CP.iT))
        fase.drhodP_T = unidades.DensityPressure(
            estado.first_partial_deriv(CP.iDmass, CP.iP, CP.iT))
        fase.drhodT_P = unidades.DensityTemperature(
            estado.first_partial_deriv(CP.iDmass, CP.iT, CP.iP))

        fase.Z_rho = unidades.SpecificVolume((fase.Z-1)/fase.rho)
        fase.IntP = unidades.Pressure(
            self.T*estado.first_partial_deriv(CP.iP, CP.iT, CP.iDmass)-self.P)
        fase.hInput = unidades.Enthalpy(
            -fase.rho*estado.first_partial_deriv(CP.iHmass, CP.iDmass, CP.iP))

        fase.virialB = unidades.SpecificVolume(estado.Bvirial())
        fase.virialC = unidades.SpecificVolume_square(estado.Cvirial())
        fase.invT = unidades.InvTemperature(-1/self.T)

        fase.mu = unidades.Viscosity(estado.viscosity())
        fase.nu = unidades.Diffusivity(fase.mu/fase.rho)
        fase.k = unidades.ThermalConductivity(estado.conductivity())
        fase.alfa = unidades.Diffusivity(fase.k/fase.rho/fase.cp)
        fase.Prandt = unidades.Dimensionless(estado.Prandtl())
        fase.fraccion = estado.get_mole_fractions()
        fase.fraccion_masica = estado.get_mass_fractions()
        fase.epsilon = unidades.Dimensionless(None)
Exemple #17
0
    def calculo(self):
        fluido = self._name()
        args = self.args()
        estado = CP.AbstractState("HEOS", fluido)
        if self._multicomponent:
            estado.set_mole_fractions(self.kwargs["fraccionMolar"])
        estado.update(self._par, *args)

        self.M = unidades.Dimensionless(estado.molar_mass()*1000)

        if self._multicomponent:
            # Disabled CoolProp critical properties for multicomponent,
            # see issue #1087

            # Calculate critical properties with mezcla method
            # Coolprop for mixtures can fail and it's slow
            Cmps = [Componente(int(i)) for i in self.kwargs["ids"]]

            # Calculate critic temperature, API procedure 4B1.1 pag 304
            V = sum([xi*cmp.Vc for xi, cmp in
                     zip(self.kwargs["fraccionMolar"], Cmps)])
            k = [xi*cmp.Vc/V for xi, cmp in
                 zip(self.kwargs["fraccionMolar"], Cmps)]
            Tcm = sum([ki*cmp.Tc for ki, cmp in zip(k, Cmps)])
            self.Tc = unidades.Temperature(Tcm)

            # Calculate pseudocritic temperature
            tpc = sum([x*cmp.Tc for x, cmp in
                       zip(self.kwargs["fraccionMolar"], Cmps)])

            # Calculate pseudocritic pressure
            ppc = sum([x*cmp.Pc for x, cmp in
                       zip(self.kwargs["fraccionMolar"], Cmps)])

            # Calculate critic pressure, API procedure 4B2.1 pag 307
            sumaw = 0
            for xi, cmp in zip(self.kwargs["fraccionMolar"], Cmps):
                sumaw += xi*cmp.f_acent
            pc = ppc+ppc*(5.808+4.93*sumaw)*(self.Tc-tpc)/tpc
            self.Pc = unidades.Pressure(pc)

            # Calculate critic volume, API procedure 4B3.1 pag 314
            sumaxvc23 = sum([xi*cmp.Vc**(2./3) for xi, cmp in
                             zip(self.kwargs["fraccionMolar"], Cmps)])
            k = [xi*cmp.Vc**(2./3)/sumaxvc23 for xi, cmp in
                 zip(self.kwargs["fraccionMolar"], Cmps)]

            # TODO: Calculate C value from component type.
            # For now it suppose all are hidrycarbon (C=0)
            C = 0

            V = [[-1.4684*abs((cmpi.Vc-cmpj.Vc)/(cmpi.Vc+cmpj.Vc))+C
                  for cmpj in Cmps] for cmpi in Cmps]
            v = [[V[i][j]*(cmpi.Vc+cmpj.Vc)/2. for j, cmpj in enumerate(
                Cmps)] for i, cmpi in enumerate(Cmps)]
            suma1 = sum([ki*cmp.Vc for ki, cmp in zip(k, Cmps)])
            suma2 = sum([ki*kj*v[i][j] for j, kj in enumerate(k)
                         for i, ki in enumerate(k)])
            self.rhoc = unidades.Density((suma1+suma2)*self.M)

        else:
            self.Tc = unidades.Temperature(estado.T_critical())
            self.Pc = unidades.Pressure(estado.p_critical())
            self.rhoc = unidades.Density(estado.rhomass_critical())

        self.R = unidades.SpecificHeat(estado.gas_constant()/self.M)
        self.Tt = unidades.Temperature(estado.Ttriple())
        estado2 = CP.AbstractState("HEOS", fluido)
        if self._multicomponent:
            estado2.set_mole_fractions(self.kwargs["fraccionMolar"])
        estado2.update(CP.PQ_INPUTS, 101325, 1)
        self.Tb = unidades.Temperature(estado2.T())
        self.f_accent = unidades.Dimensionless(estado.acentric_factor())

        # Dipole moment only available for REFPROP backend
        # self.momentoDipolar(estado.keyed_output(CP.idipole_moment))

        self.phase, x = self.getphase(estado)
        self.x = unidades.Dimensionless(x)
        if self._multicomponent:
            string = fluido.replace("&", " (%0.2f), ")
            string += " (%0.2f)"
            self.name = string % tuple(self.kwargs["fraccionMolar"])
            self.CAS = ""
            self.synonim = ""
            self.formula = ""
        else:
            self.name = fluido
            self.CAS = estado.fluid_param_string("CAS")
            self.synonim = estado.fluid_param_string("aliases")
            self.formula = estado.fluid_param_string("formula")

        self.P = unidades.Pressure(estado.p())
        self.T = unidades.Temperature(estado.T())
        self.Tr = unidades.Dimensionless(self.T/self.Tc)
        self.Pr = unidades.Dimensionless(self.P/self.Pc)
        self.rho = unidades.Density(estado.rhomass())
        self.v = unidades.SpecificVolume(1./self.rho)

        cp0 = self._prop0(estado)
        self._cp0(cp0)

        self.Liquido = ThermoAdvanced()
        self.Gas = ThermoAdvanced()
        if self.x == 0:
            # liquid phase
            self.fill(self.Liquido, estado)
            self.fill(self, estado)
            self.fillNone(self.Gas)
        elif self.x == 1:
            # vapor phase
            self.fill(self.Gas, estado)
            self.fill(self, estado)
            self.fillNone(self.Liquido)
        else:
            # Two phase
            liquido = CP.AbstractState("HEOS", fluido)
            if self._multicomponent:
                xi = estado.mole_fractions_liquid()
                liquido.set_mole_fractions(xi)
            liquido.specify_phase(CP.iphase_liquid)
            liquido.update(CP.QT_INPUTS, 0, self.T)
            self.fill(self.Liquido, liquido)

            vapor = CP.AbstractState("HEOS", fluido)
            if self._multicomponent:
                yi = estado.mole_fractions_vapor()
                vapor.set_mole_fractions(yi)
            vapor.specify_phase(CP.iphase_gas)
            vapor.update(CP.QT_INPUTS, 1, self.T)
            self.fill(self.Gas, vapor)
            self.fill(self, estado)

        # Calculate special properties useful only for one phase
        if self._multicomponent:
            self.sigma = unidades.Tension(None)
        elif x < 1 and self.Tt <= self.T <= self.Tc:
            self.sigma = unidades.Tension(estado.surface_tension())
        else:
            self.sigma = unidades.Tension(None)

        self.virialB = unidades.SpecificVolume(estado.Bvirial())
        self.virialC = unidades.SpecificVolume_square(estado.Cvirial())
        self.invT = unidades.InvTemperature(-1/self.T)

        if 0 < self.x < 1:
            self.Hvap = unidades.Enthalpy(self.Gas.h-self.Liquido.h)
            self.Svap = unidades.SpecificHeat(self.Gas.s-self.Liquido.s)
        else:
            self.Hvap = unidades.Enthalpy(None)
            self.Svap = unidades.SpecificHeat(None)
Exemple #18
0
    def fill(self, fase, T, rho, x):
        if sum(x) != 1:
            x = [round(xi, 10) for xi in x]
        mol = refprop.wmol(x)
        thermo = refprop.therm2(T, rho, x)
        thermo3 = refprop.therm3(T, rho, x)

        fase._bool = True
        fase.M = unidades.Dimensionless(mol["wmix"])
        fase.rho = unidades.Density(rho*fase.M)
        fase.v = unidades.SpecificVolume(1./fase.rho)
        fase.Z = unidades.Dimensionless(thermo["Z"])

        fase.u = unidades.Enthalpy(thermo["e"]/fase.M, "Jg")
        fase.h = unidades.Enthalpy(thermo["h"]/fase.M, "Jg")
        fase.s = unidades.SpecificHeat(thermo["s"]/fase.M, "JgK")
        fase.a = unidades.Enthalpy(thermo["A"]/fase.M, "Jg")
        fase.g = unidades.Enthalpy(thermo["G"]/fase.M, "Jg")

        fase.cv = unidades.SpecificHeat(thermo["cv"]/fase.M, "JgK")
        fase.cp = unidades.SpecificHeat(thermo["cp"]/fase.M, "JgK")
        fase.cp_cv = unidades.Dimensionless(fase.cp/fase.cv)
        fase.gamma = fase.cp_cv
        fase.w = unidades.Speed(thermo["w"])

        fase.rhoM = unidades.MolarDensity(fase.rho/self.M)
        fase.hM = unidades.MolarEnthalpy(fase.h*self.M)
        fase.sM = unidades.MolarSpecificHeat(fase.s*self.M)
        fase.uM = unidades.MolarEnthalpy(fase.u*self.M)
        fase.aM = unidades.MolarEnthalpy(fase.a*self.M)
        fase.gM = unidades.MolarEnthalpy(fase.g*self.M)
        fase.cvM = unidades.MolarSpecificHeat(fase.cv*self.M)
        fase.cpM = unidades.MolarSpecificHeat(fase.cp*self.M)

        residual = refprop.residual(T, rho, x)
        fase.pr = unidades.Pressure(residual["pr"], "kPa")
        fase.ur = unidades.Enthalpy(residual["er"]/fase.M, "Jg")
        fase.hr = unidades.Enthalpy(residual["hr"]/fase.M, "Jg")
        fase.sr = unidades.SpecificHeat(residual["sr"]/fase.M, "JgK")
        fase.ar = unidades.Enthalpy(residual["Ar"]/fase.M, "Jg")
        fase.gr = unidades.Enthalpy(residual["Gr"]/fase.M, "Jg")
        fase.cvr = unidades.SpecificHeat(residual["cvr"]/fase.M, "JgK")
        fase.cpr = unidades.SpecificHeat(residual["cpr"]/fase.M, "JgK")

        fase.alfav = unidades.InvTemperature(thermo["beta"])
        fase.kappa = unidades.InvPressure(thermo["xkappa"], "kPa")
        fase.kappas = unidades.InvPressure(thermo3["betas"], "kPa")
        fase.alfap = unidades.Density(fase.alfav/self.P/fase.kappa)
        fase.deltat = unidades.EnthalpyPressure(
            thermo3["thrott"]/fase.M, "kJkgkPa")
        fase.joule = unidades.TemperaturePressure(thermo["hjt"], "KkPa")
        fase.betas = unidades.TemperaturePressure(
            self.derivative("T", "P", "s", fase))
        fase.betap = unidades.Density(
            -1/self.P*self.derivative("P", "v", "T", fase))

        fase.Kt = unidades.Pressure(thermo3["xkkt"], "kPa")
        fase.Ks = unidades.Pressure(thermo3["bs"], "kPa")
        fase.kt = unidades.Dimensionless(thermo3["xkt"])
        fase.ks = unidades.Dimensionless(thermo3["xisenk"])

        dh = refprop.dhd1(T, rho, x)
        fase.dhdT_rho = unidades.SpecificHeat(dh["dhdt_D"]/fase.M, "kJkgK")
        fase.dhdT_P = unidades.SpecificHeat(dh["dhdt_p"]/fase.M, "kJkgK")
        fase.dhdP_T = unidades.EnthalpyPressure(dh["dhdp_t"]/fase.M, "kJkgkPa")
        # dhdtp_D : fix in library
        fase.dhdP_rho = unidades.EnthalpyPressure(
            dh["dhdtp_D"]/fase.M, "kJkgkPa")
        fase.dhdrho_T = unidades.EnthalpyDensity(
            dh["dhdD_t"]/fase.M**2, "kJkgkgm3")
        fase.dhdrho_P = unidades.EnthalpyDensity(
            dh["dhdD_p"]/fase.M**2, "kJkgkgm3")

        fase.dpdT_rho = unidades.PressureTemperature(thermo["dpdt"], "kPaK")
        fase.dpdrho_T = unidades.PressureDensity(
            thermo["dpdD"]/fase.M, "kPakgm3")
        # TODO: Add unit for derivative d^2p/dD^2 [kPa-L^2/mol^2]
        # MPa·m⁶/kg²
        fase.d2pdrho2 = unidades.Dimensionless(thermo["d2pdD2"]/fase.M**2/1000)
        fase.drhodP_T = unidades.DensityPressure(
            thermo["dDdp"]*fase.M, "kgm3kPa")
        fase.drhodT_P = unidades.DensityTemperature(thermo["dDdt"]*fase.M)
        fase.Gruneisen = unidades.Dimensionless(fase.v/fase.cv*fase.dpdT_rho)

        fase.Z_rho = unidades.SpecificVolume((fase.Z-1)/fase.rho)
        fase.IntP = unidades.Pressure(thermo3["pint"], "kPa")
        fase.hInput = unidades.Enthalpy(thermo3["spht"]/fase.M, "kJkg")
        fase.invT = unidades.InvTemperature(-1/self.T)

        fpv = refprop.fpv(T, rho, self.P.kPa, x)["Fpv"]
        fase.fpv = unidades.Dimensionless(fpv)

        chempot = refprop.chempot(T, rho, x)["u"]
        fase.chempot = [unidades.Enthalpy(c/fase.M) for c in chempot]
        fi = refprop.fugcof(T, rho, x)["f"]
        fase.fi = [unidades.Dimensionless(f) for f in fi]
        f = refprop.fgcty(T, rho, x)["f"]
        fase.f = [unidades.Pressure(f_i, "kPa") for f_i in f]

        b = refprop.virb(T, x)["b"]
        fase.virialB = unidades.SpecificVolume(b/self.M)
        c = refprop.virc(T, x)["c"]
        fase.virialC = unidades.SpecificVolume_square(c/self.M**2)
        # viriald don't supported for windows
        d = refprop.vird(T, x)["d"]
        fase.virialD = unidades.Dimensionless(d/self.M**3)
        ba = refprop.virba(T, x)["ba"]
        fase.virialBa = unidades.SpecificVolume(ba/self.M)
        ca = refprop.virca(T, x)["ca"]
        fase.virialCa = unidades.SpecificVolume_square(ca/self.M**2)
        dcdt = refprop.dcdt(T, x)["dct"]
        fase.dCdt = unidades.Dimensionless(dcdt/self.M**2)
        dcdt2 = refprop.dcdt2(T, x)["dct2"]
        fase.dCdt2 = unidades.Dimensionless(dcdt2/self.M**2)
        dbdt = refprop.dbdt(T, x)["dbt"]
        fase.dBdt = unidades.Dimensionless(dbdt/self.M)

        b12 = refprop.b12(T, x)["b"]
        fase.b12 = unidades.SpecificVolume(b12*fase.M)
        try:
            cstar = refprop.cstar(T, self.P.kPa, 0, x)["cs"]
            fase.cstar = unidades.Dimensionless(cstar)
        except refprop.RefpropdllError:
            fase.cstar = unidades.Dimensionless(None)

        fase.fraccion = [unidades.Dimensionless(xi) for xi in x]
        xg = refprop.xmass(x)["xkg"]
        fase.fraccion_masica = [unidades.Dimensionless(xi) for xi in xg]

        transport = refprop.trnprp(T, rho, x)
        fase.mu = unidades.Viscosity(transport["eta"], "muPas")
        fase.nu = unidades.Diffusivity(fase.mu/fase.rho)
        fase.k = unidades.ThermalConductivity(transport["tcx"])
        fase.alfa = unidades.Diffusivity(fase.k/fase.rho/fase.cp)
        fase.Prandt = unidades.Dimensionless(fase.mu*fase.cp/fase.k)

        dielec = refprop.dielec(T, rho, x)
        fase.epsilon = unidades.Dimensionless(dielec["de"])
Exemple #19
0
    def _calculo(self):
        self._initialization()

        x = self._x()
        m = refprop.wmol(x)["wmix"]
        self.M = unidades.Dimensionless(m)
        crit = refprop.critp(x)
        self.Pc = unidades.Pressure(crit["pcrit"], "kPa")
        self.Tc = unidades.Temperature(crit["tcrit"])
        self.rhoc = unidades.Density(crit["Dcrit"]*self.M)

        args = self.args()
        flash = refprop.flsh(*args)

        # check if ['q'] in fld
        if 'q' in flash.keys():
            x = flash['q']
        elif 'h' in flash.keys():
            x = refprop.flsh('ph', flash['p'], flash['h'], flash['x'])['q']
        elif 's' in flash.keys():
            x = refprop.flsh('ps', flash['p'], flash['s'], flash['x'])['q']
        if 0 < x < 1:
            region = 4
        else:
            region = 1

        if x < 0:
            x = 0
        elif x > 1:
            x = 1
        self.x = unidades.Dimensionless(x)
        self.T = unidades.Temperature(flash["t"])
        self.P = unidades.Pressure(flash["p"], "kPa")
        self.Tr = unidades.Dimensionless(self.T/self.Tc)
        self.Pr = unidades.Dimensionless(self.P/self.Pc)
        self.rho = unidades.Density(flash["D"]*self.M)
        self.v = unidades.SpecificVolume(1./self.rho)
        self.phase = self.getphase(Tc=self.Tc, Pc=self.Pc, T=self.T, P=self.Pc,
                                   x=self.x, region=region)

        if flash["nc"] == 1:
            name = refprop.name(flash["nc"])
            self.name = name["hname"]
            self.synonim = name["hn80"]
            self.CAS = name["hcas"]

            info = refprop.info(flash["nc"])
            self.R = unidades.SpecificHeat(info["Rgas"]/self.M)
            self.Tt = unidades.Temperature(info["ttrp"])
            self.Tb = unidades.Temperature(info["tnbpt"])
            self.f_accent = unidades.Dimensionless(info["acf"])
            self.momentoDipolar = unidades.DipoleMoment(info["dip"], "Debye")
            self._doc = {}
            for htype in ['EOS', 'CP0', 'ETA', 'VSK', 'TCX', 'TKK', 'STN',
                          'DE ', 'MLT', 'SBL', 'PS ', 'DL ', 'DV ']:
                self._doc[htype] = refprop.getmod(flash["nc"], htype)["hcite"]
        else:
            self.name = ""
            self.synonim = ""
            self.CAS = ""

            rmix = refprop.rmix2(flash["x"])
            self.R = unidades.SpecificHeat(rmix["Rgas"]/self.M)
            self.Tt = unidades.Temperature(None)
            self.Tb = unidades.Temperature(None)
            self.f_accent = unidades.Dimensionless(None)
            self.momentoDipolar = unidades.DipoleMoment(None)
            self._doc = {}

        self._cp0(flash)

        self.Liquido = ThermoRefProp()
        self.Gas = ThermoRefProp()
        if self.x == 0.:
            # liquid phase
            self.fill(self.Liquido, flash["t"], flash["D"], flash["x"])
            self.fill(self, flash["t"], flash["D"], flash["x"])
            self.fillNone(self.Gas)
        elif self.x == 1.:
            # vapor phase
            self.fill(self.Gas, flash["t"], flash["D"], flash["x"])
            self.fill(self, flash["t"], flash["D"], flash["x"])
            self.fillNone(self.Liquido)
        else:
            # Two phase
            self.fillNone(self)
            self.fill(self.Liquido, flash["t"], flash["Dliq"], flash["xliq"])
            self.fill(self.Gas, flash["t"], flash["Dvap"], flash["xvap"])

            self.v = unidades.SpecificVolume(x*self.Gas.v+(1-x)*self.Liquido.v)
            self.rho = unidades.Density(1./self.v)

            self.u = unidades.Enthalpy(flash["e"]/self.M, "Jg")
            self.h = unidades.Enthalpy(flash["h"]/self.M, "Jg")
            self.s = unidades.SpecificHeat(flash["s"]/self.M, "JgK")
            self.a = unidades.Enthalpy(self.u-self.T*self.s)
            self.g = unidades.Enthalpy(self.h-self.T*self.s)

            self.rhoM = unidades.MolarDensity(self.rho/self.M)
            self.hM = unidades.MolarEnthalpy(self.h*self.M)
            self.sM = unidades.MolarSpecificHeat(self.s*self.M)
            self.uM = unidades.MolarEnthalpy(self.u*self.M)
            self.aM = unidades.MolarEnthalpy(self.a*self.M)
            self.gM = unidades.MolarEnthalpy(self.g*self.M)

        if self.x < 1 and self.T <= self.Tc:
            surten = refprop.surten(flash["t"], flash["Dliq"], flash["Dvap"],
                                    flash["xliq"], flash["xvap"])
            self.sigma = unidades.Tension(surten["sigma"])
        else:
            self.sigma = unidades.Tension(None)

        if 0 < self.x < 1:
            self.Hvap = unidades.Enthalpy(self.Gas.h-self.Liquido.h)
            self.Svap = unidades.SpecificHeat(self.Gas.s-self.Liquido.s)
            self.K = []
            for x, y in zip(self.Liquido.fraccion, self.Gas.fraccion):
                self.K.append(unidades.Dimensionless(y/x))
        else:
            self.Hvap = unidades.Enthalpy(None)
            self.Svap = unidades.SpecificHeat(None)
            self.K = [unidades.Dimensionless(1)]*flash["nc"]
        self.invT = unidades.InvTemperature(-1/self.T)

        # NOT supported on Windows
        if sys.platform != "win32":
            excess = refprop.excess(flash["t"], flash["D"], flash["x"])
            self.vE = unidades.Volume(excess["vE"]/self.M)
            self.uE = unidades.Enthalpy(excess["eE"]/self.M, "Jg")
            self.hE = unidades.Enthalpy(excess["hE"]/self.M, "Jg")
            self.sE = unidades.SpecificHeat(excess["sE"]/self.M, "JgK")
            self.aE = unidades.Enthalpy(excess["aE"]/self.M, "Jg")
            self.gE = unidades.Enthalpy(excess["gE"]/self.M, "Jg")
        else:
            self.vE = unidades.Volume(0)
            self.uE = unidades.Enthalpy(0)
            self.hE = unidades.Enthalpy(0)
            self.sE = unidades.SpecificHeat(0)
            self.aE = unidades.Enthalpy(0)
            self.gE = unidades.Enthalpy(0)

        self.csat = []
        self.dpdt_sat = []
        self.cv2p = []
        if self.Tt <= flash["t"] <= self.Tc:
            for i in range(1, flash["nc"]+1):
                dat = refprop.dptsatk(i, flash["t"], kph=2)
                cs = unidades.SpecificHeat(dat["csat"]/self.M, "JgK")
                self.csat.append(cs)
                self.dpdt_sat.append(
                    unidades.PressureTemperature(dat["dpdt"], "kPaK"))
                cv2 = refprop.cv2pk(i, flash["t"], flash["D"])
                cv = unidades.SpecificHeat(cv2["cv2p"]/self.M, "JgK")
                self.cv2p.append(cv)
Exemple #20
0
    def calculo(self):
        # TODO: Add configuration section to Preferences
        # preos = Preferences.getboolean("refProp", "preos")
        # aga = Preferences.getboolean("refProp", "aga")
        # gerg = Preferences.getboolean("refProp", "gerg")
        preos = self.kwargs["preos"]
        aga = self.kwargs["aga"]
        gerg = self.kwargs["gerg"]

        x = self._x()
        fluido = self._name()

        kwmod = [self.kwargs[k] for k in ('htype', 'hmix', 'hcomp')]
        refprop.setmod(*kwmod)
        if gerg:
            refprop.gerg04(ixflag=1)
        refprop.setup("def", fluido)
        # refprop.setktv()
        if preos:
            refprop.preos(ixflag=2)
        elif aga:
            refprop.setaga()
        kwref = {k: self.kwargs[k] for k in (
            'hrf', 'ixflag', 'x0', 'h0', 's0', 't0', 'p0')}
        refprop.setref(**kwref)

        m = refprop.wmol(x)["wmix"]
        self.M = unidades.Dimensionless(m)
        crit = refprop.critp(x)
        self.Pc = unidades.Pressure(crit["pcrit"], "kPa")
        self.Tc = unidades.Temperature(crit["tcrit"])
        self.rhoc = unidades.Density(crit["Dcrit"]*self.M)

        args = self.args()
        flash = refprop.flsh(*args)

        # check if ['q'] in fld
        if 'q' in flash.keys():
            x = flash['q']
        elif 'h' in flash.keys():
            x = refprop.flsh('ph', flash['p'], flash['h'], flash['x'])['q']
        elif 's' in flash.keys():
            x = refprop.flsh('ps', flash['p'], flash['s'], flash['x'])['q']
        if 0 < x < 1:
            region = 4
        else:
            region = 1

        if x < 0:
            x = 0
        elif x > 1:
            x = 1
        self.x = unidades.Dimensionless(x)
        self.T = unidades.Temperature(flash["t"])
        self.P = unidades.Pressure(flash["p"], "kPa")
        self.Tr = unidades.Dimensionless(self.T/self.Tc)
        self.Pr = unidades.Dimensionless(self.P/self.Pc)
        self.rho = unidades.Density(flash["D"]*self.M)
        self.v = unidades.SpecificVolume(1./self.rho)
        self.phase = self.getphase(Tc=self.Tc, Pc=self.Pc, T=self.T, P=self.Pc,
                                   x=self.x, region=region)

        if flash["nc"] == 1:
            name = refprop.name(flash["nc"])
            self.name = name["hname"]
            self.synonim = name["hn80"]
            self.CAS = name["hcas"]

            info = refprop.info(flash["nc"])
            self.R = unidades.SpecificHeat(info["Rgas"]/self.M)
            self.Tt = unidades.Temperature(info["ttrp"])
            self.Tb = unidades.Temperature(info["tnbpt"])
            self.f_accent = unidades.Dimensionless(info["acf"])
            self.momentoDipolar = unidades.DipoleMoment(info["dip"], "Debye")
            self._doc = {}
            for htype in ['EOS', 'CP0', 'ETA', 'VSK', 'TCX', 'TKK', 'STN',
                          'DE ', 'MLT', 'SBL', 'PS ', 'DL ', 'DV ']:
                self._doc[htype] = refprop.getmod(flash["nc"], htype)["hcite"]
        else:
            self.name = ""
            self.synonim = ""
            self.CAS = ""

            rmix = refprop.rmix2(flash["x"])
            self.R = unidades.SpecificHeat(rmix["Rgas"]/self.M)
            self.Tt = unidades.Temperature(None)
            self.Tb = unidades.Temperature(None)
            self.f_accent = unidades.Dimensionless(None)
            self.momentoDipolar = unidades.DipoleMoment(None)
            self._doc = {}

        self._cp0(flash)

        self.Liquido = ThermoRefProp()
        self.Gas = ThermoRefProp()
        if self.x == 0:
            # liquid phase
            self.fill(self.Liquido, flash["t"], flash["Dliq"], flash["xliq"])
            self.fill(self, flash["t"], flash["Dliq"], flash["xliq"])
            self.fillNone(self.Gas)
        elif self.x == 1:
            # vapor phase
            self.fill(self.Gas, flash["t"], flash["Dvap"], flash["xvap"])
            self.fill(self, flash["t"], flash["Dvap"], flash["xvap"])
            self.fillNone(self.Liquido)
        else:
            # Two phase
            self.fill(self.Liquido, flash["t"], flash["Dliq"], flash["xliq"])
            self.fill(self.Gas, flash["t"], flash["Dvap"], flash["xvap"])

            self.u = unidades.Enthalpy(flash["e"]/self.M, "Jg")
            self.h = unidades.Enthalpy(flash["h"]/self.M, "Jg")
            self.s = unidades.SpecificHeat(flash["s"]/self.M, "JgK")
            self.a = unidades.Enthalpy(self.u-self.T*self.s)
            self.g = unidades.Enthalpy(self.h-self.T*self.s)

        if self.x < 1 and self.T <= self.Tc:
            surten = refprop.surten(flash["t"], flash["Dliq"], flash["Dvap"],
                                    flash["xliq"], flash["xvap"])
            self.sigma = unidades.Tension(surten["sigma"])
        else:
            self.sigma = unidades.Tension(None)

        if 0 < self.x < 1:
            self.Hvap = unidades.Enthalpy(self.Gas.h-self.Liquido.h)
            self.Svap = unidades.SpecificHeat(self.Gas.s-self.Liquido.s)
            self.K = []
            for x, y in zip(self.Liquido.fraccion, self.Gas.fraccion):
                self.K.append(unidades.Dimensionless(y/x))
        else:
            self.Hvap = unidades.Enthalpy(None)
            self.Svap = unidades.SpecificHeat(None)
            self.K = [unidades.Dimensionless(1)]*flash["nc"]

        # NOT supported on Windows
        excess = refprop.excess(flash["t"], flash["D"], flash["x"])
        self.vE = unidades.Volume(excess["vE"]/self.M)
        self.uE = unidades.Enthalpy(excess["eE"]/self.M, "Jg")
        self.hE = unidades.Enthalpy(excess["hE"]/self.M, "Jg")
        self.sE = unidades.SpecificHeat(excess["sE"]/self.M, "JgK")
        self.aE = unidades.Enthalpy(excess["aE"]/self.M, "Jg")
        self.gE = unidades.Enthalpy(excess["gE"]/self.M, "Jg")

        self.csat = []
        self.dpdt_sat = []
        self.cv2p = []
        for i in range(1, flash["nc"]+1):
            dat = refprop.dptsatk(i, flash["t"], kph=2)
            self.csat.append(unidades.SpecificHeat(dat["csat"]/self.M, "JgK"))
            self.dpdt_sat.append(
                unidades.PressureTemperature(dat["dpdt"], "kPaK"))
            cv2 = refprop.cv2pk(i, flash["t"], flash["D"])
            self.cv2p.append(unidades.SpecificHeat(cv2["cv2p"]/self.M, "JgK"))
Exemple #21
0
    def readStatefromJSON(self, fluid):
        if fluid:
            self._bool = True

            self.M = unidades.Dimensionless(fluid["M"])
            self.v = unidades.SpecificVolume(fluid["v"])
            self.rho = unidades.Density(1 / self.v)

            self.h = unidades.Enthalpy(fluid["h"])
            self.s = unidades.SpecificHeat(fluid["s"])
            self.u = unidades.Enthalpy(fluid["u"])
            self.a = unidades.Enthalpy(fluid["a"])
            self.g = unidades.Enthalpy(fluid["g"])

            self.cv = unidades.SpecificHeat(fluid["cv"])
            self.cp = unidades.SpecificHeat(fluid["cp"])
            self.cp_cv = unidades.Dimensionless(fluid["cp/cv"])
            self.w = unidades.Speed(fluid["w"])

            self.Z = unidades.Dimensionless(fluid["Z"])
            self.alfav = unidades.InvTemperature(fluid["alfav"])
            self.kappa = unidades.InvPressure(fluid["kappa"])
            self.kappas = unidades.InvPressure(fluid["kappas"])

            self.mu = unidades.Viscosity(fluid["mu"])
            self.k = unidades.ThermalConductivity(fluid["k"])
            self.nu = unidades.Diffusivity(fluid["nu"])
            self.Prandt = unidades.Dimensionless(fluid["Prandt"])

            self.alfa = unidades.Diffusivity(fluid["alfa"])
            self.joule = unidades.TemperaturePressure(fluid["joule"])
            self.deltat = unidades.EnthalpyPressure(fluid["deltat"])
            self.gamma = unidades.Dimensionless(fluid["gamma"])

            self.alfap = unidades.Dimensionless(fluid["alfap"])
            self.betap = unidades.Dimensionless(fluid["betap"])
            self.fi = [unidades.Dimensionless(f) for f in fluid["fi"]]
            self.f = [unidades.Pressure(f) for f in fluid["f"]]

            self.Q = unidades.VolFlow(fluid["volFlow"])
            self.caudalmasico = unidades.MassFlow(fluid["massFlow"])
            self.caudalmolar = unidades.MolarFlow(fluid["molarFlow"])
            self.fraccion = [
                unidades.Dimensionless(x) for x in fluid["fraction"]
            ]
            self.fraccion_masica = [
                unidades.Dimensionless(x) for x in fluid["massFraction"]
            ]
            self.caudalunitariomasico = [
                unidades.MassFlow(x) for x in fluid["massUnitFlow"]
            ]
            self.caudalunitariomolar = [
                unidades.MolarFlow(x) for x in fluid["molarUnitFlow"]
            ]

            self.rhoM = unidades.MolarDensity(self.rho / self.M)
            self.hM = unidades.MolarEnthalpy(self.h / self.M)
            self.sM = unidades.MolarSpecificHeat(self.s / self.M)
            self.uM = unidades.MolarEnthalpy(self.u / self.M)
            self.aM = unidades.MolarEnthalpy(self.a / self.M)
            self.gM = unidades.MolarEnthalpy(self.g / self.M)
            self.cvM = unidades.MolarSpecificHeat(self.cv / self.M)
            self.cpM = unidades.MolarSpecificHeat(self.cp / self.M)
Exemple #22
0
    def calculo(self):
        method = [
            freesteam.steam_pT, freesteam.steam_ph, freesteam.steam_ps,
            freesteam.steam_pv, freesteam.steam_Ts, freesteam.steam_Tx
        ]
        func = method[self._thermo]
        fluido = func(self.var1, self.var2)

        self.x = unidades.Dimensionless(fluido.x)
        self.name = mEoS.H2O.name
        self.region = fluido.region
        self.synonim = mEoS.H2O.synonym
        self.CAS = mEoS.H2O.CASNumber

        self.T = unidades.Temperature(fluido.T)
        self.P = unidades.Pressure(fluido.p)
        self.phase = self.getphase(Tc=self.Tc,
                                   Pc=self.Pc,
                                   T=self.T,
                                   P=self.P,
                                   x=self.x,
                                   region=self.region)
        self.Tr = unidades.Dimensionless(self.T / self.Tc)
        self.Pr = unidades.Dimensionless(self.P / self.Pc)
        self.rho = unidades.Density(fluido.rho)
        self.v = unidades.SpecificVolume(1. / self.rho)

        cp0 = prop0(self.T, self.P.MPa)
        cp0["h"] *= 1000
        cp0["s"] *= 1000
        cp0["cp"] *= 1000
        cp0["cv"] *= 1000
        self._cp0(cp0)

        self.Liquido = ThermoWater()
        self.Gas = ThermoWater()
        if self.x == 0:
            # only liquid phase
            self.fill(self, fluido)
            self.fill(self.Liquido, fluido)
            self.sigma = unidades.Tension(freesteam.surftens_T(self.T))

            self.Hvap = unidades.Enthalpy(None)
            self.Svap = unidades.SpecificHeat(None)
        elif self.x == 1:
            # only vapor phase
            self.fill(self, fluido)
            self.fill(self.Gas, fluido)

            self.Hvap = unidades.Enthalpy(None)
            self.Svap = unidades.SpecificHeat(None)
        else:
            # two phases
            liquido = freesteam.steam_Tx(fluido.T, 0.)
            self.fill(self.Liquido, liquido)
            self.sigma = unidades.Tension(freesteam.surftens_T(self.T))
            vapor = freesteam.steam_Tx(fluido.T, 1.)
            self.fill(self.Gas, vapor)

            self.h = unidades.Enthalpy(self.x * self.Gas.h +
                                       (1 - self.x) * self.Liquido.h)
            self.s = unidades.SpecificHeat(self.x * self.Gas.s +
                                           (1 - self.x) * self.Liquido.s)
            self.u = unidades.SpecificHeat(self.x * self.Gas.u +
                                           (1 - self.x) * self.Liquido.u)
            self.a = unidades.Enthalpy(self.x * self.Gas.a +
                                       (1 - self.x) * self.Liquido.a)
            self.g = unidades.Enthalpy(self.x * self.Gas.g +
                                       (1 - self.x) * self.Liquido.g)

            self.cv = unidades.SpecificHeat(None)
            self.cp = unidades.SpecificHeat(None)
            self.cp_cv = unidades.Dimensionless(None)
            self.w = unidades.Speed(None)

            self.Hvap = unidades.Enthalpy(vapor["h"] - liquido["h"], "kJkg")
            self.Svap = unidades.SpecificHeat(vapor["s"] - liquido["s"],
                                              "kJkgK")