SU2
complex_structure.hpp
Go to the documentation of this file.
1 
33 #pragma once
34 #include <complex>
35 
36 class CComplexType;
37 typedef CComplexType su2double;
38 
39 /*--- So the real() statement can be used even with the double type.
40  Eases the implementation of some operators. ---*/
41 inline double real(const double& r);
42 
51 class CComplexType : public std::complex<double> {
52 public:
53  CComplexType() : std::complex<double>() {}
54 
55  CComplexType(const double& d) : std::complex<double>(d) {}
56 
57  CComplexType(const double& r, const double& i) : std::complex<double>(r,i) {}
58 
59  CComplexType(const std::complex<double>& z) : std::complex<double>(z) {}
60 
61  CComplexType(const std::complex<float>& z) : std::complex<double>(z) {}
62 
63  operator double() { return this->real();}
64 
65  operator int() { return int(this->real());}
66 
67  operator short() { return short(this->real());}
68 
69  /*--- To get rid of some ambiguities, we need to reimplement some operators
70  * (although they are already implemented for std::complex). ---*/
71 
72  /*--- Comparison operators (they are defined by comparing only the real parts
73  * as we assume a very small imag. step ( < 1e-50)---*/
74 
75  template<typename T, typename Z>
76  friend bool operator==(const Z&, const T&);
77 
78  template<typename T, typename Z>
79  friend bool operator!=(const Z&, const T&);
80 
81  template<typename T, typename Z>
82  friend bool operator<(const Z&, const T&);
83 
84  template<typename T, typename Z>
85  friend bool operator>(const Z&, const T&);
86 
87  template<typename T, typename Z>
88  friend bool operator<=(const Z&, const T&);
89 
90  template<typename T, typename Z>
91  friend bool operator>=(const Z&, const T&);
92 
93  /*--- Basic arithmetic (some are templated to work with double, int, long int etc.) ---*/
94 
95  CComplexType operator+() const;
96 
97  CComplexType operator+(const CComplexType&) const;
98 
99  template<typename T>
100  friend CComplexType operator+(const CComplexType&, const T&);
101 
102  template<typename T>
103  friend CComplexType operator+(const T&, const CComplexType&);
104 
105  CComplexType operator-() const;
106 
107  CComplexType operator-(const CComplexType&) const;
108 
109  template<typename T>
110  friend CComplexType operator-(const CComplexType&, const T&);
111 
112  template<typename T>
113  friend CComplexType operator-(const T&, const CComplexType&);
114 
115  CComplexType operator*(const CComplexType&) const;
116 
117  template<typename T>
118  friend CComplexType operator*(const CComplexType&, const T&);
119 
120  template<typename T>
121  friend CComplexType operator*(const T&, const CComplexType&);
122 
123  CComplexType operator/(const CComplexType&) const;
124 
125  template<typename T>
126  friend CComplexType operator/(const CComplexType&, const T&);
127 
128  template<typename T>
129  friend CComplexType operator/(const T&, const CComplexType&);
130 
131 
132  /*--- From <math.h> ---*/
133 
134  friend CComplexType sin(const CComplexType&);
135  friend CComplexType sinh(const CComplexType&);
136  friend CComplexType cos(const CComplexType&);
137  friend CComplexType cosh(const CComplexType&);
138  friend CComplexType tan(const CComplexType&);
139  friend CComplexType tanh(const CComplexType&);
140  friend CComplexType log10(const CComplexType&);
141  friend CComplexType log(const CComplexType&);
142  friend CComplexType sqrt(const CComplexType&);
143  friend CComplexType exp(const CComplexType&);
144  friend CComplexType pow(const CComplexType&, const CComplexType&);
145  friend CComplexType pow(const CComplexType&, const double&);
146  friend CComplexType pow(const CComplexType&, const int&);
147  friend CComplexType pow(const double&, const CComplexType&);
148  friend CComplexType pow(const int&, const CComplexType&);
149  friend CComplexType min(const CComplexType& t, const CComplexType& z);
150  template<typename T>
151  friend CComplexType min(const T& t, const CComplexType& z);
152  template<typename T>
153  friend CComplexType min(const CComplexType& z, const T& t);
154  friend CComplexType max(const CComplexType& t, const CComplexType& z);
155  template<typename T>
156  friend CComplexType max(const T& t, const CComplexType& z);
157  template<typename T>
158  friend CComplexType max(const CComplexType& z, const T& t);
159 
160  /*--- std::complex versions of these are not in standard library
161  or they need to be redefined: (frexp, modf, and fmod have not been dealt with) ---*/
162 
163  friend CComplexType fabs(const CComplexType&);
164  friend CComplexType asin(const CComplexType&);
165  friend CComplexType acos(const CComplexType&);
166  friend CComplexType atan(const CComplexType&);
167  friend CComplexType atan2(const CComplexType&, const CComplexType&);
168  friend CComplexType ceil(const CComplexType&);
169  friend CComplexType floor(const CComplexType&);
170  friend CComplexType ldexp(const CComplexType&, const int&);
171  friend std::ostream& operator<< (std::ostream &out, const CComplexType &);
172 
173 };
Class for defining the complex datatype for complex step gradient computation. Based on complexify...
Definition: complex_structure.hpp:51