int main(int argc, char** argv) {
  int i;
  //double ca[10];

  std::string ctv = CANTERA_VERSION;
  bool canHandle = ctversionCanHandle(ctv);

  try {
    string id;
    Cantera::PrintCtrl pc;

    XML_Node *xc = new XML_Node();
    string path = findInputFile("ReactionSurf.xml");
    ctml::get_CTML_Tree(xc, path);

    XML_Node * const xg = xc->findNameID("phase", "reaction_surface");
    if (!xg) {
      throw CanteraError("couldn't find file", "");
    }
    ThermoPhase *surfTP = newPhase(*xg);

  
    ThermoPhase *gasTP =  newPhase("gas.xml", "");
    //IdealGasPhase *gasTP = new IdealGasPhase("gas.xml", "");

    string s_cao_s = "CaO_Solid.xml";
    id = "CaO(S)";
    Cantera::ThermoPhase *cao_s = Cantera::newPhase(s_cao_s, id);

    string  s_caco3_s = "CaCO3_Solid.xml";
    id = "CaCO3(S)";
    Cantera::ThermoPhase *caco3_s = Cantera::newPhase(s_caco3_s, id);

    string  s_c_s = "C_Solid.xml";
    id = "C(S)";
    Cantera::ThermoPhase *c_s = Cantera::newPhase(s_c_s, id);

    string  s_fe3o4_s = "Fe3O4_Solid.xml";
    id = "Fe3O4(S)";
    Cantera::ThermoPhase *fe3o4_s = Cantera::newPhase(s_fe3o4_s, id);

    string  s_feo_s = "FeO_Solid.xml";
    id = "FeO(S)";
    Cantera::ThermoPhase *feo_s = Cantera::newPhase(s_feo_s, id);


    string  s_fe_s = "Fe_Solid.xml";
    id = "Fe(S)";
    Cantera::ThermoPhase *fe_s = Cantera::newPhase(s_fe_s, id);

    //   string s_reactSurf = "ReactionSurf.xml";
    // id = "reaction_surface";
    //Cantera::ThermoPhase *surfTP = Cantera::newPhase(s_reactSurf, id);


    vector<ThermoPhase *> phaseList;
     
    phaseList.push_back(gasTP);
    phaseList.push_back(cao_s);
    phaseList.push_back(caco3_s);
    phaseList.push_back(c_s);
    phaseList.push_back(fe3o4_s);
    phaseList.push_back(feo_s);
    phaseList.push_back(fe_s);
    phaseList.push_back(surfTP);
    InterfaceKinetics *iKin_ptr = new InterfaceKinetics();
    importKinetics(*xg, phaseList, iKin_ptr);
    //    int nr = iKin_ptr->nReactions();
   

    double x[20];
    for (i = 0; i < 20; i++) x[i] = 0.0;
    double mll[20];
    for (i = 0; i < 20; i++) mll[i] = 0.0;
    //int ikca0 = iKin_ptr->kineticsSpeciesIndex("CaO(S)");
    //int ikcaco3 = iKin_ptr->kineticsSpeciesIndex("CaCO3(S)");
    //int ikco2 = iKin_ptr->kineticsSpeciesIndex("CO2");


    int igco2 = gasTP->speciesIndex("CO2");
    int igo2  = gasTP->speciesIndex("O2");
    int ign2  = gasTP->speciesIndex("N2");

    mll[igco2] = 0.2;
    mll[igo2] = 0.1;
    mll[ign2] = 0.7;
    double Temp = 1000.;
    gasTP->setState_TPX(Temp, OneAtm, mll);
   
    double p = 20.0*OneAtm/760.0;
    
    for (i = 0; i < 20; i++) x[i] = 0.0;
   

    for (i = 0; i < 20; i++) x[i] = 0.0;
    x[0] = 1.0;


    // Set the bath gas of TempK and 1 atm
    cao_s->setState_TP(Temp, OneAtm);
    caco3_s->setState_TP(Temp, OneAtm);
    c_s->setState_TP(Temp, OneAtm);
    fe3o4_s->setState_TP(Temp, OneAtm);
    surfTP->setState_TP(Temp, OneAtm);

    // Throw some asserts in here to test that they compile
    AssertTrace(p == p); 
    AssertThrow(p == p, "main"); 
    AssertThrowMsg(i == 20, "main", "are you kidding"); 

    double src[20];
    for (i = 0; i < 20; i++) src[i] = 0.0;
    //iKin_ptr->getNetProductionRates(src);
    double deltaG[20], deltaGSS[20];

    // Preamble
    printf("==========================================================================\n");
    printf("   StoichSolidKinetics Test \n");
    printf("==========================================================================\n");

    printf("  Tests for the proper behavior of heterogeneous reactions \n");
    printf("  when phases may or may not exist:\n");
    printf("        CaCO3(s) =   CO2(g) +  CaO(s)  \n");
    printf("\n\n");

    for (int ktrials = 0; ktrials < 2; ktrials++) {

    iKin_ptr->getDeltaSSGibbs(deltaGSS);

    cout << "   deltaGSS      = ";
    pc.pr_de(deltaGSS[0], 4, 13);
    cout << "\n";

    iKin_ptr->getDeltaGibbs(deltaG);
    cout << "   deltaG        = ";
    pc.pr_de(deltaG[0], 4, 13);
    cout << "\n";

    double mu[10];
    gasTP->getChemPotentials(mu);
    double mu_CO2 = mu[igco2];
    cout << "   mu_CO2(g)     = ";
    pc.pr_de(mu_CO2, 4, 13);
    cout << "\n";

 
    cao_s->getGibbs_RT(mu);
    double mu_cao = mu[0] * GasConstant * Temp;
    cout << "   mu_cao(s)     = ";
    pc.pr_de(mu_cao, 4, 13);
    cout << "\n";

    caco3_s->getChemPotentials(mu);
    double mu_caco3  = mu[0];
    cout << "   mu_caco3      = ";
    pc.pr_de(mu_caco3, 4, 13);
    cout << "\n";

    double deltaG_calc =  mu_CO2 +  mu_cao - mu_caco3;
    cout << "   deltaG_calc   = ";
    pc.pr_de(deltaG_calc, 4, 13);
    cout << "\n";
 
    double act[20];
    gasTP->getActivities(act);
    double act_CO2 = act[igco2];
    cout << "   act_CO2       = ";
    pc.pr_de(act_CO2, 4, 13);
    cout << "\n";

    cao_s->getActivities(act);
    cout << "   act_cao(s)    = ";
    pc.pr_de(act[0], 4, 13);
    cout << "\n";

    caco3_s->getActivities(act);
    cout << "   act_caco3(s)  = ";
    pc.pr_de(act[0], 4, 13);
    cout << "\n";

 
    vector<double> Rfwd(5);
    vector<double> Rrev(5);
    vector<double> Rnet(5);
    printf("==========================================================================\n");
    printf("  OK base problem assuming that all phases exist:\n");
    printf("==========================================================================\n");

  
    iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet));
    cout << "ROP_net       = ";
    pc.pr_de(Rnet[0], 4, 13);
    cout << endl;

  
    iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd));
    cout << "ROP_forward   = ";
    pc.pr_de(Rfwd[0], 4, 13);
    cout << endl;

    iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev));
    cout << "ROP_reverse   = ";
    pc.pr_de(Rrev[0], 4, 13);
    cout << endl;

    double kfwd[5];
    iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd));
    cout << "    kfwd      = ";
    pc.pr_de(kfwd[0], 4, 13);
    cout << endl;

    double krev[5];
    iKin_ptr->getRevRateConstants(DATA_PTR(krev));
    cout << "    krev      = ";
    pc.pr_de(krev[0], 4, 13);
    cout << endl;


