Skip to content

Commit

Permalink
Test fail when setTemperature is abstracted from PengRobinson to Mixt…
Browse files Browse the repository at this point in the history
…ureFugacityTP
  • Loading branch information
decaluwe committed Dec 30, 2019
1 parent d6af231 commit bbedc50
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 40 deletions.
25 changes: 17 additions & 8 deletions include/cantera/thermo/MixtureFugacityTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ class MixtureFugacityTP : public ThermoPhase
virtual void getStandardVolumes(doublereal* vol) const;
// @}

//! Set the temperature of the phase
/*!
* Currently this passes down to setState_TP(). It does not make sense to
* calculate the standard state without first setting T and P.
*
* @param temp Temperature (kelvin)
*/
virtual void setTemperature(const doublereal temp);
// //! Set the temperature of the phase
// /*!
// * Currently this passes down to setState_TP(). It does not make sense to
// * calculate the standard state without first setting T and P.
// *
// * @param temp Temperature (kelvin)
// */
// virtual void setTemperature(const doublereal temp);

//! Set the internally stored pressure (Pa) at constant temperature and
//! composition
Expand Down Expand Up @@ -306,6 +306,7 @@ class MixtureFugacityTP : public ThermoPhase
virtual void setState_TPX(doublereal t, doublereal p, const doublereal* x);

protected:
virtual void setTemperature(const double temp);
virtual void compositionChanged();
void setMoleFractions_NoState(const doublereal* const x);

Expand Down Expand Up @@ -545,6 +546,14 @@ class MixtureFugacityTP : public ThermoPhase

virtual void updateMixingExpressions();

//! Update the a and b parameters
/*!
* The a and the b parameters depend on the mole fraction and the
* temperature. This function updates the internal numbers based on the
* state of the object.
*/
void updateAB();


