25#ifndef INTERACTION_POTENTIAL_H
26#define INTERACTION_POTENTIAL_H
41 std::vector<double> M_L, std::vector<double> Tc_L, std::vector<double> pc_L, std::vector<double> omega_, std::vector<double> devi,
42 std::vector<double> alpha_, std::vector<double> gI_L, std::vector<double> gII_L);
43 double G_Excess(std::vector<double> x_i, std::vector<double> g_jk, std::vector<double> beta_jk);
44 double b_mix(std::vector<double> x_i);
45 double a_mix(std::vector<double> x_i, std::vector<double> a_i,
double b,
double G_E);
46 double p_PR(
double v,
double a_m,
double b_m);
47 double gamma_i(std::vector<double> x_i,
double a_i, std::vector<double> g_jk, std::vector<double> beta_jk,
double _T,
int i);
48 double lnfugacity_i(std::vector<double> x_i,
double v,
double a_m,
double b_m,
double gamma_i,
double _T,
int i);
49 std::vector<double>
iterate_VLE(
double residuum,
double beta0);
50 std::vector<double>
getChis(
int n);
53 std::vector<double> z;
56 const double lambda{0.6232252401};
58 std::vector<double> a_c;
59 std::vector<double> b;
60 std::vector<double> M;
61 std::vector<double> T_c;
62 std::vector<double> p_c;
63 std::vector<double> omega;
64 std::vector<double> m;
65 std::vector<double> alpha;
66 std::vector<double> g_I;
67 std::vector<double> g_II;
68 std::vector<double> init_v = {0.105,120.0};
69 std::vector<double> volatilities = {1.,0.,0.,0.};
70 std::vector<double> chis = {0.5,0.5,0.5,0.5};
73namespace interaction {
79 template <
typename V,
typename PARAMETERS>
88 template <
typename V,
typename PARAMETERS>
96 template <
typename T,
typename DESCRIPTOR,
typename FIELD>
102 template <
typename T,
typename DESCRIPTOR,
typename FIELD>
108 template <
typename T,
typename DESCRIPTOR,
typename FIELD>
114 template <
typename T,
typename DESCRIPTOR,
typename FIELD>
122 template <
typename V,
typename PARAMETERS>
124 V c = params.template get<B>() * rho / V{4};
126 * (V(0.18727 / 0.4963) * params.template get<A>() / params.template get<B>())
127 * params.template get<T>()
128 * ((V{1} +c+c*c-c*c*c) / (V{1}-c) / (V{1}-c) / (V{1}-c))
129 - params.template get<A>() * rho*rho;
130 return util::sqrt(V{6}*(p-rho/V{3})/ params.template get<G>());
149 template <
typename V,
typename COUPLING>
153 coupling.template setParameter<interaction::Polinomial::G>(g);
155 auto rhov = coupling.template getParameter<interaction::Polinomial::RHOV>()[0];
156 auto rhol = coupling.template getParameter<interaction::Polinomial::RHOL>()[0];
157 const V rhoc = 0.5 * ( rhov + rhol );
158 coupling.template setParameter<interaction::Polinomial::RHOC>(rhoc);
160 const V rho1 = rhov + V(0.33) * ( rhol - rhov );
161 const V rho2 = rhov + V(0.67) * ( rhol - rhov );
163 const V A = 1. / ( rhol - rhov );
164 const V B = 1. / 2. / sqrt(rhol) / ( sqrt(rhol) - sqrt(rhov) );
165 const V C = 1. / 2. / sqrt(rhol) / ( sqrt(rhov) + sqrt(rhol) );
167 const V f1 = A * log( sqrt(rho1) - sqrt(rhov) )
168 - B * log( sqrt(rhol) - sqrt(rho1) )
169 - C * log( sqrt(rho1) + sqrt(rhol) );
171 const V f2 = A * log( sqrt(rho2) - sqrt(rhov) )
172 - B * log( sqrt(rhol) - sqrt(rho2) )
173 - C * log( sqrt(rho2) + sqrt(rhol) );
175 auto thickness = coupling.template getParameter<interaction::Polinomial::THICKNESS>()[0];
176 const V pc = rhoc * rhoc * rhoc / V(6.) * pow( ( f2 - f1 ) / thickness, 2 );
177 coupling.template setParameter<interaction::Polinomial::PC>(pc);
179 const V a = V(1./4.);
180 const V b = rhol / V(2.);
181 const V c = sqrt(rhov) / V(3.);
182 const V d = sqrt(rhov) * rhol;
184 const V g1 = a * rhov * rhov - b * rhov - c * pow( rhov, V(1.5) ) + d * sqrt( rhov );
186 const V g2 = a * rhol * rhol - b * rhol - c * pow( rhol, V(1.5) ) + d * sqrt( rhol );
188 auto gamma = coupling.template getParameter<interaction::Polinomial::SURFTENSION>()[0];
189 const V kappaP = V(9.) * sqrt( rhoc * rhoc * rhoc ) *gamma
190 / g / sqrt( V(6.) * pc ) / ( g2 - g1 ) ;
191 coupling.template setParameter<interaction::Polinomial::KAPPAP>(kappaP);
194 template <
typename V,
typename PARAMETERS>
197 auto g = params.template get<G>();
198 V psi =
util::sqrt( V(2.)*( p - Rho/V(3.) )/g );
202 template <
typename V,
typename PARAMETERS>
204 auto rho_c = params.template get<RHOC>();
205 auto p_c = params.template get<PC>();
206 auto rho_v = params.template get<RHOV>();
207 auto rho_l = params.template get<RHOL>();
208 const V sqrt_rho_v = sqrt(rho_v);
209 const V sqrt_Rho = sqrt(Rho);
210 V p = p_c / rho_c / rho_c / rho_c * (
211 V(2.) * Rho * Rho * Rho + ( rho_v - V(2.) * rho_l ) * Rho * Rho
212 - V(3.) * sqrt_rho_v * Rho* Rho * sqrt_Rho + V(2.) * sqrt_rho_v * rho_l * Rho * sqrt_Rho
213 + sqrt_rho_v * rho_l * rho_l * sqrt_Rho );
218template <
unsigned N_COMPONENTS>
220 template <
typename X_I,
typename G_JK,
typename BETA_JK,
typename V=
typename X_I::value_t>
223 for(
unsigned i = 0; i < N_COMPONENTS; i++){
226 for(
unsigned j = 0; j < N_COMPONENTS; j++){
227 sum1 = sum1 + x_i[j]*g_jk[i+N_COMPONENTS*j]*beta_jk[i+N_COMPONENTS*j];
228 sum2 = sum2 + x_i[j]*beta_jk[i+N_COMPONENTS*j];
230 G_E = G_E + x_i[i] * sum1/sum2;
235 template <
typename X_I,
typename B,
typename V=
typename X_I::value_t>
238 for(
unsigned i = 0; i < N_COMPONENTS; i++){
244 template <
typename X_I,
typename A_I,
typename B,
typename V=
typename X_I::value_t>
247 for(
unsigned i = 0; i < N_COMPONENTS; i++){
248 a_sum = a_sum + x_i[i]*a_i[i]/b[i];
257 return b_m * (a_sum - G_E / 0.6232252401);
260 template <
typename RHO_FIELD,
typename __T,
typename K,
typename A_C,
typename B,
typename T_C,
typename M,
typename ALPHA,
typename G_I,
typename G_II,
typename BIG_M,
typename V=
typename RHO_FIELD::value_t>
261 V
compute(
const RHO_FIELD& rhoField,
const __T& _T,
const K& k,
const A_C& a_c,
const B& b,
const T_C& T_c,
const M& m,
const ALPHA& alpha,
const G_I& g_I,
const G_II& g_II,
const BIG_M& _M)
any_platform {
267 for(
unsigned i = 0; i < N_COMPONENTS; i++){
269 for(
unsigned j = 0; j < N_COMPONENTS; j++){
270 g_jk[N_COMPONENTS*i+j] = g_I[N_COMPONENTS*i+j] + g_II[N_COMPONENTS*i+j] * _T;
271 beta_jk[N_COMPONENTS*i+j] = b[j] *
util::exp(-alpha[N_COMPONENTS*i+j]*g_jk[N_COMPONENTS*i+j]/(R*_T));
273 molarRhoField[i] = rhoField[i]/_M[i];
274 molarRho += molarRhoField[i];
277 for(
unsigned i = 0; i < N_COMPONENTS; i++){
278 x_i[i] = molarRhoField[i]/molarRho;
280 V g_E =
G_Excess(x_i, g_jk, beta_jk);
281 V b_m =
b_mix(x_i, b);
282 V a_m =
a_mix(x_i, a_i, b, b_m, g_E);
283 V p = molarRho*R*_T/(1-b_m*molarRho) - a_m*molarRho*molarRho/(1+2*b_m*molarRho-b_m*molarRho*b_m*molarRho);
288 template <
typename RHO_FIELD,
typename A_C,
typename B,
typename T_C,
typename M,
typename ALPHA,
typename G_I,
typename G_II,
typename BIG_M,
typename V=
typename RHO_FIELD::value_t>
289 V
computeP(
const RHO_FIELD& rhoField, V _T,
const A_C& a_c,
const B& b,
const T_C& T_c,
const M& m,
const ALPHA& alpha,
const G_I& g_I,
const G_II& g_II,
const BIG_M& _M)
any_platform {
294 for(
unsigned i = 0; i < N_COMPONENTS; i++){
296 for(
unsigned j = 0; j < N_COMPONENTS; j++){
297 g_jk[N_COMPONENTS*i+j] = g_I[N_COMPONENTS*i+j] + g_II[N_COMPONENTS*i+j] * _T;
298 beta_jk[N_COMPONENTS*i+j] = b[j] *
util::exp(-alpha[N_COMPONENTS*i+j]*g_jk[N_COMPONENTS*i+j]/(R*_T));
300 molarRhoField[i] = rhoField[i]/_M[i];
301 molarRho += molarRhoField[i];
303 for(
unsigned i = 0; i < N_COMPONENTS; i++){
304 x_i[i] = molarRhoField[i]/molarRho;
306 V g_E =
G_Excess(x_i, g_jk, beta_jk);
307 V b_m =
b_mix(x_i, b);
308 V a_m =
a_mix(x_i, a_i, b, b_m, g_E);
309 V p = molarRho*R*_T/(1-b_m*molarRho) - a_m*molarRho*molarRho/(1+2*b_m*molarRho-b_m*molarRho*b_m*molarRho);
317#ifndef USING_LEGACY_CODEGEN
321template <
typename T,
typename S>
332template <
typename T,
typename S>
337 bool operator() (T psi[],
const S rho[])
override;
342template <
typename T,
typename S>
349 bool operator() (T psi[],
const S rho[])
override;
352template <
typename T,
typename S>
364 PengRobinson(T G, T acentricFactor=0.334, T a=2./49., T b=2./21., T tr=.8);
367 bool operator() (T psi[],
const S rho[],
const S t[]);
370template <
typename T,
typename S>
380 bool operator() (T psi[],
const S rho[])
override;
382 bool operator() (T psi[],
const S rho[],
const S t[]);
391template <
typename T,
typename S>
397 Krause(T rhoZero=1., T psiZero=1.9);
401template <
typename T,
typename S>
411template <
typename T,
typename S>
417 Normal(T sigma=1., T mu=1.);
AnalyticalF are applications from DD to XD, where X is set by the constructor.
bool operator()(T psi[], const S rho[]) override
has to be implemented for 'every' derived class
CarnahanStarling(T G, T a=1., T b=4., T tr=.7)
bool operator()(T psi[], const S rho[])
has to be implemented for 'every' derived class
Krause(T rhoZero=1., T psiZero=1.9)
std::vector< double > iterate_VLE(double residuum, double beta0)
double a_mix(std::vector< double > x_i, std::vector< double > a_i, double b, double G_E)
double b_mix(std::vector< double > x_i)
double p_PR(double v, double a_m, double b_m)
double G_Excess(std::vector< double > x_i, std::vector< double > g_jk, std::vector< double > beta_jk)
MultiComponentPengRobinson(double p_, double T_, std::vector< double > z_, std::vector< double > a_L, std::vector< double > b_L, std::vector< double > M_L, std::vector< double > Tc_L, std::vector< double > pc_L, std::vector< double > omega_, std::vector< double > devi, std::vector< double > alpha_, std::vector< double > gI_L, std::vector< double > gII_L)
std::vector< double > getChis(int n)
double lnfugacity_i(std::vector< double > x_i, double v, double a_m, double b_m, double gamma_i, double _T, int i)
double gamma_i(std::vector< double > x_i, double a_i, std::vector< double > g_jk, std::vector< double > beta_jk, double _T, int i)
bool operator()(T psi[], const S rho[])
has to be implemented for 'every' derived class
Normal(T sigma=1., T mu=1.)
bool operator()(T psi[], const S rho[])
has to be implemented for 'every' derived class
PengRobinson(T G, T acentricFactor=0.334, T a=2./49., T b=2./21., T tr=.8)
bool operator()(T psi[], const S rho[]) override
has to be implemented for 'every' derived class
bool operator()(T psi[], const S rho[])
has to be implemented for 'every' derived class
ShanChen94(T rhoZero=200., T psiZero=4.)
bool operator()(T psi[], const S rho[]) override
has to be implemented for 'every' derived class
bool operator()(T psi[], const S rho[])
has to be implemented for 'every' derived class
WeisbrodKrause(T rhoZero=1., T sigmu=1.)
Expr pow(Expr base, Expr exp)
Top level namespace for all of OpenLB.
Base of a field whose size is defined by [C_0,C_1,C_2]^T * [1,D,Q].
static constexpr auto isValid(FieldD< T, DESCRIPTOR, FIELD > value)
static constexpr auto isValid(FieldD< T, DESCRIPTOR, FIELD > value)
static constexpr auto isValid(FieldD< T, DESCRIPTOR, FIELD > value)
static constexpr auto isValid(FieldD< T, DESCRIPTOR, FIELD > value)
V compute(V rho, PARAMETERS ¶ms) any_platform
V b_mix(const X_I &x_i, const B &b) any_platform
V compute(const RHO_FIELD &rhoField, const __T &_T, const K &k, const A_C &a_c, const B &b, const T_C &T_c, const M &m, const ALPHA &alpha, const G_I &g_I, const G_II &g_II, const BIG_M &_M) any_platform
V a_mix(const X_I &x_i, const A_I &a_i, const B &b, V b_m, V G_E) any_platform
V computeP(const RHO_FIELD &rhoField, V _T, const A_C &a_c, const B &b, const T_C &T_c, const M &m, const ALPHA &alpha, const G_I &g_I, const G_II &g_II, const BIG_M &_M) any_platform
V G_Excess(const X_I &x_i, const G_JK &g_jk, const BETA_JK &beta_jk) any_platform
V computeP(V Rho, PARAMETERS ¶ms) any_platform
V compute(V Rho, PARAMETERS ¶ms) any_platform
static void computeParameters(COUPLING &coupling)
V compute(V rho, PARAMETERS ¶ms) any_platform
V compute(V rho, PARAMETERS ¶ms) any_platform