Skip to content

Commit

Permalink
Fix reference class as SurfPhase in test
Browse files Browse the repository at this point in the history
  • Loading branch information
jongyoonbae committed Sep 13, 2022
1 parent 04ff146 commit 1a7f272
Showing 1 changed file with 98 additions and 77 deletions.
175 changes: 98 additions & 77 deletions test/thermo/CoverageDependentSurfPhase_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ class CoverageDependentSurfPhase_Test: public testing::Test
{
public:
CoverageDependentSurfPhase_Test():
// Array of ten different temperatures to test if
// temperature dependence is implemented properly
test_Ts({500.0, 625.0, 427.0, 711.0, 260.0,
903.0, 475.3, 748.3, 100.1, 372.1}),
// Array of ten different surface coverages to test if
// coverage dependence is implemented properly
test_covs({
{0.00, 0.10, 0.50, 0.10, 0.30},
{0.12, 0.07, 0.21, 0.17, 0.43},
Expand All @@ -22,11 +26,15 @@ class CoverageDependentSurfPhase_Test: public testing::Test
{0.20, 0.23, 0.57, 0.00, 0.00}
})
{
test_phase.reset(newPhase("copt_covdepsurf_example.yaml", "covdep"));
surf_phase = dynamic_cast<SurfPhase*>(test_phase.get());
// CoverageDenpendentSurfPhase method values will be
// compared against SurfPhase method values
covdepsurf_phase.reset(newPhase("copt_covdepsurf_example.yaml", "covdep"));
idealsurf_phase.reset(newPhase("copt_covdepsurf_example.yaml", "ideal"));
}
std::unique_ptr<ThermoPhase> test_phase;
SurfPhase* surf_phase;
std::unique_ptr<ThermoPhase> covdepsurf_phase;
std::unique_ptr<ThermoPhase> idealsurf_phase;
// A pointer to call setCoverage method
SurfPhase* surfphase_ptr;
UnitSystem us;

vector_fp test_Ts;
Expand All @@ -35,7 +43,8 @@ class CoverageDependentSurfPhase_Test: public testing::Test

TEST_F(CoverageDependentSurfPhase_Test, construct_from_yaml)
{
CoverageDependentSurfPhase* coveragedependentsurf_phase = dynamic_cast<CoverageDependentSurfPhase*>(test_phase.get());
CoverageDependentSurfPhase* coveragedependentsurf_phase =
dynamic_cast<CoverageDependentSurfPhase*>(covdepsurf_phase.get());
EXPECT_TRUE(coveragedependentsurf_phase != NULL);
}

Expand All @@ -45,9 +54,12 @@ TEST_F(CoverageDependentSurfPhase_Test, reference_enthalpies_RT)
vector_fp expected_result(5);

for (size_t i = 0; i < 10; i++) {
test_phase->setTemperature(test_Ts[i]);
test_phase->getEnthalpy_RT_ref(&enthalpies_RT_ref[0]);
surf_phase->getEnthalpy_RT_ref(&expected_result[0]);
// Setting temperatures and compare reference enthalpy method values
// of CoverageDependentSurfPhase against those of SurfPhase
covdepsurf_phase->setTemperature(test_Ts[i]);
covdepsurf_phase->getEnthalpy_RT_ref(&enthalpies_RT_ref[0]);
idealsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->getEnthalpy_RT_ref(&expected_result[0]);
EXPECT_NEAR(enthalpies_RT_ref[1], expected_result[1], 1.e-6);
}
}
Expand All @@ -58,9 +70,12 @@ TEST_F(CoverageDependentSurfPhase_Test, reference_entropies_R)
vector_fp expected_result(5);

for (size_t i = 0; i < 10; i++) {
test_phase->setTemperature(test_Ts[i]);
test_phase->getEntropy_R_ref(&entropies_R_ref[0]);
surf_phase->getEntropy_R_ref(&expected_result[0]);
// Setting temperatures and compare reference entropy method values
// of CoverageDependentSurfPhase against those of SurfPhase
covdepsurf_phase->setTemperature(test_Ts[i]);
covdepsurf_phase->getEntropy_R_ref(&entropies_R_ref[0]);
idealsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->getEntropy_R_ref(&expected_result[0]);
EXPECT_NEAR(entropies_R_ref[2], expected_result[2], 1.e-6);
}
}
Expand All @@ -71,9 +86,12 @@ TEST_F(CoverageDependentSurfPhase_Test, reference_cp_R)
vector_fp expected_result(5);

