Exemplo n.º 1
0
doublereal WaterPropsIAPWS::psat(doublereal temperature, int waterState) {
    doublereal densLiq = -1.0, densGas = -1.0, delGRT = 0.0;
    doublereal dp, pcorr;
    if (temperature >= T_c) {
        densGas = density(temperature, P_c, WATER_SUPERCRIT);
        setState_TR(temperature, densGas);
        return P_c;
    }
    doublereal p = psat_est(temperature);
    bool conv = false;
    for (int i = 0; i < 30; i++) {
        if (method == 1) {
            corr(temperature, p, densLiq, densGas, delGRT);
            doublereal delV = M_water * (1.0/densLiq - 1.0/densGas);
            dp = - delGRT * Rgas * temperature / delV;
        } else {
            corr1(temperature, p, densLiq, densGas, pcorr);
            dp = pcorr - p;
        }
        p += dp;

        if ((method == 1) && delGRT < 1.0E-8) {
            conv = true;
            break;
        } else {
            if (fabs(dp/p) < 1.0E-9) {
                conv = true;
                break;
            }
        }
    }
    // Put the fluid in the desired end condition
    if (waterState == WATER_LIQUID) {
        setState_TR(temperature, densLiq);
    } else if (waterState == WATER_GAS) {
        setState_TR(temperature, densGas);
    } else {
        throw Cantera::CanteraError("WaterPropsIAPWS::psat",
                                    "unknown water state input: " + Cantera::int2str(waterState));
    }
    return p;
}
Exemplo n.º 2
0
int main()
{
  read_pars("input");
  read_ensemble_pars(base_path,T,ibeta,nmass,mass,iml_un,nlights,data_list_file);
  TH=L=T/2;
  
  int ncombo=nmass*nmass;
  
  //load all the corrs
  double *buf=new double[4*ncombo*T*(njack+1)];
  FILE *fin=open_file(combine("%s/%s",base_path,corr_name).c_str(),"r");
  int stat=fread(buf,sizeof(double),4*ncombo*(njack+1)*T,fin);
  if(stat!=4*ncombo*(njack+1)*T)
    {
      cerr<<"Error loading data!"<<endl;
      exit(1);
    }
  
  jvec M(ncombo,njack);
  jvec Z2(ncombo,njack);
  
  //define minuit staff
  TMinuit minu(2);
  minu.SetPrintLevel(-1);
  minu.SetFCN(chi2);
  corr_fit=new double[TH+1];
  corr_err=new double[TH+1];
  
  int ic=0;
  //fit each combo
  for(int ims=0;ims<nmass;ims++)
    for(int imc=0;imc<nmass;imc++)
      {
	int ic1=0+2*(imc+nmass*(0+2*ims));
	int ic2=1+2*(imc+nmass*(1+2*ims));
	printf("%d %d\n",ic1,ic2);
	//take into account corr
	jvec corr(T,njack);
	jvec corr1(T,njack);
	jvec corr2(T,njack);
	corr1.put(buf+ic1*T*(njack+1));
	corr2.put(buf+ic2*T*(njack+1));
	corr=(corr1+corr2)/2;
	//choose the index of the fitting interval
	if(ims>=nlights) ifit_int=2;
	else
	  if(imc>=nlights) ifit_int=1;
	  else ifit_int=0;
	
	//simmetrize
	corr=corr.simmetrized(parity);
	int ttmin=tmin[ifit_int];
	int ttmax=tmax[ifit_int];
	jvec Mcor=effective_mass(corr),Z2cor(TH+1,njack);
	jack Meff=constant_fit(Mcor,ttmin,ttmax);
	for(int t=0;t<=TH;t++)
	  for(int ijack=0;ijack<=njack;ijack++)
	    Z2cor[t].data[ijack]=corr[t].data[ijack]/fun_fit(1,Meff[ijack],t);
	jack Z2eff=constant_fit(Z2cor,ttmin,ttmax);
	
	if(!isnan(Z2eff[0])) minu.DefineParameter(0,"Z2",Z2eff[0],Z2eff.err(),0,2*Z2eff[0]);
	if(!isnan(Meff[0])) minu.DefineParameter(1,"M",Meff[0],Meff.err(),0,2*Meff[0]);
	for(int t=tmin[ifit_int];t<=tmax[ifit_int];t++) corr_err[t]=corr.data[t].err();
	
	//jacknife analysis
	for(int ijack=0;ijack<njack+1;ijack++)
	  {
	    //copy data so that glob function may access it
	    for(int t=tmin[ifit_int];t<=tmax[ifit_int];t++) corr_fit[t]=corr.data[t].data[ijack];
	  
	    //fit
	    double dum;
	    minu.Migrad();	    
	    minu.GetParameter(0,Z2.data[ic].data[ijack],dum);
	    minu.GetParameter(1,M.data[ic].data[ijack],dum);
	  }
	
	//if((ims==iml_un||ims==nlights-1||ims==nlights||ims==nmass-1)&&
	//(imc==iml_un||imc==nlights-1||imc==nlights||imc==nmass-1))
	  {
	    //plot eff mass
	    {
	      ofstream out(combine("eff_mass_plot_%02d_%02d.xmg",ims,imc).c_str());
	      out<<"@type xydy"<<endl;
	      out<<"@s0 line type 0"<<endl;
	      out<<Mcor<<endl;
	      out<<"&"<<endl;
	      out<<"@type xy"<<endl;
	      double av_mass=M[ic].med();
	      double er_mass=M[ic].err();
	      out<<tmin[ifit_int]<<" "<<av_mass-er_mass<<endl;
	      out<<tmax[ifit_int]<<" "<<av_mass-er_mass<<endl;
	      out<<tmax[ifit_int]<<" "<<av_mass+er_mass<<endl;
	      out<<tmin[ifit_int]<<" "<<av_mass+er_mass<<endl;
	      out<<tmin[ifit_int]<<" "<<av_mass-er_mass<<endl;
	    }
	    //plot fun
	    {
	      ofstream out(combine("fun_plot_%02d_%02d.xmg",ims,imc).c_str());
	      out<<"@type xydy"<<endl;
	      out<<"@s0 line type 0"<<endl;
	      out<<corr<<endl;
	      out<<"&"<<endl;
	      out<<"@type xy"<<endl;
	      for(int t=tmin[ifit_int];t<tmax[ifit_int];t++)
		out<<t<<" "<<fun_fit(Z2[ic][njack],M[ic][njack],t)<<endl;
	    }
	  }
	
	cout<<mass[ims]<<" "<<mass[imc]<<"  "<<M[ic]<<" "<<Z2[ic]<<" "<<sqrt(Z2[ic])/(sinh(M[ic])*M[ic])*(mass[ims]+mass[imc])<<endl;
	ic++;
      }
  
  ofstream out("fitted_mass.xmg");
  out<<"@type xydy"<<endl;
  for(int ims=0;ims<nmass;ims++)
    {
      //out<<"s0 line type 0"<<endl;
      for(int imc=0;imc<nmass;imc++)
	{
	  int ic=imc+nmass*ims;
	  out<<mass[imc]<<" "<<M[ic]<<endl;
	}
      out<<"&"<<endl;
    }

  M.write_to_binfile(out_file);
  Z2.append_to_binfile(out_file);
  
  return 0;
}