From 96cf312ec6e765e174e1fc5b1403682158c02ccb Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 18 Apr 2015 16:19:00 -0400 Subject: [PATCH] [Thermo] Always add species using Species objects Deprecate the non-Species-based addSpecies and addUniqueSpecies functions. --- include/cantera/thermo/Phase.h | 4 ++++ src/thermo/FixedChemPotSSTP.cpp | 14 ++++---------- src/thermo/LatticeSolidPhase.cpp | 23 +---------------------- src/thermo/Phase.cpp | 6 ++++++ 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/include/cantera/thermo/Phase.h b/include/cantera/thermo/Phase.h index caec1b758..2b70d1fdb 100644 --- a/include/cantera/thermo/Phase.h +++ b/include/cantera/thermo/Phase.h @@ -763,6 +763,8 @@ public: //! @see ignoreUndefinedElements addUndefinedElements throwUndefinedElements virtual bool addSpecies(shared_ptr spec); + //! @deprecated Use AddSpecies(shared_ptr spec) instead. To be + //! removed after Cantera 2.2. void addSpecies(const std::string& name, const doublereal* comp, doublereal charge = 0.0, doublereal size = 1.0); @@ -774,6 +776,8 @@ public: //! species. //! @param charge Charge of the species. Defaults to zero. //! @param size Size of the species (meters). Defaults to 1 meter. + //! @deprecated Use addSpecies(shared_ptr spec) instead. To be + //! removed after Cantera 2.2. void addUniqueSpecies(const std::string& name, const doublereal* comp, doublereal charge = 0.0, doublereal size = 1.0); diff --git a/src/thermo/FixedChemPotSSTP.cpp b/src/thermo/FixedChemPotSSTP.cpp index b4d5a0671..a55801cad 100644 --- a/src/thermo/FixedChemPotSSTP.cpp +++ b/src/thermo/FixedChemPotSSTP.cpp @@ -84,18 +84,12 @@ FixedChemPotSSTP::FixedChemPotSSTP(const std::string& Ename, doublereal val) : setName(pname); setNDim(3); addElement(Ename); - vector_fp ecomp(nElements(), 0.0); - ecomp[0] = 1.0; - double chrg = 0.0; - addUniqueSpecies(pname, &ecomp[0], chrg, 0.0); - double c[4]; - c[0] = 298.15; - c[1] = val; - c[2] = 0.0; - c[3] = 0.0; + shared_ptr sp(new Species(pname, parseCompString(Ename + ":1.0"))); + double c[4] = {298.15, val, 0.0, 0.0}; shared_ptr stit( newSpeciesThermoInterpType("const_cp", 0.1, 1e30, OneAtm, c)); - m_spthermo->install_STIT(0, stit); + sp->thermo = stit; + addSpecies(sp); initThermo(); m_p0 = OneAtm; m_tlast = 298.15; diff --git a/src/thermo/LatticeSolidPhase.cpp b/src/thermo/LatticeSolidPhase.cpp index 478c026a9..568eed052 100644 --- a/src/thermo/LatticeSolidPhase.cpp +++ b/src/thermo/LatticeSolidPhase.cpp @@ -341,31 +341,10 @@ void LatticeSolidPhase::installSlavePhases(Cantera::XML_Node* phaseNode) addElement(lp->elementName(es), aws[es], lp->atomicNumber(es), lp->entropyElement298(es), lp->elementType(es)); } - const std::vector & spNode = lp->speciesData(); kstart = kk; - for (size_t k = 0; k < lp->nSpecies(); k++) { - std::map comp; - lp->getAtoms(k, DATA_PTR(constArr)); - vector_fp ecomp(nElements(), 0.0); - for (size_t m = 0; m < lp->nElements(); m++) { - if (constArr[m] != 0.0) { - size_t newIndex = elementIndex(lp->elementName(m)); - if (newIndex == npos) { - throw CanteraError("LatticeSolidPhase::installSlavePhases", - "element not found"); - } - ecomp[newIndex] = constArr[m]; - } - } - addUniqueSpecies(lp->speciesName(k), &ecomp[0], lp->charge(k), - lp->size(k)); - shared_ptr stit( - newSpeciesThermoInterpType(spNode[k]->child("thermo"))); - stit->validate(spNode[k]->attrib("name")); - m_spthermo->install_STIT(kk, stit); - m_speciesData.push_back(new XML_Node(*(spNode[k]))); + addSpecies(lp->species(k)); kk++; } /* diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index 2c59ebbe4..9254ee30f 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -926,6 +926,9 @@ bool Phase::addSpecies(shared_ptr spec) { void Phase::addSpecies(const std::string& name_, const doublereal* comp, doublereal charge_, doublereal size_) { + warn_deprecated("Phase::addSpecies(string, double*, double, double)", + "Use AddSpecies(shared_ptr spec) instead. To be removed " + "after Cantera 2.2."); compositionMap cmap; for (size_t i = 0; i < nElements(); i++) { if (comp[i]) { @@ -939,6 +942,9 @@ void Phase::addSpecies(const std::string& name_, const doublereal* comp, void Phase::addUniqueSpecies(const std::string& name_, const doublereal* comp, doublereal charge_, doublereal size_) { + warn_deprecated("Phase::addUniqueSpecies", + "Use AddSpecies(shared_ptr spec) instead. To be removed " + "after Cantera 2.2."); for (size_t k = 0; k < m_kk; k++) { if (m_speciesNames[k] == name_) { // We have found a match. Do some compatibility checks.