16 nlohmann::json flags = flags_.value_or(nlohmann::json::object());
18 bool ii = flags.is_object();
19 bool verify = flags.value(
"verify",
true);
20 int Npts = flags.value(
"Npts", 1000);
21 double Theta_nearcrit = flags.value(
"Theta_nearcrit", 0.01);
24 double Tclosec = (1-Theta_nearcrit)*Tcrittrue;
26 double rhoL = rhovec[0], rhoV = rhovec[1];
27 auto molefrac = (Eigen::ArrayXd(1) << 1.0).finished();
28 double R = model.
get_R(molefrac);
29 double pcrittrue = rhocrittrue*R*Tcrittrue*(1+model.
get_Ar01(Tcrittrue, rhocrittrue, molefrac));
31 double dT = (Tcrittrue-Tmin)/(Npts-1);
34 auto getdrhodTs = [&R, &molefrac](
const auto& model,
double T,
double rhoL,
double rhoV){
37 auto get_drhodT = [&](
double T,
double rho){
38 double dpdrho = R*T*(1 + 2*model.
get_Ar01(T, rho, molefrac) + model.
get_Ar02(T, rho, molefrac));
39 double dpdT = R*rho*(1 + model.
get_Ar01(T, rho, molefrac) - model.
get_Ar11(T, rho, molefrac));
40 return -dpdT/dpdrho + dpsatdT/dpdrho;
43 return std::make_tuple(get_drhodT(T, rhoL), get_drhodT(T, rhoV));
46 std::vector<double> Thetas_, rhoLs_, rhoVs_, pLs_;
47 for (
int i = 0; i < Npts; ++i){
48 auto T = Tclosec - dT*i;
49 auto rhovec = model.
pure_VLE_T(T, rhoL, rhoV, 10);
50 rhoL = rhovec[0]; rhoV = rhovec[1];
51 auto [drhodTL, drhodTV] = getdrhodTs(model, T, rhoL, rhoV);
55 auto Theta = (Tcrittrue-T)/Tcrittrue;
56 double pL = rhoL*R*T*(1+model.
get_Ar01(T, rhoL, molefrac));
58 Thetas_.push_back(Theta);
59 rhoLs_.push_back(rhoL);
60 rhoVs_.push_back(rhoV);
63 auto N = Thetas_.size();
64 auto pLs = Eigen::Map<Eigen::ArrayXd>(&(pLs_[0]), N);
65 auto rhoLs = Eigen::Map<Eigen::ArrayXd>(&(rhoLs_[0]), N);
66 auto rhoVs = Eigen::Map<Eigen::ArrayXd>(&(rhoVs_[0]), N);
67 auto Thetass = Eigen::Map<Eigen::ArrayXd>(&(Thetas_[0]), N);
70 Eigen::ArrayXd exponents = Eigen::ArrayXd::LinSpaced(10, 0, 4.5);
71 Eigen::MatrixXd A(N,exponents.size());
72 Eigen::VectorXd bL(N), bV(N), bpL(N);
73 for (
auto i = 0; i < exponents.size(); ++i){
74 auto view = (Eigen::Map<Eigen::ArrayXd>(&(Thetass[0]), N));
75 A.col(i) =
view.pow(exponents[i]);
78 bL = (rhoLs/rhocrittrue)-1;
79 auto TTr = 1.0-Thetass;
80 bV = (rhoVs/rhocrittrue).log()*TTr;
81 bpL = (pLs/pcrittrue).log()*TTr;
83 Eigen::ArrayXd cLarray = A.colPivHouseholderQr().solve(bL).array();
84 Eigen::ArrayXd cVarray = A.colPivHouseholderQr().solve(bV).array();
85 Eigen::ArrayXd cpLarray = A.colPivHouseholderQr().solve(bpL).array();
87 auto toj = [](
const Eigen::ArrayXd& a){
88 std::vector<double> o(a.size());
89 Eigen::Map<Eigen::ArrayXd>(&(o[0]), o.size()) = a;
93 nlohmann::json jrhoL = {
97 {
"type",
"rhoLnoexp"},
98 {
"description",
"I'm a description"},
100 {
"t", toj(exponents)},
101 {
"reducing_value", rhocrittrue},
102 {
"using_tau_r",
false},
104 nlohmann::json jrhoV = {
109 {
"description",
"I'm a description"},
111 {
"t", toj(exponents)},
112 {
"reducing_value", rhocrittrue},
113 {
"using_tau_r",
true},
115 nlohmann::json jpsat = {
120 {
"description",
"I'm a description"},
121 {
"n", toj(cpLarray)},
122 {
"t", toj(exponents)},
123 {
"reducing_value", pcrittrue},
124 {
"using_tau_r",
true},
135 for (
auto i = 0U; i < Thetas_.size(); ++i){
136 double T = (1-Thetas_[i])*Tcrittrue;
138 double rhoLanc = anc.rhoL(T);
139 double rhoVanc = anc.rhoV(T);
141 if (std::abs(rhoLanc/rhoLs_[i]-1) > 1e-2){
142 std::cout << T <<
" " << rhoLs_[i] <<
" " << rhoLanc << std::endl;
144 if (std::abs(rhoVanc/rhoVs_[i]-1) > 1e-2){
145 std::cout << T <<
" " << rhoVs_[i] <<
" " << rhoVanc << std::endl;