CoolProp
BicubicBackend.h
1 #ifndef BICUBICBACKEND_H
2 #define BICUBICBACKEND_H
3 
4 #include "TabularBackends.h"
5 #include "Exceptions.h"
6 #include "DataStructures.h"
7 #include "Eigen/Core"
8 
9 namespace CoolProp {
10 
60 typedef std::vector<std::vector<double>> mat;
62 {
63  public:
65  BicubicBackend(shared_ptr<CoolProp::AbstractState> AS) : TabularBackend(AS) {
66  imposed_phase_index = iphase_not_imposed;
67  // If a pure fluid or a predefined mixture, don't need to set fractions, go ahead and build
68  if (!this->AS->get_mole_fractions().empty()) {
69  check_tables();
70  SinglePhaseGriddedTableData& single_phase_logph = dataset->single_phase_logph;
71  SinglePhaseGriddedTableData& single_phase_logpT = dataset->single_phase_logpT;
72  dataset->build_coeffs(single_phase_logph, dataset->coeffs_ph);
73  dataset->build_coeffs(single_phase_logpT, dataset->coeffs_pT);
74  is_mixture = (this->AS->get_mole_fractions().size() > 1);
75  }
76  };
77  void set_mole_fractions(const std::vector<CoolPropDbl>& mole_fractions) {
78  this->AS->set_mole_fractions(mole_fractions);
79  is_mixture = true;
80  // Check the tables and build if necessary
81  check_tables();
82  // For mixtures, the construction of the coefficients is delayed until this
83  // function so that the set_mole_fractions function can be called
84  SinglePhaseGriddedTableData& single_phase_logph = dataset->single_phase_logph;
85  SinglePhaseGriddedTableData& single_phase_logpT = dataset->single_phase_logpT;
86  dataset->build_coeffs(single_phase_logph, dataset->coeffs_ph);
87  dataset->build_coeffs(single_phase_logpT, dataset->coeffs_pT);
88  };
89  std::string backend_name(void) {
90  return get_backend_string(BICUBIC_BACKEND);
91  }
92 
106  double evaluate_single_phase_derivative(SinglePhaseGriddedTableData& table, std::vector<std::vector<CellCoeffs>>& coeffs, parameters output,
107  double x, double y, std::size_t i, std::size_t j, std::size_t Nx, std::size_t Ny);
108  double evaluate_single_phase_phmolar_derivative(parameters output, std::size_t i, std::size_t j, std::size_t Nx, std::size_t Ny) {
109  return evaluate_single_phase_derivative(dataset->single_phase_logph, dataset->coeffs_ph, output, _hmolar, _p, i, j, Nx, Ny);
110  };
111  double evaluate_single_phase_pT_derivative(parameters output, std::size_t i, std::size_t j, std::size_t Nx, std::size_t Ny) {
112  return evaluate_single_phase_derivative(dataset->single_phase_logpT, dataset->coeffs_pT, output, _T, _p, i, j, Nx, Ny);
113  };
114 
126  double evaluate_single_phase(const SinglePhaseGriddedTableData& table, const std::vector<std::vector<CellCoeffs>>& coeffs,
127  const parameters output, const double x, const double y, const std::size_t i, const std::size_t j);
128  double evaluate_single_phase_phmolar(parameters output, std::size_t i, std::size_t j) {
129  return evaluate_single_phase(dataset->single_phase_logph, dataset->coeffs_ph, output, _hmolar, _p, i, j);
130  };
131  double evaluate_single_phase_pT(parameters output, std::size_t i, std::size_t j) {
132  return evaluate_single_phase(dataset->single_phase_logpT, dataset->coeffs_pT, output, _T, _p, i, j);
133  };
134 
135  virtual void find_native_nearest_good_indices(SinglePhaseGriddedTableData& table, const std::vector<std::vector<CellCoeffs>>& coeffs, double x,
136  double y, std::size_t& i, std::size_t& j);
137 
139  virtual void find_nearest_neighbor(SinglePhaseGriddedTableData& table, const std::vector<std::vector<CellCoeffs>>& coeffs,
140  const parameters variable1, const double value1, const parameters otherkey, const double otherval,
141  std::size_t& i, std::size_t& j);
142 
151  double evaluate_single_phase_transport(SinglePhaseGriddedTableData& table, parameters output, double x, double y, std::size_t i, std::size_t j);
152 
153  double evaluate_single_phase_phmolar_transport(parameters output, std::size_t i, std::size_t j) {
154  return evaluate_single_phase_transport(dataset->single_phase_logph, output, _hmolar, _p, i, j);
155  };
156  double evaluate_single_phase_pT_transport(parameters output, std::size_t i, std::size_t j) {
157  return evaluate_single_phase_transport(dataset->single_phase_logpT, output, _T, _p, i, j);
158  };
159 
169  void invert_single_phase_x(const SinglePhaseGriddedTableData& table, const std::vector<std::vector<CellCoeffs>>& coeffs, parameters other_key,
170  double other, double y, std::size_t i, std::size_t j);
171  void invert_single_phase_y(const SinglePhaseGriddedTableData& table, const std::vector<std::vector<CellCoeffs>>& coeffs, parameters other_key,
172  double other, double x, std::size_t i, std::size_t j);
173 };
174 
175 } // namespace CoolProp
176 
177 #endif // BICUBICBACKEND_H
void check_tables()
Definition: TabularBackends.h:1337
double evaluate_single_phase(const SinglePhaseGriddedTableData &table, const std::vector< std::vector< CellCoeffs >> &coeffs, const parameters output, const double x, const double y, const std::size_t i, const std::size_t j)
Definition: BicubicBackend.cpp:83
std::vector< std::vector< double > > mat
This class implements bicubic interpolation, as very clearly laid out by the page on wikipedia: http:...
Definition: BicubicBackend.h:60
void invert_single_phase_y(const SinglePhaseGriddedTableData &table, const std::vector< std::vector< CellCoeffs >> &coeffs, parameters other_key, double other, double x, std::size_t i, std::size_t j)
Use the single_phase table to solve for y given an x.
Definition: BicubicBackend.cpp:239
virtual void find_nearest_neighbor(SinglePhaseGriddedTableData &table, const std::vector< std::vector< CellCoeffs >> &coeffs, const parameters variable1, const double value1, const parameters otherkey, const double otherval, std::size_t &i, std::size_t &j)
Ask the derived class to find the nearest neighbor (pure virtual)
Definition: BicubicBackend.cpp:26
std::string backend_name(void)
Get a string representation of the backend - for instance "HelmholtzEOSMixtureBackend" for the core m...
Definition: BicubicBackend.h:89
BicubicBackend(shared_ptr< CoolProp::AbstractState > AS)
Instantiator; base class loads or makes tables.
Definition: BicubicBackend.h:65
Definition: BicubicBackend.h:61
This class holds the data for a single-phase interpolation table that is regularly spaced...
Definition: TabularBackends.h:600
double evaluate_single_phase_transport(SinglePhaseGriddedTableData &table, parameters output, double x, double y, std::size_t i, std::size_t j)
Evaluate the single-phase transport properties using linear interpolation.
Definition: BicubicBackend.cpp:50
double evaluate_single_phase_derivative(SinglePhaseGriddedTableData &table, std::vector< std::vector< CellCoeffs >> &coeffs, parameters output, double x, double y, std::size_t i, std::size_t j, std::size_t Nx, std::size_t Ny)
Evaluate a derivative in terms of the native inputs of the table.
Definition: BicubicBackend.cpp:131
void invert_single_phase_x(const SinglePhaseGriddedTableData &table, const std::vector< std::vector< CellCoeffs >> &coeffs, parameters other_key, double other, double y, std::size_t i, std::size_t j)
Use the table to solve for the x variable of the table given the y coordinate of the table and a vari...
Definition: BicubicBackend.cpp:183
This class contains the general code for tabular backends (TTSE, bicubic, etc.)
Definition: TabularBackends.h:1063
virtual void find_native_nearest_good_indices(SinglePhaseGriddedTableData &table, const std::vector< std::vector< CellCoeffs >> &coeffs, double x, double y, std::size_t &i, std::size_t &j)
Ask the derived class to find the nearest good set of i,j that it wants to use (pure virtual) ...
Definition: BicubicBackend.cpp:8
void build_coeffs(SinglePhaseGriddedTableData &table, std::vector< std::vector< CellCoeffs >> &coeffs)
Build the coefficients for bicubic interpolation.
Definition: TabularBackends.cpp:1326
This file contains flash routines in which the state is unknown, and a solver of some kind must be us...
Definition: AbstractState.h:19
parameters
Define some constants that will be used throughout These are constants for the input and output para...
Definition: DataStructures.h:64