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
30 #include "antioch/antioch_asserts.h"
31 
32 //C++
33 #include <iostream>
34 
35 namespace Antioch{
36 
37 /*! \class InSI
38  * \brief Seven integers to characterize the power vector
39  *
40  * A unit is caracterize by the power associated to
41  * every base unit, this class stores those power.
42  */
43 class InSI{
44     public:
45 
46 /*! \brief Building constructor, fully descriptive, with zeros as default values to
47  * simplify coder's interface*/
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):
m(i0)49         m(i0),kg(i1),s(i2),A(i3),K(i4),mol(i5),cd(i6),rad(i7){}
50 
51 /*! \brief << operator, to format the power vector*/
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 
66 /*! \brief Bool equalize operator, true if all the powers are equal*/
67       bool operator== (const InSI & rhs) const;
68 /*! \brief Not bool const operator==(const InSI&)*/
69       bool operator!= (const InSI & rhs) const;
70 /*! \brief Assignement operator, equalize all the powers*/
71       InSI &     operator=  (const InSI & rhs);
72 /*! \brief Adding operator, add all the powers*/
73       InSI &     operator+= (const InSI & rhs);
74 /*! \brief Substracting operator, substract all the powers*/
75       InSI &     operator-= (const InSI & rhs);
76 /*! \brief Multiplying operator, multiply all the powers*/
77       InSI &     operator*= (int rhs);
78 /*! \brief Dividing operator.
79  *
80  * Dividing a power needs first to check that the
81  * division is possible, i.e. if the power is not
82  * null, it must be a multiple of the divider. If not
83  * it sends back an error and stops. This division
84  * exist for root purposes.
85  */
86       InSI &     operator/= (int rhs);
87 /*! \brief Adding operator, add all the powers*/
88       InSI       operator+  (const InSI & rhs) const;
89 /*! \brief Substracting operator, substract all the powers*/
90       InSI       operator-  (const InSI & rhs) const;
91 /*! \brief Multiplying operator, multiply all the powers*/
92       InSI       operator*  (int rhs) const;
93 /*! \brief Dividing operator, see InSi & operator/=(int) for details*/
94       InSI       operator/  (int rhs) const;
95 
96 /*! \brief Set all the powers to zeros*/
97       void clear();
98 
99 /*! \brief meter power getter*/
get_m()100       int get_m()   const {return m;}
101 /*! \brief kilogramme power getter*/
get_kg()102       int get_kg()  const {return kg;}
103 /*! \brief second power getter*/
get_s()104       int get_s()   const {return s;}
105 /*! \brief ampere power getter*/
get_A()106       int get_A()   const {return A;}
107 /*! \brief kelvin power getter*/
get_K()108       int get_K()   const {return K;}
109 /*! \brief mol power getter*/
get_mol()110       int get_mol() const {return mol;}
111 /*! \brief candela power getter*/
get_cd()112       int get_cd()  const {return cd;}
113 /*! \brief radian power getter*/
get_rad()114       int get_rad() const {return rad;}
115 
116 /*!\brief Check if empty (all values to zero)*/
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
190 InSI & InSI::operator+= (const InSI & rhs)
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
204 InSI & InSI::operator-= (const InSI & rhs)
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
218 InSI & InSI::operator*= (int rhs)
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
232 InSI & InSI::operator/= (int rhs)
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
clear()276 void InSI::clear()
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
empty()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
303