예제 #1
0
파일: dnsbsd.c 프로젝트: rupole1185/EriCa
void dnsbsd_tmmt( double phi[nvar], double dep[ndep], double F_i[nvar][nvar])
{
   int ivar, idir, iidir;
   
   // density jacobian ----------------
   F_i[Pvar][Pvar] = drdp( phi);
   F_i[Pvar][Tvar] = drdt( phi);

//printf(" %f %f\n", F_i[Pvar][Pvar], F_i[Pvar][Tvar]);

   for (idir=0;idir<ndir;idir++) {
   // momentum jacobian ---------------
      F_i[Uvar+idir][Pvar]      = drdp( phi) * phi[Uvar+idir];
      F_i[Uvar+idir][Uvar+idir] = dep[Rdep];
      F_i[Uvar+idir][Tvar]      = drdt( phi) * phi[Uvar+idir];

   // enthalpy jacobian/1 -------------
      F_i[Tvar][Uvar+idir] = dep[Rdep] * phi[Uvar+idir];
   }

   // enthalpy jacobian/2 -------------
   F_i[Tvar][Pvar] = drdp( phi) - ( 1.0 * dep[Rdep] * dhdp( phi));
   F_i[Tvar][Tvar] = drdt( phi) * enthalpy( phi) + dep[Rdep] * dhdt( phi);

   for (ivar=Tvar+1;ivar<nvar;ivar++)
      F_i[ivar][ivar] = dep[Rdep];
}
  void LiquidWaterFraction<EvalT,Traits,Type>::
  evaluateFields(typename Traits::EvalData d)
  {
    const double pow6 = 1e6; //[k^{-2}], k =1000
    //  double pi = atan(1.) * 4.;
    ScalarT phiNode;

    for (std::size_t cell = 0; cell < d.numCells; ++cell)
    {
      for (std::size_t node = 0; node < numNodes; ++node)
      {
        phi(cell,node) =  ( enthalpy(cell,node) < enthalpyHs(cell,node) ) ? ScalarT(0) : pow6 * (enthalpy(cell,node) - enthalpyHs(cell,node)) / (rho_w * L);
      }
    }
  }
예제 #3
0
/**
 *  Gibbs function in Kelvin (\f$ G/R \f$) for
 *  one species. @param t temperature @param s species object
 */
