flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
wrappers.cpp
Go to the documentation of this file.
1// ====================================================================
2// This file is part of FlexibleSUSY.
3//
4// FlexibleSUSY is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// FlexibleSUSY is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with FlexibleSUSY. If not, see
16// <http://www.gnu.org/licenses/>.
17// ====================================================================
18
19#include "wrappers.hpp"
20#include "Li2.hpp"
21#include "Li3.hpp"
22#include "Li4.hpp"
23#include "Li.hpp"
24#include "numerics2.hpp"
25#include "string_format.hpp"
26
27#include <complex>
28#include <cmath>
29
30namespace flexiblesusy {
31
32double Tan(double a) noexcept
33{
34 return std::tan(a);
35}
36
37double Cot(double a) noexcept
38{
39 return 1./Tan(a);
40}
41
42double Cos(double x) noexcept
43{
44 return std::cos(x);
45}
46
47double Sin(double x) noexcept
48{
49 return std::sin(x);
50}
51
52double Sec(double x) noexcept
53{
54 return 1./Cos(x);
55}
56
57double Csc(double x) noexcept
58{
59 return 1./Sin(x);
60}
61
62int Delta(int i, int j) noexcept
63{
64 return i == j;
65}
66
67bool IsClose(double a, double b, double eps) noexcept
68{
69 return std::abs(a - b) < eps;
70}
71
72bool IsCloseRel(double a, double b, double eps) noexcept
73{
74 return is_equal_rel(a, b, eps);
75}
76
77bool IsFinite(double x) noexcept
78{
79 return std::isfinite(x);
80}
81
82bool IsFinite(const std::complex<double>& x) noexcept
83{
84 return std::isfinite(x.real()) && std::isfinite(x.imag());
85}
86
87int KroneckerDelta(int i, int j) noexcept
88{
89 return i == j;
90}
91
92double Log(double a) noexcept
93{
94 return std::log(a);
95}
96
97std::complex<double> ComplexLog(double a) noexcept
98{
99 return fast_log(std::complex<double>(a,0.));
100}
101
102std::complex<double> ComplexLog(const std::complex<double>& z) noexcept
103{
104 return fast_log(z);
105}
106
107double FiniteLog(double a) noexcept
108{
109 const double l = std::log(a);
110 return std::isfinite(l) ? l : 0.;
111}
112
113double MaxAbsValue(double x) noexcept
114{
115 return Abs(x);
116}
117
118double MaxAbsValue(const std::complex<double>& x) noexcept
119{
120 return Abs(x);
121}
122
123double MaxRelDiff(double a, double b) noexcept
124{
125 const double max = std::max(std::abs(a), std::abs(b));
126
127 if (max < 1.0e-20) {
128 return 0.0;
129 }
130
131 return std::abs((a - b) / max);
132}
133
134double MaxRelDiff(const std::complex<double>& a, const std::complex<double>& b) noexcept
135{
136 const double max = std::max(std::abs(a), std::abs(b));
137
138 if (max < 1.0e-20) {
139 return 0.0;
140 }
141
142 return std::abs((a - b) / max);
143}
144
145double PolyLog(int n, double z) noexcept
146{
147 switch (n) {
148 case 1: return -std::log(1.0 - z);
149 case 2: return Li2(z);
150 case 3: return Li3(z);
151 case 4: return Li4(z);
152 default: break;
153 }
154
155 return std::real(PolyLog(n, std::complex<double>(z, 0.0)));
156}
157
158std::complex<double> PolyLog(int n, const std::complex<double>& z) noexcept
159{
160 return Li(n, z);
161}
162
163double Re(double x) noexcept
164{
165 return x;
166}
167
168double Re(const std::complex<double>& x) noexcept
169{
170 return std::real(x);
171}
172
173int Round(double a) noexcept
174{
175 return static_cast<int>(a >= 0. ? a + 0.5 : a - 0.5);
176}
177
178double Im(double) noexcept
179{
180 return 0.;
181}
182
183double Im(const std::complex<double>& x) noexcept
184{
185 return std::imag(x);
186}
187
188int Sign(double x) noexcept
189{
190 return (x >= 0.0 ? 1 : -1);
191}
192
193int Sign(int x) noexcept
194{
195 return (x >= 0 ? 1 : -1);
196}
197
198double SignedAbsSqrt(double a) noexcept
199{
200 return Sign(a) * AbsSqrt(a);
201}
202
203#define DEFINE_ToString(type) \
204 std::string ToString(type a) \
205 { \
206 return flexiblesusy::to_string(a); \
207 }
208
210DEFINE_ToString(unsigned char)
211DEFINE_ToString(unsigned short)
212DEFINE_ToString(unsigned int)
213DEFINE_ToString(unsigned long)
214DEFINE_ToString(unsigned long long)
215DEFINE_ToString(signed char)
216DEFINE_ToString(signed short)
218DEFINE_ToString(signed long)
219DEFINE_ToString(signed long long)
221DEFINE_ToString(const std::complex<double>&)
222
223double Total(double a) noexcept
224{
225 return a;
226}
227
228std::complex<double> Total(const std::complex<double>& a) noexcept
229{
230 return a;
231}
232
234Eigen::VectorXd UnitVector(int N, int i) noexcept
235{
236 Eigen::VectorXd v = Eigen::VectorXd::Zero(N);
237 v(i) = 1;
238
239 return v;
240}
241
243Eigen::MatrixXd MatrixProjector(int M, int N, int i, int j) noexcept
244{
245 Eigen::MatrixXd m = Eigen::MatrixXd::Zero(M,N);
246 m(i,j) = 1;
247
248 return m;
249}
250
251double ZeroSqrt(double x) noexcept
252{
253 return (x > 0.0 ? std::sqrt(x) : 0.0);
254}
255
256} // namespace flexiblesusy
#define M(i)
Definition: defs.h:629
double Re(double x) noexcept
Definition: wrappers.cpp:163
double Cos(double x) noexcept
Definition: wrappers.cpp:42
std::complex< double > Li(int64_t n, const std::complex< double > &z) noexcept
Complex polylogarithm .
Definition: Li.cpp:181
int Sign(double x) noexcept
Definition: wrappers.cpp:188
double FiniteLog(double a) noexcept
Definition: wrappers.cpp:107
double AbsSqrt(double x) noexcept
Definition: wrappers.hpp:110
bool IsCloseRel(double a, double b, double eps) noexcept
Definition: wrappers.cpp:72
double ZeroSqrt(double x) noexcept
sqrt(x) for x >= 0; 0 for x < 0
Definition: wrappers.cpp:251
bool IsClose(double a, double b, double eps) noexcept
Definition: wrappers.cpp:67
double PolyLog(int n, double z) noexcept
real polylogarithm
Definition: wrappers.cpp:145
double Li4(double x) noexcept
Real 4-th order polylogarithm .
Definition: Li4.cpp:136
int Delta(int i, int j) noexcept
Definition: wrappers.cpp:62
double Cot(double a) noexcept
Definition: wrappers.cpp:37
double Li2(double x) noexcept
Real dilogarithm .
Definition: Li2.cpp:68
double Sin(double x) noexcept
Definition: wrappers.cpp:47
double Log(double a) noexcept
Definition: wrappers.cpp:92
std::complex< double > ComplexLog(double a) noexcept
Definition: wrappers.cpp:97
double MaxRelDiff(double a, double b) noexcept
Definition: wrappers.cpp:123
double SignedAbsSqrt(double a) noexcept
signed square root of absolute
Definition: wrappers.cpp:198
double Total(double a) noexcept
sum of all arguments
Definition: wrappers.cpp:223
double Im(double) noexcept
Definition: wrappers.cpp:178
int KroneckerDelta(int i, int j) noexcept
Definition: wrappers.cpp:87
double Csc(double x) noexcept
Definition: wrappers.cpp:57
double Li3(double x) noexcept
Real trilogarithm .
Definition: Li3.cpp:104
std::complex< T > fast_log(const std::complex< T > &z) noexcept
fast implementation of complex logarithm
Definition: numerics2.hpp:160
double Sec(double x) noexcept
Definition: wrappers.cpp:52
int Round(double a) noexcept
Definition: wrappers.cpp:173
Eigen::MatrixXd MatrixProjector(int M, int N, int i, int j) noexcept
unit matrix projector of size MxN into direction i, j
Definition: wrappers.cpp:243
Complex< T > log(const Complex< T > &z) noexcept
Definition: complex.hpp:54
bool IsFinite(double x) noexcept
Definition: wrappers.cpp:77
bool is_equal_rel(const Eigen::PlainObjectBase< Derived > &a, const Eigen::PlainObjectBase< Derived > &b, double eps)
Definition: eigen_utils.hpp:89
double Tan(double a) noexcept
Definition: wrappers.cpp:32
Eigen::VectorXd UnitVector(int N, int i) noexcept
unit vector of length N into direction i
Definition: wrappers.cpp:234
int Abs(int x) noexcept
Definition: wrappers.hpp:62
double MaxAbsValue(double x) noexcept
Definition: wrappers.cpp:113
#define DEFINE_ToString(type)
Definition: wrappers.cpp:203