for (size_t i = 0; i < 10; i++) {
test_phase->setTemperature(test_Ts[i]);
test_phase->getCp_R_ref(&cps_R_ref[0]);
surf_phase->getCp_R_ref(&expected_result[0]);
// Setting temperatures and compare reference heat capacity method values
// of CoverageDependentSurfPhase against those of SurfPhase
covdepsurf_phase->setTemperature(test_Ts[i]);
covdepsurf_phase->getCp_R_ref(&cps_R_ref[0]);
idealsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->getCp_R_ref(&expected_result[0]);
EXPECT_NEAR(cps_R_ref[3], expected_result[3], 1.e-6);
}
}
Expand All @@ -84,9 +102,12 @@ TEST_F(CoverageDependentSurfPhase_Test, reference_gibbs_RT)
vector_fp expected_result(5);

for (size_t i = 0; i < 10; i++) {
test_phase->setTemperature(test_Ts[i]);
test_phase->getGibbs_RT_ref(&gibbs_RT_ref[0]);
surf_phase->getGibbs_RT_ref(&expected_result[0]);
// Setting temperatures and compare reference gibbs free energy method values
// of CoverageDependentSurfPhase against those of SurfPhase
covdepsurf_phase->setTemperature(test_Ts[i]);
covdepsurf_phase->getGibbs_RT_ref(&gibbs_RT_ref[0]);
idealsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->getGibbs_RT_ref(&expected_result[0]);
EXPECT_NEAR(gibbs_RT_ref[4], expected_result[4], 1.e-6);
}
}
Expand All @@ -109,11 +130,11 @@ TEST_F(CoverageDependentSurfPhase_Test, standard_enthalpies_RT)
vector_fp enthalpies_RT(5);
vector_fp expected_result(5);

test_phase->setTemperature(test_Ts[5]);
surf_phase->setCoverages(test_covs[0].data());
test_phase->getEnthalpy_RT(&enthalpies_RT[0]);
test_phase->getEnthalpy_RT_ref(&expected_result[0]);
double RT = test_phase->RT();
covdepsurf_phase->setTemperature(test_Ts[5]);
idealsurf_phase->setCoverages(test_covs[0].data());
covdepsurf_phase->getEnthalpy_RT(&enthalpies_RT[0]);
covdepsurf_phase->getEnthalpy_RT_ref(&expected_result[0]);
double RT = covdepsurf_phase->RT();
expected_result[1] += (h_slope * test_covs[0][1]) / RT;
expected_result[1] += (h_low * 0.4) / RT;
expected_result[1] += (h_high * (test_covs[0][2] - 0.4)) / RT;
Expand Down Expand Up @@ -142,10 +163,10 @@ TEST_F(CoverageDependentSurfPhase_Test, standard_entropies_R)
vector_fp entropies_R(5);
vector_fp expected_result(5);

test_phase->setTemperature(test_Ts[3]);
surf_phase->setCoverages(test_covs[0].data());
test_phase->getEntropy_R(&entropies_R[0]);
test_phase->getEntropy_R_ref(&expected_result[0]);
covdepsurf_phase->setTemperature(test_Ts[3]);
idealsurf_phase->setCoverages(test_covs[0].data());
covdepsurf_phase->getEntropy_R(&entropies_R[0]);
covdepsurf_phase->getEntropy_R_ref(&expected_result[0]);
expected_result[1] += (s_slope * test_covs[0][1]) / GasConstant;
expected_result[1] += (s_low * 0.4) / GasConstant;
expected_result[1] += (s_high * (test_covs[0][2] - 0.4)) / GasConstant;
Expand All @@ -165,10 +186,10 @@ TEST_F(CoverageDependentSurfPhase_Test, standard_cp_R)
vector_fp cps_R(5);
vector_fp expected_result(5);

test_phase->setTemperature(test_Ts[4]);
surf_phase->setCoverages(test_covs[0].data());
test_phase->getCp_R(&cps_R[0]);
test_phase->getCp_R_ref(&expected_result[0]);
covdepsurf_phase->setTemperature(test_Ts[4]);
idealsurf_phase->setCoverages(test_covs[0].data());
covdepsurf_phase->getCp_R(&cps_R[0]);
covdepsurf_phase->getCp_R_ref(&expected_result[0]);
expected_result[1] += (cp_a * log(test_Ts[4]) + cp_b)
* test_covs[0][2] * test_covs[0][2] / GasConstant;
EXPECT_NEAR(cps_R[1], expected_result[1], 1.e-6);
Expand All @@ -181,12 +202,12 @@ TEST_F(CoverageDependentSurfPhase_Test, standard_gibbs_RT)
vector_fp entropies_R(5);

