From 8f4f72369e1a6c6fcbce970ef1bef6657f38dbf2 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 27 Feb 2012 18:12:13 +0000 Subject: [PATCH] Use the associated Cabinet to look up an item's index This allowed removal the m_index member and associated methods of the ThermoPhase, Kinetics, and Transport classes. --- include/cantera/kinetics/Kinetics.h | 16 ---------- include/cantera/thermo/Phase.h | 21 ------------ include/cantera/thermo/ThermoPhase.h | 39 ----------------------- include/cantera/transport/TransportBase.h | 25 --------------- src/clib/Cabinet.h | 15 +++++++++ src/clib/ct.cpp | 2 +- src/kinetics/Kinetics.cpp | 3 -- src/thermo/Phase.cpp | 13 -------- src/thermo/ThermoPhase.cpp | 3 -- src/transport/TransportBase.cpp | 19 ----------- 10 files changed, 16 insertions(+), 140 deletions(-) diff --git a/include/cantera/kinetics/Kinetics.h b/include/cantera/kinetics/Kinetics.h index d22dbf4da..10ed03632 100644 --- a/include/cantera/kinetics/Kinetics.h +++ b/include/cantera/kinetics/Kinetics.h @@ -961,20 +961,6 @@ public: void selectPhase(const doublereal* data, const thermo_t* phase, doublereal* phase_data); - /// For internal use. May be removed in a future release. - size_t index() { - return m_index; - } - - //! Set the index of the Kinetics Manager - /*! - * @param index input index - */ - void setIndex(size_t index) { - m_index = index; - } - - protected: @@ -1048,8 +1034,6 @@ protected: * -1. */ std::map m_phaseindex; - //! Index of the Kinetics Manager - size_t m_index; //! Index in the list of phases of the one surface phase. /*! diff --git a/include/cantera/thermo/Phase.h b/include/cantera/thermo/Phase.h index f0e49c0b6..9cd71cc4c 100644 --- a/include/cantera/thermo/Phase.h +++ b/include/cantera/thermo/Phase.h @@ -247,22 +247,6 @@ public: */ void setName(std::string nm); - //! Returns the index of the phase - /*! - * The index is used in the Python and matlab interfaces to - * index into a list of ThermoPhase objects - */ - size_t index() const; - - //! Sets the index of the phase - /*! - * The index is used in the Python and matlab interfaces to - * index into a list of ThermoPhase objects - * - * @param m Integer index of the phase - */ - void setIndex(size_t m); - //! Returns the index of a species named 'name' within the Phase object /*! * The first species in the phase will have an index 0, and the last one in the @@ -572,11 +556,6 @@ protected: * dimensionality 2. */ size_t m_ndim; - /** - * m_index is the index of the phase - * - */ - size_t m_index; private: diff --git a/include/cantera/thermo/ThermoPhase.h b/include/cantera/thermo/ThermoPhase.h index 40b76f52a..17c8a2c1d 100644 --- a/include/cantera/thermo/ThermoPhase.h +++ b/include/cantera/thermo/ThermoPhase.h @@ -2035,35 +2035,6 @@ public: */ virtual void installSlavePhases(Cantera::XML_Node* phaseNode); - // The following methods are used by the clib interface - // library, and should not be used by application programs. - - /*! - * @internal - * Index number. This method can be used to identify the - * location of a phase object in a list, and is used by the - * interface library (clib) routines for this purpose. - */ - size_t index() const { - return m_index; - } - - - /** - * @internal Set the index number. The Cantera interface - * library uses this method to set the index number to the - * location of the pointer to this object in the pointer array - * it maintains. Using this method for any other purpose will - * lead to unpredictable results if used in conjunction with - * the interface library. - * - * @param m Input the index number. - */ - void setIndex(size_t m) { - m_index = m; - } - - //! Set the equation of state parameters /*! * @internal @@ -2244,16 +2215,6 @@ protected: */ std::vector m_speciesData; - //! Index number of the phase - /*! - * The Cantera interface library uses this member to set the index number to the - * location of the pointer to this object in the pointer array of ThermoPhase's - * it maintains. Using this member for any other purpose will - * lead to unpredictable results if used in conjunction with - * the interface library. - */ - size_t m_index; - //! Stored value of the electric potential for this phase /*! * Units are Volts diff --git a/include/cantera/transport/TransportBase.h b/include/cantera/transport/TransportBase.h index c4937a1ec..8b6c50185 100644 --- a/include/cantera/transport/TransportBase.h +++ b/include/cantera/transport/TransportBase.h @@ -246,25 +246,6 @@ public: */ bool ready(); - - //! Returns an integer index number. - /*! - * @internal This is for internal use - * of Cantera, and may be removed in the future. - * - * @return Returns the index number - */ - size_t index() const; - - //! Set an integer index number. - /*! - * @internal This is for internal use of - * Cantera, and may be removed in the future. - * - * @param i index value - */ - void setIndex(size_t i); - //! Set the number of dimensions to be expected in flux expressions /*! * Internal memory will be set with this value. @@ -862,12 +843,6 @@ protected: //! Number of species size_t m_nmin; - //! Value of the internal index - /*! - * @deprecated - */ - size_t m_index; - //! Number of dimensions used in flux expresions size_t m_nDim; diff --git a/src/clib/Cabinet.h b/src/clib/Cabinet.h index 4c490029c..99db07895 100644 --- a/src/clib/Cabinet.h +++ b/src/clib/Cabinet.h @@ -64,6 +64,7 @@ class Cabinet { public: typedef std::vector& dataRef; + typedef typename std::vector::iterator dataIterator; /** * Destructor. Delete all objects in the list. */ @@ -166,6 +167,20 @@ public: } } + /** + * Return the index in the Cabinet to the specified object, or -1 + * if the object is not in the cabinet. + */ + static int index(const M& obj) { + dataRef data = getData(); + dataIterator loc = std::find(data.begin(), data.end(), &obj); + if (loc != data.end()) { + return static_cast(loc-data.begin()); + } else { + return -1; + } + } + /** * Constructor. */ diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index b88499450..5a9479a89 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -1175,7 +1175,7 @@ extern "C" { size_t DLL_EXPORT kin_phase(int n, size_t i) { - return KineticsCabinet::item(n).thermo(i).index(); + return ThermoCabinet::index(KineticsCabinet::item(n).thermo(i)); } int DLL_EXPORT kin_getEquilibriumConstants(int n, size_t len, double* kc) diff --git a/src/kinetics/Kinetics.cpp b/src/kinetics/Kinetics.cpp index 5b07aad2c..8b931f8ba 100644 --- a/src/kinetics/Kinetics.cpp +++ b/src/kinetics/Kinetics.cpp @@ -32,7 +32,6 @@ Kinetics::Kinetics() : m_thermo(0), m_start(0), m_phaseindex(), - m_index(-1), m_surfphase(-1), m_rxnphase(-1), m_mindim(4), @@ -57,7 +56,6 @@ Kinetics::Kinetics(const Kinetics& right) : m_thermo(0), m_start(0), m_phaseindex(), - m_index(-1), m_surfphase(-1), m_rxnphase(-1), m_mindim(4), @@ -96,7 +94,6 @@ operator=(const Kinetics& right) m_start = right.m_start; m_phaseindex = right.m_phaseindex; - m_index = right.m_index; m_surfphase = right.m_surfphase; m_rxnphase = right.m_rxnphase; m_mindim = right.m_mindim; diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index dc89c13a4..4956ddbbe 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -22,7 +22,6 @@ Phase::Phase() : State(), m_kk(0), m_ndim(3), - m_index(-1), m_xml(new XML_Node("phase")), m_id(""), m_name("") @@ -40,7 +39,6 @@ Phase::Phase(const Phase& right) : State(), m_kk(0), m_ndim(3), - m_index(-1), m_xml(new XML_Node("phase")), m_id(""), m_name("") @@ -78,7 +76,6 @@ Phase& Phase::operator=(const Phase& right) */ m_kk = right.m_kk; m_ndim = right.m_ndim; - m_index = right.m_index; m_data = right.m_data; /* * This is a little complicated. -> Because we delete m_xml @@ -134,16 +131,6 @@ void Phase::setName(std::string nm) m_name = nm; } -size_t Phase::index() const -{ - return m_index; -} - -void Phase::setIndex(size_t m) -{ - m_index = m; -} - // Returns the index of a species named 'name' within the Phase object /* * The first species in the phase will have an index 0, and the last one in the diff --git a/src/thermo/ThermoPhase.cpp b/src/thermo/ThermoPhase.cpp index be47fbe5e..59d64cc0f 100644 --- a/src/thermo/ThermoPhase.cpp +++ b/src/thermo/ThermoPhase.cpp @@ -23,7 +23,6 @@ namespace Cantera ThermoPhase::ThermoPhase() : Phase(), m_spthermo(0), m_speciesData(0), - m_index(-1), m_phi(0.0), m_hasElementPotentials(false), m_chargeNeutralityNecessary(false), @@ -54,7 +53,6 @@ ThermoPhase::ThermoPhase(const ThermoPhase& right) : Phase(), m_spthermo(0), m_speciesData(0), - m_index(-1), m_phi(0.0), m_hasElementPotentials(false), m_chargeNeutralityNecessary(false), @@ -114,7 +112,6 @@ operator=(const ThermoPhase& right) m_speciesData[k] = new XML_Node(*(right.m_speciesData[k])); } - m_index = right.m_index; m_phi = right.m_phi; m_lambdaRRT = right.m_lambdaRRT; m_hasElementPotentials = right.m_hasElementPotentials; diff --git a/src/transport/TransportBase.cpp b/src/transport/TransportBase.cpp index fc0cb5392..783bf4a4c 100644 --- a/src/transport/TransportBase.cpp +++ b/src/transport/TransportBase.cpp @@ -33,7 +33,6 @@ Transport::Transport(thermo_t* thermo, size_t ndim) : m_thermo(thermo), m_ready(false), m_nmin(0), - m_index(npos), m_nDim(ndim), m_velocityBasis(VB_MASSAVG) { @@ -44,7 +43,6 @@ Transport::Transport(const Transport& right) m_thermo = right.m_thermo; m_ready = right.m_ready; m_nmin = right.m_nmin; - m_index = right.m_index; m_nDim = right.m_nDim; m_velocityBasis = right.m_velocityBasis; } @@ -58,7 +56,6 @@ Transport& Transport::operator=(const Transport& right) m_thermo = right.m_thermo; m_ready = right.m_ready; m_nmin = right.m_nmin; - m_index = right.m_index; m_nDim = right.m_nDim; m_velocityBasis = right.m_velocityBasis; return *this; @@ -80,19 +77,6 @@ bool Transport::ready() return m_ready; } -size_t Transport::index() const -{ - return m_index; -} - -/* Set an integer index number. This is for internal use of - * Cantera, and may be removed in the future. - */ -void Transport::setIndex(size_t i) -{ - m_index = i; -} - // Set the number of dimensions to be expected in flux expressions /* Internal memory will be set with this value */ @@ -101,9 +85,6 @@ void Transport::setNDim(const int ndim) m_nDim = ndim; } - - - /* Set transport model parameters. This method may be * overloaded in subclasses to set model-specific parameters. */