TEST(MargulesVPSSTP, fromScratch) { MargulesVPSSTP p; auto sKCl = make_shomate_species("KCl(L)", "K:1 Cl:1", kcl_shomate_coeffs); auto sLiCl = make_shomate_species("LiCl(L)", "Li:1 Cl:1", licl_shomate_coeffs); p.addSpecies(sKCl); p.addSpecies(sLiCl); size_t k = 0; for (double v : {0.03757, 0.020304}) { std::unique_ptr<PDSS_ConstVol> ss(new PDSS_ConstVol()); ss->setMolarVolume(v); p.installPDSS(k++, std::move(ss)); } p.initThermo(); p.setState_TPX(900, 101325, "KCl(L):0.3, LiCl(L):0.7"); p.addBinaryInteraction("KCl(L)", "LiCl(L)", -1.757e7, -3.77e5, -7.627e3, 4.958e3, 0.0, 0.0, 0.0, 0.0); // Regression test based on LiKCl_liquid.xml EXPECT_NEAR(p.density(), 2042.1165603245981, 1e-9); EXPECT_NEAR(p.gibbs_mass(), -9682981.421693124, 1e-5); EXPECT_NEAR(p.cp_mole(), 67478.48085733457, 1e-8); }
int main(int argc, char **argv) { int retn = 0; try { double x[20]; for (int k = 0; k < 20; k++) { x[k] = 0.0; } double um[20]; VCSnonideal::vcs_timing_print_lvl = 0; string f_li7si3 = "Li7Si3_ls.xml"; string id = "Li7Si3_and_Interstitials(S)"; #ifdef CANTERA_HAS_TEMPLATES Cantera::ThermoPhase<doublereal> *LiSi_solid = Cantera::newPhase<doublereal>(f_li7si3, id); #else Cantera::ThermoPhase *LiSi_solid = Cantera::newPhase(f_li7si3, id); #endif MargulesVPSSTP *salt = new MargulesVPSSTP(1); //int iKCl_l = salt->speciesIndex("KCl(L)"); //int iLiCl_l = salt->speciesIndex("LiCl(L)"); #ifdef CANTERA_HAS_TEMPLATES ThermoPhase<doublereal> *Li_liq = newPhase<doublereal>("Li_Liquid.xml","Li(L)"); #else ThermoPhase *Li_liq = newPhase("Li_Liquid.xml","Li(L)"); #endif /* * set states */ x[0] = 0.7; x[1] = 1.0 - x[0]; double T = 273.15 + 352.; salt->setState_TPX(T, OneAtm, x); LiSi_solid->setState_TP(T, OneAtm); salt->getChemPotentials(um); LiSi_solid->getChemPotentials(um); int ee = LiSi_solid->nElements(); printf("Number of elements = %d\n", ee); FixedChemPotSSTP *LiFixed = new FixedChemPotSSTP("Li", -2.3E7); LiFixed->setState_TP(T, OneAtm); LiFixed->getChemPotentials(um); printf(" chem pot = %g\n", um[0]); double volts = 1.635; // has some Fe in it // test suite double dg_corr = - volts * Faraday; printf("dg_corr = %g\n", dg_corr); Li_liq->getChemPotentials(um); double um_Li_liq = um[0]; double um_li_chempot = um_Li_liq + dg_corr; printf("um_li_chempot = %g\n", um_li_chempot); LiFixed->setChemicalPotential(um_li_chempot); Cantera::MultiPhase mmm; mmm.addPhase(salt, 10.); mmm.addPhase(LiSi_solid, 1.); mmm.addPhase(LiFixed, 100.); int solver = 2; int printLvl = 10; int estimateEquil = 0; vcs_equilibrate(mmm, "TP", estimateEquil, printLvl, solver); cout << mmm << endl; delete LiSi_solid; LiSi_solid = 0; delete Li_liq; Li_liq = 0; delete LiFixed; LiFixed = 0; delete salt; salt = 0; Cantera::appdelete(); return retn; } catch (CanteraError) { showErrors(); return -1; } }