OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fcst_units.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 //
3 // FCST: Fuel Cell Simulation Toolbox
4 //
5 // Copyright (C) 2013 by Energy Systems Design Laboratory, University of Alberta
6 //
7 // This software is distributed under the MIT License.
8 // For more information, see the README file in /doc/LICENSE
9 //
10 // - Class: fcst_units.h
11 // - Description: A cpp object that can be used by fcst programmers
12 // when manipulating units in order to preserve
13 // standards and prevent confusion.
14 // - Developers: Philip Wardlaw and M. Secanell
15 //
16 //---------------------------------------------------------------------------
17 
18 #include <string>
19 #include <iostream>
20 #include <stdexcept>
21 
22 #ifndef _FCST__UNITS
23 #define _FCST__UNITS
24 
49 class Units {
50 
51 public:
57  inline static double convert(double unitToConvert, double to, double from){
58 
59  if (to > 0 && from > 0){
60 
61  return unitToConvert*(to/from);
62 
63  }
64  else if (to < 0 && from < 0){
65 
66  return unitToConvert*(from/to);
67 
68  }
69  else {
70  //invalid use of the convert function. To and from must be of the same sign
71  throw std::logic_error("Incorrect unit conversion.");
72  }
73  }
74 
80  inline static double convert(double unitToConvert, int specificCase){
81 
82  switch (specificCase)
83  {
84  case KJ_to_BTU:
85  return unitToConvert/1.054;
86  case BTU_to_KJ:
87  return unitToConvert*1.054;
88  case ATM_to_PA:
89  return unitToConvert*1.01325e5;
90  }
91 
92  //Invalid case, throw error
93  throw std::invalid_argument("Specific case not implemented");
94  }
95 
96  //Static Integers denoting specific conversion cases (Typically Non Metric)
97  static const unsigned int KJ_to_BTU =1;
98  static const unsigned int BTU_to_KJ =2;
99  static const unsigned int ATM_to_PA =3;
100 
101  //Static doubles describing generic conversions
102  static double PER_K_UNIT; //1E3
103  static double PER_UNIT; // 1;
104  static double PER_C_UNIT; // 1E-2;
105  static double PER_MILLI_UNIT; // 1E-3;
106  static double PER_MICRO_UNIT; // 1E-6;
107  static double PER_N_UNIT; // 1E-9;
108  static double PER_P_UNIT; // 1E-12;
109 
110  static double PER_UNIT2; // 1;
111  static double PER_C_UNIT2; // 1E-4;
112  static double PER_MILLI_UNIT2; // 1E-6;
113  static double PER_MICRO_UNIT2; // 1E-12;
114  static double PER_N_UNIT2; // 1E-18;
115  static double PER_P_UNIT2; // 1E-24;
116 
117  static double PER_UNIT3; // 1;
118  static double PER_C_UNIT3; // 1E-6;
119  static double PER_MILLI_UNIT3; // 1E-9;
120  static double PER_MICRO_UNIT3; // 1E-18;
121  static double PER_N_UNIT3; // 1E-27;
122  static double PER_P_UNIT3; // 1E-36;
123 
124  //Sign is to differentiate between "Per unit" and "by unit"
125  static double K_UNIT; // -1E3
126  static double UNIT; // -1;
127  static double C_UNIT; //- 1E-2;
128  static double MILLI_UNIT; //- 1E-3;
129  static double MICRO_UNIT; //- 1E-6;
130  static double N_UNIT; //- 1E-9;
131  static double P_UNIT; // -1E-12;
132 
133  static double UNIT2; //- 1;
134  static double C_UNIT2; // -1E-4;
135  static double MILLI_UNIT2; // -1E-6;
136  static double MICRO_UNIT2; //- 1E-12;
137  static double N_UNIT2; //- 1E-18;
138  static double P_UNIT2; //- 1E-24;
139 
140  static double UNIT3; // -1;
141  static double C_UNIT3; // -1E-6;
142  static double MILLI_UNIT3; // -1E-9;
143  static double MICRO_UNIT3; // -1E-18;
144  static double N_UNIT3; //- 1E-27;
145  static double P_UNIT3; // -1E-36;
146 };
147 
148 
149 
150 
151 #endif
static double PER_P_UNIT
Definition: fcst_units.h:108
static double PER_N_UNIT3
Definition: fcst_units.h:121
static double PER_K_UNIT
Definition: fcst_units.h:102
static double N_UNIT2
Definition: fcst_units.h:137
static double C_UNIT3
Definition: fcst_units.h:141
static double PER_MILLI_UNIT
Definition: fcst_units.h:105
static double C_UNIT
Definition: fcst_units.h:127
static double MILLI_UNIT3
Definition: fcst_units.h:142
static double PER_C_UNIT3
Definition: fcst_units.h:118
static double MICRO_UNIT
Definition: fcst_units.h:129
static double PER_UNIT
Definition: fcst_units.h:103
static double PER_C_UNIT2
Definition: fcst_units.h:111
static double MICRO_UNIT2
Definition: fcst_units.h:136
static double MILLI_UNIT
Definition: fcst_units.h:128
static double UNIT
Definition: fcst_units.h:126
static double PER_N_UNIT2
Definition: fcst_units.h:114
static double MILLI_UNIT2
Definition: fcst_units.h:135
static const unsigned int KJ_to_BTU
Definition: fcst_units.h:97
static double N_UNIT
Definition: fcst_units.h:130
static double PER_P_UNIT3
Definition: fcst_units.h:122
static double K_UNIT
Definition: fcst_units.h:125
static double C_UNIT2
Definition: fcst_units.h:134
static double MICRO_UNIT3
Definition: fcst_units.h:143
static double PER_MICRO_UNIT3
Definition: fcst_units.h:120
static double PER_MILLI_UNIT2
Definition: fcst_units.h:112
static double PER_P_UNIT2
Definition: fcst_units.h:115
static double UNIT2
Definition: fcst_units.h:133
Class used to convert units using a standard convention.
Definition: fcst_units.h:49
static double PER_N_UNIT
Definition: fcst_units.h:107
static double PER_MILLI_UNIT3
Definition: fcst_units.h:119
static double N_UNIT3
Definition: fcst_units.h:144
static double P_UNIT3
Definition: fcst_units.h:145
static double PER_C_UNIT
Definition: fcst_units.h:104
static double PER_UNIT3
Definition: fcst_units.h:117
static const unsigned int BTU_to_KJ
Definition: fcst_units.h:98
static double convert(double unitToConvert, int specificCase)
Convert using on a case by case basis.
Definition: fcst_units.h:80
static double UNIT3
Definition: fcst_units.h:140
static const unsigned int ATM_to_PA
Definition: fcst_units.h:99
static double P_UNIT
Definition: fcst_units.h:131
static double PER_UNIT2
Definition: fcst_units.h:110
static double P_UNIT2
Definition: fcst_units.h:138
static double PER_MICRO_UNIT2
Definition: fcst_units.h:113
static double PER_MICRO_UNIT
Definition: fcst_units.h:106
static double convert(double unitToConvert, double to, double from)
The conversion routine convert(unitToConvert, X, Y) should be read as:
Definition: fcst_units.h:57