for (size_t i = 0; i < 5; i++) {
test_phase->setTemperature(test_Ts[i]);
surf_phase->setCoverages(test_covs[i].data());
test_phase->getEnthalpy_RT(&expected_result[0]);
test_phase->getEntropy_R(&entropies_R[0]);
covdepsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->setCoverages(test_covs[i].data());
covdepsurf_phase->getEnthalpy_RT(&expected_result[0]);
covdepsurf_phase->getEntropy_R(&entropies_R[0]);
expected_result[1] -= entropies_R[1];
test_phase->getGibbs_RT(&gibbs_RT[0]);
covdepsurf_phase->getGibbs_RT(&gibbs_RT[0]);
EXPECT_NEAR(gibbs_RT[1], expected_result[1], 1.e-6);
}
}
Expand All @@ -197,11 +218,11 @@ TEST_F(CoverageDependentSurfPhase_Test, standard_gibbs)
vector_fp expected_result(5);

for (size_t i = 0; i < 5; i++) {
test_phase->setTemperature(test_Ts[i]);
surf_phase->setCoverages(test_covs[i].data());
test_phase->getPureGibbs(&gibbs[0]);
test_phase->getGibbs_RT(&expected_result[0]);
expected_result[1] *= test_phase->RT();
covdepsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->setCoverages(test_covs[i].data());
covdepsurf_phase->getPureGibbs(&gibbs[0]);
covdepsurf_phase->getGibbs_RT(&expected_result[0]);
expected_result[1] *= covdepsurf_phase->RT();
EXPECT_NEAR(gibbs[1], expected_result[1], 1.e-6);
}
}
Expand All @@ -212,10 +233,10 @@ TEST_F(CoverageDependentSurfPhase_Test, standard_chempotentials)
vector_fp expected_result(5);

for (size_t i = 0; i < 5; i++) {
test_phase->setTemperature(test_Ts[i]);
surf_phase->setCoverages(test_covs[i].data());
test_phase->getStandardChemPotentials(&chempotentials_st[0]);
test_phase->getPureGibbs(&expected_result[0]);
covdepsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->setCoverages(test_covs[i].data());
covdepsurf_phase->getStandardChemPotentials(&chempotentials_st[0]);
covdepsurf_phase->getPureGibbs(&expected_result[0]);
EXPECT_NEAR(chempotentials_st[1], expected_result[1], 1.e-6);
}
}
Expand All @@ -226,11 +247,11 @@ TEST_F(CoverageDependentSurfPhase_Test, partial_molar_enthalpies)
vector_fp expected_result(5);

for (size_t i = 0; i < 5; i++) {
test_phase->setTemperature(test_Ts[i]);
surf_phase->setCoverages(test_covs[i].data());
test_phase->getPartialMolarEnthalpies(&partialmolar_enthalpies[0]);
test_phase->getEnthalpy_RT(&expected_result[0]);
expected_result[1] *= test_phase->RT();
covdepsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->setCoverages(test_covs[i].data());
covdepsurf_phase->getPartialMolarEnthalpies(&partialmolar_enthalpies[0]);
covdepsurf_phase->getEnthalpy_RT(&expected_result[0]);
expected_result[1] *= covdepsurf_phase->RT();
EXPECT_NEAR(partialmolar_enthalpies[1], expected_result[1], 1.e-6);
}
}
Expand All @@ -241,10 +262,10 @@ TEST_F(CoverageDependentSurfPhase_Test, partial_molar_entropies)
vector_fp expected_result(5);

