antioch-0.4.0
converter.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_CONVERTER_H
27 #define ANTIOCH_CONVERTER_H
28 
29 //Antioch
31 
32 //C++
33 #include <iostream>
34 
35 namespace Antioch{
36 
46 template <typename T = double>
47 class Converter{
48  public:
50  Converter();
52  Converter(const T &coef, const T &trans);
54  template <typename P>
55  Converter(const Converter<P> &rhs){*this = rhs;}
58 
60  template <typename P = T>
61  const P geta() const {return (P)a;} //only scalar type
63  template <typename P = T>
64  const P getb() const {return (P)b;} //only scalar type
66  void clear() {a = 1.L; Antioch::set_zero(b);}
67 
69  friend std::ostream &operator<< (std::ostream &out, const Converter<T> & rhs)
70  {
71  out << "(" << rhs.geta() << "," << rhs.getb() << ")";
72  return out;
73  }
74 
76  template <typename P>
77  bool operator== (const Converter<P> &rhs) const;
79  template <typename P>
80  bool operator!=(const Converter<P> &rhs) const {return !(*this == rhs);}
82  template <typename P>
83  Converter & operator= (const Converter<P> &rhs);
94  template <typename P>
95  Converter & operator*= (const Converter<P> &rhs);
106  template <typename P>
107  Converter & operator/= (const Converter<P> &rhs);
118  template <typename P>
119  Converter & operator+= (const Converter<P> &rhs);
121  template <typename P>
122  Converter operator/ (const Converter<P> &rhs) const;
124  template <typename P>
125  Converter operator* (const Converter<P> &rhs) const;
127  template <typename P>
128  Converter & operator*= (const P &coef);
130  template <typename P>
131  Converter & operator/= (const P &coef);
133  template <typename P>
134  Converter operator* (const P &coef) const;
136  template <typename P>
137  Converter operator/ (const P &coef) const;
138 
139  private:
141  T a;
142  T b;
143 
144 };
145 
146 template<typename T>
147 inline
149 {
150  clear();
151  return;
152 }
153 
154 template<typename T>
155 inline
156 Converter<T>::Converter(const T &coef, const T &tran)
157 {
158  a = Antioch::constant_clone(a,coef);
159  b = Antioch::constant_clone(b,tran);
160  return;
161 }
162 
163 
164 template<typename T>
165 template<typename P>
166 inline
168 {
169  // if(this == static_cast<Converter<T>*>(&rhs)){return *this;}
170  a = Antioch::constant_clone(a,rhs.geta());
171  b = Antioch::constant_clone(b,rhs.getb());
172  return *this;
173 }
174 
175 template<typename T>
176 template<typename P>
177 inline
179 {
180  a *= coef;
181  return *this;
182 }
183 
184 template<typename T>
185 template<typename P>
186 inline
188 {
189  a /= coef;
190  return *this;
191 }
192 
193 template<typename T>
194 template<typename P>
195 inline
197 {
198  a *= rhs.geta();
199  b = (b + rhs.getb())/rhs.geta();
200  return *this;
201 }
202 
203 template<typename T>
204 template<typename P>
205 inline
207 {
208  a /= rhs.geta();
209  b = (b - rhs.getb())/rhs.geta();
210  return *this;
211 }
212 
213 template<typename T>
214 template<typename P>
215 inline
217 {
218  a *= rhs.geta();
219  b += rhs.getb();
220  return *this;
221 }
222 
223 template<typename T>
224 template<typename P>
225 inline
227 {
228  return Converter<T>(a*coef,b);
229 }
230 
231 template<typename T>
232 template<typename P>
233 inline
235 {
236  return Converter<T>(a/coef,b);
237 }
238 
239 template<typename T>
240 template<typename P>
241 inline
243 {
244  return Converter(a/rhs.geta(),(b-rhs.getb())/rhs.geta());
245 }
246 
247 template<typename T>
248 template<typename P>
249 inline
251 {
252  return Converter<T>(a * rhs.geta() , (b + rhs.getb())/rhs.geta());
253 }
254 }// end namespace
255 
256 #endif
T a
Two double for a multiplicative and translationnal part of a coefficient.
Definition: converter.h:141
bool operator==(const Converter< P > &rhs) const
Comparison operator, equal if the two values are equal.
Converter operator/(const Converter< P > &rhs) const
Dividing operator, same operations as Converter &operator/=(const Converter&)
Converter & operator*=(const Converter< P > &rhs)
Multiplying operator.
Converter()
Default constructor, defaults values are (1.,0.)
Definition: converter.h:148
const ANTIOCH_AUTO(StateType) EuckenThermalConductivity< ThermoEvaluator > return trans(s, mu_s)
const P geta() const
Multiplicative factor getter.
Definition: converter.h:61
Converter operator*(const Converter< P > &rhs) const
Multiplying operator, same operations as Converter &operator*=(const Converter&)
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > constant_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex, const Scalar &value)
Definition: eigen_utils.h:181
Converter & operator/=(const Converter< P > &rhs)
Dividing operator.
void set_zero(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a)
Definition: eigen_utils.h:217
Class to deal with the conversion between units.
Definition: converter.h:47
const P getb() const
Translationnal factor getter.
Definition: converter.h:64
Converter & operator+=(const Converter< P > &rhs)
Adding operator.
bool operator!=(const Converter< P > &rhs) const
Comparison operator, not equal is not "equal".
Definition: converter.h:80
The parameters are reduced parameters.
Converter(const Converter< P > &rhs)
Copy constructor, uses Converter & operator=(const Converter&)
Definition: converter.h:55
~Converter()
Default constructor.
Definition: converter.h:57
Converter & operator=(const Converter< P > &rhs)
Assignement operator, equalize the two values.
void clear()
Set the values to (1.,0.)
Definition: converter.h:66

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