def residual_enthalpy_and_PVT(p,Data_Enthalpy_H,Data_Enthalpy_PkPa,Data_Enthalpy_T,Data_Enthalpy_x_h2,Data_Enthalpy_x_h2o,Data_pXT_P,Data_pXT_T,Data_pXT_density,Data_pXT_x_h2,Data_pXT_x_h2o,Data_B_B_vals,Data_B_T_vals,Data_B_x_h2_vals,Data_B_x_h2o_vals,Data_C_vals):
        from residual_enthalpy_data import residual_enthalpy_data
        from residual_pXT_data import residual_pXT_data
        from residual_B_data import residual_B_data
        from residual_C_data import residual_C_data
        from numpy import zeros,shape
        err1=residual_pXT_data(p,Data_pXT_P,Data_pXT_T,Data_pXT_density,Data_pXT_x_h2,Data_pXT_x_h2o)
        err2=residual_enthalpy_data(p,Data_Enthalpy_H,Data_Enthalpy_PkPa,Data_Enthalpy_T,Data_Enthalpy_x_h2,Data_Enthalpy_x_h2o)
        err3=residual_B_data(p,Data_B_B_vals,Data_B_T_vals,Data_B_x_h2_vals,Data_B_x_h2o_vals)
        err4=residual_C_data(p,Data_C_vals,Data_B_T_vals,Data_B_x_h2_vals,Data_B_x_h2o_vals)
        [m1]=shape(err1)
        [m2]=shape(err2)
        [m3]=shape(err3)
        [m4]=shape(err4)
        err_total=zeros(int(m1+m2+m3+m4))
        #print m1,m2
        #print shape(err1)
        #print shape(Data_Enthalpy_H)
        #print shape(err_total[0:m1])
        err2[len(err2)-1]=err2[len(err2)-1]*10
        err2[len(err2)-6]=err2[len(err2)-6]*10
        err2[len(err2)-4]=err2[len(err2)-4]*10
        err2[len(err2)-9]=err2[len(err2)-9]*10
        err_total[0:m1]=100.0*(err1/Data_pXT_P)
        err_total[m1:m1+m2]=100.0*(err2/Data_Enthalpy_H)
        err_total[m1+m2:m1+m2+m3]=100.0*(err3/Data_B_B_vals)
        err_total[m1+m2+m3:m1+m2+m3+m4]=100.0*(err4/Data_C_vals)
        print 'error', err_total
        print 'params',p
        return err_total
Beispiel #2
0
#p=asarray([ -2.39988683e-01,  -5.67507832e-02,  -3.43399440e+00,   5.44194356e-02,
#  -8.00207656e+01,   1.86165685e+05,   1.34772817e+01,  -1.81481992e+01,
#   1.35574437e+01,   9.79293834e+00,  -4.11498654e+00,  -1.20523004e+00,
#   2.75811665e+00,  -1.20533998e+00,   4.98924356e+00,   1.46220733e+00,
#   3.80942341e-01,   6.58968592e+00,  -7.62088181e-08,   3.81278639e-01])
#in cc/mol-> L/mol: (cc/mol)*(1 L/1000 cc)=multiply by 0.001
p=asarray([  2.38772690e+00,   6.00345713e-01,  -4.76986887e+00,  -5.28153326e-01,
             1.48640322e+02,   3.37750345e+02,  -8.02065003e-07,  -1.93552324e+01,
            -1.50381489e+02,  -5.81587781e-01,   2.47064023e-01,  -1.36572784e-02,
            -7.90363321e-01,   8.74730671e-01,   5.54290051e-01,  -3.98399346e-01,
             1.18211958e+01,   8.38816225e-01,  -1.16348077e+00,   8.07927755e-06])
CC_per_mol_to_Liters_per_mol=0.001
Data_B_B_vals=CC_per_mol_to_Liters_per_mol*asarray([-72.3,-72.86,-65.5,-60.75,-58.8,-55.52,-38.62,-23.49,-6.26,5.9,8.16,-62.34,-57.42,-62.99,-56.35,-55.78,-53.14,-40.79,-19.24,-3.42,4.05,9.94,-62.57,-59.42,-59.38,-53.98,-52.24,-47.49,-35.37,-19.17,-4.38,5.35,8.6,-58.82,-56.22,-55.97,-50.65,-50.99,-42.79,-30.66,-18.16,-5.2,6.4,8.16])
#in C converted to K
Data_B_T_vals=273.15+asarray([380,380,380,380,380,380,380,380,380,380,380,400,400,400,400,400,400,400,400,400,400,400,420,420,420,420,420,420,420,420,420,420,420,440,440,440,440,440,440,440,440,440,440,440])
Data_B_x_h2_vals=asarray([0.01,0.03,0.06,0.09,0.12,0.2,0.25,0.4,0.6,0.8,0.9,0.01,0.03,0.06,0.09,0.12,0.2,0.25,0.4,0.6,0.8,0.9,0.01,0.03,0.06,0.09,0.12,0.2,0.25,0.4,0.6,0.8,0.9,0.01,0.03,0.06,0.09,0.12,0.2,0.25,0.4,0.6,0.8,0.9])
Data_B_x_h2o_vals=1.0-Data_B_x_h2_vals#asarray([])
Data_C_vals=CC_per_mol_to_Liters_per_mol*CC_per_mol_to_Liters_per_mol*asarray([1580.57,1578.49,1439.30,1395.68,1399.75,1511.79,1047.75,806.92,605.14,503.93,565.32,1281.16,1188.67,1420.97,1296.81,1345.21,1478.18,1166.11,710.47,528.30,566.33,496.10,1381.01,1299.78,1369.50,1297.59,1289.93,1309.09,1029.32,735.58,589.89,545.00,542.15,1315.16,1258.02,1320.81,1239.98,1345.80,1150.23,914.58,745.09,656.09,508.69,557.31])                       

#[optimized_params,message]=leastsq(residual_B_data,p[:],args=(Data_B_B_vals,Data_B_T_vals,Data_B_x_h2_vals,Data_B_x_h2o_vals))
res=residual_B_data(p[:],Data_B_B_vals,Data_B_T_vals,Data_B_x_h2_vals,Data_B_x_h2o_vals)

res2=residual_C_data(p[:],Data_C_vals,Data_B_T_vals,Data_B_x_h2_vals,Data_B_x_h2o_vals)

print Data_B_B_vals
print Data_C_vals
#params=asarray([BetaT,BetaV,GammaT,GammaV])

#best,val,d=mpfit('residual_B_data',params,fprime=None,args=(Data_B_B_vals,Data_B_T_vals,Data_B_x_h2_vals,Data_B_x_h2o_vals),approx_grad=1,bounds=[(0.5,5),(0.5,5),(0.5,5),(0.5,5)],iprint=1)