double gibbs(double t, const Species& s) {
    if (s.thermoFormatType == 1) {
        double s0r = entropy(t, s);
        double h0r = enthalpy(t, s);
        return (h0r - s0r * t);
    }
    const vector_fp* cp;
    if (t > s.tmid) cp = &s.highCoeffs;
    else cp = &s.lowCoeffs;
    const vector_fp& c = *cp;
    double h0rt = c[0] + 0.5*c[1]*t + c[2]*t*t/3.0 + 0.25*c[3]*t*t*t
                  + 0.2*c[4]*t*t*t*t + c[5]/t;
    double s0r = c[0]*log(t) + c[1]*t + 0.5*c[2]*t*t + c[3]*t*t*t/3.0
                 + 0.25*c[4]*t*t*t*t + c[6];
    return t*(h0rt - s0r);
}
예제 #4
0
파일: main.c 프로젝트: simula67/engsim
  // Function which calculates the derivative of pressure
  double funcf2(char *process, char *gas, int cycl, double
		angle,double t1, double t2, double t3, double p1, double p2,
		double v1, double v2, double v1p, double v2p, double dv1, double
		dv2, double m1, double m2, double m1p, double m2p, double dm1,
		double dm2, struct data *pdat){
    double w,rho1,rho2,h1,h2;
    w=rho1=rho2=h1=h2=0.;
    if(strcmp(process,"COMPRESSION")==0){
      if(v1<=(*pdat).Vc){
	rho1=m1/(*pdat).Vc;
	check(&rho1);
      }else{
	rho1=m1/v1;
	check(&rho1);
      }
      w=1.e-5*rho1*(1./drdp(process,t1,p1,p2,rho1,rho2,pdat));
      w*=(-((sin(angle)+.5*sin(2.*angle)\
	     *(*pdat).R)/(1.-cos(angle)+.5*(*pdat).R*pow(sin(angle),2.)))-\
	  (1./rho1)*drdt(process,t1,t2,rho1,0.,pdat)*funcf1(process,gas,cycl,angle, \
							    t1,t2,t3,p1,p2,v1,v2,v1p,v2p,dv1,dv2,m1,m2,m1p,m2p,dm1,dm2,pdat));
    }
    else if(strcmp(process,"COMBUSTION")==0){
      if(strcmp(gas,"u")==0){
	h1=enthalpy(t1,MBr);
	if((m1<=1.e-10)&&(v1<=1.e-10)){ rho1=1.e-10;}
	else{ if(m1<=1.e-10){
	    rho1=1.e-10;}
	  else{
	    rho1=m1/v1;
	    check(&rho1);}
	}
	h2=enthalpy(t2,MBr);
	if((m1p<=1.e-10)&&(v1p<=1.e-10)){
	  rho1=1.e-10;}
	else{ if(m1p<=1.e-10){ rho2=1.e-10;}
	  else{
	    rho2=m1p/v1p;
	    check(&rho2);}
	}
	w=rho1*(1./drdp(process,t1,p1,p2,rho1,rho2,pdat))*(-(dv1/v1)-(1./rho1)*	\
							   drdt(process,t1,t2,rho1,rho2,pdat)* \
							   funcf1(process,gas,cycl,angle, \
								  t1,t2,t3,p1,p2,v1,v2,v1p,v2p,dv1,dv2,	\
								  m1,m2,m1p,m2p,dm1,dm2,pdat)+(dm1/m1));
      }
      else if(strcmp(gas,"b")==0){
	h1=enthalpy(t1,MBp);
	if((m2<=1.e-10)&&(v2<=1.e-10)){ rho1=1.e-10;}
	else{ if(m2<=1.e-10){
	    rho1=1.e-10;}
	  else{
	    rho1=m2/v2;
	    check(&rho1);}
	}
	h2=enthalpy(t2,MBp);
	if((m2p<=1.e-10)&&(v2p<=1.e-10)){
	  rho1=1.e-10;}
	else{ if(m2p<=1.e-10){ rho2=1.e-10;}
	  else{
	    rho2=m2p/v2p;
	    check(&rho2);}
	}
	w=rho1*(1./drdp(process,t1,p1,p2,rho1,rho2,pdat))*(-(dv2/v2)-(1./rho2)*\
							   drdt(process,t1,t2,rho1,rho2,pdat)*\
							   funcf1(process,gas,cycl,angle,\
								  t1,t2,t3,p1,p2,v1,v2,v1p,v2p,dv1,dv2,\
								  m1,m2,m1p,m2p,dm1,dm2,pdat)+(dm2/m2));
      }
    }
    else if(strcmp(process,"EXPANSION")==0){
      if(v1<=(*pdat).Vc){
	rho1=m1/(*pdat).Vc;
	check(&rho1);
      }else{
	rho1=m1/v1;
	check(&rho1);
      }
      w=1.e-5*rho1*(1./drdp(process,t1,p1,p2,rho1,0.,pdat));
      w*=(-((sin(angle)+.5*sin(2.*angle)*(*pdat).R)/(1.-cos(angle)+.5*(*pdat).R*\
						     pow(cos(angle),2.)))-(1./rho1)*drdt(process,t1,t2,rho1,0.,pdat)*\
	  funcf1(process,gas,cycl,angle,\
		 t1,t2,t3,p1,p2,v1,v2,v1p,v2p,dv1,dv2,\
		 m1,m2,m1p,m2p,dm1,dm2,pdat));
    }
    return(w);
  }
