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) \
35 std::cout << __FILE__ << " " << __LINE__ << ": " << msg << std::endl
36#else
37#define DEBUG(msg)
38#endif
39
46#define ASSERT(expr, msg) \
47 m_assert(expr, #expr, __METHOD_NAME__, __FILE__, __LINE__, msg)
48
52#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
53
64std::string scientific_format(double d, int width = 20, int prec = 10);
65
77std::string scientific_format(const std::vector<double> &v, int width = 20,
78 int prec = 10);
79
92 void m_assert(bool expr, std::string expr_str, std::string func,
93 std::string file, int line, std::string msg);
94
106 bool close_to(arma::vec &a, arma::vec &b, double tol = 1e-8);
107
118 static inline std::string methodName(const std::string &pretty_function)
119{
120 size_t colons = pretty_function.find("::");
121 size_t begin = pretty_function.substr(0, colons).rfind(" ") + 1;
122 size_t end = pretty_function.rfind("(") - begin;
123
124 return pretty_function.substr(begin, end) + "()";
125}
126
137 bool mkpath(std::string path, int mode = 0777);
138
139#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:40
mkpath
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:72
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:58
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