1 |
#include <iostream> |
2 |
#include <fstream> |
3 |
#include <string> |
4 |
#include <vector> |
5 |
#include <cmath> |
6 |
#include "visualizerCmd.h" |
7 |
#include "SHAPE.hpp" |
8 |
|
9 |
using namespace std; |
10 |
|
11 |
int main(int argc, char* argv[]){ |
12 |
|
13 |
gengetopt_args_info args_info; |
14 |
int npts, i, j, k, write_size; |
15 |
double xmin, xmax, x; |
16 |
double ymin, ymax, y; |
17 |
double zmin, zmax, z; |
18 |
double r, theta, phi, costheta; |
19 |
double sigmaShape, sShape, epsShape; |
20 |
double sigmaProbe, sProbe, epsProbe; |
21 |
double sigma, s, eps; |
22 |
double rTerm, r6, r12; |
23 |
double energy; |
24 |
double range; |
25 |
|
26 |
char* shapeFileName; |
27 |
char* outputFileName; |
28 |
SHAPE* shape; |
29 |
FILE* outputFile; |
30 |
|
31 |
//parse the command line options |
32 |
if (cmdline_parser (argc, argv, &args_info) != 0) |
33 |
exit(1) ; |
34 |
|
35 |
if (args_info.shape_given){ |
36 |
shapeFileName = args_info.shape_arg; |
37 |
} |
38 |
else{ |
39 |
std::cerr << "Does not have shape file name" << endl; |
40 |
exit(1); |
41 |
} |
42 |
|
43 |
shape = new SHAPE(); |
44 |
shape->readSHAPEfile(shapeFileName); |
45 |
|
46 |
|
47 |
if (args_info.output_given){ |
48 |
outputFileName = args_info.output_arg; |
49 |
} |
50 |
else{ |
51 |
std::cerr << "Does not have output file name" << endl; |
52 |
exit(1); |
53 |
} |
54 |
|
55 |
outputFile = fopen(outputFileName, "w"); |
56 |
|
57 |
if (outputFile == NULL) { |
58 |
(void) fprintf(stderr, "Unable to open outputFile %s!\n", outputFileName); |
59 |
exit(8); |
60 |
} |
61 |
|
62 |
// grid has a default value (default=51), so it is always given |
63 |
npts = args_info.grid_arg; |
64 |
range = args_info.range_arg; |
65 |
|
66 |
xmin = -range; |
67 |
xmax = range; |
68 |
|
69 |
ymin = -range; |
70 |
ymax = range; |
71 |
|
72 |
zmin = -range; |
73 |
zmax = range; |
74 |
|
75 |
//sigmaProbe = 2.28; |
76 |
//sProbe = 2.28; |
77 |
//epsProbe = 0.020269601874; |
78 |
sigmaProbe = 0.0; |
79 |
sProbe = 0.0; |
80 |
epsProbe = 1.0; |
81 |
|
82 |
for (i = 0; i < npts; i++) { |
83 |
x = xmin + (xmax-xmin) * (double)i/(double)(npts-1); |
84 |
|
85 |
for (j = 0; j < npts; j++) { |
86 |
y = ymin + (ymax-ymin) * (double)j/(double)(npts-1); |
87 |
|
88 |
for (k = 0; k < npts; k++) { |
89 |
z = zmin + (zmax-zmin) * (double)k/(double)(npts-1); |
90 |
|
91 |
r = sqrt(x*x + y*y + z*z); |
92 |
costheta = z/r; |
93 |
phi = atan2(y,x); |
94 |
|
95 |
sigmaShape = shape->getSigmaAt(costheta, phi); |
96 |
sShape = shape->getSAt(costheta, phi); |
97 |
epsShape = shape->getEpsAt(costheta, phi); |
98 |
|
99 |
// Lorentz-Berthellot combining rules: |
100 |
|
101 |
sigma = (sigmaShape + sigmaProbe) / 2.0; |
102 |
s = (sShape + sProbe) / 2.0; |
103 |
eps = sqrt(epsShape * epsProbe); |
104 |
|
105 |
rTerm = s / (r - sigma + s); |
106 |
|
107 |
r6 = pow(rTerm, 6); |
108 |
r12 = r6*r6; |
109 |
|
110 |
energy = 4.0 * eps * (r12 - r6); |
111 |
|
112 |
write_size = fwrite(&energy,1,8,outputFile); |
113 |
|
114 |
} |
115 |
} |
116 |
} |
117 |
fclose(outputFile); |
118 |
return(0); |
119 |
} |