mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-02-06 03:45:02 -05:00
Add code for tabular data management
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include "miniz.h"
|
||||
|
||||
namespace CoolProp{
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param table
|
||||
@@ -316,6 +318,48 @@ void CoolProp::TabularBackend::load_tables(){
|
||||
if (get_debug_level() > 0){ std::cout << "Tables loaded" << std::endl; }
|
||||
}
|
||||
|
||||
void CoolProp::TabularDataSet::write_tables(const std::string &path_to_tables)
|
||||
{
|
||||
make_dirs(path_to_tables);
|
||||
write_table(single_phase_logph, path_to_tables, "single_phase_logph");
|
||||
write_table(single_phase_logpT, path_to_tables, "single_phase_logpT");
|
||||
write_table(pure_saturation, path_to_tables, "pure_saturation");
|
||||
write_table(phase_envelope, path_to_tables, "phase_envelope");
|
||||
}
|
||||
|
||||
void CoolProp::TabularDataSet::load_tables(const std::string &path_to_tables, shared_ptr<CoolProp::AbstractState> &AS)
|
||||
{
|
||||
single_phase_logph.AS = AS;
|
||||
single_phase_logpT.AS = AS;
|
||||
pure_saturation.AS = AS;
|
||||
single_phase_logph.set_limits();
|
||||
single_phase_logpT.set_limits();
|
||||
load_table(single_phase_logph, path_to_tables, "single_phase_logph.bin.z");
|
||||
load_table(single_phase_logpT, path_to_tables, "single_phase_logpT.bin.z");
|
||||
load_table(pure_saturation, path_to_tables, "pure_saturation.bin.z");
|
||||
load_table(phase_envelope, path_to_tables, "phase_envelope.bin.z");
|
||||
if (get_debug_level() > 0){ std::cout << "Tables loaded" << std::endl; }
|
||||
};
|
||||
|
||||
/// Return the set of tabular datasets
|
||||
CoolProp::TabularDataSet const * CoolProp::TabularDataLibrary::get_set(shared_ptr<AbstractState> &AS)
|
||||
{
|
||||
const std::string path = path_to_tables(AS);
|
||||
// Try to find tabular set if it is already loaded
|
||||
std::map<std::string, TabularDataSet>::iterator it = data.find(path);
|
||||
// It is already in the map, return it
|
||||
if (it != data.end()){
|
||||
return &(it->second);
|
||||
}
|
||||
// It is not in the map, build it
|
||||
else{
|
||||
TabularDataSet set;
|
||||
data.insert(std::pair<std::string, TabularDataSet>(path, set));
|
||||
set.load_tables(path, AS);
|
||||
return &(data[path]);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ENABLE_CATCH)
|
||||
#include "catch.hpp"
|
||||
|
||||
|
||||
@@ -568,7 +568,6 @@ class TabularBackend : public AbstractState
|
||||
{
|
||||
protected:
|
||||
bool tables_loaded, using_single_phase_table, is_mixture;
|
||||
shared_ptr<CoolProp::AbstractState> AS;
|
||||
enum selected_table_options{SELECTED_NO_TABLE=0, SELECTED_PH_TABLE, SELECTED_PT_TABLE};
|
||||
selected_table_options selected_table;
|
||||
std::size_t cached_single_phase_i, cached_single_phase_j;
|
||||
@@ -576,7 +575,7 @@ class TabularBackend : public AbstractState
|
||||
std::vector<std::vector<double> > *z, *dzdx, *dzdy, *d2zdx2, *d2zdxdy, *d2zdy2;
|
||||
std::vector<CoolPropDbl> mole_fractions;
|
||||
public:
|
||||
|
||||
shared_ptr<CoolProp::AbstractState> AS;
|
||||
TabularBackend(shared_ptr<CoolProp::AbstractState> AS) : tables_loaded(false), using_single_phase_table(false), AS(AS), is_mixture(false) {
|
||||
selected_table = SELECTED_NO_TABLE;
|
||||
// Flush the cached indices (set to large number)
|
||||
@@ -937,6 +936,36 @@ class TabularBackend : public AbstractState
|
||||
}
|
||||
}
|
||||
};
|
||||
/// This class contains the data for one set of Tabular data including single-phase and two-phase data
|
||||
class TabularDataSet
|
||||
{
|
||||
public:
|
||||
LogPHTable single_phase_logph;
|
||||
LogPTTable single_phase_logpT;
|
||||
PureFluidSaturationTableData pure_saturation;
|
||||
PhaseEnvelopeData phase_envelope;
|
||||
void write_tables(const std::string &path_to_tables);
|
||||
void load_tables(const std::string &path_to_tables, shared_ptr<CoolProp::AbstractState> &AS);
|
||||
};
|
||||
|
||||
class TabularDataLibrary
|
||||
{
|
||||
private:
|
||||
std::map<std::string, TabularDataSet> data;
|
||||
public:
|
||||
TabularDataLibrary(){};
|
||||
std::string path_to_tables(shared_ptr<CoolProp::AbstractState> &AS){
|
||||
std::vector<std::string> fluids = AS->fluid_names();
|
||||
std::vector<CoolPropDbl> fractions = AS->get_mole_fractions();
|
||||
std::vector<std::string> components;
|
||||
for (std::size_t i = 0; i < fluids.size(); ++i){
|
||||
components.push_back(format("%s[%0.10Lf]", fluids[i].c_str(), fractions[i]));
|
||||
}
|
||||
return get_home_dir() + "/.CoolProp/Tables/" + AS->backend_name() + "(" + strjoin(components, "&") + ")";
|
||||
}
|
||||
/// Return the set of tabular datasets
|
||||
TabularDataSet const * get_set(shared_ptr<AbstractState> &AS);
|
||||
};
|
||||
|
||||
} /* namespace CoolProp*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user