From 26bd71af539d964a1ac5dd920734e7628f5fcd6f Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 30 Jan 2019 15:24:02 -0500 Subject: [PATCH] [Input] Create Surface and Edge phases from YAML definitions --- include/cantera/thermo/SurfPhase.h | 1 + src/thermo/SurfPhase.cpp | 9 ++++++ src/thermo/ThermoFactory.cpp | 2 ++ test/data/surface-phases.yaml | 44 ++++++++++++++++++++++++++++++ test/thermo/thermoFromYaml.cpp | 23 ++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 test/data/surface-phases.yaml diff --git a/include/cantera/thermo/SurfPhase.h b/include/cantera/thermo/SurfPhase.h index 3cfc1ffb8..3b5cf04b5 100644 --- a/include/cantera/thermo/SurfPhase.h +++ b/include/cantera/thermo/SurfPhase.h @@ -284,6 +284,7 @@ public: * @endcode */ virtual void setParametersFromXML(const XML_Node& thermoData); + virtual void initThermo(); virtual bool addSpecies(shared_ptr spec); diff --git a/src/thermo/SurfPhase.cpp b/src/thermo/SurfPhase.cpp index 6c0a466a2..dac2d997e 100644 --- a/src/thermo/SurfPhase.cpp +++ b/src/thermo/SurfPhase.cpp @@ -323,6 +323,15 @@ void SurfPhase::setParametersFromXML(const XML_Node& eosdata) setSiteDensity(n); } +void SurfPhase::initThermo() +{ + if (m_input.hasKey("site-density")) { + // Units are kmol/m^2 for surface phases or kmol/m for edge phases + setSiteDensity(m_input.convert("site-density", + Units(1.0, 0, -static_cast(m_ndim), 0, 0, 0, 1))); + } +} + void SurfPhase::setStateFromXML(const XML_Node& state) { double t; diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index aa0bec293..4934143b0 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -53,7 +53,9 @@ ThermoFactory::ThermoFactory() m_synonyms["ideal-gas"] = "IdealGas"; reg("Incompressible", []() { return new ConstDensityThermo(); }); reg("Surface", []() { return new SurfPhase(); }); + m_synonyms["ideal-surface"] = "Surface"; reg("Edge", []() { return new EdgePhase(); }); + m_synonyms["edge"] = "Edge"; reg("Metal", []() { return new MetalPhase(); }); reg("StoichSubstance", []() { return new StoichSubstance(); }); m_synonyms["fixed-stoichiometry"] = "StoichSubstance"; diff --git a/test/data/surface-phases.yaml b/test/data/surface-phases.yaml new file mode 100644 index 000000000..0c145dd5a --- /dev/null +++ b/test/data/surface-phases.yaml @@ -0,0 +1,44 @@ +phases: +- name: Pt-surf + thermo: ideal-surface + species: [{Pt-surf-species: all}] + site-density: 2.7063e-9 mol/cm^2 + state: {T: 900 K, P: 1 atm, coverages: {Pt(s): 0.5, H(s): 0.4, O(s): 0.1}} + +- name: TPB + thermo: edge + species: [(tpb)] + site-density: 5e-17 mol/cm + state: {T: 1073.15 K, P: 1 atm, coverages: {(tpb): 1.0}} + +species: +- name: (tpb) + composition: {} + thermo: + model: constant-cp + +Pt-surf-species: +- name: Pt(s) + composition: {Pt: 1} + thermo: + model: constant-cp +- name: H(s) + composition: {H: 1, Pt: 1} + thermo: + model: NASA7 + temperature-ranges: [300, 1000, 3000] + data: + - [-1.3029877E+00, 5.4173199E-03, 3.1277972E-07, -3.2328533E-09, + 1.1362820E-12, -4.2277075E+03, 5.8743238E+00] + - [1.0696996E+00, 1.5432230E-03, -1.5500922E-07, -1.6573165E-10, + 3.8359347E-14, -5.0546128E+03, -7.1555238E+00] +- name: O(s) + composition: {O: 1, Pt: 1} + thermo: + model: NASA7 + temperature-ranges: [300, 1000, 3000] + data: + - [-9.4986904E-01, 7.4042305E-03, -1.0451424E-06, -6.1120420E-09, + 3.3787992E-12, -1.3209912E+04, 3.6137905E+00] + - [1.9454180E+00, 9.1761647E-04, -1.1226719E-07, -9.9099624E-11, + 2.4307699E-14, -1.4005187E+04, -1.1531663E+01] diff --git a/test/thermo/thermoFromYaml.cpp b/test/thermo/thermoFromYaml.cpp index 18e4f22cc..ad410d588 100644 --- a/test/thermo/thermoFromYaml.cpp +++ b/test/thermo/thermoFromYaml.cpp @@ -3,6 +3,7 @@ #include "cantera/thermo/Elements.h" #include "cantera/thermo/MolalityVPSSTP.h" #include "cantera/thermo/IdealGasPhase.h" +#include "cantera/thermo/SurfPhase.h" using namespace Cantera; @@ -86,6 +87,28 @@ TEST(ThermoFromYaml, StoichSubstance2) EXPECT_NEAR(thermo->density(), 1980, 0.1); } +TEST(ThermoFromYaml, SurfPhase) +{ + auto thermo = newThermo("surface-phases.yaml", "Pt-surf"); + EXPECT_EQ(thermo->type(), "Surf"); + EXPECT_EQ(thermo->nSpecies(), (size_t) 3); + auto surf = std::dynamic_pointer_cast(thermo); + EXPECT_DOUBLE_EQ(surf->siteDensity(), 2.7063e-8); + vector_fp cov(surf->nSpecies()); + surf->getCoverages(cov.data()); + EXPECT_DOUBLE_EQ(cov[surf->speciesIndex("Pt(s)")], 0.5); + EXPECT_DOUBLE_EQ(cov[surf->speciesIndex("H(s)")], 0.4); +} + +TEST(ThermoFromYaml, EdgePhase) +{ + auto thermo = newThermo("surface-phases.yaml", "TPB"); + EXPECT_EQ(thermo->type(), "Edge"); + EXPECT_EQ(thermo->nSpecies(), (size_t) 1); + auto edge = std::dynamic_pointer_cast(thermo); + EXPECT_DOUBLE_EQ(edge->siteDensity(), 5e-18); +} + TEST(ThermoFromYaml, WaterSSTP) { auto thermo = newThermo("thermo-models.yaml", "liquid-water");