# | Line 2 | Line 2 | |
---|---|---|
2 | #include <fstream> | |
3 | #include <string> | |
4 | #include <vector> | |
5 | + | #include <cmath> |
6 | #include "visualizerCmd.h" | |
7 | + | #include "SHAPE.hpp" |
8 | ||
7 | – | |
8 | – | int count_tokens(char *line, char *delimiters); |
9 | using namespace std; | |
10 | ||
11 | int main(int argc, char* argv[]){ | |
# | Line 15 | Line 15 | int main(int argc, char* argv[]){ | |
15 | double xmin, xmax, x; | |
16 | double ymin, ymax, y; | |
17 | double zmin, zmax, z; | |
18 | < | double r, theta, phi, f, s, w, w0; |
19 | < | double fp, sp, wp, tot; |
20 | < | double rup, ru, rlow; |
21 | < | FILE *my_file; |
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.input_given){ |
36 | < | shapeFileName = args_info.input_arg; |
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 | } | |
34 | – | |
35 | – | // grid has a default value (default=51), so it is always given |
36 | – | npts = args_info.grid_arg; |
42 | ||
43 | < | printf ("opening %s\n", shapeFileName); |
44 | < | shapeFile = fopen( shapeFileName, "r" ); |
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 | < | my_file = fopen("junk.dat", "w"); |
56 | < | if (my_file == NULL) { |
57 | < | (void) fprintf(stderr, "No File\n"); |
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 | < | npts = 51; |
66 | > | xmin = -range; |
67 | > | xmax = range; |
68 | ||
69 | < | xmin = -5.0; |
70 | < | xmax = 5.0; |
69 | > | ymin = -range; |
70 | > | ymax = range; |
71 | ||
72 | < | ymin = -5.0; |
73 | < | ymax = 5.0; |
72 | > | zmin = -range; |
73 | > | zmax = range; |
74 | ||
75 | < | zmin = -5.0; |
76 | < | zmax = 5.0; |
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 | ||
60 | – | rup = 4.0; |
61 | – | ru = 3.35; |
62 | – | rlow = 2.75; |
63 | – | w0 = 0.07715; |
64 | – | |
82 | for (i = 0; i < npts; i++) { | |
83 | < | x = xmin + (xmax-xmin) * (double)i/(double)npts; |
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; |
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; |
89 | > | z = zmin + (zmax-zmin) * (double)k/(double)(npts-1); |
90 | ||
91 | r = sqrt(x*x + y*y + z*z); | |
92 | < | theta = acos(z/r); |
93 | < | phi = atan(y/x); |
77 | < | |
78 | < | fp = pow((cos(theta) - 0.6),2) * pow((cos(theta) + 0.8),2); |
92 | > | costheta = z/r; |
93 | > | phi = atan2(y,x); |
94 | ||
95 | < | sp = (rup + 2.0*r - 3.0*rlow) * pow((rup - r),2) / pow((rup -rlow),3); |
95 | > | sigmaShape = shape->getSigmaAt(costheta, phi); |
96 | > | sShape = shape->getSAt(costheta, phi); |
97 | > | epsShape = shape->getEpsAt(costheta, phi); |
98 | ||
99 | < | if (r > rup) sp = 0.0; |
83 | < | if (r < rlow) sp = 1.0; |
99 | > | // Lorentz-Berthellot combining rules: |
100 | ||
101 | < | wp = sp*(fp - w0); |
101 | > | sigma = (sigmaShape + sigmaProbe) / 2.0; |
102 | > | s = (sShape + sProbe) / 2.0; |
103 | > | eps = sqrt(epsShape * epsProbe); |
104 | ||
105 | < | f = sin(theta)*sin(2.0*theta)*cos(2.0*phi); |
88 | < | |
89 | < | s = (ru + 2.0*r - 3.0*rlow) * pow((ru - r),2) / pow((ru -rlow),3); |
105 | > | rTerm = s / (r - sigma + s); |
106 | ||
107 | < | if (r > ru) s = 0.0; |
108 | < | if (r < rlow) s = 1.0; |
109 | < | |
110 | < | w = f*s; |
111 | < | |
112 | < | tot = w + wp; |
113 | < | |
98 | < | write_size = fwrite(&tot,1,8,my_file); |
99 | < | |
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(my_file); |
117 | > | fclose(outputFile); |
118 | return(0); | |
119 | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |