CoolProp  4.2.5
An open-source fluid property and humid air property database
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IncompBase.cpp
Go to the documentation of this file.
1 
2 #include <string>
3 #include <vector>
4 #include <math.h>
5 #include <stdio.h>
6 #include "CoolPropTools.h"
7 #include "CPExceptions.h"
8 #include "IncompBase.h"
9 #include "IncompLiquid.h"
10 #include "IncompSolution.h"
11 
12 
14 
16 bool IncompressibleClass::checkCoefficients(std::vector<double> const& coefficients, unsigned int n){
17  if (coefficients.size() == n){
18  return true;
19  } else {
20  throw ValueError(format("The number of coefficients %d does not match with %d. ",coefficients.size(),n));
21  }
22  return false;
23 }
24 
25 bool IncompressibleClass::checkCoefficients(std::vector< std::vector<double> > const& coefficients, unsigned int rows, unsigned int columns){
26  if (coefficients.size() == rows){
27  bool result = true;
28  for(unsigned int i=0; i<rows; i++) {
29  result = result && checkCoefficients(coefficients[i],columns);
30  }
31  return result;
32  } else {
33  throw ValueError(format("The number of rows %d does not match with %d. ",coefficients.size(),rows));
34  }
35  return false;
36 }
37 
38 
48 
52 double IncompressibleClass::simplePolynomial(std::vector<double> const& coefficients, double T){
53  if (this->DEBUG) {
54  std::cout << "Running simplePolynomial(std::vector, " << T << "): ";
55  }
56  bool db = this->DEBUG;
57  this->DEBUG = false;
58  double result = 0.;
59  for(unsigned int i=0; i<coefficients.size();i++) {
60  result += coefficients[i] * pow(T,(int)i);
61  }
62  this->DEBUG = db;
63  if (this->DEBUG) {
64  std::cout << result << std::endl;
65  }
66  return result;
67 }
68 double IncompressibleClass::simplePolynomial(std::vector<std::vector<double> > const& coefficients, double x, double T){
69  if (this->DEBUG) {
70  std::cout << "Running simplePolynomial(std::vector, " << x << ", " << T << "): ";
71  }
72  bool db = this->DEBUG;
73  this->DEBUG = false;
74  double result = 0;
75  for(unsigned int i=0; i<coefficients.size();i++) {
76  result += pow(x,(int)i) * simplePolynomial(coefficients[i], T);
77  }
78  this->DEBUG = db;
79  if (this->DEBUG) {
80  std::cout << result << std::endl;
81  }
82  return result;
83 }
84 
86 
90 double IncompressibleClass::simplePolynomialInt(std::vector<double> const& coefficients, double T){
92  if (this->DEBUG) {
93  std::cout << "Running simplePolynomialInt(std::vector, " << T << "): ";
94  }
95  bool db = this->DEBUG;
96  this->DEBUG = false;
97  double result = 0.;
98  for(unsigned int i=0; i<coefficients.size();i++) {
99  result += 1./(i+1.) * coefficients[i] * pow(T,(int)(i+1.));
100  }
101  this->DEBUG = db;
102  if (this->DEBUG) {
103  std::cout << result << std::endl;
104  }
105  return result;
106 }
108 double IncompressibleClass::simplePolynomialInt(std::vector<double> const& coefficients, double T1, double T0){
109  if (this->DEBUG) {
110  std::cout << "Running simplePolynomialInt(std::vector, " << T1 << ", " << T0 << "): ";
111  }
112  bool db = this->DEBUG;
113  this->DEBUG = false;
114  double result = 0.;
115  for(unsigned int i=0; i<coefficients.size();i++) {
116  result += 1./(i+1.) * coefficients[i] * ( pow(T1,(int)(i+1.)) - pow(T0,(int)(i+1.)) );
117  }
118  this->DEBUG = db;
119  if (this->DEBUG) {
120  std::cout << result << std::endl;
121  }
122  return result;
123 }
125 double IncompressibleClass::simplePolynomialInt(std::vector<std::vector<double> > const& coefficients, double x, double T){
126  if (this->DEBUG) {
127  std::cout << "Running simplePolynomialInt(std::vector, " << x << ", " << T << "): ";
128  }
129  bool db = this->DEBUG;
130  this->DEBUG = false;
131  double result = 0.;
132  for(unsigned int i=0; i<coefficients.size();i++) {
133  result += pow(x,(int)i) * simplePolynomialInt(coefficients[i], T);
134  }
135  this->DEBUG = db;
136  if (this->DEBUG) {
137  std::cout << result << std::endl;
138  }
139  return result;
140 }
142 double IncompressibleClass::simplePolynomialInt(std::vector<std::vector<double> > const& coefficients, double x, double T1, double T0){
143  if (this->DEBUG) {
144  std::cout << "Running simplePolynomialInt(std::vector, " << x << ", " << T1 << ", " << T0 << "): ";
145  }
146  bool db = this->DEBUG;
147  this->DEBUG = false;
148  double result = 0.;
149  for(unsigned int i=0; i<coefficients.size();i++) {
150  result += pow(x,(int)i) * simplePolynomialInt(coefficients[i], T1, T0);
151  }
152  this->DEBUG = db;
153  if (this->DEBUG) {
154  std::cout << result << std::endl;
155  }
156  return result;
157 }
158 
160 
164 double IncompressibleClass::simpleFracInt(std::vector<double> const& coefficients, double T){
165  if (this->DEBUG) {
166  std::cout << "Running simpleFracInt(std::vector, " << T << "): ";
167  }
168  double result = coefficients[0] * log(T);
169  if (coefficients.size() > 1) {
170  for (unsigned int i=1; i<coefficients.size(); i++){
171  result += 1./(i) * coefficients[i] * pow(T,(int)(i));
172  }
173  }
174  if (this->DEBUG) {
175  std::cout << result << std::endl;
176  }
177  return result;
178 }
179 double IncompressibleClass::simpleFracInt(std::vector<double> const& coefficients, double T1, double T0){
180  if (this->DEBUG) {
181  std::cout << "Running simpleFracInt(std::vector, " << T1 << ", " << T0 << "): ";
182  }
183  double result = coefficients[0] * log(T1/T0);
184  if (coefficients.size() > 1) {
185  for (unsigned int i=1; i<coefficients.size(); i++){
186  result += 1./(i) * coefficients[i] * (pow(T1,(int)(i))-pow(T0,(int)(i)));
187  }
188  }
189  if (this->DEBUG) {
190  std::cout << result << std::endl;
191  }
192  return result;
193 }
194 double IncompressibleClass::simpleFracInt(std::vector< std::vector<double> > const& coefficients, double x, double T){
195  if (this->DEBUG) {
196  std::cout << "Running simpleFracInt(std::vector, " << x << ", " << T << "): ";
197  }
198  bool db = this->DEBUG;
199  this->DEBUG = false;
200  double result = 0;
201  for (unsigned int i=0; i<coefficients.size(); i++){
202  result += pow(x,(int)i) * polyfracint(coefficients[i],T);
203  }
204  this->DEBUG = db;
205  if (this->DEBUG) {
206  std::cout << result << std::endl;
207  }
208  return result;
209 }
210 double IncompressibleClass::simpleFracInt(std::vector< std::vector<double> > const& coefficients, double x, double T1, double T0){
211  if (this->DEBUG) {
212  std::cout << "Running simpleFracInt(std::vector, " << x << ", " << T1 << ", " << T0 <<"): ";
213  }
214  bool db = this->DEBUG;
215  this->DEBUG = false;
216  double result = 0;
217  for (unsigned int i=0; i<coefficients.size(); i++){
218  result += pow(x,(int)i) * polyfracint(coefficients[i],T1,T0);
219  }
220  this->DEBUG = db;
221  if (this->DEBUG) {
222  std::cout << result << std::endl;
223  }
224  return result;
225 }
226 
227 
236 //double IncompressibleClass::factorial(double nValue){
238 // double result = nValue;
239 // double result_next;
240 // double pc = nValue;
241 // do {
242 // result_next = result*(pc-1);
243 // result = result_next;
244 // pc--;
245 // } while(pc>2);
246 // nValue = result;
247 // return nValue;
248 //}
249 //double IncompressibleClass::factorial(double nValue){
250 // if (nValue == 0) return (1);
251 // else return (nValue * factorial(nValue - 1));
252 //}
253 double IncompressibleClass::factorial(double nValue){
254  double value = 1;
255  for(int i = 2; i <= nValue; i++){
256  value = value * i;
257  }
258  return value;
259 }
260 double IncompressibleClass::binom(double nValue, double nValue2){
261  double result;
262  if(nValue2 == 1) return nValue;
263  result = (factorial(nValue)) / (factorial(nValue2)*factorial((nValue - nValue2)));
264  nValue2 = result;
265  return nValue2;
266 }
268 std::vector<double> IncompressibleClass::fracIntCentralDvector(int m, double T, double Tbase){
269  std::vector<double> D;
270  double tmp;
271  if (m<1) throw ValueError(format("You have to provide coefficients, a vector length of %d is not a valid. ",m));
272  for (int j=0; j<m; j++){ // loop through row
273  tmp = pow(-1.0,j) * log(T) * pow(Tbase,(int)j);
274  for(int k=0; k<j; k++) { // internal loop for every entry
275  tmp += binom(j,k) * pow(-1.0,k) / (j-k) * pow(T,j-k) * pow(Tbase,k);
276  }
277  D.push_back(tmp);
278  }
279  return D;
280 }
281 std::vector<double> IncompressibleClass::fracIntCentralDvector(int m, double T1, double T0, double Tbase){
282  std::vector<double> D;
283  double tmp;
284  if (m<1) throw ValueError(format("You have to provide coefficients, a vector length of %d is not a valid. ",m));
285  for (int j=0; j<m; j++){ // loop through row
286  tmp = pow(-1.0,(int)j) * log(T1/T0) * pow(Tbase,(double)j);
287  for(int k=0; k<j; k++) { // internal loop for every entry
288  tmp += binom(j,k) * pow(-1.0,(int)k) / (j-k) * (pow(T1,(int)(j-k))-pow(T0,(int)(j-k))) * pow(Tbase,(int)k);
289  }
290  D.push_back(tmp);
291  }
292  return D;
293 }
295 double IncompressibleClass::fracIntCentral(std::vector<double> const& coefficients, double T, double Tbase){
296  if (this->DEBUG) {
297  std::cout << "Running fracIntCentral(std::vector, " << T << ", " << Tbase << "): ";
298  }
299  bool db = this->DEBUG;
300  this->DEBUG = false;
301  int m = coefficients.size();
302  std::vector<double> D = fracIntCentralDvector(m, T, Tbase);
303  double result = 0;
304  for(int j=0; j<m; j++) {
305  result += coefficients[j] * D[j];
306  }
307  this->DEBUG = db;
308  if (this->DEBUG) {
309  std::cout << result << std::endl;
310  }
311  return result;
312 }
314 double IncompressibleClass::fracIntCentral(std::vector<double> const& coefficients, double T1, double T0, double Tbase){
315  if (this->DEBUG) {
316  std::cout << "Running fracIntCentral(std::vector, " << T1 << ", " << T0 << ", " << Tbase << "): ";
317  }
318  bool db = this->DEBUG;
319  this->DEBUG = false;
320  int m = coefficients.size();
321  std::vector<double> D = fracIntCentralDvector(m, T1, T0, Tbase);
322  double result = 0;
323  for(int j=0; j<m; j++) {
324  result += coefficients[j] * D[j];
325  }
326  this->DEBUG = db;
327  if (this->DEBUG) {
328  std::cout << result << std::endl;
329  }
330  return result;
331 }
332 
334 
338 double IncompressibleClass::baseHorner(std::vector<double> const& coefficients, double T){
339  if (this->DEBUG) {
340  std::cout << "Running baseHorner(std::vector, " << T << "): ";
341  }
342  double result = 0;
343  for(int i=coefficients.size()-1; i>=0; i--) {
344  result *= T;
345  result += coefficients[i];
346  }
347  if (this->DEBUG) {
348  std::cout << result << std::endl;
349  }
350  return result;
351 }
352 double IncompressibleClass::baseHorner(std::vector< std::vector<double> > const& coefficients, double x, double T){
353  if (this->DEBUG) {
354  std::cout << "Running baseHorner(std::vector, " << x << ", " << T << "): ";
355  }
356  bool db = this->DEBUG;
357  this->DEBUG = false;
358  double result = 0;
359  for(int i=coefficients.size()-1; i>=0; i--) {
360  result *= x;
361  result += baseHorner(coefficients[i], T);
362  }
363  this->DEBUG = db;
364  if (this->DEBUG) {
365  std::cout << result << std::endl;
366  }
367  return result;
368 }
370 double IncompressibleClass::baseHornerInt(std::vector<double> const& coefficients, double T){
371  if (this->DEBUG) {
372  std::cout << "Running baseHornerInt(std::vector, " << T << "): ";
373  }
374  double result = 0;
375  for(int i=coefficients.size()-1; i>=0; i--) {
376  result *= T;
377  result += coefficients[i]/(i+1.);
378  }
379  result = result * T;
380  if (this->DEBUG) {
381  std::cout << result << std::endl;
382  }
383  return result;
384 }
386 double IncompressibleClass::baseHornerInt(std::vector<double> const& coefficients, double T1, double T0){
387  if (this->DEBUG) {
388  std::cout << "Running baseHornerInt(std::vector, " << T1 << ", " << T0 << "): ";
389  }
390  bool db = this->DEBUG;
391  this->DEBUG = false;
392 
393  double result1 = 0;
394  double result0 = 0;
395  for(int i=coefficients.size()-1; i>=0; i--) {
396  result1 *= T1;
397  result1 += coefficients[i]/(i+1.);
398  result0 *= T0;
399  result0 += coefficients[i]/(i+1.);
400  }
401  result1 *= T1;
402  result0 *= T0;
403 
404  result1 -= result0;
405 
406  this->DEBUG = db;
407  if (this->DEBUG) {
408  std::cout << result1 << std::endl;
409  }
410  return result1;
411 }
413 double IncompressibleClass::baseHornerInt(std::vector<std::vector<double> > const& coefficients, double x, double T){
414  if (this->DEBUG) {
415  std::cout << "Running baseHornerInt(std::vector, " << x << ", " << T << "): ";
416  }
417  bool db = this->DEBUG;
418  this->DEBUG = false;
419  double result = 0;
420  for(int i=coefficients.size()-1; i>=0; i--) {
421  result *= x;
422  result += baseHornerInt(coefficients[i], T);
423  }
424  this->DEBUG = db;
425  if (this->DEBUG) {
426  std::cout << result << std::endl;
427  }
428  return result;
429 }
431 double IncompressibleClass::baseHornerInt(std::vector<std::vector<double> > const& coefficients, double x, double T1, double T0){
432  if (this->DEBUG) {
433  std::cout << "Running baseHornerInt(std::vector, " << x << ", " << T1 << ", " << T0 << "): ";
434  }
435  bool db = this->DEBUG;
436  this->DEBUG = false;
437  double result = 0;
438  for(int i=coefficients.size()-1; i>=0; i--) {
439  result *= x;
440  result += baseHornerInt(coefficients[i], T1, T0);
441  }
442  this->DEBUG = db;
443  if (this->DEBUG) {
444  std::cout << result << std::endl;
445  }
446  return result;
447 }
449 //double IncompressibleClass::baseHornerFra(std::vector<double> const& coefficients, double T);
451 //double IncompressibleClass::baseHornerFra(std::vector<double> const& coefficients, double T1, double T0);
453 //double IncompressibleClass::baseHornerFra(std::vector<std::vector<double> > const& coefficients, double x, double T);
455 //double IncompressibleClass::baseHornerFra(std::vector<std::vector<double> > const& coefficients, double x, double T1, double T0);
456 
458 double IncompressibleClass::baseHornerFra(std::vector<double> const& coefficients, double T){
459  if (this->DEBUG) {
460  std::cout << "Running baseHornerFra(std::vector, " << T << "): ";
461  }
462  bool db = this->DEBUG;
463  this->DEBUG = false;
464  double result = 0;
465  if (coefficients.size() > 1) {
466  for(int i=coefficients.size()-1; i>=1; i--) {
467  result *= T;
468  result += coefficients[i]/(i);
469  }
470  result *= T;
471  }
472  result += coefficients[0] * log(T);
473  this->DEBUG = db;
474  if (this->DEBUG) {
475  std::cout << result << std::endl;
476  }
477  return result;
478 }
480 double IncompressibleClass::baseHornerFra(std::vector<double> const& coefficients, double T1, double T0){
481  if (this->DEBUG) {
482  std::cout << "Running baseHornerFra(std::vector, " << T1 << ", " << T0 << "): ";
483  }
484  bool db = this->DEBUG;
485  this->DEBUG = false;
486 
487  double result = 0;
488  if (coefficients.size() > 1) {
489  double result0 = 0;
490  for(int i=coefficients.size()-1; i>=1; i--) {
491  result *= T1;
492  result += coefficients[i]/(i);
493  result0 *= T0;
494  result0 += coefficients[i]/(i);
495  }
496  result *= T1;
497  result0 *= T0;
498  result -= result0;
499  }
500  result += coefficients[0] * log(T1/T0);
501  this->DEBUG = db;
502  if (this->DEBUG) {
503  std::cout << result << std::endl;
504  }
505  return result;
506 }
508 double IncompressibleClass::baseHornerFra(std::vector<std::vector<double> > const& coefficients, double x, double T){
509  if (this->DEBUG) {
510  std::cout << "Running baseHornerFra(std::vector, " << x << ", " << T << "): ";
511  }
512  bool db = this->DEBUG;
513  this->DEBUG = false;
514 
515  double result = 0;
516  for(int i=coefficients.size()-1; i>=0; i--) {
517  result *= x;
518  result += baseHornerFra(coefficients[i], T);
519  }
520 
521  this->DEBUG = db;
522  if (this->DEBUG) {
523  std::cout << result << std::endl;
524  }
525  return result;
526 }
528 double IncompressibleClass::baseHornerFra(std::vector<std::vector<double> > const& coefficients, double x, double T1, double T0){
529  if (this->DEBUG) {
530  std::cout << "Running baseHornerFra(std::vector, " << x << ", " << T1 << ", " << T0 << "): ";
531  }
532  bool db = this->DEBUG;
533  this->DEBUG = false;
534 
535  double result = 0;
536  for(int i=coefficients.size()-1; i>=0; i--) {
537  result *= x;
538  result += baseHornerFra(coefficients[i], T1, T0);
539  }
540 
541  this->DEBUG = db;
542  if (this->DEBUG) {
543  std::cout << result << std::endl;
544  }
545  return result;
546 }
547 
548 
549 
554 std::vector<double> IncompressibleClass::integrateCoeffs(std::vector<double> const& coefficients){
555  std::vector<double> newCoefficients;
556  unsigned int sizeX = coefficients.size();
557  if (sizeX<1) throw ValueError(format("You have to provide coefficients, a vector length of %d is not a valid. ",sizeX));
558  // pushing a zero elevates the order by 1
559  newCoefficients.push_back(0.0);
560  for(unsigned int i=0; i<coefficients.size(); i++) {
561  newCoefficients.push_back(coefficients[i]/(i+1.));
562  }
563  return newCoefficients;
564 }
565 
567 std::vector< std::vector<double> > IncompressibleClass::integrateCoeffs(std::vector< std::vector<double> > const& coefficients, bool axis){
568  std::vector< std::vector<double> > newCoefficients;
569  unsigned int sizeX = coefficients.size();
570  if (sizeX<1) throw ValueError(format("You have to provide coefficients, a vector length of %d is not a valid. ",sizeX));
571 
572  if (axis==true){
573  std::vector< std::vector<double> > tmpCoefficients;
574  tmpCoefficients = transpose(coefficients);
575  unsigned int sizeY = tmpCoefficients.size();
576  for(unsigned int i=0; i<sizeY; i++) {
577  newCoefficients.push_back(integrateCoeffs(tmpCoefficients[i]));
578  }
579  return transpose(newCoefficients);
580  } else if (axis==false){
581  for(unsigned int i=0; i<sizeX; i++) {
582  newCoefficients.push_back(integrateCoeffs(coefficients[i]));
583  }
584  return newCoefficients;
585  } else {
586  throw ValueError(format("You can only use x-axis (0) and y-axis (1) for integration. %d is not a valid input. ",axis));
587  }
588  return newCoefficients;
589 }
590 
594 std::vector<double> IncompressibleClass::deriveCoeffs(std::vector<double> const& coefficients){
595  std::vector<double> newCoefficients;
596  unsigned int sizeX = coefficients.size();
597  if (sizeX<1) throw ValueError(format("You have to provide coefficients, a vector length of %d is not a valid. ",sizeX));
598  // skipping the first element lowers the order
599  for(unsigned int i=1; i<coefficients.size(); i++) {
600  newCoefficients.push_back(coefficients[i]*i);
601  }
602  return newCoefficients;
603 }
604 
605 //std::vector< std::vector<double> > IncompressibleClass::deriveCoeffs(std::vector< std::vector<double> > coefficients, unsigned int axis){
606 // std::vector< std::vector<double> > newCoefficients;
607 // unsigned int sizeX = coefficients.size();
608 // if (sizeX<1) throw ValueError(format("You have to provide coefficients, a vector length of %d is not a valid. ",sizeX));
609 //
610 // if (axis==0){
611 // std::vector< std::vector<double> > tmpCoefficients;
612 // tmpCoefficients = transpose(coefficients);
613 // unsigned int sizeY = tmpCoefficients.size();
614 // for(unsigned int i=0; i<sizeY; i++) {
615 // newCoefficients.push_back(deriveCoeffs(tmpCoefficients[i]));
616 // }
617 // return transpose(newCoefficients);
618 // } else if (axis==1){
619 // for(unsigned int i=0; i<sizeX; i++) {
620 // newCoefficients.push_back(deriveCoeffs(coefficients[i]));
621 // }
622 // return newCoefficients;
623 // } else {
624 // throw ValueError(format("You can only use x-axis (0) and y-axis (1) for derivation. %d is not a valid input. ",axis));
625 // }
626 // return newCoefficients;
627 //}
628 
629 
635 double IncompressibleClass::integrateIn2Steps(std::vector<double> const& coefficients, double T){
637  if (this->DEBUG) {
638  std::cout << "Running integrateIn2Steps(std::vector, " << T << "): ";
639  }
640  bool db = this->DEBUG;
641  this->DEBUG = false;
642  double result = polyval(integrateCoeffs(coefficients),T);
643  this->DEBUG = db;
644  if (this->DEBUG) {
645  std::cout << result << std::endl;
646  }
647  return result;
648 }
650 double IncompressibleClass::integrateIn2Steps(std::vector<double> const& coefficients, double T1, double T0){
651  if (this->DEBUG) {
652  std::cout << "Running integrateIn2Steps(std::vector, " << T1 << ", " << T0 << "): ";
653  }
654  bool db = this->DEBUG;
655  this->DEBUG = false;
656  std::vector<double> coefficientsInt(integrateCoeffs(coefficients));
657  double result = polyval(coefficientsInt,T1)-polyval(coefficientsInt,T0);
658  this->DEBUG = db;
659  if (this->DEBUG) {
660  std::cout << result << std::endl;
661  }
662  return result;
663 }
665 double IncompressibleClass::integrateIn2Steps(std::vector< std::vector<double> > const& coefficients, double x, double T, bool axis){
666  if (this->DEBUG) {
667  std::cout << "Running integrateIn2Steps(std::vector, " << x << ", " << T << "): ";
668  }
669  bool db = this->DEBUG;
670  this->DEBUG = false;
671  double result = polyval(integrateCoeffs(coefficients,axis),x,T);
672  this->DEBUG = db;
673  if (this->DEBUG) {
674  std::cout << result << std::endl;
675  }
676  return result;
677 }
679 double IncompressibleClass::integrateIn2Steps(std::vector< std::vector<double> > const& coefficients, double x, double T1, double T0){
680  if (this->DEBUG) {
681  std::cout << "Running integrateIn2Steps(std::vector, " << x << ", " << T1 << ", " << T0 << "): ";
682  }
683  bool db = this->DEBUG;
684  this->DEBUG = false;
685  std::vector< std::vector<double> > coefficientsInt(integrateCoeffs(coefficients,false));
686  double result = polyval(coefficientsInt,x,T1)-polyval(coefficientsInt,x,T0);
687  this->DEBUG = db;
688  if (this->DEBUG) {
689  std::cout << result << std::endl;
690  }
691  return result;
692 }
694 double IncompressibleClass::fracIntIn2Steps(std::vector<double> const& coefficients, double T){
695  if (this->DEBUG) {
696  std::cout << "Running fracIntIn2Steps(std::vector, " << T << "): ";
697  }
698  bool db = this->DEBUG;
699  this->DEBUG = false;
700  double result = coefficients[0] * log(T);
701  if (coefficients.size() > 1) {
702  std::vector<double> newCoeffs(coefficients.begin() + 1, coefficients.end());
703  result += polyint(newCoeffs,T);
704  }
705  this->DEBUG = db;
706  if (this->DEBUG) {
707  std::cout << result << std::endl;
708  }
709  return result;
710 }
712 double IncompressibleClass::fracIntIn2Steps(std::vector<double> const& coefficients, double T1, double T0){
713  if (this->DEBUG) {
714  std::cout << "Running fracIntIn2Steps(std::vector, " << T1 << ", " << T0 << "): ";
715  }
716  bool db = this->DEBUG;
717  this->DEBUG = false;
718  double result = coefficients[0] * log(T1/T0);
719  if (coefficients.size() > 1) {
720  std::vector<double> newCoeffs(coefficients.begin() + 1, coefficients.end());
721  result += polyint(newCoeffs,T1,T0);
722  }
723  this->DEBUG = db;
724  if (this->DEBUG) {
725  std::cout << result << std::endl;
726  }
727  return result;
728 }
730 double IncompressibleClass::fracIntIn2Steps(std::vector<std::vector<double> > const& coefficients, double x, double T){
731  if (this->DEBUG) {
732  std::cout << "Running fracIntIn2Steps(std::vector, " << x << ", " << T << "): ";
733  }
734  bool db = this->DEBUG;
735  this->DEBUG = false;
736  std::vector<double> newCoeffs;
737  for (unsigned int i=0; i<coefficients.size(); i++){
738  newCoeffs.push_back(polyfracint(coefficients[i],T));
739  }
740  double result = polyval(newCoeffs,x);
741  this->DEBUG = db;
742  if (this->DEBUG) {
743  std::cout << result << std::endl;
744  }
745  return result;
746 }
748 double IncompressibleClass::fracIntIn2Steps(std::vector<std::vector<double> > const& coefficients, double x, double T1, double T0){
749  if (this->DEBUG) {
750  std::cout << "Running fracIntIn2Steps(std::vector, " << x << ", " << T1 << ", " << T0 << "): ";
751  }
752  bool db = this->DEBUG;
753  this->DEBUG = false;
754  std::vector<double> newCoeffs;
755  for (unsigned int i=0; i<coefficients.size(); i++){
756  newCoeffs.push_back(polyfracint(coefficients[i],T1,T0));
757  }
758  double result = polyval(newCoeffs,x);
759  this->DEBUG = db;
760  if (this->DEBUG) {
761  std::cout << result << std::endl;
762  }
763  return result;
764 }
765 
766 double IncompressibleClass::fracIntCentral2Steps(std::vector<std::vector<double> > const& coefficients, double x, double T, double Tbase){
767  if (this->DEBUG) {
768  std::cout << "Running fracIntCentral2Steps(std::vector, " << x << ", " << T << ", " << Tbase << "): ";
769  }
770  bool db = this->DEBUG;
771  this->DEBUG = false;
772  std::vector<double> newCoeffs;
773  for (unsigned int i=0; i<coefficients.size(); i++){
774  newCoeffs.push_back(fracIntCentral(coefficients[i], T, Tbase));
775  }
776  double result = polyval(newCoeffs,x);
777  this->DEBUG = db;
778  if (this->DEBUG) {
779  std::cout << result << std::endl;
780  }
781  return result;
782 }
784 double IncompressibleClass::fracIntCentral2Steps(std::vector<std::vector<double> > const& coefficients, double x, double T1, double T0, double Tbase){
785  if (this->DEBUG) {
786  std::cout << "Running fracIntCentral2Steps(std::vector, " << x << ", " << T1 << ", " << T0 << ", " << Tbase << "): ";
787  }
788  bool db = this->DEBUG;
789  this->DEBUG = false;
790  std::vector<double> newCoeffs;
791  for (unsigned int i=0; i<coefficients.size(); i++){
792  newCoeffs.push_back(fracIntCentral(coefficients[i], T1, T0, Tbase));
793  }
794  double result = polyval(newCoeffs,x);
795  this->DEBUG = db;
796  if (this->DEBUG) {
797  std::cout << result << std::endl;
798  }
799  return result;
800 }
801 
802 
808 double IncompressibleClass::expval(std::vector<double> const& coefficients, double T, int n){
813  double result = 0.;
814  if (n==1) {
815  checkCoefficients(coefficients,3);
816  result = exp(coefficients[0]/(T+coefficients[1]) - coefficients[2]);
817  } else if (n==2) {
818  result = exp(polyval(coefficients, T));
819  } else {
820  throw ValueError(format("There is no function defined for this input (%d). ",n));
821  }
822  return result;
823 }
824 
830 double IncompressibleClass::expval(std::vector< std::vector<double> > const& coefficients, double x, double T, int n){
831  double result = 0.;
832  if (n==2) {
833  result = exp(polyval(coefficients, x, T));
834  } else {
835  throw ValueError(format("There is no function defined for this input (%d). ",n));
836  }
837  return result;
838 }
839 
840 
841 //int main() {
842 //
843 // SimpleIncompressible* liquid = new DowthermQClass();
844 // double AT = 150.0 + 273.15;
845 // double Ap = 3e5;
846 // liquid->testInputs(AT,Ap);
847 //
848 //
849 // SecCoolSolution* obj = new MethanolSolution();
850 // double x = 0.25;
851 // double T = 5.0 + 273.15;
852 // double p = 3e5;
853 //
854 // obj->testInputs(T+00,p,x);
855 // obj->testInputs(T+05,p,x);
856 // obj->testInputs(T+10,p,x);
857 // obj->testInputs(T+15,p,x);
858 //
859 //
860 //}
std::vector< std::vector< double > > transpose(std::vector< std::vector< double > > const &in)
Definition: MatrixMath.cpp:330
double polyfracint(std::vector< double > const &coefficients, double T)
Definition: IncompBase.h:267
double polyint(std::vector< double > const &coefficients, double T)
Definition: IncompBase.h:227
std::string format(const char *fmt,...)
std::vector< double > x(ncmax, 0)
double expval(std::vector< double > const &coefficients, double T, int n)
Definition: IncompBase.cpp:812
bool checkCoefficients(std::vector< double > const &coefficients, unsigned int n)
Basic checks for coefficient vectors.
Definition: IncompBase.cpp:16
double polyval(std::vector< double > const &coefficients, double x)
Definition: IncompBase.h:210