1 /*
2 XLiFE++ is an extended library of finite elements written in C++
3 Copyright (C) 2014 Lunéville, Eric; Kielbasiewicz, Nicolas; Lafranche, Yvon; Nguyen, Manh-Ha; Chambeyron, Colin
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 /*!
18 \file complexUtils.hpp
19 \author E. Lunéville
20 \since 14 dec 2011
21 \date 3 may 2012
22
23 \brief overloaded functions "missing" in stl::class complex
24 */
25
26
27 #ifndef COMPLEX_UTILS_HPP
28 #define COMPLEX_UTILS_HPP
29
30 #include "config.h"
31
32 namespace xlifepp
33 {
34
35 // definition of asin, acos, atan, asinh, acosh, atanh, cbrt (cubic root) for complex value
36 // equivalent formula
37 complex_t asin(const complex_t&);
38 complex_t acos(const complex_t&);
39 complex_t atan(const complex_t&);
40 complex_t asinh(const complex_t&);
41 complex_t acosh(const complex_t&);
42 complex_t atanh(const complex_t&);
43 complex_t cbrt(const complex_t&);
44 real_t asinh(const real_t&);
45 real_t acosh(const real_t&);
46 real_t atanh(const real_t&);
47 real_t cbrt(const real_t&);
48
49 // hybrid algebraic operations
50 complex_t operator+(const int_t, const complex_t&);
51 complex_t operator+(const int, const complex_t&);
52 complex_t operator+(const number_t, const complex_t&);
53 complex_t operator+(const complex_t&, const int_t);
54 complex_t operator+(const complex_t&, const int);
55 complex_t operator+(const complex_t&, const number_t);
56 // complex_t operator+=(const int);
57 complex_t operator-(const int_t, const complex_t&);
58 complex_t operator-(const number_t, const complex_t&);
59 complex_t operator-(const int, const complex_t&);
60 complex_t operator-(const complex_t&, const int_t);
61 complex_t operator-(const complex_t&, const int);
62 complex_t operator-(const complex_t&, const number_t);
63 // complex_t operator-=(const int);
64 complex_t operator*(const int_t, const complex_t&);
65 complex_t operator*(const int, const complex_t&);
66 complex_t operator*(const number_t, const complex_t&);
67 complex_t operator*(const complex_t&, const int_t);
68 complex_t operator*(const complex_t&, const int);
69 complex_t operator*(const complex_t&, const number_t);
70 // complex_t operator*=(const int);
71 // complex_t operator/(const int, const complex_t&);
72 complex_t operator/(const complex_t& z, const int_t);
73 complex_t operator/(const complex_t& z, const int);
74 complex_t operator/(const complex_t& z, const number_t);
75 // complex_t operator/=(const int);
76
77 // other complex operations for consistency
78 complex_t cmplx(const real_t&);
79 real_t realPart(const complex_t&);
80 real_t realPart(const real_t&);
81 real_t imagPart(const complex_t&);
82 real_t imagPart(const real_t&);
83 real_t conj(const real_t&);
84 real_t tran(const real_t&);
85 complex_t tran(const complex_t&);
86 real_t adj(const real_t&);
87 complex_t adj(const complex_t&);
88 real_t diag(const real_t&);
89 complex_t diag(const complex_t&);
90 real_t norm2(const real_t&);
91 real_t norm2(const complex_t&);
92 complex_t maxAbsVal(const real_t&);
93 complex_t maxAbsVal(const complex_t&);
94
95 //! forced cast complex to any
96 template<class T>
complexToT(const complex_t & c)97 inline T complexToT(const complex_t& c){return c;}
98 template<>
complexToT(const complex_t & c)99 inline real_t complexToT(const complex_t& c){return c.real();} //real specialization
complexToRorC(const complex_t & c,const real_t & r)100 inline real_t complexToRorC(const complex_t& c, const real_t& r) {return c.real();}
complexToRorC(const complex_t & c,const complex_t & cc)101 inline complex_t complexToRorC(const complex_t& c, const complex_t& cc) {return c;}
102
103 //! various useful definition to insure consistancy with other classes
104
cmplx(const real_t & x)105 inline complex_t cmplx(const real_t& x)
106 { return complex_t(x);}
107
realPart(const complex_t & x)108 inline real_t realPart(const complex_t& x)
109 { return x.real();}
110
realPart(const real_t & x)111 inline real_t realPart(const real_t& x)
112 { return x;}
113
imagPart(const complex_t & x)114 inline real_t imagPart(const complex_t& x)
115 { return x.imag();}
116
imagPart(const real_t & x)117 inline real_t imagPart(const real_t& x)
118 { return 0.;}
119
conj(const real_t & r)120 inline real_t conj(const real_t& r)
121 { return r;}
122
tran(const real_t & r)123 inline real_t tran(const real_t& r)
124 { return r;}
125
tran(const complex_t & c)126 inline complex_t tran(const complex_t& c)
127 { return c;}
128
adj(const real_t & r)129 inline real_t adj(const real_t& r)
130 { return r;}
131
adj(const complex_t & c)132 inline complex_t adj(const complex_t& c)
133 { return conj(c);}
134
diag(const real_t & r)135 inline real_t diag(const real_t& r)
136 { return r;}
137
diag(const complex_t & z)138 inline complex_t diag(const complex_t& z)
139 { return z;}
140
norm2(const real_t & r)141 inline real_t norm2(const real_t& r)
142 { return std::abs(r);}
143
norm2(const complex_t & z)144 inline real_t norm2(const complex_t& z)
145 { return std::abs(z);}
146
norminfty(const real_t & r)147 inline real_t norminfty(const real_t& r)
148 { return std::abs(r);}
149
norminfty(const complex_t & z)150 inline real_t norminfty(const complex_t& z)
151 { return std::abs(z);}
152
maxAbsVal(const real_t & r)153 inline complex_t maxAbsVal(const real_t& r)
154 { return complex_t(r);}
155
maxAbsVal(const complex_t & z)156 inline complex_t maxAbsVal(const complex_t& z)
157 { return z;}
158
159
160 } // end of namespace xlifepp;
161
162 #endif // COMPLEX_UTILS_HPP
163