From 7a79ea961961536ce02697aa1e0210ca15437428 Mon Sep 17 00:00:00 2001 From: Ian Bell <ian.bell@nist.gov> Date: Thu, 3 Nov 2022 21:36:27 -0400 Subject: [PATCH] Update PC-SAFT Closing in with the models --- include/teqp/json_builder.hpp | 26 +++++++++++++++++++++++++- include/teqp/models/pcsaft.hpp | 22 ++++++++-------------- interface/pybind11_wrapper.cpp | 13 ------------- setup.py | 22 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 28 deletions(-) diff --git a/include/teqp/json_builder.hpp b/include/teqp/json_builder.hpp index c002210..f9c5531 100644 --- a/include/teqp/json_builder.hpp +++ b/include/teqp/json_builder.hpp @@ -59,7 +59,31 @@ namespace teqp { return CPA::CPAfactory(spec); } else if (kind == "PCSAFT") { - return PCSAFT::PCSAFTfactory(spec); + using namespace PCSAFT; + Eigen::ArrayXXd kmat(0, 0); + if (spec.contains("kmat")){ + kmat = build_square_matrix(spec["kmat"]); + } + + if (spec.contains("names")){ + return PCSAFTMixture(spec["names"], kmat); + } + else if (spec.contains("coeffs")){ + std::vector<SAFTCoeffs> coeffs; + for (auto j : spec["coeffs"]) { + SAFTCoeffs c; + c.name = j.at("name"); + c.m = j.at("m"); + c.sigma_Angstrom = j.at("sigma_Angstrom"); + c.epsilon_over_k = j.at("epsilon_over_k"); + c.BibTeXKey = j.at("BibTeXKey"); + coeffs.push_back(c); + } + return PCSAFTMixture(coeffs, kmat); + } + else{ + throw std::invalid_argument("you must provide names or coeffs, but not both"); + } } else if (kind == "multifluid") { return multifluidfactory(spec); diff --git a/include/teqp/models/pcsaft.hpp b/include/teqp/models/pcsaft.hpp index 9478056..d6d1767 100644 --- a/include/teqp/models/pcsaft.hpp +++ b/include/teqp/models/pcsaft.hpp @@ -44,6 +44,13 @@ public: throw std::invalid_argument("Bad name:" + name); } } + auto get_coeffs(const std::vector<std::string>& names){ + std::vector<SAFTCoeffs> c; + for (auto n : names){ + c.push_back(get_normal_fluid(n)); + } + return c; + } }; /// Eqn. A.11 @@ -197,21 +204,8 @@ private: public: PCSAFTMixture(const std::vector<std::string> &names, const Eigen::ArrayXXd& kmat = {}) : names(names), kmat(kmat) { - check_kmat(names.size()); - m.resize(names.size()); - mminus1.resize(names.size()); - sigma_Angstrom.resize(names.size()); - epsilon_over_k.resize(names.size()); - auto i = 0; PCSAFTLibrary library; - for (auto name : names) { - const SAFTCoeffs& coeff = library.get_normal_fluid(name); - m[i] = coeff.m; - mminus1[i] = m[i] - 1; - sigma_Angstrom[i] = coeff.sigma_Angstrom; - epsilon_over_k[i] = coeff.epsilon_over_k; - i++; - } + PCSAFTMixture(library.get_coeffs(names), kmat); }; PCSAFTMixture(const std::vector<SAFTCoeffs> &coeffs, const Eigen::ArrayXXd &kmat = {}) : kmat(kmat) { diff --git a/interface/pybind11_wrapper.cpp b/interface/pybind11_wrapper.cpp index e2805b9..afb0909 100644 --- a/interface/pybind11_wrapper.cpp +++ b/interface/pybind11_wrapper.cpp @@ -9,18 +9,9 @@ using namespace py::literals; #define stringify(A) #A -// The implementation of each prototype are in separate files to move the compilation into -// multiple compilation units so that multiple processors can be used -// at the same time to carry out the compilation -// -// This speeds up things a lot on linux, but not much in MSVC -void add_vdW(py::module &m); void add_PCSAFT(py::module& m); -void add_CPA(py::module& m); void add_multifluid(py::module& m); void add_multifluid_mutant(py::module& m); -void add_cubics(py::module& m); -void add_model_potentials(py::module& m); template<typename Model, int iT, int iD, typename Class> void add_ig_deriv_impl(Class& cls) { @@ -210,13 +201,9 @@ void init_teqp(py::module& m) { add_ig_derivatives<IdealHelmholtz>(m, alphaig); alphaig.def("get_deriv_mat2", [](const IdealHelmholtz &ig, double T, double rho, const Eigen::ArrayXd& z){return DerivativeHolderSquare<2, AlphaWrapperOption::idealgas>(ig, T, rho, z).derivs;}); - add_vdW(m); add_PCSAFT(m); - add_CPA(m); add_multifluid(m); add_multifluid_mutant(m); - add_cubics(m); - add_model_potentials(m); call_method_factory(m, "get_Ar00iso"); call_method_factory(m, "get_Ar10iso"); diff --git a/setup.py b/setup.py index f1d9a4f..12ada8f 100644 --- a/setup.py +++ b/setup.py @@ -147,6 +147,28 @@ def CPAfactory(spec): } return make_model(j) +def PCSAFTEOS(names_or_coeffs, kmat = []): + if isinstance(names_or_coeffs[0], SAFTCoeffs): + coeffs = [] + for c in names_or_coeffs: + coeffs.append({ + 'name': c.name, + 'm': c.m, + 'sigma_Angstrom': c.sigma_Angstrom, + 'epsilon_over_k': c.epsilon_over_k, + 'BibTeXKey': c.BibTeXKey + }) + spec = {'coeffs': coeffs, 'kmat': tolist(kmat)} + else: + spec = {'names': names_or_coeffs, 'kmat': tolist(kmat)} + + j = { + "kind": "PCSAFT", + "model": spec + } + return make_model(j) + + ''' def prepare(): -- GitLab