15 Eigen::ArrayXd
n,
t,
d;
17 template<
typename TauType,
typename DeltaType>
18 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
19 using result = std::common_type_t<TauType, DeltaType>;
21 TauType lntau = log(tau);
23 if (base_delta == 0) {
24 for (
auto i = 0; i <
n.size(); ++i) {
25 r = r +
n[i] * exp(
t[i] * lntau)*
powi(delta,
static_cast<int>(
d[i]));
29 DeltaType lndelta = log(delta);
30 for (
auto i = 0; i <
n.size(); ++i) {
31 r +=
n[i] * exp(
t[i] * lntau +
d[i] * lndelta);
51 template<
typename TauType,
typename DeltaType>
52 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
53 using result = std::common_type_t<TauType, DeltaType>;
55 TauType lntau = log(tau);
57 throw std::invalid_argument(
"l_i cannot be zero length if some terms are provided");
60 for (
auto i = 0; i <
coeffs.
n.size(); ++i) {
65 DeltaType lndelta = log(delta);
68 for (
auto i = 0; i <
coeffs.
n.size(); ++i) {
70 arg = (
coeffs.
t[i] * lntau) + dpart;
86 template<
typename TauType,
typename DeltaType>
87 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
88 using result = std::common_type_t<TauType, DeltaType>;
89 result r = 0.0, lntau = log(tau);
91 for (
auto i = 0; i <
n.size(); ++i) {
92 r = r +
n[i] * exp(
t[i] * lntau -
g[i] *
powi(delta,
l_i[i]))*
powi(delta,
static_cast<int>(
d[i]));
96 result lndelta = log(delta);
97 for (
auto i = 0; i <
n.size(); ++i) {
98 r +=
n[i] * exp(
t[i] * lntau +
d[i] * lndelta -
g[i] *
powi(delta,
l_i[i]));
113 template<
typename TauType,
typename DeltaType>
114 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
115 using result = std::common_type_t<TauType, DeltaType>;
116 result r = 0.0, lntau = log(tau);
117 if (
ld_i.size() == 0 &&
n.size() > 0) {
118 throw std::invalid_argument(
"ld_i cannot be zero length if some terms are provided");
121 for (
auto i = 0; i <
n.size(); ++i) {
122 r = r +
n[i] *
powi(delta,
static_cast<int>(
d[i])) * exp(
t[i] * lntau -
gd[i]*
powi(delta,
ld_i[i]) -
gt[i]*
pow(tau,
lt[i]));
126 result lndelta = log(delta);
127 for (
auto i = 0; i <
n.size(); ++i) {
128 r = r +
n[i] * exp(
t[i] * lntau +
d[i] * lndelta -
gd[i]*
powi(delta,
ld_i[i]) -
gt[i]*
pow(tau,
lt[i]));
142 template<
typename TauType,
typename DeltaType>
143 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
144 using result = std::common_type_t<TauType, DeltaType>;
145 result r = 0.0, lntau = log(tau);
146 auto square = [](
auto x) {
return x * x; };
148 for (
auto i = 0; i <
n.size(); ++i) {
149 r = r +
n[i] * exp(
t[i] * lntau -
eta[i] * square(delta -
epsilon[i]) -
beta[i] * square(tau -
gamma[i]))*
powi(delta,
static_cast<int>(
d[i]));
153 DeltaType lndelta = log(delta);
157 for (
auto i = 0; i <
n.size(); ++i) {
158 d1 = delta -
epsilon[i]; d2 = d1*d1;
159 t1 = tau -
gamma[i]; t2 = t1*t1;
160 arg =
t[i] * lntau +
d[i] * lndelta -
eta[i]*d2 -
beta[i]*t2;
161 r = r +
n[i] * exp(arg);
175 template<
typename TauType,
typename DeltaType>
176 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
177 using result = std::common_type_t<TauType, DeltaType>;
178 result r = 0.0, lntau = log(tau);
179 auto square = [](
auto x) {
return x * x; };
181 for (
auto i = 0; i <
n.size(); ++i) {
182 r = r +
n[i] * exp(
t[i] * lntau -
eta[i] * square(delta -
epsilon[i]) -
beta[i] * (delta -
gamma[i]))*
powi(delta,
static_cast<int>(
d[i]));
186 result lndelta = log(delta);
187 for (
auto i = 0; i <
n.size(); ++i) {
188 r = r +
n[i] * exp(
t[i] * lntau +
d[i] * lndelta -
eta[i] * square(delta -
epsilon[i]) -
beta[i] * (delta -
gamma[i]));
204 template<
typename TauType,
typename DeltaType>
205 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
206 using result = std::common_type_t<TauType, DeltaType>;
207 result r = 0.0, lntau = log(tau);
209 for (
auto i = 0; i <
n.size(); ++i) {
210 r = r +
n[i] * exp(
t[i] * lntau -
powi(delta,
l_i[i]) -
pow(tau,
m[i]))*
powi(delta,
static_cast<int>(
d[i]));
214 result lndelta = log(delta);
215 for (
auto i = 0; i <
n.size(); ++i) {
216 r = r +
n[i] * exp(
t[i] * lntau +
d[i] * lndelta -
powi(delta,
l_i[i]) -
pow(tau,
m[i]));
230 template<
typename TauType,
typename DeltaType>
231 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
233 using result = std::common_type_t<TauType, DeltaType>;
234 result r = 0.0, lntau = log(tau);
235 auto square = [](
auto x) {
return x * x; };
237 for (
auto i = 0; i <
n.size(); ++i) {
238 r = r +
n[i] * exp(
t[i] * lntau -
eta[i] * square(delta -
epsilon[i]) + 1.0 / (
beta[i] * square(tau -
gamma[i]) +
b[i]))*
powi(delta,
static_cast<int>(
d[i]));
242 result lndelta = log(delta);
243 for (
auto i = 0; i <
n.size(); ++i) {
244 r = r +
n[i] * exp(
t[i] * lntau +
d[i] * lndelta -
eta[i] * square(delta -
epsilon[i]) + 1.0 / (
beta[i] * square(tau -
gamma[i]) +
b[i]));
260 template<
typename vectype,
typename XType>
262 int N =
static_cast<int>(c.size()) - 1;
263 std::common_type_t<typename vectype::Scalar, XType> u_k = 0, u_kp1 = 0, u_kp2 = 0;
264 for (
int k = N; k >= 0; --k){
266 u_k = 2.0*ind*u_kp1 - u_kp2 + c[k];
269 u_kp2 = u_kp1; u_kp1 = u_k;
272 return (u_k - u_kp2)/2.0;
276 template<
typename MatType,
typename XType>
278 int N =
static_cast<int>(c.rows()) - 1;
279 constexpr int Cols = MatType::ColsAtCompileTime;
280 using NumType = std::common_type_t<typename MatType::Scalar, XType>;
281 static Eigen::Array<NumType, 1, Cols> u_k, u_kp1, u_kp2;
283 if constexpr (Cols == Eigen::Dynamic) {
284 int M =
static_cast<int>(c.rows());
289 u_k.setZero(); u_kp1.setZero(); u_kp2.setZero();
291 for (
int k = N; k >= 0; --k) {
293 u_k = 2.0 * ind * u_kp1 - u_kp2 + c.row(k).template cast<XType>();
296 u_kp2 = u_kp1; u_kp1 = u_k;
299 return (u_k - u_kp2) / 2.0;
307 template<
typename MatType,
typename XType,
typename YType>
313 template<
typename TauType,
typename DeltaType>
314 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
326 template<
typename TauType,
typename DeltaType>
327 auto alphar(
const TauType& ,
const DeltaType& )
const {
328 return static_cast<std::common_type_t<TauType, DeltaType>
>(0.0);
336 template<
typename TauType,
typename DeltaType>
337 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
339 auto square = [](
auto x) {
return x * x; };
340 auto delta_min1_sq = square(delta - 1.0);
342 using result = std::common_type_t<TauType, DeltaType>;
344 for (
auto i = 0; i <
n.size(); ++i) {
345 auto Psi = exp(-
C[i]*delta_min1_sq -
D[i]*square(tau - 1.0));
346 auto k = 1.0 / (2.0 *
beta[i]);
347 auto theta = (1.0 - tau) +
A[i] *
pow(delta_min1_sq, k);
348 auto Delta = square(theta) +
B[i]*
pow(delta_min1_sq,
a[i]);
349 r = r +
n[i]*
pow(Delta,
b[i])*delta*Psi;
354 double dbl =
static_cast<double>(
getbaseval(outval));
355 if (std::isfinite(dbl)) {
359 return static_cast<decltype(outval)
>(0.0);
375 R_gas(spec.at(
"R / J/mol/K")),
376 Delta1(spec.at(
"Delta1")),
377 Delta2(spec.at(
"Delta2")),
378 Tred_K(spec.at(
"Tred / K")),
389 template<
typename TauType,
typename DeltaType>
390 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
395 auto Psiminus = -log(1.0 -
b_cubic * rhomolar);
397 auto val = Psiminus - a_cubic / (
R_gas * T) * Psiplus;
411 Tred_K(spec.at(
"Tred / K")),
416 template<
typename TauType,
typename DeltaType>
417 auto alphar(
const TauType& tau,
const DeltaType& delta)
const {
424template<
typename... Args>
427 using varEOSTerms = std::variant<Args...>;
428 std::vector<varEOSTerms> coll;
431 auto size()
const {
return coll.size(); }
433 template<
typename Instance>
435 coll.emplace_back(instance);
438 template <
class Tau,
class Delta>
439 auto alphar(
const Tau& tau,
const Delta& delta)
const {
440 std::common_type_t <Tau, Delta> ar = 0.0;
441 for (
const auto& term : coll) {
452 auto contrib = std::visit([&](
auto& t) {
return t.alphar(tau, delta); }, term);
static auto Clenshaw1DByRow(const MatType &c, const XType &ind)
Clenshaw evaluation of one dimensional flattening of the Chebyshev expansion.
static auto Clenshaw1D(const vectype &c, const XType &ind)
Clenshaw evaluation of a Chebyshev expansion in 1D.
auto alphar(const TauType &tau, const DeltaType &delta) const
static auto Clenshaw2DEigen(const MatType &a, const XType &x, const YType &y)
auto alphar(const TauType &tau, const DeltaType &delta) const
auto alphar(const Tau &tau, const Delta &delta) const
auto add_term(Instance &&instance)
auto alphar(const TauType &tau, const DeltaType &delta) const
auto alphar(const TauType &tau, const DeltaType &delta) const
auto alphar(const TauType &tau, const DeltaType &delta) const
auto alphar(const TauType &tau, const DeltaType &delta) const
const double rhored_molm3
GenericCubicTerm(const nlohmann::json &spec)
auto alphar(const TauType &tau, const DeltaType &delta) const
const std::vector< AlphaFunctionOptions > alphas_cubic
auto alphar(const TauType &tau, const DeltaType &delta) const
auto alphar(const TauType &tau, const DeltaType &delta) const
auto alphar(const TauType &tau, const DeltaType &delta) const
auto alphar(const TauType &, const DeltaType &) const
const saft::PCSAFT::PCSAFTPureGrossSadowski2001 pcsaft
PCSAFTGrossSadowski2001Term(const nlohmann::json &spec)
const double rhored_molm3
auto alphar(const TauType &tau, const DeltaType &delta) const
const PowerEOSTermCoeffs coeffs
PowerEOSTerm(const PowerEOSTermCoeffs &coef)
auto alphar(const TauType &tau, const DeltaType &delta) const
auto alphar(const TTYPE &T, const RhoType &rhomolar, const VecType &) const
auto getbaseval(const T &expr)
T powi(const T &x, int n)
From Ulrich Deiters.
auto pow(const double &x, const double &e)
auto build_alpha_functions(const TC &Tc_K, const nlohmann::json &jalphas)