-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcppUtility.cpp
More file actions
111 lines (68 loc) · 2.13 KB
/
Copy pathcppUtility.cpp
File metadata and controls
111 lines (68 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
cppUtility.cpp
Utilities for non-gpu stuff.
Nicolas Sawaya
2013
*/
cuDoubleComplex get_neg_inv_hbar_imag() {
cuDoubleComplex neg_inv_hbar_imag;
double hbar_inv_cm_fs, lightspeed;
//double planck_J_s = 6.62606957e-34; //J s
double pi = atan(1)*4;
//double hbar_J_s = planck_J_s/(2*pi); //J s
lightspeed = 299792548.; //m/s
hbar_inv_cm_fs = (1/100.) * (1e15) * 1./(lightspeed * 2*pi); //cm^-1 * fs
cout << "hbar_inv_cm_fs = " << hbar_inv_cm_fs << endl;
neg_inv_hbar_imag.x = 0;
neg_inv_hbar_imag.y = -1./hbar_inv_cm_fs; // i*(1/hbar)
cout << "neg_inv_hbar_imag.x = " << neg_inv_hbar_imag.x << endl;
cout << "neg_inv_hbar_imag.y = " << neg_inv_hbar_imag.y << endl;
return neg_inv_hbar_imag;
}
cuDoubleComplex powMult(cuDoubleComplex i, cuDoubleComplex j) {
cuDoubleComplex returnVal;
double a = i.x;
double b = i.y;
double c = j.x;
double d = j.y;
returnVal.x = a*c - b*d;
returnVal.y = a*d + b*c;
return returnVal;
}
cuDoubleComplex powComplex(cuDoubleComplex inVal, int n) {
cuDoubleComplex outVal;
outVal.x = 1;
outVal.y = 0;
if(n==0) {
return outVal;
}
// if(n==1) {
// return inVal;
// }
for(int i=0;i<n;i++) {
outVal = powMult(outVal, inVal);
}
return outVal;
}
int helperFactorial(int n)
{
return (n == 1 || n == 0) ? 1 : helperFactorial(n - 1) * n;
}
void stringSplit(string& str, string& str1, string& str2, char chrSplit) {
int pos = str.find(chrSplit);
str2 = str.substr( pos+2, str.size()-1);
str1 = str.substr(0,pos);
}
void stringTrim(string& str)
{
//Remove tabs
string::size_type pos1 = str.find_first_not_of('\t');
string::size_type pos2 = str.find_last_not_of('\t');
str = str.substr(pos1 == string::npos ? 0 : pos1,
pos2 == string::npos ? str.length() - 1 : pos2 - pos1 + 1);
//Remove spaces
pos1 = str.find_first_not_of(' ');
pos2 = str.find_last_not_of(' ');
str = str.substr(pos1 == string::npos ? 0 : pos1,
pos2 == string::npos ? str.length() - 1 : pos2 - pos1 + 1);
}