Exemplo n.º 1
0
TEST_F(ConstructFromScratch, AddElements)
{
    IdealGasPhase p;
    p.addElement("H");
    p.addElement("O");
    ASSERT_EQ((size_t) 2, p.nElements());
    ASSERT_EQ("H", p.elementName(0));
    ASSERT_EQ((size_t) 1, p.elementIndex("O"));
}
Exemplo n.º 2
0
 int DLL_EXPORT flow_new(int type, int iph, int np) {
     IdealGasPhase* ph = (IdealGasPhase*)_thermo(iph);
     StFlow* x;
     try {
         switch (type) {
         case 0:
             x = new AxiStagnFlow(ph, ph->nSpecies(), np); break;
         case 1:
             x = new OneDFlow(ph, ph->nSpecies(), np); break;
         default:
             return -2;
         }
         return Cabinet<StFlow>::cabinet()->add(x);
     }
     catch (CanteraError) { return -1; }
 }
Exemplo n.º 3
0
    //! iRef is the index of the corresponding reaction in the reference mech
    void check_rates(int iRef) {
        ASSERT_EQ((size_t) 1, kin.nReactions());

        std::string X = "O:0.02 H2:0.2 O2:0.5 H:0.03 OH:0.05 H2O:0.1 HO2:0.01";
        p.setState_TPX(1200, 5*OneAtm, X);
        p_ref.setState_TPX(1200, 5*OneAtm, X);

        vector_fp k(1), k_ref(kin_ref.nReactions());

        kin.getFwdRateConstants(&k[0]);
        kin_ref.getFwdRateConstants(&k_ref[0]);
        EXPECT_DOUBLE_EQ(k_ref[iRef], k[0]);

        kin.getRevRateConstants(&k[0]);
        kin_ref.getRevRateConstants(&k_ref[0]);
        EXPECT_DOUBLE_EQ(k_ref[iRef], k[0]);
    }
Exemplo n.º 4
0
TEST_F(ConstructFromScratch, ignoreUndefinedElements)
{
    IdealGasPhase p;
    p.addElement("H");
    p.addElement("O");
    p.ignoreUndefinedElements();

    p.addSpecies(sO2);
    p.addSpecies(sOH);
    ASSERT_EQ((size_t) 2, p.nSpecies());

    p.addSpecies(sCO);
    p.addSpecies(sCO2);
    ASSERT_EQ((size_t) 2, p.nSpecies());
    ASSERT_EQ((size_t) 2, p.nElements());
    ASSERT_EQ(npos, p.speciesIndex("CO2"));
}
Exemplo n.º 5
0
    void check_rates(size_t N, const std::string& X) {
        for (size_t i = 0; i < kin_ref.nReactions(); i++) {
            if (i >= N) {
                kin_ref.setMultiplier(i, 0);
            } else {
                kin_ref.setMultiplier(i, 1);
            }
        }
        p.setState_TPX(1200, 5*OneAtm, X);
        p_ref.setState_TPX(1200, 5*OneAtm, X);

        vector_fp k(kin.nReactions()), k_ref(kin_ref.nReactions());
        vector_fp w(kin.nTotalSpecies()), w_ref(kin_ref.nTotalSpecies());

        kin.getFwdRateConstants(k.data());
        kin_ref.getFwdRateConstants(k_ref.data());
        for (size_t i = 0; i < kin.nReactions(); i++) {
            EXPECT_DOUBLE_EQ(k_ref[i], k[i]) << "i = " << i << "; N = " << N;
        }

        kin.getFwdRatesOfProgress(k.data());
        kin_ref.getFwdRatesOfProgress(k_ref.data());
        for (size_t i = 0; i < kin.nReactions(); i++) {
            EXPECT_DOUBLE_EQ(k_ref[i], k[i]) << "i = " << i << "; N = " << N;
        }

        kin.getRevRateConstants(k.data());
        kin_ref.getRevRateConstants(k_ref.data());
        for (size_t i = 0; i < kin.nReactions(); i++) {
            EXPECT_DOUBLE_EQ(k_ref[i], k[i]) << "i = " << i << "; N = " << N;
        }

        kin.getRevRatesOfProgress(k.data());
        kin_ref.getRevRatesOfProgress(k_ref.data());
        for (size_t i = 0; i < kin.nReactions(); i++) {
            EXPECT_DOUBLE_EQ(k_ref[i], k[i]) << "i = " << i << "; N = " << N;
        }

        kin.getCreationRates(w.data());
        kin_ref.getCreationRates(w_ref.data());
        for (size_t i = 0; i < kin.nTotalSpecies(); i++) {
            size_t iref = p_ref.speciesIndex(p.speciesName(i));
            EXPECT_DOUBLE_EQ(w_ref[iref], w[i]) << "sp = " << p.speciesName(i) << "; N = " << N;
        }
    }
