CoolProp 6.8.1dev
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
11#include "DataStructures.h"
12#include "Helmholtz.h"
13#include "Solvers.h"
14
15#include <numeric>
16#include <string>
17#include <vector>
18#include <map>
19#include <cassert>
20#include <iterator>
21
22#include <Eigen/Core>
23#include "PolyMath.h"
24#include "MatrixMath.h"
25
26namespace CoolProp {
27
29{
31 {
38 };
40 Eigen::MatrixXd coeffs; //TODO: Can we store the Eigen::Matrix objects more efficiently?
41 //std::vector<std::vector<double> > coeffs;
44 };
45};
46
47#if !defined(NO_FMTLIB) && FMT_VERSION >= 90000
48inline int format_as(IncompressibleData::IncompressibleTypeEnum type) {
49 return fmt::underlying(type);
50}
51#endif
52
54
58{
59
60 protected:
61 bool strict;
62
63 std::string name;
64 std::string description;
65 std::string reference;
66
67 double Tmin, Tmax;
68 double xmin, xmax;
70
71 double TminPsat;
72 double xbase, Tbase;
73
75
85
90
97
102
107
112
116
118
123
128
132
134
135 // Forward declaration of the some internal functions
136 //double h_u(double T, double p, double x);
137 //double u_h(double T, double p, double x);
138
139 public:
140 IncompressibleFluid() : Tmin(_HUGE), Tmax(_HUGE), xmin(_HUGE), xmax(_HUGE), TminPsat(_HUGE), xbase(_HUGE), Tbase(_HUGE) {
141 strict = true;
143 };
145
146 std::string getName() const {
147 return name;
148 }
149 std::string get_name() const {
150 return getName();
151 } // For backwards-compatibility.
152 std::string getDescription() const {
153 return description;
154 }
155 std::string getReference() const {
156 return reference;
157 }
158
159 double getTmax() const {
160 return Tmax;
161 }
162 double getTmin() const {
163 return Tmin;
164 }
165 double getxmax() const {
166 return xmax;
167 }
168 double getxmin() const {
169 return xmin;
170 }
172 return xid;
173 }
174 double getTminPsat() const {
175 return TminPsat;
176 }
177 double getTbase() const {
178 return Tbase;
179 }
180 double getxbase() const {
181 return xbase;
182 }
183
184 void setName(const std::string& name) {
185 this->name = name;
186 }
187 void setDescription(const std::string& description) {
188 this->description = description;
189 }
190 void setReference(const std::string& reference) {
191 this->reference = reference;
192 }
193 void setTmax(double Tmax) {
194 this->Tmax = Tmax;
195 }
196 void setTmin(double Tmin) {
197 this->Tmin = Tmin;
198 }
199 void setxmax(double xmax) {
200 this->xmax = xmax;
201 }
202 void setxmin(double xmin) {
203 this->xmin = xmin;
204 }
206 this->xid = xid;
207 }
208 void setTminPsat(double TminPsat) {
209 this->TminPsat = TminPsat;
210 }
211 void setTbase(double Tbase) {
212 this->Tbase = Tbase;
213 }
214 void setxbase(double xbase) {
215 this->xbase = xbase;
216 }
217
220 this->density = density;
221 }
223 this->specific_heat = specific_heat;
224 }
226 this->viscosity = viscosity;
227 }
229 this->conductivity = conductivity;
230 }
232 this->p_sat = p_sat;
233 }
235 this->T_freeze = T_freeze;
236 }
237
240 this->mass2input = mass2input;
241 }
243 this->volume2input = volume2input;
244 }
246 this->mole2input = mole2input;
247 }
248
250 void validate();
252 bool is_pure();
253
254 protected:
256 double baseExponential(IncompressibleData data, double y, double ybase);
257 double baseLogexponential(IncompressibleData data, double y, double ybase);
259 double basePolyOffset(IncompressibleData data, double y, double z = 0.0);
260
261 public:
262 /* All functions need T and p as input. Might not
263 * be necessary, but gives a clearer structure.
264 */
266 double rho(double T, double p, double x);
268 double c(double T, double p, double x);
269 double cp(double T, double p, double x) {
270 throw ValueError(format("%s (%d): Please use the c-function instead.", __FILE__, __LINE__));
271 }
272 double cv(double T, double p, double x) {
273 throw ValueError(format("%s (%d): Please use the c-function instead.", __FILE__, __LINE__));
274 }
276 double s(double T, double p, double x) {
277 throw ValueError(format("%s (%d): The internal calculations have changed, use the backend to calculate entropy from the partial derivatives.",
278 __FILE__, __LINE__));
279 }
281 double u(double T, double p, double x) {
282 throw ValueError(
283 format("%s (%d): The internal calculations have changed, use the backend to calculate internal energy from enthalpy.", __FILE__, __LINE__));
284 }
286 double h(double T, double p, double x) {
287 throw ValueError(
288 format("%s (%d): The internal calculations have changed, use the backend to calculate enthalpy from the partial derivatives.", __FILE__,
289 __LINE__));
290 }
292 double visc(double T, double p, double x);
294 double cond(double T, double p, double x);
296 double psat(double T, double x);
298 double Tfreeze(double p, double x);
299
300 /* Below are direct calculations of the derivatives. Nothing
301 * special is going on, we simply use the polynomial class to
302 * derive the different functions with respect to temperature.
303 */
305 // with respect to temperature at constant pressure and composition
306 double drhodTatPx(double T, double p, double x);
309 //double dsdTatPx (double T, double p, double x){return c(T,p,x)/T;};
312 //double dhdTatPx (double T, double p, double x){return c(T,p,x);};
314 // with respect to temperature at constant pressure and composition
315 // integrated in temperature
316 double dsdTatPxdT(double T, double p, double x);
318 // with respect to temperature at constant pressure and composition
319 // integrated in temperature
320 double dhdTatPxdT(double T, double p, double x);
321
323
325 double inputFromMass(double T, double x);
327
329 double inputFromVolume(double T, double x);
331
333 double inputFromMole(double T, double x);
334
335 /* Some functions can be inverted directly, those are listed
336 * here. It is also possible to solve for other quantities, but
337 * that involves some more sophisticated processing and is not
338 * done here, but in the backend, T(h,p) for example.
339 */
341 double T_rho(double Dmass, double p, double x);
343 double T_c(double Cmass, double p, double x);
345 double T_s(double Smass, double p, double x) {
346 throw NotImplementedError(format("%s (%d): T from entropy is not implemented in the fluid, use the backend.", __FILE__, __LINE__));
347 }
349 double T_u(double Umass, double p, double x) {
350 throw NotImplementedError(format("%s (%d): T from internal energy is not implemented in the fluid, use the backend.", __FILE__, __LINE__));
351 }
353 double T_h(double Hmass, double p, double x) {
354 throw NotImplementedError(format("%s (%d): T from enthalpy is not implemented in the fluid, use the backend.", __FILE__, __LINE__));
355 }
357 double T_visc(double visc, double p, double x) {
358 throw NotImplementedError(format("%s (%d): T from viscosity is not implemented.", __FILE__, __LINE__));
359 }
361 double T_cond(double cond, double p, double x) {
362 throw NotImplementedError(format("%s (%d): T from conductivity is not implemented.", __FILE__, __LINE__));
363 }
365 double T_psat(double psat, double x) {
366 throw NotImplementedError(format("%s (%d): T from psat is not implemented.", __FILE__, __LINE__));
367 }
369 double x_Tfreeze(double Tfreeze, double p) {
370 throw NotImplementedError(format("%s (%d): x from T_freeze is not implemented.", __FILE__, __LINE__));
371 }
372
373 protected:
374 /* Define internal energy and enthalpy as functions of the
375 * other properties to provide data in case there are no
376 * coefficients.
377 */
379
382 double h_u(double T, double p, double x) {
383 return u(T, p, x) + p / rho(T, p, x);
384 };
385
387
390 double u_h(double T, double p, double x) {
391 return h(T, p, x) - p / rho(T, p, x);
392 };
393
394 /*
395 * Some more functions to provide a single implementation
396 * of important routines.
397 * We start with the check functions that can validate input
398 * in terms of pressure p, temperature T and composition x.
399 */
401
404 bool checkT(double T, double p, double x);
405
407
413 bool checkP(double T, double p, double x);
414
415 public:
417
420 bool checkX(double x);
421
423 bool checkTPX(double T, double p, double x) {
424 return (checkT(T, p, x) && checkP(T, p, x) && checkX(x));
425 };
426};
427
428} /* namespace CoolProp */
429#endif /* INCOMPRESSIBLEFLUID_H_ */