예제 #5
0
파일: main.c 프로젝트: simula67/engsim
  // ===================================================================
  // Function which calculates the derivative of temperature
  double funcf1(char *process, char *gas, int cycl, double angle,
		double t1, double t2, double t3, double p1,
		double p2, double v1, double v2, double v1p, double v2p, double
		dv1, double dv2, double m1, double m2, double m1p, double m2p,
		double dm1, double dm2, struct data *pdat){
    double w,rho1,rho2,h1,h2;
    double AlphaU, BhtaU, AlphaB, BhtaB;
    w=rho1=rho2=h1=h2=0.;
    if(strcmp(process,"COMPRESSION")==0){
      if(v1<=(*pdat).Vc){
	rho1=m1/(*pdat).Vc;
	check(&rho1);
      }else{
	rho1=m1/v1;
	check(&rho1);
      }
      w=(Bhta(process,gas,p1,p2,t1,t2,rho1,0.,0.,0.,pdat)	\
	 /Alpha(process,gas,p1,p2,t1,t2,rho1,0.,0.,0.,pdat));
      w*=(-((sin(angle)+.5*sin(2.*angle)*(*pdat).R)/(1.-cos(angle)	\
						     +.5*(*pdat).R*pow(sin(angle),2.)))-(1./(*pdat).omega) \
	  *dQwall(cycl,angle,t1,pdat)/(Bhta(process,gas,p1,p2,t1,t2,rho1,0.,0.,0.,pdat)*m1));
    }
    else if(strcmp(process,"COMBUSTION")==0){
      if(strcmp(gas,"u")==0){
	h1=enthalpy(t1,MBr);
	if((m1<=1.e-10)&&(v1<=1.e-10)){ rho1=1.e-10;}
	else{ if(m1<=1.e-10){
	    rho1=1.e-10;}
	  else{
	    rho1=m1/v1;
	    check(&rho1);}
	}
	h2=enthalpy(t2,MBr);
	if((m1p<=1.e-10)&&(v1p<=1.e-10)){
	  rho2=1.e-10;}
	else{ if(m1p<=1.e-10){ rho2=1.e-10;}
	  else{
	    rho2=m1p/v1p;
	    check(&rho2);}
	}
	AlphaU = Alpha(process,gas,p1,p2,t1,t2,rho1,rho2,h1,h2,pdat); //check(&AlphaU);
	if (AlphaU >=1.+20) AlphaU = 1.e+20;
	if (AlphaU <=-1.+20) AlphaU = -1.e+20;
	BhtaU = Bhta(process,gas,p1,p2,t1,t2,rho1,rho2,h1,h2,pdat); //check(&BhtaU);
	if (BhtaU >=1.+20) BhtaU = 1.e+20;
	if (BhtaU <=-1.+20) BhtaU = -1.e+20;
	w = BhtaU / AlphaU;
	printf("%lf \t bhtaU=%lg, alphaU=%lg\n",180.*angle/pi,BhtaU, AlphaU);
	w*=((1./(*pdat).omega)*(dm1/m1)*(1.-h1/BhtaU)-(dv1/v1)+(1./(*pdat).omega)*\
	    (-dQwall(cycl,angle,t1,pdat)+dm1*(5./2.)*(Rgas/MBr)*t1)/(BhtaU*m1));
      }
      else if(strcmp(gas,"b")==0){
	h1=enthalpy(t1,MBp);
	if((m2<=1.e-10)&&(v2<=1.e-10)){ rho1=1.e-10;}
	else{ if(m2<=1.e-10){
	    rho1=1.e-10;}
	  else{
	    rho1=m2/v2;
	    check(&rho1);}
	}
	h2=enthalpy(t2,MBp);
	if((m2p<=1.e-10)&&(v2p<=1.e-10)){
	  rho2=1.e-10;}
	else{ if(m2p<=1.e-10){ rho2=1.e-10;}
	  else{
	    rho2=m2p/v2p;
	    check(&rho2);}
	}
	AlphaB = Alpha(process,gas,p1,p2,t1,t2,rho1,rho2,h1,h2,pdat); //check(&AlphaB);
	if (AlphaB >=1.+20) AlphaB = 1.e+20;
	if (AlphaB <=-1.+20) AlphaB = -1.e+20;
	BhtaB = Bhta(process,gas,p1,p2,t1,t2,rho1,rho2,h1,h2,pdat); //check(&BhtaB);
	if (BhtaB >=1.+20) BhtaB = 1.e+20;
	if (BhtaB <=-1.+20) BhtaB = -1.e+20;
	w = BhtaB / AlphaB;
	printf("%lf \t bhtaB=%lg, alphaB=%lg\n",180.*angle/pi,BhtaB, AlphaB);
	w*=((1./(*pdat).omega)*(dm2/m2)*(1.-h1/BhtaB)-(dv2/v2)+(1./(*pdat).omega)*\
	    (-dQwall(cycl,angle,t1,pdat)+dm2*(5./2.)*(Rgas/MBr)*t3)/(BhtaB*m2));
      }
    }
    else if(strcmp(process,"EXPANSION")==0){
      if(v1<=(*pdat).Vc){
	rho1=m1/(*pdat).Vc;
	check(&rho1);
      }else{
	rho1=m1/v1;
	check(&rho1);
      }
      w=(Bhta(process,gas,p1,p2,t1,t2,rho1,0.,0.,0.,pdat)\
	 /Alpha(process,gas,p1,p2,t1,t2,rho1,0.,0.,0.,pdat));
      w*=(-((sin(angle)+.5*sin(2*angle)*(*pdat).R)/(1.-cos(angle)\
						    +.5*(*pdat).R*pow(sin(angle),2.)))-(1./(*pdat).omega)\
	  *(dQwall(cycl,angle,t1,pdat))/(Bhta(process,gas,p1,p2,t1,t2,rho1,0.,0.,0.,pdat)*m2));
    }
    return(w);
  }
예제 #6
0
/**
 *  Check the thermodynamic property parameterizations for all species.
 *  The following are verified:
 *  - The heat capacity is positive throughout the full temperature range;
 *  - The entropy at Tmin is positive;
 *  - The heat capacity, entropy, and enthalpy evaluated at Tmid using
 *    both the high and low polynomial coefficients are the same to within
 *    relative error tol
 *  - The heat capacity at Tmax is not greater than the equipartition limit
 *    for the number of atoms in the molecule
 */ 
