CoolProp 8.0.0
An open-source fluid property and humid air property database
IncompressibleFluid.h
Go to the documentation of this file.
1/*
2 * CoolPropFluid.h
3 *
4 * Created on: 20 Dec 2013
5 * Author: jowr
6 */
7
8#ifndef INCOMPRESSIBLEFLUID_H_
9#define INCOMPRESSIBLEFLUID_H_
10
14
15#include <numeric>
16#include <string>
17#include <utility>
18#include <vector>
19#include <map>
20#include <cassert>
21#include <iterator>
22
23#include <Eigen/Core>
26
27namespace CoolProp {
28
30{
32 {
39 };
41 Eigen::MatrixXd coeffs; //TODO: Can we store the Eigen::Matrix objects more efficiently?
42 //std::vector<std::vector<double> > coeffs;
45
46 };
47};
48
49#if !defined(NO_FMTLIB) && FMT_VERSION >= 90000
50inline int format_as(IncompressibleData::IncompressibleTypeEnum type) {
51 return fmt::underlying(type);
52}
53#endif
54
56
60{
61
62 protected:
63 bool strict;
64
65 std::string name;
66 std::string description;
67 std::string reference;
68
69 double Tmin, Tmax;
70 double xmin, xmax;
72
73 double TminPsat;
74 double xbase, Tbase;
75
77
87
92
99
104
109
114
118
120
125
130
134
136
137 // Forward declaration of the some internal functions
138 //double h_u(double T, double p, double x);
139 //double u_h(double T, double p, double x);
140
141 public:
143 : strict(true), Tmin(_HUGE), Tmax(_HUGE), xmin(_HUGE), xmax(_HUGE), xid(IFRAC_UNDEFINED), TminPsat(_HUGE), xbase(_HUGE), Tbase(_HUGE) {
144
145 };
146 virtual ~IncompressibleFluid() = default;
147
148 std::string getName() const {
149 return name;
150 }
151 std::string get_name() const {
152 return getName();
153 } // For backwards-compatibility.
154 std::string getDescription() const {
155 return description;
156 }
157 std::string getReference() const {
158 return reference;
159 }
160
161 double getTmax() const {
162 return Tmax;
163 }
164 double getTmin() const {
165 return Tmin;
166 }
167 double getxmax() const {
168 return xmax;
169 }
170 double getxmin() const {
171 return xmin;
172 }
174 return xid;
175 }
176 double getTminPsat() const {
177 return TminPsat;
178 }
179 double getTbase() const {
180 return Tbase;
181 }
182 double getxbase() const {
183 return xbase;
184 }
185
186 void setName(const std::string& name) {
187 this->name = name;
188 }
189 void setDescription(const std::string& description) {
190 this->description = description;
191 }
192 void setReference(const std::string& reference) {
193 this->reference = reference;
194 }
195 void setTmax(double Tmax) {
196 this->Tmax = Tmax;
197 }
198 void setTmin(double Tmin) {
199 this->Tmin = Tmin;
200 }
201 void setxmax(double xmax) {
202 this->xmax = xmax;
203 }
204 void setxmin(double xmin) {
205 this->xmin = xmin;
206 }
208 this->xid = xid;
209 }
210 void setTminPsat(double TminPsat) {
211 this->TminPsat = TminPsat;
212 }
213 void setTbase(double Tbase) {
214 this->Tbase = Tbase;
215 }
216 void setxbase(double xbase) {
217 this->xbase = xbase;
218 }
219
222 this->density = std::move(density);
223 }
225 this->specific_heat = std::move(specific_heat);
226 }
228 this->viscosity = std::move(viscosity);
229 }
231 this->conductivity = std::move(conductivity);
232 }
234 this->p_sat = std::move(p_sat);
235 }
237 this->T_freeze = std::move(T_freeze);
238 }
239
242 this->mass2input = std::move(mass2input);
243 }
245 this->volume2input = std::move(volume2input);
246 }
248 this->mole2input = std::move(mole2input);
249 }
250
252 void validate();
254 bool is_pure();
255
256 protected:
258 double baseExponential(const IncompressibleData& data, double y, double ybase);
259 double baseLogexponential(const IncompressibleData& data, double y, double ybase);
261 double basePolyOffset(IncompressibleData data, double y, double z = 0.0);
262
263 public:
264 /* All functions need T and p as input. Might not
265 * be necessary, but gives a clearer structure.
266 */
268 double rho(double T, double p, double x);
270 double c(double T, double p, double x);
271 double cp(double T, double p, double x) {
272 throw ValueError(format("%s (%d): Please use the c-function instead.", __FILE__, __LINE__));
273 }
274 double cv(double T, double p, double x) {
275 throw ValueError(format("%s (%d): Please use the c-function instead.", __FILE__, __LINE__));
276 }
278 double s(double T, double p, double x) {
279 throw ValueError(format("%s (%d): The internal calculations have changed, use the backend to calculate entropy from the partial derivatives.",
280 __FILE__, __LINE__));
281 }
283 double u(double T, double p, double x) {
284 throw ValueError(
285 format("%s (%d): The internal calculations have changed, use the backend to calculate internal energy from enthalpy.", __FILE__, __LINE__));
286 }
288 double h(double T, double p, double x) {
289 throw ValueError(
290 format("%s (%d): The internal calculations have changed, use the backend to calculate enthalpy from the partial derivatives.", __FILE__,
291 __LINE__));
292 }
294 double visc(double T, double p, double x);
296 double cond(double T, double p, double x);
298 double psat(double T, double x);
300 double Tfreeze(double p, double x);
301
302 /* Below are direct calculations of the derivatives. Nothing
303 * special is going on, we simply use the polynomial class to
304 * derive the different functions with respect to temperature.
305 */
307 // with respect to temperature at constant pressure and composition
308 double drhodTatPx(double T, double p, double x);
311 //double dsdTatPx (double T, double p, double x){return c(T,p,x)/T;};
314 //double dhdTatPx (double T, double p, double x){return c(T,p,x);};
316 // with respect to temperature at constant pressure and composition
317 // integrated in temperature
318 double dsdTatPxdT(double T, double p, double x);
320 // with respect to temperature at constant pressure and composition
321 // integrated in temperature
322 double dhdTatPxdT(double T, double p, double x);
323
325
327 double inputFromMass(double T, double x);
329
331 double inputFromVolume(double T, double x);
333
335 double inputFromMole(double T, double x);
336
337 /* Some functions can be inverted directly, those are listed
338 * here. It is also possible to solve for other quantities, but
339 * that involves some more sophisticated processing and is not
340 * done here, but in the backend, T(h,p) for example.
341 */
343 double T_rho(double Dmass, double p, double x);
345 double T_c(double Cmass, double p, double x);
347 double T_s(double Smass, double p, double x) {
348 throw NotImplementedError(format("%s (%d): T from entropy is not implemented in the fluid, use the backend.", __FILE__, __LINE__));
349 }
351 double T_u(double Umass, double p, double x) {
352 throw NotImplementedError(format("%s (%d): T from internal energy is not implemented in the fluid, use the backend.", __FILE__, __LINE__));
353 }
355 double T_h(double Hmass, double p, double x) {
356 throw NotImplementedError(format("%s (%d): T from enthalpy is not implemented in the fluid, use the backend.", __FILE__, __LINE__));
357 }
359 double T_visc(double visc, double p, double x) {
360 throw NotImplementedError(format("%s (%d): T from viscosity is not implemented.", __FILE__, __LINE__));
361 }
363 double T_cond(double cond, double p, double x) {
364 throw NotImplementedError(format("%s (%d): T from conductivity is not implemented.", __FILE__, __LINE__));
365 }
367 double T_psat(double psat, double x) {
368 throw NotImplementedError(format("%s (%d): T from psat is not implemented.", __FILE__, __LINE__));
369 }
371 double x_Tfreeze(double Tfreeze, double p) {
372 throw NotImplementedError(format("%s (%d): x from T_freeze is not implemented.", __FILE__, __LINE__));
373 }
374
375 protected:
376 /* Define internal energy and enthalpy as functions of the
377 * other properties to provide data in case there are no
378 * coefficients.
379 */
381
384 double h_u(double T, double p, double x) {
385 return u(T, p, x) + p / rho(T, p, x);
386 };
387
389
392 double u_h(double T, double p, double x) {
393 return h(T, p, x) - p / rho(T, p, x);
394 };
395
396 /*
397 * Some more functions to provide a single implementation
398 * of important routines.
399 * We start with the check functions that can validate input
400 * in terms of pressure p, temperature T and composition x.
401 */
403
406 bool checkT(double T, double p, double x);
407
409
415 bool checkP(double T, double p, double x);
416
417 public:
419
422 bool checkX(double x);
423
425 bool checkTPX(double T, double p, double x) {
426 return (checkT(T, p, x) && checkP(T, p, x) && checkX(x));
427 };
428};
429
430} /* namespace CoolProp */
431#endif /* INCOMPRESSIBLEFLUID_H_ */