-
Notifications
You must be signed in to change notification settings - Fork 6
/
lewenstein.cpp
110 lines (98 loc) · 4.26 KB
/
lewenstein.cpp
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
107
108
109
110
/*
Provides a DLL / shared object file making available the Lewenstein model implemented in lewenstein.hpp.
Only used for the Python module (lewenstein.py); the Matlab/Octave wrapper is implemented in hhgmax_lewenstein.cpp.
Compilation for Linux (compiler is needed; e.g. on Ubuntu: `sudo aptitude install build-essential`):
# g++ -shared -o lewenstein.so lewenstein.cpp -fPIC -fopenmp -O3 -ansi
Notes:
* option -ffast-math will improve speed by 10% but might be unsafe
Compilation for Windows with MinGW, 64 bit (either on Windows or cross-compile on Linux):
x86_64-w64-mingw32-c++ -m64 -shared -o dll64/lewenstein.dll lewenstein.cpp -fopenmp -O3 -ansi
For 32 bit:
mingw32-c++ -shared -o dll32/lewenstein.dll lewenstein.cpp -fopenmp -O3 -ansi
(compiler might be called i686-w64-mingw32-c++ instead of mingw32-c++)
*/
#include "lewenstein.hpp"
extern "C" {
// expose H dipole elements (constructor and destructor)
void *dipole_elements_H_double(int dims, double alpha) {
if (dims==1) {
dipole_elements_H<1,double> *elements = new dipole_elements_H<1,double>(alpha);
return elements;
}
else if (dims==2) {
dipole_elements_H<2,double> *elements = new dipole_elements_H<2,double>(alpha);
return elements;
}
else if (dims==3) {
dipole_elements_H<3,double> *elements = new dipole_elements_H<3,double>(alpha);
return elements;
}
else {
return 0;
}
}
void dipole_elements_H_double_destroy(int dims, void *ptr) {
if (dims==1) {
dipole_elements_H<1,double> *elements = (dipole_elements_H<1,double> *)ptr;
delete elements;
}
else if (dims==2) {
dipole_elements_H<2,double> *elements = (dipole_elements_H<2,double> *)ptr;
delete elements;
}
else if (dims==3) {
dipole_elements_H<3,double> *elements = (dipole_elements_H<3,double> *)ptr;
delete elements;
}
}
// expose symmetric interpolated dipole elements (constructor and destructor)
void *dipole_elements_symmetric_interpolate_double(int dims, int N, double dp, double *dr, double *di) {
if (dims==1) {
dipole_elements_symmetric_interpolate<1,double> *elements = new dipole_elements_symmetric_interpolate<1,double>(N,dp,dr,di);
return elements;
}
else if (dims==2) {
dipole_elements_symmetric_interpolate<2,double> *elements = new dipole_elements_symmetric_interpolate<2,double>(N,dp,dr,di);
return elements;
}
else if (dims==3) {
dipole_elements_symmetric_interpolate<3,double> *elements = new dipole_elements_symmetric_interpolate<3,double>(N,dp,dr,di);
return elements;
}
else {
return 0;
}
}
void dipole_elements_symmetric_interpolate_double_destroy(int dims, void *ptr) {
if (dims==1) {
dipole_elements_symmetric_interpolate<1,double> *elements = (dipole_elements_symmetric_interpolate<1,double> *)ptr;
delete elements;
}
else if (dims==2) {
dipole_elements_symmetric_interpolate<2,double> *elements = (dipole_elements_symmetric_interpolate<2,double> *)ptr;
delete elements;
}
else if (dims==3) {
dipole_elements_symmetric_interpolate<3,double> *elements = (dipole_elements_symmetric_interpolate<3,double> *)ptr;
delete elements;
}
}
// expose implementation of Lewenstein model
void lewenstein_double(int dims, int N, double *t, double *Et, int weights_length, double *weights, double *at, double ip, double epsilon_t, void *dp, double *output) {
if (dims==1) {
lewenstein<1,double>(N, t, Et, weights_length, weights, at, ip, epsilon_t, *(dipole_elements_H<1,double> *)dp, output);
}
else if (dims==2) {
lewenstein<2,double>(N, t, Et, weights_length, weights, at, ip, epsilon_t, *(dipole_elements_H<2,double> *)dp, output);
}
else if (dims==3) {
lewenstein<3,double>(N, t, Et, weights_length, weights, at, ip, epsilon_t, *(dipole_elements_H<3,double> *)dp, output);
}
}
// expose implementation of Lewenstein in saddle-point approximation
void yakovlev_double(int dims, int N, double *t, double *Et, int weight_length, double *weights, int min_tau_i, double *dtfraction, double *at, double ip, double *output) {
if (dims==1) {
yakovlev<1,double>(N, t, Et, weight_length, weights, min_tau_i, dtfraction, at, ip, output);
}
}
}