示例#1
0
 def getSpeedOfSound(self, P_in, T_in): #Miller 2001 2.14
   if isinstance(T_in, float):
     self.computed2AdT2(T_in)
     self.setNASAcoeff(T_in)
     rho = self.getDensityfromPressureTemperature(P_in,T_in)[0]     
     v_in = tools.getVfromRho(rho, self.MW)
     self.computeK1(v_in)
     K_S = self.getIsentropicComp(v_in, T_in)
     return np.sqrt(1.0/(rho*K_S))
   rho = self.getDensityfromPressureTemperature(P_in,T_in)[0]     
   v_in = tools.getVfromRho(rho, self.MW)
   K_S = self.getIsentropicComp(v_in, T_in)
   return np.sqrt(1.0/(rho*K_S))
示例#2
0
    def NewtonIterate_TemperaturefromPrho(self,
                                          rho_target,
                                          P_target,
                                          T_in=300.0,
                                          eps=1E-10,
                                          omega=1.0):
        T_n = T_in * np.ones(rho_target.shape)
        v_target = tools.getVfromRho(rho_target, self.MW)
        self.setRealFluidThermodynamics(v_target, T_n)
        P_n = self.getPressurefromVolumeTemperature(v_target, T_n)
        # if P_target.any() == 0:
        #   keyboard()
        diff = (P_n - P_target) / P_target
        prevdiff = diff
        diff0 = max(abs(diff))
        #print "diff , diff0", diff, diff0
        itera = 0
        #Newton solver
        range_convergence_complete = False
        pointwise_converged = np.zeros(diff.shape)
        flagged = False
        while not range_convergence_complete:
            diff0 = abs(max(diff))
            prevdiff = diff
            dPdT = self.getdPdT(v_target, T_n)
            T_correction = omega * diff * P_target / dPdT
            T_correction[np.where(pointwise_converged == True)] = 0.
            T_n -= T_correction
            self.setRealFluidThermodynamics(v_target, T_n)
            P_n = self.getPressurefromVolumeTemperature(v_target, T_n)
            diff = (P_n - P_target) / P_target
            diff1 = max(abs(diff))

            if (diff1 > diff0):
                if (pointwise_converged[0]) and (
                        pointwise_converged[-1]
                ):  # if ghost cells have converged (for continuity)
                    break
                elif itera > 10:  # Taking too long AND ends not converged yet
                    print "Taking too long"
                    flagged = True
                    break
                elif np.mean(prevdiff) < np.mean(diff):  # average diverging
                    print "The average diverging is not optimistic"
                    flagged = True
                    break

            pointwise_converged = abs(
                diff
            ) < eps  #Still converging means FALSE, if converged then True
            range_convergence_complete = not (
                False in pointwise_converged
            )  #Still converging means False, if converged True
            pointwise_converged = np.array(pointwise_converged)
            itera += 1

        return T_n
示例#3
0
def pres(dens, eint):
    """
    Given the density and the specific internal energy, return the
    pressure
    Parameters
    ----------
    gamma : float
        The ratio of specific heats
    dens : float
        The density
    eint : float
        The specific internal energy
    Returns
    -------
    out : float
       The pressure
     """
    #p = dens*eint*(gamma - 1.0)
    # p = eint.copy()
    # if (eint.ndim == 2):
    #     for i in range(np.shape(eint)[0]):
    #         for j in range(np.shape(eint)[1]):
    #             if dens[i][j] < 0.1 :
    #                 p[i][j] = 0.0
    #                 continue
    #             p[i][j] = PropsSI('P', 'UMASS', eint[i][j],'DMASS', dens[i][j], fluid)
    #     p = np.array(p, order = 'F')
    #     return p
    # else:
    #     p = PropsSI('P', 'UMASS', eint,'DMASS', dens, fluid)
    #     p = np.array(p, order = 'F')
    #     return p
    MW = 32.0
    vol = tools.getVfromRho(dens, MW)
    T = np.ones(np.shape(vol))
    p = np.ones(np.shape(vol))
    if (vol.ndim == 2):
        for i in range(np.shape(vol)[0]):
            if dens[i].any() < 0.1:
                temp = dens[i]
                temp[temp < 0.1] = np.nan
                dens[i] = temp
                continue
            eint[i] = tools.convertMassToMolar(eint[i], MW)
            eint[i] = tools.convertMolarToMass(eint[i], MW)
            T[i] = PREOS.NewtonIterate_TemperaturefromEv(eint[i],vol[i], T_in = 300.0 ,eps=1E-6,omega=1.0)
            p[i] = PREOS.getPressurefromVolumeTemperature(vol[i],T[i])
        return p
    else:
        eint = tools.convertMassToMolar(eint, MW)
        T_in = PREOS.NewtonIterate_TemperaturefromEv(eint,vol, T_in = 300.0 ,eps=1E-6,omega=1.0)
        p = PREOS.getPressurefromVolumeTemperature(vol,T_in)
    return p
示例#4
0
    def getConservativeFromPrimitive(self, u, P, T, scalar):
        '''    get conservatives from primitives  variables  '''
        self.computeA(T)
        rho = self.getDensityfromPressureTemperature(P, T)
        v = tools.getVfromRho(rho, self.MW)
        self.setRealFluidThermodynamics(v, T)
        Eint_mol = self.getEnergyfromVolumeTemperature(v, T)
        Eint_mass = tools.convertMolarToMass(Eint_mol, self.MW)  #

        rhou = rho * u
        rhoE = rho * (Eint_mass + 0.5 * u * u)  # Total energy
        rhoScalar = rho * scalar
        return rho, rhou, rhoE, rhoScalar
示例#5
0
    def getPrimitiveFromConservative(self, rho, rhou, rhoE, rhoScalar):
        '''       get primitives from conservatives variables     '''
        u = rhou / rho
        scalar = rhoScalar / rho
        Eint_mass = rhoE / rho - 0.5 * u * u
        Eint_mol = tools.convertMassToMolar(Eint_mass, self.MW)

        self.v = tools.getVfromRho(rho, self.MW)

        T = self.NewtonIterate_TemperaturefromEv(Eint_mol, self.v, self.Told)
        P = self.getPressurefromVolumeTemperature(self.v, T)

        self.Told = T

        return u, P, T, scalar
示例#6
0
 def getPressure(self, rho, T_in):
     '''
    get pressure given rho, T
   '''
     v_in = tools.getVfromRho(rho, self.MW)
     return self.getPressurefromVolumeTemperature(v_in, T_in)
示例#7
0
 def getEnthalpyFromTemperature(self, T_in, rho_in, p_in):
     v_in = tools.getVfromRho(rho_in, self.MW)
     return self.getEnthalpyfromVolumeTemperature(v_in, T_in, p_in)
示例#8
0
 def getCompressibilityFactor(self, p, rho, T):
     v_in = tools.getVfromRho(rho, self.MW)
     self.setRealFluidThermodynamics(v_in, T)
     self.updateGamma(v_in, T)
     return (p / (rho * self.RoM * 1000 * T))