for (size_t i = 0; i < 5; i++) {
test_phase->setTemperature(test_Ts[i]);
surf_phase->setCoverages(test_covs[i].data());
test_phase->getPartialMolarEntropies(&partialmolar_entropies[0]);
test_phase->getEntropy_R(&expected_result[0]);
covdepsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->setCoverages(test_covs[i].data());
covdepsurf_phase->getPartialMolarEntropies(&partialmolar_entropies[0]);
covdepsurf_phase->getEntropy_R(&expected_result[0]);
expected_result[1] -= log(test_covs[i][1]);
expected_result[1] *= GasConstant;
EXPECT_NEAR(partialmolar_entropies[1], expected_result[1], 1.e-6);
Expand All @@ -257,10 +278,10 @@ TEST_F(CoverageDependentSurfPhase_Test, partial_molar_cp)
vector_fp expected_result(5);

for (size_t i = 0; i < 5; i++) {
test_phase->setTemperature(test_Ts[i]);
surf_phase->setCoverages(test_covs[i].data());
test_phase->getPartialMolarCp(&partialmolar_cps[0]);
test_phase->getCp_R(&expected_result[0]);
covdepsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->setCoverages(test_covs[i].data());
covdepsurf_phase->getPartialMolarCp(&partialmolar_cps[0]);
covdepsurf_phase->getCp_R(&expected_result[0]);
expected_result[1] *= GasConstant;
EXPECT_NEAR(partialmolar_cps[1], expected_result[1], 1.e-6);
}
Expand All @@ -272,11 +293,11 @@ TEST_F(CoverageDependentSurfPhase_Test, chemical_potentials)
vector_fp expected_result(5);

for (size_t i = 0; i < 5; i++) {
test_phase->setTemperature(test_Ts[i]);
surf_phase->setCoverages(test_covs[i].data());
test_phase->getChemPotentials(&chempotentials[0]);
test_phase->getStandardChemPotentials(&expected_result[0]);
expected_result[1] += log(test_covs[i][1]) * test_phase->RT();
covdepsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->setCoverages(test_covs[i].data());
covdepsurf_phase->getChemPotentials(&chempotentials[0]);
covdepsurf_phase->getStandardChemPotentials(&expected_result[0]);
expected_result[1] += log(test_covs[i][1]) * covdepsurf_phase->RT();
EXPECT_NEAR(chempotentials[1], expected_result[1], 1.e-6);
}
}
Expand All @@ -287,11 +308,11 @@ TEST_F(CoverageDependentSurfPhase_Test, enthalpy_mole)
double expected_result;

for (size_t i = 0; i < 5; i++) {
test_phase->setTemperature(test_Ts[i]);
surf_phase->setCoverages(test_covs[i].data());
test_phase->getPartialMolarEnthalpies(&partialmolar_enthalpies[0]);
expected_result = test_phase->mean_X(partialmolar_enthalpies);
EXPECT_NEAR(test_phase->enthalpy_mole(), expected_result, 1.e-6);
covdepsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->setCoverages(test_covs[i].data());
covdepsurf_phase->getPartialMolarEnthalpies(&partialmolar_enthalpies[0]);
expected_result = covdepsurf_phase->mean_X(partialmolar_enthalpies);
EXPECT_NEAR(covdepsurf_phase->enthalpy_mole(), expected_result, 1.e-6);
}
}

Expand All @@ -301,11 +322,11 @@ TEST_F(CoverageDependentSurfPhase_Test, entropy_mole)
double expected_result;

for (size_t i = 0; i < 5; i++) {
test_phase->setTemperature(test_Ts[i]);
surf_phase->setCoverages(test_covs[i].data());
test_phase->getPartialMolarEntropies(&partialmolar_entropies[0]);
expected_result = test_phase->mean_X(partialmolar_entropies);
EXPECT_NEAR(test_phase->entropy_mole(), expected_result, 1.e-6);
covdepsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->setCoverages(test_covs[i].data());
covdepsurf_phase->getPartialMolarEntropies(&partialmolar_entropies[0]);
expected_result = covdepsurf_phase->mean_X(partialmolar_entropies);
EXPECT_NEAR(covdepsurf_phase->entropy_mole(), expected_result, 1.e-6);
}
}

Expand All @@ -315,11 +336,11 @@ TEST_F(CoverageDependentSurfPhase_Test, cp_mole)
double expected_result;

for (size_t i = 0; i < 5; i++) {
test_phase->setTemperature(test_Ts[i]);
surf_phase->setCoverages(test_covs[i].data());
test_phase->getPartialMolarCp(&partialmolar_cps[0]);
expected_result = test_phase->mean_X(partialmolar_cps);
EXPECT_NEAR(test_phase->cp_mole(), expected_result, 1.e-6);
covdepsurf_phase->setTemperature(test_Ts[i]);
idealsurf_phase->setCoverages(test_covs[i].data());
covdepsurf_phase->getPartialMolarCp(&partialmolar_cps[0]);
expected_result = covdepsurf_phase->mean_X(partialmolar_cps);
EXPECT_NEAR(covdepsurf_phase->cp_mole(), expected_result, 1.e-6);
}
}

Expand Down

0 comments on commit 1a7f272

Please sign in to comment.