7#if defined(TEQP_MULTIPRECISION_ENABLED)
9#include <boost/multiprecision/cpp_bin_float.hpp>
10using namespace boost::multiprecision;
15namespace cppinterface{
20template<
typename ModelType>
26 const auto&
get_cref()
const {
return model; };
28 Owner(ModelType&& m) : model(m),
index(std::type_index(typeid(ModelType))) {};
33template<
typename ModelType>
36 const ModelType& model;
39 const auto&
get_cref()
const {
return model; };
53template<
typename... Funcs>
60 const auto&
get_cref()
const {
return *
this; };
64 template<
typename MoleFracType>
65 auto R(
const MoleFracType& molefrac){
70 template<
typename TType,
typename RhoType,
typename MoleFracType>
71 auto alphar(
const TType& T,
const RhoType& rhomolar,
const MoleFracType& molefrac)
const {
72 auto sum_func = [&T, &rhomolar, &molefrac](
auto const&... e)->
decltype(
auto) {
73 return (e.alphar(T, rhomolar, molefrac)+...);
79template <
typename... Args>
86 template<
class T>
struct tag{
using type=T;};
96template<
typename ModelPack>
118 return mp.get_cref().R(molefrac);
121 virtual double get_Arxy(
const int NT,
const int ND,
const double T,
const double rhomolar,
const EArrayd& molefrac)
const override{
122 return TDXDerivatives<
decltype(mp.get_cref()),
double,
EArrayd>::get_Ar(NT, ND, mp.get_cref(), T, rhomolar, molefrac);
126#define X(i,j) virtual double get_Ar ## i ## j(const double T, const double rho, const REArrayd& molefrac) const override { return TDXDerivatives<decltype(mp.get_cref()), double, EArrayd>::template get_Arxy<i,j>(mp.get_cref(), T, rho, molefrac); };
130#define X(i) virtual EArrayd get_Ar0 ## i ## n(const double T, const double rho, const REArrayd& molefrac) const override { auto vals = TDXDerivatives<decltype(mp.get_cref()), double, EArrayd>::template get_Ar0n<i>(mp.get_cref(), T, rho, molefrac); return Eigen::Map<Eigen::ArrayXd>(&(vals[0]), vals.size()); };
134#define X(i) virtual EArrayd get_Ar ## i ## 0n(const double T, const double rho, const REArrayd& molefrac) const override { auto vals = TDXDerivatives<decltype(mp.get_cref()), double, EArrayd>::template get_Arn0<i>(mp.get_cref(), T, rho, molefrac); return Eigen::Map<Eigen::ArrayXd>(&(vals[0]), vals.size()); };
138 virtual double get_Ar01ep(
const double T,
const double rho,
const EArrayd& molefrac)
const override {
139 using namespace boost::multiprecision;
140 using my_float_t = number<cpp_bin_float<100U>>;
141 auto f = [&](
const auto& rhoep){
142 return mp.get_cref().alphar(T, rhoep, molefrac);
144 return rho*
static_cast<double>(
centered_diff<1,4>(f,
static_cast<my_float_t
>(rho), 1e-16*
static_cast<my_float_t
>(rho)));
146 virtual double get_Ar02ep(
const double T,
const double rho,
const EArrayd& molefrac)
const override {
147 using namespace boost::multiprecision;
148 using my_float_t = number<cpp_bin_float<100U>>;
149 auto f = [&](
const auto& rhoep){
150 return mp.get_cref().alphar(T, rhoep, molefrac);
152 return rho*rho*
static_cast<double>(
centered_diff<2,4>(f,
static_cast<my_float_t
>(rho), 1e-16*
static_cast<my_float_t
>(rho)));
154 virtual double get_Ar03ep(
const double T,
const double rho,
const EArrayd& molefrac)
const override {
155 using namespace boost::multiprecision;
156 using my_float_t = number<cpp_bin_float<100U>>;
157 auto f = [&](
const auto& rhoep){
158 return mp.get_cref().alphar(T, rhoep, molefrac);
160 return rho*rho*rho*
static_cast<double>(
centered_diff<3,4>(f,
static_cast<my_float_t
>(rho), 1e-16*
static_cast<my_float_t
>(rho)));
167 virtual std::map<int, double>
get_Bnvir(
const int Nderiv,
const double T,
const EArrayd& z)
const override {
173 virtual double get_dmBnvirdTm(
const int Nderiv,
const int NTderiv,
const double T,
const EArrayd& molefrac)
const override {
174 return VirialDerivatives<
decltype(mp.get_cref()),
double,
EArrayd>::get_dmBnvirdTm_runtime(Nderiv, NTderiv, mp.get_cref(), T, molefrac);
178 virtual double get_ATrhoXi(
const double T,
const int NT,
const double rhomolar,
const int ND,
const EArrayd& molefrac,
const int i,
const int NXi)
const override {
179 return TDXDerivatives<
decltype(mp.get_cref()),
double,
EArrayd>::get_ATrhoXi_runtime(mp.get_cref(), T, NT, rhomolar, ND, molefrac, i, NXi);
181 virtual double get_ATrhoXiXj(
const double T,
const int NT,
const double rhomolar,
const int ND,
const EArrayd& molefrac,
const int i,
const int NXi,
const int j,
const int NXj)
const override {
182 return TDXDerivatives<
decltype(mp.get_cref()),
double,
EArrayd>::get_ATrhoXiXj_runtime(mp.get_cref(), T, NT, rhomolar, ND, molefrac, i, NXi, j, NXj);
184 virtual double get_ATrhoXiXjXk(
const double T,
const int NT,
const double rhomolar,
const int ND,
const EArrayd& molefrac,
const int i,
const int NXi,
const int j,
const int NXj,
const int k,
const int NXk)
const override {
185 return TDXDerivatives<
decltype(mp.get_cref()),
double,
EArrayd>::get_ATrhoXiXjXk_runtime(mp.get_cref(), T, NT, rhomolar, ND, molefrac, i, NXi, j, NXj, k, NXk);
189 virtual double get_AtaudeltaXi(
const double tau,
const int NT,
const double delta,
const int ND,
const EArrayd& molefrac,
const int i,
const int NXi)
const override {
190 return TDXDerivatives<
decltype(mp.get_cref()),
double,
EArrayd>::get_AtaudeltaXi_runtime(mp.get_cref(), tau, NT, delta, ND, molefrac, i, NXi);
192 virtual double get_AtaudeltaXiXj(
const double tau,
const int NT,
const double delta,
const int ND,
const EArrayd& molefrac,
const int i,
const int NXi,
const int j,
const int NXj)
const override {
193 return TDXDerivatives<
decltype(mp.get_cref()),
double,
EArrayd>::get_AtaudeltaXiXj_runtime(mp.get_cref(), tau, NT, delta, ND, molefrac, i, NXi, j, NXj);
195 virtual double get_AtaudeltaXiXjXk(
const double tau,
const int NT,
const double delta,
const int ND,
const EArrayd& molefrac,
const int i,
const int NXi,
const int j,
const int NXj,
const int k,
const int NXk)
const override {
196 return TDXDerivatives<
decltype(mp.get_cref()),
double,
EArrayd>::get_AtaudeltaXiXjXk_runtime(mp.get_cref(), tau, NT, delta, ND, molefrac, i, NXi, j, NXj, k, NXk);
200#define X(f) virtual double f(const double T, const EArrayd& rhovec) const override { return IsochoricDerivatives<decltype(mp.get_cref()), double, EArrayd>::f(mp.get_cref(), T, rhovec); };
203#define X(f) virtual EArrayd f(const double T, const EArrayd& rhovec) const override { return IsochoricDerivatives<decltype(mp.get_cref()), double, EArrayd>::f(mp.get_cref(), T, rhovec); };
206#define X(f) virtual EMatrixd f(const double T, const EArrayd& rhovec) const override { return IsochoricDerivatives<decltype(mp.get_cref()), double, EArrayd>::f(mp.get_cref(), T, rhovec); };
209#define X(f) virtual std::tuple<double, Eigen::ArrayXd, Eigen::MatrixXd> f(const double T, const EArrayd& rhovec) const override { return IsochoricDerivatives<decltype(mp.get_cref()), double, EArrayd>::f(mp.get_cref(), T, rhovec); };
221template<
typename TemplatedModel>
auto view(
const TemplatedModel& tp){
225template<
typename TemplatedModel>
auto own(
const TemplatedModel&& tp){
226 Owner o(std::move(tp));
230template<
typename TemplatedModel>
auto make_owned(
const TemplatedModel& tmodel){
232 return std::unique_ptr<AbstractModel>(
own(std::move(tmodel)));
235template<
typename TemplatedModel>
auto make_cview(
const TemplatedModel& tmodel){
237 return std::unique_ptr<AbstractModel>(
view(tmodel));
245template<
typename ModelType>
253 if (mptr !=
nullptr){
256 else if (mptr2 !=
nullptr){
269template<
typename ModelType>
276 if (mptr2 !=
nullptr){
280 throw teqp::InvalidArgument(
"Unable to cast model to desired type; only the Owner ownership model is allowed");
Eigen::Array< double, Nderivsmax+1, Nderivsmax+1 > derivs
virtual ISOCHORIC_multimatrix_args Eigen::ArrayXd get_Psir_sigma_derivs(const double T, const EArrayd &rhovec, const EArrayd &v) const override
virtual double get_AtaudeltaXi(const double tau, const int NT, const double delta, const int ND, const EArrayd &molefrac, const int i, const int NXi) const override
const std::type_index & get_type_index() const override
virtual double get_dmBnvirdTm(const int Nderiv, const int NTderiv, const double T, const EArrayd &molefrac) const override
auto & get_ModelPack_ref()
virtual EArray33d get_deriv_mat2(const double T, double rho, const EArrayd &z) const override
virtual double get_Ar02ep(const double T, const double rho, const EArrayd &molefrac) const override
virtual double get_AtaudeltaXiXjXk(const double tau, const int NT, const double delta, const int ND, const EArrayd &molefrac, const int i, const int NXi, const int j, const int NXj, const int k, const int NXk) const override
virtual double get_ATrhoXiXjXk(const double T, const int NT, const double rhomolar, const int ND, const EArrayd &molefrac, const int i, const int NXi, const int j, const int NXj, const int k, const int NXk) const override
virtual std::map< int, double > get_Bnvir(const int Nderiv, const double T, const EArrayd &z) const override
virtual double get_Arxy(const int NT, const int ND, const double T, const double rhomolar, const EArrayd &molefrac) const override
virtual double get_B2vir(const double T, const EArrayd &z) const override
virtual double get_AtaudeltaXiXj(const double tau, const int NT, const double delta, const int ND, const EArrayd &molefrac, const int i, const int NXi, const int j, const int NXj) const override
virtual double get_R(const EArrayd &molefrac) const override
virtual ARN0_args double get_Ar01ep(const double T, const double rho, const EArrayd &molefrac) const override
virtual double get_B12vir(const double T, const EArrayd &z) const override
virtual double get_ATrhoXiXj(const double T, const int NT, const double rhomolar, const int ND, const EArrayd &molefrac, const int i, const int NXi, const int j, const int NXj) const override
DerivativeAdapter(internal::tag< T >, const T &&mp)
virtual double get_Ar03ep(const double T, const double rho, const EArrayd &molefrac) const override
virtual double get_ATrhoXi(const double T, const int NT, const double rhomolar, const int ND, const EArrayd &molefrac, const int i, const int NXi) const override
const auto & get_ModelPack_cref() const
A collection type that allows you to sum contributions from multiple EOS terms.
const std::type_index index
auto alphar(const TType &T, const RhoType &rhomolar, const MoleFracType &molefrac) const
The generic alphar function, which sums the contributions coming from the individual models passed in...
OwnershipSummer(Funcs &&...f)
const auto & get_cref() const
auto R(const MoleFracType &molefrac)
The gas constant, obtained from the first model in the tuple.
std::tuple< Funcs... > contributions
auto make_cview(const TemplatedModel &tmodel)
auto own(const TemplatedModel &&tp)
auto view(const TemplatedModel &tp)
ModelType & get_model_ref(AbstractModel *am)
Get a mutable reference to the model.
auto make_owned(const TemplatedModel &tmodel)
OwnershipSummer< Args... > make_OwnershipSummer(Args &&... args)
const ModelType & get_model_cref(const AbstractModel *am)
Get a const reference to the model that is being held in a DerivativeAdapter instance.
auto centered_diff(const Function &f, const Scalar x, const Scalar h)
ConstViewer(ModelType &m)
const std::type_index index
const auto & get_cref() const
const auto & get_cref() const
const std::type_index index
#define ISOCHORIC_matrix_args
#define ISOCHORIC_double_args
Eigen::Array< double, 3, 3 > EArray33d
#define ISOCHORIC_multimatrix_args
#define ISOCHORIC_array_args
Eigen::ArrayX< double > EArrayd