diff --git a/include/cantera/thermo/Phase.h b/include/cantera/thermo/Phase.h index 0dc75d7f4..5365a3b41 100644 --- a/include/cantera/thermo/Phase.h +++ b/include/cantera/thermo/Phase.h @@ -124,30 +124,31 @@ public: */ void setXMLdata(XML_Node& xmlPhase); - /*! @name Name and ID - * Class Phase contains two strings that identify a phase. The ID is the - * value of the ID attribute of the XML phase node that is used to - * initialize a phase when it is read. The name field is also initialized - * to the value of the ID attribute of the XML phase node. + /*! @name Name + * Class Phase uses the string name to identify a phase. The name is the + * value of the corresponding key in the phase map (in YAML), name (in + * CTI), or id (in XML) that is used to initialize a phase when it is read. * * However, the name field may be changed to another value during the - * course of a calculation. For example, if a phase is located in two - * places, but has the same constitutive input, the IDs of the two phases - * will be the same, but the names of the two phases may be different. - * - * It is an error to have two phases in a single problem with the same name - * and ID (or the name from one phase being the same as the id of - * another phase). Thus, it is expected that there is a 1-1 correspondence - * between names and unique phases within a Cantera problem. + * course of a calculation. For example, if duplicates of a phase object + * are instantiated and used in multiple places (e.g. a ReactorNet), they + * will have the same constitutive input, i.e. the names of the phases will + * be the same. Note that this is not a problem for Cantera internally; + * however, a user may want to rename phase objects in order to clarify. */ //!@{ //! Return the string id for the phase. + /*! + * @deprecated To be removed after Cantera 2.5. + */ std::string id() const; //! Set the string id for the phase. /*! * @param id String id of the phase + * + * @deprecated To be removed after Cantera 2.5. */ void setID(const std::string& id); diff --git a/interfaces/cython/cantera/composite.py b/interfaces/cython/cantera/composite.py index 191d1d2ea..b5d661c67 100644 --- a/interfaces/cython/cantera/composite.py +++ b/interfaces/cython/cantera/composite.py @@ -39,8 +39,9 @@ class Solution(ThermoPhase, Kinetics, Transport): gas = ct.Solution('diamond.yaml', name='gas') diamond = ct.Solution('diamond.yaml', name='diamond') - The name of the `Solution` object defaults to the *phase* specified in the - input file. Once instatiated, a custom name can assigned via:: + The name of the `Solution` object defaults to the *phase* identifier + specified in the input file. Upon initialization of a 'Solution' object, + a custom name can assigned via:: gas.name = 'my_custom_name' diff --git a/interfaces/cython/cantera/test/test_mixture.py b/interfaces/cython/cantera/test/test_mixture.py index b96107ee1..42f882bb4 100644 --- a/interfaces/cython/cantera/test/test_mixture.py +++ b/interfaces/cython/cantera/test/test_mixture.py @@ -112,11 +112,10 @@ class TestMixture(utilities.CanteraTest): def test_phase_moles(self): M = self.mix.phase_moles() - name = self.phase2.name self.assertEqual(M[0], self.mix.phase_moles(0)) - self.assertEqual(M[1], self.mix.phase_moles(name)) + self.assertEqual(M[1], self.mix.phase_moles('air')) - self.mix.set_phase_moles(name, 4) + self.mix.set_phase_moles('air', 4) self.assertEqual(self.mix.phase_moles(1), 4) def test_species_moles(self): diff --git a/src/kinetics/Kinetics.cpp b/src/kinetics/Kinetics.cpp index 300110b57..570f592f9 100644 --- a/src/kinetics/Kinetics.cpp +++ b/src/kinetics/Kinetics.cpp @@ -306,7 +306,7 @@ size_t Kinetics::kineticsSpeciesIndex(const std::string& nm, } for (size_t n = 0; n < m_thermo.size(); n++) { - string id = thermo(n).id(); + string id = thermo(n).name(); if (ph == id) { size_t k = thermo(n).speciesIndex(nm); if (k == npos) { @@ -451,7 +451,7 @@ void Kinetics::addPhase(thermo_t& thermo) m_rxnphase = nPhases(); } m_thermo.push_back(&thermo); - m_phaseindex[m_thermo.back()->id()] = nPhases(); + m_phaseindex[m_thermo.back()->name()] = nPhases(); resizeSpecies(); } @@ -608,7 +608,7 @@ shared_ptr Kinetics::reaction(size_t i) checkReactionIndex(i); return m_reactions[i]; } - + shared_ptr Kinetics::reaction(size_t i) const { checkReactionIndex(i); diff --git a/src/kinetics/importKinetics.cpp b/src/kinetics/importKinetics.cpp index 7d05355ff..296eb6f35 100644 --- a/src/kinetics/importKinetics.cpp +++ b/src/kinetics/importKinetics.cpp @@ -168,7 +168,7 @@ bool importKinetics(const XML_Node& phase, std::vector th, // loop over the supplied 'ThermoPhase' objects representing // phases, to find an object with the same id. for (size_t m = 0; m < th.size(); m++) { - if (th[m]->id() == phase_id) { + if (th[m]->name() == phase_id) { phase_ok = true; // if no phase with this id has been added to //the kinetics manager yet, then add this one @@ -176,7 +176,7 @@ bool importKinetics(const XML_Node& phase, std::vector th, k->addPhase(*th[m]); } } - msg += " "+th[m]->id(); + msg += " "+th[m]->name(); } if (!phase_ok) { throw CanteraError("importKinetics", @@ -254,7 +254,7 @@ bool checkElectrochemReaction(const XML_Node& p, Kinetics& kin, const XML_Node& size_t k = ph.speciesIndex(sp.first); double stoich = sp.second; for (size_t m = 0; m < phase_ids.size(); m++) { - if (phase_ids[m] == ph.id()) { + if (phase_ids[m] == ph.name()) { e_counter[m] += stoich * ph.charge(k); break; } @@ -267,7 +267,7 @@ bool checkElectrochemReaction(const XML_Node& p, Kinetics& kin, const XML_Node& size_t k = ph.speciesIndex(sp.first); double stoich = sp.second; for (size_t m = 0; m < phase_ids.size(); m++) { - if (phase_ids[m] == ph.id()) { + if (phase_ids[m] == ph.name()) { e_counter[m] -= stoich * ph.charge(k); break; } diff --git a/src/thermo/FixedChemPotSSTP.cpp b/src/thermo/FixedChemPotSSTP.cpp index a94a0e105..62105fdf9 100644 --- a/src/thermo/FixedChemPotSSTP.cpp +++ b/src/thermo/FixedChemPotSSTP.cpp @@ -40,7 +40,6 @@ FixedChemPotSSTP::FixedChemPotSSTP(const std::string& Ename, doublereal val) : chemPot_(0.0) { std::string pname = Ename + "Fixed"; - setID(pname); setName(pname); setNDim(3); addElement(Ename); diff --git a/src/thermo/LatticeSolidPhase.cpp b/src/thermo/LatticeSolidPhase.cpp index 02293b85b..a3ce57767 100644 --- a/src/thermo/LatticeSolidPhase.cpp +++ b/src/thermo/LatticeSolidPhase.cpp @@ -347,7 +347,7 @@ void LatticeSolidPhase::setLatticeStoichiometry(const compositionMap& comp) } // Add in the lattice stoichiometry constraint for (size_t i = 1; i < m_lattice.size(); i++) { - string econ = fmt::format("LC_{}_{}", i, id()); + string econ = fmt::format("LC_{}_{}", i, name()); size_t m = addElement(econ, 0.0, 0, 0.0, CT_ELEM_TYPE_LATTICERATIO); size_t mm = nElements(); for (size_t k = 0; k < m_lattice[0]->nSpecies(); k++) { diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index f1ef31a9a..e662fbded 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -68,11 +68,17 @@ void Phase::setXMLdata(XML_Node& xmlPhase) std::string Phase::id() const { + warn_deprecated("Phase::id", + "To be removed after Cantera 2.5. " + "Usage merged with 'Phase::name'"); return m_id; } void Phase::setID(const std::string& id_) { + warn_deprecated("Phase::setID", + "To be removed after Cantera 2.5. " + "Usage merged with 'Phase::setName'"); m_id = id_; m_name = id_; } diff --git a/src/thermo/PureFluidPhase.cpp b/src/thermo/PureFluidPhase.cpp index 2382ac511..5b7732350 100644 --- a/src/thermo/PureFluidPhase.cpp +++ b/src/thermo/PureFluidPhase.cpp @@ -64,7 +64,7 @@ void PureFluidPhase::initThermo() m_sub->setStdState(h0_RT*GasConstant*298.15/m_mw, s_R*GasConstant/m_mw, T0, p); debuglog("PureFluidPhase::initThermo: initialized phase " - +id()+"\n", m_verbose); + +name()+"\n", m_verbose); } void PureFluidPhase::setParametersFromXML(const XML_Node& eosdata) diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index 239c4af6a..d9e64b4aa 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -250,7 +250,6 @@ void importPhase(XML_Node& phase, ThermoPhase* th) th->setXMLdata(phase); // set the id attribute of the phase to the 'id' attribute in the XML tree. - th->setID(phase.id()); th->setName(phase.id()); // Number of spatial dimensions. Defaults to 3 (bulk phase) @@ -258,7 +257,7 @@ void importPhase(XML_Node& phase, ThermoPhase* th) int idim = intValue(phase["dim"]); if (idim < 1 || idim > 3) { throw CanteraError("importPhase", - "phase, " + th->id() + + "phase, " + th->name() + ", has unphysical number of dimensions: " + phase["dim"]); } th->setNDim(idim); @@ -274,7 +273,7 @@ void importPhase(XML_Node& phase, ThermoPhase* th) th->setParametersFromXML(eos); } else { throw CanteraError("importPhase", - " phase, " + th->id() + + " phase, " + th->name() + ", XML_Node does not have a \"thermo\" XML_Node"); } @@ -284,7 +283,7 @@ void importPhase(XML_Node& phase, ThermoPhase* th) vpss_ptr = dynamic_cast (th); if (vpss_ptr == 0) { throw CanteraError("importPhase", - "phase, " + th->id() + ", was VPSS, but dynamic cast failed"); + "phase, " + th->name() + ", was VPSS, but dynamic cast failed"); } } @@ -300,7 +299,7 @@ void importPhase(XML_Node& phase, ThermoPhase* th) vector sparrays = phase.getChildren("speciesArray"); if (ssConvention != cSS_CONVENTION_SLAVE && sparrays.empty()) { throw CanteraError("importPhase", - "phase, " + th->id() + ", has zero \"speciesArray\" XML nodes.\n" + "phase, " + th->name() + ", has zero \"speciesArray\" XML nodes.\n" + " There must be at least one speciesArray nodes " "with one or more species"); } @@ -448,7 +447,6 @@ void addSpecies(ThermoPhase& thermo, const AnyValue& names, const AnyValue& spec void setupPhase(ThermoPhase& thermo, AnyMap& phaseNode, const AnyMap& rootNode) { thermo.setName(phaseNode["name"].asString()); - thermo.setID(phaseNode["name"].asString()); if (rootNode.hasKey("__file__")) { phaseNode["__file__"] = rootNode["__file__"]; }