From 3c978cdff6bb950c609b15215eb3d8f608abba96 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 5 Jun 2018 23:12:39 -0400 Subject: [PATCH] [Equil] Deprecate get/setElementPotentials --- include/cantera/equil/ChemEquil.h | 3 +++ include/cantera/thermo/ThermoPhase.h | 2 ++ interfaces/cython/cantera/thermo.pyx | 3 +++ src/equil/ChemEquil.cpp | 3 --- src/thermo/ThermoPhase.cpp | 10 +++++++++- test/thermo/ThermoPhase_Test.cpp | 23 ----------------------- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/include/cantera/equil/ChemEquil.h b/include/cantera/equil/ChemEquil.h index c5e35e966..49e8c5c9b 100644 --- a/include/cantera/equil/ChemEquil.h +++ b/include/cantera/equil/ChemEquil.h @@ -123,6 +123,8 @@ public: */ int equilibrate(thermo_t& s, const char* XY, vector_fp& elMoles, int loglevel = 0); + + //! @deprecated To be removed after Cantera 2.4. const vector_fp& elementPotentials() const { return m_lambda; } @@ -266,6 +268,7 @@ protected: vector_fp m_molefractions; //! Current value of the dimensional element potentials. length = #m_mm + //! @deprecated To be removed after Cantera 2.4. vector_fp m_lambda; //! Current value of the sum of the element abundances given the current diff --git a/include/cantera/thermo/ThermoPhase.h b/include/cantera/thermo/ThermoPhase.h index e4810f64f..11ee84b8f 100644 --- a/include/cantera/thermo/ThermoPhase.h +++ b/include/cantera/thermo/ThermoPhase.h @@ -1618,10 +1618,12 @@ protected: doublereal m_phi; //! Vector of element potentials. Length equal to number of elements. + //! @deprecated To be removed after Cantera 2.4. vector_fp m_lambdaRRT; //! Boolean indicating whether there is a valid set of saved element //! potentials for this phase + //! @deprecated To be removed after Cantera 2.4. bool m_hasElementPotentials; //! Boolean indicating whether a charge neutrality condition is a necessity diff --git a/interfaces/cython/cantera/thermo.pyx b/interfaces/cython/cantera/thermo.pyx index b80be1737..ce03fe44d 100644 --- a/interfaces/cython/cantera/thermo.pyx +++ b/interfaces/cython/cantera/thermo.pyx @@ -1331,6 +1331,9 @@ cdef class ThermoPhase(_SolutionBase): defined for equilibrium states. This method first sets the composition to a state of equilibrium at constant T and P, then computes the element potentials for this equilibrium state. + + .. deprecated:: 2.3 + To be removed after Cantera 2.4. """ self.equilibrate('TP') cdef np.ndarray[np.double_t, ndim=1] data = np.zeros(self.n_elements) diff --git a/src/equil/ChemEquil.cpp b/src/equil/ChemEquil.cpp index 83cb8de42..20e979293 100644 --- a/src/equil/ChemEquil.cpp +++ b/src/equil/ChemEquil.cpp @@ -585,9 +585,6 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr, adjustEloc(s, elMolesGoal); } - // Save the calculated and converged element potentials to the - // original ThermoPhase object. - s.setElementPotentials(m_lambda); if (s.temperature() > s.maxTemp() + 1.0 || s.temperature() < s.minTemp() - 1.0) { writelog("Warning: Temperature ({} K) outside valid range of " diff --git a/src/thermo/ThermoPhase.cpp b/src/thermo/ThermoPhase.cpp index a5e677408..fdd9b9ef8 100644 --- a/src/thermo/ThermoPhase.cpp +++ b/src/thermo/ThermoPhase.cpp @@ -702,7 +702,11 @@ void ThermoPhase::equilibrate(const std::string& XY, const std::string& solver, throw CanteraError("ThermoPhase::equilibrate", "ChemEquil solver failed. Return code: {}", ret); } - setElementPotentials(E.elementPotentials()); + m_lambdaRRT.resize(nElements()); + for (size_t m = 0; m < nElements(); m++) { + m_lambdaRRT[m] = E.elementPotentials()[m] / RT(); + } + m_hasElementPotentials = true; debuglog("ChemEquil solver succeeded\n", log_level); return; } catch (std::exception& err) { @@ -733,6 +737,8 @@ void ThermoPhase::equilibrate(const std::string& XY, const std::string& solver, void ThermoPhase::setElementPotentials(const vector_fp& lambda) { + warn_deprecated("ThermoPhase::setElementPotentials", + "To be removed after Cantera 2.4"); size_t mm = nElements(); if (lambda.size() < mm) { throw CanteraError("setElementPotentials", "lambda too small"); @@ -746,6 +752,8 @@ void ThermoPhase::setElementPotentials(const vector_fp& lambda) bool ThermoPhase::getElementPotentials(doublereal* lambda) const { + warn_deprecated("ThermoPhase::getElementPotentials", + "To be removed after Cantera 2.4"); if (m_hasElementPotentials) { scale(m_lambdaRRT.begin(), m_lambdaRRT.end(), lambda, RT()); } diff --git a/test/thermo/ThermoPhase_Test.cpp b/test/thermo/ThermoPhase_Test.cpp index 72022d45b..fd2673f02 100644 --- a/test/thermo/ThermoPhase_Test.cpp +++ b/test/thermo/ThermoPhase_Test.cpp @@ -23,29 +23,6 @@ public: } }; -TEST_F(ThermoPhase_Fixture, SetAndGetElementPotentials) -{ - initializeElements(); - - // Check that getElementPotentials returns false if no element potentials have been set yet. - vector_fp getLambda(3); - EXPECT_FALSE(test_phase.getElementPotentials(&getLambda[0])); - - vector_fp tooSmall(2); - EXPECT_THROW(test_phase.setElementPotentials(tooSmall), CanteraError); - - vector_fp setLambda(3); - setLambda[0] = 1.; - setLambda[1] = 2.; - setLambda[2] = 3.; - test_phase.setElementPotentials(setLambda); - - EXPECT_TRUE(test_phase.getElementPotentials(&getLambda[0])); - EXPECT_DOUBLE_EQ(setLambda[0], getLambda[0]); - EXPECT_DOUBLE_EQ(setLambda[1], getLambda[1]); - EXPECT_DOUBLE_EQ(setLambda[2], getLambda[2]); -} - class TestThermoMethods : public testing::Test { public: