BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
complex_aux.hpp
Go to the documentation of this file.
1 // Copyright (C) 2011-2012 by the BEM++ Authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef bempp_complex_aux_hpp
22 #define bempp_complex_aux_hpp
23 
26 #include "scalar_traits.hpp"
27 
28 namespace Fiber
29 {
30 
31 template <typename T>
32 inline typename ScalarTraits<T>::RealType realPart(const T& x)
33 {
34  return x;
35 }
36 
37 template <>
38 inline float realPart(const std::complex<float>& x)
39 {
40  return x.real();
41 }
42 
43 template <>
44 inline double realPart(const std::complex<double>& x)
45 {
46  return x.real();
47 }
48 
49 template <typename T>
50 inline typename ScalarTraits<T>::RealType imagPart(const T& x)
51 {
52  return 0.;
53 }
54 
55 template <>
56 inline float imagPart(const std::complex<float>& x)
57 {
58  return x.imag();
59 }
60 
61 template <>
62 inline double imagPart(const std::complex<double>& x)
63 {
64  return x.imag();
65 }
66 
67 template <typename T>
68 inline T conj(const T& x)
69 {
70  return x;
71 }
72 
73 template <>
74 inline std::complex<float> conj(const std::complex<float>& x)
75 {
76  return std::conj(x);
77 }
78 
79 template <>
80 inline std::complex<double> conj(const std::complex<double>& x)
81 {
82  return std::conj(x);
83 }
84 
88 template <typename ValueType>
89 inline ValueType expm(const ValueType& x)
90 {
91  return std::exp(-x);
92 }
93 
97 template <typename ValueType>
98 inline std::complex<ValueType> expm(const std::complex<ValueType>& x)
99 {
100  ValueType emx = std::exp(-x.real());
101  return std::complex<ValueType>(cos(x.imag()) * emx, -sin(x.imag() * emx));
102 }
103 
104 } // namespace Fiber
105 
106 namespace Bempp
107 {
108 using Fiber::realPart;
109 using Fiber::imagPart;
110 using Fiber::conj;
111 } // namespace Bempp
112 
113 #endif