From a8f4c7609717e3053b51bed96529e19e3b93ee7f Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 27 Sep 2014 00:08:54 +0000 Subject: [PATCH] [Thermo] Check to make sure thermo data is installed for all species --- include/cantera/thermo/SimpleThermo.h | 1 + include/cantera/thermo/SpeciesThermo.h | 9 +++++++++ include/cantera/thermo/SpeciesThermoMgr.h | 1 + src/thermo/GeneralSpeciesThermo.cpp | 2 ++ src/thermo/NasaThermo.cpp | 1 + src/thermo/ShomateThermo.h | 2 +- src/thermo/SpeciesThermo.cpp | 24 +++++++++++++++++++++++ src/thermo/ThermoPhase.cpp | 5 +++++ 8 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/thermo/SpeciesThermo.cpp diff --git a/include/cantera/thermo/SimpleThermo.h b/include/cantera/thermo/SimpleThermo.h index 6f6419cee..7799c8123 100644 --- a/include/cantera/thermo/SimpleThermo.h +++ b/include/cantera/thermo/SimpleThermo.h @@ -166,6 +166,7 @@ public: throw CanteraError("install()", "Species have different reference pressures"); } m_p0 = refPressure_; + markInstalled(index); } virtual void install_STIT(SpeciesThermoInterpType* stit_ptr) { diff --git a/include/cantera/thermo/SpeciesThermo.h b/include/cantera/thermo/SpeciesThermo.h index 4a1a99d0e..d84a6ae1a 100644 --- a/include/cantera/thermo/SpeciesThermo.h +++ b/include/cantera/thermo/SpeciesThermo.h @@ -331,6 +331,15 @@ public: */ virtual void modifyOneHf298(const size_t k, const doublereal Hf298New) = 0; + //! Check if data for all species (0 through nSpecies-1) has been installed. + bool ready(size_t nSpecies); + +protected: + //! Mark species *k* as having its thermodynamic data installed + void markInstalled(size_t k); + +private: + std::vector m_installed; // indicates if data for species has been installed }; //@} } diff --git a/include/cantera/thermo/SpeciesThermoMgr.h b/include/cantera/thermo/SpeciesThermoMgr.h index 456101e53..fae145e26 100644 --- a/include/cantera/thermo/SpeciesThermoMgr.h +++ b/include/cantera/thermo/SpeciesThermoMgr.h @@ -174,6 +174,7 @@ SpeciesThermoDuo::install(const std::string& name, size_t sp, int type, } else { throw UnknownSpeciesThermo("SpeciesThermoDuo:install",type); } + markInstalled(sp); } template diff --git a/src/thermo/GeneralSpeciesThermo.cpp b/src/thermo/GeneralSpeciesThermo.cpp index e0d9d975d..fdc78f895 100644 --- a/src/thermo/GeneralSpeciesThermo.cpp +++ b/src/thermo/GeneralSpeciesThermo.cpp @@ -165,6 +165,7 @@ void GeneralSpeciesThermo::install(const std::string& name, } m_tlow_max = max(minTemp_, m_tlow_max); m_thigh_min = min(maxTemp_, m_thigh_min); + markInstalled(index); } void GeneralSpeciesThermo::install_STIT(SpeciesThermoInterpType* stit_ptr) @@ -194,6 +195,7 @@ void GeneralSpeciesThermo::install_STIT(SpeciesThermoInterpType* stit_ptr) */ m_tlow_max = max(stit_ptr->minTemp(), m_tlow_max); m_thigh_min = min(stit_ptr->maxTemp(), m_thigh_min); + markInstalled(index); } void GeneralSpeciesThermo::installPDSShandler(size_t k, PDSS* PDSS_ptr, diff --git a/src/thermo/NasaThermo.cpp b/src/thermo/NasaThermo.cpp index 75bfe1492..8bd3841d4 100644 --- a/src/thermo/NasaThermo.cpp +++ b/src/thermo/NasaThermo.cpp @@ -108,6 +108,7 @@ void NasaThermo::install(const std::string& name, size_t index, int type, throw CanteraError("install()", "species have different reference pressures"); } m_p0 = ref_pressure; + markInstalled(index); } void NasaThermo::update_one(size_t k, doublereal t, doublereal* cp_R, diff --git a/src/thermo/ShomateThermo.h b/src/thermo/ShomateThermo.h index f1bd317be..78c11f3d0 100644 --- a/src/thermo/ShomateThermo.h +++ b/src/thermo/ShomateThermo.h @@ -191,7 +191,7 @@ public: throw CanteraError("install()", "Species have different reference pressures"); } m_p0 = refPressure; - + markInstalled(index); } virtual void install_STIT(SpeciesThermoInterpType* stit_ptr) { diff --git a/src/thermo/SpeciesThermo.cpp b/src/thermo/SpeciesThermo.cpp new file mode 100644 index 000000000..7754403ce --- /dev/null +++ b/src/thermo/SpeciesThermo.cpp @@ -0,0 +1,24 @@ +#include "cantera/thermo/SpeciesThermo.h" + +namespace Cantera { + +bool SpeciesThermo::ready(size_t nSpecies) { + if (m_installed.size() < nSpecies) { + return false; + } + for (size_t k = 0; k < nSpecies; k++) { + if (!m_installed[k]) { + return false; + } + } + return true; +} + +void SpeciesThermo::markInstalled(size_t k) { + if (k >= m_installed.size()) { + m_installed.resize(k+1, false); + } + m_installed[k] = true; +} + +} diff --git a/src/thermo/ThermoPhase.cpp b/src/thermo/ThermoPhase.cpp index 18995761e..4f318f72e 100644 --- a/src/thermo/ThermoPhase.cpp +++ b/src/thermo/ThermoPhase.cpp @@ -677,6 +677,11 @@ void ThermoPhase::initThermo() throw CanteraError("ThermoPhase::initThermo()", "Number of species is equal to zero"); } + // Check to see that all of the species thermo objects have been initialized + if (!m_spthermo->ready(m_kk)) { + throw CanteraError("ThermoPhase::initThermo()", + "Missing species thermo data"); + } xMol_Ref.resize(m_kk, 0.0); } void ThermoPhase::installSlavePhases(Cantera::XML_Node* phaseNode)