BSMPT 3.0.7
BSMPT - Beyond the Standard Model Phase Transitions : A C++ package for the computation of the EWPT in BSM models
Loading...
Searching...
No Matches
utility.h
Go to the documentation of this file.
1// Copyright (C) 2020 Philipp Basler, Margarete Mühlleitner and Jonas Müller
2// SPDX-FileCopyrightText: 2021 Philipp Basler, Margarete Mühlleitner and Jonas
3// Müller
4//
5// SPDX-License-Identifier: GPL-3.0-or-later
6
7#pragma once
8
9#include <BSMPT/config.h>
10#include <algorithm>
11#include <functional>
12#include <gsl/gsl_integration.h>
13#include <iostream>
14#include <numeric>
15#include <random>
16#include <string>
17#include <vector>
18
19#ifdef Boost_FOUND
20#include <boost/version.hpp>
21#if BOOST_VERSION >= 107200
22#include <boost/math/interpolators/cardinal_cubic_b_spline.hpp>
23#else
24#include <boost/math/interpolators/cubic_b_spline.hpp>
25#endif
26#endif
27
31namespace BSMPT
32{
33
37bool StringStartsWith(const std::string &str, const std::string &prefix);
38
45bool StringEndsWith(const std::string &str, const std::string &suffix);
46
50const std::string sep = "\t";
51
55int factorial(const int &a);
56
60template <typename T>
61std::vector<T> push_back(std::vector<T> &a, const std::vector<T> &b)
62{
63 return a.insert(a.end(), b.begin(), b.end());
64}
65
69template <typename T> std::string vec_to_string(const std::vector<T> &vec)
70{
71 std::string res;
72 bool first = true;
73 for (const auto &el : vec)
74 {
75 if (not first)
76 {
77 res += sep + std::to_string(el);
78 }
79 else
80 {
81 res = std::to_string(el);
82 first = false;
83 }
84 }
85 return res;
86}
87
91std::vector<std::string> split(const std::string &str, char delimiter);
92
96template <typename T>
97std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec)
98{
99 bool first = true;
100 for (const auto &el : vec)
101 {
102 if (not first)
103 {
104 os << sep;
105 }
106 else
107 {
108 first = false;
109 }
110 os << el;
111 }
112 return os;
113}
114
118template <typename T>
119std::vector<T> operator+(const std::vector<T> &a, const std::vector<T> &b)
120{
121 if (a.size() != b.size())
122 throw std::runtime_error(
123 "Vector cannot be added. Must have the same size.");
124 std::vector<T> result;
125 result.reserve(a.size());
126
127 std::transform(a.begin(),
128 a.end(),
129 b.begin(),
130 std::back_inserter(result),
131 std::plus<T>());
132 return result;
133}
134
138template <typename T>
139std::vector<T> operator-(const std::vector<T> &a, const std::vector<T> &b)
140{
141 if (a.size() != b.size())
142 throw("Vector cannot be subtracted. Must have the same size.");
143
144 std::vector<T> result;
145 result.reserve(a.size());
146
147 std::transform(a.begin(),
148 a.end(),
149 b.begin(),
150 std::back_inserter(result),
151 std::minus<T>());
152 return result;
153}
154
158template <typename T, typename T2>
159std::vector<T> operator*(const T2 &a, const std::vector<T> &b)
160{
161 std::vector<T> result;
162 result.reserve(b.size());
163
164 std::transform(b.begin(),
165 b.end(),
166 std::back_inserter(result),
167 [&a](T i) { return a * i; });
168 return result;
169}
170
174template <typename T, typename T2>
175std::vector<T> operator/(const std::vector<T> &a, const T2 &b)
176{
177 std::vector<T> result;
178 result.reserve(a.size());
179
180 std::transform(a.begin(),
181 a.end(),
182 std::back_inserter(result),
183 [&b](T i) { return i / b; });
184 return result;
185}
186
190template <typename T>
191T operator*(const std::vector<T> &a, const std::vector<T> &b)
192{
193 if (a.size() != b.size())
194 throw(
195 "Dot product between vectors cannot be done. Must have the same size.");
196
197 std::vector<T> result;
198 result.reserve(a.size());
199
200 std::transform(a.begin(),
201 a.end(),
202 b.begin(),
203 std::back_inserter(result),
204 [](T i, T j) { return (i * j); });
205
206 T result1 = std::accumulate(result.begin(), result.end(), 0.0);
207
208 return result1;
209}
210
214template <typename T>
215std::vector<T> operator*(const std::vector<std::vector<T>> &a,
216 const std::vector<T> &b)
217{
218 if (a.size() != b.size())
219 throw("Multiplication of matrix with vector cannot be done. Must have the "
220 "same size.");
221
222 std::vector<T> result;
223 result.reserve(a.size());
224
225 std::transform(a.begin(),
226 a.end(),
227 std::back_inserter(result),
228 [&](std::vector<T> i) { return (i * b); });
229
230 return result;
231}
232
236template <typename T>
237std::vector<T> flatten(std::vector<std::vector<T>> const &vec)
238{
239 std::vector<T> flattened;
240 for (auto const &v : vec)
241 {
242 flattened.insert(flattened.end(), v.begin(), v.end());
243 }
244 return flattened;
245}
246
252double L2NormVector(const std::vector<double> &vec);
253
259std::vector<std::vector<double>>
260Transpose(const std::vector<std::vector<double>> &A);
261
270double Li2(const double &x);
271
285double EllipIntSecond(const double &x);
286
290namespace ModelID
291{
292enum class ModelIDs;
293}
294std::ostream &operator<<(std::ostream &os, const ModelID::ModelIDs &Model);
295std::string ModelIDToString(const ModelID::ModelIDs &Model);
296
297#ifdef Boost_FOUND
298#if BOOST_VERSION >= 107200
299template <typename T>
300using boost_cubic_b_spline =
301 boost::math::interpolators::cardinal_cubic_b_spline<T>;
302#else
303template <typename T>
304using boost_cubic_b_spline = boost::math::cubic_b_spline<T>;
305#endif
306#endif
307
308} // namespace BSMPT
ModelIDs
The ModelIDs enum containing all IDs for identifying the Models.
Definition IncludeAllModels.h:32
This classes calculates the Bounce action of the potential with a set temperature.
Definition CalculateEtaInterface.h:24
std::vector< T > operator*(const T2 &a, const std::vector< T > &b)
multiplication of vector with scalar
Definition utility.h:159
std::vector< T > operator+(const std::vector< T > &a, const std::vector< T > &b)
vector addition
Definition utility.h:119
std::vector< T > operator-(const std::vector< T > &a, const std::vector< T > &b)
vector subtraction
Definition utility.h:139
std::vector< T > operator/(const std::vector< T > &a, const T2 &b)
division of vector by scalar
Definition utility.h:175
std::string vec_to_string(const std::vector< T > &vec)
vector to_string
Definition utility.h:69
bool StringStartsWith(const std::string &str, const std::string &prefix)
StringStartsWith checks if str starts with prefix.
Definition utility.cpp:46
int factorial(const int &a)
factorial function
Definition utility.cpp:51
std::vector< T > flatten(std::vector< std::vector< T > > const &vec)
flatten matrix
Definition utility.h:237
double L2NormVector(const std::vector< double > &vec)
L2NormVector.
Definition utility.cpp:56
std::vector< T > push_back(std::vector< T > &a, const std::vector< T > &b)
push back vector into vector
Definition utility.h:61
double Li2(const double &x)
Dilogarithm of x.
Definition utility.cpp:84
const std::string sep
seperator used to write into output files
Definition utility.h:50
std::vector< std::vector< double > > Transpose(const std::vector< std::vector< double > > &A)
Calculates the tranpose of a matrix.
Definition utility.cpp:68
bool StringEndsWith(const std::string &str, const std::string &suffix)
StringEndsWith tests if str ends with suffix.
Definition utility.cpp:104
std::ostream & operator<<(std::ostream &os, const StatusNLOStability &status)
Override << operator to handle StatusNLOStability.
Definition minimum_tracer.cpp:18
double EllipIntSecond(const double &x)
Incomplete elliptic integral of the second kind of x with a different parameterization and k^2 = -2.
Definition utility.cpp:110
std::vector< std::string > split(const std::string &str, char delimiter)
split string separated by delimiter into substrings
Definition utility.cpp:26