Skip to content

Commit

Permalink
Test for order of l terms
Browse files Browse the repository at this point in the history
Closes #78
  • Loading branch information
ianhbell committed Dec 19, 2023
1 parent fd81a55 commit f035835
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/teqp/models/multifluid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ inline auto build_departure_function(const nlohmann::json& j) {
Eigen::ArrayXd c(N), l(N); c.setZero();

int Nlzero = 0, Nlnonzero = 0;
bool contiguous_lzero;
bool contiguous_lzero = false;

if (term["l"].empty()) {
// exponential part not included
Expand Down Expand Up @@ -248,7 +248,7 @@ inline auto build_departure_function(const nlohmann::json& j) {
}
Nlnonzero = static_cast<int>(l.size()) - Nlzero;

if ((l[0] != 0) && (l[l.size() - 1] == 0)) {
if (contiguous_lzero && (l.tail(Nlnonzero) == 0).any()) {
throw std::invalid_argument("If l_i has zero and non-zero values, the zero values need to come first");
}

Expand Down
38 changes: 37 additions & 1 deletion src/tests/catch_test_mutant.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,40 @@ TEST_CASE("Mutant with Chebyshev departure function", "[mutant]") {
auto z = (Eigen::ArrayXd(2) << 0.4, 0.6).finished();
using tdx = TDXDerivatives<decltype(mutant0)>;
CHECK(tdx::get_Ar00(mutant0, T, rho, z) != tdx::get_Ar00(mutant1, T, rho, z));
}
}

TEST_CASE("Exponential terms in the wrong order","[mutant]"){
std::vector<std::string> fluids = { "Methane", "Water" };
std::string root = "../mycp";
const auto model = build_multifluid_model(fluids, root);

nlohmann::json jnormal = R"({"0": {"1": {"BIP": {"betaT": 0.850879634551532, "gammaT": 1.2416653630048216, "betaV": 0.7616480056314916, "gammaV": 0.9947751468478655, "Fij": 1.0}, "departure": {
"Name": "Methane-WaterHerrig",
"BibTeX": "Herrig (2018) / see Herrig (2018) PhD thesis",
"aliases": [],
"n": [3.3,-2.88,9.6,-11.7,2.13,-0.53],
"t": [1.1,0.8,0.8,1,4,3.4],
"d": [1,1,1,1,2,4],
"l": [0,0,1,1,1,1],
"type": "Exponential"
}}}})"_json;
CHECK_NOTHROW(build_multifluid_mutant(model, jnormal));

nlohmann::json jbackwards = R"({"0": {"1": {"BIP": {"betaT": 0.850879634551532, "gammaT": 1.2416653630048216, "betaV": 0.7616480056314916, "gammaV": 0.9947751468478655, "Fij": 1.0}, "departure": {
"Name": "Methane-WaterHerrig",
"BibTeX": "Herrig (2018) / see Herrig (2018) PhD thesis",
"aliases": [],
"n": [3.3,9.6,-11.7,2.13,-0.53,-2.88],
"t": [1.1,0.8,1,4,3.4,0.8],
"d": [1,1,1,2,4,1],
"l": [0,1,1,1,1,0],
"type": "Exponential"
}}}})"_json;
CHECK_THROWS(build_multifluid_mutant(model, jbackwards));

// double T = 300, rho = 1000;
// auto z = (Eigen::ArrayXd(1) << 1.0).finished();
// double alphar1 = mutant1.alphar(T, rho, z);
// double alphar2 = mutant2.alphar(T, rho, z);
// CHECK(alphar1 == alphar2);
}

0 comments on commit f035835

Please sign in to comment.