1 /* ----------------------------------------------------------------------
2 This is the
3
4 ██╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗████████╗███████╗
5 ██║ ██║██╔════╝ ██╔════╝ ██╔════╝ ██║ ██║╚══██╔══╝██╔════╝
6 ██║ ██║██║ ███╗██║ ███╗██║ ███╗███████║ ██║ ███████╗
7 ██║ ██║██║ ██║██║ ██║██║ ██║██╔══██║ ██║ ╚════██║
8 ███████╗██║╚██████╔╝╚██████╔╝╚██████╔╝██║ ██║ ██║ ███████║
9 ╚══════╝╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝®
10
11 DEM simulation engine, released by
12 DCS Computing Gmbh, Linz, Austria
13 http://www.dcs-computing.com, office@dcs-computing.com
14
15 LIGGGHTS® is part of CFDEM®project:
16 http://www.liggghts.com | http://www.cfdem.com
17
18 Core developer and main author:
19 Christoph Kloss, christoph.kloss@dcs-computing.com
20
21 LIGGGHTS® is open-source, distributed under the terms of the GNU Public
22 License, version 2 or later. It is distributed in the hope that it will
23 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You should have
25 received a copy of the GNU General Public License along with LIGGGHTS®.
26 If not, see http://www.gnu.org/licenses . See also top-level README
27 and LICENSE files.
28
29 LIGGGHTS® and CFDEM® are registered trade marks of DCS Computing GmbH,
30 the producer of the LIGGGHTS® software and the CFDEM®coupling software
31 See http://www.cfdem.com/terms-trademark-policy for details.
32
33 -------------------------------------------------------------------------
34 Contributing author and copyright for this file:
35 This file is from LAMMPS, but has been modified. Copyright for
36 modification:
37
38 Copyright 2012- DCS Computing GmbH, Linz
39 Copyright 2009-2012 JKU Linz
40
41 Copyright of original file:
42 LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
43 http://lammps.sandia.gov, Sandia National Laboratories
44 Steve Plimpton, sjplimp@sandia.gov
45
46 Copyright (2003) Sandia Corporation. Under the terms of Contract
47 DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
48 certain rights in this software. This software is distributed under
49 the GNU General Public License.
50 ------------------------------------------------------------------------- */
51
52 #include <mpi.h>
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <string.h>
56 #include "ctype.h"
57 #include "unistd.h"
58 #include "sys/stat.h"
59 #include "input.h"
60 #include "style_command.h"
61 #include "universe.h"
62 #include "atom.h"
63 #include "atom_vec.h"
64 #include "comm.h"
65 #include "group.h"
66 #include "domain.h"
67 #include "output.h"
68 #include "thermo.h"
69 #include "force.h"
70 #include "pair.h"
71 #include "min.h"
72 #include "modify.h"
73 #include "compute.h"
74 #include "bond.h"
75 #include "angle.h"
76 #include "dihedral.h"
77 #include "improper.h"
78 #include "kspace.h"
79 #include "update.h"
80 #include "neighbor.h"
81 #include "special.h"
82 #include "variable.h"
83 #include "accelerator_cuda.h"
84 #include "error.h"
85 #include "memory.h"
86 #include "signal_handling.h"
87
88 #ifdef _OPENMP
89 #include "omp.h"
90 #endif
91
92 using namespace LAMMPS_NS;
93
94 #define DELTALINE 256
95 #define DELTA 4
96
97 /* ---------------------------------------------------------------------- */
98
Input(LAMMPS * lmp,int argc,char ** argv)99 Input::Input(LAMMPS *lmp, int argc, char **argv) : Pointers(lmp)
100 {
101 MPI_Comm_rank(world,&me);
102
103 maxline = maxcopy = maxwork = 0;
104 line = copy = work = NULL;
105 narg = maxarg = 0;
106 arg = NULL;
107
108 echo_screen = 0;
109 echo_log = 1;
110
111 label_active = 0;
112 labelstr = NULL;
113 jump_skip = 0;
114 ifthenelse_flag = 0;
115
116 if (me == 0) {
117 nfile = maxfile = 1;
118 infiles = (FILE **) memory->smalloc(sizeof(FILE *),"input:infiles");
119 infiles[0] = infile;
120 } else infiles = NULL;
121
122 variable = new Variable(lmp);
123
124 // fill map with commands listed in style_command.h
125
126 command_map = new std::map<std::string,CommandCreator>();
127
128 #define COMMAND_CLASS
129 #define CommandStyle(key,Class) \
130 (*command_map)[#key] = &command_creator<Class>;
131 #include "style_command.h"
132 #undef CommandStyle
133 #undef COMMAND_CLASS
134
135 // process command-line args
136 // check for args "-var" and "-echo"
137 // caller has already checked that sufficient arguments exist
138
139 int iarg = 0;
140 while (iarg < argc) {
141 if (strcmp(argv[iarg],"-var") == 0 || strcmp(argv[iarg],"-v") == 0) {
142 int jarg = iarg+3;
143 while (jarg < argc && argv[jarg][0] != '-') jarg++;
144 variable->set(argv[iarg+1],jarg-iarg-2,&argv[iarg+2]);
145 iarg = jarg;
146 } else if (strcmp(argv[iarg],"-echo") == 0 ||
147 strcmp(argv[iarg],"-e") == 0) {
148 narg = 1;
149 char **tmp = arg; // trick echo() into using argv instead of arg
150 arg = &argv[iarg+1];
151 echo();
152 arg = tmp;
153 iarg += 2;
154 } else iarg++;
155 }
156
157 seed_check_error = true;
158 }
159
160 /* ---------------------------------------------------------------------- */
161
~Input()162 Input::~Input()
163 {
164 // don't free command and arg strings
165 // they just point to other allocated memory
166
167 memory->sfree(line);
168 memory->sfree(copy);
169 memory->sfree(work);
170 if (labelstr) delete [] labelstr;
171 memory->sfree(arg);
172 memory->sfree(infiles);
173 delete variable;
174
175 delete command_map;
176 }
177
178 /* ----------------------------------------------------------------------
179 process all input from infile
180 infile = stdin or file if command-line arg "-in" was used
181 ------------------------------------------------------------------------- */
182
file()183 void Input::file()
184 {
185 int m,n;
186
187 while (1) {
188
189 // read a line from input script
190 // n = length of line including str terminator, 0 if end of file
191 // if line ends in continuation char '&', concatenate next line
192
193 if (me == 0) {
194 m = 0;
195 while (1) {
196 if (maxline-m < 2) reallocate(line,maxline,0);
197 if (fgets(&line[m],maxline-m,infile) == NULL) {
198 if (m) n = strlen(line) + 1;
199 else n = 0;
200 break;
201 }
202 m = strlen(line);
203 if (line[m-1] != '\n') continue;
204
205 m--;
206 while (m >= 0 && isspace(line[m])) m--;
207 if (m < 0 || line[m] != '&') {
208 line[m+1] = '\0';
209 n = m+2;
210 break;
211 }
212 }
213 }
214
215 // bcast the line
216 // if n = 0, end-of-file
217 // error if label_active is set, since label wasn't encountered
218 // if original input file, code is done
219 // else go back to previous input file
220
221 MPI_Bcast(&n,1,MPI_INT,0,world);
222 if (n == 0) {
223 if (label_active) error->all(FLERR,"Label wasn't found in input script");
224 if (me == 0) {
225 if (infile != stdin) fclose(infile);
226 nfile--;
227 }
228 MPI_Bcast(&nfile,1,MPI_INT,0,world);
229 if (nfile == 0) break;
230 if (me == 0) infile = infiles[nfile-1];
231 continue;
232 }
233
234 if (n > maxline) reallocate(line,maxline,n);
235 MPI_Bcast(line,n,MPI_CHAR,0,world);
236
237 // echo the command unless scanning for label
238
239 if (me == 0 && label_active == 0) {
240 if (echo_screen && screen) fprintf(screen,"%s\n",line);
241 if (echo_log && logfile) fprintf(logfile,"%s\n",line);
242 }
243
244 // parse the line
245 // if no command, skip to next line in input script
246
247 parse();
248 if (command == NULL) continue;
249
250 // if scanning for label, skip command unless it's a label command
251
252 if (label_active && strcmp(command,"label") != 0) continue;
253
254 // execute the command
255
256 if (execute_command()) {
257 char *str = new char[maxline+32];
258 sprintf(str,"Unknown command: %s",line);
259 error->all(FLERR,str);
260 }
261
262 if (SignalHandler::request_quit)
263 return;
264 }
265 }
266
267 /* ----------------------------------------------------------------------
268 process all input from filename
269 called from library interface
270 ------------------------------------------------------------------------- */
271
file(const char * filename)272 void Input::file(const char *filename)
273 {
274 // error if another nested file still open, should not be possible
275 // open new filename and set infile, infiles[0], nfile
276 // call to file() will close filename and decrement nfile
277
278 if (me == 0) {
279 if (nfile > 1)
280 error->one(FLERR,"Invalid use of library file() function");
281 infile = fopen(filename,"r");
282 if (infile == NULL) {
283 char str[512];
284 sprintf(str,"Cannot open input script %s",filename);
285 error->one(FLERR,str);
286 }
287 infiles[0] = infile;
288 nfile = 1;
289 }
290
291 file();
292 }
293
294 /* ----------------------------------------------------------------------
295 copy command in single to line, parse and execute it
296 return command name to caller
297 ------------------------------------------------------------------------- */
298
one(const char * single)299 char *Input::one(const char *single)
300 {
301 int n = strlen(single) + 1;
302 if (n > maxline) reallocate(line,maxline,n);
303 strcpy(line,single);
304
305 // echo the command unless scanning for label
306
307 if (me == 0 && label_active == 0) {
308 if (echo_screen && screen) fprintf(screen,"%s\n",line);
309 if (echo_log && logfile) fprintf(logfile,"%s\n",line);
310 }
311
312 // parse the line
313 // if no command, just return NULL
314
315 parse();
316 if (command == NULL) return NULL;
317
318 // if scanning for label, skip command unless it's a label command
319
320 if (label_active && strcmp(command,"label") != 0) return NULL;
321
322 // execute the command and return its name
323
324 if (execute_command()) {
325 char *str = new char[maxline+32];
326 sprintf(str,"Unknown command: %s",line);
327 error->all(FLERR,str);
328 }
329
330 return command;
331 }
332
333 /* ----------------------------------------------------------------------
334 parse copy of command line by inserting string terminators
335 strip comment = all chars from # on
336 replace all $ via variable substitution
337 command = first word
338 narg = # of args
339 arg[] = individual args
340 treat text between single/double quotes as one arg
341 ------------------------------------------------------------------------- */
342
parse()343 void Input::parse()
344 {
345 // duplicate line into copy string to break into words
346
347 int n = strlen(line) + 1;
348 if (n > maxcopy) reallocate(copy,maxcopy,n);
349 strcpy(copy,line);
350
351 // strip any # comment by replacing it with 0
352 // do not strip # inside single/double quotes
353
354 char quote = '\0';
355 char *ptr = copy;
356 while (*ptr) {
357 if (*ptr == '#' && !quote) {
358 *ptr = '\0';
359 break;
360 }
361 if (*ptr == quote) quote = '\0';
362 else if (*ptr == '"' || *ptr == '\'') quote = *ptr;
363 ptr++;
364 }
365
366 // perform $ variable substitution (print changes)
367 // except if searching for a label since earlier variable may not be defined
368
369 if (!label_active) substitute(copy,work,maxcopy,maxwork,1);
370
371 // command = 1st arg in copy string
372
373 char *next;
374 command = nextword(copy,&next);
375 if (command == NULL) return;
376
377 // point arg[] at each subsequent arg in copy string
378 // nextword() inserts string terminators into copy string to delimit args
379 // nextword() treats text between single/double quotes as one arg
380
381 narg = 0;
382 ptr = next;
383 while (ptr) {
384 if (narg == maxarg) {
385 maxarg += DELTA;
386 arg = (char **) memory->srealloc(arg,maxarg*sizeof(char *),"input:arg");
387 }
388 arg[narg] = nextword(ptr,&next);
389 if (!arg[narg]) break;
390 narg++;
391 ptr = next;
392 }
393 }
394
395 /* ----------------------------------------------------------------------
396 find next word in str
397 insert 0 at end of word
398 ignore leading whitespace
399 treat text between single/double quotes as one arg
400 matching quote must be followed by whitespace char if not end of string
401 strip quotes from returned word
402 return ptr to start of word
403 return next = ptr after word or NULL if word ended with 0
404 return NULL if no word in string
405 ------------------------------------------------------------------------- */
406
nextword(char * str,char ** next)407 char *Input::nextword(char *str, char **next)
408 {
409 char *start,*stop;
410
411 start = &str[strspn(str," \t\n\v\f\r")];
412 if (*start == '\0') return NULL;
413
414 if (*start == '"' || *start == '\'') {
415 stop = strchr(&start[1],*start);
416 if (!stop) error->all(FLERR,"Unbalanced quotes in input line");
417 if (stop[1] && !isspace(stop[1]))
418 error->all(FLERR,"Input line quote not followed by whitespace");
419 start++;
420 } else stop = &start[strcspn(start," \t\n\v\f\r")];
421
422 if (*stop == '\0') *next = NULL;
423 else *next = stop+1;
424 *stop = '\0';
425 return start;
426 }
427
428 /* ----------------------------------------------------------------------
429 substitute for $ variables in str using work str2 and return it
430 reallocate str/str2 to hold expanded version if necessary & reset max/max2
431 print updated string if flag is set and not searching for label
432 label_active will be 0 if called from external class
433 ------------------------------------------------------------------------- */
434
substitute(char * & str,char * & str2,int & max,int & max2,int flag)435 void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag)
436 {
437 // use str2 as scratch space to expand str, then copy back to str
438 // reallocate str and str2 as necessary
439 // do not replace $ inside single/double quotes
440 // var = pts at variable name, ended by NULL
441 // if $ is followed by '{', trailing '}' becomes NULL
442 // else $x becomes x followed by NULL
443 // beyond = points to text following variable
444
445 int i,n,paren_count;
446 char immediate[256];
447 char *var,*value,*beyond;
448 bool in_double_quote = false;
449 bool in_single_quote = false;
450 char *ptr = str;
451
452 n = strlen(str) + 1;
453 if (n > max2) reallocate(str2,max2,n);
454 *str2 = '\0';
455 char *ptr2 = str2;
456
457 while (*ptr) {
458 // variable substitution
459 if (*ptr == '$' && !in_double_quote && !in_single_quote) {
460
461 // value = ptr to expanded variable
462 // variable name between curly braces, e.g. ${a}
463
464 if (*(ptr+1) == '{') {
465 var = ptr+2;
466 i = 0;
467 while (var[i] != '\0' && var[i] != '}') i++;
468 if (var[i] == '\0') error->one(FLERR,"Invalid variable name");
469 var[i] = '\0';
470 beyond = ptr + strlen(var) + 3;
471 value = variable->retrieve(var);
472
473 // immediate variable between parenthesis, e.g. $(1/2)
474
475 } else if (*(ptr+1) == '(') {
476 var = ptr+2;
477 paren_count = 0;
478 i = 0;
479
480 while (var[i] != '\0' && !(var[i] == ')' && paren_count == 0)) {
481 switch (var[i]) {
482 case '(': paren_count++; break;
483 case ')': paren_count--; break;
484 default: ;
485 }
486 i++;
487 }
488
489 if (var[i] == '\0') error->one(FLERR,"Invalid immediate variable");
490 var[i] = '\0';
491 beyond = ptr + strlen(var) + 3;
492 sprintf(immediate,"%.20g",variable->compute_equal(var));
493 value = immediate;
494
495 // single character variable name, e.g. $a
496 } else {
497 var = ptr;
498 var[0] = var[1];
499 var[1] = '\0';
500 beyond = ptr + 2;
501 value = variable->retrieve(var);
502 }
503 if (value == NULL) {
504
505 error->one(FLERR,"Substitution for illegal variable");
506 }
507
508 // check if storage in str2 needs to be expanded
509 // re-initialize ptr and ptr2 to the point beyond the variable.
510
511 n = strlen(str2) + strlen(value) + strlen(beyond) + 1;
512 if (n > max2) reallocate(str2,max2,n);
513 strcat(str2,value);
514 ptr2 = str2 + strlen(str2);
515 ptr = beyond;
516
517 // output substitution progress if requested
518 if (flag && me == 0 && label_active == 0) {
519 if (echo_screen && screen) fprintf(screen,"%s%s\n",str2,beyond);
520 if (echo_log && logfile) fprintf(logfile,"%s%s\n",str2,beyond);
521 }
522 continue;
523 }
524 if (*ptr == '"')
525 in_double_quote = !in_double_quote;
526 else if (*ptr == '\'')
527 in_single_quote = !in_single_quote;
528 // copy current character into str2
529
530 *ptr2++ = *ptr++;
531 *ptr2 = '\0';
532 }
533 // set length of input str to length of work str2
534 // copy work string back to input str
535
536 if (max2 > max) reallocate(str,max,max2);
537 strcpy(str,str2);
538 }
539
540 /* ----------------------------------------------------------------------
541 rellocate a string
542 if n > 0: set max >= n in increments of DELTALINE
543 if n = 0: just increment max by DELTALINE
544 ------------------------------------------------------------------------- */
545
reallocate(char * & str,int & max,int n)546 void Input::reallocate(char *&str, int &max, int n)
547 {
548 if (n) {
549 while (n > max) max += DELTALINE;
550 } else max += DELTALINE;
551
552 str = (char *) memory->srealloc(str,max*sizeof(char),"input:str");
553 }
554
555 /* ----------------------------------------------------------------------
556 process a single parsed command
557 return 0 if successful, -1 if did not recognize command
558 ------------------------------------------------------------------------- */
559
execute_command()560 int Input::execute_command()
561 {
562 int flag = 1;
563
564 if (!strcmp(command,"clear")) clear();
565 else if (!strcmp(command,"echo")) echo();
566 else if (!strcmp(command,"if")) ifthenelse();
567 else if (!strcmp(command,"include")) include();
568 else if (!strcmp(command,"jump")) jump();
569 else if (!strcmp(command,"label")) label();
570 else if (!strcmp(command,"log")) log();
571 else if (!strcmp(command,"next")) next_command();
572 else if (!strcmp(command,"partition")) partition();
573 else if (!strcmp(command,"print")) print();
574 else if (!strcmp(command,"quit")) quit();
575 else if (!strcmp(command,"shell")) shell();
576 else if (!strcmp(command,"variable")) variable_command();
577
578 else if (!strcmp(command,"angle_coeff")) angle_coeff();
579 else if (!strcmp(command,"angle_style")) angle_style();
580 else if (!strcmp(command,"atom_modify")) atom_modify();
581 else if (!strcmp(command,"atom_style")) atom_style();
582 else if (!strcmp(command,"bond_coeff")) bond_coeff();
583 else if (!strcmp(command,"bond_style")) bond_style();
584 else if (!strcmp(command,"boundary")) boundary();
585 else if (!strcmp(command,"box")) box();
586 else if (!strcmp(command,"communicate")) communicate();
587 else if (!strcmp(command,"compute")) compute();
588 else if (!strcmp(command,"compute_modify")) compute_modify();
589 else if (!strcmp(command,"dielectric")) dielectric();
590 else if (!strcmp(command,"dihedral_coeff")) dihedral_coeff();
591 else if (!strcmp(command,"dihedral_style")) dihedral_style();
592 else if (!strcmp(command,"dimension")) dimension();
593 else if (!strcmp(command,"dump")) dump();
594 else if (!strcmp(command,"dump_modify")) dump_modify();
595 else if (!strcmp(command,"fix")) fix();
596 else if (!strcmp(command,"fix_modify")) fix_modify();
597 else if (!strcmp(command,"force_dt_reset")) force_dt_reset();
598 else if (!strcmp(command,"group")) group_command();
599 else if (!strcmp(command,"improper_coeff")) improper_coeff();
600 else if (!strcmp(command,"improper_style")) improper_style();
601 else if (!strcmp(command,"kspace_modify")) kspace_modify();
602 else if (!strcmp(command,"kspace_style")) kspace_style();
603 else if (!strcmp(command,"lattice")) lattice();
604 else if (!strcmp(command,"mass")) mass();
605 else if (!strcmp(command,"min_modify")) min_modify();
606 else if (!strcmp(command,"min_style")) min_style();
607 else if (!strcmp(command,"neighbor")) neighbor_command();
608 else if (!strcmp(command,"newton")) newton();
609 else if (!strcmp(command,"package")) package();
610 else if (!strcmp(command,"pair_coeff")) pair_coeff();
611 else if (!strcmp(command,"pair_modify")) pair_modify();
612 else if (!strcmp(command,"pair_style")) pair_style();
613 else if (!strcmp(command,"pair_write")) pair_write();
614 else if (!strcmp(command,"processors")) processors();
615 else if (!strcmp(command,"region")) region();
616 else if (!strcmp(command,"reset_timestep")) reset_timestep();
617 else if (!strcmp(command,"restart")) restart();
618 else if (!strcmp(command,"run_style")) run_style();
619 else if (!strcmp(command,"soft_particles")) soft_particles();
620 else if (!strcmp(command,"hard_particles")) hard_particles();
621 else if (!strcmp(command,"write_restart_on_signal")) write_restart_on_signal();
622 else if (!strcmp(command,"special_bonds")) special_bonds();
623 else if (!strcmp(command,"suffix")) suffix();
624 else if (!strcmp(command,"thermo")) thermo();
625 else if (!strcmp(command,"thermo_modify")) thermo_modify();
626 else if (!strcmp(command,"thermo_style")) thermo_style();
627 else if (!strcmp(command,"thermo_log")) thermo_log();
628 else if (!strcmp(command,"timestep")) timestep();
629 else if (!strcmp(command,"uncompute")) uncompute();
630 else if (!strcmp(command,"undump")) undump();
631 else if (!strcmp(command,"unfix")) unfix();
632 else if (!strcmp(command,"units")) units();
633 else if (!strcmp(command,"modify_timing")) modify_timing();
634
635 else flag = 0;
636
637 // return if command was listed above
638
639 if (flag) return 0;
640
641 // invoke commands added via style_command.h
642
643 if (command_map->find(command) != command_map->end()) {
644 CommandCreator command_creator = (*command_map)[command];
645 command_creator(lmp,narg,arg);
646 return 0;
647 }
648
649 // unrecognized command
650
651 return -1;
652 }
653
654 /* ----------------------------------------------------------------------
655 one instance per command in style_command.h
656 ------------------------------------------------------------------------- */
657
658 template <typename T>
command_creator(LAMMPS * lmp,int narg,char ** arg)659 void Input::command_creator(LAMMPS *lmp, int narg, char **arg)
660 {
661 T cmd(lmp);
662 cmd.command(narg,arg);
663 }
664
665 /* ---------------------------------------------------------------------- */
666 /* ---------------------------------------------------------------------- */
667 /* ---------------------------------------------------------------------- */
668
669 /* ---------------------------------------------------------------------- */
670
clear()671 void Input::clear()
672 {
673 if (narg > 0) error->all(FLERR,"Illegal clear command");
674 lmp->destroy();
675 lmp->create();
676 lmp->post_create();
677 }
678
679 /* ---------------------------------------------------------------------- */
680
echo()681 void Input::echo()
682 {
683 if (narg != 1) error->all(FLERR,"Illegal echo command");
684
685 if (strcmp(arg[0],"none") == 0) {
686 echo_screen = 0;
687 echo_log = 0;
688 } else if (strcmp(arg[0],"screen") == 0) {
689 echo_screen = 1;
690 echo_log = 0;
691 } else if (strcmp(arg[0],"log") == 0) {
692 echo_screen = 0;
693 echo_log = 1;
694 } else if (strcmp(arg[0],"both") == 0) {
695 echo_screen = 1;
696 echo_log = 1;
697 } else error->all(FLERR,"Illegal echo command");
698 }
699
700 /* ---------------------------------------------------------------------- */
701
ifthenelse()702 void Input::ifthenelse()
703 {
704 if (narg < 3) error->all(FLERR,"Illegal if command");
705
706 // substitute for variables in Boolean expression for "if"
707 // in case expression was enclosed in quotes
708 // must substitute on copy of arg else will step on subsequent args
709
710 int n = strlen(arg[0]) + 1;
711 if (n > maxline) reallocate(line,maxline,n);
712 strcpy(line,arg[0]);
713 substitute(line,work,maxline,maxwork,0);
714
715 // evaluate Boolean expression for "if"
716
717 double btest;
718
719 if(strncmp(line,"property_",9) == 0)
720 {
721 if(strlen(line) < 11)
722 error->all(FLERR,"Illegal if command, length of argument too short");
723 if(modify->find_fix_property(&(line[9]),"property/global","any",0,0,"if",false))
724 btest = 1.0;
725 else
726 btest = 0.0;
727 }
728
729 else
730 btest = variable->evaluate_boolean(line);
731
732 // bound "then" commands
733
734 if (strcmp(arg[1],"then") != 0) error->all(FLERR,"Illegal if command");
735
736 int first = 2;
737 int iarg = first;
738 while (iarg < narg &&
739 (strcmp(arg[iarg],"elif") != 0 && strcmp(arg[iarg],"else") != 0))
740 iarg++;
741 int last = iarg-1;
742
743 // execute "then" commands
744 // make copies of all arg string commands
745 // required because re-parsing a command via one() will wipe out args
746
747 if (btest != 0.0) {
748 int ncommands = last-first + 1;
749 if (ncommands <= 0) error->all(FLERR,"Illegal if command");
750
751 char **commands = new char*[ncommands];
752 ncommands = 0;
753 for (int i = first; i <= last; i++) {
754 int n = strlen(arg[i]) + 1;
755 if (n == 1) error->all(FLERR,"Illegal if command");
756 commands[ncommands] = new char[n];
757 strcpy(commands[ncommands],arg[i]);
758 ncommands++;
759 }
760
761 ifthenelse_flag = 1;
762 for (int i = 0; i < ncommands; i++)
763 {
764 one(commands[i]);
765 if (SignalHandler::request_quit)
766 break;
767 }
768 ifthenelse_flag = 0;
769
770 for (int i = 0; i < ncommands; i++) delete [] commands[i];
771 delete [] commands;
772
773 return;
774 }
775
776 // done if no "elif" or "else"
777
778 if (iarg == narg) return;
779
780 // check "elif" or "else" until find commands to execute
781 // substitute for variables and evaluate Boolean expression for "elif"
782 // must substitute on copy of arg else will step on subsequent args
783 // bound and execute "elif" or "else" commands
784
785 while (1) {
786 if (iarg+2 > narg) error->all(FLERR,"Illegal if command");
787 if (strcmp(arg[iarg],"elif") == 0) {
788 n = strlen(arg[iarg+1]) + 1;
789 if (n > maxline) reallocate(line,maxline,n);
790 strcpy(line,arg[iarg+1]);
791 substitute(line,work,maxline,maxwork,0);
792 btest = variable->evaluate_boolean(line);
793 first = iarg+2;
794 } else {
795 btest = 1.0;
796 first = iarg+1;
797 }
798
799 iarg = first;
800 while (iarg < narg &&
801 (strcmp(arg[iarg],"elif") != 0 && strcmp(arg[iarg],"else") != 0))
802 iarg++;
803 last = iarg-1;
804
805 if (btest == 0.0) continue;
806
807 int ncommands = last-first + 1;
808 if (ncommands <= 0) error->all(FLERR,"Illegal if command");
809
810 char **commands = new char*[ncommands];
811 ncommands = 0;
812 for (int i = first; i <= last; i++) {
813 int n = strlen(arg[i]) + 1;
814 if (n == 1) error->all(FLERR,"Illegal if command");
815 commands[ncommands] = new char[n];
816 strcpy(commands[ncommands],arg[i]);
817 ncommands++;
818 }
819
820 // execute the list of commands
821
822 ifthenelse_flag = 1;
823 for (int i = 0; i < ncommands; i++) one(commands[i]);
824 ifthenelse_flag = 0;
825
826 // clean up
827
828 for (int i = 0; i < ncommands; i++) delete [] commands[i];
829 delete [] commands;
830
831 return;
832 }
833 }
834
835 /* ---------------------------------------------------------------------- */
836
include()837 void Input::include()
838 {
839 if (narg != 1) error->all(FLERR,"Illegal include command");
840
841 // do not allow include inside an if command
842 // NOTE: this check will fail if a 2nd if command was inside the if command
843 // and came before the include
844
845 if (ifthenelse_flag)
846 error->all(FLERR,"Cannot use include command within an if command");
847 if (me == 0) {
848 if (nfile == maxfile) {
849 maxfile++;
850 infiles = (FILE **)
851 memory->srealloc(infiles,maxfile*sizeof(FILE *),"input:infiles");
852 if(!infiles)
853 error->one(FLERR,"overflow in including input scripts");
854 }
855 infile = fopen(arg[0],"r");
856 if (infile == NULL) {
857 char str[512];
858 sprintf(str,"Cannot open input script %s",arg[0]);
859 error->one(FLERR,str);
860 }
861 infiles[nfile++] = infile;
862 }
863 }
864
865 /* ---------------------------------------------------------------------- */
866
jump()867 void Input::jump()
868 {
869 if (narg < 1 || narg > 2) error->all(FLERR,"Illegal jump command");
870
871 if (jump_skip) {
872 jump_skip = 0;
873 return;
874 }
875
876 if (me == 0) {
877 if (strcmp(arg[0],"SELF") == 0)
878 {
879 if (infile == stdin)
880 error->one(FLERR, "jump SELF is not allowed when using stdin, use -in instead");
881 rewind(infile);
882 }
883 else {
884 if (infile != stdin) fclose(infile);
885 infile = fopen(arg[0],"r");
886 if (infile == NULL) {
887 char str[512];
888 sprintf(str,"Cannot open input script %s",arg[0]);
889 error->one(FLERR,str);
890 }
891 infiles[nfile-1] = infile;
892 }
893 }
894
895 if (narg == 2) {
896 label_active = 1;
897 if (labelstr) delete [] labelstr;
898 int n = strlen(arg[1]) + 1;
899 labelstr = new char[n];
900 strcpy(labelstr,arg[1]);
901 }
902 }
903
904 /* ---------------------------------------------------------------------- */
905
label()906 void Input::label()
907 {
908 if (narg != 1) error->all(FLERR,"Illegal label command");
909 if (label_active && strcmp(labelstr,arg[0]) == 0) label_active = 0;
910 }
911
912 /* ---------------------------------------------------------------------- */
913
log()914 void Input::log()
915 {
916 if (narg > 2) error->all(FLERR,"Illegal log command");
917
918 int appendflag = 0;
919 if (narg == 2) {
920 if (strcmp(arg[1],"append") == 0) appendflag = 1;
921 else error->all(FLERR,"Illegal log command");
922 }
923
924 if (me == 0) {
925 if (logfile) fclose(logfile);
926 if (strcmp(arg[0],"none") == 0) logfile = NULL;
927 else {
928 if (appendflag) logfile = fopen(arg[0],"a");
929 else logfile = fopen(arg[0],"w");
930 if (logfile == NULL) {
931 char str[512];
932 sprintf(str,"Cannot open logfile %s",arg[0]);
933 error->one(FLERR,str);
934 }
935 }
936 if (universe->nworlds == 1) universe->ulogfile = logfile;
937 }
938 }
939
940 /* ---------------------------------------------------------------------- */
941
thermo_log()942 void Input::thermo_log()
943 {
944 if (narg > 2) error->all(FLERR,"Illegal thermo_log command");
945
946 int appendflag = 0;
947 if (narg == 2) {
948 if (strcmp(arg[1],"append") == 0) appendflag = 1;
949 else error->all(FLERR,"Illegal thermo_log command");
950 }
951
952 if (me == 0) {
953 if (thermofile) fclose(thermofile);
954 if (strcmp(arg[0],"none") == 0) thermofile = NULL;
955 else {
956 if (appendflag) thermofile = fopen(arg[0],"a");
957 else thermofile = fopen(arg[0],"w");
958 if (thermofile == NULL) {
959 char str[512];
960 sprintf(str,"Cannot open thermo log file %s",arg[0]);
961 error->one(FLERR,str);
962 }
963 }
964 if (universe->nworlds == 1) universe->uthermofile = thermofile;
965 }
966 }
967
968 /* ---------------------------------------------------------------------- */
969
next_command()970 void Input::next_command()
971 {
972 if (variable->next(narg,arg)) jump_skip = 1;
973 }
974
975 /* ---------------------------------------------------------------------- */
976
partition()977 void Input::partition()
978 {
979 if (narg < 3) error->all(FLERR,"Illegal partition command");
980
981 int yesflag = 0;
982 if (strcmp(arg[0],"yes") == 0) yesflag = 1;
983 else if (strcmp(arg[0],"no") == 0) yesflag = 0;
984 else error->all(FLERR,"Illegal partition command");
985
986 int ilo,ihi;
987 force->bounds(arg[1],universe->nworlds,ilo,ihi);
988
989 // copy original line to copy, since will use strtok() on it
990 // ptr = start of 4th word
991
992 strcpy(copy,line);
993 char *ptr = strtok(copy," \t\n\r\f");
994 ptr = strtok(NULL," \t\n\r\f");
995 ptr = strtok(NULL," \t\n\r\f");
996 ptr += strlen(ptr) + 1;
997 ptr += strspn(ptr," \t\n\r\f");
998
999 // execute the remaining command line on requested partitions
1000
1001 if (yesflag) {
1002 if (universe->iworld+1 >= ilo && universe->iworld+1 <= ihi) one(ptr);
1003 } else {
1004 if (universe->iworld+1 < ilo || universe->iworld+1 > ihi) one(ptr);
1005 }
1006 }
1007
1008 /* ---------------------------------------------------------------------- */
1009
print()1010 void Input::print()
1011 {
1012 if (narg < 1)
1013 error->all(FLERR,"Illegal print command");
1014
1015 // copy 1st arg back into line (copy is being used)
1016 // check maxline since arg[0] could have been exanded by variables
1017 // substitute for $ variables (no printing) and print arg
1018
1019 int n = strlen(arg[0]) + 1;
1020 if (n > maxline)
1021 reallocate(line,maxline,n);
1022 strcpy(line,arg[0]);
1023 substitute(line,work,maxline,maxwork,0);
1024
1025 // parse optional args
1026
1027 FILE *fp = NULL;
1028 int screenflag = 1;
1029 bool newline = true;
1030
1031 int iarg = 1;
1032 while (iarg < narg)
1033 {
1034 if (strcmp(arg[iarg],"file") == 0 || strcmp(arg[iarg],"append") == 0)
1035 {
1036 if (iarg+2 > narg)
1037 error->all(FLERR,"Illegal print command");
1038 if (me == 0)
1039 {
1040 if (strcmp(arg[iarg],"file") == 0)
1041 fp = fopen(arg[iarg+1],"w");
1042 else
1043 fp = fopen(arg[iarg+1],"a");
1044 if (fp == NULL)
1045 {
1046 char str[512];
1047 sprintf(str,"Cannot open print file %s",arg[iarg+1]);
1048 error->one(FLERR,str);
1049 }
1050 }
1051 iarg += 2;
1052 }
1053 else if (strcmp(arg[iarg],"screen") == 0)
1054 {
1055 if (iarg+2 > narg)
1056 error->all(FLERR,"Illegal print command");
1057 if (strcmp(arg[iarg+1],"yes") == 0)
1058 screenflag = 1;
1059 else if (strcmp(arg[iarg+1],"no") == 0)
1060 screenflag = 0;
1061 else
1062 error->all(FLERR,"Illegal print command");
1063 iarg += 2;
1064 }
1065 else if (strcmp(arg[iarg], "newline") == 0)
1066 {
1067 if (iarg+2 > narg)
1068 error->all(FLERR,"Illegal print command");
1069 if (strcmp(arg[iarg+1],"yes") == 0)
1070 newline = true;
1071 else if (strcmp(arg[iarg+1],"no") == 0)
1072 newline = false;
1073 else
1074 error->all(FLERR,"Illegal print command");
1075 iarg += 2;
1076 }
1077 else
1078 error->all(FLERR,"Illegal print command");
1079 }
1080
1081 if (me == 0)
1082 {
1083 if (screenflag && screen)
1084 {
1085 if (newline)
1086 fprintf(screen, "%s\n", line);
1087 else
1088 fprintf(screen, "%s", line);
1089 }
1090 if (screenflag && logfile)
1091 {
1092 if (newline)
1093 fprintf(logfile, "%s\n", line);
1094 else
1095 fprintf(logfile, "%s", line);
1096 }
1097 if (fp)
1098 {
1099 if (newline)
1100 fprintf(fp, "%s\n", line);
1101 else
1102 fprintf(fp, "%s", line);
1103 fclose(fp);
1104 }
1105 }
1106 }
1107
1108 /* ---------------------------------------------------------------------- */
1109
quit()1110 void Input::quit()
1111 {
1112 if (narg) error->all(FLERR,"Illegal quit command");
1113 error->done();
1114 }
1115
1116 /* ---------------------------------------------------------------------- */
1117
shell()1118 void Input::shell()
1119 {
1120 if (narg < 1) error->all(FLERR,"Illegal shell command");
1121
1122 if (strcmp(arg[0],"cd") == 0) {
1123 if (narg != 2) error->all(FLERR,"Illegal shell cd command");
1124 chdir(arg[1]);
1125
1126 } else if (strcmp(arg[0],"mkdir") == 0) {
1127 if (narg < 2) error->all(FLERR,"Illegal shell mkdir command");
1128 #if !defined(WINDOWS) && !defined(__MINGW32__)
1129 if (me == 0)
1130 for (int i = 1; i < narg; i++)
1131 mkdir(arg[i], S_IRWXU | S_IRGRP | S_IXGRP);
1132 #endif
1133
1134 } else if (strcmp(arg[0],"mv") == 0) {
1135 if (narg != 3) error->all(FLERR,"Illegal shell mv command");
1136 if (me == 0) rename(arg[1],arg[2]);
1137
1138 } else if (strcmp(arg[0],"rm") == 0) {
1139 if (narg < 2) error->all(FLERR,"Illegal shell rm command");
1140 if (me == 0)
1141 for (int i = 1; i < narg; i++) unlink(arg[i]);
1142
1143 } else if (strcmp(arg[0],"rmdir") == 0) {
1144 if (narg < 2) error->all(FLERR,"Illegal shell rmdir command");
1145 if (me == 0)
1146 for (int i = 1; i < narg; i++) rmdir(arg[i]);
1147 } else if (strcmp(arg[0],"putenv") == 0) {
1148 if (narg < 2) error->all(FLERR,"Illegal shell putenv command");
1149 for (int i = 1; i < narg; i++) {
1150 char *ptr = strdup(arg[i]);
1151 #ifdef _WIN32
1152 if (ptr != NULL) _putenv(ptr);
1153 #else
1154 if (ptr != NULL) putenv(ptr);
1155 #endif
1156 }
1157
1158 // use work string to concat args back into one string separated by spaces
1159 // invoke string in shell via system()
1160
1161 } else {
1162 int n = 0;
1163 for (int i = 0; i < narg; i++) n += strlen(arg[i]) + 1;
1164 if (n > maxwork) reallocate(work,maxwork,n);
1165 strcpy(work,arg[0]);
1166 for (int i = 1; i < narg; i++) {
1167 strcat(work," ");
1168 strcat(work,arg[i]);
1169 }
1170 if (me == 0) system(work);
1171 }
1172 }
1173
1174 /* ---------------------------------------------------------------------- */
1175
variable_command()1176 void Input::variable_command()
1177 {
1178 variable->set(narg,arg);
1179 }
1180
1181 /* ---------------------------------------------------------------------- */
1182 /* ---------------------------------------------------------------------- */
1183 /* ---------------------------------------------------------------------- */
1184
1185 /* ----------------------------------------------------------------------
1186 one function for each LAMMPS-specific input script command
1187 ------------------------------------------------------------------------- */
1188
1189 /* ---------------------------------------------------------------------- */
1190
angle_coeff()1191 void Input::angle_coeff()
1192 {
1193 if (domain->box_exist == 0)
1194 error->all(FLERR,"Angle_coeff command before simulation box is defined");
1195 if (force->angle == NULL)
1196 error->all(FLERR,"Angle_coeff command before angle_style is defined");
1197 if (atom->avec->angles_allow == 0)
1198 error->all(FLERR,"Angle_coeff command when no angles allowed");
1199 force->angle->coeff(narg,arg);
1200 }
1201
1202 /* ---------------------------------------------------------------------- */
1203
angle_style()1204 void Input::angle_style()
1205 {
1206 if (narg < 1) error->all(FLERR,"Illegal angle_style command");
1207 if (atom->avec->angles_allow == 0)
1208 error->all(FLERR,"Angle_style command when no angles allowed");
1209 force->create_angle(arg[0],lmp->suffix);
1210 if (force->angle) force->angle->settings(narg-1,&arg[1]);
1211 }
1212
1213 /* ---------------------------------------------------------------------- */
1214
atom_modify()1215 void Input::atom_modify()
1216 {
1217 atom->modify_params(narg,arg);
1218 }
1219
1220 /* ---------------------------------------------------------------------- */
1221
atom_style()1222 void Input::atom_style()
1223 {
1224 if (narg < 1) error->all(FLERR,"Illegal atom_style command");
1225 if (domain->box_exist)
1226 error->all(FLERR,"Atom_style command after simulation box is defined");
1227 atom->create_avec(arg[0],narg-1,&arg[1],lmp->suffix);
1228 }
1229
1230 /* ---------------------------------------------------------------------- */
1231
bond_coeff()1232 void Input::bond_coeff()
1233 {
1234 if (domain->box_exist == 0)
1235 error->all(FLERR,"Bond_coeff command before simulation box is defined");
1236 if (force->bond == NULL)
1237 error->all(FLERR,"Bond_coeff command before bond_style is defined");
1238 if (atom->avec->bonds_allow == 0)
1239 error->all(FLERR,"Bond_coeff command when no bonds allowed");
1240 force->bond->coeff(narg,arg);
1241 }
1242
1243 /* ---------------------------------------------------------------------- */
1244
bond_style()1245 void Input::bond_style()
1246 {
1247 if (narg < 1) error->all(FLERR,"Illegal bond_style command");
1248 if (atom->avec->bonds_allow == 0)
1249 error->all(FLERR,"Bond_style command when no bonds allowed");
1250 force->create_bond(arg[0],lmp->suffix);
1251 if (force->bond) force->bond->settings(narg-1,&arg[1]);
1252 }
1253
1254 /* ---------------------------------------------------------------------- */
1255
boundary()1256 void Input::boundary()
1257 {
1258 if (domain->box_exist)
1259 error->all(FLERR,"Boundary command after simulation box is defined");
1260 domain->set_boundary(narg,arg,0);
1261 }
1262
1263 /* ---------------------------------------------------------------------- */
1264
box()1265 void Input::box()
1266 {
1267 if (domain->box_exist)
1268 error->all(FLERR,"Box command after simulation box is defined");
1269 domain->set_box(narg,arg);
1270 }
1271
1272 /* ---------------------------------------------------------------------- */
communicate()1273 void Input::communicate()
1274 {
1275 comm->set(narg,arg);
1276 }
1277
1278 /* ---------------------------------------------------------------------- */
1279
compute()1280 void Input::compute()
1281 {
1282 modify->add_compute(narg,arg,lmp->suffix);
1283 }
1284
1285 /* ---------------------------------------------------------------------- */
1286
compute_modify()1287 void Input::compute_modify()
1288 {
1289 modify->modify_compute(narg,arg);
1290 }
1291
1292 /* ---------------------------------------------------------------------- */
1293
dielectric()1294 void Input::dielectric()
1295 {
1296 if (narg != 1) error->all(FLERR,"Illegal dielectric command");
1297 force->dielectric = force->numeric(FLERR,arg[0]);
1298 }
1299
1300 /* ---------------------------------------------------------------------- */
1301
dihedral_coeff()1302 void Input::dihedral_coeff()
1303 {
1304 if (domain->box_exist == 0)
1305 error->all(FLERR,"Dihedral_coeff command before simulation box is defined");
1306 if (force->dihedral == NULL)
1307 error->all(FLERR,"Dihedral_coeff command before dihedral_style is defined");
1308 if (atom->avec->dihedrals_allow == 0)
1309 error->all(FLERR,"Dihedral_coeff command when no dihedrals allowed");
1310 force->dihedral->coeff(narg,arg);
1311 }
1312
1313 /* ---------------------------------------------------------------------- */
1314
dihedral_style()1315 void Input::dihedral_style()
1316 {
1317 if (narg < 1) error->all(FLERR,"Illegal dihedral_style command");
1318 if (atom->avec->dihedrals_allow == 0)
1319 error->all(FLERR,"Dihedral_style command when no dihedrals allowed");
1320 force->create_dihedral(arg[0],lmp->suffix);
1321 if (force->dihedral) force->dihedral->settings(narg-1,&arg[1]);
1322 }
1323
1324 /* ---------------------------------------------------------------------- */
1325
dimension()1326 void Input::dimension()
1327 {
1328 if (narg != 1) error->all(FLERR,"Illegal dimension command");
1329 if (domain->box_exist)
1330 error->all(FLERR,"Dimension command after simulation box is defined");
1331 domain->dimension = force->inumeric(FLERR,arg[0]);
1332 if (domain->dimension != 2 && domain->dimension != 3)
1333 error->all(FLERR,"Illegal dimension command");
1334
1335 // must reset default extra_dof of all computes
1336 // since some were created before dimension command is encountered
1337
1338 for (int i = 0; i < modify->ncompute; i++)
1339 modify->compute[i]->reset_extra_dof();
1340 }
1341
1342 /* ---------------------------------------------------------------------- */
1343
dump()1344 void Input::dump()
1345 {
1346 output->add_dump(narg,arg);
1347 }
1348
1349 /* ---------------------------------------------------------------------- */
1350
dump_modify()1351 void Input::dump_modify()
1352 {
1353 output->modify_dump(narg,arg);
1354 }
1355
1356 /* ---------------------------------------------------------------------- */
1357
fix()1358 void Input::fix()
1359 {
1360 modify->add_fix(narg,arg,lmp->suffix);
1361 }
1362
1363 /* ---------------------------------------------------------------------- */
1364
fix_modify()1365 void Input::fix_modify()
1366 {
1367 modify->modify_fix(narg,arg);
1368 }
1369
1370 /* ---------------------------------------------------------------------- */
1371
force_dt_reset()1372 void Input::force_dt_reset()
1373 {
1374 if(narg != 1)
1375 error->all(FLERR,"force_dt_reset expects 'yes' or 'no'");
1376 if(0 == strcmp(arg[0],"yes"))
1377 update->set_force_dt_reset(true);
1378 else if(0 == strcmp(arg[0],"no"))
1379 update->set_force_dt_reset(false);
1380 else
1381 error->all(FLERR,"force_dt_reset expects 'yes' or 'no'");
1382 }
1383
1384 /* ---------------------------------------------------------------------- */
1385
group_command()1386 void Input::group_command()
1387 {
1388 group->assign(narg,arg);
1389 }
1390
1391 /* ---------------------------------------------------------------------- */
1392
improper_coeff()1393 void Input::improper_coeff()
1394 {
1395 if (domain->box_exist == 0)
1396 error->all(FLERR,"Improper_coeff command before simulation box is defined");
1397 if (force->improper == NULL)
1398 error->all(FLERR,"Improper_coeff command before improper_style is defined");
1399 if (atom->avec->impropers_allow == 0)
1400 error->all(FLERR,"Improper_coeff command when no impropers allowed");
1401 force->improper->coeff(narg,arg);
1402 }
1403
1404 /* ---------------------------------------------------------------------- */
1405
improper_style()1406 void Input::improper_style()
1407 {
1408 if (narg < 1) error->all(FLERR,"Illegal improper_style command");
1409 if (atom->avec->impropers_allow == 0)
1410 error->all(FLERR,"Improper_style command when no impropers allowed");
1411 force->create_improper(arg[0],lmp->suffix);
1412 if (force->improper) force->improper->settings(narg-1,&arg[1]);
1413 }
1414
1415 /* ---------------------------------------------------------------------- */
1416
kspace_modify()1417 void Input::kspace_modify()
1418 {
1419 if (force->kspace == NULL)
1420 error->all(FLERR,"KSpace style has not yet been set");
1421 force->kspace->modify_params(narg,arg);
1422 }
1423
1424 /* ---------------------------------------------------------------------- */
1425
kspace_style()1426 void Input::kspace_style()
1427 {
1428 force->create_kspace(narg,arg,lmp->suffix);
1429 }
1430
1431 /* ---------------------------------------------------------------------- */
1432
lattice()1433 void Input::lattice()
1434 {
1435 domain->set_lattice(narg,arg);
1436 }
1437
1438 /* ---------------------------------------------------------------------- */
1439
mass()1440 void Input::mass()
1441 {
1442 if (narg != 2) error->all(FLERR,"Illegal mass command");
1443 if (domain->box_exist == 0)
1444 error->all(FLERR,"Mass command before simulation box is defined");
1445 atom->set_mass(narg,arg);
1446 }
1447
1448 /* ---------------------------------------------------------------------- */
1449
min_modify()1450 void Input::min_modify()
1451 {
1452 update->minimize->modify_params(narg,arg);
1453 }
1454
1455 /* ---------------------------------------------------------------------- */
1456
min_style()1457 void Input::min_style()
1458 {
1459 if (domain->box_exist == 0)
1460 error->all(FLERR,"Min_style command before simulation box is defined");
1461 update->create_minimize(narg,arg);
1462 }
1463
1464 /* ---------------------------------------------------------------------- */
1465
neighbor_command()1466 void Input::neighbor_command()
1467 {
1468 neighbor->set(narg, arg);
1469 }
1470
1471 /* ---------------------------------------------------------------------- */
1472
newton()1473 void Input::newton()
1474 {
1475 int newton_pair=1,newton_bond=1;
1476
1477 if (narg == 1) {
1478 if (strcmp(arg[0],"off") == 0) newton_pair = newton_bond = 0;
1479 else if (strcmp(arg[0],"on") == 0) newton_pair = newton_bond = 1;
1480 else error->all(FLERR,"Illegal newton command");
1481 } else if (narg == 2) {
1482 if (strcmp(arg[0],"off") == 0) newton_pair = 0;
1483 else if (strcmp(arg[0],"on") == 0) newton_pair= 1;
1484 else error->all(FLERR,"Illegal newton command");
1485 if (strcmp(arg[1],"off") == 0) newton_bond = 0;
1486 else if (strcmp(arg[1],"on") == 0) newton_bond = 1;
1487 else error->all(FLERR,"Illegal newton command");
1488 } else error->all(FLERR,"Illegal newton command");
1489
1490 force->newton_pair = newton_pair;
1491
1492 if (newton_bond == 0) {
1493 if (domain->box_exist && force->newton_bond == 1)
1494 error->all(FLERR,"Newton bond change after simulation box is defined");
1495 force->newton_bond = 0;
1496 } else {
1497 if (domain->box_exist && force->newton_bond == 0)
1498 error->all(FLERR,"Newton bond change after simulation box is defined");
1499 force->newton_bond = 1;
1500 }
1501
1502 if (newton_pair || newton_bond) force->newton = 1;
1503 else force->newton = 0;
1504 }
1505
1506 /* ---------------------------------------------------------------------- */
1507
modify_timing()1508 void Input::modify_timing()
1509 {
1510 int timing = 0;
1511
1512 if (narg == 1) {
1513 if (strcmp(arg[0],"off") == 0) timing = 0;
1514 else if (strcmp(arg[0],"on") == 0) timing = 1;
1515 else if (strcmp(arg[0],"verbose") == 0) timing = 2;
1516 else error->all(FLERR,"Illegal modify_timing command");
1517 } else error->all(FLERR,"Illegal modify_timing command");
1518
1519 modify->timing = timing;
1520 }
1521
1522 /* ---------------------------------------------------------------------- */
1523
package()1524 void Input::package()
1525 {
1526 if (domain->box_exist)
1527 error->all(FLERR,"Package command after simulation box is defined");
1528 if (narg < 1) error->all(FLERR,"Illegal package command");
1529
1530 if (strcmp(arg[0],"cuda") == 0) {
1531 if (!lmp->cuda)
1532 error->all(FLERR,"Package cuda command without USER-CUDA installed");
1533 lmp->cuda->accelerator(narg-1,&arg[1]);
1534
1535 } else if (strcmp(arg[0],"gpu") == 0) {
1536 char **fixarg = new char*[2+narg];
1537 fixarg[0] = (char *) "package_gpu";
1538 fixarg[1] = (char *) "all";
1539 fixarg[2] = (char *) "GPU";
1540 for (int i = 1; i < narg; i++) fixarg[i+2] = arg[i];
1541 modify->add_fix(2+narg,fixarg,NULL);
1542 delete [] fixarg;
1543 force->newton_pair = 0;
1544
1545 } else if (strcmp(arg[0],"omp") == 0) {
1546 char **fixarg = new char*[2+narg];
1547 fixarg[0] = (char *) "package_omp";
1548 fixarg[1] = (char *) "all";
1549 fixarg[2] = (char *) "OMP";
1550 for (int i = 1; i < narg; i++) fixarg[i+2] = arg[i];
1551 modify->add_fix(2+narg,fixarg,NULL);
1552 delete [] fixarg;
1553
1554 } else error->all(FLERR,"Illegal package command");
1555 }
1556
1557 /* ---------------------------------------------------------------------- */
1558
pair_coeff()1559 void Input::pair_coeff()
1560 {
1561 if (domain->box_exist == 0)
1562 error->all(FLERR,"Pair_coeff command before simulation box is defined");
1563 if (force->pair == NULL)
1564 error->all(FLERR,"Pair_coeff command before pair_style is defined");
1565 force->pair->coeff(narg,arg);
1566 }
1567
1568 /* ---------------------------------------------------------------------- */
1569
pair_modify()1570 void Input::pair_modify()
1571 {
1572 if (force->pair == NULL)
1573 error->all(FLERR,"Pair_modify command before pair_style is defined");
1574 force->pair->modify_params(narg,arg);
1575 }
1576
1577 /* ----------------------------------------------------------------------
1578 if old pair style exists and new style is same, just change settings
1579 else create new pair class
1580 ------------------------------------------------------------------------- */
1581
pair_style()1582 void Input::pair_style()
1583 {
1584 if (narg < 1) error->all(FLERR,"Illegal pair_style command");
1585
1586 /*
1587 if (!modify->fix_restart_in_progress() && force->pair && strcmp(arg[0],force->pair_style) == 0) {
1588 force->pair->settings(narg-1,&arg[1]);
1589 return;
1590 }*/
1591 int num_remaining_arg = narg - 1;
1592 char ** remaining_args = &arg[1];
1593 force->create_pair(arg[0],lmp->suffix);
1594 if (force->pair) force->pair->settings(num_remaining_arg,remaining_args);
1595 }
1596
1597 /* ---------------------------------------------------------------------- */
1598
pair_write()1599 void Input::pair_write()
1600 {
1601 if (force->pair == NULL)
1602 error->all(FLERR,"Pair_write command before pair_style is defined");
1603 force->pair->write_file(narg,arg);
1604 }
1605
1606 /* ---------------------------------------------------------------------- */
1607
processors()1608 void Input::processors()
1609 {
1610 if (domain->box_exist)
1611 error->all(FLERR,"Processors command after simulation box is defined");
1612 comm->set_processors(narg,arg);
1613 }
1614
1615 /* ---------------------------------------------------------------------- */
1616
region()1617 void Input::region()
1618 {
1619 domain->add_region(narg,arg);
1620 }
1621
1622 /* ---------------------------------------------------------------------- */
1623
reset_timestep()1624 void Input::reset_timestep()
1625 {
1626 update->reset_timestep(narg,arg);
1627 }
1628
1629 /* ---------------------------------------------------------------------- */
1630
restart()1631 void Input::restart()
1632 {
1633 output->create_restart(narg,arg);
1634 }
1635
1636 /* ---------------------------------------------------------------------- */
1637
run_style()1638 void Input::run_style()
1639 {
1640 if (domain->box_exist == 0)
1641 error->all(FLERR,"Run_style command before simulation box is defined");
1642 update->create_integrate(narg,arg,lmp->suffix);
1643 }
1644
1645 /* ---------------------------------------------------------------------- */
write_restart_on_signal()1646 void Input::write_restart_on_signal()
1647 {
1648 if(narg != 1)
1649 error->all(FLERR,"write_restart_on_signal expects 'yes' or 'no'");
1650 if(0 == strcmp(arg[0],"yes"))
1651 SignalHandler::enable_restart_writing = true;
1652 else if(0 == strcmp(arg[0],"no"))
1653 SignalHandler::enable_restart_writing = false;
1654 else
1655 error->all(FLERR,"write_restart_on_signal expects 'yes' or 'no'");
1656 }
1657
1658 /* ---------------------------------------------------------------------- */
hard_particles()1659 void Input::hard_particles()
1660 {
1661 if(narg != 1)
1662 error->all(FLERR,"hard_particles expects 'yes' or 'no'");
1663 if(0 == strcmp(arg[0],"yes"))
1664 atom->get_properties()->do_allow_hard_particles();
1665 else if(0 == strcmp(arg[0],"no"))
1666 atom->get_properties()->do_not_allow_hard_particles();
1667 else
1668 error->all(FLERR,"hard_particles expects 'yes' or 'no'");
1669 }
1670
1671 /* ---------------------------------------------------------------------- */
1672
soft_particles()1673 void Input::soft_particles()
1674 {
1675 if(narg != 1)
1676 error->all(FLERR,"soft_particles expects 'yes' or 'no'");
1677 if(0 == strcmp(arg[0],"yes"))
1678 atom->get_properties()->do_allow_soft_particles();
1679 else if(0 == strcmp(arg[0],"no"))
1680 atom->get_properties()->do_not_allow_soft_particles();
1681 else
1682 error->all(FLERR,"soft_particles expects 'yes' or 'no'");
1683 }
1684
1685 /* ---------------------------------------------------------------------- */
1686
special_bonds()1687 void Input::special_bonds()
1688 {
1689 // store 1-3,1-4 and dihedral/extra flag values before change
1690 // change in 1-2 coeffs will not change the special list
1691
1692 double lj2 = force->special_lj[2];
1693 double lj3 = force->special_lj[3];
1694 double coul2 = force->special_coul[2];
1695 double coul3 = force->special_coul[3];
1696 int angle = force->special_angle;
1697 int dihedral = force->special_dihedral;
1698 int extra = force->special_extra;
1699
1700 force->set_special(narg,arg);
1701
1702 // if simulation box defined and saved values changed, redo special list
1703
1704 if (domain->box_exist && atom->molecular) {
1705 if (lj2 != force->special_lj[2] || lj3 != force->special_lj[3] ||
1706 coul2 != force->special_coul[2] || coul3 != force->special_coul[3] ||
1707 angle != force->special_angle ||
1708 dihedral != force->special_dihedral ||
1709 extra != force->special_extra) {
1710 Special special(lmp);
1711 special.build();
1712 }
1713 }
1714 }
1715
1716 /* ---------------------------------------------------------------------- */
1717
suffix()1718 void Input::suffix()
1719 {
1720 if (narg != 1) error->all(FLERR,"Illegal suffix command");
1721
1722 if (strcmp(arg[0],"off") == 0) lmp->suffix_enable = 0;
1723 else if (strcmp(arg[0],"on") == 0) lmp->suffix_enable = 1;
1724 else {
1725 delete [] lmp->suffix;
1726 int n = strlen(arg[0]) + 1;
1727 lmp->suffix = new char[n];
1728 strcpy(lmp->suffix,arg[0]);
1729 lmp->suffix_enable = 1;
1730 }
1731 }
1732
1733 /* ---------------------------------------------------------------------- */
1734
thermo()1735 void Input::thermo()
1736 {
1737 output->set_thermo(narg,arg);
1738 }
1739
1740 /* ---------------------------------------------------------------------- */
1741
thermo_modify()1742 void Input::thermo_modify()
1743 {
1744 output->thermo->modify_params(narg,arg);
1745 }
1746
1747 /* ---------------------------------------------------------------------- */
1748
thermo_style()1749 void Input::thermo_style()
1750 {
1751 output->create_thermo(narg,arg);
1752 }
1753
1754 /* ---------------------------------------------------------------------- */
1755
timestep()1756 void Input::timestep()
1757 {
1758 if (narg != 1) error->all(FLERR,"Illegal timestep command");
1759 update->dt = force->numeric(FLERR,arg[0]);
1760 update->timestep_set = true;
1761
1762 }
1763
1764 /* ---------------------------------------------------------------------- */
1765
uncompute()1766 void Input::uncompute()
1767 {
1768 if (narg != 1) error->all(FLERR,"Illegal uncompute command");
1769 modify->delete_compute(arg[0],true);
1770 }
1771
1772 /* ---------------------------------------------------------------------- */
1773
undump()1774 void Input::undump()
1775 {
1776 if (narg != 1) error->all(FLERR,"Illegal undump command");
1777 output->delete_dump(arg[0]);
1778 }
1779
1780 /* ---------------------------------------------------------------------- */
1781
unfix()1782 void Input::unfix()
1783 {
1784 if (narg != 1) error->all(FLERR,"Illegal unfix command");
1785 modify->delete_fix(arg[0],true);
1786 }
1787
1788 /* ---------------------------------------------------------------------- */
1789
units()1790 void Input::units()
1791 {
1792 if (narg != 1) error->all(FLERR,"Illegal units command");
1793 if (domain->box_exist)
1794 error->all(FLERR,"Units command after simulation box is defined");
1795 update->set_units(arg[0]);
1796 }
1797
1798 /* ----------------------------------------------------------------------
1799 parse line of non-LAMMPS origin
1800 ------------------------------------------------------------------------- */
1801
parse_nonlammps()1802 void Input::parse_nonlammps()
1803 {
1804 // duplicate line into copy string to break into words
1805
1806 int n = strlen(line) + 1;
1807 if (n > maxcopy) reallocate(copy,maxcopy,n);
1808 strcpy(copy,line);
1809
1810 // strip any # comment by replacing it with 0
1811 // do not strip # inside single/double quotes
1812
1813 char quote = '\0';
1814 char *ptr = copy;
1815 while (*ptr) {
1816 if (*ptr == '#' && !quote) {
1817 *ptr = '\0';
1818 break;
1819 }
1820 if (*ptr == quote) quote = '\0';
1821 else if (*ptr == '"' || *ptr == '\'') quote = *ptr;
1822 ptr++;
1823 }
1824
1825 // point arg[] at each subsequent arg in copy string
1826 // nextword() inserts string terminators into copy string to delimit args
1827 // nextword() treats text between single/double quotes as one arg
1828
1829 narg = 0;
1830 ptr = copy;
1831 char *next;
1832
1833 while (ptr) {
1834 if (narg == maxarg) {
1835 maxarg += DELTA;
1836 arg = (char **) memory->srealloc(arg,maxarg*sizeof(char *),"input:arg");
1837 }
1838 arg[narg] = nextword(ptr,&next);
1839 if (!arg[narg]) break;
1840 narg++;
1841 ptr = next;
1842 }
1843 }
1844
1845