3#include "nlohmann/json.hpp"
17#include "RPinterop/interop.hpp"
19#if defined(TEQP_MULTICOMPLEX_ENABLED)
20#include "MultiComplex/MultiComplex.hpp"
27#include <boost/algorithm/string/join.hpp>
29#if defined(TEQP_MULTICOMPLEX_ENABLED)
32 template<
typename TN>
struct NumTraits<mcx::MultiComplex<TN>> : NumTraits<double>
38 RequireInitialization = 1,
49template<
typename EOSCollection>
53 const EOSCollection EOSs;
57 auto size()
const {
return EOSs.size(); }
59 template<
typename TauType,
typename DeltaType,
typename MoleFractions>
60 auto alphar(
const TauType& tau,
const DeltaType& delta,
const MoleFractions& molefracs)
const {
61 using resulttype = std::common_type_t<
decltype(tau),
decltype(molefracs[0]),
decltype(delta)>;
63 auto N = molefracs.size();
64 for (
auto i = 0U; i < N; ++i) {
65 alphar =
alphar + molefracs[i] * EOSs[i].alphar(tau, delta);
70 template<
typename TauType,
typename DeltaType>
71 auto alphari(
const TauType& tau,
const DeltaType& delta, std::size_t i)
const {
72 return EOSs[i].alphar(tau, delta);
80template<
typename FCollection,
typename DepartureFunctionCollection>
85 const DepartureFunctionCollection funcs;
89 const auto&
get_F()
const {
return F; }
91 template<
typename TauType,
typename DeltaType,
typename MoleFractions>
92 auto alphar(
const TauType& tau,
const DeltaType& delta,
const MoleFractions& molefracs)
const {
93 using resulttype = std::common_type_t<
decltype(tau),
decltype(molefracs[0]),
decltype(delta)>;
95 std::size_t N = molefracs.size();
96 for (
auto i = 0U; i < N; ++i) {
97 for (
auto j = i+1; j < N; ++j) {
98 alphar =
alphar + molefracs[i] * molefracs[j] * F(i, j) * funcs[i][j].alphar(tau, delta);
105 template<
typename TauType,
typename DeltaType>
106 auto get_alpharij(
const std::size_t i,
const std::size_t j,
const TauType& tau,
const DeltaType& delta)
const {
107 std::size_t N = funcs.size();
111 if (i >= N || j >= N){
118template<
typename CorrespondingTerm,
typename DepartureTerm>
122 std::string meta =
"";
130 template<
class VecType>
131 auto R(
const VecType& molefracs)
const {
132 return std::visit([&molefracs](
const auto& el){
return el.get_R(molefracs); },
Rcalc);
140 const std::variant<double, std::string>
get_BIP(
const std::size_t &i,
const std::size_t &j,
const std::string& key)
const{
141 if (key ==
"F" || key ==
"Fij"){
142 auto F =
dep.get_F();
143 if (0 <= i && i < F.rows() && 0 <= j && j < F.cols()){
152 template<
typename TType,
typename RhoType>
154 const RhoType& rhovec,
155 const std::optional<typename RhoType::value_type> rhotot = std::nullopt)
const
157 typename RhoType::value_type rhotot_ = (rhotot.has_value()) ? rhotot.value() : std::accumulate(std::begin(rhovec), std::end(rhovec), (
decltype(rhovec[0]))0.0);
158 auto molefrac = rhovec / rhotot_;
159 return alphar(T, rhotot_, molefrac);
162 template<
typename TType,
typename RhoType,
typename MoleFracType>
165 const MoleFracType& molefrac)
const
167 if (
static_cast<std::size_t
>(molefrac.size()) !=
corr.size()){
168 throw teqp::InvalidArgument(
"Wrong size of mole fractions; "+std::to_string(
corr.size()) +
" are loaded but "+std::to_string(molefrac.size()) +
" were provided");
174 auto val =
corr.alphar(tau, delta, molefrac) +
dep.alphar(tau, delta, molefrac);
178 template<
typename TType,
typename RhoType,
typename MoleFracType>
180 const RhoType &delta,
181 const MoleFracType& molefrac)
const
183 if (
static_cast<std::size_t
>(molefrac.size()) !=
corr.size()){
184 throw teqp::InvalidArgument(
"Wrong size of mole fractions; "+std::to_string(
corr.size()) +
" are loaded but "+std::to_string(molefrac.size()) +
" were provided");
186 auto val =
corr.alphar(tau, delta, molefrac) +
dep.alphar(tau, delta, molefrac);
198 std::string filepath = std::filesystem::is_regular_file(path) ? path : path +
"/dev/mixtures/mixture_departure_functions.json";
200 std::string js = j.dump(2);
203 if (el.at(
"Name") == name) {
209 for (
auto &alias : el.at(
"aliases")) {
215 throw std::invalid_argument(
"Could not match the name: " + name +
"when looking up departure function");
219 auto build_power = [&](
auto term,
auto& dep) {
220 std::size_t N = term[
"n"].size();
229 auto eigorzero = [&term, &N](
const std::string& name) -> Eigen::ArrayXd {
230 if (!term[name].empty()) {
231 return toeig(term[name]);
234 return Eigen::ArrayXd::Zero(N);
239 eos.
n = eigorzero(
"n");
240 eos.
t = eigorzero(
"t");
241 eos.
d = eigorzero(
"d");
243 Eigen::ArrayXd c(N), l(N); c.setZero();
245 int Nlzero = 0, Nlnonzero = 0;
246 bool contiguous_lzero =
false;
248 if (term[
"l"].empty()) {
252 throw std::invalid_argument(
"Lengths are not all identical in polynomial-like term");
257 throw std::invalid_argument(
"Lengths are not all identical in exponential term");
259 l =
toeig(term[
"l"]);
261 for (
auto i = 0; i < c.size(); ++i) {
268 contiguous_lzero = (l[0] == 0);
269 for (
auto i = 0; i < c.size(); ++i) {
275 Nlnonzero =
static_cast<int>(l.size()) - Nlzero;
277 if (contiguous_lzero && (l.tail(Nlnonzero) == 0).any()) {
278 throw std::invalid_argument(
"If l_i has zero and non-zero values, the zero values need to come first");
284 eos.
l_i = eos.
l.cast<
int>();
286 if (Nlzero + Nlnonzero != l.size()) {
287 throw std::invalid_argument(
"Somehow the l lengths don't add up");
291 if (((eos.
l_i.cast<
double>() - eos.
l).cwiseAbs() > 0.0).any()) {
292 throw std::invalid_argument(
"Non-integer entry in l found");
307 else if (l.sum() > 0 && contiguous_lzero){
309 poly.
n = eos.
n.head(Nlzero);
310 poly.
t = eos.
t.head(Nlzero);
311 poly.
d = eos.
d.head(Nlzero);
315 e.
n = eos.
n.tail(Nlnonzero);
316 e.
t = eos.
t.tail(Nlnonzero);
317 e.
d = eos.
d.tail(Nlnonzero);
318 e.
c = eos.
c.tail(Nlnonzero);
319 e.
l = eos.
l.tail(Nlnonzero);
320 e.
l_i = eos.
l_i.tail(Nlnonzero);
329 auto build_doubleexponential = [&](
auto& term,
auto& dep) {
331 throw std::invalid_argument(
"Lengths are not all identical in double exponential term");
334 eos.
n =
toeig(term.at(
"n"));
335 eos.
t =
toeig(term.at(
"t"));
336 eos.
d =
toeig(term.at(
"d"));
341 eos.
ld_i = eos.
ld.cast<
int>();
344 auto build_Chebyshev2D = [&](
auto& term,
auto& dep) {
346 int Ntau = term.at(
"Ntau");
347 int Ndelta = term.at(
"Ndelta");
348 Eigen::ArrayXd c =
toeig(term.at(
"a"));
349 if ((Ntau + 1)*(Ndelta + 1) != c.size()){
350 throw std::invalid_argument(
"Provided length [" + std::to_string(c.size()) +
"] is not equal to (Ntau+1)*(Ndelta+1)");
352 eos.
a = c.reshaped(Ntau+1, Ndelta+1).eval();
353 eos.
taumin = term.at(
"taumin");
354 eos.
taumax = term.at(
"taumax");
373 auto build_GERG2004 = [&](
const auto& term,
auto& dep) {
374 if (!
all_same_length(term, {
"n",
"t",
"d",
"eta",
"beta",
"gamma",
"epsilon" })) {
375 throw std::invalid_argument(
"Lengths are not all identical in GERG term");
377 int Npower = term[
"Npower"];
378 auto NGERG =
static_cast<int>(term[
"n"].size()) - Npower;
381 eos.
n =
toeig(term[
"n"]).head(Npower);
382 eos.
t =
toeig(term[
"t"]).head(Npower);
383 eos.
d =
toeig(term[
"d"]).head(Npower);
384 if (term.contains(
"l")) {
385 eos.
l =
toeig(term[
"l"]).head(Npower);
390 eos.
c = (eos.
l > 0).cast<int>().cast<
double>();
391 eos.
l_i = eos.
l.cast<
int>();
395 e.
n =
toeig(term[
"n"]).tail(NGERG);
396 e.
t =
toeig(term[
"t"]).tail(NGERG);
397 e.
d =
toeig(term[
"d"]).tail(NGERG);
398 e.
eta =
toeig(term[
"eta"]).tail(NGERG);
399 e.
beta =
toeig(term[
"beta"]).tail(NGERG);
404 auto build_GaussianExponential = [&](
const auto& term,
auto& dep) {
405 if (!
all_same_length(term, {
"n",
"t",
"d",
"eta",
"beta",
"gamma",
"epsilon" })) {
406 throw std::invalid_argument(
"Lengths are not all identical in Gaussian+Exponential term");
408 int Npower = term[
"Npower"];
409 auto NGauss =
static_cast<int>(term[
"n"].size()) - Npower;
412 eos.
n =
toeig(term[
"n"]).head(Npower);
413 eos.
t =
toeig(term[
"t"]).head(Npower);
414 eos.
d =
toeig(term[
"d"]).head(Npower);
415 if (term.contains(
"l")) {
416 eos.
l =
toeig(term[
"l"]).head(Npower);
421 eos.
c = (eos.
l > 0).cast<int>().cast<
double>();
422 eos.
l_i = eos.
l.cast<
int>();
426 e.
n =
toeig(term[
"n"]).tail(NGauss);
427 e.
t =
toeig(term[
"t"]).tail(NGauss);
428 e.
d =
toeig(term[
"d"]).tail(NGauss);
429 e.
eta =
toeig(term[
"eta"]).tail(NGauss);
430 e.
beta =
toeig(term[
"beta"]).tail(NGauss);
436 std::string type = j.at(
"type");
438 if (type ==
"Exponential") {
441 else if (type ==
"DoubleExponential") {
442 build_doubleexponential(j, dep);
444 else if (type ==
"GERG-2004" || type ==
"GERG-2008") {
445 build_GERG2004(j, dep);
447 else if (type ==
"Gaussian+Exponential") {
448 build_GaussianExponential(j, dep);
450 else if (type ==
"Chebyshev2D") {
451 build_Chebyshev2D(j, dep);
453 else if (type ==
"none") {
458 std::vector<std::string> options = {
"Exponential",
"GERG-2004",
"GERG-2008",
"Gaussian+Exponential",
"none",
"DoubleExponential",
"Chebyshev2D"};
459 throw std::invalid_argument(
"Bad departure term type: " + type +
". Options are {" + boost::algorithm::join(options,
",") +
"}");
464inline auto get_departure_function_matrix(
const nlohmann::json& depcollection,
const nlohmann::json& BIPcollection,
const std::vector<std::string>& components,
const nlohmann::json& flags) {
467 std::vector<std::vector<DepartureTerms>> funcs(components.size());
for (
auto i = 0U; i < funcs.size(); ++i) { funcs[i].resize(funcs.size()); }
472 for (
auto& el : depcollection) {
473 if (el[
"Name"] == Name) {
return el; }
475 throw std::invalid_argument(
"Bad departure function name: "+Name);
478 auto funcsmeta = nlohmann::json::object();
480 for (
auto i = 0U; i < funcs.size(); ++i) {
481 std::string istr = std::to_string(i);
482 if (funcsmeta.contains(istr)) { funcsmeta[istr] = {}; }
483 for (
auto j = i + 1; j < funcs.size(); ++j) {
484 std::string jstr = std::to_string(j);
485 auto [BIP, swap_needed] =
reducing::get_BIPdep(BIPcollection, { components[i], components[j] }, flags);
486 std::string funcname = BIP.contains(
"function") ? BIP[
"function"] :
"";
488 if (!funcname.empty()) {
497 funcsmeta[istr][jstr] = { {
"departure", jj}, {
"BIP", BIP} };
498 funcsmeta[istr][jstr][
"BIP"][
"swap_needed"] = swap_needed;
501 return std::make_tuple(funcs, funcsmeta);
506 auto alphar = j[
"EOS"][0][
"alphar"];
509 const std::vector<std::string> allowed_types = {
"ResidualHelmholtzPower",
"ResidualHelmholtzGaussian",
"ResidualHelmholtzNonAnalytic",
"ResidualHelmholtzGaoB",
"ResidualHelmholtzLemmon2005",
"ResidualHelmholtzExponential",
"ResidualHelmholtzDoubleExponential" };
511 auto isallowed = [&](
const auto& conventional_types,
const std::string& name) {
512 for (
auto& a : conventional_types) {
if (name == a) {
return true; }; }
return false;
515 for (
auto& term : alphar) {
516 std::string type = term[
"type"];
517 if (!isallowed(allowed_types, type)) {
518 std::string a = allowed_types[0];
for (
auto i = 1U; i < allowed_types.size(); ++i) { a +=
"," + allowed_types[i]; }
519 throw std::invalid_argument(
"Bad type:" + type +
"; allowed types are: {" + a +
"}");
525 auto build_power = [&](
auto term,
auto & container) {
526 std::size_t N = term[
"n"].
size();
530 auto eigorzero = [&term, &N](
const std::string& name) -> Eigen::ArrayXd {
531 if (!term[name].empty()) {
532 return toeig(term[name]);
535 return Eigen::ArrayXd::Zero(N);
540 eos.
n = eigorzero(
"n");
541 eos.
t = eigorzero(
"t");
542 eos.
d = eigorzero(
"d");
544 Eigen::ArrayXd c(N), l(N); c.setZero();
545 int Nlzero = 0, Nlnonzero = 0;
546 bool contiguous_lzero;
547 if (term[
"l"].empty()) {
552 l =
toeig(term[
"l"]);
554 for (
auto i = 0; i < c.size(); ++i) {
561 contiguous_lzero = (l[0] == 0);
562 for (
auto i = 0; i < c.size(); ++i) {
568 Nlnonzero =
static_cast<int>(l.size()) - Nlzero;
573 eos.
l_i = eos.
l.cast<
int>();
575 if (Nlzero + Nlnonzero != l.size()) {
576 throw std::invalid_argument(
"Somehow the l lengths don't add up");
579 if (((eos.
l_i.cast<
double>() - eos.
l).cwiseAbs() > 0.0).any()) {
580 throw std::invalid_argument(
"Non-integer entry in l found");
595 else if (l.sum() > 0 && contiguous_lzero) {
597 poly.
n = eos.
n.head(Nlzero);
598 poly.
t = eos.
t.head(Nlzero);
599 poly.
d = eos.
d.head(Nlzero);
603 e.
n = eos.
n.tail(Nlnonzero);
604 e.
t = eos.
t.tail(Nlnonzero);
605 e.
d = eos.
d.tail(Nlnonzero);
606 e.
c = eos.
c.tail(Nlnonzero);
607 e.
l = eos.
l.tail(Nlnonzero);
608 e.
l_i = eos.
l_i.tail(Nlnonzero);
617 auto build_Lemmon2005 = [&](
auto term) {
624 eos.
l_i = eos.
l.cast<
int>();
626 throw std::invalid_argument(
"Lengths are not all identical in Lemmon2005 term");
628 if (((eos.
l_i.cast<
double>() - eos.
l).cwiseAbs() > 0.0).any()) {
629 throw std::invalid_argument(
"Non-integer entry in l found");
634 auto build_gaussian = [&](
auto term) {
643 if (!
all_same_length(term, {
"n",
"t",
"d",
"eta",
"beta",
"gamma",
"epsilon" })) {
644 throw std::invalid_argument(
"Lengths are not all identical in Gaussian term");
649 auto build_exponential = [&](
auto term) {
656 eos.
l_i = eos.
l.cast<
int>();
658 throw std::invalid_argument(
"Lengths are not all identical in exponential term");
663 auto build_doubleexponential = [&](
auto& term) {
665 throw std::invalid_argument(
"Lengths are not all identical in double exponential term");
668 eos.
n =
toeig(term.at(
"n"));
669 eos.
t =
toeig(term.at(
"t"));
670 eos.
d =
toeig(term.at(
"d"));
675 eos.
ld_i = eos.
ld.cast<
int>();
679 auto build_GaoB = [&](
auto term) {
689 if (!
all_same_length(term, {
"n",
"t",
"d",
"eta",
"beta",
"gamma",
"epsilon",
"b" })) {
690 throw std::invalid_argument(
"Lengths are not all identical in GaoB term");
696 auto build_na = [&](
auto& term) {
707 throw std::invalid_argument(
"Lengths are not all identical in nonanalytic term");
712 for (
auto& term : alphar) {
713 std::string type = term[
"type"];
714 if (type ==
"ResidualHelmholtzPower") {
715 build_power(term, container);
717 else if (type ==
"ResidualHelmholtzGaussian") {
718 container.
add_term(build_gaussian(term));
720 else if (type ==
"ResidualHelmholtzNonAnalytic") {
723 else if (type ==
"ResidualHelmholtzLemmon2005") {
724 container.
add_term(build_Lemmon2005(term));
726 else if (type ==
"ResidualHelmholtzGaoB") {
727 container.
add_term(build_GaoB(term));
729 else if (type ==
"ResidualHelmholtzExponential") {
730 container.
add_term(build_exponential(term));
732 else if (type ==
"ResidualHelmholtzDoubleExponential") {
733 container.
add_term(build_doubleexponential(term));
736 throw std::invalid_argument(
"Bad term type: "+type);
742inline auto get_EOSs(
const std::vector<nlohmann::json>& pureJSON) {
743 std::vector<EOSTerms> EOSs;
744 for (
auto& j : pureJSON) {
746 EOSs.emplace_back(term);
753 std::vector<nlohmann::json> out;
754 for (
auto c : components) {
756 std::vector<std::filesystem::path> candidates = { c, root +
"/dev/fluids/" + c +
".json" };
757 std::filesystem::path selected_path =
"";
758 for (
auto candidate : candidates) {
759 if (std::filesystem::is_regular_file(candidate)) {
760 selected_path = candidate;
764 if (selected_path !=
"") {
768 throw std::invalid_argument(
"Could not load any of the candidates:" + c);
776 std::vector<std::string> CAS, Name, REFPROP, hash;
777 for (
auto j : pureJSON) {
778 auto INFO = j.at(
"INFO");
779 Name.push_back(INFO.at(
"NAME"));
780 CAS.push_back(INFO.at(
"CAS"));
781 REFPROP.push_back(INFO.at(
"REFPROP_NAME"));
782 if (INFO.contains(
"HASH")){
783 hash.push_back(INFO.at(
"HASH"));
786 std::map<std::string, std::vector<std::string>> result{
791 if (hash.size() == result[
"CAS"].size()){
792 result[
"hash"] = hash;
798template<
typename mapvec
string>
799inline auto select_identifier(
const nlohmann::json& BIPcollection,
const mapvecstring& identifierset,
const nlohmann::json& flags){
800 for (
const auto &ident: identifierset){
801 std::string key; std::vector<std::string> identifiers;
802 std::tie(key, identifiers) = ident;
804 for (
auto i = 0U; i < identifiers.size(); ++i){
805 for (
auto j = i+1; j < identifiers.size(); ++j){
806 const std::vector<std::string> pair = {identifiers[i], identifiers[j]};
817 for (
const auto& [k,v] : identifierset){
824 throw std::invalid_argument(
"Unable to match any of the identifier options: " + errmsg);
829 std::map<std::string, std::string> aliasmap;
830 for (
auto path : get_files_in_folder(root +
"/dev/fluids",
".json")) {
832 std::string REFPROP_name = j.at(
"INFO").at(
"REFPROP_NAME");
833 std::string name = j.at(
"INFO").at(
"NAME");
834 for (std::string k : {
"NAME",
"CAS",
"REFPROP_NAME"}) {
835 std::string val = j.at(
"INFO").at(k);
837 if (k ==
"REFPROP_NAME" && val == name) {
841 if (k ==
"REFPROP_NAME" && val ==
"N/A") {
844 if (aliasmap.count(val) > 0) {
845 throw std::invalid_argument(
"Duplicated reverse lookup identifier ["+k+
"] found in file:" + path.string());
848 aliasmap[val] = std::filesystem::absolute(path).string();
851 std::vector<std::string> aliases = j.at(
"INFO").at(
"ALIASES");
853 for (std::string alias : aliases) {
854 if (alias != REFPROP_name && alias != name) {
855 if (aliasmap.count(alias) > 0) {
856 throw std::invalid_argument(
"Duplicated alias [" + alias +
"] found in file:" + path.string());
859 aliasmap[alias] = std::filesystem::absolute(path).string();
869inline auto _build_multifluid_model(
const std::vector<nlohmann::json> &pureJSON,
const nlohmann::json& BIPcollection,
const nlohmann::json& depcollection,
const nlohmann::json& flags = {}) {
871 auto get_Rvals = [](
const std::vector<nlohmann::json> &pureJSON) -> std::vector<double>{
872 std::vector<double> o;
873 for (
auto pure : pureJSON){
874 o.push_back(pure.at(
"EOS")[0].at(
"gas_constant"));
882 auto Rvals = get_Rvals(pureJSON);
887 auto identifiers = identifierset[
select_identifier(BIPcollection, identifierset, flags)];
896 if (flags.contains(
"Rmodel") && flags.at(
"Rmodel") ==
"CODATA"){
897 Rcalc = multifluid::gasconstant::CODATA();
901 nlohmann::json meta = {
906 auto redfunc =
ReducingFunctions(std::move(MultiFluidReducingFunction(betaT, gammaT, betaV, gammaV, Tc, vc)));
908 auto model = MultiFluid(
910 CorrespondingStatesContribution(std::move(EOSs)),
911 DepartureContribution(std::move(F), std::move(funcs)),
914 model.set_meta(meta.dump(1));
919inline auto build_multifluid_JSONstr(
const std::vector<std::string>& componentJSON,
const std::string& BIPJSON,
const std::string& departureJSON,
const nlohmann::json& flags = {}) {
922 const auto BIPcollection = nlohmann::json::parse(BIPJSON);
923 const auto depcollection = nlohmann::json::parse(departureJSON);
926 std::vector<nlohmann::json> pureJSON;
927 for (
auto& c : componentJSON) {
928 pureJSON.emplace_back(nlohmann::json::parse(c));
943 std::vector<nlohmann::json> pureJSON;
944 if (!components.is_array()){
945 throw std::invalid_argument(
"Must be an array");
948 for (
const nlohmann::json& comp : components){
949 auto get_or_aliasmap = [&](){
961 if (comp.is_string()){
962 std::string contents = comp;
964 if (contents.find(
"PATH::") == 0){
967 else if (contents.find(
"FLDPATH::") == 0){
968 pureJSON.push_back(RPinterop::FLDfile(contents.substr(9)).make_json(
""));
970 else if (contents.find(
"FLD::") == 0){
971 pureJSON.push_back(RPinterop::FLDfile(contents.substr(5)).make_json(
""));
974 pureJSON.push_back(get_or_aliasmap());
978 pureJSON.push_back(get_or_aliasmap());
984inline auto build_multifluid_model(
const std::vector<std::string>& components,
const std::string& root,
const std::string& BIPcollectionpath = {},
const nlohmann::json& flags = {},
const std::string& departurepath = {}) {
987 nlohmann::json BIPcollection = nlohmann::json::array();
988 nlohmann::json depcollection = nlohmann::json::array();
989 if (components.size() > 1){
990 nlohmann::json B = BIPcollectionpath, D = departurepath;
992 depcollection =
multilevel_JSON_load(D, root +
"/dev/mixtures/mixture_departure_functions.json");
1008 nlohmann::json flags = (spec.contains(
"flags")) ? spec.at(
"flags") : nlohmann::json();
1011 if (spec.contains(
"HMX.BNC")){
1012 std::vector<nlohmann::json> componentJSON;
1013 for (
auto comp : spec.at(
"components")){
1014 componentJSON.push_back(RPinterop::FLDfile(comp).make_json(
""));
1016 auto [BIPcollection, depcollection] = RPinterop::HMXBNCfile(spec.at(
"HMX.BNC")).make_jsons();
1021 std::string root = (spec.contains(
"root")) ? spec.at(
"root") :
"";
1023 auto components = spec.at(
"components");
1025 nlohmann::json BIPcollection = nlohmann::json::array();
1026 nlohmann::json depcollection = nlohmann::json::array();
1027 if (components.size() > 1){
1028 BIPcollection =
multilevel_JSON_load(spec.at(
"BIP"), root +
"/dev/mixtures/mixture_binary_pairs.json");
1029 depcollection =
multilevel_JSON_load(spec.at(
"departure"), root +
"/dev/mixtures/mixture_departure_functions.json");
CorrespondingStatesContribution(EOSCollection &&EOSs)
auto alphari(const TauType &tau, const DeltaType &delta, std::size_t i) const
auto alphar(const TauType &tau, const DeltaType &delta, const MoleFractions &molefracs) const
auto get_EOS(std::size_t i) const
DepartureContribution(FCollection &&F, DepartureFunctionCollection &&funcs)
auto alphar(const TauType &tau, const DeltaType &delta, const MoleFractions &molefracs) const
auto get_alpharij(const std::size_t i, const std::size_t j, const TauType &tau, const DeltaType &delta) const
Call a single departure term at i,j.
const auto & get_F() const
auto add_term(Instance &&instance)
auto alphar(const TType &T, const RhoType &rho, const MoleFracType &molefrac) const
const std::variant< double, std::string > get_BIP(const std::size_t &i, const std::size_t &j, const std::string &key) const
Return a binary interaction parameter.
const CorrespondingTerm corr
auto get_meta() const
Get the metadata stored in string form.
void set_meta(const std::string &m)
Store some sort of metadata in string form (perhaps a JSON representation of the model?...
MultiFluid(ReducingFunctions &&redfunc, CorrespondingTerm &&corr, DepartureTerm &&dep, GasConstantCalculator &&Rcalc)
multifluid::gasconstant::GasConstantCalculator GasConstantCalculator
const ReducingFunctions redfunc
const GasConstantCalculator Rcalc
auto alphar(TType T, const RhoType &rhovec, const std::optional< typename RhoType::value_type > rhotot=std::nullopt) const
auto alphar_taudelta(const TType &tau, const RhoType &delta, const MoleFracType &molefrac) const
auto R(const VecType &molefracs) const
auto get_rhor(const MoleFractions &molefracs) const
auto get_Tr(const MoleFractions &molefracs) const
auto get_BIP(const std::size_t &i, const std::size_t &j, const std::string &key) const
std::variant< MoleFractionWeighted, CODATA > GasConstantCalculator
auto get_Tcvc(const std::vector< nlohmann::json > &pureJSON)
auto get_F_matrix(const nlohmann::json &collection, const std::vector< std::string > &identifiers, const nlohmann::json &flags)
Get the matrix F of Fij factors multiplying the departure functions.
auto get_BIPdep(const nlohmann::json &collection, const std::vector< std::string > &identifiers, const nlohmann::json &flags)
auto get_BIP_matrices(const nlohmann::json &collection, const std::vector< std::string > &components, const nlohmann::json &flags, const Tcvec &Tc, const vcvec &vc)
Build the matrices of betaT, gammaT, betaV, gammaV for the multi-fluid model.
auto _build_multifluid_model(const std::vector< nlohmann::json > &pureJSON, const nlohmann::json &BIPcollection, const nlohmann::json &depcollection, const nlohmann::json &flags={})
Internal method for actually constructing the model with the provided JSON data structures.
auto get_EOS_terms(const nlohmann::json &j)
auto get_EOSs(const std::vector< nlohmann::json > &pureJSON)
auto build_alias_map(const std::string &root)
Build a reverse-lookup map for finding a fluid JSON structure given a backup identifier.
auto toeig(const std::vector< double > &v) -> Eigen::ArrayXd
nlohmann::json load_a_JSON_file(const std::string &path)
Load a JSON file from a specified file.
auto collect_identifiers(const std::vector< nlohmann::json > &pureJSON)
auto build_multifluid_JSONstr(const std::vector< std::string > &componentJSON, const std::string &BIPJSON, const std::string &departureJSON, const nlohmann::json &flags={})
A builder function where the JSON-formatted strings are provided explicitly rather than file paths.
auto get_departure_json(const std::string &name, const std::string &path)
auto get_departure_function_matrix(const nlohmann::json &depcollection, const nlohmann::json &BIPcollection, const std::vector< std::string > &components, const nlohmann::json &flags)
auto build_departure_function(const nlohmann::json &j)
auto all_same_length(const nlohmann::json &j, const std::vector< std::string > &ks)
auto select_identifier(const nlohmann::json &BIPcollection, const mapvecstring &identifierset, const nlohmann::json &flags)
Iterate over the possible options for identifiers to determine which one will satisfy all the binary ...
auto multifluidfactory(const nlohmann::json &spec)
Load a model from a JSON data structure.
auto build_multifluid_model(const std::vector< std::string > &components, const std::string &root, const std::string &BIPcollectionpath={}, const nlohmann::json &flags={}, const std::string &departurepath={})
auto make_pure_components_JSON(const nlohmann::json &components, const std::string &root)
ReducingTermContainer< MultiFluidReducingFunction, MultiFluidInvariantReducingFunction > ReducingFunctions
auto collect_component_json(const std::vector< std::string > &components, const std::string &root)
auto multilevel_JSON_load(const nlohmann::json &j, const std::string &default_path)