teqp 0.22.0
Loading...
Searching...
No Matches
multifluid_ecs_mutant.hpp
Go to the documentation of this file.
1#pragma once
2#include <Eigen/Dense>
3#include "teqp/exceptions.hpp"
4
5
6namespace teqp {
7
22
23 private:
27 Eigen::MatrixXd tr_coeffs;
31 Eigen::MatrixXd dr_coeffs;
32
33 public:
37 Eigen::ArrayXd Tc;
41 Eigen::ArrayXd vc;
42 template<typename ArrayLike>
43 Reducing_ECS(const ArrayLike& Tc, const ArrayLike& vc, const nlohmann::json& jj) : Tc(Tc), vc(vc) {
44
45 if (not jj.contains("tr_coeffs")) {
46 throw teqp::InvalidArgument("tr_coeffs not in provided json");
47 }
48
49 if (not jj.contains("dr_coeffs")) {
50 throw teqp::InvalidArgument("dr_coeffs not in provided json");
51 }
52
53 auto json_tr_coeffs = jj.at("tr_coeffs");
54 auto json_dr_coeffs = jj.at("dr_coeffs");
55
56 auto rows_tr = json_tr_coeffs.size();
57 auto cols_tr = json_tr_coeffs[0].size();
58 tr_coeffs.resize(rows_tr, cols_tr);
59
60 auto rows_dr = json_dr_coeffs.size();
61 auto cols_dr = json_dr_coeffs[0].size();
62 dr_coeffs.resize(rows_dr, cols_dr);
63
64
65 for (auto i = 0; i < rows_tr; ++i) {
66 for (auto j = 0; j < cols_tr; ++j) {
67 tr_coeffs(i, j) = json_tr_coeffs[i][j];
68 }
69 }
70
71 for (auto i = 0; i < rows_dr; ++i) {
72 for (auto j = 0; j < cols_dr; ++j) {
73 dr_coeffs(i, j) = json_dr_coeffs[i][j];
74 }
75 }
76
77 }
78
82 template <typename TTYPE, typename RHOTYPE, typename MoleFractions>
83 auto get_tr(const TTYPE& temperature, const RHOTYPE& density, const MoleFractions& molefraction) const {
84
85 auto p00 = tr_coeffs(0, 0) + molefraction[0] * tr_coeffs(0, 1) + molefraction[0] * molefraction[0] * tr_coeffs(0, 2);
86 auto p10 = tr_coeffs(1, 0) + molefraction[0] * tr_coeffs(1, 1) + molefraction[0] * molefraction[0] * tr_coeffs(1, 2);
87 auto p01 = tr_coeffs(2, 0) + molefraction[0] * tr_coeffs(2, 1) + molefraction[0] * molefraction[0] * tr_coeffs(2, 2);
88 auto p20 = tr_coeffs(3, 0) + molefraction[0] * tr_coeffs(3, 1) + molefraction[0] * molefraction[0] * tr_coeffs(3, 2);
89 auto p11 = tr_coeffs(4, 0) + molefraction[0] * tr_coeffs(4, 1) + molefraction[0] * molefraction[0] * tr_coeffs(4, 2);
90 auto p02 = tr_coeffs(5, 0) + molefraction[0] * tr_coeffs(5, 1) + molefraction[0] * molefraction[0] * tr_coeffs(5, 2);
91 auto dc_scale = 1.0/(0.125* pow( pow(vc[0],1.0/3.0) + pow(vc[1],1.0/3.0),3.0));
92 auto tc_scale = sqrt(Tc[0] * Tc[1]);
93 auto tau = tc_scale / temperature;
94 auto delta = density / dc_scale;
95
96 auto tc_func = pow(molefraction[0], 2.0) * Tc[0] + pow(molefraction[1], 2.0) * Tc[1] + 2.0 * molefraction[0] * molefraction[1] * \
97 (p00 + p10 * delta + p01 * tau + p20 * delta * delta + p02 * tau * tau + p11 * delta * tau) * tc_scale;
98 return forceeval(tc_func);
99 }
100
101
105 template <typename TTYPE, typename RHOTYPE, typename MoleFractions>
106 auto get_dr(const TTYPE& temperature, const RHOTYPE& density, const MoleFractions& molefraction) const {
107
108 auto p00 = dr_coeffs(0, 0) + molefraction[0] * dr_coeffs(0, 1) + molefraction[0] * molefraction[0] * dr_coeffs(0, 2);
109 auto p10 = dr_coeffs(1, 0) + molefraction[0] * dr_coeffs(1, 1) + molefraction[0] * molefraction[0] * dr_coeffs(1, 2);
110 auto p01 = dr_coeffs(2, 0) + molefraction[0] * dr_coeffs(2, 1) + molefraction[0] * molefraction[0] * dr_coeffs(2, 2);
111 auto p20 = dr_coeffs(3, 0) + molefraction[0] * dr_coeffs(3, 1) + molefraction[0] * molefraction[0] * dr_coeffs(3, 2);
112 auto p11 = dr_coeffs(4, 0) + molefraction[0] * dr_coeffs(4, 1) + molefraction[0] * molefraction[0] * dr_coeffs(4, 2);
113 auto p02 = dr_coeffs(5, 0) + molefraction[0] * dr_coeffs(5, 1) + molefraction[0] * molefraction[0] * dr_coeffs(5, 2);
114 auto dc_scale = 1.0/(0.125* pow( pow(vc[0],1.0/3.0) + pow(vc[1],1.0/3.0),3.0));
115 auto vc_scale = 1.0/dc_scale;
116 auto tc_scale = sqrt(Tc[0] * Tc[1]);
117 auto tau = tc_scale / temperature;
118 auto delta = density / dc_scale;
119
120 auto vc_ = pow(molefraction[0], 2.0) * vc[0] + pow(molefraction[1], 2.0) * vc[1] + 2.0 * molefraction[0] * molefraction[1] * \
121 (p00 + p10 * delta + p01 * tau + p20 * delta * delta + p02 * tau * tau + p11 * delta * tau) * vc_scale;
122 auto dc_func = (1.0 / vc_);
123 return forceeval(dc_func);
124 }
125
126 };
127
128 template<typename BaseClass>
130
131 private:
132 std::string meta = "";
133
134 public:
135 const BaseClass& base;
137
138 template<class VecType>
139 auto R(const VecType& molefrac) const { return base.R(molefrac); }
140
142
144 void set_meta(const std::string& m) { meta = m; }
145
147 auto get_meta() const { return meta; }
148
149 template<typename TType, typename RhoType, typename MoleFracType>
150 auto alphar(const TType& T,
151 const RhoType& rho,
152 const MoleFracType& molefrac) const
153 {
154 if (static_cast<std::size_t>(molefrac.size()) != 2){
155 throw teqp::InvalidArgument("Wrong size of mole fractions - ECS mutant is only valid for a binary mixture");
156 }
157 auto Tred = forceeval(redfunc.get_tr(T, rho, molefrac));
158 auto rhored = forceeval(redfunc.get_dr(T, rho, molefrac));
159 auto delta = forceeval(rho / rhored);
160 auto tau = forceeval(Tred / T);
161 auto val = base.corr.alphar(tau, delta, molefrac);
162 return forceeval(val);
163 }
164 };
165
166 template<class Model>
167 auto build_multifluid_ecs_mutant(const Model& model, const nlohmann::json& jj) {
168 auto N = model.redfunc.Tc.size();
169 auto red = model.redfunc;
170 auto Tc = red.Tc, vc = red.vc;
171 auto newred = Reducing_ECS(Tc, vc, jj);
172 auto mfa = MultiFluidAdapter_Ecs(model, std::move(newred));
173 mfa.set_meta(jj.dump());
174 return mfa;
175 }
176
177}
178
MultiFluidAdapter_Ecs(const BaseClass &base, Reducing_ECS &&redfunc)
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?...
auto alphar(const TType &T, const RhoType &rho, const MoleFracType &molefrac) const
auto R(const VecType &molefrac) const
auto get_tr(const TTYPE &temperature, const RHOTYPE &density, const MoleFractions &molefraction) const
Reducing_ECS(const ArrayLike &Tc, const ArrayLike &vc, const nlohmann::json &jj)
auto get_dr(const TTYPE &temperature, const RHOTYPE &density, const MoleFractions &molefraction) const
auto build_multifluid_ecs_mutant(const Model &model, const nlohmann::json &jj)
auto pow(const double &x, const double &e)
Definition types.hpp:195
auto forceeval(T &&expr)
Definition types.hpp:52