[Equil] Deprecate get/setElementPotentials

This commit is contained in:
Ray Speth 2018-06-05 23:12:39 -04:00
parent 74167cc3eb
commit 3c978cdff6
6 changed files with 17 additions and 27 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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