Ejemplo n.º 1
0
 def fit(self):
     
     from summer import PPF_summer
     Tc = Props(self.RefString, 'Tcrit')
     rhoc = Props(self.RefString, 'rhocrit')
     self.PPF = PPF_summer(Tc/self.T,self.rho/rhoc)
     self.PPF.set_constants(self.T0,self.D0,self.L0,6)
     
     self.N = scipy.optimize.minimize(self.OBJECTIVE, np.array(list(self.N0)+list(self.T0)), options = dict(maxiter = 20)).x
     
     h = h5py.File('fit_coeffs.h5','a')
     grp = h.create_group(self.Ref)
     grp.create_dataset("n", data = np.array(self.N[0:len(self.N)//2]), compression = "gzip")
     grp.create_dataset("t", data = np.array(self.N[len(self.N)//2::]), compression = "gzip")
     h.close()
Ejemplo n.º 2
0
class ResidualPartFitter(object):
    
    def __init__(self, Ref):
        self.Ref = Ref
        self.RefString, self.N0, self.T0, self.D0, self.L0 = get_fluid_constants(Ref)
        
    def generate_1phase_data(self):
        
        Tc = Props(self.RefString, 'Tcrit')
        rhoc = Props(self.RefString, 'rhocrit')
        TTT, RHO, PPP = [], [], []
        
        for _T in np.linspace(220, 450, 300):
            print _T
            for _rho in np.logspace(np.log10(1e-10), np.log10(2.5*rhoc), 300):
                try:
                    if _T > Tc:
                        p = Props('P', 'T', _T, 'D', _rho, self.RefString)
                    else:
                        DL = Props('D', 'T', _T, 'Q', 0, self.RefString)
                        DV = Props('D', 'T', _T, 'Q', 1, self.RefString)
                        if _rho < DV or _rho > DL:
                            p = Props('P', 'T', _T, 'D', _rho, self.RefString)
                        else:
                            p = None
                    if p is not None:
                        TTT.append(_T)
                        RHO.append(_rho)
                        PPP.append(p)
                except ValueError as VE:
                    print VE
                    pass
                    
        h = h5py.File('T_rho_p.h5','w')
        grp = h.create_group(self.Ref)
        grp.create_dataset("T",data = np.array(TTT),compression = "gzip")
        grp.create_dataset("rho", data = np.array(RHO),compression = "gzip")
        grp.create_dataset("p", data = np.array(PPP),compression = "gzip")
        h.close()
    
    def load_data(self):
        h = h5py.File('T_rho_p.h5','r')
        self.T = h.get(self.Ref + '/T').value
        self.rho = h.get(self.Ref + '/rho').value
        self.p = h.get(self.Ref + '/p').value
    
    def pressure_from_EOS(self, N):
        
        self.PPF.n = N[0:len(N)//2]
        self.PPF.t = N[len(N)//2::]
        
        ddD1 = self.PPF.dphir_dDelta()

        Tc = Props(self.RefString, 'Tcrit')
        rhoc = Props(self.RefString, 'rhocrit')
        R = 8.314472/Props(self.RefString,'molemass')
        
        p = (self.rho*R*self.T)*(1+self.rho/rhoc*ddD1)
        return np.array(p,ndmin=1).T
    
    def OBJECTIVE(self, N):
        pPPF = self.pressure_from_EOS(N)
        RMS = np.sqrt(np.mean(np.power((pPPF-self.p)/self.p, 2)))
        print RMS
        return RMS
    
    def fit(self):
        
        from summer import PPF_summer
        Tc = Props(self.RefString, 'Tcrit')
        rhoc = Props(self.RefString, 'rhocrit')
        self.PPF = PPF_summer(Tc/self.T,self.rho/rhoc)
        self.PPF.set_constants(self.T0,self.D0,self.L0,6)
        
        self.N = scipy.optimize.minimize(self.OBJECTIVE, np.array(list(self.N0)+list(self.T0)), options = dict(maxiter = 20)).x
        
        h = h5py.File('fit_coeffs.h5','a')
        grp = h.create_group(self.Ref)
        grp.create_dataset("n", data = np.array(self.N[0:len(self.N)//2]), compression = "gzip")
        grp.create_dataset("t", data = np.array(self.N[len(self.N)//2::]), compression = "gzip")
        h.close()