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
48#define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
49
50
64std::string scientific_format(double d, int width=20, int prec=10);
65
74std::string scientific_format(const std::vector<double>& v,
75 int width=20,
76 int prec=10);
77
90void m_assert(bool expr,
91 std::string expr_str,
92 std::string func,
93 std::string file,
94 int line,
95 std::string msg);
96
97
109bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol=1e-8);
110
111
112static inline std::string methodName(const std::string& prettyFunction)
113{
114 size_t colons = prettyFunction.find("::");
115 size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
116 size_t end = prettyFunction.rfind("(") - begin;
117
118 return prettyFunction.substr(begin,end) + "()";
119}
120
121#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:59
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
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:14