Penning Trap Simulation
Simulate particle behavior inside a Penning Trap
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1
15#ifndef __UTILS__
16#define __UTILS__
17
18#include <armadillo>
19#include <iomanip>
20#include <sstream>
21#include <string>
22#include <vector>
23
32#ifdef DBG
33 #define DEBUG(msg) std::cout << __FILE__ << " " << __LINE__ << ": " \
34 << msg << std::endl
35#else
36 #define DEBUG(msg)
37#endif
38
45#define ASSERT(expr, msg) m_assert(expr, #expr, __METHOD_NAME__, __FILE__, \
46 __LINE__, msg)
47
51#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
52
53
64std::string scientific_format(double d, int width=20, int prec=10);
65
66
77std::string scientific_format(const std::vector<double>& v,
78 int width=20,
79 int prec=10);
80
81
94void m_assert(bool expr,
95 std::string expr_str,
96 std::string func,
97 std::string file,
98 int line,
99 std::string msg);
100
101
113bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8);
114
115
126static inline std::string methodName(const std::string& pretty_function)
127{
128 size_t colons = pretty_function.find("::");
129 size_t begin = pretty_function.substr(0,colons).rfind(" ") + 1;
130 size_t end = pretty_function.rfind("(") - begin;
131
132 return pretty_function.substr(begin,end) + "()";
133}
134
135
146bool mkpath(std::string path, int mode = 0777);
147
148#endif
bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8)
Test if two armadillo vectors are close to each other.
Definition: utils.cpp:62
void m_assert(bool expr, std::string expr_str, std::string func, std::string file, int line, std::string msg)
Test an expression, confirm that test is ok, or abort execution.
Definition: utils.cpp:43
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:76
std::string scientific_format(double d, int width=20, int prec=10)
Turns a double into a string written in scientific format.
Definition: utils.cpp:17