From 5898bf025fa4564a677a35eb9ace0cbd864e2478 Mon Sep 17 00:00:00 2001 From: Victor Brunini Date: Thu, 6 Mar 2014 20:23:23 +0000 Subject: [PATCH] Implement MaskellSolidSolnPhase::getPartialMolarVolumes() User VPStandardStateVP as base class and just return the standard state molar volumes. --- .../cantera/thermo/MaskellSolidSolnPhase.h | 5 +- src/thermo/MaskellSolidSolnPhase.cpp | 22 +++++++-- test/data/MaskellSolidSolnPhase_valid.xml | 36 +++++--------- test/thermo/MaskellSolidSolnPhase_Test.cpp | 49 +++++++------------ 4 files changed, 52 insertions(+), 60 deletions(-) diff --git a/include/cantera/thermo/MaskellSolidSolnPhase.h b/include/cantera/thermo/MaskellSolidSolnPhase.h index 007a38c41..02478ba36 100644 --- a/include/cantera/thermo/MaskellSolidSolnPhase.h +++ b/include/cantera/thermo/MaskellSolidSolnPhase.h @@ -16,6 +16,7 @@ #include "mix_defs.h" #include "ThermoPhase.h" +#include "VPStandardStateTP.h" #include "ThermoFactory.h" #include "SpeciesThermo.h" @@ -30,7 +31,7 @@ namespace Cantera * * @ingroup thermoprops */ -class MaskellSolidSolnPhase : public ThermoPhase +class MaskellSolidSolnPhase : public VPStandardStateTP { public: /** @@ -137,6 +138,8 @@ public: */ virtual void setDensity(const doublereal rho); + virtual void calcDensity(); + /** * Overwritten setMolarDensity() function is necessary because the * density is not an independent variable. diff --git a/src/thermo/MaskellSolidSolnPhase.cpp b/src/thermo/MaskellSolidSolnPhase.cpp index 38534dd3e..9430d31bb 100644 --- a/src/thermo/MaskellSolidSolnPhase.cpp +++ b/src/thermo/MaskellSolidSolnPhase.cpp @@ -21,7 +21,6 @@ namespace Cantera { //===================================================================================================== MaskellSolidSolnPhase::MaskellSolidSolnPhase() : - ThermoPhase(), m_Pref(OneAtm), m_Pcurrent(OneAtm), m_tlast(-1.0), @@ -34,7 +33,6 @@ MaskellSolidSolnPhase::MaskellSolidSolnPhase() : } //===================================================================================================== MaskellSolidSolnPhase::MaskellSolidSolnPhase(const MaskellSolidSolnPhase& b) : - ThermoPhase(), m_Pref(OneAtm), m_Pcurrent(OneAtm), m_tlast(-1.0), @@ -51,7 +49,7 @@ MaskellSolidSolnPhase& MaskellSolidSolnPhase:: operator=(const MaskellSolidSolnPhase& b) { if (this != &b) { - ThermoPhase::operator=(b); + VPStandardStateTP::operator=(b); } return *this; } @@ -110,6 +108,21 @@ setDensity(const doublereal rho) } } +void MaskellSolidSolnPhase:: +calcDensity() +{ + const vector_fp & vbar = getStandardVolumes(); + + vector_fp moleFracs(m_kk); + Phase::getMoleFractions(&moleFracs[0]); + doublereal vtotal = 0.0; + for (size_t i = 0; i < m_kk; i++) { + vtotal += vbar[i] * moleFracs[i]; + } + doublereal dd = meanMolecularWeight() / vtotal; + Phase::setDensity(dd); +} + void MaskellSolidSolnPhase::setPressure(doublereal p) { m_Pcurrent = p; @@ -180,6 +193,7 @@ getPartialMolarCp(doublereal* cpbar) const void MaskellSolidSolnPhase:: getPartialMolarVolumes(doublereal* vbar) const { + getStandardVolumes(vbar); } void MaskellSolidSolnPhase:: @@ -254,7 +268,7 @@ void MaskellSolidSolnPhase::initThermoXML(XML_Node& phaseNode, const std::string * Call the base initThermo, which handles setting the initial * state. */ - ThermoPhase::initThermoXML(phaseNode, id_); + VPStandardStateTP::initThermoXML(phaseNode, id_); } void MaskellSolidSolnPhase::_updateThermo() const diff --git a/test/data/MaskellSolidSolnPhase_valid.xml b/test/data/MaskellSolidSolnPhase_valid.xml index 7ba5ff539..dfe4ee689 100644 --- a/test/data/MaskellSolidSolnPhase_valid.xml +++ b/test/data/MaskellSolidSolnPhase_valid.xml @@ -29,17 +29,12 @@ H:1 He:2 - - - 1., - 1., - 1., - 1., - 1., - 1., - 1., - - + + 1 + 0 + 0 + 0 + 0.005 @@ -49,20 +44,15 @@ H:0 He:1 - - - 6.94544000E+01, - 6.94544000E+01, - 6.94544000E+01, - 6.94544000E+01, - 6.94544000E+01, - 6.94544000E+01, - 6.94544000E+01, - - + + 1 + 1000 + 0 + 0 + - 0.005 + 0.01 diff --git a/test/thermo/MaskellSolidSolnPhase_Test.cpp b/test/thermo/MaskellSolidSolnPhase_Test.cpp index 75f2cb620..3b0daa9e5 100644 --- a/test/thermo/MaskellSolidSolnPhase_Test.cpp +++ b/test/thermo/MaskellSolidSolnPhase_Test.cpp @@ -1,6 +1,7 @@ #include "gtest/gtest.h" #include "cantera/thermo/MaskellSolidSolnPhase.h" #include "cantera/thermo/SimpleThermo.h" +#include "cantera/thermo/VPSSMgr_General.h" #include "cantera/thermo/ThermoFactory.h" #include @@ -16,37 +17,6 @@ public: ~MaskellSolidSolnPhase_Test() { delete test_phase; } - void initializeTestPhaseWithSimpleThermo() - { - test_phase = new MaskellSolidSolnPhase(); - test_phase->addElement("A", 1.); - test_phase->addElement("B", 2.); - std::vector comp(2); - comp[0] = 1.; - comp[1] = 0.; - test_phase->addSpecies("A", &comp[0], 0., 1.); - comp[0] = 0.; - comp[1] = 1.; - test_phase->addSpecies("B", &comp[0], 0., 1.); - - // Setup simple thermo so that the standard state enthalpy and - // gibbs free energies are always 0 so that we can just test the - // additional contribution from the Maskell model - SimpleThermo * spec_thermo = new SimpleThermo(); - std::vector coeffs(4); - coeffs[0] = 1; - coeffs[1] = 0; - coeffs[2] = 0; - coeffs[3] = 0; - spec_thermo->install("A", 0, 0, &coeffs[0], 0., 1000., 1.); - coeffs[1] = 1000; - spec_thermo->install("B", 1, 0, &coeffs[0], 0., 1000., 1.); - test_phase->setSpeciesThermo(spec_thermo); - - test_phase->setState_TP(298., 1.); - set_r(0.5); - } - void initializeTestPhaseWithXML(const std::string & filename) { test_phase = newPhase(filename.c_str(), ""); @@ -87,7 +57,10 @@ TEST_F(MaskellSolidSolnPhase_Test, construct_from_xml) TEST_F(MaskellSolidSolnPhase_Test, chem_potentials) { - initializeTestPhaseWithSimpleThermo(); + const std::string valid_file("../data/MaskellSolidSolnPhase_valid.xml"); + initializeTestPhaseWithXML(valid_file); + test_phase->setState_TP(298., 1.); + set_r(0.5); MaskellSolidSolnPhase * maskell_phase = dynamic_cast(test_phase); @@ -104,4 +77,16 @@ TEST_F(MaskellSolidSolnPhase_Test, chem_potentials) check_chemPotentials(expected_result_minus_5000); } +TEST_F(MaskellSolidSolnPhase_Test, partialMolarVolumes) +{ + const std::string valid_file("../data/MaskellSolidSolnPhase_valid.xml"); + initializeTestPhaseWithXML(valid_file); + ASSERT_TRUE(dynamic_cast(test_phase) != NULL); + + std::vector pmv(2); + test_phase->getPartialMolarVolumes(&pmv[0]); + EXPECT_EQ(0.005, pmv[0]); + EXPECT_EQ(0.01, pmv[1]); +} + };