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
Units.h
Go to the documentation of this file.
1 #ifndef UNITS_H
2 #define UNITS_H
3 
4 #include "GlobalConstants.h"
5 #include "CoolPropTools.h"
6 #include "CPExceptions.h"
7 
8 
10 {
11 protected:
12  double SI_val;
13 
14 public:
15  virtual ~StandardUnit(){};
16  virtual void set_SI(double val) = 0;
17 };
18 
19 class PressureUnit : public StandardUnit
20 {
21 public:
22  double kPa, Pa, bar;
23 
25  PressureUnit(double val, int unit)
26  {
27  // Convert given units to Pa
28  switch (unit)
29  {
30  case UNIT_PA:
31  break;
32  case UNIT_KPA:
33  val *= 1000;
34  break;
35  case UNIT_BAR:
36  val *= 1e5;
37  break;
38  default:
39  throw ValueError(format("Your unit [%d] is not a pressure unit",unit).c_str());
40  break;
41  };
42  // Set the internal variable using Pa units
43  set_SI(val);
44  };
45  void set_in_unit_system(double val, int unit_system)
46  {
47  // Convert given units to Pa
48  switch (unit_system)
49  {
50  case UNIT_SYSTEM_SI:
51  break;
52  case UNIT_SYSTEM_KSI:
53  val *= 1000;
54  break;
55  default:
56  throw ValueError(format("Your unit system [%d] is not valid",unit_system).c_str());
57  break;
58  };
59  set_SI(val);
60  };
62  {
63  // Convert given units to Pa
64  switch (unit_system)
65  {
66  case UNIT_SYSTEM_SI:
67  return Pa;
68  case UNIT_SYSTEM_KSI:
69  return kPa;
70  default:
71  throw ValueError(format("Your unit system [%d] is not valid",unit_system).c_str());
72  break;
73  };
74  return _HUGE;
75  };
76 
78  double get_SI(void) { return SI_val; };
82  void set_SI(double SI_val)
83  {
84  this->SI_val = SI_val;
85  Pa = SI_val;
86  kPa = SI_val/1000;
87  bar = SI_val/1e5;
88  };
89 };
90 
91 double convert_from_unit_system_to_SI(long iInput, double value, int old_system);
92 double convert_from_SI_to_unit_system(long iInput, double value, int new_system);
93 double convert_from_SI_to_unit_system(std::string input, double value, std::string new_system);
94 double convert_from_unit_system_to_SI(std::string input, double value, std::string old_system);
95 double convert_from_SI_to_unit_system(char *input, double value, char *new_system);
96 double convert_from_unit_system_to_SI(char *input, double value, char *old_system);
97 
98 // Get a conversion factor from SI to the unit system for string
99 // Example num = "T*T" is units of temperature^2, or "P*P" is pressure^2 or "T/P" is temperature/pressure
100 double conversion_factor(std::string num);
101 
102 #endif
double SI_val
Definition: Units.h:12
double kPa
Definition: Units.h:22
PressureUnit(double val, int unit)
Definition: Units.h:25
double get_SI(void)
Return the SI system value (in Pa)
Definition: Units.h:78
double convert_from_SI_to_unit_system(long iInput, double value, int new_system)
Definition: Units.cpp:123
double get_in_unit_system(int unit_system)
Definition: Units.h:61
double Pa
Definition: Units.h:22
double bar
Definition: Units.h:22
void set_in_unit_system(double val, int unit_system)
Definition: Units.h:45
std::string format(const char *fmt,...)
void set_SI(double SI_val)
Definition: Units.h:82
int unit_system
Definition: CoolProp.cpp:57
double convert_from_unit_system_to_SI(long iInput, double value, int old_system)
Definition: Units.cpp:5
double conversion_factor(std::string num)
Definition: Units.cpp:267
virtual ~StandardUnit()
Definition: Units.h:15
virtual void set_SI(double val)=0
PressureUnit()
Definition: Units.h:24