From a9f2065f8cc360a62f74e436d12931f2176691a3 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sat, 27 Jun 2020 11:25:53 -0500 Subject: [PATCH] [Input] Preserve YAML note field for ThermoPhase --- include/cantera/thermo/Phase.h | 13 +++++++++++++ interfaces/cython/cantera/_cantera.pxd | 1 + interfaces/cython/cantera/thermo.pyx | 5 +++++ src/thermo/Phase.cpp | 3 ++- src/thermo/ThermoFactory.cpp | 2 ++ test/thermo/thermoFromYaml.cpp | 1 + 6 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/cantera/thermo/Phase.h b/include/cantera/thermo/Phase.h index efafdd5d474..2837c00b8ce 100644 --- a/include/cantera/thermo/Phase.h +++ b/include/cantera/thermo/Phase.h @@ -177,6 +177,16 @@ class Phase return "Phase"; } + //! Return the annotation string + std::string note() const { + return m_note; + } + + //! Set the annotation string + void setNote(const std::string& note) { + m_note = note; + } + //!@} end group Name //! @name Element and Species Information @@ -1004,6 +1014,9 @@ class Phase std::vector m_elementNames; //!< element names vector_int m_elem_type; //!< Vector of element types + //! Annotation string describing the phase + std::string m_note; + //! Entropy at 298.15 K and 1 bar of stable state pure elements (J kmol-1) vector_fp m_entropy298; diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 4044227c819..cba55d63a92 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -151,6 +151,7 @@ cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera": # miscellaneous string type() + string note() string phaseOfMatter() except +translate_exception string report(cbool, double) except +translate_exception cbool hasPhaseTransition() diff --git a/interfaces/cython/cantera/thermo.pyx b/interfaces/cython/cantera/thermo.pyx index 4d68d62cc35..79c735c3dd0 100644 --- a/interfaces/cython/cantera/thermo.pyx +++ b/interfaces/cython/cantera/thermo.pyx @@ -297,6 +297,11 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return pystr(self.thermo.type()) + property note: + """ Annotation string describing the thermo phase. """ + def __get__(self): + return pystr(self.thermo.note()) + property phase_of_matter: """ Get the thermodynamic phase (gas, liquid, etc.) at the current conditions. diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index 43bb989a4f1..305d46ea0ff 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -29,7 +29,8 @@ Phase::Phase() : m_mmw(0.0), m_stateNum(-1), m_mm(0), - m_elem_type(0) + m_elem_type(0), + m_note("") { } diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index ff40c20ea0d..4bd004a65fb 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -458,6 +458,8 @@ void setupPhase(ThermoPhase& thermo, AnyMap& phaseNode, const AnyMap& rootNode) warn_deprecated(method, msg); } + thermo.setNote(phaseNode.getString("note", "")); + // Add elements if (phaseNode.hasKey("elements")) { if (phaseNode.getBool("skip-undeclared-elements", false)) { diff --git a/test/thermo/thermoFromYaml.cpp b/test/thermo/thermoFromYaml.cpp index 2ae8ef5ceca..db267705e3f 100644 --- a/test/thermo/thermoFromYaml.cpp +++ b/test/thermo/thermoFromYaml.cpp @@ -45,6 +45,7 @@ TEST(ThermoFromYaml, elementOverride) EXPECT_DOUBLE_EQ(thermo->atomicWeight(0), getElementWeight("N")); EXPECT_DOUBLE_EQ(thermo->atomicWeight(1), getElementWeight("O")); EXPECT_DOUBLE_EQ(thermo->atomicWeight(2), 36); + EXPECT_EQ(thermo->note(), "replace Argon with custom element"); } TEST(ThermoFromYaml, elementFromDifferentFile)