Exemplo n.º 6
0
 int DLL_EXPORT stflow_new(int iph, int ikin, int itr, int itype) {
     try {
         IdealGasPhase* ph = (IdealGasPhase*)_thermo(iph);
         if (itype == 1) {
             AxiStagnFlow* x = new AxiStagnFlow(ph, ph->nSpecies(), 2);
             x->setKinetics(*_kinetics(ikin));
             x->setTransport(*_transport(itr));
             return Cabinet<Domain1D>::cabinet()->add(x);
         }
         else if (itype == 2) {
             FreeFlame* x = new FreeFlame(ph, ph->nSpecies(), 2);
             x->setKinetics(*_kinetics(ikin));
             x->setTransport(*_transport(itr));
             return Cabinet<Domain1D>::cabinet()->add(x);
         }
         else {
             return -2;
         }
     }
     catch (CanteraError) { return -1; }
 }
Exemplo n.º 7
0
    //! iRef is the index of the corresponding reaction in the reference mech
    void check_rates(int iRef) {
        ASSERT_EQ((size_t) 1, kin.nReactions());

        std::string X = "H2:0.2 O2:0.5 H2O:0.1 N2:0.2";
        std::string Xs = "H(m):0.1 O(m):0.2 OH(m):0.3 (m):0.4";
        gas.setState_TPX(1200, 5*OneAtm, X);
        gas_ref.setState_TPX(1200, 5*OneAtm, X);
        surf.setState_TP(1200, 5*OneAtm);
        surf_ref.setState_TP(1200, 5*OneAtm);
        surf.setCoveragesByName(Xs);
        surf_ref.setCoveragesByName(Xs);

        vector_fp k(1), k_ref(kin_ref.nReactions());

        kin.getFwdRateConstants(&k[0]);
        kin_ref.getFwdRateConstants(&k_ref[0]);
        EXPECT_DOUBLE_EQ(k_ref[iRef], k[0]);

        kin.getRevRateConstants(&k[0]);
        kin_ref.getRevRateConstants(&k_ref[0]);
        EXPECT_DOUBLE_EQ(k_ref[iRef], k[0]);
    }
