[Thermo] deprecate Phase::id and Phase::setID

* Merge usage of 'id' and 'name' in the context of Phase objects
* Raise deprecation warnings for Phase::id and Phase::setID
This commit is contained in:
Ingmar Schoegl 2019-10-10 06:37:19 -05:00 committed by Ray Speth
parent 6e5d45273a
commit 7c08e17f08
10 changed files with 38 additions and 34 deletions

View file

@ -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);

View file

@ -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'

View file

@ -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):

View file

@ -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();
}

View file

@ -168,7 +168,7 @@ bool importKinetics(const XML_Node& phase, std::vector<ThermoPhase*> 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<ThermoPhase*> 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;
}

View file

@ -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);

View file

@ -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++) {

View file

@ -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_;
}

View file

@ -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)

View file

@ -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 <VPStandardStateTP*>(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<XML_Node*> 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__"];
}