DFT-EFE
 
Loading...
Searching...
No Matches
DataTypeOverloads.h
Go to the documentation of this file.
1#ifndef dftefeDataTypeOverloads_h
2#define dftefeDataTypeOverloads_h
3
4#include <complex>
5#include <algorithm>
6#include <utils/TypeConfig.h>
7namespace dftefe
8{
9 namespace utils
10 {
11 inline unsigned int
12 abs_(unsigned int a)
13 {
14 return a;
15 }
16
17 inline int
18 abs_(int a)
19 {
20 return std::abs(a);
21 }
22
23 inline double
24 abs_(double a)
25 {
26 return std::abs(a);
27 }
28
29 inline float
30 abs_(float a)
31 {
32 return std::abs(a);
33 }
34
35 inline double
36 abs_(std::complex<double> a)
37 {
38 return std::abs(a);
39 }
40
41 inline float
42 abs_(std::complex<float> a)
43 {
44 return std::abs(a);
45 }
46
47 inline unsigned int
48 absSq(unsigned int a)
49 {
50 return a * a;
51 }
52
53 inline int
54 absSq(int a)
55 {
56 return a * a;
57 }
58
59 inline double
60 absSq(double a)
61 {
62 return a * a;
63 }
64
65 inline float
66 absSq(float a)
67 {
68 return a * a;
69 }
70
71 inline double
72 absSq(std::complex<double> a)
73 {
74 return a.real() * a.real() + a.imag() * a.imag();
75 }
76
77 inline float
78 absSq(std::complex<float> a)
79 {
80 return a.real() * a.real() + a.imag() * a.imag();
81 }
82
83 template <typename ValueType>
84 inline bool
85 absCompare(ValueType a, ValueType b)
86 {
87 return (abs_(a) < abs_(b));
88 }
89
90 // Get real part
91
92 template <typename T>
93 inline typename RealType<T>::Type
94 realPart(const T &x)
95 {
96 throwException(false, "realPart() not implemented for datatype.");
97 return 0;
98 }
99
100 template <>
102 realPart(const float &x)
103 {
104 return x;
105 }
106
107 template <>
109 realPart(const double &x)
110 {
111 return x;
112 }
113
114 template <>
115 inline RealType<std::complex<float>>::Type
116 realPart(const std::complex<float> &x)
117 {
118 return x.real();
119 }
120
121 template <>
123 realPart(const std::complex<double> &x)
124 {
125 return x.real();
126 }
127
128 // Get imaginary part
129
130 template <typename T>
131 inline typename RealType<T>::Type
132 imagPart(const T &x)
133 {
134 throwException(false, "imagPart() not implemented for datatype.");
135 return 0;
136 }
137
138 template <>
140 imagPart(const float &x)
141 {
142 return x;
143 }
144
145 template <>
147 imagPart(const double &x)
148 {
149 return x;
150 }
151
152 template <>
153 inline RealType<std::complex<float>>::Type
154 imagPart(const std::complex<float> &x)
155 {
156 return x.imag();
157 }
158
159 template <>
161 imagPart(const std::complex<double> &x)
162 {
163 return x.imag();
164 }
165
166 // Get the complex conjugate
167
168 template <typename T>
169 inline T
170 conjugate(const T &x)
171 {
172 throwException(false, "conjugate() not implemented for datatype.");
173 return 0;
174 }
175
176 template <>
177 inline float
178 conjugate(const float &x)
179 {
180 return x;
181 }
182
183 template <>
184 inline double
185 conjugate(const double &x)
186 {
187 return x;
188 }
189
190 template <>
191 inline std::complex<float>
192 conjugate(const std::complex<float> &x)
193 {
194 return std::conj(x);
195 }
196
197 template <>
198 inline std::complex<double>
199 conjugate(const std::complex<double> &x)
200 {
201 return std::conj(x);
202 }
203
204 } // namespace utils
205
206} // namespace dftefe
207
208#endif
unsigned int abs_(unsigned int a)
Definition: DataTypeOverloads.h:12
unsigned int absSq(unsigned int a)
Definition: DataTypeOverloads.h:48
bool absCompare(ValueType a, ValueType b)
Definition: DataTypeOverloads.h:85
void throwException(bool condition, std::string msg)
Definition: Exceptions.cpp:56
RealType< T >::Type imagPart(const T &x)
Definition: DataTypeOverloads.h:132
T conjugate(const T &x)
Definition: DataTypeOverloads.h:170
RealType< T >::Type realPart(const T &x)
Definition: DataTypeOverloads.h:94
dealii includes
Definition: AtomFieldDataSpherical.cpp:31
Definition: TypeConfig.h:15
void Type
Definition: TypeConfig.h:16