antioch-0.4.0
insi.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // Antioch - A Gas Dynamics Thermochemistry Library
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk,
7 // Sylvain Plessis, Roy H. Stonger
8 //
9 // Copyright (C) 2013 The PECOS Development Team
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the Version 2.1 GNU Lesser General
13 // Public License as published by the Free Software Foundation.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
23 // Boston, MA 02110-1301 USA
24 //
25 //-----------------------------------------------------------------------el-
26 #ifndef ANTIOCH_IN_SI_H
27 #define ANTIOCH_IN_SI_H
28 
29 //Antioch
31 
32 //C++
33 #include <iostream>
34 
35 namespace Antioch{
36 
43 class InSI{
44  public:
45 
48  InSI(int i0=0,int i1=0, int i2=0, int i3=0, int i4=0, int i5=0, int i6=0, int i7=0):
49  m(i0),kg(i1),s(i2),A(i3),K(i4),mol(i5),cd(i6),rad(i7){}
50 
52  friend std::ostream &operator<< (std::ostream &out, const InSI & rhs)
53  {
54  out << "["
55  << rhs.get_m() << "(m),"
56  << rhs.get_kg() << "(kg),"
57  << rhs.get_s() << "(s),"
58  << rhs.get_A() << "(A),"
59  << rhs.get_K() << "(K),"
60  << rhs.get_mol() << "(mol),"
61  << rhs.get_cd() << "(cd),"
62  << rhs.get_rad() << "(rad)]";
63  return out;
64  }
65 
67  bool operator== (const InSI & rhs) const;
69  bool operator!= (const InSI & rhs) const;
71  InSI & operator= (const InSI & rhs);
73  InSI & operator+= (const InSI & rhs);
75  InSI & operator-= (const InSI & rhs);
77  InSI & operator*= (int rhs);
86  InSI & operator/= (int rhs);
88  InSI operator+ (const InSI & rhs) const;
90  InSI operator- (const InSI & rhs) const;
92  InSI operator* (int rhs) const;
94  InSI operator/ (int rhs) const;
95 
97  void clear();
98 
100  int get_m() const {return m;}
102  int get_kg() const {return kg;}
104  int get_s() const {return s;}
106  int get_A() const {return A;}
108  int get_K() const {return K;}
110  int get_mol() const {return mol;}
112  int get_cd() const {return cd;}
114  int get_rad() const {return rad;}
115 
117  bool empty() const;
118 
119  private:
120  int m,kg,s,A,K,mol,cd,rad;
121 };
122 
123 inline
124 bool InSI::operator== (const InSI & rhs)const
125 {
126  return (
127  m == rhs.get_m() &&
128  kg == rhs.get_kg() &&
129  s == rhs.get_s() &&
130  A == rhs.get_A() &&
131  K == rhs.get_K() &&
132  mol == rhs.get_mol() &&
133  cd == rhs.get_cd() &&
134  rad == rhs.get_rad()
135  );
136 }
137 
138 inline
139 bool InSI::operator!= (const InSI & rhs)const
140 {
141  return (!(*this == rhs));
142 }
143 
144 inline
145 InSI & InSI::operator= (const InSI & rhs)
146 {
147  if(this == &rhs){return *this;}
148  m = rhs.get_m();
149  kg = rhs.get_kg();
150  s = rhs.get_s();
151  A = rhs.get_A();
152  K = rhs.get_K();
153  mol = rhs.get_mol();
154  cd = rhs.get_cd();
155  rad = rhs.get_rad();
156  return *this;
157 }
158 
159 inline
160 InSI InSI::operator+ (const InSI & rhs)const
161 {
162  return InSI(
163  m + rhs.get_m() ,
164  kg + rhs.get_kg() ,
165  s + rhs.get_s() ,
166  A + rhs.get_A() ,
167  K + rhs.get_K() ,
168  mol + rhs.get_mol(),
169  cd + rhs.get_cd() ,
170  rad + rhs.get_rad()
171  );
172 }
173 
174 inline
175 InSI InSI::operator- (const InSI & rhs)const
176 {
177  return InSI(
178  m - rhs.get_m() ,
179  kg - rhs.get_kg() ,
180  s - rhs.get_s() ,
181  A - rhs.get_A() ,
182  K - rhs.get_K() ,
183  mol - rhs.get_mol(),
184  cd - rhs.get_cd() ,
185  rad - rhs.get_rad()
186  );
187 }
188 
189 inline
191 {
192  m += rhs.get_m();
193  kg += rhs.get_kg();
194  s += rhs.get_s();
195  A += rhs.get_A();
196  K += rhs.get_K();
197  mol += rhs.get_mol();
198  cd += rhs.get_cd();
199  rad += rhs.get_rad();
200  return *this;
201 }
202 
203 inline
205 {
206  m -= rhs.get_m();
207  kg -= rhs.get_kg();
208  s -= rhs.get_s();
209  A -= rhs.get_A();
210  K -= rhs.get_K();
211  mol -= rhs.get_mol();
212  cd -= rhs.get_cd();
213  rad -= rhs.get_rad();
214  return *this;
215 }
216 
217 inline
219 {
220  m *= rhs;
221  kg *= rhs;
222  s *= rhs;
223  A *= rhs;
224  K *= rhs;
225  mol *= rhs;
226  cd *= rhs;
227  rad *= rhs;
228  return *this;
229 }
230 
231 inline
233 {
234  if(m %rhs != 0)antioch_unit_error("Cannot have non integer power (m).");
235  if(kg %rhs != 0)antioch_unit_error("Cannot have non integer power (kg).");
236  if(s %rhs != 0)antioch_unit_error("Cannot have non integer power (s).");
237  if(A %rhs != 0)antioch_unit_error("Cannot have non integer power (A).");
238  if(K %rhs != 0)antioch_unit_error("Cannot have non integer power (K).");
239  if(mol%rhs != 0)antioch_unit_error("Cannot have non integer power (mol).");
240  if(cd %rhs != 0)antioch_unit_error("Cannot have non integer power (cd).");
241  if(rad%rhs != 0)antioch_unit_error("Cannot have non integer power (rad).");
242  m /= rhs;
243  kg /= rhs;
244  s /= rhs;
245  A /= rhs;
246  K /= rhs;
247  mol /= rhs;
248  cd /= rhs;
249  rad /= rhs;
250 
251  return *this;
252 }
253 
254 inline
255 InSI InSI::operator* (int rhs)const
256 {
257  return InSI(
258  m * rhs,
259  kg * rhs,
260  s * rhs,
261  A * rhs,
262  K * rhs,
263  mol * rhs,
264  cd * rhs,
265  rad * rhs
266  );
267 }
268 
269 inline
270 InSI InSI::operator/ (int rhs)const
271 {
272  return (InSI(*this) /= rhs);
273 }
274 
275 inline
277 {
278  m = 0;
279  kg = 0;
280  s = 0;
281  A = 0;
282  K = 0;
283  mol = 0;
284  cd = 0;
285  rad = 0;
286 }
287 
288 inline
289 bool InSI::empty() const
290 {
291  return (m == 0 &&
292  kg == 0 &&
293  s == 0 &&
294  A == 0 &&
295  K == 0 &&
296  mol == 0 &&
297  cd == 0 &&
298  rad == 0);
299 }
300 } //Antioch namespace
301 
302 #endif
int get_m() const
meter power getter
Definition: insi.h:100
bool operator!=(const InSI &rhs) const
Not bool const operator==(const InSI&)
Definition: insi.h:139
bool operator==(const InSI &rhs) const
Bool equalize operator, true if all the powers are equal.
Definition: insi.h:124
InSI operator/(int rhs) const
Dividing operator, see InSi & operator/=(int) for details.
Definition: insi.h:270
friend std::ostream & operator<<(std::ostream &out, const InSI &rhs)
<< operator, to format the power vector
Definition: insi.h:52
InSI & operator/=(int rhs)
Dividing operator.
Definition: insi.h:232
int get_rad() const
radian power getter
Definition: insi.h:114
InSI & operator-=(const InSI &rhs)
Substracting operator, substract all the powers.
Definition: insi.h:204
InSI operator-(const InSI &rhs) const
Substracting operator, substract all the powers.
Definition: insi.h:175
InSI(int i0=0, int i1=0, int i2=0, int i3=0, int i4=0, int i5=0, int i6=0, int i7=0)
Building constructor, fully descriptive, with zeros as default values to simplify coder's interface...
Definition: insi.h:48
int get_mol() const
mol power getter
Definition: insi.h:110
int get_s() const
second power getter
Definition: insi.h:104
int get_kg() const
kilogramme power getter
Definition: insi.h:102
#define antioch_unit_error(description)
int cd
Definition: insi.h:120
int mol
Definition: insi.h:120
void clear()
Set all the powers to zeros.
Definition: insi.h:276
InSI operator*(int rhs) const
Multiplying operator, multiply all the powers.
Definition: insi.h:255
int get_A() const
ampere power getter
Definition: insi.h:106
Seven integers to characterize the power vector.
Definition: insi.h:43
int get_K() const
kelvin power getter
Definition: insi.h:108
InSI operator+(const InSI &rhs) const
Adding operator, add all the powers.
Definition: insi.h:160
InSI & operator*=(int rhs)
Multiplying operator, multiply all the powers.
Definition: insi.h:218
int kg
Definition: insi.h:120
int get_cd() const
candela power getter
Definition: insi.h:112
bool empty() const
Check if empty (all values to zero)
Definition: insi.h:289
InSI & operator=(const InSI &rhs)
Assignement operator, equalize all the powers.
Definition: insi.h:145
The parameters are reduced parameters.
InSI & operator+=(const InSI &rhs)
Adding operator, add all the powers.
Definition: insi.h:190
int rad
Definition: insi.h:120

Generated on Thu Jul 7 2016 11:09:46 for antioch-0.4.0 by  doxygen 1.8.8