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 
10 namespace CoolProp
11 {
12 
13 
14 
64 typedef std::vector<std::vector<double> > mat;
66 {
67  public:
69  BicubicBackend(shared_ptr<CoolProp::AbstractState> AS) : TabularBackend(AS){
70  imposed_phase_index = iphase_not_imposed;
71  // If a pure fluid or a predefined mixture, don't need to set fractions, go ahead and build
72  if (!this->AS->get_mole_fractions().empty()){
73  check_tables();
74  SinglePhaseGriddedTableData &single_phase_logph = dataset->single_phase_logph;
75  SinglePhaseGriddedTableData &single_phase_logpT = dataset->single_phase_logpT;
76  dataset->build_coeffs(single_phase_logph, dataset->coeffs_ph);
77  dataset->build_coeffs(single_phase_logpT, dataset->coeffs_pT);
78  is_mixture = (this->AS->get_mole_fractions().size() > 1);
79  }
80  };
81  void set_mole_fractions(const std::vector<CoolPropDbl> &mole_fractions){
82  this->AS->set_mole_fractions(mole_fractions);
83  is_mixture = true;
84  // Check the tables and build if necessary
85  check_tables();
86  // For mixtures, the construction of the coefficients is delayed until this
87  // function so that the set_mole_fractions function can be called
88  SinglePhaseGriddedTableData &single_phase_logph = dataset->single_phase_logph;
89  SinglePhaseGriddedTableData &single_phase_logpT = dataset->single_phase_logpT;
90  dataset->build_coeffs(single_phase_logph, dataset->coeffs_ph);
91  dataset->build_coeffs(single_phase_logpT, dataset->coeffs_pT);
92  };
93  std::string backend_name(void){return get_backend_string(BICUBIC_BACKEND);}
94 
108  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);
109  double evaluate_single_phase_phmolar_derivative(parameters output, std::size_t i, std::size_t j, std::size_t Nx, std::size_t Ny){
110  return evaluate_single_phase_derivative(dataset->single_phase_logph, dataset->coeffs_ph, output, _hmolar, _p, i, j, Nx, Ny);
111  };
112  double evaluate_single_phase_pT_derivative(parameters output, std::size_t i, std::size_t j, std::size_t Nx, std::size_t Ny){
113  return evaluate_single_phase_derivative(dataset->single_phase_logpT, dataset->coeffs_pT, output, _T, _p, i, j, Nx, Ny);
114  };
115 
127  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);
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, double y, std::size_t &i, std::size_t &j);
136 
139  const std::vector<std::vector<CellCoeffs> > &coeffs,
140  const parameters variable1,
141  const double value1,
142  const parameters otherkey,
143  const double otherval,
144  std::size_t &i,
145  std::size_t &j);
146 
155  double evaluate_single_phase_transport(SinglePhaseGriddedTableData &table, parameters output, double x, double y, std::size_t i, std::size_t j);
156 
157  double evaluate_single_phase_phmolar_transport(parameters output, std::size_t i, std::size_t j){
158  return evaluate_single_phase_transport(dataset->single_phase_logph, output, _hmolar, _p, i, j);
159  };
160  double evaluate_single_phase_pT_transport(parameters output, std::size_t i, std::size_t j){
161  return evaluate_single_phase_transport(dataset->single_phase_logpT, output, _T, _p, i, j);
162  };
163 
173  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);
174  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);
175 };
176 
177 }
178 
179 #endif // BICUBICBACKEND_H
void check_tables()
Definition: TabularBackends.h:1042
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:64
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:116
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
std::string backend_name(void)
Get a string representation of the backend - for instance "HelmholtzEOSMixtureBackend" for the core m...
Definition: BicubicBackend.h:93
BicubicBackend(shared_ptr< CoolProp::AbstractState > AS)
Instantiator; base class loads or makes tables.
Definition: BicubicBackend.h:69
Definition: BicubicBackend.h:65
This class holds the data for a single-phase interpolation table that is regularly spaced...
Definition: TabularBackends.h:439
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:52
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:220
void build_coeffs(SinglePhaseGriddedTableData &table, std::vector< std::vector< CellCoeffs > > &coeffs)
Build the coefficients for bicubic interpolation.
Definition: TabularBackends.cpp:1289
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:24
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:165
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:80
This class contains the general code for tabular backends (TTSE, bicubic, etc.)
Definition: TabularBackends.h:837
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:49