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 <sys/stat.h>
23#include <vector>
24
33#ifdef DBG
34 #define DEBUG(msg) std::cout << __FILE__ << " " << __LINE__ << ": " \
35 << msg << std::endl
36#else
37 #define DEBUG(msg)
38#endif
39
46#define ASSERT(expr, msg) m_assert(expr, #expr, __METHOD_NAME__, __FILE__, \
47 __LINE__, msg)
48
52#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
53
54
65std::string scientific_format(double d, int width=20, int prec=10);
66
67
78std::string scientific_format(const std::vector<double>& v,
79 int width=20,
80 int prec=10);
81
82
95 void m_assert(bool expr,
96 std::string expr_str,
97 std::string func,
98 std::string file,
99 int line,
100 std::string msg);
101
102
114 bool close_to(arma::vec &a, arma::vec &b, double tol=1e-8);
115
116
127 static inline std::string methodName(const std::string& pretty_function)
128{
129 size_t colons = pretty_function.find("::");
130 size_t begin = pretty_function.substr(0,colons).rfind(" ") + 1;
131 size_t end = pretty_function.rfind("(") - begin;
132
133 return pretty_function.substr(begin,end) + "()";
134}
135
136
147 bool mkpath(std::string path, int mode = 0777);
148
149#endif
m_assert
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:41
mkpath
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:74
close_to
bool 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:60
scientific_format
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:15