teqp 0.22.0
Loading...
Searching...
No Matches
mie.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "teqp/types.hpp"
4#include <Eigen/Dense>
5
6namespace teqp {
7namespace Mie{
8
14
15 private:
16 using EArray6 = Eigen::Array<double, 6, 1>;
17 using EArray4 = Eigen::Array<double, 4, 1>;
18
19 const EArray6 c1_pol = (EArray6() << -0.0192944,1.38,-2.2653,1.6291,-1.974,0.40412 ).finished();
20 const EArray6 c1_exp = (EArray6() << 0.1845,-0.3227,1.1351,2.232,-2.344,-0.4238 ).finished();
21 const EArray4 c1_gbs = (EArray4() << -4.367,0.0371,1.3895,2.835 ).finished();
22 const EArray6 c2_pol = (EArray6() << 0.26021,-5.525,8.329,-19.492,25.8,-3.8133 ).finished();
23 const EArray6 c2_exp = (EArray6() << -5.05,2.7842,-9.523,-30.383,17.902,2.2264 ).finished();
24 const EArray4 c2_gbs = (EArray4() << 48.445,-5.506,-11.643,-24.36 ).finished();
25 const EArray6 t_pol = (EArray6() << 1,0.236,0.872,0.313,0.407,0.703 ).finished();
26 const EArray6 t_exp = (EArray6() << 1.78,2.99,2.866,1.2,3.06,1.073 ).finished();
27 const EArray4 t_gbs = (EArray4() << 1.50,1.03,4.02,1.57 ).finished();
28 const EArray6 d_pol = (EArray6() << 4,1,1,2,2,3 ).finished();
29 const EArray6 d_exp = (EArray6() << 1,1,3,2,2,5 ).finished();
30 const EArray4 d_gbs = (EArray4() << 2,3,2,2 ).finished();
31 const EArray6 p = (EArray6() << 1,2,2,1,2,1 ).finished();
32 const EArray4 eta = (EArray4() << 0.362,0.313,1.17,0.957 ).finished();
33 const EArray4 beta = (EArray4() << 0.0761,0.143,0.63,1.32 ).finished();
34 const EArray4 gam = (EArray4() << 1.55,-0.0826,1.505,1.07 ).finished();
35 const EArray4 eps = (EArray4() << -1,-1,-0.195,-0.287 ).finished();
36
37 const double m_lambda_r;
38 const EArray6 n_pol, n_exp;
39 const EArray4 n_gbs;
40 const double Tc, rhoc; // In simulation units
41 public:
42
43 Mie6Pohl2023(double lambda_r) : m_lambda_r(lambda_r),
44 n_pol(c1_pol + c2_pol / m_lambda_r),
45 n_exp(c1_exp + c2_exp / m_lambda_r),
46 n_gbs(c1_gbs + c2_gbs / m_lambda_r),
47 Tc(0.668 + 6.84 / m_lambda_r + 145 / pow(m_lambda_r, 3)), // T^*
48 rhoc(0.2516 + 0.049 * log10(m_lambda_r)) // rho^*
49 {}
50
51 auto get_lambda_r() const { return m_lambda_r; }
52
53 // We are in "simulation units", so R is 1.0, and T and rho that
54 // go into alphar are actually T^* and rho^*
55 template<typename MoleFracType>
56 double R(const MoleFracType &) const { return 1.0; }
57
58 template<typename TTYPE, typename RHOTYPE, typename MoleFracType>
59 auto alphar(const TTYPE& Tstar, const RHOTYPE& rhostar, const MoleFracType& /*molefrac*/) const {
60 auto tau = forceeval(Tc / Tstar); auto delta = forceeval(rhostar / rhoc);
61 using _t = std::decay_t<std::common_type_t<TTYPE, RHOTYPE>>;
62 _t s1 = 0; for (auto i = 0; i < n_pol.size(); ++i){ s1 += n_pol[i] * pow(tau, t_pol[i]) * powi(delta, static_cast<int>(d_pol[i])); }
63 _t s2 = 0; for (auto i = 0; i < n_exp.size(); ++i){ s2 += n_exp[i] * pow(tau, t_exp[i]) * powi(delta, static_cast<int>(d_exp[i])) * exp(-powi(delta, static_cast<int>(p[i]))); }
64 _t s3 = 0; for (auto i = 0; i < n_gbs.size(); ++i){ s3 += n_gbs[i] * pow(tau, t_gbs[i]) * powi(delta, static_cast<int>(d_gbs[i])) * exp(-eta[i] * powi(forceeval(delta - eps[i]), 2) - beta[i] * powi(forceeval(tau - gam[i]), 2)); }
65 return forceeval(s1 + s2 + s3);
66 }
67
68 };
69
70};
71
72namespace FEANN{
73
74 namespace FEANNMatrices{
75 extern const Eigen::MatrixXd kernel_0, kernel_1, kernel_2, kernel_3, kernel_helmholtz;
76 extern const Eigen::ArrayXd bias_0, bias_1, bias_2, bias_3;
77 }
78
80
81private:
82 const double m_lambda_r, m_lambda_a, m_alpha;
83
84 auto alpha_helper(double lambda_r, double lambda_a){
85 auto c_alpha = lambda_r / (lambda_r-lambda_a) * pow(lambda_r/lambda_a, lambda_a/(lambda_r-lambda_a));
86 auto alpha = c_alpha*(1.0/(lambda_a-3) - 1.0/(lambda_r-3));
87 return alpha;
88 }
89public:
90
91 ChaparroJCP2023(double lambda_r, double lambda_a) : m_lambda_r(lambda_r), m_lambda_a(lambda_a), m_alpha(alpha_helper(m_lambda_r, m_lambda_a)){}
92
93 auto get_lambda_r() const { return m_lambda_r; }
94 auto get_lambda_a() const { return m_lambda_a; }
95 auto get_alpha() const { return m_alpha; }
96
97 // We are in "simulation units", so R is 1.0, and T and rho that
98 // go into alphar are actually T^* and rho^*
99 template<typename MoleFracType>
100 double R(const MoleFracType &) const { return 1.0; }
101
102 template<typename TTYPE, typename RHOTYPE, typename MoleFracType>
103 auto alphar(const TTYPE& Tstar, const RHOTYPE& rhostar, const MoleFracType& /*molefrac*/) const {
104 using namespace FEANNMatrices;
105
106 using Type = std::decay_t<std::common_type_t<TTYPE, RHOTYPE>>;
107 Eigen::RowVectorX<Type> x = (Eigen::ArrayX<Type>(3) << m_alpha, rhostar, 1.0/Tstar).finished();
108 Eigen::RowVectorX<Type> x_rhoad0 = (Eigen::ArrayX<Type>(3) << m_alpha, 0.0, 1.0/Tstar).finished();
109
110 x = tanh(((x*kernel_0.cast<Type>()).reshaped().array() + bias_0.cast<Type>()).array());
111 x_rhoad0 = tanh(((x_rhoad0*kernel_0.cast<Type>()).reshaped().array() + bias_0.cast<Type>()).array());
112
113 x = tanh(((x*kernel_1.cast<Type>()).reshaped().array() + bias_1.cast<Type>()).array());
114 x_rhoad0 = tanh(((x_rhoad0*kernel_1.cast<Type>()).reshaped().array() + bias_1.cast<Type>()).array());
115
116 x = tanh(((x*kernel_2.cast<Type>()).reshaped().array() + bias_2.cast<Type>()).array());
117 x_rhoad0 = tanh(((x_rhoad0*kernel_2.cast<Type>()).reshaped().array() + bias_2.cast<Type>()).array());
118
119 x = tanh(((x*kernel_3.cast<Type>()).reshaped().array() + bias_3.cast<Type>()).array());
120 x_rhoad0 = tanh(((x_rhoad0*kernel_3.cast<Type>()).reshaped().array() + bias_3.cast<Type>()).array());
121
122 // The last layer doesn't have bias
123 x = x*kernel_helmholtz.cast<Type>();
124 x_rhoad0 = x_rhoad0*kernel_helmholtz.cast<Type>();
125
126 return forceeval((x - x_rhoad0).array()[0]/(Tstar));
127 }
128};
129
130}
131};
auto alphar(const TTYPE &Tstar, const RHOTYPE &rhostar, const MoleFracType &) const
Definition mie.hpp:103
ChaparroJCP2023(double lambda_r, double lambda_a)
Definition mie.hpp:91
auto get_lambda_a() const
Definition mie.hpp:94
auto get_lambda_r() const
Definition mie.hpp:93
auto get_alpha() const
Definition mie.hpp:95
double R(const MoleFracType &) const
Definition mie.hpp:100
Mie6Pohl2023(double lambda_r)
Definition mie.hpp:43
auto alphar(const TTYPE &Tstar, const RHOTYPE &rhostar, const MoleFracType &) const
Definition mie.hpp:59
double R(const MoleFracType &) const
Definition mie.hpp:56
auto get_lambda_r() const
Definition mie.hpp:51
const Eigen::ArrayXd bias_0
const Eigen::ArrayXd bias_3
Definition mie.hpp:76
const Eigen::ArrayXd bias_2
Definition mie.hpp:76
const Eigen::ArrayXd bias_1
Definition mie.hpp:76
const Eigen::MatrixXd kernel_1
Definition mie.hpp:75
const Eigen::MatrixXd kernel_3
Definition mie.hpp:75
const Eigen::MatrixXd kernel_2
Definition mie.hpp:75
const Eigen::MatrixXd kernel_helmholtz
Definition mie.hpp:75
const Eigen::MatrixXd kernel_0
T powi(const T &x, int n)
From Ulrich Deiters.
Definition types.hpp:139
auto pow(const double &x, const double &e)
Definition types.hpp:195
auto forceeval(T &&expr)
Definition types.hpp:52