Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose SAFT-VRQ Mie in C++ wrapper. #179

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ objects
bin
installed/
build/
dist/
run*
doc/dox.out
doc/doxygen/html
Expand Down Expand Up @@ -51,6 +52,8 @@ TAGS

*.DS_Store
local_testing/
tmp/
sandbox/
venv/
venv*
*.idea
Expand Down
9 changes: 9 additions & 0 deletions addon/cppThermopack/cppThermopack/saft.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
#pragma once
#include "thermo.h"

extern "C" {
void get_export_name(saft_interface, sigma_ij)(size_t* i, size_t* j, double* sigma);
void get_export_name(saft_interface, epsilon_ij)(size_t* i, size_t* j, double* eps);
void get_export_name(saft_interface, sigma_eff_ij)(size_t* i, size_t* j, double* T, double* sigma_eff);
void get_export_name(saft_interface, epsilon_eff_ij)(size_t* i, size_t* j, double* T, double* epsilon_eff);
}

class Saft : public Thermo {
public:
Saft(std::string comps) : Thermo(comps){
Expand All @@ -17,11 +24,13 @@ class Saft : public Thermo {
ms = std::vector<double>(nc);
}

// virtual void set_sigma(size_t ci, double sigma_);
double get_sigma(size_t ci){return sigma[ci];}
virtual std::vector<double> get_sigma(){
return sigma;
}

// virtual void set_eps_div_k(size_t ci, double eps_div_k_);
double get_eps_div_k(size_t ci){return eps_div_k[ci];}
virtual std::vector<double> get_eps_div_k(){
return eps_div_k;
Expand Down
41 changes: 40 additions & 1 deletion addon/cppThermopack/cppThermopack/saftvrmie.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,42 @@ class Saftvrmie : public Saft {
init_params();
}

void set_pure_fluid_param(size_t ci, double ms_, double sigma_, double eps_div_k_, double la, double lr){
size_t i = ci - 1;
ms[i] = ms_; sigma[i] = sigma_, eps_div_k[i] = eps_div_k_; lambda_a[i] = la; lambda_r[i] = lr;
reset_pure_fluid_param(ci);
}

void set_sigma(size_t ci, double sigma_){
sigma[ci - 1] = sigma_;
reset_pure_fluid_param(ci);
}

void set_eps_div_k(size_t ci, double eps_div_k_){
eps_div_k[ci - 1] = eps_div_k_;
reset_pure_fluid_param(ci);
}

void set_la(size_t ci, double la){
lambda_a[ci - 1] = la;
reset_pure_fluid_param(ci);
}

void set_lr(size_t ci, double lr){
lambda_r[ci - 1] = lr;
reset_pure_fluid_param(ci);
}

protected:
std::vector<double> lambda_a, lambda_r;

explicit Saftvrmie(std::string comps, bool is_inheriting) // Used by inheriting classes to skip saftvrmie eoslibinit call
: Saft(comps)
{
lambda_a = std::vector<double>(nc);
lambda_r = std::vector<double>(nc);
}

void init_params(){
activate();
size_t ci; // Fortran component index
Expand All @@ -33,6 +68,10 @@ class Saftvrmie : public Saft {
}

private:
std::vector<double> lambda_a, lambda_r;
void reset_pure_fluid_param(size_t ci){
activate();
size_t i = ci - 1;
get_export_name(saftvrmie_containers, set_saftvrmie_pure_fluid_param)(&ci, &(ms[i]), &(sigma[i]), &(eps_div_k[i]), &(lambda_a[i]), &(lambda_r[i]));
}

};
49 changes: 49 additions & 0 deletions addon/cppThermopack/cppThermopack/saftvrqmie.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once
#include <string>
#include "dllmacros.h"
#include "saftvrmie.h"
#include "saft.h"

extern "C" {
void get_export_name(eoslibinit, init_quantum_saftvrmie)(char* comps, int* fh_order, int* additive_hard_sphere, char* parameter_ref, size_t comps_strlen, size_t ref_strlen);
void get_export_name(saftvrmie_containers, get_feynman_hibbs_order)(size_t* ci, int* fh_order, int* fh_hs);
}

class Saftvrqmie : public Saftvrmie {
public:
Saftvrqmie(std::string comps, int feynman_hibbs_order=1, bool additive_hard_sphere=false, std::string parameter_reference="Default", double minimum_temperature=20.)
: Saftvrmie(comps, true)
{
activate();
int additive_hs = (additive_hard_sphere) ? true_int : 0;
get_export_name(eoslibinit, init_quantum_saftvrmie)(comps.data(), &feynman_hibbs_order, &additive_hs,
parameter_reference.data(), comps.size(), parameter_reference.size());
lambda_a = std::vector<double>(nc);
lambda_r = std::vector<double>(nc);
init_params();
set_tmin(minimum_temperature);
}

double get_sigma_eff(size_t i, double T){return get_sigma_eff(i, i, T);}
double get_sigma_eff(size_t i, size_t j, double T){
activate();
double sigma_eff;
get_export_name(saft_interface, sigma_eff_ij)(&i, &j, &T, &sigma_eff);
return sigma_eff;
}

double get_epsilon_eff(size_t i, double T){return get_epsilon_eff(i, i, T);}
double get_epsilon_eff(size_t i, size_t j, double T){
activate();
double epsilon_eff;
get_export_name(saft_interface, epsilon_eff_ij)(&i, &j, &T, &epsilon_eff);
return epsilon_eff;
}

int get_feynman_hibbs_order(size_t ci){
activate();
int fh, fh_hs;
get_export_name(saftvrmie_containers, get_feynman_hibbs_order)(&ci, &fh, &fh_hs);
return fh;
}
};
Loading