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
CPState.cpp
Go to the documentation of this file.
1 // On PowerPC, we are going to use the stdint.h integer types and not let rapidjson use its own
2 #if defined(__powerpc__)
3 #include "stdint.h"
4 #define RAPIDJSON_NO_INT64DEFINE
5 #endif
6 
7 #include "CPExceptions.h"
8 #include "Solvers.h"
9 #include "CPState.h"
10 #include "float.h"
11 #include "math.h"
12 #include "Spline.h"
13 
14 #ifndef __ISWINDOWS__
15  #ifndef DBL_EPSILON
16  #include <limits>
17  #define DBL_EPSILON std::numeric_limits<double>::epsilon()
18  #endif
19 #endif
20 
21 #include <stdio.h>
22 
23 // TODO Fix duplicate objects
26 
27 // Constructor with fluid name
29 {
30  // If a REFPROP fluid, add the fluid to the list of fluids
31  if (Fluid.find("REFPROP-")==0){
32  add_REFPROP_fluid(Fluid);
34  // Try to get the index of the fluid
35  long iFluid = get_Fluid_index(Fluid);
36  // If iFluid is greater than -1, it is a CoolProp Fluid, otherwise not
37  if (iFluid > -1)
38  {
39  // Get a pointer to the fluid object
40  pFluid = get_fluid(iFluid);
41  }
42  }
43  // If an incompressible liquid, check that
44  else if(IsIncompressibleLiquid(Fluid)){
45  pIncompLiquid = LiquidsList.get_liquid(Fluid);
47  }
48  // If an incompressible solution, check that
49  else if(IsIncompressibleSolution(Fluid)){ // TODO SOLUTION: Check if working
50  pIncompSolution = SolutionsList.get_solution(Fluid);
51  this->brine_string = Fluid;
53  }
54  else
55  {
56  // Try to get the index of the fluid
57  long iFluid = get_Fluid_index(Fluid);
58  // If iFluid is greater than -1, it is a CoolProp Fluid, otherwise not
59  if (iFluid > -1)
60  {
61  // Get a pointer to the fluid object
62  pFluid = get_fluid(iFluid);
63 
64  if (pFluid->pure())
65  {
67  }
68  else
69  {
71  }
72  }
73  else
74  {
75  throw ValueError(format("Bad Fluid name [%s] - not a CoolProp fluid",Fluid.c_str()));
76  }
77  }
78  this->cache.clear();
79 
80  // If flag_SinglePhase is true, it will always assume that it is not in the two-phase region
81  // If flag_TwoPhase is true, it it always assume that you are in the two-phase region
82  // Can be over-written by changing the flag to true
83  flag_SinglePhase = false;
84  flag_TwoPhase = false;
85 
86  SatL = NULL;
87  SatV = NULL;
88  _noSatLSatV = false;
89 }
90 
91 // Constructor with pointer to fluid
93  this->pFluid = pFluid;
94  this->cache.clear();
95 
96  // If flag_SinglePhase is true, it will always assume that it is not in the two-phase region
97  // If flag_TwoPhase is true, it it always assume that you are in the two-phase region
98  // Can be over-written by changing the flag to true
99  flag_SinglePhase = false;
100  flag_TwoPhase = false;
101 
102  SatL = NULL;
103  SatV = NULL;
104  _noSatLSatV = false;
105 
106  if (pFluid->pure())
107  {
109  }
110  else
111  {
113  }
114 }
115 
117 {
118  if (!_noSatLSatV) // We are de-alllocating one of the saturation classes
119  {
120  if (SatL != NULL)
121  {
122  delete SatL;
123  SatL = NULL;
124  }
125  if (SatV != NULL)
126  {
127  delete SatV;
128  SatV = NULL;
129  }
130  }
131 }
132 bool match_pair(long iI1, long iI2, long I1, long I2)
133 {
134  return ((iI1 == I1 || iI1 == I2) && (iI2 == I1 || iI2 == I2) && iI1!=iI2);
135 }
136 void sort_pair(long *iInput1, double *Value1, long *iInput2, double *Value2, long I1, long I2)
137 {
138  if (!(*iInput1 == I1) || !(*iInput2 == I2)){
139  std::swap(*iInput1,*iInput2);
140  std::swap(*Value1,*Value2);
141  }
142 }
143 double CoolPropStateClassSI::Tsat(double Q){
144  double mach_eps = 10*DBL_EPSILON;
145  double rhoL,rhoV, TL, TV;
146 
147  pFluid->saturation_p(_p,false,TL,TV,rhoL,rhoV);
148 
149  if (fabs(Q-1) < mach_eps){
150  return TV;
151  }
152  else if (fabs(Q) < mach_eps){
153  return TL;
154  }
155  else{
156  throw ValueError();
157  }
158 }
160  return _T - Tsat(1.0);
161 }
162 
164  double mach_eps = 10*DBL_EPSILON;
165 
166  if (fabs(Q-1) < mach_eps){
167  SaturatedL = false; SaturatedV = true;
168  }
169  else if (fabs(Q) < mach_eps){
170  SaturatedL = true; SaturatedV = false;
171  }
172  else{
173  SaturatedL = false; SaturatedV = false;
174  }
175 }
176 
178 {
179  // Clear the cached helmholtz energy derivative terms
180  this->cache.clear();
181 
182  // Reset all the internal variables to _HUGE
183  _T = _HUGE;
184  _p = _HUGE;
185  _logp = _HUGE;
186  _h = _HUGE;
187  _s = _HUGE;
188  _rho = _HUGE;
189  _logrho = _HUGE;
190  _Q = _HUGE;
191 
192  // Reset the cached values for _h and _s
193  s_cached = false;
194  h_cached = false;
195 
196  // Only build the Saturation classes if this is a top-level CPState for which no_SatLSatV() has not been called
197  if (!_noSatLSatV){
198  if (SatL == NULL){
200  SatL->no_SatLSatV(); // Kill the recursive building of the saturation classes
201  }
202  if (SatV == NULL){
204  SatV->no_SatLSatV(); // Kill the recursive building of the saturation classes
205  }
206  }
207 
208  // Don't know if it is single phase or not, so assume it isn't
209  SinglePhase = false;
210 }
211 
212 // Main updater function
213 void CoolPropStateClassSI::update(long iInput1, double Value1, long iInput2, double Value2, double T0, double rho0){
214  /* Options for inputs (in either order) are:
215  | T,P
216  | T,D
217  | H,P
218  | S,P
219  | P,Q
220  | T,Q
221  | H,S
222  | P,D
223  | T,S
224  */
225 
226  if (get_debug_level()>3){
227  std::cout << format("%s:%d: CoolPropStateClassSI::update %d,%g,%d,%g,%s",__FILE__,__LINE__,iInput1,Value1,iInput2,Value2,pFluid->get_name().c_str()).c_str() << std::endl;
228  }
229 
230  // Use the liquid or solution updating functions if they are in use
232  {
233  this->update_incompressible(iInput1,Value1,iInput2,Value2);
234  return;
235  }
236 
237  // Common code for all updating functions (set flags, clear cache, etc.)
238  this->_pre_update();
239 
240  // Determine whether the EOS or the TTSE will be used
241  bool using_EOS = true;
242  if (!pFluid->enabled_TTSE_LUT)
243  {
244  using_EOS = true;
245  }
246  else
247  {
248  // Try to build the LUT; Nothing will happen if the tables are already built
250 
251  // If inputs are in range of LUT, use it, otherwise just use the EOS
252  if (within_TTSE_range(iInput1,Value1,iInput2,Value2)){
253  using_EOS = false;
254  }
255  else
256  {
257  using_EOS = true;
258  }
259  }
260 
261  if (using_EOS)
262  {
263 
264  // If the inputs are P,Q or T,Q , it is guaranteed to require a call to the saturation routine
265  if (match_pair(iInput1,iInput2,iP,iQ) || match_pair(iInput1,iInput2,iT,iQ)){
266  update_twophase(iInput1,Value1,iInput2,Value2);
267  }
268  else if (match_pair(iInput1,iInput2,iT,iD)){
269  update_Trho(iInput1,Value1,iInput2,Value2);
270  }
271  else if (match_pair(iInput1,iInput2,iT,iP)){
272  update_Tp(iInput1,Value1,iInput2,Value2);
273  }
274  else if (match_pair(iInput1,iInput2,iP,iH)){
275  update_ph(iInput1,Value1,iInput2,Value2, T0, rho0);
276  }
277  else if (match_pair(iInput1,iInput2,iP,iS)){
278  update_ps(iInput1,Value1,iInput2,Value2);
279  }
280  else if (match_pair(iInput1,iInput2,iP,iD)){
281  update_prho(iInput1,Value1,iInput2,Value2);
282  }
283  else if (match_pair(iInput1,iInput2,iH,iS)){
284  update_hs(iInput1,Value1,iInput2,Value2);
285  }
286  else if (match_pair(iInput1,iInput2,iT,iS)){
287  update_Ts(iInput1,Value1,iInput2,Value2);
288  }
289  else
290  {
291  throw ValueError(format("Sorry your inputs didn't work; valid pairs are P,Q T,Q T,D T,P P,H P,S T,S"));
292  }
293  }
294  else
295  {
296  // Update using the LUT
297  update_TTSE_LUT(iInput1, Value1, iInput2, Value2);
298 
299  // Calculate the log of the pressure since a lot of terms need it and log() is a very slow function
300  if (!ValidNumber(_logp)) _logp = log(_p);
301  if (!ValidNumber(_logrho)) _logrho = log(_rho);
302  }
303 
304  if (get_debug_level()>3){
305  std::cout << format("%s:%d: StateClassSI updated; T = %15.13g rho = %15.13g \n", __FILE__, __LINE__, _T, _rho).c_str();
306  }
307 
308  // Common code for all updating functions
309  this->_post_update();
310 }
311 
313 {
314  if (get_debug_level()>9){ std::cout << format("%s:%d: StateClassSI::_post_update: T=%g rho=%g p=%g s=%g h=%g\n", __FILE__,__LINE__,_T,_rho,_p,_s,_h).c_str(); }
315  if (get_debug_level()>9){ std::cout << format("%s:%d: StateClassSI::_post_update: !_noSatLSatV %d TwoPhase %d !flag_TwoPhase %d\n", __FILE__,__LINE__,!_noSatLSatV, TwoPhase, !flag_TwoPhase).c_str(); }
316 
317 
318  if (!_noSatLSatV && TwoPhase && !flag_TwoPhase)
319  {
320  if (get_debug_level()>5){ std::cout << format("%s Adding saturation states \n", __FILE__).c_str(); }
321  // Update temperature and density for SatL and SatV
323  }
324 
325  // Reduced parameters
326  delta = this->_rho/pFluid->reduce.rho;
327  tau = pFluid->reduce.T/this->_T;
328 }
329 
330 void CoolPropStateClassSI::update_twophase(long iInput1, double Value1, long iInput2, double Value2)
331 {
332  // This function handles setting internal variables when the state is known to be saturated
333  // Either T,Q or P,Q are given
334  double Q;
335 
336  SinglePhase = false;
337  TwoPhase = true;
338 
339  if (iInput1 == iQ){
340  Q = Value1;
341  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iInput2,iQ);
342  }
343  else{
344  Q = Value2;
345  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iInput1,iQ);
346  }
347 
348  // Check whether saturated liquid or vapor
350 
351  if (match_pair(iInput1,iInput2,iP,iQ)){
352  // Sort so they are in the order P, Q
353  sort_pair(&iInput1, &Value1, &iInput2, &Value2, iP, iQ);
354 
355  // Out-of-range checks
356  if (Value1 < pFluid->params.ptriple*0.98 || Value1 > pFluid->crit.p.Pa+100*DBL_EPSILON){ throw ValueError(format("Your saturation pressure [%f Pa] is out of range [%f Pa, %f Pa]",Value1,pFluid->params.ptriple,pFluid->crit.p.Pa ));}
357  if (Value2 > 1+10*DBL_EPSILON || Value2 < -10*DBL_EPSILON){ throw ValueError(format("Your quality [%f] is out of range (0, 1)",Value2 )); }
358 
359  // Carry out the saturation call to get the temperature and density for each phases
360  if (pFluid->pure()){
362  TsatV = TsatL;
363  psatV = Value1;
364  psatL = Value1;
365  }
366  else{
367  TsatL = pFluid->Tsat_anc(Value1,0);
368  TsatV = pFluid->Tsat_anc(Value1,1);
369  psatL = Value1;
370  psatV = Value1;
371  // Saturation densities
374  }
375  }
376  else{
377  // Sort so they are in the order T, Q
378  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iT,iQ);
379 
380  // Pseudo-pure fluids cannot use T,Q as inputs if Q is not 0 or 1
381  if (!pFluid->pure() && !(fabs(Value2) < 10*DBL_EPSILON) && !(fabs(Value2-1) < 10*DBL_EPSILON))
382  {
383  throw ValueError(format("Pseudo-pure fluids cannot use temperature-quality as inputs if Q is not 1 or 0"));
384  }
385 
386  // Out-of-range checks
387  if (Value1 < pFluid->limits.Tmin-10*DBL_EPSILON || Value1 > pFluid->crit.T+10*DBL_EPSILON){ throw ValueError(format("Your saturation temperature [%f K] is out of range [%f K, %f K]",Value1,pFluid->limits.Tmin, pFluid->crit.T ));}
388  if (Value2 > 1+10*DBL_EPSILON || Value2 < -10*DBL_EPSILON){ throw ValueError(format("Your quality [%f] is out of range (0, 1)",Value2 )); }
389 
390  // Carry out the saturation call to get the temperature and density for each phases
391  // for the given temperature
392  if (pFluid->pure()){
394  TsatL = Value1;
395  TsatV = Value1;
396  }
397  else{
398  TsatL = Value1;
399  TsatV = Value1;
400  // Saturation pressures
403 
404  try{
405  // Saturation densities
408  }
409  catch (std::exception &){
410  // Near the critical point, the behavior is not very nice, so we will just use the ancillary near the critical point
413  }
414  }
415  }
416  // Set internal variables
417  _T = Q*TsatV+(1-Q)*TsatL;
418  _rho = 1/(Q/rhosatV+(1-Q)/rhosatL);
419  _p = Q*psatV+(1-Q)*psatL;
420  _Q = Q;
421 }
422 
423 // Updater if T,rho are inputs
424 void CoolPropStateClassSI::update_Trho(long iInput1, double Value1, long iInput2, double Value2)
425 {
426  // Get them in the right order
427  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iT,iD);
428 
429  // Set internal variables
430  _T = Value1;
431  _rho = Value2;
432 
433  if (Value1 < 0 ){ throw ValueError(format("Your temperature [%f K] is less than zero",Value1));}
434  if (Value2 < 0 ){ throw ValueError(format("Your density [%f kg/m^3] is less than zero",Value2));}
435 
436  if (flag_SinglePhase && flag_TwoPhase) throw ValueError(format("Only one of flag_SinglePhase and flag_TwoPhase may be set to true"));
437 
438  // If either SinglePhase or flag_SinglePhase is set to true, it will not make the call to the saturation routine
439  // SinglePhase is set by the class routines, and flag_SinglePhase is a flag that can be set externally
440  bool _TwoPhase;
441 
443  _TwoPhase = false;
444  }
445  else if(flag_TwoPhase){
446  _TwoPhase = true;
447  }
448  else{
449  // Set _TwoPhase to true if the state is two phase
451  }
452 
453  if (_TwoPhase)
454  {
455  if (flag_TwoPhase){
457  }
458  TsatV = _T;
459  TsatL = _T;
460  // If it made it to the saturation routine and it is two-phase the saturation variables have been set
461  TwoPhase = true;
462  SinglePhase = false;
463 
464  // Get the quality and pressure
465  _Q = (1/_rho-1/rhosatL)/(1/rhosatV-1/rhosatL);
466  _p = _Q*psatV+(1-_Q)*psatL;
467 
469  }
470  else{
471  TwoPhase = false;
472  SinglePhase = true;
473  SaturatedL = false;
474  SaturatedV = false;
475 
476  // Reduced parameters
477  double delta = this->_rho/pFluid->reduce.rho;
478  double tau = pFluid->reduce.T/this->_T;
479 
480  // Use the local function for dphir_dDelta to ensure that dphir_dDelta gets cached
481  _p = pFluid->R()*_T*_rho*(1.0 + delta*dphir_dDelta(tau,delta));
482  }
483 }
484 
485 // Updater if p,rho are inputs
486 void CoolPropStateClassSI::update_prho(long iInput1, double Value1, long iInput2, double Value2)
487 {
488  double T0;
489  long phase;
490  // Get them in the right order
491  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iP,iD);
492 
493  // Set internal variables
494  _p = Value1;
495  _rho = Value2;
496 
497  if (_p < 0 ){ throw ValueError(format("Your pressure [%f Pa] is less than zero",Value1));}
498  if (_rho < 0 ){ throw ValueError(format("Your density [%f kg/m^3] is less than zero",Value2));}
499 
500  if (flag_SinglePhase && flag_TwoPhase) throw ValueError(format("Only one of flag_SinglePhase and flag_TwoPhase may be set to true"));
501 
502  // If either SinglePhase or flag_SinglePhase is set to true, it will not make the call to the saturation routine
503  // SinglePhase is set by the class routines, and flag_SinglePhase is a flag that can be set externally
504  bool _TwoPhase;
505 
507  _TwoPhase = false;
508  }
509  else if(flag_TwoPhase){
510  _TwoPhase = true;
511  }
512  else{
514  _TwoPhase = (phase == iTwoPhase);
515  }
516 
517  if (_TwoPhase)
518  {
519  if (flag_TwoPhase){
521  }
522  // If it made it to the saturation routine and it is two-phase the saturation variables have been set
523  TwoPhase = true;
524  SinglePhase = false;
525 
526  // Get the quality and pressure
527  _Q = (1/_rho-1/rhosatL)/(1/rhosatV-1/rhosatL);
528 
530  }
531  else{
532  TwoPhase = false;
533  SinglePhase = true;
534  SaturatedL = false;
535  SaturatedV = false;
536  if (!ValidNumber(_T))
537  {
538  if (phase == iLiquid)
539  {
540  T0 = TsatL;
541  }
542  else
543  {
545  }
546  _T = pFluid->temperature_prho(_p, _rho, T0);
547  }
548  }
549 }
550 
551 // Updater if T,p are inputs
552 void CoolPropStateClassSI::update_Tp(long iInput1, double Value1, long iInput2, double Value2)
553 {
554  // Get them in the right order
555  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iT,iP);
556 
557  if (get_debug_level() > 5)
558  {
559  std::cout << format("%s:%d: CoolPropStateClassSI::update_Tp(%d, %g, %d, %g)\n",__FILE__,__LINE__,iInput1,Value1,iInput2,Value2).c_str();
560  }
561 
562  if (Value1 < 0 ){ throw ValueError(format("Your temperature [%g K] is less than zero",Value1));}
563  if (Value2 < 0 ){ throw ValueError(format("Your pressure [%g Pa] is less than zero",Value2));}
564 
565  // Set internal variables
566  _T = Value1;
567  _p = Value2;
568 
569  // If either SinglePhase or flag_SinglePhase is set to true, it will not make the call to the saturation routine
570  // SinglePhase is set by the class routines, and flag_SinglePhase is a flag that can be set externally
571  bool _TwoPhase;
572 
574  _TwoPhase = false;
575  }
576  else if(flag_TwoPhase){
577  _TwoPhase = true;
578  }
579  else{
581  if (get_debug_level() > 5) { std::cout << format("%s:%d: CoolPropStateClass::update_Tp::_TwoPhase : %d\n",__FILE__,__LINE__,_TwoPhase).c_str(); }
582  }
583 
584  if (_TwoPhase)
585  {
586  throw ValueError(format("TwoPhase is not possible with T,P as inputs"));
587  }
588  else{
589  TwoPhase = false;
590  SinglePhase = true;
591  SaturatedL = false;
592  SaturatedV = false;
593  _rho = pFluid->density_Tp(_T,_p);
594  }
595 }
596 
597 // Updater if p,h are inputs
598 void CoolPropStateClassSI::update_ph(long iInput1, double Value1, long iInput2, double Value2, double T0, double rho0)
599 {
600  // Get them in the right order
601  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iP,iH);
602 
603  if (Value1 < 0 ){ throw ValueError(format("Your pressure [%g Pa] is less than zero",Value1));}
604 
605  // Set internal variables
606  _p = Value1;
607  _h = Value2;
608  h_cached = true;
609 
610  if (get_debug_level() > 8){
611  std::cout << format("%s:%d: CoolPropStateClassSI::update_ph(p=%g,h=%g,T0=%g,rho0=%g)\n",__FILE__,__LINE__, _p, _h, T0, rho0) ;
612  }
613  // Solve for temperature and density with or without the guess values provided
614  pFluid->temperature_ph(_p, _h, _T, _rho, rhosatL, rhosatV, TsatL, TsatV, T0, rho0);
615 
616  // Set the phase flags
617  if (double_equal(_rho,rhosatL) || double_equal(_rho,rhosatV) ||(_p < pFluid->reduce.p.Pa && _rho <= rhosatL && _rho >= rhosatV))
618  {
619  TwoPhase = true;
620  SinglePhase = false;
621  _Q = (1/_rho-1/rhosatL)/(1/rhosatV-1/rhosatL);
623 
624  psatL = _p;
625  psatV = _p;
626  }
627  else
628  {
629  TwoPhase = false;
630  SinglePhase = true;
631  SaturatedL = false;
632  SaturatedV = true;
633  }
634 }
635 
636 // Updater if p,s are inputs
637 void CoolPropStateClassSI::update_ps(long iInput1, double Value1, long iInput2, double Value2)
638 {
639  // Get them in the right order
640  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iP,iS);
641 
642  if (Value1 < 0 ){ throw ValueError(format("Your pressure [%g Pa] is less than zero",Value1));}
643 
644  // Set internal variables
645  _p = Value1;
646  _s = Value2;
647  s_cached = true;
648 
649  // Solve for temperature and density
651 
652  if (get_debug_level() > 9)
653  {
654  std::cout << format("pFluid->temperature_ps(_p, _s, &_T, &_rho, &rhosatL, &rhosatV, &TsatL, &TsatV)\n").c_str();
655  std::cout << format("pFluid->temperature_ps(%g, %g, %g, %g, %g, %g, %g, %g)\n", _p, _s, _T, _rho, rhosatL, rhosatV, TsatL, TsatV).c_str();
656  }
657 
658  // Set the phase flags
659  if (double_equal(_rho,rhosatL) || double_equal(_rho,rhosatV) ||(_p < pFluid->reduce.p.Pa && _rho <= rhosatL && _rho >= rhosatV))
660  {
661  TwoPhase = true;
662  SinglePhase = false;
663  _Q = (1/_rho-1/rhosatL)/(1/rhosatV-1/rhosatL);
665 
666  psatL = _p;
667  psatV = _p;
668  }
669  else
670  {
671  TwoPhase = false;
672  SinglePhase = true;
673  SaturatedL = false;
674  SaturatedV = true;
675  }
676 }
677 
678 // Updater if h,s are inputs
679 void CoolPropStateClassSI::update_hs(long iInput1, double Value1, long iInput2, double Value2)
680 {
681  // Get them in the right order
682  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iH,iS);
683 
684  // Set internal variables
685  _h = Value1;
686  _s = Value2;
687  h_cached = true;
688  s_cached = true;
689 
690  // Solve for temperature and density
692 
693  // Reduced parameters
694  double delta = this->_rho/pFluid->reduce.rho;
695  double tau = pFluid->reduce.T/this->_T;
696  _p = pFluid->R()*_T*_rho*(1.0 + delta*dphir_dDelta(tau, delta));
697 
698  // Set the phase flags
699  if ( _p < pFluid->crit.p.Pa && _rho < rhosatL && _rho > rhosatV)
700  {
701  TwoPhase = true;
702  SinglePhase = false;
703  _Q = (1/_rho-1/rhosatL)/(1/rhosatV-1/rhosatL);
705 
706  psatL = _p;
707  psatV = _p;
708  }
709  else
710  {
711  TwoPhase = false;
712  SinglePhase = true;
713  SaturatedL = false;
714  SaturatedV = true;
715  }
716 }
717 
718 // Updater if T,s are inputs
719 void CoolPropStateClassSI::update_Ts(long iInput1, double Value1, long iInput2, double Value2)
720 {
721  // Get them in the right order
722  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iT,iS);
723 
724  if (Value1 < 0 ){ throw ValueError(format("Your temperature [%g K] is less than zero",Value1));}
725 
726  // Set internal variables
727  _T = Value1;
728  _s = Value2;
729  s_cached = true;
730 
731  // Solve for density and pressure
733 
734  if (get_debug_level() > 9)
735  {
736  std::cout << format("pFluid->density_Ts(_T, _s, &_rho, &_p, &rhosatL, &rhosatV, &psatL, &psatV)\n").c_str();
737  std::cout << format("pFluid->density_Ts(%g, %g, %g, %g, %g, %g, %g, %g)\n", _T, _s, _rho, _p, rhosatL, rhosatV, psatL, psatV).c_str();
738  }
739 
740  // Set the phase flags
741  if ( _T < pFluid->crit.T && _rho < rhosatL && _rho > rhosatV)
742  {
743  TwoPhase = true;
744  SinglePhase = false;
745  _Q = (1/_rho-1/rhosatL)/(1/rhosatV-1/rhosatL);
747 
748  TsatL = _T;
749  TsatV = _T;
750  }
751  else
752  {
753  TwoPhase = false;
754  SinglePhase = true;
755  SaturatedL = false;
756  SaturatedV = false;
757  }
758 }
759 
760 // Updater if you are using TTSE LUT
761 void CoolPropStateClassSI::update_TTSE_LUT(long iInput1, double Value1, long iInput2, double Value2)
762 {
763  // If the inputs are P,Q or T,Q , it is guaranteed to be two-phase
764  if (match_pair(iInput1,iInput2,iP,iQ))
765  {
766  // Set phase flags
767  SinglePhase = false;
768  TwoPhase = true;
769 
770  // Sort in the right order (P,Q)
771  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iP,iQ);
772 
773  double p = Value1;
774  double Q = Value2;
775 
776  // Check whether saturated liquid or vapor
778 
783  psatL = p;
784  psatV = p;
785 
786  // Set internal variables
787  _T = Q*TsatV+(1-Q)*TsatL;
788  _rho = 1/(Q/rhosatV+(1-Q)/rhosatL);
789  _p = Q*psatV+(1-Q)*psatL;
790  _Q = Q;
791  }
792  else if (match_pair(iInput1,iInput2,iT,iQ))
793  {
794  // We know it is a pure fluid since pseudo-pure can't get this far (see update function)
795  // Set phase flags
796  SinglePhase = false;
797  TwoPhase = true;
798 
799  // Sort in the right order (T,Q)
800  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iT,iQ);
801 
802  double T = Value1;
803  double Q = Value2;
804 
805  // Check whether saturated liquid or vapor
807 
808  double p = pFluid->TTSESatL.evaluate_T(T);
813  psatL = p;
814  psatV = p;
815 
816  // Set internal variables
817  _T = Q*TsatV+(1-Q)*TsatL;
818  _rho = 1/(Q/rhosatV+(1-Q)/rhosatL);
819  _p = Q*psatV+(1-Q)*psatL;
820  _Q = Q;
821  }
822  else if (match_pair(iInput1,iInput2,iP,iH))
823  {
824  // Sort in the right order (P,H)
825  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iP,iH);
826 
827  double p = Value1;
828  double h = Value2;
829  _p = p;
830  _h = h;
831  h_cached = true;
832 
833  // If enthalpy is outside the saturation region or flag_SinglePhase is set, it is single-phase
834  if (p > pFluid->reduce.p.Pa || p < pFluid->params.ptriple || flag_SinglePhase || h < pFluid->TTSESatL.evaluate(iH,p) || h > pFluid->TTSESatV.evaluate(iH,p))
835  {
836  TwoPhase = false;
837  SinglePhase = true;
838  _logp = log(p);
841  }
842  else
843  {
844  TwoPhase = true;
845  SinglePhase = false;
846 
847  double hsatL = pFluid->TTSESatL.evaluate(iH,p);
848  double hsatV = pFluid->TTSESatV.evaluate(iH,p);
853  psatL = p;
854  psatV = p;
855 
856  _Q = (h-hsatL)/(hsatV-hsatL);
857  _rho = 1/(_Q/rhosatV+(1-_Q)/rhosatL);
858  _T = _Q*TsatV+(1-_Q)*TsatL;
859  _p = _Q*psatV+(1-_Q)*psatL;
861  }
862  }
863  else if (match_pair(iInput1,iInput2,iP,iT))
864  {
865  SinglePhase = true;
866  TwoPhase = false;
867  // Sort in the right order (P,T)
868  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iP,iT);
869 
870  _logp = log(Value1);
872  h_cached = true;
874  _p = Value1;
875  _T = Value2;
876  }
877  else if (match_pair(iInput1,iInput2,iP,iD))
878  {
879  // Sort in the right order (P,D)
880  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iP,iD);
881 
882  double p = Value1;
883  double rho = Value2;
884 
885  // If density is outside the saturation region, it is single-phase
886  if (p > pFluid->reduce.p.Pa || p < pFluid->params.ptriple || rho < pFluid->TTSESatV.evaluate(iD,p) || rho > pFluid->TTSESatL.evaluate(iD,p))
887  {
888  TwoPhase = false;
889  SinglePhase = true;
890  _logp = log(p);
891  // Saturation calls happen again inside evaluate_one_other_input - perhaps pass values
893  h_cached = true;
895  _p = Value1;
896  _rho = Value2;
897  }
898  else
899  {
900  TwoPhase = true;
901  SinglePhase = false;
902 
903  double hsatL = pFluid->TTSESatL.evaluate(iH,p);
904  double hsatV = pFluid->TTSESatV.evaluate(iH,p);
909  psatL = p;
910  psatV = p;
911 
912  _Q = (1/rho-1/rhosatL)/(1/rhosatV-1/rhosatL);
913  _rho = rho;
914  _T = _Q*TsatV + (1-_Q)*TsatL;
915  _p = p;
916  _h = _Q*hsatV + (1-_Q)*hsatL;
917 
919  }
920  }
921  else if (match_pair(iInput1,iInput2,iP,iS))
922  {
923  // Sort in the right order (P,S)
924  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iP,iS);
925 
926  double p = Value1;
927  double s = Value2;
928 
929  _p = p;
930  _s = s;
931 
932  // If entropy is outside the saturation region, it is single-phase
933  if (p > pFluid->reduce.p.Pa || p < pFluid->params.ptriple || s > pFluid->TTSESatV.evaluate(iS,p) || s < pFluid->TTSESatL.evaluate(iS,p))
934  {
935  TwoPhase = false;
936  SinglePhase = true;
937  _logp = log(p);
938  _h = pFluid->TTSESinglePhase.evaluate_one_other_input(iP,p,iS,s); // Get the enthalpy
939  h_cached = true;
942  }
943  else
944  {
945  TwoPhase = true;
946  SinglePhase = false;
947 
948  double hsatL = pFluid->TTSESatL.evaluate(iH,p);
949  double hsatV = pFluid->TTSESatV.evaluate(iH,p);
950  double ssatL = pFluid->TTSESatL.evaluate(iS,p);
951  double ssatV = pFluid->TTSESatV.evaluate(iS,p);
956  psatL = p;
957  psatV = p;
958 
959  _Q = (s-ssatL)/(ssatV-ssatL);
960  _rho = 1/(_Q/rhosatV+(1-_Q)/rhosatL);
961  _T = _Q*TsatV + (1-_Q)*TsatL;
962  _h = _Q*hsatV + (1-_Q)*hsatL;
963 
965  }
966  }
967  else if (match_pair(iInput1,iInput2,iT,iD))
968  {
969  // Sort in the right order (T,D)
970  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iT,iD);
971 
972  _T = Value1;
973  _rho = Value2;
974  _logrho = log(_rho);
975 
976  // If density is outside the saturation region, it is single-phase
977  if (Value1 > pFluid->crit.T || Value1 < pFluid->params.Ttriple){
978  SinglePhase = true;
979  }
980  else{
981  double psatL = pFluid->TTSESatL.evaluate_T(Value1);
982  double psatV = pFluid->TTSESatV.evaluate_T(Value1);
983  if (Value2 < pFluid->TTSESatV.evaluate(iD,psatV) || Value2 > pFluid->TTSESatL.evaluate(iD,psatL)){
984  SinglePhase = true;
985  }
986  else{
987  SinglePhase = false;
988  }
989  }
990 
991  if (SinglePhase)
992  {
993  TwoPhase = false;
994  SinglePhase = true;
995 
996  _p = pFluid->TTSESinglePhase.evaluate_Trho(iP,Value1,Value2,_logrho);
997  }
998  else
999  {
1000  TwoPhase = true;
1001  SinglePhase = false;
1002  _p = pFluid->TTSESatL.evaluate_T(Value1);
1007  psatL = _p;
1008  psatV = _p;
1009 
1010  _Q = (1/_rho-1/rhosatL)/(1/rhosatV-1/rhosatL);
1011  }
1012  }
1013  else
1014  {
1015  printf("Sorry your inputs[%d,%d] don't work for now with TTSE\n",(int)iInput1,(int)iInput2);
1016  throw ValueError(format("Sorry your inputs don't work for now with TTSE"));
1017  }
1018 }
1019 
1020 void CoolPropStateClassSI::update_incompressible(long iInput1, double Value1, long iInput2, double Value2)
1021 {
1022  if (match_pair(iInput1,iInput2,iT,iP))
1023  {
1024  // Get them in the right order
1025  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iT,iP);
1026  _T = Value1; _p = Value2;
1028  {
1029  _rho = pIncompLiquid->rho(_T, _p);
1030  }
1032  {
1033  _rho = Props("D",'T',_T,'P',_p,brine_string); // TODO SOLUTION
1034  }
1035  }
1036  else if (match_pair(iInput1,iInput2,iH,iP))
1037  {
1038  // Get them in the right order
1039  sort_pair(&iInput1,&Value1,&iInput2,&Value2,iP,iH);
1040  _p = Value1;
1041  double h = Value2;
1042 
1043  double x1=0,x2=0,x3=0,y1=0,y2=0,eps=1e-8,change=999,f=999;
1044  int iter=1;
1045 
1046  while ((iter<=3 || fabs(f)>eps) && iter<100)
1047  {
1048  if (iter==1){x1 = 300; _T=x1;}
1049  if (iter==2){x2 = 300+0.1; _T=x2;}
1050  if (iter>2) {_T=x2;}
1052  f = this->h()-h;
1053  if (iter==1){y1=f;}
1054  if (iter>1)
1055  {
1056  y2=f;
1057  x3=x2-y2/(y2-y1)*(x2-x1);
1058  change=fabs(y2/(y2-y1)*(x2-x1));
1059  y1=y2; x1=x2; x2=x3;
1060  }
1061  iter=iter+1;
1062  if (iter>100)
1063  {
1064  throw SolutionError(format("T_hp not converging with inputs (h=%g,p=%g) value: %0.12g\n",h,_p,_T));
1065  }
1066  }
1067  }
1068  else
1069  {
1070  printf("Sorry your inputs[%d,%d] don't work for now with incompressible\n",(int)iInput1,(int)iInput2);
1071  throw ValueError(format("Sorry your inputs don't work for now with incompressible"));
1072  }
1073 
1074 }
1075 
1078 {
1079  double output;
1080  switch (iOutput)
1081  {
1082  // --------------------------
1083  // Fluid constants
1084  // --------------------------
1085  case iMM:
1086  output = pFluid->params.molemass; break;
1087  case iPcrit:
1088  output = pFluid->crit.p.Pa; break;
1089  case iTcrit:
1090  output = pFluid->crit.T; break;
1091  case iTreduce:
1092  output = pFluid->reduce.T; break;
1093  case iScrit:
1094  output = pFluid->crit.s; break;
1095  case iHcrit:
1096  output = pFluid->crit.h; break;
1097  case iTtriple:
1098  output = pFluid->params.Ttriple; break;
1099  case iPtriple:
1100  output = pFluid->params.ptriple; break;
1101  case iRhocrit:
1102  output = pFluid->crit.rho; break;
1103  case iRhoreduce:
1104  output = pFluid->reduce.rho; break;
1105  case iAccentric:
1106  output = pFluid->params.accentricfactor; break;
1107  case iTmin:
1108  output = pFluid->limits.Tmin; break;
1109  case iTmax:
1110  output = pFluid->limits.Tmax; break;
1111  case iPmax:
1112  output = pFluid->limits.pmax; break;
1113  case iCritSplineT:
1114  output = pFluid->CriticalSpline_T.Tend; break;
1115 
1116  // --------------------------
1117  // Phase Constants
1118  // --------------------------
1119  case iPHASE_LIQUID:
1120  output = iLiquid; break;
1121  case iPHASE_GAS:
1122  output = iGas; break;
1123  case iPHASE_SUPERCRITICAL:
1124  output = iSupercritical; break;
1125  case iPHASE_TWOPHASE:
1126  output = iTwoPhase; break;
1127 
1128  // --------------------------
1129  // Environmental properties
1130  // --------------------------
1131  case iODP:
1132  output = pFluid->environment.ODP; break;
1133  case iGWP20:
1134  output = pFluid->environment.GWP20; break;
1135  case iGWP100:
1136  output = pFluid->environment.GWP100; break;
1137  case iGWP500:
1138  output = pFluid->environment.GWP500; break;
1139 
1140  // --------------------------
1141  // Thermodynamic properties
1142  // --------------------------
1143  case iT:
1144  output = _T; break;
1145  case iD:
1146  output = _rho; break;
1147  case iP:
1148  output = p(); break;
1149  case iC:
1150  output = cp(); break;
1151  case iC0:
1152  output = pFluid->specific_heat_p_ideal_Trho(_T); break;
1153  case iO:
1154  output = cv(); break;
1155  case iA:
1156  output = speed_sound(); break;
1157  case iG:
1158  output = h()-_T*s(); break;
1159  case iQ:
1160  {
1161  if (TwoPhase)
1162  output = _Q;
1163  else
1164  output = -1;
1165  break;
1166  }
1167  case iH:
1168  output = h(); break;
1169  case iS:
1170  output = s(); break;
1171  case iU:
1172  output = h()-p()/_rho; break;
1173 
1174  case iPhase:
1175  output = phase(); break;
1176 
1177  // --------------------------
1178  // Transport properties
1179  // --------------------------
1180  case iV:
1181  output = viscosity(); break;
1182  case iL:
1183  output = conductivity(); break;
1184  case iI:
1185  output = surface_tension(); break;
1186  case iPrandtl:
1187  output = Prandtl(); break;
1188 
1189  // -----------------------------------
1190  // A few grandfathered derivatives
1191  // -----------------------------------
1192  case iDpdT:
1193  output = dpdT_constrho(); break;
1194  case iDrhodT_p:
1195  output = drhodT_constp(); break;
1196 
1197  // -----------------------------------
1198  // Add all other derivatives to remove
1199  // DerivTerms from wrappers in future
1200  // versions.
1201  // -----------------------------------
1202  case iDERdh_dp__rho:
1203  case iDERdh_dp__v:
1204  output = dhdp_constrho(); break;
1205  case iDERZ:
1206  output = Z(); break;
1207  case iDERdZ_dDelta:
1208  output = dZdDelta(); break;
1209  case iDERdZ_dTau:
1210  output = dZdTau(); break;
1211  case iDERB:
1212  output = B(); break;
1213  case iDERdB_dT:
1214  output = dBdT(); break;
1215  case iDERC:
1216  output = C(); break;
1217  case iDERdC_dT:
1218  output = dCdT(); break;
1219  case iDERphir:
1220  output = phir(tau, delta); break;
1221  case iDERdphir_dTau:
1222  output = dphir_dTau(tau, delta); break;
1223  case iDERdphir_dDelta:
1224  output = dphir_dDelta(tau, delta); break;
1225  case iDERd2phir_dTau2:
1226  output = d2phir_dTau2(tau, delta); break;
1227  case iDERd2phir_dDelta2:
1228  output = d2phir_dDelta2(tau,delta); break;
1230  output = d2phir_dDelta_dTau(tau,delta); break;
1231  case iDERd3phir_dDelta3:
1232  output = d3phir_dDelta3(tau, delta); break;
1234  output = d3phir_dDelta2_dTau(tau, delta); break;
1236  output = d3phir_dDelta_dTau2(tau, delta); break;
1237  case iDERd3phir_dTau3:
1238  output = d3phir_dTau3(tau, delta); break;
1239  case iDERphi0:
1240  output = phi0(tau, delta); break;
1241  case iDERdphi0_dTau:
1242  output = dphi0_dTau(tau, delta); break;
1243  case iDERd2phi0_dTau2:
1244  output = d2phi0_dTau2(tau, delta); break;
1245  case iDERdphi0_dDelta:
1246  output = dphi0_dDelta(tau, delta); break;
1247  case iDERd2phi0_dDelta2:
1248  output = d2phi0_dDelta2(tau, delta); break;
1250  output = d2phi0_dDelta_dTau(tau, delta); break;
1251  case iDERd3phi0_dTau3:
1252  output = d3phi0_dTau3(tau, delta); break;
1253  case iDERdp_dT__rho:
1254  output = dpdT_constrho(); break;
1255  case iDERdp_drho__T:
1256  output = dpdrho_constT(); break;
1257  case iDERdh_dT__rho:
1258  output = dhdT_constrho(); break;
1259  case iDERdh_drho__T:
1260  output = dhdrho_constT(); break;
1261  case iDERdrho_dT__p:
1262  output = drhodT_constp(); break;
1263  case iDERdrho_dh__p:
1264  output = drhodh_constp(); break;
1265  case iDERdrho_dp__h:
1266  output = drhodp_consth(); break;
1267  case iDERrho_smoothed:
1268  //double rhospline, dsplinedp, dsplinedh;
1269  //update(iT,T,iQ,rho);
1271  output = rhospline; break;
1272  case iDERdrho_smoothed_dh:
1273  //double rhospline, dsplinedp, dsplinedh;
1274  //CPS.update(iT,T,iQ,rho);
1276  output = dsplinedh; break;
1277  case iDERdrho_smoothed_dp:
1278  //double rhospline, dsplinedp, dsplinedh;
1279  //CPS.update(iT,T,iQ,rho);
1281  output = dsplinedp; break;
1283  output = drhodh_constp_smoothed(0.1); break;
1285  output = drhodp_consth_smoothed(0.1); break;
1287  output = isothermal_compressibility(); break;
1288  case iDERdh_dp__T:
1289  output = dhdp_constT(); break;
1290  default:
1291  throw ValueError(format("Invalid Output index to CPState function keyed_output: %d ",iOutput));
1292  }
1293  if (get_debug_level() > 8){
1294  std::cout << format("%s:%d: CoolPropStateClassSI::keyed_output(%d) -> %g\n",__FILE__,__LINE__, iOutput,output) ;
1295  }
1296  return output;
1297 }
1298 
1300 {
1301  double pL,pV,rhoL,rhoV;
1303  {
1304  return iLiquid;
1305  }
1306  else
1307  {
1308  return pFluid->phase_Trho_indices(_T,_rho,pL,pV,rhoL,rhoV);
1309  }
1310 }
1311 
1313 {
1314  // While SatL and SatV are technically two-phase, we consider
1315  // them to be single-phase to speed up the calcs and avoid saturation calls
1316  SatL->flag_SinglePhase = true;
1317  SatL->flag_TwoPhase = false;
1319  SatL->flag_SinglePhase = false;
1320  SatL->SinglePhase = true;
1321  SatL->TwoPhase = false;
1322 
1323  SatV->flag_SinglePhase = true;
1325  SatV->flag_SinglePhase = false;
1326  SatV->SinglePhase = true;
1327  SatV->TwoPhase = false;
1328 }
1329 
1331  if (pFluid->enabled_TTSE_LUT)
1332  {
1334  return pFluid->TTSESatL.evaluate(iH,psatL);
1335  }
1336  else
1337  {
1338  return SatL->h();
1339  }
1340 }
1342  if (pFluid->enabled_TTSE_LUT)
1343  {
1345  return pFluid->TTSESatV.evaluate(iH,psatV);
1346  }
1347  else
1348  {
1349  return SatV->h();
1350  }
1351 }
1353  if (pFluid->enabled_TTSE_LUT)
1354  {
1356  return pFluid->TTSESatL.evaluate(iS,psatL);
1357  }
1358  else
1359  {
1360  return SatL->s();
1361  }
1362 }
1364  if (pFluid->enabled_TTSE_LUT)
1365  {
1367  return pFluid->TTSESatV.evaluate(iS,psatV);
1368  }
1369  else
1370  {
1371  return SatV->s();
1372  }
1373 }
1374 
1375 double CoolPropStateClassSI::cpL(void){return SatL->cp();};
1376 double CoolPropStateClassSI::cpV(void){return SatV->cp();};
1381 
1383  if (get_debug_level()>9){ std::cout << format("%s:%d: StateClassSI::h: tau %g delta %g TwoPhase %d\n", __FILE__,__LINE__,tau,delta,TwoPhase).c_str(); }
1385  {
1386  return pIncompLiquid->h(_T, _p);
1387  }
1389  {
1390  // TODO SOLUTION
1391  double val_kJkg = Props("H",'T',_T,'P',_p,brine_string);
1393  }
1394  else if (TwoPhase){
1395  // This will use the TTSE LUT if enable_TTSE_LUT() has been called
1396  return _Q*hV()+(1-_Q)*hL();
1397  }
1398  else{
1399  if (h_cached && ValidNumber(_h)){
1400  // Use the pre-calculated value
1401  return _h;
1402  }
1403  else
1404  {
1406  {
1407  if (get_debug_level()>9){ std::cout << format("%s:%d: StateClassSI::h: _T %g, _rho %g\n", __FILE__,__LINE__,_T,_rho).c_str(); }
1409  }
1410  else
1411  {
1412  // Use the EOS, using the cached value if possible
1413  double val = pFluid->R()*_T*(1.0+tau*(dphi0_dTau(tau,delta)+dphir_dTau(tau,delta))+delta*dphir_dDelta(tau,delta));
1414  if (get_debug_level()>9){ std::cout << format("%s:%d: StateClassSI::h: h %g\n", __FILE__,__LINE__,val).c_str(); }
1415  return val;
1416  }
1417  }
1418  }
1419 }
1422  {
1423  return pIncompLiquid->s(_T, _p);
1424  }
1426  {
1427  // TODO SOLUTION
1428  double val_kJkgK = Props("S",'T',_T,'P',_p,brine_string);
1430  }
1431  else if (TwoPhase){
1432  // This will use the TTSE LUT if enable_TTSE_LUT() has been called
1433  return _Q*sV()+(1-_Q)*sL();
1434  }
1435  else{
1437  {
1438  // Use the pre-calculated value
1439  return _s;
1440  }
1441  else
1442  {
1443  if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP, p(), iH, h()) )
1444  {
1445  if (h_cached){
1447  }
1448  else{
1450  }
1451  }
1452  else
1453  {
1454  // Use the EOS, using the cached values if possible
1456  }
1457  }
1458  }
1459 }
1462  {
1463  return pIncompLiquid->c(_T, _p);
1464  }
1466  {
1467  // TODO SOLUTION
1468  double val_kJkgK = Props("C",'T',_T,'P',_p,brine_string);
1470  }
1471  else if (TwoPhase && _Q > 0 && _Q < 1)
1472  {
1474  return interp_linear(_Q,cpL(),cpV());
1475  } else {
1476  return -_HUGE;
1477  }
1478  }
1479  else if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP, p(), iH, h()) )
1480  {
1481  // cp is also given by (dh/dT)|p, or 1/((dT/dh)|p) which is tabulated
1482  _h = h();
1484  }
1485  else
1486  {
1487  double c1 = pow(1.0+delta*dphir_dDelta(tau,delta)-delta*tau*d2phir_dDelta_dTau(tau,delta),2);
1488  double c2 = (1.0+2.0*delta*dphir_dDelta(tau,delta)+pow(delta,2)*d2phir_dDelta2(tau,delta));
1489  double val = pFluid->R()*(-pow(tau,2)*(d2phi0_dTau2(tau,delta)+d2phir_dTau2(tau,delta))+c1/c2);
1490  return val;
1491  }
1492 }
1493 
1496  {
1497  return pIncompLiquid->visc(_T, _p);
1498  }
1500  {
1501  // TODO SOLUTION
1502  double val = Props("V",'T',_T,'P',_p,brine_string);
1504  }
1505  else if (TwoPhase)
1506  {
1508  {
1509  return interp_recip(_Q,viscL(),viscV());
1510  } else {
1511  return -_HUGE;
1512  }
1513  }
1514  else if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP,p(),iH,h()))
1515  {
1517  }
1518  else
1519  {
1520  return pFluid->viscosity_Trho(_T,_rho);
1521  }
1522 }
1523 
1526  {
1527  return pIncompLiquid->cond(_T, _p);
1528  }
1530  {
1531  // TODO SOLUTION
1532  double val_KSI = Props("L",'T',_T,'P',_p,brine_string);
1534  }
1535  else if (TwoPhase)
1536  {
1538  {
1539  return interp_linear(_Q,condL(),condV());
1540  } else
1541  {
1542  return -_HUGE;
1543  }
1544  }
1545  else if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP,p(),iH,h()))
1546  {
1548  }
1549  else{
1550  return pFluid->conductivity_Trho(_T,_rho);
1551  }
1552 }
1554  return this->cp()*this->viscosity()/this->conductivity();
1555 }
1556 
1557 double CoolPropStateClassSI::B_TTSE(double p, double h){
1558  // Slightly modified, doesn't use specific volume at all, also sign switched
1563  return (drhodp_h*dsdh_p-drhodh_p*dsdp_h);
1564 }
1565 double CoolPropStateClassSI::B_over_D_TTSE(double p, double h)
1566 {
1573  return (drhodh_p*dsdp_h-drhodp_h*dsdh_p)/(dTdh_p*drhodp_h-dTdp_h*drhodh_p);
1574 }
1577  {
1578  return pIncompLiquid->c(_T, _p);
1579  }
1581  {
1582  // TODO SOLUTION
1583  double val_KSI = Props("C",'T',_T,'P',_p,brine_string);
1585  }
1586  else if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP, p(), iH, h()) )
1587  {
1588  if (TwoPhase && _Q>0 && _Q < 1)
1589  {
1595  double dvdTL = -drhodTL/rhoL()/rhoL();
1596  double dvdTV = -drhodTV/rhoV()/rhoV();
1597  double dxdT_v = (_Q*dvdTV + (1-_Q)*dvdTL)/(1/rhoL()-1/rhoV());
1598  double Tsat = (TV() - TL()) * _Q + TL();
1599  return Tsat*dsdTL + Tsat*dxdT_v*(sV()-sL()) + _Q*Tsat*(dsdTV - dsdTL);
1600  }
1601  else
1602  {
1603  // cv is also given by -B*T/D which is tabulated (indirectly)
1604  _h = h();
1606  }
1607  }
1608  else
1609  {
1610  if (TwoPhase)
1611  {
1613  double dsdTL = dsdT_along_sat_liquid();
1614  double dsdTV = dsdT_along_sat_vapor();
1615  double dvdTL = -drhodT_along_sat_liquid()/rhoL()/rhoL();
1616  double dvdTV = -drhodT_along_sat_vapor()/rhoV()/rhoV();
1617  double dxdT_v = (_Q*dvdTV + (1-_Q)*dvdTL)/(1/rhoL()-1/rhoV());
1618  double Tsat = (TV() - TL()) * _Q + TL();
1619  return Tsat*dsdTL + Tsat*dxdT_v*(sV()-sL()) + _Q*Tsat*(dsdTV - dsdTL);
1620  }
1621  else
1622  {
1623  return -pFluid->R()*pow(tau,2)*(d2phi0_dTau2(tau,delta)+d2phir_dTau2(tau,delta)); //[J/kg/K]
1624  }
1625  }
1626 }
1628  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("speed_sound invalid for incompressibles");}
1629 
1630  if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP, p(), iH, h()) )
1631  {
1632  if (TwoPhase && _Q>0 && _Q < 1)
1633  {
1635  double dsdpL = pFluid->TTSESatL.evaluate_sat_derivative(iS,_p);
1636  double dsdpV = pFluid->TTSESatV.evaluate_sat_derivative(iS,_p);
1637  double dvdpL = -pFluid->TTSESatL.evaluate_sat_derivative(iD,_p)/rhoL()/rhoL();
1638  double dvdpV = -pFluid->TTSESatV.evaluate_sat_derivative(iD,_p)/rhoV()/rhoV();
1639  double dxdp_s = (-_Q*(dsdpV-dsdpL) - dsdpL)/(sV()-sL());
1640  double dddp_s = -pow(_rho,2)*(dvdpL + dxdp_s*(1/rhoV() - 1/rhoL()) + _Q*(dvdpV-dvdpL));
1641  return pow(1.0/dddp_s,0.5);
1642  }
1643  else
1644  {
1645  _h = h();
1646  // speed of sound given by sqrt(v^2/B*dsdh|p), or sqrt(dpdrho|s)
1651  // TODO: Fix this
1653  return 1/sqrt((drhodp__h-drhodh__p*dsdp__h/dsdh__p));
1654  }
1655  } else {
1656  if (TwoPhase) {
1658  double dvdpL = -drhodp_along_sat_liquid()/rhoL()/rhoL();
1659  double dvdpV = -drhodp_along_sat_vapor()/rhoV()/rhoV();
1660  double dsdpL = dsdp_along_sat_liquid();
1661  double dsdpV = dsdp_along_sat_vapor();
1662  double dxdp_s = (-_Q*(dsdpV-dsdpL) - dsdpL)/(sV()-sL());
1663  double dddp_s = -pow(_rho,2)*(dvdpL + dxdp_s*(1/rhoV() - 1/rhoL()) + _Q*(dvdpV-dvdpL));
1664  return pow(1.0/dddp_s,0.5);
1665  } else {
1666  double c1 = pow(tau,2)*(d2phi0_dTau2(tau,delta)+d2phir_dTau2(tau,delta));
1667  double c2 = (1.0+2.0*delta*dphir_dDelta(tau,delta)+pow(delta,2)*d2phir_dDelta2(tau,delta));
1668  return sqrt(-c2*this->_T*this->cp()/c1);
1669  }
1670  }
1671 }
1672 
1674  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("isothermal_compressibility invalid for incompressibles");}
1675 
1676  if (TwoPhase && _Q>0 && _Q < 1)
1677  {
1679  {
1680  // dpdrho_constT not defined in two-phase region, thus linearized in between phases
1681  //double dpdrhoL = SatL->dpdrho_constT();
1682  //double dpdrhoV = SatV->dpdrho_constT();
1683  //return 1.0/(_rho*(dpdrhoL+_Q*(dpdrhoV-dpdrhoL)));
1684  // Simplified approach to give consistent value from standard and TTSE functions
1686  }
1687  else
1688  {
1689  // Not defined for two-phase
1690  return -1.0;
1691  }
1692  }
1693  else if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP, p(), iH, h()) )
1694  {
1695  _h = h();
1696  // isothermal compressibility given by kappa = -1/v*dvdp|T = 1/rho*drhodp|T
1702  return 1.0/rho*(drhodp__h-drhodh__p*dTdp__h/dTdh__p);
1703  }
1704  else
1705  {
1706  return 1.0/(_rho*dpdrho_constT());
1707  }
1708 }
1709 
1711  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("isobaric_expansion_coefficient invalid for incompressibles");}
1712 
1713  if (TwoPhase)
1714  {
1716  // drhodT_constp not defined in two-phase region, thus linearised in between phases
1717  //double dvdTL = -1/(_rho*_rho)*SatL->drhodT_constp();
1718  //double dvdTV = -1/(_rho*_rho)*SatV->drhodT_constp();
1719  //return _rho*(dvdTL+_Q*(dvdTV-dvdTL));
1720  // Simplified approach to give consistent value from standard and TTSE functions
1722  } else {
1723  return -_HUGE;
1724  }
1725  }
1726  else if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP, p(), iH, h()) )
1727  {
1728  _h = h();
1729  // isobaric expansion coefficient given by beta = 1/v*dvdT|p = -1/rho*drhodT|p
1733  return -1.0/(rho)*drhodh__p/dTdh__p;
1734  }
1735  else
1736  {
1737  return -1.0/(_rho)*drhodT_constp();
1738  }
1739 }
1741  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("surface_tension invalid for incompressibles");}
1742  return pFluid->surface_tension_T(_T);
1743 }
1744 
1746  //if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION)
1747  //{
1748  // throw ValueError("function invalid for incompressibles");
1749  //}
1750  // TODO: reimplement to avoid ugly numerical derivative
1751  double deltaT = .5;
1753  {
1754  double drho = Props("D",'P',p(),'T',T()+deltaT,pIncompLiquid->getName())-Props("D",'P',p(),'T',T()-deltaT,pIncompLiquid->getName());
1755  double dh = Props("H",'P',p(),'T',T()+deltaT,pIncompLiquid->getName())-Props("H",'P',p(),'T',T()-deltaT,pIncompLiquid->getName());
1756  return (drho/dh);
1757  }
1759  {
1760  double drho = Props("D",'P',p(),'T',T()+deltaT,brine_string)-Props("D",'P',p(),'T',T()-deltaT,brine_string);
1761  double dh = Props("H",'P',p(),'T',T()+deltaT,brine_string)-Props("H",'P',p(),'T',T()-deltaT,brine_string);
1762  return (drho/dh);
1763  }
1764  else if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP,p(),iH,h()) )
1765  {
1766  if (TwoPhase && _Q>0 && _Q < 1)
1767  {
1768  // equals -rho^2*dvdh_p where dvdh_p = 1/T*dTdp|sat
1770  }
1771  else
1772  {
1773  _h = h();
1775  }
1776  }
1777  else
1778  {
1779  if (TwoPhase)
1780  {
1781  // equals -rho^2*dvdh_p where dvdh_p = 1/T*dTdp|sat
1782  return -_rho*_rho/_T*dTdp_along_sat();
1783  }
1784  else
1785  {
1787  }
1788  }
1789 }
1790 
1792  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
1793  // Make a state class instance
1795  SplineClass SC = SplineClass();
1796  double hL = this->hL();
1797  double hV = this->hV();
1798  double hend = xend*hV+(1-xend)*hL;
1799 
1800  // We do the interpolation in terms of enthalpy because it is a bit simpler to do
1801  // The values at x = 0, but faking out CoolProp by using T,rho and enforcing singlephase
1802  CPS.flag_SinglePhase = true;
1803  if (isenabled_TTSE_LUT()){
1804  CPS.update(iP,psatL,iH,hL);
1805  }
1806  else{
1807  CPS.update(iT,TsatL,iD,rhosatL);
1808  }
1809  SC.add_value_constraint(hL, CPS.drhodp_consth());
1810  SC.add_derivative_constraint(hL, CPS.d2rhodhdp());
1811  // The values at x = xend
1812  CPS.flag_SinglePhase = false;
1813  CPS.update(iT,TsatL,iQ,xend);
1814  SC.add_value_constraint(hend, CPS.drhodp_consth());
1815  double d2vdhdp = 1/CPS.T()*CPS.d2Tdp2_along_sat()-1*pow(CPS.dTdp_along_sat()/CPS.T(),2);
1816  SC.add_derivative_constraint(hend, 2/CPS.rho()*CPS.drhodp_consth()*CPS.drhodh_constp()-pow(CPS.rho(),2)*d2vdhdp);
1817  SC.build();
1818  return SC.evaluate(_Q*hV+(1-_Q)*hL);
1819 }
1820 
1822  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
1823  // Make a state class instance
1825  SplineClass SC = SplineClass();
1826  double hL = this->hL();
1827  double hV = this->hV();
1828  double hend = xend*hV+(1-xend)*hL;
1829 
1830  // We do the interpolation in terms of enthalpy because it is a bit simpler to do
1831  // The values at x = 0, but faking out CoolProp by using T,rho and enforcing singlephase
1832  CPS.flag_SinglePhase = true;
1833  // Get the value at the saturated liquid part
1834  if (isenabled_TTSE_LUT()){
1835  CPS.update(iP,psatL,iH,hL);
1836  }
1837  else{
1838  CPS.update(iT,TsatL,iD,rhosatL);
1839  }
1840  SC.add_value_constraint(hL, CPS.drhodh_constp());
1842  // The values at x = xend
1843  CPS.update(iT,TsatL,iQ,xend);
1844  SC.add_value_constraint(hend, CPS.drhodh_constp());
1845  SC.add_derivative_constraint(hend, 2/CPS.rho()*CPS.drhodh_constp()*CPS.drhodh_constp());
1846  SC.build();
1847  return SC.evaluate(_Q*hV+(1-_Q)*hL);
1848 }
1849 
1850 
1851 void CoolPropStateClassSI::rho_smoothed(double xend, double &rho_spline, double &dsplinedh, double &dsplinedp){
1852  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
1853  // Make a state class instance in two-phase at the junction point (end):
1855  CPS.update(iT,TsatL,iQ,xend);
1856 
1857  // A few necessary properties:
1858  double h_l = this->hL(); //[J/kg]
1859  double h_v = this->hV(); //[J/kg]
1860  double rho_l = this->rhoL(); //[kg/m^3]
1861  double rho_v = this->rhoV(); //[kg/m^3]
1862  double x = _Q; //[-]
1863  double h_end = xend * h_v + (1-xend)*h_l; // [J/kg]
1864  double rho_end = (rho_l * rho_v)/(xend * rho_l + (1-xend)*rho_v); //[kg/m^3]
1865 
1866  // Getting the total derivatives along the saturation lines:
1867  double drholdp = CPS.drhodp_along_sat_liquid(); //[kg/m^3/Pa]
1868  double dhldp = CPS.dhdp_along_sat_liquid(); //[J/kg/Pa]
1869  double drhovdp = CPS.drhodp_along_sat_vapor(); //[kg/m^3/Pa]
1870  double dhvdp = CPS.dhdp_along_sat_vapor(); //[J/kg/Pa]
1871 
1872  // Getting the required partial derivatives just outside the two-phase zone (faking single-phase fluid):
1873  double drhodh_l = CPS.SatL->drhodh_constp();
1874  double drhodhdp_l = CPS.SatL->d2rhodhdp();
1875 
1876  // Same as above, but detailed:
1877  double dxdp = ((xend - 1 )* dhldp - xend* dhvdp)/(h_v - h_l);
1878  double drhodh_end = pow(rho_end,2)/(rho_l*rho_v) * (rho_v - rho_l)/(h_v - h_l);
1879  double dvdh_end = (1/rho_v - 1/rho_l)/(h_v - h_l);
1880  double dvdp_end = (-1/pow(rho_l,2) * drholdp + dxdp * (1/rho_v - 1/rho_l) + xend * (-1/pow(rho_v,2) * drhovdp + 1/pow(rho_l,2) * drholdp));
1881  double drhodp_end = -pow(rho_end,2) * dvdp_end;
1882  double dvdhdp_end = 1/(h_v - h_l) * (-1/pow(rho_v,2)*drhovdp + 1/pow(rho_l,2) * drholdp) - (1/rho_v - 1/rho_l) / pow((h_v - h_l),2) * (dhvdp - dhldp);
1883  double drhodhdp_end = -2 * rho_end * dvdh_end * drhodp_end -pow(rho_end,2)*dvdhdp_end;
1884 
1885  // Derivative at constant quality (xend):
1886  double drhoxdp = pow(rho_end,2)*(xend / pow(rho_v,2) * drhovdp + (1-xend)/pow(rho_l,2) * drholdp);
1887 
1888  // Arguments of the spline function (rho is smoothed as a function of h):
1889  double delta = x * (h_v - h_l); //[J/kg]
1890  double delta_end = h_end - h_l; //[J/kg]
1891  double ddeltaxdp = xend * (dhvdp - dhldp); //[J/kg/(Pa)]
1892  double ddeltadp = -dhldp; //[J/kg/(Pa)]
1893 
1894  // Coefficients of the spline function
1895  double a = 1/pow(delta_end,3) * (2*rho_l - 2*rho_end + delta_end * (drhodh_l + drhodh_end));
1896  double b = 3/pow(delta_end,2) * (-rho_l + rho_end) - 1/delta_end * (drhodh_end + 2 * drhodh_l);
1897  double c = drhodh_l;
1898  double d = rho_l;
1899 
1900  // First pressure derivative of the coefficients
1901  double dadp = -6/pow(delta_end,4) * ddeltaxdp * (rho_l - rho_end) + 2/pow(delta_end,3) * (drholdp - drhoxdp) + 1/pow(delta_end,2) * (drhodhdp_l + drhodhdp_end) -2/pow(delta_end,3) * (drhodh_l + drhodh_end)*ddeltaxdp;
1902  double dbdp = -6/pow(delta_end,3) * ddeltaxdp * (-rho_l + rho_end) + 3/pow(delta_end,2) * (-drholdp + drhoxdp) + 1/pow(delta_end,2) * ddeltaxdp * (drhodh_end + 2 * drhodh_l) - 1/delta_end * (drhodhdp_end + 2 * drhodhdp_l);
1903  double dcdp = drhodhdp_l;
1904  double dddp = drholdp;
1905 
1906  // Computing the final useful values:
1907  rho_spline = a * pow(delta,3) + b * pow(delta,2) + c * delta + d;
1908  dsplinedp = (3*a * pow(delta,2) +2* b * delta + c)* ddeltadp + pow(delta,3) * dadp + pow(delta,2) * dbdp + delta * dcdp + dddp;
1909  dsplinedh = 3 * a * pow(delta,2) + 2*b * delta + c;
1910 
1911 }
1912 
1913 
1914 //Checking that the derivatives are ok:
1915 //double pend = CPS._p;
1916 //double step = 0.1;
1917 //CPS.update(iH,h_end+step,iP,pend);
1918 //double rho_hplus = CPS._rho;
1919 //CPS.update(iH,h_end+step,iP,pend+step);
1920 //double rho_hplus_pplus = CPS._rho;
1921 //CPS.update(iH,h_end,iP,pend+step);
1922 //double rho_pplus = CPS._rho;
1923 //double dvdh_end_pplus = (1/CPS.rhoV() - 1/CPS.rhoL())/(CPS.hV() - CPS.hL());
1924 //double drhodh_check_pplus = -rho_pplus*rho_pplus * dvdh_end_pplus;
1925 //double drhodh_check2_pplus = CPS.drhodh_constp();
1926 //CPS.update(iH,h_end+step,iP,pend-step);
1927 //double rho_hplus_pminus = CPS._rho;
1928 //CPS.update(iH,h_end-step,iP,pend+step);
1929 //double rho_hminus_pplus = CPS._rho;
1930 //CPS.update(iH,h_end-step,iP,pend-step);
1931 //double rho_hminus_pminus = CPS._rho;
1932 //double dvdhdp_check = (dvdh_end_pplus - dvdh_end)/step;
1933 //double drhodhdp_check = -rho_end*rho_end * dvdhdp_check;
1934 //double drhodhdp_check2 = (drhodh_check2_pplus - drhodh_end)/step;
1935 //double drhodp_hend = (rho_pplus - rho_end)/step;
1936 //double drhodp_hplus = (rho_hplus_pplus - rho_hplus)/step;
1937 //double drhodh_pend = (rho_hplus - rho_end)/step;
1938 //double drhodh_pplus = (rho_hplus_pplus - rho_pplus)/step;
1939 //double drhodhdp_1 = (drhodp_hplus - drhodp_hend)/step;
1940 //double drhodhdp_2 = (drhodh_pplus - drhodh_pend)/step;
1941 //double drhodhdp_3 = (rho_hplus_pplus + rho_hminus_pminus - rho_hplus_pminus - rho_hminus_pplus)/(4*step*step);
1942 //double dvdhdp_3 = (1/rho_hplus_pplus + 1/rho_hminus_pminus - 1/rho_hplus_pminus - 1/rho_hminus_pplus)/(4*step*step);
1943 
1944 #ifndef DISABLE_CATCH
1945 #include "Catch/catch.hpp"
1946 
1947 TEST_CASE("Check of density smoothing derivatives","[normal]")
1948 {
1949  int ttse_flag;
1950  double rho_spline, dsplinedh, dsplinedp;
1951  std::string TTSE;
1952 
1953  WHEN("TTSE is off")
1954  {
1955  ttse_flag = 0;
1956  TTSE = "off";
1957  THEN("drho_dh|p")
1958  {
1959  double x = 0.3;
1960  double dh = 0.01;
1961  CoolPropStateClassSI CPS("n-Propane");
1962  CPS.disable_TTSE_LUT();
1963  CPS.update(iT, 300, iQ, x);
1964  CPS.rho_smoothed(0.3,rho_spline, dsplinedh, dsplinedp);
1965  CoolPropStateClassSI CPS2("n-Propane");
1966  CPS2.disable_TTSE_LUT();
1967  CPS2.update(iP, CPS.p(), iH, CPS.h() +dh);
1968  double drho_dh__constp_num = (CPS2.rho()-CPS.rho())/dh;
1969  double drho_dh__constp = CPS.drhodh_constp();
1970  CAPTURE(x);
1971  CAPTURE(TTSE);
1972  CAPTURE(dsplinedh);
1973  CAPTURE(drho_dh__constp);
1974  CHECK(fabs(dsplinedh/drho_dh__constp-1) < 1e-4);
1975  CHECK(fabs(drho_dh__constp_num/drho_dh__constp-1) < 1e-4);
1976  }
1977 
1978  THEN("Smoothed Density")
1979  {
1980  for (double x = 0; x <=0.31; x+= 0.3)
1981  {
1982  CoolPropStateClassSI CPS("n-Propane");
1983  CPS.update(iT, 300, iQ, x);
1984  CPS.disable_TTSE_LUT();
1985  CPS.rho_smoothed(0.3, rho_spline, dsplinedh, dsplinedp);
1986  double rho_EOS = CPS.rho();
1987  CAPTURE(x);
1988  CAPTURE(TTSE);
1989  CAPTURE(rho_spline);
1990  CAPTURE(rho_EOS);
1991  CHECK(fabs(rho_spline/rho_EOS-1) < 1e-6);
1992  }
1993  }
1994  }
1995  WHEN("TTSE is on")
1996  {
1997  ttse_flag = 1;
1998  TTSE = "on";
1999  THEN("drho_dh|p at x = xend")
2000  {
2001  double x = 0.3;
2002  CoolPropStateClassSI CPS("n-Propane");
2003  CPS.enable_TTSE_LUT();
2004  CPS.update(iT, 300, iQ, x);
2005  CPS.rho_smoothed(0.3, rho_spline, dsplinedh, dsplinedp);
2006  double drho_dh__constp = CPS.drhodh_constp();
2007  CAPTURE(x);
2008  CAPTURE(TTSE);
2009  CAPTURE(dsplinedh);
2010  CAPTURE(drho_dh__constp);
2011  CPS.disable_TTSE_LUT();
2012  CHECK(fabs(dsplinedh/drho_dh__constp-1) < 1e-2);
2013  }
2014 
2015  THEN("Smoothed Density")
2016  {
2017  for (double x = 0; x <=0.31; x+= 0.3)
2018  {
2019  CoolPropStateClassSI CPS("n-Propane");
2020  CPS.update(iT, 300, iQ, x);
2021  CPS.enable_TTSE_LUT();
2022  CPS.rho_smoothed(0.3, rho_spline, dsplinedh, dsplinedp);
2023  double rho_EOS = CPS.rho();
2024  CAPTURE(x);
2025  CAPTURE(TTSE);
2026  CAPTURE(rho_spline);
2027  CAPTURE(rho_EOS);
2028  CPS.disable_TTSE_LUT();
2029  CHECK(fabs(rho_spline/rho_EOS-1) < 1e-2);
2030  }
2031  }
2032  }
2033 }
2034 #endif
2035 
2036 
2039  { // TODO: Fix this
2040  throw ValueError("function invalid for incompressibles");
2041  }
2042  else if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP,p(),iH,h()) )
2043  {
2044  if (TwoPhase && _Q>0 && _Q < 1)
2045  {
2046  double hL = pFluid->TTSESatL.evaluate(iH,_p);
2047  double hV = pFluid->TTSESatV.evaluate(iH,_p);
2048  double rhoL = pFluid->TTSESatL.evaluate(iD,_p);
2049  double rhoV = pFluid->TTSESatV.evaluate(iD,_p);
2050  double dhdpL = pFluid->TTSESatL.evaluate_sat_derivative(iH,_p);
2051  double dhdpV = pFluid->TTSESatV.evaluate_sat_derivative(iH,_p);
2052  double dvdpL = -pFluid->TTSESatL.evaluate_sat_derivative(iD,_p)/rhoL/rhoL;
2053  double dvdpV = -pFluid->TTSESatV.evaluate_sat_derivative(iD,_p)/rhoV/rhoV;
2054 
2055  double dxdp_h = (dhdpL+_Q*(dhdpV-dhdpL))/(hL-hV);
2056  double dvdp_h = dvdpL+dxdp_h*(1/rhoV-1/rhoL)+_Q*(dvdpV-dvdpL);
2057 
2058  return -_rho*_rho*dvdp_h;
2059  }
2060  else
2061  {
2062  _h = h();
2064  }
2065  }
2066  else
2067  {
2068  if (TwoPhase)
2069  {
2070  double dhdpL = dhdp_along_sat_liquid();
2071  double dhdpV = dhdp_along_sat_vapor();
2072  double dvdpL = -drhodp_along_sat_liquid()/rhosatL/rhosatL;
2073  double dvdpV = -drhodp_along_sat_vapor()/rhosatV/rhosatV;
2074 
2075  double dxdp_h = (dhdpL+_Q*(dhdpV-dhdpL))/(hL()-hV());
2076  double dvdp_h = dvdpL+dxdp_h*(1/rhosatV-1/rhosatL)+_Q*(dvdpV-dvdpL);
2077  return -_rho*_rho*dvdp_h;
2078  }
2079  else
2080  {
2082  }
2083  }
2084 }
2085 
2087  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2088  if (TwoPhase) { throw ValueError("TwoPhase not supported for d2rhodh2_constp");}
2092  double ddT_drhodh_p_constrho = 1/A*d2pdT2_constrho()-1/(A*A)*dAdT_constrho*dpdT_constrho();
2093  double ddrho_drhodh_p_constT = 1/A*d2pdrhodT()-1/(A*A)*dAdrho_constT*dpdT_constrho();
2094  return ddT_drhodh_p_constrho/dhdT_constp()+ddrho_drhodh_p_constT/dhdrho_constp();
2095 }
2096 
2098  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2099  if (TwoPhase) { throw ValueError("TwoPhase not supported for d2rhodhdp");}
2103  double ddT_drhodp_h_constrho = -1/A*d2hdT2_constrho()+1/(A*A)*dAdT_constrho*dhdT_constrho();
2104  double ddrho_drhodp_h_constT = -1/A*d2hdrhodT()+1/(A*A)*dAdrho_constT*dhdT_constrho();
2105  return ddT_drhodp_h_constrho/dhdT_constp()+ddrho_drhodp_h_constT/dhdrho_constp();
2106 }
2107 
2109  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2110  double dpdrho_T = pFluid->R()*_T*(1+2*delta*dphir_dDelta(tau,delta)+delta*delta*d2phir_dDelta2(tau,delta));
2111  double dpdT_rho = pFluid->R()*_rho*(1+delta*dphir_dDelta(tau,delta)-delta*tau*d2phir_dDelta_dTau(tau,delta));
2112  return -dpdT_rho/dpdrho_T;
2113 }
2115  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2116  return pFluid->R()*_T*(1+2*delta*dphir_dDelta(tau,delta)+delta*delta*d2phir_dDelta2(tau,delta)); //[Pa/(kg/m3)]
2117 }
2119  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2121 }
2123  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2125 }
2127  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2129 }
2131  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2133 }
2135  double cv = this->cv();
2136  // Convert each derivative in terms of volume rather than density
2137  // Note drhodv = -rho^2
2138  double d2pdv2_constT = _rho*_rho*_rho*_rho*d2pdrho2_constT()+2*_rho*_rho*_rho*dpdrho_constT();
2139  double dpdT_constv = dpdT_constrho();
2140  double d2pdvdT = -_rho*_rho*d2pdrhodT();
2141  double d2pdT2_constv = d2pdT2_constrho();
2143  double LAMBDA1 = d2pdv2_constT;
2144  double LAMBDA2 = -3*_T/cv*dpdT_constv*d2pdvdT;
2145  double LAMBDA3 = +pow(_T/cv*dpdT_constv,2)*(3*d2pdT2_constv+1/_T*dpdT_constv*(1-_T/cv*dcv_dT_constv));
2146  return LAMBDA1 + LAMBDA2 + LAMBDA3;
2147 }
2149 {
2150  return this->d2pdv2_consts()/pow(this->speed_sound(),2)/2/pow(this->rho(),3);
2151 }
2152 
2154 // double dphir_dDelta = pFluid->dphir_dDelta(tau,delta);
2155 // double d2phir_dDelta_dTau = pFluid->d2phir_dDelta_dTau(tau,delta);
2156 // double d2phir_dDelta2 = pFluid->d2phir_dDelta2(tau,delta);
2157 // double dpdrho = R*T*(1+2*delta*dphir_dDelta+delta*delta*d2phir_dDelta2);
2158 // double dpdT = R*rho*(1+delta*dphir_dDelta-delta*tau*d2phir_dDelta_dTau);
2159 // double cp = -tau*tau*R*(pFluid->d2phi0_dTau2(tau,delta)+pFluid->d2phir_dTau2(tau,delta))+T/rho/rho*(dpdT*dpdT)/dpdrho;
2160 
2161  double dpdrho = this->dpdrho_constT();
2162  double dpdT = this->dpdT_constrho();
2163  double cp = this->cp();
2164  double drhodT = -dpdT/dpdrho;
2165  return -cp/dpdrho/drhodT-_T*drhodT*(-1/_rho/_rho)+1/_rho;
2166 }
2167 
2168 
2170  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2171  return 1+delta*dphir_dDelta(tau,delta);
2172 }
2174  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2176 }
2178  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2180 }
2181 
2183  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2184  // given by B*rhoc=lim(delta --> 0) [dphir_ddelta(tau)]
2185  return 1.0/pFluid->reduce.rho*pFluid->dphir_dDelta(tau,1e-12);
2186 }
2188  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2189  return 1.0/pFluid->reduce.rho*pFluid->d2phir_dDelta_dTau(tau,1e-12)*-pFluid->reduce.T/_T/_T;
2190 }
2192  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2193  // given by C*rhoc^2=lim(delta --> 0) [d2phir_dDelta2(tau)]
2194  return 1.0/(pFluid->reduce.rho*pFluid->reduce.rho)*pFluid->d2phir_dDelta2(tau,1e-12);
2195 }
2197  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2199 }
2200 
2201 
2202 // DERIVATIVES OF ENTHALPY FROM EOS
2204  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2206 }
2208  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2210 }
2212  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2214 }
2216  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2217  // d3phi0_dDelta_dTau2V is zero by definition
2219 }
2221  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2223 }
2224 
2225 // DERIVATIVES OF ENTROPY FROM EOS
2227  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2229 }
2231  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2233 }
2235  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2237 }
2239  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2241 }
2243  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2244  // d2phi0_dDelta_dTau2(tau,delta) is zero by definition
2246 }
2247 
2248 
2250  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2251  return -1/(_rho*_rho)/dpdrho_constT();
2252 }
2254  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2255  return -1/(_rho*_rho)*drhodT_constp();
2256 }
2257 
2259  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2261 }
2263  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2265 }
2266 // Enthalpy
2268  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2269  return dhdrho_constT()/dpdrho_constT();
2270 }
2272  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2274 }
2276  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2278 }
2280 {
2281  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2284  return ddT_dhdT-drho_dhdT*dpdT_constrho()/dpdrho_constT();
2285 }
2287 {
2288  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2289  return (d2hdrho2_constT()-dhdp_constT()*d2pdrho2_constT())/pow(dpdrho_constT(),2);
2290 }
2292 {
2293  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2295 }
2296 
2297 // Entropy
2299  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2300  return dsdrho_constT()/dpdrho_constT();
2301 }
2303  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2305 }
2307  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2309 }
2311 {
2312  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2315  return ddT_dsdT-drho_dsdT*dpdT_constrho()/dpdrho_constT();
2316 }
2318 {
2319  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2320  return (d2sdrho2_constT()-dsdp_constT()*d2pdrho2_constT())/pow(dpdrho_constT(),2);
2321 }
2323 {
2324  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2326 }
2327 
2329 {
2330  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2331  return 1/dpdrho_constT();
2332 }
2334 {
2335  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2336  return -d2pdrho2_constT()/pow(dpdrho_constT(),3);
2337 }
2339 {
2340  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2342 }
2344 {
2345  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2346  double ddrho_drhodT_p_constT = (dpdT_constrho()*d2pdrho2_constT()-dpdrho_constT()*d2pdrhodT())/pow(dpdrho_constT(),2);
2347  double ddT_drhodT_p_constrho = (dpdT_constrho()*d2pdrhodT()-dpdrho_constT()*d2pdT2_constrho())/pow(dpdrho_constT(),2);
2348  return ddT_drhodT_p_constrho+ddrho_drhodT_p_constT*drhodT_constp();
2349 }
2351 {
2352  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2353  return 2/_rho*pow(drhodh_constp(),2)*(hV() - hL());
2354 }
2356 {
2357  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2358  double d2vdhdp = 1/_T*d2Tdp2_along_sat() - pow(dTdp_along_sat()/_T,2);
2359  return (2/_rho*drhodp_consth()*drhodh_constp()-pow(_rho,2)*d2vdhdp)*(hV() - hL());
2360 }
2361 
2365 
2367 {
2368  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2369  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2370  if (pFluid->enabled_TTSE_LUT)
2371  {
2374  }
2375  else{
2376  return _T*(1/SatV->rho()-1/SatL->rho())/(SatV->h()-SatL->h());
2377  }
2378 }
2380 {
2381  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2382  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2383  return 1/(SatV->h()-SatL->h())*(_T*(SatV->dvdp_constT()-SatL->dvdp_constT())-dTdp_along_sat()*(SatV->dhdp_constT()-SatL->dhdp_constT()));
2384 }
2386 {
2387  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2388  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2389  return 1/(SatV->h()-SatL->h())*(_T*(SatV->dvdT_constp()-SatL->dvdT_constp())-dTdp_along_sat()*(SatV->dhdT_constp()-SatL->dhdT_constp())+(1/SatV->rho()-1/SatL->rho()));
2390 }
2392 {
2393  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2394  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2396 }
2397 
2399 {
2400  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2401  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2402  if (pFluid->enabled_TTSE_LUT){
2405  }
2406  else{
2408  }
2409 }
2411 {
2412  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2413  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2414  if (pFluid->enabled_TTSE_LUT){
2417  }
2418  else{
2420  }
2421 }
2423 {
2424  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2425  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2426  double ddp_dhdpsigmaV = SatV->d2hdp2_constT()+SatV->dhdT_constp()*ddp_dTdp_along_sat()+SatV->d2hdTdp()*dTdp_along_sat();
2427  double ddT_dhdpsigmaV = SatV->d2hdTdp()+SatV->dhdT_constp()*ddT_dTdp_along_sat()+SatV->d2hdT2_constp()*dTdp_along_sat();
2428  return ddp_dhdpsigmaV+ddT_dhdpsigmaV*dTdp_along_sat();
2429 }
2431 {
2432  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2433  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2434  double ddp_dhdpsigmaL = SatL->d2hdp2_constT()+SatL->dhdT_constp()*ddp_dTdp_along_sat()+SatL->d2hdTdp()*dTdp_along_sat();
2435  double ddT_dhdpsigmaL = SatL->d2hdTdp()+SatL->dhdT_constp()*ddT_dTdp_along_sat()+SatL->d2hdT2_constp()*dTdp_along_sat();
2436  return ddp_dhdpsigmaL+ddT_dhdpsigmaL*dTdp_along_sat();
2437 }
2438 
2440 {
2441  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2442  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2444 }
2446 {
2447  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2448  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2450 }
2452 {
2453  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2454  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2455  double ddp_dsdpsigmaV = SatV->d2sdp2_constT()+SatV->dsdT_constp()*ddp_dTdp_along_sat()+SatV->d2sdTdp()*dTdp_along_sat();
2456  double ddT_dsdpsigmaV = SatV->d2sdTdp()+SatV->dsdT_constp()*ddT_dTdp_along_sat()+SatV->d2sdT2_constp()*dTdp_along_sat();
2457  return ddp_dsdpsigmaV+ddT_dsdpsigmaV*dTdp_along_sat();
2458 }
2460 {
2461  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2462  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2463  double ddp_dsdpsigmaL = SatL->d2sdp2_constT()+SatL->dsdT_constp()*ddp_dTdp_along_sat()+SatL->d2sdTdp()*dTdp_along_sat();
2464  double ddT_dsdpsigmaL = SatL->d2sdTdp()+SatL->dsdT_constp()*ddT_dTdp_along_sat()+SatL->d2sdT2_constp()*dTdp_along_sat();
2465  return ddp_dsdpsigmaL+ddT_dsdpsigmaL*dTdp_along_sat();
2466 }
2467 
2469 {
2470  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2471  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2472  if (pFluid->enabled_TTSE_LUT)
2473  {
2476  }
2477  else
2478  {
2480  }
2481 }
2483 {
2484  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2485  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2486  if (pFluid->enabled_TTSE_LUT)
2487  {
2490  }
2491  else
2492  {
2494  }
2495 }
2497 {
2498  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2499  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2500  double ddp_drhodpsigmaV = SatV->d2rhodp2_constT()+SatV->drhodT_constp()*ddp_dTdp_along_sat()+SatV->d2rhodTdp()*dTdp_along_sat();
2501  double ddT_drhodpsigmaV = SatV->d2rhodTdp()+SatV->drhodT_constp()*ddT_dTdp_along_sat()+SatV->d2rhodT2_constp()*dTdp_along_sat();
2502  return ddp_drhodpsigmaV+ddT_drhodpsigmaV*dTdp_along_sat();
2503 }
2505 {
2506  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2507  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2508  double ddp_drhodpsigmaL = SatL->d2rhodp2_constT()+SatL->drhodT_constp()*ddp_dTdp_along_sat()+SatL->d2rhodTdp()*dTdp_along_sat();
2509  double ddT_drhodpsigmaL = SatL->d2rhodTdp()+SatL->drhodT_constp()*ddT_dTdp_along_sat()+SatL->d2rhodT2_constp()*dTdp_along_sat();
2510  return ddp_drhodpsigmaL+ddT_drhodpsigmaL*dTdp_along_sat();
2511 }
2512 
2514 {
2515  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2517 }
2519 {
2520  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2522 }
2523 
2525 {
2526  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2528 }
2530 {
2531  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2533 }
2534 
2536 {
2537  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2538  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2540 }
2542 {
2543  if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID || fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION){throw ValueError("function invalid for incompressibles");}
2544  if (!TwoPhase){throw ValueError(format("Saturation derivative cannot be called now. Call update() with a two-phase set of inputs"));}
2546 }
2547 
2548 // All the derivatives of the ideal-gas and residual Helmholtz energy
2549 double CoolPropStateClassSI::phi0(double tau, double delta){
2550  if (cache.phi0)
2551  {
2552  return cache.phi0;
2553  }
2554  else
2555  {
2556  cache.phi0 = pFluid->phi0(tau,delta);
2557  return cache.phi0;
2558  }
2559 };
2560 double CoolPropStateClassSI::dphi0_dDelta(double tau, double delta){
2561  if (cache.dphi0_dDelta)
2562  {
2563  return cache.dphi0_dDelta;
2564  }
2565  else
2566  {
2567  cache.dphi0_dDelta = pFluid->dphi0_dDelta(tau,delta);
2568  return cache.dphi0_dDelta;
2569  }
2570 };
2571 double CoolPropStateClassSI::dphi0_dTau(double tau, double delta){
2572  if (cache.dphi0_dTau)
2573  {
2574  return cache.dphi0_dTau;
2575  }
2576  else
2577  {
2578  cache.dphi0_dTau = pFluid->dphi0_dTau(tau,delta);
2579  return cache.dphi0_dTau;
2580  }
2581 };
2582 double CoolPropStateClassSI::d2phi0_dDelta2(double tau, double delta){
2583  if (cache.d2phi0_dDelta2)
2584  {
2585  return cache.d2phi0_dDelta2;
2586  }
2587  else
2588  {
2589  cache.d2phi0_dDelta2 = pFluid->d2phi0_dDelta2(tau,delta);
2590  return cache.d2phi0_dDelta2;
2591  }
2592 };
2593 double CoolPropStateClassSI::d2phi0_dDelta_dTau(double tau, double delta){
2595  {
2596  return cache.d2phi0_dDelta_dTau;
2597  }
2598  else
2599  {
2601  return cache.d2phi0_dDelta_dTau;
2602  }
2603 };
2604 double CoolPropStateClassSI::d2phi0_dTau2(double tau, double delta){
2605  if (cache.d2phi0_dTau2)
2606  {
2607  return cache.d2phi0_dTau2;
2608  }
2609  else
2610  {
2611  cache.d2phi0_dTau2 = pFluid->d2phi0_dTau2(tau,delta);
2612  return cache.d2phi0_dTau2;
2613  }
2614 };
2615 
2616 double CoolPropStateClassSI::d3phi0_dTau3(double tau, double delta){
2617  if (cache.d3phi0_dTau3)
2618  {
2619  return cache.d3phi0_dTau3;
2620  }
2621  else
2622  {
2623  cache.d3phi0_dTau3 = pFluid->d3phi0_dTau3(tau,delta);
2624  return cache.d3phi0_dTau3;
2625  }
2626 };
2627 
2628 double CoolPropStateClassSI::d3phi0_dDelta_dTau2(double tau, double delta){
2629  return 0;
2630 };
2631 
2632 double CoolPropStateClassSI::d3phi0_dDelta2_dTau(double tau, double delta){
2633  return 0;
2634 };
2635 
2636 double CoolPropStateClassSI::d3phi0_dDelta3(double tau, double delta){
2637  if (cache.d3phi0_dDelta3)
2638  {
2639  return cache.d3phi0_dDelta3;
2640  }
2641  else
2642  {
2643  cache.d3phi0_dDelta3 = pFluid->d3phi0_dDelta3(tau,delta);
2644  return cache.d3phi0_dDelta3;
2645  }
2646 };
2647 
2648 
2649 double CoolPropStateClassSI::phir(double tau, double delta){
2650  if (cache.phir)
2651  {
2652  return cache.phir;
2653  }
2654  else
2655  {
2656  cache.phir = pFluid->phir(tau,delta);
2657  return cache.phir;
2658  }
2659 };
2660 double CoolPropStateClassSI::dphir_dDelta(double tau, double delta){
2661  if (cache.dphir_dDelta)
2662  {
2663  return cache.dphir_dDelta;
2664  }
2665  else
2666  {
2667  cache.dphir_dDelta = pFluid->dphir_dDelta(tau,delta);
2668  return cache.dphir_dDelta;
2669  }
2670 };
2671 double CoolPropStateClassSI::dphir_dTau(double tau, double delta){
2672  if (cache.dphir_dTau)
2673  {
2674  return cache.dphir_dTau;
2675  }
2676  else
2677  {
2678  cache.dphir_dTau = pFluid->dphir_dTau(tau,delta);
2679  return cache.dphir_dTau;
2680  }
2681 };
2682 double CoolPropStateClassSI::d2phir_dDelta2(double tau, double delta){
2683  if (cache.d2phir_dDelta2)
2684  {
2685  return cache.d2phir_dDelta2;
2686  }
2687  else
2688  {
2689  cache.d2phir_dDelta2 = true;
2690  cache.d2phir_dDelta2 = pFluid->d2phir_dDelta2(tau,delta);
2691  return cache.d2phir_dDelta2;
2692  }
2693 };
2694 double CoolPropStateClassSI::d2phir_dDelta_dTau(double tau, double delta){
2696  {
2697  return cache.d2phir_dDelta_dTau;
2698  }
2699  else
2700  {
2702  return cache.d2phir_dDelta_dTau;
2703  }
2704 };
2705 double CoolPropStateClassSI::d2phir_dTau2(double tau, double delta){
2706  if (cache.d2phir_dTau2)
2707  {
2708  return cache.d2phir_dTau2;
2709  }
2710  else
2711  {
2712  cache.d2phir_dTau2 = pFluid->d2phir_dTau2(tau,delta);
2713  return cache.d2phir_dTau2;
2714  }
2715 };
2716 
2717 double CoolPropStateClassSI::d3phir_dTau3(double tau, double delta){
2718  if (cache.d3phir_dTau3)
2719  {
2720  return cache.d3phir_dTau3;
2721  }
2722  else
2723  {
2724  cache.d3phir_dTau3 = pFluid->d3phir_dTau3(tau,delta);
2725  return cache.d3phir_dTau3;
2726  }
2727 };
2728 
2729 double CoolPropStateClassSI::d3phir_dDelta_dTau2(double tau, double delta){
2731  {
2732  return cache.d3phir_dDelta_dTau2;
2733  }
2734  else
2735  {
2737  return cache.d3phir_dDelta_dTau2;
2738  }
2739 };
2740 
2741 double CoolPropStateClassSI::d3phir_dDelta2_dTau(double tau, double delta){
2743  {
2744  return cache.d3phir_dDelta2_dTau;
2745  }
2746  else
2747  {
2749  return cache.d3phir_dDelta2_dTau;
2750  }
2751 };
2752 
2753 double CoolPropStateClassSI::d3phir_dDelta3(double tau, double delta){
2754  if (cache.d3phir_dDelta3)
2755  {
2756  return cache.d3phir_dDelta3;
2757  }
2758  else
2759  {
2760  cache.d3phir_dDelta3 = pFluid->d3phir_dDelta3(tau,delta);
2761  return cache.d3phir_dDelta3;
2762  }
2763 };
2765 double CoolPropStateClassSI::interp_linear(double Q, double valueL, double valueV) {
2766  return valueL+Q*(valueV-valueL);
2767 }
2768 double CoolPropStateClassSI::interp_recip(double Q, double valueL, double valueV){
2769  return 1.0 / interp_linear(Q, 1.0/valueL, 1.0/valueV);
2770 }
2794 void CoolPropStateClassSI::set_TTSESinglePhase_LUT_range(double hmin, double hmax, double pmin, double pmax){pFluid->set_TTSESinglePhase_LUT_range(hmin,hmax,pmin,pmax);};
2796 void CoolPropStateClassSI::get_TTSESinglePhase_LUT_range(double *hmin, double *hmax, double *pmin, double *pmax){pFluid->get_TTSESinglePhase_LUT_range(hmin,hmax,pmin,pmax);};
2797 
2798 
2799 
2800 // Default constructor for CoolPropStateClass
2803 {
2804 }
2805 
2807  : CoolPropStateClassSI(pFluid)
2808 {
2809 }
2810 
2812  : CoolPropStateClassSI(FluidName)
2813 {
2814 }
2815 
2816 
2817 
2818 void CoolPropStateClass::update(long iInput1, double Value1, long iInput2, double Value2)
2819 {
2820  double val1 = convert_from_unit_system_to_SI(iInput1, Value1, get_standard_unit_system());
2821  double val2 = convert_from_unit_system_to_SI(iInput2, Value2, get_standard_unit_system());
2822  if (get_debug_level() > 8)
2823  {
2824  std::cout << format("%s:%d: CoolPropStateClass::update(%d,%g,%d,%g)\n",__FILE__,__LINE__,iInput1,Value1,iInput2,Value2).c_str();
2825  }
2826  CoolPropStateClassSI::update(iInput1, val1, iInput2, val2);
2827 }
2828 
2829 
2830 
2831 
2835 #ifndef DISABLE_CATCH
2836 #include "Catch/catch.hpp"
2837 TEST_CASE((char*)"Check REFPROP and coolprop state classes match", "")
2838 {
2839  CoolPropStateClassSI CPWater("Water");
2840  CoolPropStateClassSI RPWater("REFPROP-Water");
2841 
2842  SECTION((char*)"check T,rho -> p")
2843  {
2844  double T = 313, rho = 1;
2845  CPWater.update(iT,T,iD,rho);
2846  RPWater.update(iT,T,iD,rho);
2847  REQUIRE(fabs(CPWater.p() - RPWater.p()) < 1e-4);
2848  }
2849  SECTION((char*)"check T,p -> rho")
2850  {
2851  double T = 313, p = 101325;
2852  CPWater.update(iT,T,iP,p);
2853  RPWater.update(iT,T,iP,p);
2854  double RPrho = RPWater.rho();
2855  double CPrho = CPWater.rho();
2856  CAPTURE(RPrho);
2857  CAPTURE(CPrho);
2858  REQUIRE(fabs(RPrho - CPrho) < 1e-4);
2859  }
2860  SECTION((char*)"check cp")
2861  {
2862  double T = 313, p = 101325;
2863  CPWater.update(iT,T,iP,p);
2864  RPWater.update(iT,T,iP,p);
2865  double RPcp = RPWater.cp();
2866  double CPcp = CPWater.cp();
2867  CAPTURE(RPcp);
2868  CAPTURE(CPcp);
2869  REQUIRE(fabs(RPcp - CPcp) < 1e-4);
2870  }
2871  SECTION((char*)"check cv")
2872  {
2873  double T = 313, p = 101325;
2874  CPWater.update(iT,T,iP,p);
2875  RPWater.update(iT,T,iP,p);
2876  double RPcv = RPWater.cv();
2877  double CPcv = CPWater.cv();
2878  CAPTURE(RPcv);
2879  CAPTURE(CPcv);
2880  REQUIRE(fabs(RPcv - CPcv) < 1e-4);
2881  }
2882  SECTION((char*)"check viscosity")
2883  {
2884  double T = 313, p = 101325;
2885  CPWater.update(iT,T,iP,p);
2886  RPWater.update(iT,T,iP,p);
2888  double CPvisc = CPWater.viscosity();
2889  CAPTURE(RPvisc);
2890  CAPTURE(CPvisc);
2891  REQUIRE(fabs(RPvisc - CPvisc) < 1e-4);
2892  }
2893  SECTION((char*)"check conductivity")
2894  {
2895  double T = 313, p = 101325;
2896  CPWater.update(iT,T,iP,p);
2897  RPWater.update(iT,T,iP,p);
2899  double CPcond = CPWater.conductivity();
2900  CAPTURE(RPcond);
2901  CAPTURE(CPcond);
2902  REQUIRE(fabs(RPcond - CPcond) < 1e-4);
2903  }
2904  SECTION((char*)"check surface tension")
2905  {
2906  double T = 313, p = 101325;
2907  CPWater.update(iT,T,iP,p);
2908  RPWater.update(iT,T,iP,p);
2910  double CPsigma = CPWater.surface_tension();
2911  CAPTURE(RPsigma);
2912  CAPTURE(CPsigma);
2913  REQUIRE(fabs(RPsigma - CPsigma) < 1e-4);
2914  }
2915 }
2916 #endif
double dhdp_constrho(void)
Definition: CPState.cpp:2153
TEST_CASE("Check of density smoothing derivatives","[normal]")
Definition: CPState.cpp:1947
double d2pdv2_consts(void)
Definition: CPState.cpp:2134
double CPsigma
Definition: CPState.cpp:2910
double dsdp_constT(void)
Definition: CPState.cpp:2298
double conductivity(void)
Definition: CPState.cpp:1524
double drhodp_along_sat_vapor(void)
Definition: CPState.cpp:2468
void update_Ts(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:719
double interp_recip(double Q, double valueL, double valueV)
Definition: CPState.cpp:2768
Fluid * get_fluid(long iFluid)
Definition: CoolProp.cpp:236
double cpV(void)
Definition: CPState.cpp:1376
double d2rhodhdQ(void)
Definition: CPState.cpp:2350
virtual double d3phir_dDelta_dTau2(double tau, double delta)
Definition: FluidClass.cpp:362
CoolPropStateClassSI RPWater("REFPROP-Water")
double R()
Returns the mass-specific gas constant for the fluid in the desired units.
virtual double d2phi0_dTau2(double tau, double delta)
Definition: FluidClass.cpp:411
std::string brine_string
Temporary until solutions are fixed.
Definition: CPState.h:104
double dphi0_dDelta(double tau, double delta)
Definition: CPState.cpp:2560
void _pre_update(void)
Definition: CPState.cpp:177
bool match_pair(long iI1, long iI2, long I1, long I2)
Definition: CPState.cpp:132
double evaluate(long iParam, double p, double logp, double h)
Definition: TTSE.cpp:1487
CAPTURE(RPrho)
double hV(void)
Definition: CPState.cpp:1341
double keyed_output(long iInput)
Return an output based on the integer key for the term.
Definition: CPState.cpp:1077
virtual double d2phir_dDelta_dTau(double tau, double delta)
Definition: FluidClass.cpp:329
void disable_TTSE_LUT_writing(void)
Disable the writing of TTSE tables to file.
Definition: CPState.cpp:2788
virtual void temperature_ph(double p, double h, double &Tout, double &rhoout, double &rhoL, double &rhoV, double &TsatLout, double &TsatVout, double T0=-1, double rho0=-1)
long get_Fluid_index(std::string FluidName)
Definition: CoolProp.cpp:239
double isothermal_compressibility(void)
Definition: CPState.cpp:1673
double CPrho
Definition: CPState.cpp:2855
double dphir_dTau(double tau, double delta)
Definition: CPState.cpp:2671
bool build_TTSE_LUT(bool force=false)
Build of the TTSE LUT.
double rhoL(void)
Definition: CPState.h:265
virtual void temperature_ps(double p, double s, double &Tout, double &rhoout, double &rhoL, double &rhoV, double &TsatLout, double &TsatVout)
struct FluidLimits limits
Definition: FluidClass.h:219
virtual double d3phir_dDelta3(double tau, double delta)
Definition: FluidClass.cpp:353
virtual double density_Tp(double T, double p)
Definition: FluidClass.cpp:719
virtual void temperature_hs(double h, double s, double &Tout, double &rhoout, double &rhoL, double &rhoV, double &TsatLout, double &TsatVout)
double dhdp_along_sat_vapor(void)
Definition: CPState.cpp:2410
double Tsat(double Q)
Saturation temperature.
Definition: CPState.cpp:143
double dsdrho_constT(void)
Definition: CPState.cpp:2226
void enable_TTSE_LUT_writing(void)
Enable the writing of TTSE tables to file.
void update_twophase(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:330
void set_TTSESinglePhase_LUT_size(int Np, int Nh)
Over-ride the default size of the single-phase LUT.
Definition: CPState.cpp:2792
double Tsat_anc(double p, double Q)
bool isenabled_TTSE_LUT_writing(void)
Check if the writing of TTSE tables to file is enabled.
double d2phir_dDelta_dTau(double tau, double delta)
Definition: CPState.cpp:2694
void update_ps(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:637
double dsdT_along_sat_vapor(void)
Definition: CPState.cpp:2529
double dhdT_constp(void)
Definition: CPState.cpp:2271
virtual double d3phi0_dTau3(double tau, double delta)
Definition: FluidClass.cpp:419
double psatV_anc(double T)
Definition: FluidClass.h:380
#define WHEN(desc)
Definition: catch.hpp:8110
double d2sdrho2_constT(void)
Definition: CPState.cpp:2238
void no_SatLSatV(void)
Stop it from adding the SatL and SatV class pointers.
Definition: CPState.h:252
bool enabled_EXTTP
Definition: FluidClass.h:584
CachedElement d2phir_dDelta2
Definition: CPState.h:56
double specific_heat_p_ideal_Trho(double T)
Definition: FluidClass.cpp:497
double d2rhodp2_along_sat_liquid(void)
Definition: CPState.cpp:2504
PressureUnit p
Definition: FluidClass.h:50
virtual double d3phir_dTau3(double tau, double delta)
Definition: FluidClass.cpp:346
double drhodp_consth(void)
Definition: CPState.cpp:2037
void update_hs(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:679
double d3phir_dDelta3(double tau, double delta)
Definition: CPState.cpp:2753
double phir(double tau, double delta)
Definition: CPState.cpp:2649
virtual double phi0(double tau, double delta)
Definition: FluidClass.cpp:381
EXPORT_CODE int CONVENTION get_debug_level()
double Props(std::string Output, std::string Name1, double Prop1, std::string Name2, double Prop2, std::string Ref)
Definition: CoolProp.cpp:902
void set_TTSESinglePhase_LUT_range(double hmin, double hmax, double pmin, double pmax)
Over-ride the default range of the single-phase LUT.
double d2hdp2_along_sat_vapor(void)
Definition: CPState.cpp:2422
void enable_EXTTP(void)
double Pa
Definition: Units.h:22
double d3phi0_dTau3(double tau, double delta)
Definition: CPState.cpp:2616
void enable_TTSE_LUT(void)
Enable the TTSE.
Definition: CPState.cpp:2778
double d3phir_dDelta_dTau2(double tau, double delta)
Definition: CPState.cpp:2729
double d2rhodh2_constp(void)
Definition: CPState.cpp:2086
double d2sdrhodT(void)
Definition: CPState.cpp:2242
double ddp_dTdp_along_sat(void)
Partial derivative w.r.t. pressure of dTdp along saturation curve.
Definition: CPState.cpp:2379
void disable_EXTTP(void)
Disable the TTSE.
void get_TTSESinglePhase_LUT_range(double *hmin, double *hmax, double *pmin, double *pmax)
Get the current range of the single-phase LUT.
Definition: CPState.cpp:2796
double dhdT_along_sat_vapor(void)
Definition: CPState.cpp:2518
double dCdT(void)
Definition: CPState.cpp:2196
double TL(void)
Definition: CPState.h:269
virtual double d3phi0_dDelta3(double tau, double delta)
Definition: FluidClass.h:274
std::string getName() const
Definition: IncompBase.h:31
double pL(void)
Definition: CPState.h:267
double dpdT_consth(void)
Definition: CPState.cpp:2258
double CPvisc
Definition: CPState.cpp:2888
double dvdp_constT(void)
Definition: CPState.cpp:2249
double surface_tension(void)
Definition: CPState.cpp:1740
IncompressibleLiquid * pIncompLiquid
A pointer to the class for an incompressible liquid.
Definition: CPState.h:189
double molemass
Definition: FluidClass.h:43
void update(long iInput1, double Value1, long iInput2, double Value2, double T0=-1, double rho0=-1)
Definition: CPState.cpp:213
double d2hdp2_along_sat_liquid(void)
Definition: CPState.cpp:2430
long phase_prho_indices(double p, double rho, double &T, double &TL, double &TV, double &rhoL, double &rhoV)
double dhdrho_constp(void)
Definition: CPState.cpp:2275
double dZdDelta(void)
Definition: CPState.cpp:2173
double psatL_anc(double T)
Definition: FluidClass.h:374
double d2phi0_dDelta2(double tau, double delta)
Definition: CPState.cpp:2582
virtual double dphi0_dTau(double tau, double delta)
Definition: FluidClass.cpp:403
double drhodp_constT(void)
Definition: CPState.cpp:2328
double CPcv
Definition: CPState.cpp:2877
bool double_equal(double a, double b)
double d2rhodp2_along_sat_vapor(void)
Definition: CPState.cpp:2496
EXPORT_CODE int CONVENTION get_standard_unit_system(void)
#define DBL_EPSILON
Definition: Helmholtz.cpp:10
struct CriticalStruct reduce
A pointer to the point that is used to reduce the T and rho for EOS.
Definition: FluidClass.h:222
double d2sdTdp(void)
Definition: CPState.cpp:2322
double ddT_dTdp_along_sat(void)
Partial derivative w.r.t. temperature of dTdp along saturation curve.
Definition: CPState.cpp:2385
bool isenabled_TTSE_LUT(void)
Check if TTSE is enabled.
Definition: CPState.cpp:2780
long phase_Trho_indices(double T, double rho, double &pL, double &pV, double &rhoL, double &rhoV)
Return the phase using the phase flags from phase enum in CoolProp.h.
double Z(void)
Definition: CPState.cpp:2169
double sL(void)
Definition: CPState.cpp:1352
double drhodh_constp_smoothed(double xend)
A smoothed version of the derivative using a spline curve in the region of x=0 to x=xend...
Definition: CPState.cpp:1821
CachedElement d2phir_dDelta_dTau
Definition: CPState.h:56
double d3phi0_dDelta2_dTau(double tau, double delta)
Definition: CPState.cpp:2632
void set_TTSESinglePhase_LUT_size(int Np, int Nh)
Over-ride the default size of the single-phase LUT.
std::string get_name()
Returns a std::string with the name of the fluid.
Definition: FluidClass.h:235
double Tmax
Definition: FluidClass.h:54
double dsdrho_constp(void)
Definition: CPState.cpp:2306
double Ttriple
Definition: FluidClass.h:43
virtual double surface_tension_T(double T)
CachedElement phi0
Definition: CPState.h:56
virtual double rhosatV(double T)
Definition: FluidClass.h:371
double dZdTau(void)
Definition: CPState.cpp:2177
std::string format(const char *fmt,...)
double dphi0_dTau(double tau, double delta)
Definition: CPState.cpp:2571
CachedElement d3phir_dDelta2_dTau
Definition: CPState.h:56
double d2hdp2_constT(void)
Definition: CPState.cpp:2286
double superheat(void)
Definition: CPState.cpp:159
double cp(void)
Definition: CPState.cpp:1460
Fluid * pFluid
A pointer to a CoolProp fluid.
Definition: CPState.h:195
double evaluate_first_derivative(long iOF, long iWRT, long iCONSTANT, double p, double logp, double h)
Definition: TTSE.cpp:2491
TTSETwoPhaseTableClass TTSESatV
Definition: FluidClass.h:227
Fluid is the abstract base class that is employed by all the other fluids.
Definition: FluidClass.h:147
double d2sdT2_constp(void)
Definition: CPState.cpp:2310
double B_over_D_TTSE(double _p, double _h)
Get the ratio directly which is just a bit faster.
Definition: CPState.cpp:1565
virtual double rho(double T_K, double p)
Density as a function of temperature and pressure.
Definition: IncompLiquid.h:32
double d2rhodTdp(void)
Definition: CPState.cpp:2338
void set_TTSESinglePhase_LUT_range(double hmin, double hmax, double pmin, double pmax)
Over-ride the default range of the single-phase LUT.
Definition: CPState.cpp:2794
void sort_pair(long *iInput1, double *Value1, long *iInput2, double *Value2, long I1, long I2)
Definition: CPState.cpp:136
double Q(void)
Definition: CPState.h:292
double CPcond
Definition: CPState.cpp:2899
double d2phir_dDelta2(double tau, double delta)
Definition: CPState.cpp:2682
CachedElement d2phi0_dTau2
Definition: CPState.h:56
virtual double dphir_dTau(double tau, double delta)
Definition: FluidClass.cpp:295
void disable_EXTTP(void)
Disable the extended two-phase calculations.
Definition: CPState.cpp:2776
virtual double dphi0_dDelta(double tau, double delta)
Definition: FluidClass.cpp:389
EnvironmentalFactorsStruct environment
Definition: FluidClass.h:176
double d2hdrhodT(void)
Definition: CPState.cpp:2215
double RPcv
Definition: CPState.cpp:2876
CachedElement dphir_dTau
Definition: CPState.h:56
CachedElement d2phi0_dDelta_dTau
Definition: CPState.h:56
long phase_Tp_indices(double T, double p, double &pL, double &pV, double &rhoL, double &rhoV)
Return the phase using the phase flags from phase enum in CoolProp.h.
void enable_TTSE_LUT(void)
double C(void)
Definition: CPState.cpp:2191
bool isenabled_TTSE_LUT_writing(void)
Check if the writing of TTSE tables to file is enabled.
Definition: CPState.cpp:2786
double dhdrho_constT(void)
Definition: CPState.cpp:2203
void set_TTSESat_LUT_size(int Nsat)
Over-ride the default size of both of the saturation LUT.
double dpdrho_constT(void)
Definition: CPState.cpp:2114
double d2sdp2_constT(void)
Definition: CPState.cpp:2317
TTSESinglePhaseTableClass TTSESinglePhase
Definition: FluidClass.h:228
std::vector< double > x(ncmax, 0)
void update_TTSE_LUT(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:761
double dhdp_along_sat_liquid(void)
Definition: CPState.cpp:2398
CachedElement d3phir_dDelta_dTau2
Definition: CPState.h:56
double speed_sound(void)
Definition: CPState.cpp:1627
double condL(void)
Definition: CPState.cpp:1379
bool isenabled_EXTTP(void)
Check if TTSE is enabled.
double drhodT_constp(void)
Definition: CPState.cpp:2108
double rhoV(void)
Definition: CPState.h:266
struct OtherParameters params
Definition: FluidClass.h:220
void update_incompressible(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:1020
double evaluate(double x)
Definition: Spline.cpp:62
IncompressibleSolution * get_solution(long index)
bool add_value_constraint(double x, double y)
Definition: Spline.cpp:29
double dhdp_constT(void)
Definition: CPState.cpp:2267
double hL(void)
Definition: CPState.cpp:1330
double CPcp
Definition: CPState.cpp:2866
double d2hdT2_constrho(void)
Definition: CPState.cpp:2220
void update_ph(long iInput1, double Value1, long iInput2, double Value2, double T0=-1, double rho0=-1)
Definition: CPState.cpp:598
double RPvisc
Definition: CPState.cpp:2887
double Prandtl(void)
Definition: CPState.cpp:1553
void clear()
Definition: CPState.h:62
StateCache cache
Definition: CPState.h:106
double RPrho
Definition: CPState.cpp:2854
double d2hdT2_constp(void)
Definition: CPState.cpp:2279
double viscosity(void)
Definition: CPState.cpp:1494
CriticalSplineStruct_T CriticalSpline_T
Definition: FluidClass.h:231
LiquidsContainer LiquidsList
Definition: CPState.cpp:25
double dsdp_along_sat_vapor(void)
Definition: CPState.cpp:2445
CachedElement dphi0_dDelta
Definition: CPState.h:56
double cpL(void)
Definition: CPState.cpp:1375
void set_TTSESat_LUT_size(int N)
Over-ride the default size of both of the saturation LUT.
Definition: CPState.cpp:2790
double d2rhodT2_constp(void)
Definition: CPState.cpp:2343
double dphir_dDelta(double tau, double delta)
Definition: CPState.cpp:2660
double B_TTSE(double _p, double _h)
Evaluate the B term from TTSE method.
Definition: CPState.cpp:1557
bool add_REFPROP_fluid(std::string FluidName)
Add a REFPROP fluid to the fluid listing in CoolProp.
Definition: CoolProp.cpp:253
CachedElement d3phi0_dTau3
Definition: CPState.h:56
double pmax
Definition: FluidClass.h:54
bool IsIncompressibleLiquid(std::string name)
virtual double s(double T_K, double p)
Entropy as a function of temperature and pressure.
Definition: IncompLiquid.h:38
double fundamental_derivative_of_gas_dynamics(void)
Definition: CPState.cpp:2148
double dhdT_along_sat_liquid(void)
Definition: CPState.cpp:2513
double d2hdTdp(void)
Definition: CPState.cpp:2291
void disable_TTSE_LUT_writing(void)
Disable the writing of TTSE tables to file.
double d2Tdp2_along_sat(void)
Second derivative of temperature w.r.t. pressure along saturation curve.
Definition: CPState.cpp:2391
double evaluate(long iParam, double p)
Definition: TTSE.cpp:2699
params
virtual double d2phir_dDelta2(double tau, double delta)
Definition: FluidClass.cpp:276
void update_prho(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:486
double drhodT_along_sat_liquid(void)
Definition: CPState.cpp:2541
CachedElement phir
Definition: CPState.h:56
struct CriticalStruct crit
Definition: FluidClass.h:218
double evaluate_T(double T)
Definition: TTSE.cpp:2786
bool IsIncompressibleSolution(std::string name)
double d2phir_dTau2(double tau, double delta)
Definition: CPState.cpp:2705
double p(void)
Definition: CPState.h:291
double d2pdrho2_constT(void)
Definition: CPState.cpp:2122
#define THEN(desc)
Definition: catch.hpp:8112
double sV(void)
Definition: CPState.cpp:1363
double d2sdT2_constrho(void)
Definition: CPState.cpp:2234
double d3phi0_dDelta_dTau2(double tau, double delta)
Definition: CPState.cpp:2628
double h(void)
Definition: CPState.cpp:1382
virtual double c(double T_K, double p)
Heat capacities as a function of temperature and pressure.
Definition: IncompLiquid.h:34
double drhodh_constp(void)
Definition: CPState.cpp:1745
double d2rhodhdp(void)
Definition: CPState.cpp:2097
virtual double h(double T_K, double p)
Enthalpy as a function of temperature and pressure.
Definition: IncompLiquid.h:42
CachedElement dphi0_dTau
Definition: CPState.h:56
virtual double phir(double tau, double delta)
Definition: FluidClass.cpp:237
REQUIRE(fabs(CPWater.p()-RPWater.p())< 1e-4)
double d2sdp2_along_sat_vapor(void)
Definition: CPState.cpp:2451
bool enabled_TTSE_LUT
Parameters for the Tabular Taylor Series Expansion (TTSE) Method.
Definition: FluidClass.h:584
double ptriple
Definition: FluidClass.h:43
double temperature_prho(double p, double rho, double T0)
double dsdT_along_sat_liquid(void)
Definition: CPState.cpp:2524
double B(void)
Definition: CPState.cpp:2182
void rho_smoothed(double xend, double &rho_spline, double &dsplinedh, double &dsplinedp)
Density corresponding to the smoothed derivatives in the region of x=0 to x=xend. ...
Definition: CPState.cpp:1851
double drhodT_along_sat_vapor(void)
Definition: CPState.cpp:2535
CachedElement dphir_dDelta
Definition: CPState.h:56
void enable_TTSE_LUT_writing(void)
Enable the writing of TTSE tables to file.
Definition: CPState.cpp:2784
CachedElement d3phir_dDelta3
Definition: CPState.h:56
virtual double d2phi0_dDelta2(double tau, double delta)
Definition: FluidClass.cpp:396
double phi0(double tau, double delta)
Definition: CPState.cpp:2549
double isobaric_expansion_coefficient(void)
Definition: CPState.cpp:1710
CachedElement d3phi0_dDelta3
Definition: CPState.h:56
double T(void)
Definition: CPState.h:289
double s(void)
Definition: CPState.cpp:1420
void get_TTSESinglePhase_LUT_range(double *hmin, double *hmax, double *pmin, double *pmax)
Get the current range of the single-phase LUT.
double d2sdp2_along_sat_liquid(void)
Definition: CPState.cpp:2459
double rho(void)
Definition: CPState.h:290
void update(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:2818
double pV(void)
Definition: CPState.h:268
double d2rhodpdQ(void)
Definition: CPState.cpp:2355
IncompressibleLiquid * get_liquid(long index)
CoolPropStateClassSI * SatV
Definition: CPState.h:116
double dsdT_constrho(void)
Definition: CPState.cpp:2230
double dhdT_constrho(void)
Definition: CPState.cpp:2207
void enable_EXTTP(void)
Enable the extended two-phase calculations.
Definition: CPState.cpp:2772
virtual double viscosity_Trho(double T, double rho)
Definition: FluidClass.cpp:788
void check_saturated_quality(double Q)
Definition: CPState.cpp:163
bool within_TTSE_range(long iInput1, double Value1, long iInput2, double Value2)
Check whether within the TTSE range.
Definition: CPState.h:159
virtual double d2phi0_dDelta_dTau(double tau, double delta)
Definition: FluidClass.cpp:427
bool isenabled_TTSE_LUT(void)
Check if TTSE is enabled.
double convert_from_unit_system_to_SI(long iInput, double value, int old_system)
Definition: Units.cpp:5
double viscL(void)
Definition: CPState.cpp:1377
double dsdp_along_sat_liquid(void)
Definition: CPState.cpp:2439
bool pure()
Returns true if the fluid is pure, false if pseudo-pure or a mixture.
Definition: FluidClass.h:243
virtual double d2phir_dTau2(double tau, double delta)
Definition: FluidClass.cpp:312
double d3phir_dTau3(double tau, double delta)
Definition: CPState.cpp:2717
#define SECTION(name, description)
Definition: catch.hpp:8088
double dBdT(void)
Definition: CPState.cpp:2187
double dsdT_constp(void)
Definition: CPState.cpp:2302
double temperature_prho_PengRobinson(double p, double rho)
Definition: FluidClass.cpp:687
double d3phi0_dDelta3(double tau, double delta)
Definition: CPState.cpp:2636
TTSETwoPhaseTableClass TTSESatL
Definition: FluidClass.h:226
virtual double dphir_dDelta(double tau, double delta)
Definition: FluidClass.cpp:257
double dvdT_constp(void)
Definition: CPState.cpp:2253
double dpdrho_consth(void)
Definition: CPState.cpp:2262
double cv(void)
Definition: CPState.cpp:1575
virtual double rhosatL(double T)
Definition: FluidClass.h:368
virtual void saturation_p(double p, bool UseLUT, double &TsatLout, double &TsatVout, double &rhoLout, double &rhoVout)
void add_saturation_states(void)
Definition: CPState.cpp:1312
void update_Tp(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:552
void _post_update(void)
Definition: CPState.cpp:312
IncompressibleSolution * pIncompSolution
A pointer to the class for an incompressible solution.
Definition: CPState.h:192
bool add_derivative_constraint(double x, double dydx)
Definition: Spline.cpp:49
void disable_TTSE_LUT(void)
Disable the TTSE.
Definition: CPState.cpp:2782
virtual double d3phir_dDelta2_dTau(double tau, double delta)
Definition: FluidClass.cpp:370
double d2pdrhodT(void)
Definition: CPState.cpp:2126
bool isenabled_EXTTP(void)
Check if extended two-phase calculations are enabled.
Definition: CPState.cpp:2774
double evaluate_sat_derivative(long iParam, double p)
Definition: TTSE.cpp:2847
virtual double conductivity_Trho(double T, double rho)
Definition: FluidClass.cpp:795
void update_Trho(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:424
virtual double cond(double T_K, double p)
Thermal conductivity as a function of temperature and pressure.
Definition: IncompLiquid.h:46
void disable_TTSE_LUT(void)
Disable the TTSE.
CoolPropStateClassSI * SatL
Definition: CPState.h:116
virtual void density_Ts(double T, double s, double &rhoout, double &pout, double &rhoLout, double &rhoVout, double &psatLout, double &psatVout)
CachedElement d2phi0_dDelta2
Definition: CPState.h:56
virtual void saturation_T(double T, bool UseLUT, double &psatLout, double &psatVout, double &rhoLout, double &rhoVout)
Definition: FluidClass.cpp:948
double Tmin
Definition: FluidClass.h:54
double viscV(void)
Definition: CPState.cpp:1378
double d2phi0_dTau2(double tau, double delta)
Definition: CPState.cpp:2604
double d2pdT2_constrho(void)
Definition: CPState.cpp:2130
double RPcond
Definition: CPState.cpp:2898
double d2phi0_dDelta_dTau(double tau, double delta)
Definition: CPState.cpp:2593
double d2hdrho2_constT(void)
Definition: CPState.cpp:2211
double interp_linear(double Q, double valueL, double valueV)
Extended two-phase calculations need different interpolation functions.
Definition: CPState.cpp:2765
SolutionsContainer SolutionsList
Definition: CPState.cpp:24
bool build(void)
Definition: Spline.cpp:13
#define CHECK(expr)
Definition: catch.hpp:8058
double drhodp_consth_smoothed(double xend)
A smoothed version of the derivative using a spline curve in the region of x=0 to x=xend...
Definition: CPState.cpp:1791
double d2rhodp2_constT(void)
Definition: CPState.cpp:2333
double dTdp_along_sat(void)
Derivative of temperature w.r.t. pressure along saturation curve.
Definition: CPState.cpp:2366
double condV(void)
Definition: CPState.cpp:1380
CachedElement d2phir_dTau2
Definition: CPState.h:56
bool ValidNumber(double x)
double accentricfactor
Definition: FluidClass.h:43
double Tend
The last temperature for which the conventional methods can be used.
Definition: FluidClass.h:106
double RPsigma
Definition: CPState.cpp:2909
double evaluate_one_other_input(long iInput1, double Param1, long iOther, double Other)
Evaluate the TTSE using P,S or P,T.
Definition: TTSE.cpp:2188
double d3phir_dDelta2_dTau(double tau, double delta)
Definition: CPState.cpp:2741
double evaluate_Trho(long iOutput, double T, double rho, double logrho)
Definition: TTSE.cpp:2448
double dpdT_constrho(void)
Definition: CPState.cpp:2118
double TV(void)
Definition: CPState.h:270
double RPcp
Definition: CPState.cpp:2865
double drhodp_along_sat_liquid(void)
Definition: CPState.cpp:2482
virtual double visc(double T_K, double p)
Viscosity as a function of temperature and pressure.
Definition: IncompLiquid.h:44
CachedElement d3phir_dTau3
Definition: CPState.h:56