bool checkThermo(std::ostream& log, speciesList& sp, double tol) {
    const double dt = 0.0001;
    double t, cp0, h0, s0, cp1, h1, s1;
    int nsp = static_cast<int>(sp.size());
    const int n_points = 20;

    int k;
    bool ok = true;
    for (k = 0; k < nsp; k++) {
        Species& s = sp[k];

        if (s.valid <= 0) {
            ok = false;
            log << endl << "species " << s.name 
                << " contains an error." << endl;
        }
        if (!ok) return false;
    }

    log << endl << "   Checking that cp/R is positive... ";

    for (k = 0; k < nsp; k++) {
        Species& s = sp[k];

        // check that cp is positive

        cp0 = 0.0;
        for (int j = 0; j < n_points; j++) {
            t = j*(s.thigh - s.tlow)/(n_points - 1) + s.tlow;
            
            cp0 = cp(t, s);
            if (cp0 < 0.0) {
                log << endl << "   error... Cp/R < 0 at T = " << t 
                    << " for species " << s.name << endl;
                s.valid = -1;
                ok = false;
            }
        }
    }
    if (ok) log << "ok" << endl;
    else return ok;


    // check that S(tlow) > 0
    
    log << "   Checking that the species entropies are positive... ";
    for (k = 0; k < nsp; k++) {
        Species& s = sp[k];
        if (entropy(s.tlow, s) <= 0.0) {
            log << endl << "   error... negative entropy for species " 
                << s.name << endl;
            s.valid = -1;
            ok = false;
        }
    }
    if (ok) log << "ok" << endl;
    else return ok;

    log << "   Checking that properties are continuous at the midpoint temperature... ";
    for (k = 0; k < nsp; k++) {
        Species& s = sp[k];

        // check continuity at Tmid
        t = s.tmid - dt;
        cp0 = cp(t, s);
        h0 = enthalpy(t, s) + cp0*dt;
        s0 = entropy(t, s) + dt*cp0/t;
        
        t = s.tmid + dt; 
        cp1 = cp(t, s);
        h1 = enthalpy(t, s) - cp1*dt;
        s1 = entropy(t, s) - cp1*dt/t;
        
        if (absval((cp0 - cp1)/cp0) > tol) {
            log << endl << "Warning... species " << s.name 
                << ": discontinuity in Cp at Tmid = " 
                << s.tmid << endl;
            log << "Cp/R (low, high) = " << cp0 
                << ", " << cp1 << endl;
            ok = false;
        }

        if (absval((h0 - h1)/h0) > tol) {
            log << endl << "Warning... species " << s.name 
                << ": discontinuity in enthalpy at Tmid = " 
                << s.tmid << endl;
            log << "h/R (low, high) = " 
                << h0 << ", " << h1 << endl;
            ok = false;
        }
        
        if (absval((s0 - s1)/s0) > tol) {
            log << endl << "Warning... species " << s.name 
                << ": discontinuity in entropy at Tmid = " 
                << s.tmid << endl;
            log << "s/R (low, high) = " 
                << s0 << ", " << s1 << endl;
            ok = false;
        }
    }
    if (ok) log << "ok \n\n\n";
    else log << "\n\n\n";

    log << "   Checking that cp is less that the high-temperature\n"
        << "   limiting value predicted by equipartition of energy.\n";
    log << "   Note that this limit does not account for the electronic\n"
        << "   contribution to cp, and so may be violated in some cases."
        << endl << endl;
    

    for (k = 0; k < nsp; k++) {
        Species& s = sp[k];
        
        // check that cp at Tmax is less than the equipartion value
        // This does not include any possible electronic contribution
        
        cp0 = cp(s.thigh, s);
        int nel = static_cast<int>(s.elements.size());
        int i;
        double na = 0.0;
        for (i = 0; i < nel; i++) 
            if (s.elements[i].name != "E") na += s.elements[i].number;
        int natoms = int(floor(na));
        double cpmax;
        switch (natoms) {
        case 1: cpmax = 2.5; break;
        case 2: cpmax = 4.5; break;
        default: cpmax = 3.0*natoms - 3.0;
        }
        
        if (cp0 > cpmax) {
            double over = 100.0*(cp0 - cpmax)/cpmax;
            log << endl << "Warning... species " << s.name 
                << ": cp(Tmax) greater than equipartition value \nby "
                <<  over << " percent.";
            if ((natoms > 2) && (cp0 - cpmax < 0.5)) 
                log << endl << "      (if molecule is linear, cp is ok)" 
                    << endl;
        }
    }
    
    return valid(sp);
}