CoMD
A Mini-app for Co-Design of Classical Molecular Dynamics.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mycommand.c
Go to the documentation of this file.
1 /// \file
2 /// Handle command line arguments.
3 
4 #include "mycommand.h"
5 
6 #include <string.h>
7 #include <stdlib.h>
8 
9 #include "cmdLineParser.h"
10 #include "parallel.h"
11 #include "mytype.h"
12 
13 /// \page pg_running_comd Running CoMD
14 ///
15 /// \section sec_command_line_options Command Line Options
16 ///
17 /// CoMD accepts a number of command line options to set the parameters
18 /// of the simulation. Every option has both a long form and a short
19 /// form. The long and short form of the arguments are entirely
20 /// interchangeable and may be mixed. All the arguments are independent
21 /// with the exception of the \--potDir, \--potName, and \--potType,
22 /// (short forms -d, -n, and -t) arguments which are only relevant when
23 /// used in conjunction with \--doeam, (-e).
24 ///
25 /// Supported options are:
26 ///
27 /// | Long Form | Short Form | Default Value | Description
28 /// | :------------ | :---------: | :-----------: | :----------
29 /// | \--help | -h | N/A | print this message
30 /// | \--potDir | -d | pots | potential directory
31 /// | \--potName | -p | Cu_u6.eam | potential name
32 /// | \--potType | -t | funcfl | potential type (funcfl or setfl)
33 /// | \--doeam | -e | N/A | compute eam potentials (default is LJ)
34 /// | \--nx | -x | 20 | number of unit cells in x
35 /// | \--ny | -y | 20 | number of unit cells in y
36 /// | \--nz | -z | 20 | number of unit cells in z
37 /// | \--xproc | -i | 1 | number of ranks in x direction
38 /// | \--yproc | -j | 1 | number of ranks in y direction
39 /// | \--zproc | -k | 1 | number of ranks in z direction
40 /// | \--nSteps | -N | 100 | total number of time steps
41 /// | \--printRate | -n | 10 | number of steps between output
42 /// | \--dt | -D | 1 | time step (in fs)
43 /// | \--lat | -l | -1 | lattice parameter (Angstroms)
44 /// | \--temp | -T | 600 | initial temperature (K)
45 /// | \--delta | -r | 0 | initial delta (Angstroms)
46 ///
47 /// Notes:
48 ///
49 /// The negative value for the lattice parameter (such as the default
50 /// value, -1) is interpreted as a flag to indicate that the lattice
51 /// parameter should be set from the potential. All supplied potentials
52 /// are for copper and have a lattice constant of 3.615
53 /// Angstroms. Setting the lattice parameter to any positive value will
54 /// override the values provided in the potential files.
55 ///
56 /// The default potential name for the funcfl potential type is
57 /// Cu_u6.eam (Adams potential). For the setfl type the default
58 /// potential name is Cu01.eam.alloy (Mishin potential). Although these
59 /// will yield similar dynamics, the table have a very different number
60 /// of entries (500 vs. 10,000 points, respectively) This may give very
61 /// different performance, depending on the hardware.
62 ///
63 /// The default temperature is 600K. However, when using a perfect
64 /// lattice the system will rapidly cool to 300K due to equipartition of
65 /// energy.
66 ///
67 ///
68 /// \subsection ssec_example_command_lines Examples
69 ///
70 /// All of the examples below assume:
71 /// - The current working directory contains a copy of the pots dir (or
72 /// a link to it).
73 /// - The CoMD bin directory is located in ../bin
74 ///
75 /// Running in the examples directory will satisfy these requirements.
76 ///
77 /// ------------------------------
78 ///
79 /// The canonical base simulation, is
80 ///
81 /// $ mpirun -np 1 ../bin/CoMD-mpi
82 ///
83 /// Or, if the code was built without MPI:
84 ///
85 /// $ ../bin/CoMD-serial
86 ///
87 /// ------------------------------
88 ///
89 /// \subsubsection cmd_examples_potential Changing Potentials
90 ///
91 /// To run with the default (Adams) EAM potential, specify -e:
92 ///
93 /// $ ../bin/CoMD-mpi -e
94 ///
95 /// ------------------------------
96 ///
97 /// To run using the Mishin EAM potential contained in the setfl file
98 /// Cu01.eam.alloy. This potential uses much larger tables (10,000
99 /// entries vs. 500 for the Adams potential).
100 ///
101 /// $ ../bin/CoMD-mpi -e -t setfl
102 ///
103 /// ------------------------------
104 ///
105 /// Selecting the name of a setfl file without setting the appropriate
106 /// potential type
107 ///
108 /// $ ../bin/CoMD-mpi -e -p Cu01.eam.alloy
109 ///
110 /// will result in an error message:
111 ///
112 /// Only FCC Lattice type supported, not . Fatal Error.
113 ///
114 /// Instead use:
115 ///
116 /// $ ../bin/CoMD-mpi -e -t setfl -p Cu01.eam.alloy
117 ///
118 /// ------------------------------
119 ///
120 /// \subsubsection cmd_example_struct Initial Structure Modifications
121 ///
122 /// To change the lattice constant and run with an expanded or
123 /// compressed lattice:
124 ///
125 /// $ ../bin/CoMD-mpi -l 3.5
126 ///
127 /// This can be useful to test that the potential is being correctly
128 /// evaluated as a function of interatomic spacing (the cold
129 /// curve). However, due to the high degree of symmetry of a perfect
130 /// lattice, this type of test is unlikely to detect errors in the force
131 /// computation.
132 ///
133 /// ------------------------------
134 ///
135 /// Initialize with zero temperature (zero instantaneous particle
136 /// velocity) but with a random displacements of the atoms (in this
137 /// case the maximum displacement is 0.1 Angstrom along each axis).
138 ///
139 /// $ ../bin/CoMD-mpi --delta 0.1 -T 0
140 ///
141 /// Typical values of delta are in the range of 0.1 to 0.5 Angstroms.
142 /// Larger values of delta correspond to higher initial potential energy
143 /// which in turn produce higer temperatures as the structure
144 /// equilibrates.
145 ///
146 /// ------------------------------
147 ///
148 ///
149 /// \subsubsection cmd_examples_scaling Scaling Examples
150 ///
151 /// Simple shell scripts that demonstrate weak and strong scaling
152 /// studies are provided in the examples directory.
153 ///
154 /// ------------------------------
155 ///
156 /// Run the default global simulation size (32,000 atoms) distributed
157 /// over 8 cubic subdomains, an example of strong scaling. If the
158 /// number of processors does not equal (i*j*k) the run will abort.
159 /// Notice that spaces are optional between short form options and their
160 /// arguments.
161 ///
162 /// $ mpirun -np 8 ../bin/CoMD-mpi -i2 -j2 -k2
163 ///
164 /// ------------------------------
165 ///
166 /// Run a weak scaling example: the simulation is doubled in each
167 /// dimension from the default 20 x 20 x 20 and the number of subdomains
168 /// in each direction is also doubled.
169 ///
170 /// $ mpirun -np 8 ../bin/CoMD-mpi -i2 -j2 -k2 -x 40 -y 40 -z 40
171 ///
172 /// ------------------------------
173 ///
174 /// The same weak scaling run, but for 10,000 timesteps, with output
175 /// only every 100 steps.
176 ///
177 /// $ mpirun -np 8 ../bin/CoMD-mpi -i2 -j2 -k2 -x 40 -y 40 -z 40 -N 10000 -n 100
178 ///
179 
180 /// \details Initialize a Command structure with default values, then
181 /// parse any command line arguments that were supplied to overwrite
182 /// defaults.
183 ///
184 /// \param [in] argc the number of command line arguments
185 /// \param [in] argv the command line arguments array
186 Command parseCommandLine(int argc, char** argv)
187 {
188  Command cmd;
189 
190  memset(cmd.potDir, 0, 1024);
191  memset(cmd.potName, 0, 1024);
192  memset(cmd.potType, 0, 1024);
193  strcpy(cmd.potDir, "pots");
194  strcpy(cmd.potName, "\0"); // default depends on potType
195  strcpy(cmd.potType, "funcfl");
196  cmd.doeam = 0;
197  cmd.nx = 20;
198  cmd.ny = 20;
199  cmd.nz = 20;
200  cmd.xproc = 1;
201  cmd.yproc = 1;
202  cmd.zproc = 1;
203  cmd.nSteps = 100;
204  cmd.printRate = 10;
205  cmd.dt = 1.0;
206  cmd.lat = -1.0;
207  cmd.temperature = 600.0;
208  cmd.initialDelta = 0.0;
209 
210  int help=0;
211  // add arguments for processing. Please update the html documentation too!
212  addArg("help", 'h', 0, 'i', &(help), 0, "print this message");
213  addArg("potDir", 'd', 1, 's', cmd.potDir, sizeof(cmd.potDir), "potential directory");
214  addArg("potName", 'p', 1, 's', cmd.potName, sizeof(cmd.potName), "potential name");
215  addArg("potType", 't', 1, 's', cmd.potType, sizeof(cmd.potType), "potential type (funcfl or setfl)");
216  addArg("doeam", 'e', 0, 'i', &(cmd.doeam), 0, "compute eam potentials");
217  addArg("nx", 'x', 1, 'i', &(cmd.nx), 0, "number of unit cells in x");
218  addArg("ny", 'y', 1, 'i', &(cmd.ny), 0, "number of unit cells in y");
219  addArg("nz", 'z', 1, 'i', &(cmd.nz), 0, "number of unit cells in z");
220  addArg("xproc", 'i', 1, 'i', &(cmd.xproc), 0, "processors in x direction");
221  addArg("yproc", 'j', 1, 'i', &(cmd.yproc), 0, "processors in y direction");
222  addArg("zproc", 'k', 1, 'i', &(cmd.zproc), 0, "processors in z direction");
223  addArg("nSteps", 'N', 1, 'i', &(cmd.nSteps), 0, "number of time steps");
224  addArg("printRate", 'n', 1, 'i', &(cmd.printRate), 0, "number of steps between output");
225  addArg("dt", 'D', 1, 'd', &(cmd.dt), 0, "time step (in fs)");
226  addArg("lat", 'l', 1, 'd', &(cmd.lat), 0, "lattice parameter (Angstroms)");
227  addArg("temp", 'T', 1, 'd', &(cmd.temperature), 0, "initial temperature (K)");
228  addArg("delta", 'r', 1, 'd', &(cmd.initialDelta), 0, "initial delta (Angstroms)");
229 
230  processArgs(argc,argv);
231 
232  // If user didn't set potName, set type dependent default.
233  if (strlen(cmd.potName) == 0)
234  {
235  if (strcmp(cmd.potType, "setfl" ) == 0)
236  strcpy(cmd.potName, "Cu01.eam.alloy");
237  if (strcmp(cmd.potType, "funcfl") == 0)
238  strcpy(cmd.potName, "Cu_u6.eam");
239  }
240 
241  if (help)
242  {
243  printArgs();
244  freeArgs();
245  exit(2);
246  }
247  freeArgs();
248 
249  return cmd;
250 }
251 
252 void printCmdYaml(FILE* file, Command* cmd)
253 {
254  if (! printRank())
255  return;
256  fprintf(file,
257  "Command Line Parameters:\n"
258  " doeam: %d\n"
259  " potDir: %s\n"
260  " potName: %s\n"
261  " potType: %s\n"
262  " nx: %d\n"
263  " ny: %d\n"
264  " nz: %d\n"
265  " xproc: %d\n"
266  " yproc: %d\n"
267  " zproc: %d\n"
268  " Lattice constant: %g Angstroms\n"
269  " nSteps: %d\n"
270  " printRate: %d\n"
271  " Time step: %g fs\n"
272  " Initial Temperature: %g K\n"
273  " Initial Delta: %g Angstroms\n"
274  "\n",
275  cmd->doeam,
276  cmd->potDir,
277  cmd->potName,
278  cmd->potType,
279  cmd->nx, cmd->ny, cmd->nz,
280  cmd->xproc, cmd->yproc, cmd->zproc,
281  cmd->lat,
282  cmd->nSteps,
283  cmd->printRate,
284  cmd->dt,
285  cmd->temperature,
286  cmd->initialDelta
287  );
288  fflush(file);
289 }
290