Exemplo n.º 1
0
TEST(HMWSoln, fromScratch)
{
    // Regression test based on HMW_test_3
    HMWSoln p;
    auto sH2O = make_species("H2O(l)", "H:2, O:1", h2oliq_nasa_coeffs);
    auto sCl = make_species("Cl-", "Cl:1, E:1", 0.0,
                            298.15, -52.8716, 333.15, -52.8716, 1e5);
    sCl->charge = -1;
    auto sH = make_species("H+", "H:1, E:-1", 0.0, 298.15, 0.0, 333.15, 0.0, 1e5);
    sH->charge = 1;
    auto sNa = make_species("Na+", "Na:1, E:-1", 0.0,
                            298.15, -125.5213, 333.15, -125.5213, 1e5);
    sNa->charge = 1;
    auto sOH = make_species("OH-", "O:1, H:1, E:1", 0.0,
                            298.15, -91.523, 333.15, -91.523, 1e5);
    sOH->charge = -1;
    for (auto& s : {sH2O, sCl, sH, sNa, sOH}) {
        p.addSpecies(s);
    }
    std::unique_ptr<PDSS_Water> ss(new PDSS_Water());
    p.installPDSS(0, std::move(ss));
    size_t k = 1;
    for (double v : {1.3, 1.3, 1.3, 1.3}) {
        std::unique_ptr<PDSS_ConstVol> ss(new PDSS_ConstVol());
        ss->setMolarVolume(v);
        p.installPDSS(k++, std::move(ss));
    }
    p.setPitzerTempModel("complex");
    p.setA_Debye(1.175930);
    p.initThermo();

    set_hmw_interactions(p);
    p.setMolalitiesByName("Na+:6.0997 Cl-:6.0996986044628 H+:2.1628E-9 OH-:1.3977E-6");
    p.setState_TP(150 + 273.15, 101325);

    size_t N = p.nSpecies();
    vector_fp acMol(N), mf(N), activities(N), moll(N), mu0(N);
    p.getMolalityActivityCoefficients(acMol.data());
    p.getMoleFractions(mf.data());
    p.getActivities(activities.data());
    p.getMolalities(moll.data());
    p.getStandardChemPotentials(mu0.data());

    double acMolRef[] = {0.9341, 1.0191, 3.9637, 1.0191, 0.4660};
    double mfRef[] = {0.8198, 0.0901, 0.0000, 0.0901, 0.0000};
    double activitiesRef[] = {0.7658, 6.2164, 0.0000, 6.2164, 0.0000};
    double mollRef[] = {55.5084, 6.0997, 0.0000, 6.0997, 0.0000};
    double mu0Ref[] = {-317.175788, -186.014558, 0.0017225, -441.615429, -322.000412}; // kJ/gmol

    for (size_t k = 0 ; k < N; k++) {
        EXPECT_NEAR(acMol[k], acMolRef[k], 2e-4);
        EXPECT_NEAR(mf[k], mfRef[k], 2e-4);
        EXPECT_NEAR(activities[k], activitiesRef[k], 2e-4);
        EXPECT_NEAR(moll[k], mollRef[k], 2e-4);
        EXPECT_NEAR(mu0[k]/1e6, mu0Ref[k], 2e-6);
    }
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
#ifdef _MSC_VER
    _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
   int retn = 0;

   try {
  
     HMWSoln *HMW = new HMWSoln(1);

#ifdef DEBUG_MODE
     CHECK_DEBUG_MODE = 1;
#endif
     if (CHECK_DEBUG_MODE == 1) {
       HMW->m_debugCalc = 1;
       if (HMW->debugPrinting()) {
         FILE *ff = fopen("CheckDebug.txt", "w");
         fprintf(ff,"%1d\n", 1);
         fclose(ff);
       }
       HMW->m_debugCalc = 0;
     }
     
     int nsp = HMW->nSpecies();
    
     double a1 = HMW->AionicRadius(1);
     printf("a1 = %g\n", a1);
     double a2 = HMW->AionicRadius(2);
     printf("a2 = %g\n", a2); 
     double mu0[100];
     double moll[100]; 
     string sName;
  
     HMW->getMolalities(moll);
     moll[1] = 6.0997;
     moll[2] = 2.1628E-9;
     moll[3] = 6.0997;
     moll[4] =1.3977E-6;
     /*
      * Equalize charge balance and dump into Cl-
      */
     double sum = -moll[1] + moll[2] + moll[3] - moll[4];
     moll[1] += sum;

     HMW->setMolalities(moll);
     HMW->setState_TP(298.15, 1.01325E5);
     pAtable(HMW);

     HMW->setState_TP(298.15, 1.01325E5);
     HMW->getStandardChemPotentials(mu0);
     // translate from J/kmol to kJ/gmol
     int k;
     for (k = 0; k < nsp; k++) {
        mu0[k] *= 1.0E-6; 
     }

     printf("           Species   Standard chemical potentials (kJ/gmol) \n");
     printf("------------------------------------------------------------\n");
     for (k = 0; k < nsp; k++) {
       sName = HMW->speciesName(k);
       printf("%16s %16.9g\n", sName.c_str(), mu0[k]);
     }
     printf("------------------------------------------------------------\n");
     printf(" Some DeltaSS values:               Delta(mu_0)\n");
     double deltaG;
     int i1, i2, j1;
     double RT = 8.314472E-3 * 298.15;

 
     
   
 
     i1 = HMW->speciesIndex("Na+");
     i2 = HMW->speciesIndex("Cl-");
     deltaG = -432.6304 - mu0[i1] - mu0[i2];
     printf(" NaCl(S): Na+ + Cl- -> NaCl(S): %14.7g kJ/gmol \n",
            deltaG);
     printf("                                : %14.7g (dimensionless) \n",
            deltaG/RT);
     printf("                                : %14.7g (dimensionless/ln10) \n",
            deltaG/(RT * log(10.0)));
     printf("            G0(NaCl(S)) = %14.7g (fixed)\n", -432.6304);
     printf("            G0(Na+)     = %14.7g\n", mu0[i1]);
     printf("            G0(Cl-)     = %14.7g\n", mu0[i2]);

     i1 = HMW->speciesIndex("H+");
     i2 = HMW->speciesIndex("H2O(L)");
     j1 = HMW->speciesIndex("OH-");
     if (i1 < 0 || i2 < 0 || j1 < 0) {
       printf("problems\n");
       exit(-1);
     }
     deltaG = mu0[j1] + mu0[i1] - mu0[i2];
     printf(" OH-: H2O(L) - H+ -> OH-: %14.7g kJ/gmol \n",
            deltaG);
     printf("                                : %14.7g (dimensionless) \n",
            deltaG/RT);
     printf("                                : %14.7g (dimensionless/ln10) \n",
            deltaG/(RT * log(10.0)));
     printf("            G0(OH-)    = %14.7g\n", mu0[j1]);
     printf("            G0(H+)     = %14.7g\n", mu0[i1]);
     printf("            G0(H2O(L)) = %14.7g\n", mu0[i2]);


     printf("------------------------------------------------------------\n");

     delete HMW;
     HMW = 0;
     Cantera::appdelete();

     return retn;

   } catch (CanteraError) {

     showErrors();
     return -1;
   }
} 
Exemplo n.º 3
0
int main(int argc, char** argv)
{
#if defined(_MSC_VER) && _MSC_VER < 1900
    _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
    int retn = 0;

    try {

        HMWSoln* HMW = new HMWSoln("HMW_NaCl.xml");
        HMW->printCoeffs();

        size_t nsp = HMW->nSpecies();

        double a1 = HMW->AionicRadius(1);
        printf("a1 = %g\n", a1);
        double a2 = HMW->AionicRadius(2);
        printf("a2 = %g\n", a2);
        double mu0[100];
        double moll[100];
        string sName;

        HMW->getMolalities(moll);
        moll[1] = 6.0997;
        moll[2] = 2.1628E-9;
        moll[3] = 6.0997;
        moll[4] =1.3977E-6;
        /*
         * Equalize charge balance and dump into Cl-
         */
        double sum = -moll[1] + moll[2] + moll[3] - moll[4];
        moll[1] += sum;

        HMW->setMolalities(moll);
        HMW->setState_TP(298.15, 1.01325E5);
        pAtable(HMW);

        HMW->setState_TP(298.15, 1.01325E5);
        HMW->getStandardChemPotentials(mu0);
        // translate from J/kmol to kJ/gmol
        for (size_t k = 0; k < nsp; k++) {
            mu0[k] *= 1.0E-6;
        }

        printf("           Species   Standard chemical potentials (kJ/gmol) \n");
        printf("------------------------------------------------------------\n");
        for (size_t k = 0; k < nsp; k++) {
            sName = HMW->speciesName(k);
            printf("%16s %16.9g\n", sName.c_str(), mu0[k]);
        }
        printf("------------------------------------------------------------\n");
        printf(" Some DeltaSS values:               Delta(mu_0)\n");
        double deltaG;
        size_t i1, i2, j1;
        double RT = 8.314472E-3 * 298.15;

        i1 = HMW->speciesIndex("Na+");
        i2 = HMW->speciesIndex("Cl-");
        deltaG = -432.6304 - mu0[i1] - mu0[i2];
        printf(" NaCl(S): Na+ + Cl- -> NaCl(S): %14.7g kJ/gmol \n",
               deltaG);
        printf("                                : %14.7g (dimensionless) \n",
               deltaG/RT);
        printf("                                : %14.7g (dimensionless/ln10) \n",
               deltaG/(RT * log(10.0)));
        printf("            G0(NaCl(S)) = %14.7g (fixed)\n", -432.6304);
        printf("            G0(Na+)     = %14.7g\n", mu0[i1]);
        printf("            G0(Cl-)     = %14.7g\n", mu0[i2]);

        i1 = HMW->speciesIndex("H+");
        i2 = HMW->speciesIndex("H2O(L)");
        j1 = HMW->speciesIndex("OH-");
        if (i1 == npos || i2 == npos || j1 == npos) {
            printf("problems\n");
            exit(-1);
        }
        deltaG = mu0[j1] + mu0[i1] - mu0[i2];
        printf(" OH-: H2O(L) - H+ -> OH-: %14.7g kJ/gmol \n",
               deltaG);
        printf("                                : %14.7g (dimensionless) \n",
               deltaG/RT);
        printf("                                : %14.7g (dimensionless/ln10) \n",
               deltaG/(RT * log(10.0)));
        printf("            G0(OH-)    = %14.7g\n", mu0[j1]);
        printf("            G0(H+)     = %14.7g\n", mu0[i1]);
        printf("            G0(H2O(L)) = %14.7g\n", mu0[i2]);


        printf("------------------------------------------------------------\n");

        delete HMW;
        HMW = 0;
        Cantera::appdelete();

        return retn;

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