make more functions NotImplemented for PlasmaPhase

This commit is contained in:
bangshiuh 2022-10-11 22:15:04 -04:00 committed by Ingmar Schoegl
parent a1d393087b
commit 2f9abcfa73
3 changed files with 150 additions and 62 deletions

View File

@ -228,20 +228,38 @@ public:
*/
virtual double enthalpy_mole() const;
virtual double entropy_mole() const;
virtual double cp_mole() const {
throw NotImplementedError("PlasmaPhase::cp_mole");
}
virtual double gibbs_mole() const;
virtual double entropy_mole() const {
throw NotImplementedError("PlasmaPhase::entropy_mole");
}
virtual double gibbs_mole() const {
throw NotImplementedError("PlasmaPhase::gibbs_mole");
}
virtual double intEnergy_mole() const {
throw NotImplementedError("PlasmaPhase::intEnergy_mole");
}
virtual void getEntropy_R(double* sr) const;
virtual void getGibbs_RT(double* grt) const;
virtual void getGibbs_ref(double* g) const;
virtual void getStandardVolumes_ref(double* vol) const;
virtual void getStandardChemPotentials(double* mu) const;
virtual void getChemPotentials(double* mu) const;
virtual void getStandardChemPotentials(double* muStar) const;
virtual void getPartialMolarEnthalpies(double* hbar) const;
virtual void getPartialMolarEntropies(double* sbar) const;
virtual void getPartialMolarIntEnergies(double* ubar) const;
virtual void getParameters(AnyMap& phaseNode) const;

View File

@ -276,20 +276,6 @@ double PlasmaPhase::enthalpy_mole() const {
return value;
}
double PlasmaPhase::entropy_mole() const {
warn_user("PlasmaPhase::entropy_mole",
"Use the same equation of IdealGasPhase::entropy_mole "
"which is not correct for plasma.");
return IdealGasPhase::entropy_mole();
}
double PlasmaPhase::gibbs_mole() const {
warn_user("PlasmaPhase::gibbs_mole",
"Use the same equation of IdealGasPhase::gibbs_mole "
"which is not correct for plasma.");
return IdealGasPhase::gibbs_mole();
}
void PlasmaPhase::getGibbs_ref(double* g) const
{
IdealGasPhase::getGibbs_ref(g);
@ -302,28 +288,20 @@ void PlasmaPhase::getStandardVolumes_ref(double* vol) const
vol[m_electronSpeciesIndex] *= electronTemperature() / temperature();
}
void PlasmaPhase::getStandardChemPotentials(double* muStar) const
{
warn_user("PlasmaPhase::getStandardChemPotentials",
"Use the same equation of IdealGasPhase::getStandardChemPotentials "
"which is not correct for plasma.");
IdealGasPhase::getStandardChemPotentials(muStar);
}
void PlasmaPhase::getChemPotentials(double* mu) const
{
warn_user("PlasmaPhase::getChemPotentials",
"Use the same equation of IdealGasPhase::getChemPotentials "
"which is not correct for plasma.");
IdealGasPhase::getChemPotentials(mu);
}
void PlasmaPhase::getPartialMolarEnthalpies(double* hbar) const
{
IdealGasPhase::getPartialMolarEnthalpies(hbar);
hbar[m_electronSpeciesIndex] *= electronTemperature() / temperature();
}
void PlasmaPhase::getPartialMolarEntropies(double* sbar) const
{
IdealGasPhase::getPartialMolarEntropies(sbar);
double logp = log(pressure());
double logpe = log(electronPressure());
sbar[m_electronSpeciesIndex] += GasConstant * (logp - logpe);
}
void PlasmaPhase::getPartialMolarIntEnergies(double* ubar) const
{
const vector_fp& _h = enthalpy_RT_ref();
@ -334,4 +312,48 @@ void PlasmaPhase::getPartialMolarIntEnergies(double* ubar) const
ubar[k] = RTe() * (_h[k] - 1.0);
}
void PlasmaPhase::getChemPotentials(double* mu) const
{
IdealGasPhase::getChemPotentials(mu);
size_t k = m_electronSpeciesIndex;
double xx = std::max(SmallNumber, moleFraction(k));
mu[k] += (RTe() - RT()) * log(xx);
}
void PlasmaPhase::getStandardChemPotentials(double* muStar) const
{
IdealGasPhase::getStandardChemPotentials(muStar);
size_t k = m_electronSpeciesIndex;
muStar[k] -= log(pressure() / refPressure()) * RT();
muStar[k] += log(electronPressure() / refPressure()) * RTe();
}
void PlasmaPhase::getEntropy_R(double* sr) const
{
const vector_fp& _s = entropy_R_ref();
copy(_s.begin(), _s.end(), sr);
double tmp = log(pressure() / refPressure());
for (size_t k = 0; k < m_kk; k++) {
if (k != m_electronSpeciesIndex) {
sr[k] -= tmp;
} else {
sr[k] -= log(electronPressure() / refPressure());
}
}
}
void PlasmaPhase::getGibbs_RT(double* grt) const
{
const vector_fp& gibbsrt = gibbs_RT_ref();
copy(gibbsrt.begin(), gibbsrt.end(), grt);
double tmp = log(pressure() / refPressure());
for (size_t k = 0; k < m_kk; k++) {
if (k != m_electronSpeciesIndex) {
grt[k] += tmp;
} else {
grt[k] += log(electronPressure() / refPressure());
}
}
}
}

