Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for R125 term loading when in CoolProp format #169

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 49 additions & 6 deletions include/teqp/models/multifluid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,21 +640,64 @@ inline auto get_EOS_terms(const nlohmann::json& j)
}
};

auto build_Lemmon2005 = [&](auto term) {
auto build_Lemmon2005 = [&](auto term, auto & container) {
if (!all_same_length(term, { "n","t","d","m","l" })) {
throw std::invalid_argument("Lengths are not all identical in Lemmon2005 term");
}

Lemmon2005EOSTerm eos;
eos.n = toeig(term["n"]);
eos.t = toeig(term["t"]);
eos.d = toeig(term["d"]);
eos.m = toeig(term["m"]);
eos.l = toeig(term["l"]);
eos.l_i = eos.l.cast<int>();
if (!all_same_length(term, { "n","t","d","m","l" })) {
throw std::invalid_argument("Lengths are not all identical in Lemmon2005 term");
}
if (((eos.l_i.cast<double>() - eos.l).cwiseAbs() > 0.0).any()) {
throw std::invalid_argument("Non-integer entry in l found");
}
return eos;

auto getindices = [](const auto& mask){
std::vector<int> indices;
for (auto i = 0; i < mask.size(); ++i){
if (mask[i]){ indices.push_back(i); }
}
return indices;
};
auto pow_indices = getindices((eos.m == 0 ) && (eos.l == 0));
auto mzerolpos_indices = getindices((eos.m == 0) && (eos.l > 0));
auto mzero_indices = getindices((eos.m > 0) && (eos.l > 0));

if (pow_indices.size() + mzerolpos_indices.size() + mzero_indices.size() != static_cast<std::size_t>(eos.m.size())) {
throw std::invalid_argument("Term subdivision failed in Lemmon2005 term");
}

if (!pow_indices.empty()){
JustPowerEOSTerm poly;
poly.n = eos.n(pow_indices);
poly.t = eos.t(pow_indices);
poly.d = eos.d(pow_indices);
container.add_term(poly);
}
if (!mzerolpos_indices.empty()){
PowerEOSTerm::PowerEOSTermCoeffs e;
e.n = eos.n(mzerolpos_indices);
e.t = eos.t(mzerolpos_indices);
e.d = eos.d(mzerolpos_indices);
e.l = eos.l(mzerolpos_indices);
e.c = (1 + 0*eos.l).cast<double>();
e.l_i = eos.l_i(mzerolpos_indices);
container.add_term(PowerEOSTerm(e));
}
if (!mzero_indices.empty()){
Lemmon2005EOSTerm e;
e.n = eos.n(mzero_indices);
e.t = eos.t(mzero_indices);
e.d = eos.d(mzero_indices);
e.m = eos.m(mzero_indices);
e.l = eos.l(mzero_indices);
e.l_i = e.l.cast<int>();
container.add_term(e);
}
};

auto build_gaussian = [&](auto term) {
Expand Down Expand Up @@ -747,7 +790,7 @@ inline auto get_EOS_terms(const nlohmann::json& j)
container.add_term(build_na(term));
}
else if (type == "ResidualHelmholtzLemmon2005") {
container.add_term(build_Lemmon2005(term));
build_Lemmon2005(term, container);
}
else if (type == "ResidualHelmholtzGaoB") {
container.add_term(build_GaoB(term));
Expand Down
Loading