GPUE  v1.0
GPU Gross-Pitaevskii Equation numerical solver for Bose-Einstein condensates
parser.cu
Go to the documentation of this file.
1 #include "../include/parser.h"
2 #include "../include/unit_test.h"
3 #include "../include/operators.h"
4 
5 struct stat st = {0};
6 
7 Grid parseArgs(int argc, char** argv){
8 
9  // Creates initial grid class for the parameters
10  Grid par;
11  int opt;
12 
13  // Setting default values
14  par.store("xDim", 256);
15  par.store("yDim", 256);
16  par.store("zDim", 256);
17  par.store("omega", 0.0);
18  par.store("gammaY", 1.0);
19  par.store("gsteps", 1);
20  par.store("esteps", 1);
21  par.store("gdt", 1e-4);
22  par.store("dt", 1e-4);
23  par.store("device", 0);
24  par.store("atoms", 1);
25  par.store("read_wfc", false);
26  par.store("printSteps", 100);
27  par.store("winding", 0.0);
28  par.store("corotating", false);
29  par.store("gpe", false);
30  par.store("omegaZ", 6.283);
31  par.store("interaction",1.0);
32  par.store("laser_power",0.0);
33  par.store("angle_sweep",0.0);
34  par.store("kick_it", 0);
35  par.store("write_it", false);
36  par.store("x0_shift",0.0);
37  par.store("y0_shift",0.0);
38  par.store("z0_shift",0.0);
39  par.store("sepMinEpsilon",0.0);
40  par.store("graph", false);
41  par.store("unit_test",false);
42  par.store("omegaX", 6.283);
43  par.store("omegaY", 6.283);
44  par.store("data_dir", (std::string)"data/");
45  par.store("ramp", false);
46  par.store("ramp_type", 1);
47  par.store("dimnum", 2);
48  par.store("write_file", true);
49  par.store("fudge", 0.0);
50  par.store("kill_idx", -1);
51  par.store("mask_2d", 1.5e-4);
52  par.store("box_size", -0.01);
53  par.store("found_sobel", false);
54  par.store("energy_calc", false);
55  par.store("use_param_file", false);
56  par.store("param_file","param.cfg");
57  par.store("cyl_coord",false);
58  par.Afn = "rotation";
59  par.Kfn = "rotation_K";
60  par.Vfn = "2d";
61  par.Wfcfn = "2d";
62  par.store("conv_type", (std::string)"FFT");
63  par.store("charge", 0);
64  par.store("flip", false);
65  par.store("thresh_const", 1.0);
66 
67  optind = 1;
68 
69  while ((opt = getopt (argc, argv,
70  "b:d:D:C:x:y:w:m:G:g:e:T:t:n:p:rQ:L:Elsi:P:X:Y:O:k:WU:V:S:ahz:H:uA:v:Z:fc:F:K:R:q:I:j:J;")) !=-1)
71  {
72  switch (opt)
73  {
74  case 'x':
75  {
76  int xDim = atoi(optarg);
77  printf("Argument for x is given as %d\n",xDim);
78  par.store("xDim",(int)xDim);
79  break;
80  }
81  case 'b':
82  {
83  double box_size = atof(optarg);
84  printf("Argument for box_size is given as %E\n",box_size);
85  par.store("box_size",(double)box_size);
86  break;
87  }
88  case 'j':
89  {
90  double thresh_const = atof(optarg);
91  printf("Threshold constant is given as %E\n", thresh_const);
92  par.store("thresh_const",(double)thresh_const);
93  break;
94  }
95  case 'y':
96  {
97  int yDim = atoi(optarg);
98  printf("Argument for y is given as %d\n",yDim);
99  par.store("yDim",(int)yDim);
100  break;
101  }
102  case 'z':
103  {
104  int zDim = atoi(optarg);
105  printf("Argument for z is given as %d\n",zDim);
106  par.store("zDim",(int)zDim);
107  break;
108  }
109  case 'w':
110  {
111  double omega = atof(optarg);
112  printf("Argument for OmegaRotate is given as %E\n",omega);
113  par.store("omega",(double)omega);
114  break;
115  }
116  case 'm':
117  {
118  double mask_2d = atof(optarg);
119  printf("Argument for mask_2d is given as %E\n",mask_2d);
120  par.store("mask_2d",(double)mask_2d);
121  break;
122  }
123  case 'G':
124  {
125  double gammaY = atof(optarg);
126  printf("Argument for gamma is given as %E\n",gammaY);
127  par.store("gammaY",(double)gammaY);
128  break;
129  }
130  case 'g':
131  {
132  double gsteps = atof(optarg);
133  printf("Argument for Groundsteps is given as %E\n",gsteps);
134  par.store("gsteps",(int)gsteps);
135  break;
136  }
137  case 'e':
138  {
139  double esteps = atof(optarg);
140  printf("Argument for EvSteps is given as %E\n",esteps);
141  par.store("esteps",(int)esteps);
142  break;
143  }
144  case 'F':
145  {
146  double fudge = atof(optarg);
147  printf("Argument for Fudge Factor is given as %E\n",fudge);
148  par.store("fudge",fudge);
149  break;
150  }
151  case 'T':
152  {
153  double gdt = atof(optarg);
154  printf("Argument for groundstate Timestep is given as %E\n",
155  gdt);
156  par.store("gdt",(double)gdt);
157  break;
158  }
159  case 't':
160  {
161  double dt = atof(optarg);
162  printf("Argument for Timestep is given as %E\n",dt);
163  par.store("dt",(double)dt);
164  break;
165  }
166  case 'C':
167  {
168  int device = atoi(optarg);
169  printf("Argument for device (Card) is given as %d\n",device);
170  par.store("device",(int)device);
171  break;
172  }
173  case 'n':
174  {
175  double atoms = atof(optarg);
176  printf("Argument for atoms is given as %E\n",atoms);
177  par.store("atoms",(int)atoms);
178  break;
179  }
180  case 'I':
181  {
182  std::string data_dir = par.sval("data_dir");
183  std::string param_file = filecheck(data_dir
184  + (std::string)optarg);
185  std::cout << "Input parameter file is " << param_file << '\n';
186  par.store("param_file", (std::string)param_file);
187  par.store("use_param_file", true);
188  break;
189  }
190  case 'R':
191  {
192  int ramp_type = atoi(optarg);
193  printf("Ramping omega with imaginary time evolution\n");
194  par.store("ramp",true);
195  par.store("ramp_type", ramp_type);
196  break;
197  }
198  case 'r':
199  {
200  printf("Reading wavefunction from file.\n");
201  std::string data_dir = par.sval("data_dir");
202  std::string infile = filecheck(data_dir + "wfc_load");
203  std::string infilei = filecheck(data_dir + "wfci_load");
204  par.store("infile", infile);
205  par.store("infilei", infilei);
206  par.store("read_wfc",true);
207  break;
208  }
209  case 'p':
210  {
211  int print = atoi(optarg);
212  printf("Argument for Printout is given as %d\n",print);
213  par.store("printSteps",(int)print);
214  break;
215  }
216  case 'L':
217  {
218  double l = atof(optarg);
219  printf("Vortex winding is given as : %E\n",l);
220  par.store("winding",(double)l);
221  break;
222  }
223  case 'l':
224  {
225  printf("Angular momentum mode engaged\n");
226  par.store("corotating",true);
227  break;
228  }
229  case 'E':
230  {
231  printf("Printing energy calculation\n");
232  par.store("energy_calc",true);
233  break;
234  }
235  case 'f':
236  {
237  printf("No longer writing initial variables to file.\n");
238  par.store("write_file", false);
239  break;
240  }
241  case 'J':
242  {
243  printf("Using cylindrical coordinates for B field\n");
244  par.store("cyl_coord", true);
245  break;
246  }
247  case 'q':
248  {
249  int q = atoi(optarg);
250  std::cout << "Imprinting vortex with charge q " << q << '\n';
251  par.store("flip", true);
252  par.store("charge",(int)q);
253  break;
254  }
255  case 's':
256  {
257  printf("Non-linear mode engaged\n");
258  par.store("gpe",true);
259  break;
260  }
261  case 'Z':
262  {
263  double omegaZ = atof(optarg);
264  printf("Argument for OmegaZ is given as %E\n",omegaZ);
265  par.store("omegaZ",(double)omegaZ);
266  break;
267  }
268  case 'h':
269  {
270  std::string command = "src/print_help.sh ";
271  system(command.c_str());
272  exit(0);
273  break;
274  }
275  case 'H':
276  {
277  std::string command = "src/print_help.sh ";
278  command.append(optarg);
279  system(command.c_str());
280  exit(0);
281  break;
282  }
283  case 'i':
284  {
285  double interaction = atof(optarg);
286  printf("Argument for interaction scaling is %E\n",interaction);
287  par.store("interaction",interaction);
288  break;
289  }
290  case 'P':
291  {
292  double laser_power = atof(optarg);
293  printf("Argument for laser power is %E\n",laser_power);
294  par.store("laser_power",laser_power);
295  break;
296  }
297  case 'X':
298  {
299  double omegaX = atof(optarg);
300  printf("Argument for omegaX is %E\n",omegaX);
301  par.store("omegaX",(double)omegaX);
302  break;
303  }
304  case 'Y':
305  {
306  double omegaY = atof(optarg);
307  printf("Argument for omegaY is %E\n",omegaY);
308  par.store("omegaY",omegaY);
309  break;
310  }
311  case 'O':
312  {
313  double angle_sweep = atof(optarg);
314  printf("Argument for angle_sweep is %E\n",angle_sweep);
315  par.store("angle_sweep",angle_sweep);
316  break;
317  }
318  case 'k':
319  {
320  int kick_it = atoi(optarg);
321  printf("Argument for kick_it is %i\n",kick_it);
322  par.store("kick_it",kick_it);
323  break;
324  }
325  case 'W':
326  {
327  printf("Writing out\n");
328  par.store("write_it",true);
329  break;
330  }
331  case 'd':
332  {
333  std::string data_dir = optarg;
334  std::cout << "Data directory is: " << data_dir << '\n';
335  par.store("data_dir", data_dir + "/");
336  break;
337  }
338  case 'U':
339  {
340  double x0_shift = atof(optarg);
341  printf("Argument for x0_shift is %lf\n",x0_shift);
342  par.store("x0_shift",x0_shift);
343  break;
344  }
345  case 'u':
346  {
347  std::cout << "performing all unit tests" << '\n';
348  par.store("unit_test", true);
349  test_all();
350  exit(0);
351  }
352  case 'V':
353  {
354  double y0_shift = atof(optarg);
355  printf("Argument for y0_shift is %lf\n",y0_shift);
356  par.store("y0_shift",y0_shift);
357  break;
358  }
359  case 'v':
360  {
361  std::string pot = optarg;
362  std::cout << "Chosen potential is: " << pot << '\n';
363  par.Vfn = pot;
364  par.Wfcfn = pot;
365  break;
366  }
367  case 'S':
368  {
369  double sepMinEpsilon = atof(optarg);
370  printf("Argument for sepMinEpsilon is %lf\n",sepMinEpsilon);
371  par.store("sepMinEpsilon",sepMinEpsilon);
372  break;
373  }
374  case 'Q':
375  {
376  double z0_shift = atof(optarg);
377  printf("Argument for z0_shift is %lf\n",z0_shift);
378  par.store("z0_shift",z0_shift);
379  break;
380  }
381  case 'c':
382  {
383  int dimnum = atoi(optarg);
384  printf("Argument for number of coordinates is %d\n",dimnum);
385 
386  //setting 3d parameters
387  if (dimnum == 3){
388  par.Kfn = "rotation_K3d";
389  par.Vfn = "3d";
390  par.Wfcfn = "3d";
391  if (par.Afn == "file"){
392  std::cout << "Finding file for Az..." << '\n';
393  par.Azfile = filecheck("src/Azgauge");
394  }
395  par.store("box_size", 2.5e-5);
396  }
397  if (dimnum == 2){
398  par.store("zDim", 1);
399  }
400  par.store("dimnum",(int)dimnum);
401  break;
402  }
403 
404  // this case is special and may require reading input from a file
405  // or from cin
406  case 'A':
407  {
408  std::string field = optarg;
409  std::cout << "Chosen gauge field is: " << field << '\n';
410 
411  // If the file gauge field is chosen, we need to make sure the
412  // the files exist
413  if (strcmp(optarg, "file") == 0){
414  std::string data_dir = par.sval("data_dir");
415  std::cout << "Finding file for Ax..." << '\n';
416  par.Axfile = filecheck(data_dir + "/Axgauge");
417  std::cout << "Finding file for Ay..." << '\n';
418  par.Ayfile = filecheck(data_dir + "/Aygauge");
419  if (par.ival("dimnum") == 3){
420  std::cout << "Finding file for Az..." << '\n';
421  par.Azfile = filecheck(data_dir + "/Azgauge");
422  }
423  }
424 
425  par.Afn = field;
426  //exit(0);
427  break;
428  }
429  case 'a':
430  {
431  printf("Graphing mode engaged\n");
432  par.store("graph",true);
433  break;
434  }
435 
436  case 'K':
437  {
438  int kill_idx = atoi(optarg);
439  printf("Argument for kill_idx is %d\n",kill_idx);
440  par.store("kill_idx",kill_idx);
441  break;
442  }
443 
444  case '?':
445  {
446  if (optopt == 'c') {
447  fprintf (stderr,
448  "Option -%c requires an argument.\n", optopt);
449  }
450  else if (isprint (optopt)) {
451  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
452  }
453  else {
454  fprintf (stderr,
455  "Unknown option character `\\x%x'.\n",optopt);
456  }
457  return par;
458  default:
459  abort ();
460  }
461  }
462  }
463 
464  // Setting variables
465  if (stat(par.sval("data_dir").c_str(), &st) == -1) {
466  mkdir(par.sval("data_dir").c_str(), 0700);
467  }
468 
469  if (par.ival("dimnum") == 2){
470  par.store("zDim", 1);
471  }
472 
473 
474  return par;
475 }