View File

@ -121,16 +121,26 @@ map<pair<string, string>, shared_ptr<ThermoPhase>> TestConsistency::cache = {};
// --------------- Definitions for individual consistency tests ---------------
TEST_P(TestConsistency, h_eq_u_plus_Pv) {
double h = phase->enthalpy_mole();
double u = phase->intEnergy_mole();
double v = phase->molarVolume();
double h, u, v;
try {
h = phase->enthalpy_mole();
u = phase->intEnergy_mole();
v = phase->molarVolume();
} catch (NotImplementedError& err) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
EXPECT_NEAR(h, u + p * v, atol);
}
TEST_P(TestConsistency, g_eq_h_minus_Ts) {
double g = phase->gibbs_mole();
double h = phase->enthalpy_mole();
double s = phase->entropy_mole();
double g, h, s;
try {
g = phase->gibbs_mole();
h = phase->enthalpy_mole();
s = phase->entropy_mole();
} catch (NotImplementedError& err) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
EXPECT_NEAR(g, h - T * s, atol);
}
@ -145,11 +155,9 @@ TEST_P(TestConsistency, hk_eq_uk_plus_P_vk)
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
for (size_t k = 0; k < nsp; k++) {
if (k == ke) {
EXPECT_NEAR(hk[k], uk[k] + RTe, atol) << "k = " << k;
} else {
if (k != ke) {
EXPECT_NEAR(hk[k], uk[k] + p * vk[k], atol) << "k = " << k;
}
} // not applicable for electron
}
}
@ -164,7 +172,9 @@ TEST_P(TestConsistency, gk_eq_hk_minus_T_sk)
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
for (size_t k = 0; k < nsp; k++) {
EXPECT_NEAR(gk[k], hk[k] - T * sk[k], atol) << "k = " << k;
if (k != ke) {
EXPECT_NEAR(gk[k], hk[k] - T * sk[k], atol) << "k = " << k;
} // not applicable for electron
}
}
@ -182,34 +192,40 @@ TEST_P(TestConsistency, h_eq_sum_hk_Xk)
TEST_P(TestConsistency, u_eq_sum_uk_Xk)
{
vector_fp uk(nsp);
double u;
try {
phase->getPartialMolarIntEnergies(uk.data());
u = phase->intEnergy_mole();
} catch (NotImplementedError& err) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
EXPECT_NEAR(phase->intEnergy_mole(), phase->mean_X(uk), atol);
EXPECT_NEAR(u, phase->mean_X(uk), atol);
}
TEST_P(TestConsistency, g_eq_sum_gk_Xk)
{
vector_fp gk(nsp);
double g;
try {
phase->getChemPotentials(gk.data());
g = phase->gibbs_mole();
} catch (NotImplementedError& err) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
EXPECT_NEAR(phase->gibbs_mole(), phase->mean_X(gk), atol);
EXPECT_NEAR(g, phase->mean_X(gk), atol);
}
TEST_P(TestConsistency, s_eq_sum_sk_Xk)
{
vector_fp sk(nsp);
double s;
try {
phase->getPartialMolarEntropies(sk.data());
s = phase->entropy_mole();
} catch (NotImplementedError& err) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
EXPECT_NEAR(phase->entropy_mole(), phase->mean_X(sk), atol);
EXPECT_NEAR(s, phase->mean_X(sk), atol);
}
TEST_P(TestConsistency, v_eq_sum_vk_Xk)
@ -226,12 +242,14 @@ TEST_P(TestConsistency, v_eq_sum_vk_Xk)
TEST_P(TestConsistency, cp_eq_sum_cpk_Xk)
{
vector_fp cpk(nsp);
double cp;
try {
phase->getPartialMolarCp(cpk.data());
cp = phase->cp_mole();
} catch (NotImplementedError& err) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
EXPECT_NEAR(phase->cp_mole(), phase->mean_X(cpk), atol);
EXPECT_NEAR(cp, phase->mean_X(cpk), atol);
}
TEST_P(TestConsistency, cp_eq_dhdT)
@ -320,10 +338,15 @@ TEST_P(TestConsistency, cv_eq_dsdT_const_v_times_T)
TEST_P(TestConsistency, dsdP_const_T_eq_minus_dV_dT_const_P)
{
double s1 = phase->entropy_mole();
double P1 = phase->pressure();
double T1 = phase->temperature();
double v1 = phase->molarVolume();
double s1, P1, T1, v1;
try {
s1 = phase->entropy_mole();
P1 = phase->pressure();
T1 = phase->temperature();
v1 = phase->molarVolume();
} catch (NotImplementedError& err) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
double P2 = P1 * (1 + 1e-6);
phase->setState_TP(T1, P2);
double s2 = phase->entropy_mole();
@ -339,7 +362,12 @@ TEST_P(TestConsistency, dsdP_const_T_eq_minus_dV_dT_const_P)
TEST_P(TestConsistency, dSdv_const_T_eq_dPdT_const_V) {
if (phase->isCompressible()) {
double s1 = phase->entropy_mass();
double s1;
try {
s1 = phase->entropy_mass();
} catch (NotImplementedError& err) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
double v1 = 1 / phase->density();
double P1 = phase->pressure();
double v2 = v1 * (1 + 1e-7);
@ -423,7 +451,11 @@ TEST_P(TestConsistency, standard_gibbs_nondim)
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
for (size_t k = 0; k < nsp; k++) {
EXPECT_NEAR(g0_RT[k] * RT , mu0[k], atol) << "k = " << k;
if (k != ke) {
EXPECT_NEAR(g0_RT[k] * RT , mu0[k], atol) << "k = " << k;
} else {
EXPECT_NEAR(g0_RT[k] * RTe , mu0[k], atol) << "k = " << k;
}
}
}
@ -437,9 +469,15 @@ TEST_P(TestConsistency, chem_potentials_to_activities) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
for (size_t k = 0; k < nsp; k++) {
double a_from_mu = exp((mu[k] - mu0[k]) / RT);
double scale = std::max(std::abs(a[k]), std::abs(a_from_mu));
EXPECT_NEAR(a_from_mu, a[k], 1e-9 * scale + 1e-14) << "k = " << k;
if (k != ke) {
double a_from_mu = exp((mu[k] - mu0[k]) / RT);
double scale = std::max(std::abs(a[k]), std::abs(a_from_mu));
EXPECT_NEAR(a_from_mu, a[k], 1e-9 * scale + 1e-14) << "k = " << k;
} else {
double a_from_mu = exp((mu[k] - mu0[k]) / RTe);
double scale = std::max(std::abs(a[k]), std::abs(a_from_mu));
EXPECT_NEAR(a_from_mu, a[k], 1e-9 * scale + 1e-14) << "k = " << k;
}
}
}
@ -505,7 +543,11 @@ TEST_P(TestConsistency, hRef_eq_uRef_plus_P_vRef)
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
for (size_t k = 0; k < nsp; k++) {
EXPECT_NEAR(hRef[k] * RT, uRef[k] * RT + OneAtm * vRef[k], atol) << "k = " << k;
if (k != ke) {
EXPECT_NEAR(hRef[k] * RT, uRef[k] * RT + OneAtm * vRef[k], atol) << "k = " << k;
} else {
EXPECT_NEAR(hRef[k] * RTe, uRef[k] * RTe + OneAtm * vRef[k], atol) << "k = " << k;
}
}
}
@ -521,9 +563,15 @@ TEST_P(TestConsistency, gRef_eq_hRef_minus_T_sRef)
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}
for (size_t k = 0; k < nsp; k++) {
EXPECT_NEAR(gRef[k], gRef_RT[k] * RT, atol) << "k = " << k;
EXPECT_NEAR(gRef[k], hRef[k] * RT - T * sRef[k] * GasConstant,
atol) << "k = " << k;
if (k != ke) {
EXPECT_NEAR(gRef[k], gRef_RT[k] * RT, atol) << "k = " << k;
EXPECT_NEAR(gRef[k], hRef[k] * RT - T * sRef[k] * GasConstant,
atol) << "k = " << k;
} else {
EXPECT_NEAR(gRef[k], gRef_RT[k] * RTe, atol) << "k = " << k;
EXPECT_NEAR(gRef[k], hRef[k] * RTe - Te * sRef[k] * GasConstant,
atol) << "k = " << k;
}
}
}