//! Solve the cubic equation of state
/*!
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/PengRobinson.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class PengRobinson : public MixtureFugacityTP

protected:

virtual void setTemperature(const double temp);
// virtual void setTemperature(const double temp);
virtual void compositionChanged();

public:
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/RedlichKwongMFTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class RedlichKwongMFTP : public MixtureFugacityTP

protected:

virtual void setTemperature(const doublereal temp);
// virtual void setTemperature(const doublereal temp);
virtual void compositionChanged();

public:
Expand Down
17 changes: 11 additions & 6 deletions src/thermo/MixtureFugacityTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,17 @@ bool MixtureFugacityTP::addSpecies(shared_ptr<Species> spec)
return added;
}

void MixtureFugacityTP::setTemperature(const doublereal temp)
void MixtureFugacityTP::setPressure(doublereal p)
{
_updateReferenceStateThermo();
setState_TR(temperature(), density());
setState_TP(temperature(), p);
}

void MixtureFugacityTP::setPressure(doublereal p)
void MixtureFugacityTP::setTemperature(const doublereal temp)
{
setState_TP(temperature(), p);
}
Phase::setTemperature(temp);
_updateReferenceStateThermo();
updateAB();
}

void MixtureFugacityTP::compositionChanged()
{
Expand Down Expand Up @@ -537,6 +538,10 @@ doublereal MixtureFugacityTP::densityCalc(doublereal TKelvin, doublereal presPa,
return densBase;
}

void MixtureFugacityTP::updateAB()
{
}

void MixtureFugacityTP::updateMixingExpressions()
{
}
Expand Down
22 changes: 11 additions & 11 deletions src/thermo/PengRobinson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ double PengRobinson::pressure() const
return pp;
}

void PengRobinson::setTemperature(const double temp)
{
Phase::setTemperature(temp);
_updateReferenceStateThermo();
updateAB();
}
// void PengRobinson::setTemperature(const doublereal temp)
// {
// Phase::setTemperature(temp);
// _updateReferenceStateThermo();
// updateAB();
// }

void PengRobinson::compositionChanged()
{
Expand Down Expand Up @@ -918,12 +918,12 @@ void PengRobinson::updateAB()
double temp = temperature();
//Update aAlpha_i
double sqt_alpha;
double criTemp = critTemperature();
double sqt_T_reduced = sqrt(temp / criTemp);
double critTemp = critTemperature();
double sqt_T_reduced = sqrt(temp / critTemp);

// Update indiviual alpha
for (size_t j = 0; j < m_kk; j++) {
sqt_alpha = 1 + kappa_vec_[j] * (1 - sqt_T_reduced);
sqt_alpha = 1. + kappa_vec_[j] * (1. - sqt_T_reduced);
alpha_vec_Curr_[j] = sqt_alpha*sqt_alpha;
}

Expand All @@ -932,7 +932,7 @@ void PengRobinson::updateAB()
for (size_t j = 0; j < m_kk; j++) {
size_t counter = i * m_kk + j;
a_vec_Curr_[counter] = a_coeff_vec(0, counter);
aAlpha_vec_Curr_[counter] = sqrt(alpha_vec_Curr_[i] * alpha_vec_Curr_[j]) * a_coeff_vec(0, counter);
aAlpha_vec_Curr_[counter] = sqrt(alpha_vec_Curr_[i] * alpha_vec_Curr_[j]) * a_vec_Curr_[counter];
}
}

Expand All @@ -944,7 +944,7 @@ void PengRobinson::updateAB()
m_b_current += moleFractions_[i] * b_vec_Curr_[i];
for (size_t j = 0; j < m_kk; j++) {
m_a_current += a_vec_Curr_[i * m_kk + j] * moleFractions_[i] * moleFractions_[j];
m_aAlpha_current += aAlpha_vec_Curr_[i * m_kk + j] * moleFractions_[i] * moleFractions_[j];
m_aAlpha_current += aAlpha_vec_Curr_[i * m_kk + j] * moleFractions_[i] * moleFractions_[j];
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/thermo/RedlichKwongMFTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,6 @@ doublereal RedlichKwongMFTP::pressure() const
return pp;
}

void RedlichKwongMFTP::setTemperature(const doublereal temp)
{
Phase::setTemperature(temp);
_updateReferenceStateThermo();
updateAB();
}

void RedlichKwongMFTP::compositionChanged()
{
MixtureFugacityTP::compositionChanged();
Expand Down
13 changes: 7 additions & 6 deletions test/thermo/PengRobinson_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,22 @@ TEST_F(PengRobinson_Test, getPressure)
double acc_factor = 0.228;
double pres_theoretical, kappa, alpha, mv;
const double rho = 1.0737;

set_r(1.);
const double Tcrit = test_phase->critTemperature();

//Calculate kappa value
kappa = 0.37464 + 1.54226*acc_factor - 0.26992*acc_factor*acc_factor;

for (int i = 0; i<10; i++)
{
const double temp = 296 + i * 2;
set_r(0.999);
test_phase->setState_TR(temp, 1.0737);
mv = 1 / rho * test_phase->meanMolecularWeight();
const double temp = 296 + i * 2.;
test_phase->setState_TR(temp, rho);
mv = test_phase->meanMolecularWeight() / rho ;
//Calculate pressure using Peng-Robinson EoS
alpha = pow(1 + kappa*(1 - sqrt(temp / Tcrit)), 2);
alpha = pow(1. + kappa*(1 - sqrt(temp / Tcrit)), 2.);
pres_theoretical = GasConstant*temp / (mv - b_coeff) - a_coeff*alpha / (mv*mv + 2*b_coeff*mv - b_coeff*b_coeff);
EXPECT_NEAR(test_phase->pressure(), pres_theoretical, 2);
EXPECT_NEAR(test_phase->pressure(), pres_theoretical, 1.e-8);
}
}
};

0 comments on commit bbedc50

Please sign in to comment.