#if  defined (CANTERA_VERSION_18_LTD) || defined (CANTERA_VERSION_18_XXX)

    printf("==========================================================================\n");
    printf("  OK Changing the problem setting CaO(S) phase to nonexistent:\n");
    printf("==========================================================================\n");

    int ip_cao = iKin_ptr->phaseIndex("CaO(S)");
    iKin_ptr->setPhaseExistence(ip_cao, false);
    iKin_ptr->setPhaseStability(ip_cao, true);

    iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet));
    cout << "ROP_net       = ";
    pc.pr_de(Rnet[0], 4, 13);
    cout << endl;

  
    iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd));
    cout << "ROP_forward   = ";
    pc.pr_de(Rfwd[0], 4, 13);
    cout << endl;

    iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev));
    cout << "ROP_reverse   = ";
    pc.pr_de(Rrev[0], 4, 13);
    cout << endl;


   
    iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd));
    cout << "    kfwd      = ";
    pc.pr_de(kfwd[0], 4, 13);
    cout << endl;

    iKin_ptr->getRevRateConstants(DATA_PTR(krev));
    cout << "    krev      = ";
    pc.pr_de(krev[0], 4, 13);
    cout << endl;

    printf("==========================================================================\n");
    printf("  OK Changing the problem setting CaCO3(S) phase to nonexistent:\n");
    printf("==========================================================================\n");

    int ip_caco3 = iKin_ptr->phaseIndex("CaCO3(S)");
    iKin_ptr->setPhaseExistence(ip_caco3, false);
    iKin_ptr->setPhaseStability(ip_caco3, true);


    iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet));
    cout << "ROP_net       = ";
    pc.pr_de(Rnet[0], 4, 13);
    cout << endl;

  
    iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd));
    cout << "ROP_forward   = ";
    pc.pr_de(Rfwd[0], 4, 13);
    cout << endl;

    iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev));
    cout << "ROP_reverse   = ";
    pc.pr_de(Rrev[0], 4, 13);
    cout << endl;

   
    iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd));
    cout << "    kfwd      = ";
    pc.pr_de(kfwd[0], 4, 13);
    cout << endl;

 
    iKin_ptr->getRevRateConstants(DATA_PTR(krev));
    cout << "    krev      = ";
    pc.pr_de(krev[0], 4, 13);
    cout << endl;


    printf("==========================================================================\n");
    printf("  OK Changing the problem setting CaO(S) phase to existent, CaCO3 nonexistent:\n");
    printf("==========================================================================\n");


    iKin_ptr->setPhaseExistence(ip_cao, true);

    iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet));
    cout << "ROP_net       = ";
    pc.pr_de(Rnet[0], 4, 13);
    cout << endl;

  
    iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd));
    cout << "ROP_forward   = ";
    pc.pr_de(Rfwd[0], 4, 13);
    cout << endl;

    iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev));
    cout << "ROP_reverse   = ";
    pc.pr_de(Rrev[0], 4, 13);
    cout << endl;

   
    iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd));
    cout << "    kfwd      = ";
    pc.pr_de(kfwd[0], 4, 13);
    cout << endl;

 
    iKin_ptr->getRevRateConstants(DATA_PTR(krev));
    cout << "    krev      = ";
    pc.pr_de(krev[0], 4, 13);
    cout << endl;


    printf("==========================================================================\n");
    printf("  OK Changing the problem setting Gas phase to nonexistent, CaCO3 nonexistent:\n");
    printf("==========================================================================\n");

    int ip_gas = iKin_ptr->phaseIndex("air");
    iKin_ptr->setPhaseExistence(ip_gas, false);
    iKin_ptr->setPhaseStability(ip_gas, true);

    iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet));
    cout << "ROP_net       = ";
    pc.pr_de(Rnet[0], 4, 13);
    cout << endl;

  
    iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd));
    cout << "ROP_forward   = ";
    pc.pr_de(Rfwd[0], 4, 13);
    cout << endl;

    iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev));
    cout << "ROP_reverse   = ";
    pc.pr_de(Rrev[0], 4, 13);
    cout << endl;

   
    iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd));
    cout << "    kfwd      = ";
    pc.pr_de(kfwd[0], 4, 13);
    cout << endl;

 
    iKin_ptr->getRevRateConstants(DATA_PTR(krev));
    cout << "    krev      = ";
    pc.pr_de(krev[0], 4, 13);
    cout << endl;


    printf("==========================================================================\n");
    printf("  OK Changing the problem setting to all phases existing:\n");
    printf("==========================================================================\n");
    iKin_ptr->setPhaseExistence(ip_gas, true);
    iKin_ptr->setPhaseExistence(ip_cao, true);
    iKin_ptr->setPhaseExistence(ip_caco3, true);


    iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet));
    cout << "ROP_net       = ";
    pc.pr_de(Rnet[0], 4, 13);
    cout << endl;

  
    iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd));
    cout << "ROP_forward   = ";
    pc.pr_de(Rfwd[0], 4, 13);
    cout << endl;

    iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev));
    cout << "ROP_reverse   = ";
    pc.pr_de(Rrev[0], 4, 13);
    cout << endl;

   
    iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd));
    cout << "    kfwd      = ";
    pc.pr_de(kfwd[0], 4, 13);
    cout << endl;

 
    iKin_ptr->getRevRateConstants(DATA_PTR(krev));
    cout << "    krev      = ";
    pc.pr_de(krev[0], 4, 13);
    cout << endl;

