Simulating the Schrödinger wave equation using the Crank-Nicolson method in 2+1 dimensions
Simulating the Schrödinger wave equation using the Crank-Nicolson method in 2+1 dimensions
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1
17#ifndef __UTILS__
18#define __UTILS__
19
20#include <armadillo>
21#include <iomanip>
22#include <sstream>
23#include <string>
24#include <sys/stat.h>
25#include <vector>
26
35#ifdef DBG
36#define DEBUG(msg) \
37 std::cout << __FILE__ << " " << __LINE__ << ": " << msg << std::endl
38#else
39#define DEBUG(msg)
40#endif
41
45#define __METHOD_NAME__ details::methodName(__PRETTY_FUNCTION__)
46
47namespace details {
58inline std::string methodName(const std::string &pretty_function)
59{
60 size_t colons = pretty_function.find("::");
61 size_t begin = pretty_function.substr(0, colons).rfind(" ") + 1;
62 size_t end = pretty_function.rfind("(") - begin;
63
64 return pretty_function.substr(begin, end) + "()";
65}
66
67} // namespace details
68
69namespace utils {
70
81std::string scientific_format(double d, int width = 20, int prec = 10);
82
94std::string scientific_format(const std::vector<double> &v, int width = 20,
95 int prec = 10);
96
107bool mkpath(std::string path, int mode = 0777);
108
115std::string dirname(const std::string &path);
116
130std::string concatpath(const std::string &left, const std::string &right);
131
132// A function that prints the structure of a sparse matrix to screen.
133void print_sp_matrix_structure(const arma::sp_cx_mat &A);
134
135// A function that splits a string using a delimiter
136std::vector<std::string> split(const std::string &s, char delim);
137
138// trim from left
139std::string &ltrim(std::string &s, const char *t = " \t\n\r\f\v");
140
141// trim from right
142std::string &rtrim(std::string &s, const char *t = " \t\n\r\f\v");
143
144// trim from left & right
145std::string &trim(std::string &s, const char *t = " \t\n\r\f\v");
146
147// copying versions
148
149std::string ltrim_copy(std::string s, const char *t = " \t\n\r\f\v");
150
151std::string rtrim_copy(std::string s, const char *t = " \t\n\r\f\v");
152
153std::string trim_copy(std::string s, const char *t = " \t\n\r\f\v");
154} // namespace utils
155
156#endif
std::string methodName(const std::string &pretty_function)
Takes in the PRETTY_FUNCTION string and removes the return type.
Definition: utils.hpp:58
bool mkpath(std::string path, int mode=0777)
Make path given.
std::string scientific_format(double d, int width=20, int prec=10)
Turns a double into a string written in scientific format.
std::string concatpath(const std::string &left, const std::string &right)
Take 2 strings and concatenate them and make sure there is a directory separator (/) between them.
std::string dirname(const std::string &path)
Get the directory name of the path.