Exemplo n.º 8
0
TEST_F(ConstructFromScratch, addUndefinedElements)
{
    IdealGasPhase p;
    p.addElement("H");
    p.addElement("O");
    p.addUndefinedElements(); // default behavior

    p.addSpecies(sH2);
    p.addSpecies(sOH);
    ASSERT_EQ((size_t) 2, p.nSpecies());
    ASSERT_EQ((size_t) 2, p.nElements());

    p.addSpecies(sCO);
    p.addSpecies(sCO2);
    ASSERT_EQ((size_t) 4, p.nSpecies());
    ASSERT_EQ((size_t) 3, p.nElements());
    ASSERT_EQ((size_t) 1, p.nAtoms(p.speciesIndex("CO2"), p.elementIndex("C")));
    ASSERT_EQ((size_t) 2, p.nAtoms(p.speciesIndex("co2"), p.elementIndex("O")));
    p.setMassFractionsByName("H2:0.5, CO2:0.5");
    ASSERT_DOUBLE_EQ(0.5, p.massFraction("CO2"));
}
Exemplo n.º 9
0
TEST_F(ConstructFromScratch, throwUndefindElements)
{
    IdealGasPhase p;
    p.throwUndefinedElements();
    p.addElement("H");
    p.addElement("O");
    p.addSpecies(sH2O);
    p.addSpecies(sH2);

    ASSERT_EQ((size_t) 2, p.nSpecies());

    p.addSpecies(sO2);
    p.addSpecies(sOH);

    ASSERT_EQ((size_t) 4, p.nSpecies());
    ASSERT_EQ("H2", p.speciesName(1));
    ASSERT_EQ(2, p.nAtoms(2, 1)); // O in O2
    ASSERT_EQ(2, p.nAtoms(0, 0)); // H in H2O
    ASSERT_THROW(p.addSpecies(sCO), CanteraError);
}
Exemplo n.º 10
0
int main(int argc, char** argv)
{
#ifdef _MSC_VER
    _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
#ifdef DEBUG_CHEMEQUIL
    ChemEquil_print_lvl = 0;
#endif
    try {
        suppress_deprecation_warnings();
        IdealGasPhase* gas = new IdealGasMix("air_below6000K.xml","air_below6000K");

        vector_fp IndVar2(6, 0.0);
        IndVar2[0] = 1.5E5;
        IndVar2[1] = 3.0E5;
        IndVar2[2] = 9.0E5;
        IndVar2[3] = 2.7E6;
        IndVar2[4] = 6.7E6;
        IndVar2[5] = 1.0E7;

        vector_fp IndVar1(7, 0.0);
        IndVar1[0] = 1.0E-8;
        IndVar1[1] = 1.0E-7;
        IndVar1[2] = 1.0E-6;
        IndVar1[3] = 1.0E-5;
        IndVar1[4] = 1.0E-4;
        IndVar1[5] = 1.0E-3;
        IndVar1[6] = 1.0E-2;
        int nj = 6;
        int ni = 7;
        FILE* FF = fopen("table.csv","w");
        size_t kk = gas->nSpecies();
        std::vector<double> Xmol(kk, 0.0);
        const std::vector<string> &snames = gas->speciesNames();
        fprintf(FF,"Temperature,  Pressure,");
        for (size_t k = 0; k < kk; k++) {
            fprintf(FF, "%11s", snames[k].c_str());
            if (k < kk-1) {
                fprintf(FF,",");
            }
        }
        fprintf(FF,"\n");

        for (int j=0; j<nj; j++) {
            for (int i=0; i<ni; i++) {
                double offset = -301471.39;
                gas->setState_UV(IndVar2[j]+offset,1.0/IndVar1[i]);
                double tkelvin = gas->temperature();
                double pres = gas->pressure();
                printf("Initial T = %g, pres = %g atm\n", tkelvin, pres/OneAtm);

                equilibrate(*gas,"UV", 0, 1e-12);

                tkelvin = gas->temperature();
                pres = gas->pressure();
                printf("Final T = %g, pres = %g atm\n", tkelvin, pres/OneAtm);
                cout << "enthalpy = " << gas->enthalpy_mass() << endl;
                cout << "entropy = " << gas->entropy_mass() << endl;
                cout << "Gibbs function = " << gas->gibbs_mass() << endl;
                cout << "heat capacity c_p = " << gas->cp_mass() << endl;
                cout << "heat capacity c_v = " << gas->cv_mass() << endl << endl;

                gas->getMoleFractions(DATA_PTR(Xmol));
                fprintf(FF,"%10.4g, %10.4g,", tkelvin, pres);
                for (size_t k = 0; k < kk; k++) {
                    if (fabs(Xmol[k]) < 1.0E-130) {
                        fprintf(FF," %10.4g", 0.0);
                    } else {
                        fprintf(FF," %10.4g", Xmol[k]);
                    }
                    if (k < kk-1) {
                        fprintf(FF,",");
                    }
                }
                fprintf(FF,"\n");
            }
        }
        delete gas;
        fclose(FF);
    }

    catch (CanteraError& err) {
        std::cout << err.what() << std::endl;
        return -1;
    }
    return 0;
}
Exemplo n.º 11
0
int main(int argc, char **argv) {
#ifdef DEBUG_CHEMEQUIL
  ChemEquil_print_lvl = 0;
#endif
  try {

    IdealGasPhase* gas = new IdealGasMix("air_below6000K.xml","air_below6000K");

    vector_fp IndVar2(6, 0.0);
    IndVar2[0] = 1.5E5;
    IndVar2[1] = 3.0E5;
    IndVar2[2] = 9.0E5;
    IndVar2[3] = 2.7E6;
    IndVar2[4] = 6.7E6;
    IndVar2[5] = 1.0E7;

    vector_fp IndVar1(7, 0.0);
    IndVar1[0] = 1.0E-8;
    IndVar1[1] = 1.0E-7;
    IndVar1[2] = 1.0E-6;
    IndVar1[3] = 1.0E-5;
    IndVar1[4] = 1.0E-4;
    IndVar1[5] = 1.0E-3;
    IndVar1[6] = 1.0E-2;
    int nj = 6;
    int ni = 7;
    FILE *FF = fopen("table.csv","w");
    int kk = gas->nSpecies();
    std::vector<double> Xmol(kk, 0.0);
    const std::vector<string> &snames = gas->speciesNames();
    fprintf(FF,"Temperature,  Pressure,");
    for (int k = 0; k < kk; k++) {
      fprintf(FF, "%11s", snames[k].c_str());
      if (k < kk-1) {
        fprintf(FF,",");
      }
    }
    fprintf(FF,"\n");

    for (int j=0; j<nj; j++) {
      for (int i=0; i<ni; i++) {
	double offset = -301471.39;
	gas->setState_UV(IndVar2[j]+offset,1.0/IndVar1[i]);
	double tkelvin = gas->temperature();
	double pres = gas->pressure();
	printf("Initial T = %g, pres = %g atm \n", tkelvin, pres/OneAtm);
	beginLogGroup("topEquil", -1);
	equilibrate(*gas,"UV", -1);
	endLogGroup("topEquil");
	cout << report(*gas) << endl;

	tkelvin = gas->temperature();
	pres = gas->pressure();
	printf("Final T = %g, pres = %g atm\n", tkelvin, pres/OneAtm);
        gas->getMoleFractions(DATA_PTR(Xmol)); 
        fprintf(FF,"%10.4g, %10.4g,", tkelvin, pres); 
        for (int k = 0; k < kk; k++) {
          if (fabs(Xmol[k]) < 1.0E-130) {
            fprintf(FF," %10.4g", 0.0);
          } else {
            fprintf(FF," %10.4g", Xmol[k]);
          }
          if (k < kk-1) {
            fprintf(FF,",");
          }
        }
        fprintf(FF,"\n");
      }
    }
    delete gas;
    fclose(FF);
  }

  catch (CanteraError) {
    showErrors();
  }
  return 0;
}