#endif

    if (ktrials == 0) {
      printf("==========================================================================\n");
      printf("  OK Changing the problem setting so that forward rate if faster:\n");
      printf("==========================================================================\n");
      mll[igco2] = 0.002;
      mll[igo2] =  0.1;
      mll[ign2] =  0.898;
      gasTP->setState_TPX(Temp, OneAtm, mll);
    }

    }


    printf("==========================================================================\n");

  }
  catch (CanteraError) {
    showErrors(cout);
  }

  return 0;
}
Exemple #2
0
int main(int argc, char** argv) {
    int i, k;
    string infile = "diamond.xml";
 
    try {
      XML_Node *xc = new XML_Node();
      string path = findInputFile(infile);
      ctml::get_CTML_Tree(xc, path);

      XML_Node * const xg = xc->findNameID("phase", "gas");
      ThermoPhase *gasTP = newPhase(*xg);
      int nsp = gasTP->nSpecies();
      cout << "Number of species = " << nsp << endl;

      XML_Node * const xd = xc->findNameID("phase", "diamond");
      ThermoPhase *diamondTP = newPhase(*xd);
      int nsp_diamond = diamondTP->nSpecies();
      cout << "Number of species in diamond = " << nsp_diamond << endl;


      XML_Node * const xs = xc->findNameID("phase", "diamond_100");
      ThermoPhase *diamond100TP = newPhase(*xs);
      //SurfPhase *diamond100TP = new SurfPhase(*xs);
      int nsp_d100 = diamond100TP->nSpecies();
      cout << "Number of species in diamond_100 = " << nsp_d100 << endl;

      vector<ThermoPhase *> phaseList;
      phaseList.push_back(gasTP);     
      phaseList.push_back(diamondTP);
      phaseList.push_back(diamond100TP);
      InterfaceKinetics *iKin_ptr = new InterfaceKinetics();
      importKinetics(*xs, phaseList, iKin_ptr);
      int nr = iKin_ptr->nReactions();
      cout << "Number of reactions = " << nr << endl;

      double x[20];
      for (i = 0; i < 20; i++) x[i] = 0.0;
      x[0] = 0.0010;
      x[1] = 0.9888;
      x[2] = 0.0002;
      x[3] = 0.0100;
      double p = 20.0*OneAtm/760.0;

      gasTP->setState_TPX(1200., p, x);
      
      for (i = 0; i < 20; i++) x[i] = 0.0;
      int i0 = diamond100TP->speciesIndex("c6H*");
      x[i0] = 0.1;
      int i1 = diamond100TP->speciesIndex("c6HH");
      x[i1] = 0.9;
      diamond100TP->setState_TX(1200., x);

      for (i = 0; i < 20; i++) x[i] = 0.0;
      x[0] = 1.0;
      diamondTP->setState_TPX(1200., p, x);

      iKin_ptr->advanceCoverages(100.);

      // Throw some asserts in here to test that they compile
      AssertTrace(p == p); 
      AssertThrow(p == p, "main"); 
      AssertThrowMsg(i == 20, "main", "are you kidding"); 

      double src[20];
      for (i = 0; i < 20; i++) src[i] = 0.0;
      iKin_ptr->getNetProductionRates(src);
      double sum = 0.0;
      double naH = 0.0;
      for (k = 0; k < 13; k++) {
	if (k < 4) {
	  naH = gasTP->nAtoms(k, 0);
	} else if (k == 4) {
	  naH = 0;
	} else if (k > 4) {
	  int itp = k - 5;
	  naH = diamond100TP->nAtoms(itp, 0);
	}
	cout << k << "  " << naH << "  " ;
	printDbl(src[k]);
	cout << endl;
	sum += naH * src[k];
	
      }
  
      cout << "sum = ";
      printDbl(sum);
      cout << endl; 
      double mwd = diamondTP->molecularWeight(0);
      double dens = diamondTP->density();
      double gr = src[4] * mwd / dens;
      gr *= 1.0E6 * 3600.;
      cout << "growth rate = " << gr << " microns per hour" << endl;

      
      diamond100TP->getMoleFractions(x);
      cout << "Coverages:" << endl;
      for (k = 0; k < 8; k++) {
	cout << k << "   " << diamond100TP->speciesName(k) 
	     << "   " 
	     << x[k] << endl;
      }    
    }
    catch (CanteraError) {
      showErrors(cout);
    }

    return 0;
}
Exemple #3
0
int main()
{
#ifdef _MSC_VER
    _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
    double pres;
    try {

        XML_Node* xc = get_XML_File("liquidvapor.xml");
        XML_Node* const xs = xc->findNameID("phase", "water");
        thermo_t_double* water_tp = newPhase<doublereal>(*xs);
        PureFluidPhase* w = dynamic_cast <PureFluidPhase*>(water_tp);

        /*
         * Print out the triple point conditions
         */
        double temp = 273.16;
        pres = w->satPressure(temp);
        printf("psat(%g) = %.4g\n", temp, pres);
        double presLow = 1.0E-2;
        temp = 298.15;
        double oneBar = 1.0E5;

        printf("Comparisons to NIST: (see http://webbook.nist.gov):\n\n");

        w->setDensity(1.0E-8);
        w->setState_TP(temp, presLow);
        double h = w->enthalpy_mole();
        printf("H0(298.15) = %g J/kmol\n", h);
        double h298 = h;

        double s = w->entropy_mole();
        s -= GasConstant * log(oneBar/presLow);
        printf("S0(298.15) = %g J/kmolK\n", s);


        double T[20];
        T[0] = 298.15;
        T[1] = 500.;
        T[2] = 600.;
        T[3] = 1000.;

        double Cp0, delh0, delg0, g;

        printf("\nIdeal Gas Standard State:\n");
        printf("        T      Cp0           S0     "
               " -(G0-H298)/T       H0-H298\n");
        printf("       (K)   (J/molK)     (J/molK)  "
               "   (J/molK)        (kJ/mol)\n");
        for (int i = 0; i < 4; i++) {
            temp = T[i];
            w->setState_TP(temp, presLow);
            h = w->enthalpy_mole();
            delh0 = tvalue(h - h298, 1.0E-6);
            g = w->gibbs_mole();
            delg0 = (g - h298)/temp + GasConstant * log(oneBar/presLow);
            Cp0 = w->cp_mole();
            s = w->entropy_mole();
            s -= GasConstant * log(oneBar/presLow);
            printf("%10g %10g %13.4g %13.4g %13.4g\n", temp, Cp0*1.0E-3, s*1.0E-3,
                   -delg0*1.0E-3, delh0*1.0E-6);
        }
        printf("\n\n");

        temp = 298.15;
        w->setDensity(1000.);
        w->setState_TP(temp, oneBar);
        h = w->enthalpy_mole();
        printf("H_liq(298.15, onebar) = %g J/kmol\n", h);
        double h298l = h;
        s = w->entropy_mole();
        printf("S_liq(298.15, onebar) = %g J/kmolK\n", s);


        T[0] = 273.19;
        T[1] = 298.15;
        T[2] = 300.;
        T[3] = 373.15;
        T[4] = 400.;
        T[5] = 500.;
        printf("\nLiquid 1bar or psat Standard State\n");
        printf("       T     press         psat            Cp0            S0   "
               "  -(G0-H298)/T       H0-H298\n");
        printf("      (K)     (bar)        (bar)        (J/molK)       (J/molK)"
               "     (J/molK)        (kJ/mol)\n");

        for (int i = 0; i < 6; i++) {
            temp = T[i];
            double psat = w->satPressure(temp);
            double press = oneBar;
            if (psat > press) {
                press = psat*1.002;
            }
            w->setState_TP(temp, press);
            h = w->enthalpy_mole();
            delh0 = tvalue(h - h298l, 1.0E-6);
            g = w->gibbs_mole();
            delg0 = (g - h298l)/temp;
            Cp0 = w->cp_mole();
            s = w->entropy_mole();
            printf("%10g %10g %12g %13.4g %13.4g %13.4g %13.4g\n", temp, press*1.0E-5,
                   psat*1.0E-5,
                   Cp0*1.0E-3, s*1.0E-3,
                   -delg0*1.0E-3, delh0*1.0E-6);
        }

        printf("\nLiquid Densities:\n");
        printf("       T     press         psat        Density          molarVol   "
               "\n");
        printf("      (K)     (bar)        (bar)      (kg/m3)          (m3/kmol)"
               "\n");
        for (int i = 0; i < 6; i++) {
            temp = T[i];
            double psat = w->satPressure(temp);
            double press = oneBar;
            if (psat > press) {
                press = psat*1.002;
            }
            w->setState_TP(temp, press);
            double d = w->density();
            double mw = w->molecularWeight(0);
            double vbar = mw/d;
            // not implemented
            //w.getPartialMolarVolumes(&vbar);

            printf("%10g %10g %12g %13.4g %13.4g\n", temp, press*1.0E-5,
                   psat*1.0E-5, d, vbar);

        }

        printf("\n\nTable of increasing Enthalpy at 1 atm\n\n");
        double dens;
        printf("  Enthalpy,   Temperature,     x_Vapor,    Density, Entropy_mass, Gibbs_mass\n");
        w->setState_TP(298., OneAtm);
        double Hset = w->enthalpy_mass();
        double vapFrac = w->vaporFraction();
        double Tcalc = w->temperature();
        double Scalc = w->entropy_mass();
        double Gcalc = w->gibbs_mass();
        dens = w->density();
        printf(" %10g, %10g, %10g, %11.5g, %11.5g, %11.5g\n", Hset , Tcalc, vapFrac, dens, Scalc, Gcalc);
        w->setState_HP(Hset, OneAtm);
        vapFrac = w->vaporFraction();
        Tcalc = w->temperature();
        dens = w->density();
        Scalc = w->entropy_mass();
        Gcalc = w->gibbs_mass();
        printf(" %10g, %10g, %10g, %11.5g, %11.5g, %11.5g\n", Hset , Tcalc, vapFrac, dens, Scalc, Gcalc);

        double deltaH = 100000.;
        for (int i = 0; i < 40; i++) {
            Hset += deltaH;
            w->setState_HP(Hset, OneAtm);
            vapFrac = w->vaporFraction();
            Tcalc = w->temperature();
            dens = w->density();
            Scalc = w->entropy_mass();
            Gcalc = w->gibbs_mass();
            printf(" %10g, %10g, %10g, %11.5g, %11.5g, %11.5g\n", Hset , Tcalc, vapFrac, dens, Scalc, Gcalc);
        }


        printf("Critical Temp     = %10.3g K\n", w->critTemperature());
        printf("Critical Pressure = %10.3g atm\n", w->critPressure()/OneAtm);
        printf("Critical Dens     = %10.3g kg/m3\n", w->critDensity());

        delete w;
    } catch (CanteraError& err) {
        std::cout << err.what() << std::endl;
        Cantera::appdelete();
        return -1;
    }


    return 0;
}
Exemple #4
0
int main(int argc, char** argv)
{
#ifdef _MSC_VER
    _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
    try {
        if (argc != 2) {
            cout << "Error: no input file specified.\n"
                 "Choose either 'noxNeg.cti' or 'noxNeg_blessed.xml" << endl;
            exit(-1);
        }
        std::string infile(argv[1]);

        size_t i;
        double x[20];
        double cdot[20], ddot[20];

        XML_Node* xc = new XML_Node();
        string path = findInputFile(infile);
        ctml::get_CTML_Tree(xc, path);

        XML_Node* const xg = xc->findNameID("phase", "air");
        ThermoPhase* gasTP = newPhase(*xg);
        size_t nsp = gasTP->nSpecies();
        cout << "Number of species = " << nsp << endl;


        vector<ThermoPhase*> phaseList;
        phaseList.push_back(gasTP);
        GasKinetics* iKin_ptr = new GasKinetics();
        importKinetics(*xg, phaseList, iKin_ptr);
        size_t nr = iKin_ptr->nReactions();
        cout << "Number of reactions = " << nr << endl;

        size_t iH = gasTP->speciesIndex("H");
        size_t iO2 = gasTP->speciesIndex("O2");
        size_t iH2O = gasTP->speciesIndex("H2O");
        size_t iNH = gasTP->speciesIndex("NH");
        size_t iNO = gasTP->speciesIndex("NO");
        size_t iN2O = gasTP->speciesIndex("N2O");

        for (i = 0; i < nsp; i++) {
            x[i] = 0.0;
        }
        x[iH2O] = 1.0 /2.0;
        x[iH]   = 0.2 /2.0;
        x[iO2]  = 0.3 /2.0;
        x[iNH]  = 0.05/2.0;
        x[iNO]  = 0.05/2.0;
        x[iN2O]  = 0.05/2.0;

        double p = OneAtm;

        gasTP->setState_TPX(2000., p, x);


        double src[20];
        for (i = 0; i < 20; i++) {
            src[i] = 0.0;
        }
        iKin_ptr->getNetProductionRates(src);

        for (i = 0; i < nsp; i++) {
            string sSt = gasTP->speciesName(i);
            printf("rop [ %.4d:%s ] = %.5g \n", (int) i, sSt.c_str(), src[i]);
        }

        size_t nReactions = iKin_ptr->nReactions();
        cout << "number of reactions = " << nReactions << endl;

        double fwd_rop[20];
        double rev_rop[20];
        iKin_ptr->getFwdRatesOfProgress(fwd_rop);
        iKin_ptr->getRevRatesOfProgress(rev_rop);
        for (i = 0; i < nReactions; i++) {
            printf("fwd_rop[%3d] = %13g    rev_rop[%3d] = %13g\n", (int) i,
                   fwd_rop[i], (int) i, rev_rop[i]);
        }



        iKin_ptr->getCreationRates(cdot);
        iKin_ptr->getDestructionRates(ddot);


        return 0;
    } catch (CanteraError& err) {
        std::cerr << err.what() << std::endl;
        cerr << "program terminating." << endl;
        return -1;
    }
}
Exemple #5
0
int main(int argc, char** argv)
{
#if defined(_MSC_VER) && _MSC_VER < 1900
    _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
    if (argc != 2) {
        cout << "Error: no input file specified.\n"
             "Choose either 'diamond.cti' or 'diamond_blessed.xml" << endl;
        exit(-1);
    }
    std::string infile(argv[1]);
    int i, k;

    try {
        XML_Node* xc = get_XML_File(infile);

        XML_Node* const xg = xc->findNameID("phase", "gas");
        ThermoPhase* gasTP = newPhase(*xg);
        size_t nsp = gasTP->nSpecies();
        cout.precision(4);
        cout << "Number of species = " << nsp << endl;

        XML_Node* const xd = xc->findNameID("phase", "diamond");
        ThermoPhase* diamondTP = newPhase(*xd);
        size_t nsp_diamond = diamondTP->nSpecies();
        cout << "Number of species in diamond = " << nsp_diamond << endl;


        XML_Node* const xs = xc->findNameID("phase", "diamond_100");
        ThermoPhase* diamond100TP = newPhase(*xs);
        size_t nsp_d100 = diamond100TP->nSpecies();
        cout << "Number of species in diamond_100 = " << nsp_d100 << endl;

        vector<ThermoPhase*> phaseList { gasTP, diamondTP, diamond100TP };
        InterfaceKinetics* iKin_ptr = new InterfaceKinetics();
        importKinetics(*xs, phaseList, iKin_ptr);
        size_t nr = iKin_ptr->nReactions();
        cout << "Number of reactions = " << nr << endl;

        double x[20];
        for (i = 0; i < 20; i++) {
            x[i] = 0.0;
        }
        x[0] = 0.0010;
        x[1] = 0.9888;
        x[2] = 0.0002;
        x[3] = 0.0100;
        double p = 20.0*OneAtm/760.0;

        gasTP->setState_TPX(1200., p, x);

        for (i = 0; i < 20; i++) {
            x[i] = 0.0;
        }
        size_t i0 = diamond100TP->speciesIndex("c6H*");
        x[i0] = 0.1;
        size_t i1 = diamond100TP->speciesIndex("c6HH");
        x[i1] = 0.9;
        diamond100TP->setState_TX(1200., x);

        for (i = 0; i < 20; i++) {
            x[i] = 0.0;
        }
        x[0] = 1.0;
        diamondTP->setState_TPX(1200., p, x);

        iKin_ptr->advanceCoverages(100.);

        // Throw some asserts in here to test that they compile
        AssertTrace(p == p);
        AssertThrow(p == p, "main");
        AssertThrowMsg(i == 20, "main", "are you kidding");

        double src[20];
        for (i = 0; i < 20; i++) {
            src[i] = 0.0;
        }
        iKin_ptr->getNetProductionRates(src);
        double sum = 0.0;
        double naH = 0.0;
        for (k = 0; k < 13; k++) {
            if (k < 4) {
                naH = gasTP->nAtoms(k, 0);
            } else if (k == 4) {
                naH = 0;
            } else if (k > 4) {
                int itp = k - 5;
                naH = diamond100TP->nAtoms(itp, 0);
            }
            cout << k << "  " << naH << "  " ;
            printDbl(src[k]);
            cout << endl;
            sum += naH * src[k];

        }

        cout << "sum = ";
        printDbl(sum);
        cout << endl;
        double mwd = diamondTP->molecularWeight(0);
        double dens = diamondTP->density();
        double gr = src[4] * mwd / dens;
        gr *= 1.0E6 * 3600.;
        cout << "growth rate = " << gr << " microns per hour" << endl;


        diamond100TP->getMoleFractions(x);
        cout << "Coverages:" << endl;
        for (k = 0; k < 8; k++) {
            cout << k << "   " << diamond100TP->speciesName(k)
                 << "   "
                 << x[k] << endl;
        }
    } catch (CanteraError& err) {
        std::cout << err.what() << std::endl;
    }

    return 0;
}
int main(int argc, char** argv)
{
    int i, k;
    string infile = "diamond.xml";

    try {
        XML_Node* xc = get_XML_File(infile);
        cout.precision(3);

        XML_Node* const xg = xc->findNameID("phase", "gas");
        ThermoPhase* gasTP = newPhase(*xg);
        int nsp = gasTP->nSpecies();
        cout << "Number of species = " << nsp << endl;

        XML_Node* const xd = xc->findNameID("phase", "diamond");
        ThermoPhase* diamondTP = newPhase(*xd);
        int nsp_diamond = diamondTP->nSpecies();
        cout << "Number of species in diamond = " << nsp_diamond << endl;


        XML_Node* const xs = xc->findNameID("phase", "diamond_100");
        ThermoPhase* diamond100TP = newPhase(*xs);
        int nsp_d100 = diamond100TP->nSpecies();
        cout << "Number of species in diamond_100 = " << nsp_d100 << endl;

        vector<ThermoPhase*> phaseList { gasTP, diamondTP, diamond100TP };
        InterfaceKinetics* iKin_ptr = new InterfaceKinetics();
        importKinetics(*xs, phaseList, iKin_ptr);
        int nr = iKin_ptr->nReactions();
        cout << "Number of reactions = " << nr << endl;

        double x[20];
        for (i = 0; i < 20; i++) {
            x[i] = 0.0;
        }
        x[0] = 0.0010;
        x[1] = 0.9888;
        x[2] = 0.0002;
        x[3] = 0.0100;
        double p = 20.0*OneAtm/760.0;

        gasTP->setState_TPX(1200., p, x);

        for (i = 0; i < 20; i++) {
            x[i] = 0.0;
        }
        int i0 = diamond100TP->speciesIndex("c6H*");
        x[i0] = 0.1;
        int i1 = diamond100TP->speciesIndex("c6HH");
        x[i1] = 0.9;
        diamond100TP->setState_TX(1200., x);

        for (i = 0; i < 20; i++) {
            x[i] = 0.0;
        }
        x[0] = 1.0;
        diamondTP->setState_TPX(1200., p, x);

        iKin_ptr->advanceCoverages(100.);

        // Throw some asserts in here to test that they compile
        AssertTrace(p == p);
        AssertThrow(p == p, "main");
        AssertThrowMsg(i == 20, "main", "are you kidding");

        double src[20];
        for (i = 0; i < 20; i++) {
            src[i] = 0.0;
        }
        iKin_ptr->getNetProductionRates(src);
        double sum = 0.0;
        double naH = 0.0;
        for (k = 0; k < 13; k++) {
            if (k < 4) {
                naH = gasTP->nAtoms(k, 0);
            } else if (k == 4) {
                naH = 0;
            } else if (k > 4) {
                int itp = k - 5;
                naH = diamond100TP->nAtoms(itp, 0);
            }
            cout << k << "  " << naH << "  " ;
            printDbl(src[k]);
            cout << endl;
            sum += naH * src[k];

        }

        cout << "sum = ";
        printDbl(sum);
        cout << endl;
        double mwd = diamondTP->molecularWeight(0);
        double dens = diamondTP->density();
        double gr = src[4] * mwd / dens;
        gr *= 1.0E6 * 3600.;
        cout << "growth rate = " << gr << " microns per hour" << endl;


        diamond100TP->getMoleFractions(x);
        cout << "Coverages:" << endl;
        for (k = 0; k < 8; k++) {
            cout << k << "   " << diamond100TP->speciesName(k)
                 << "   "
                 << x[k] << endl;
        }


        /*********************************************************************************/
        /*
         *  OK NOW DUPLICATE EVERYTHING AND RECALCULATE
         */
        ThermoPhase* gasTP_dupl         = gasTP->duplMyselfAsThermoPhase();
        ThermoPhase* diamondTP_dupl     = diamondTP->duplMyselfAsThermoPhase();
        ThermoPhase* diamond100TP_dupl  = diamond100TP->duplMyselfAsThermoPhase();

        vector<ThermoPhase*> phaseList_dupl { gasTP_dupl, diamondTP_dupl,
                                              diamond100TP_dupl };
        InterfaceKinetics* iKin_ptr_dupl = new InterfaceKinetics();
        importKinetics(*xs, phaseList_dupl, iKin_ptr_dupl);
        int nr_dupl = iKin_ptr_dupl->nReactions();
        cout << "Number of reactions = " << nr_dupl << endl;


        for (i = 0; i < 20; i++) {
            x[i] = 0.0;
        }
        x[0] = 0.0010;
        x[1] = 0.9888;
        x[2] = 0.0002;
        x[3] = 0.0100;
        p = 20.0*OneAtm/760.0;

        gasTP_dupl->setState_TPX(1200., p, x);

        for (i = 0; i < 20; i++) {
            x[i] = 0.0;
        }
        i0 = diamond100TP_dupl->speciesIndex("c6H*");
        x[i0] = 0.1;
        i1 = diamond100TP_dupl->speciesIndex("c6HH");
        x[i1] = 0.9;
        diamond100TP_dupl->setState_TX(1200., x);

        for (i = 0; i < 20; i++) {
            x[i] = 0.0;
        }
        x[0] = 1.0;
        diamondTP_dupl->setState_TPX(1200., p, x);

        iKin_ptr_dupl->advanceCoverages(100.);

        // Throw some asserts in here to test that they compile
        AssertTrace(p == p);
        AssertThrow(p == p, "main");
        AssertThrowMsg(i == 20, "main", "are you kidding");


        for (i = 0; i < 20; i++) {
            src[i] = 0.0;
        }
        iKin_ptr_dupl->getNetProductionRates(src);
        sum = 0.0;
        naH = 0.0;
        for (k = 0; k < 13; k++) {
            if (k < 4) {
                naH = gasTP_dupl->nAtoms(k, 0);
            } else if (k == 4) {
                naH = 0;
            } else if (k > 4) {
                int itp = k - 5;
                naH = diamond100TP_dupl->nAtoms(itp, 0);
            }
            cout << k << "  " << naH << "  " ;
            printDbl(src[k]);
            cout << endl;
            sum += naH * src[k];

        }

        cout << "sum = ";
        printDbl(sum);
        cout << endl;
        mwd = diamondTP_dupl->molecularWeight(0);
        dens = diamondTP_dupl->density();
        gr = src[4] * mwd / dens;
        gr *= 1.0E6 * 3600.;
        cout << "growth rate = " << gr << " microns per hour" << endl;


        diamond100TP_dupl->getMoleFractions(x);
        cout << "Coverages:" << endl;
        for (k = 0; k < 8; k++) {
            cout << k << "   " << diamond100TP_dupl->speciesName(k)
                 << "   "
                 << x[k] << endl;
        }



    } catch (CanteraError& err) {
        std::cout << err.what() << std::endl;
        return -1;
    }

    return 0;
}
Exemple #7
0
int main(int argc, char** argv) {
#ifdef _MSC_VER
    _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
    int i, k;
    string infile = "frac.xml";
    double x[10], kc[10];
    double cdot[10], ddot[10];
    //double fwd_rop[10]; 
    try {
      XML_Node *xc = new XML_Node();
      string path = findInputFile(infile);
      ctml::get_CTML_Tree(xc, path);

      XML_Node * const xg = xc->findNameID("phase", "gas");
      ThermoPhase *gasTP = newPhase(*xg);
      int nsp = gasTP->nSpecies();
      cout << "Number of species = " << nsp << endl;



      vector<ThermoPhase *> phaseList;
      phaseList.push_back(gasTP);     
      GasKinetics *iKin_ptr = new GasKinetics();
      importKinetics(*xg, phaseList, iKin_ptr);
      int nr = iKin_ptr->nReactions();
      cout << "Number of reactions = " << nr << endl;

      int iH2 = gasTP->speciesIndex("H2");
      int iH = gasTP->speciesIndex("H");
      int iO2 = gasTP->speciesIndex("O2");
      int iOH = gasTP->speciesIndex("OH");
      int iH2O = gasTP->speciesIndex("H2O");


      for (i = 0; i < nsp; i++) {
       x[i] = 0.0;
      }
      x[iH2O] = 1.0/2.0;
      x[iOH] = 0.1/2.0;
      x[iH]  = 0.2/2.0;
      x[iO2] = 0.3/2.0;
      x[iH2] = 0.4/2.0;

      double p = OneAtm;

      gasTP->setState_TPX(2000., p, x);


      double src[20];
      for (i = 0; i < 20; i++) src[i] = 0.0;
      iKin_ptr->getNetProductionRates(src);

      double fwd_rop[10];
      iKin_ptr->getFwdRatesOfProgress(fwd_rop);
      cout << "fwd_rop[0] = " << fwd_rop[0] << endl;
      cout << "fwd_rop[1] = " << fwd_rop[1] << endl;

      iKin_ptr->getCreationRates(cdot);
      iKin_ptr->getDestructionRates(ddot);

      for (k = 0; k < nsp; k++) {
        string sss = gasTP->speciesName(k);
	cout << k << "  " << sss << "  ";
	printDbl(src[k]);
	cout << endl;
      }

      printf("Creation Rates: \n");
      for (k = 0; k < nsp - 1; k++) {
        string sss = gasTP->speciesName(k);
        cout << k << "  " << sss << "  ";
        cout << cdot[k] << "  ";
        cout << cdot[k] / fwd_rop[0] << " "; 
        cout << endl;
      }
     string sss = gasTP->speciesName(iH2O);
     cout << iH2O << "  " << sss << "  ";
        cout << cdot[iH2O] << "  ";
        cout << cdot[iH2O] / fwd_rop[1] << " ";
        cout << endl;


      printf("Destruction Rates: \n");
      for (k = 0; k < nsp-1; k++) {
        string sss = gasTP->speciesName(k);
        cout << k << "  " << sss << "  ";
        cout << ddot[k] << "  ";
        cout << ddot[k] / fwd_rop[1] << " "; 
        cout << endl;
      }
     sss = gasTP->speciesName(iH2O);
     cout << iH2O << "  " << sss << "  ";
     cout << ddot[iH2O] << "  ";
     cout << ddot[iH2O] / fwd_rop[0] << " ";
     cout << endl;


     double c[10];
     gasTP->getConcentrations(c);

     double order_H2 = 0.8;
     double order_OH = 2.0;
     double order_O2 = 1.0;

     double kf[10];
     iKin_ptr->getFwdRateConstants(kf);
     printf("kf[0] = %g\n", kf[0]);
     printf("kf[1] = %g\n", kf[1]);
  
     //double cprod0 = c[iH2O];
     double cprod1 = pow(c[iH2], order_H2) * pow(c[iOH], order_OH) * pow(c[iO2], order_O2);

     printf("equal numbers 0: %g %g \n", kf[0] * c[iH2O], fwd_rop[0]);

     printf("equal numbers 1: %g %g\n", kf[1] * cprod1, fwd_rop[1]);

     iKin_ptr->getEquilibriumConstants(kc);

     printf("Equilibrium constants for irreversible fractional rxns:\n");
     printf("Kc[0] = %g\n", kc[0]);
     printf("Kc[1] = %g\n", kc[1]);

   
     delete(iKin_ptr);
     iKin_ptr = 0;
     delete(gasTP);
     delete(xc);
     appdelete();


    }
    catch (CanteraError) {
      showErrors(cout);
    }

    return 0;
}
Exemple #8
0
int main(int argc, char **argv) {
  try {   
    int i;
    std::string infile = "noxNeg.xml";
    double x[20];
    double cdot[20], ddot[20];
    
    XML_Node *xc = new XML_Node();
    string path = findInputFile(infile);
    ctml::get_CTML_Tree(xc, path);

    XML_Node * const xg = xc->findNameID("phase", "air");
    ThermoPhase *gasTP = newPhase(*xg);
    int nsp = gasTP->nSpecies();
    cout << "Number of species = " << nsp << endl;


    vector<ThermoPhase *> phaseList;
    phaseList.push_back(gasTP);
    GasKinetics *iKin_ptr = new GasKinetics();
    importKinetics(*xg, phaseList, iKin_ptr);
    int nr = iKin_ptr->nReactions();
    cout << "Number of reactions = " << nr << endl;

    int iH2 = gasTP->speciesIndex("H2");
    int iH = gasTP->speciesIndex("H");
    int iO2 = gasTP->speciesIndex("O2");
    int iOH = gasTP->speciesIndex("OH");
    int iH2O = gasTP->speciesIndex("H2O");
    int iNH = gasTP->speciesIndex("NH");
    int iNO = gasTP->speciesIndex("NO");
    int iN2O = gasTP->speciesIndex("N2O");

    for (i = 0; i < nsp; i++) {
      x[i] = 0.0;
    }
    x[iH2O] = 1.0 /2.0;
    x[iOH]  = 0.1 /2.0;
    x[iH]   = 0.2 /2.0;
    x[iO2]  = 0.3 /2.0;
    x[iH2]  = 0.25 /2.0;
    x[iNH]  = 0.05/2.0;
    x[iNO]  = 0.05/2.0;
    x[iN2O]  = 0.05/2.0;

    double p = OneAtm;

    gasTP->setState_TPX(2000., p, x);


    double src[20];
    for (i = 0; i < 20; i++) src[i] = 0.0;
    iKin_ptr->getNetProductionRates(src);

    for (i = 0; i < nsp; i++) {
      string sSt = gasTP->speciesName(i);
      printf("rop [ %d:%s ] = %g \n", i, sSt.c_str(), src[i]);
    }

    int nReactions = iKin_ptr->nReactions();
    cout << "number of reactions = " << nReactions << endl;

    double fwd_rop[20];
    double rev_rop[20];
    iKin_ptr->getFwdRatesOfProgress(fwd_rop);
    iKin_ptr->getRevRatesOfProgress(rev_rop);
    for (i = 0; i < nReactions; i++) {
      printf("fwd_rop[%3d] = %13g    rev_rop[%3d] = %13g\n", i, fwd_rop[i],
	     i, rev_rop[i]);
    }



    iKin_ptr->getCreationRates(cdot);
    iKin_ptr->getDestructionRates(ddot);
    

    return 0;
  }
  catch (CanteraError) {
    showErrors(cerr);
    cerr << "program terminating." << endl;
    return -1;
  }
}