CoolProp  6.6.1dev
An open-source fluid property and humid air property database
IncompressibleBackend.h
Go to the documentation of this file.
1 
2 #ifndef INCOMPRESSIBLEBACKEND_H_
3 #define INCOMPRESSIBLEBACKEND_H_
4 
5 #include "DataStructures.h"
6 #include "IncompressibleFluid.h"
7 #include "AbstractState.h"
8 #include "Exceptions.h"
9 
10 #include <vector>
11 
12 namespace CoolProp {
13 
15 {
16 
17  protected:
19  //double _T, _p; // From AbstractState
20  std::vector<CoolPropDbl> _fractions;
21 
25 
29 
31 
33 
36  void set_fractions(const std::vector<CoolPropDbl>& fractions);
37 
38  public:
41  std::string backend_name(void) {
43  }
44 
50  IncompressibleBackend(const std::string& fluid_name);
53  IncompressibleBackend(const std::vector<std::string>& component_names);
54 
55  // Incompressible backend uses different compositions
56  bool using_mole_fractions(void) {
57  return this->fluid->getxid() == IFRAC_MOLE;
58  };
59  bool using_mass_fractions(void) {
60  return (this->fluid->getxid() == IFRAC_MASS || this->fluid->getxid() == IFRAC_PURE);
61  };
62  bool using_volu_fractions(void) {
63  return this->fluid->getxid() == IFRAC_VOLUME;
64  };
65 
67 
75  void update(CoolProp::input_pairs input_pair, double value1, double value2);
76 
77  std::string fluid_param_string(const std::string& ParamName) {
78  if (!ParamName.compare("long_name")) {
79  return calc_name();
80  } else {
81  throw ValueError(format("Input value [%s] is invalid.", ParamName.c_str()));
82  }
83  }
84 
86  bool clear();
87 
89  void set_reference_state(double T0 = 20 + 273.15, double p0 = 101325, double x0 = 0.0, double h0 = 0.0, double s0 = 0.0);
90 
92 
95  void set_mole_fractions(const std::vector<CoolPropDbl>& mole_fractions);
96  const std::vector<CoolPropDbl>& get_mole_fractions(void) {
97  throw NotImplementedError("get_mole_fractions not implemented for this backend");
98  };
99 
101 
104  void set_mass_fractions(const std::vector<CoolPropDbl>& mass_fractions);
105 
107 
110  void set_volu_fractions(const std::vector<CoolPropDbl>& volu_fractions);
111 
113  void check_status();
114 
121  double rhomass(void);
123  double hmass(void);
125  double smass(void);
127  double umass(void);
129  double cmass(void);
130 
131  double drhodTatPx(void);
132  double dsdTatPx(void);
133  double dhdTatPx(void);
134  double dsdTatPxdT(void);
135  double dhdTatPxdT(void);
136  double dsdpatTx(void);
137  double dhdpatTx(void);
138 
140  double T_ref(void);
142  double p_ref(void);
144  double x_ref(void);
146  double h_ref(void);
148  double s_ref(void);
149 
151  double hmass_ref(void);
153  double smass_ref(void);
154 
159 
166 
173 
179 
180  // /// Calculate T given pressure and internal energy
181  // /**
182  // @param umass The mass internal energy in J/kg
183  // @param p The pressure in Pa
184  // @returns T The temperature in K
185  // */
186  // CoolPropDbl PUmass_flash(CoolPropDbl p, CoolPropDbl umass);
187 
190  return fluid->rho(_T, _p, _fractions[0]);
191  };
193  return fluid->c(_T, _p, _fractions[0]);
194  };
196  return cmass();
197  };
199  return cmass();
200  };
202  return fluid->visc(_T, _p, _fractions[0]);
203  };
205  return fluid->cond(_T, _p, _fractions[0]);
206  };
208  // No update is called - T_freeze is a trivial output
209  fluid->checkX(_fractions[0]);
210  return fluid->Tfreeze(_p, _fractions[0]);
211  };
212  CoolPropDbl calc_melting_line(int param, int given, CoolPropDbl value);
213  CoolPropDbl calc_umass(void);
214 
216  CoolPropDbl calc_hmass(void);
217  CoolPropDbl calc_smass(void);
218 
219  public:
221  CoolPropDbl raw_calc_hmass(double T, double p, double x);
222  CoolPropDbl raw_calc_smass(double T, double p, double x);
223 
224  protected:
227 
228  /* Below are direct calculations of the derivatives. Nothing
229  * special is going on, we simply use the polynomial class to
230  * derive the different functions with respect to temperature.
231  */
233  double calc_drhodTatPx(double T, double p, double x) {
234  return fluid->drhodTatPx(T, p, x);
235  };
237  double calc_dsdTatPx(double T, double p, double x) {
238  return fluid->c(T, p, x) / T;
239  };
241  double calc_dhdTatPx(double T, double p, double x) {
242  return fluid->c(T, p, x);
243  };
247  double calc_dsdTatPxdT(double T, double p, double x) {
248  return fluid->dsdTatPxdT(T, p, x);
249  };
253  double calc_dhdTatPxdT(double T, double p, double x) {
254  return fluid->dhdTatPxdT(T, p, x);
255  };
256 
257  /* Other useful derivatives
258  */
261  double calc_dsdpatTx(double rho, double drhodTatPx);
264  double calc_dhdpatTx(double T, double rho, double drhodTatPx);
265 
266  public:
269  return fluid->getTmax();
270  };
272  return fluid->getTmin();
273  };
275  return fluid->getxmin();
276  };
278  return fluid->getxmax();
279  };
280  std::string calc_name(void) {
281  return fluid->getName();
282  };
283  std::string calc_description(void) {
284  return fluid->getDescription();
285  };
286 };
287 
288 } /* namespace CoolProp */
289 #endif /* INCOMPRESSIBLEBACKEND_H_ */