Merge branch 'develop' into type-labels
This commit is contained in:
118
src/input.cpp
118
src/input.cpp
@ -27,9 +27,11 @@
|
||||
#include "dihedral.h"
|
||||
#include "domain.h"
|
||||
#include "error.h"
|
||||
#include "fix.h"
|
||||
#include "force.h"
|
||||
#include "group.h"
|
||||
#include "improper.h"
|
||||
#include "integrate.h"
|
||||
#include "kspace.h"
|
||||
#include "label_map.h"
|
||||
#include "memory.h"
|
||||
@ -49,13 +51,21 @@
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
#include <cctype>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
#define DELTALINE 256
|
||||
#define DELTA 4
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per command in style_command.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T> static Command *command_creator(LAMMPS *lmp)
|
||||
{
|
||||
return new T(lmp);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/** \class LAMMPS_NS::Input
|
||||
@ -819,9 +829,21 @@ int Input::execute_command()
|
||||
if (flag) return 0;
|
||||
|
||||
// invoke commands added via style_command.h
|
||||
// try suffixed version first
|
||||
|
||||
if (command_map->find(command) != command_map->end()) {
|
||||
CommandCreator &command_creator = (*command_map)[command];
|
||||
std::string mycmd = command;
|
||||
if (lmp->suffix_enable) {
|
||||
mycmd = command + std::string("/") + lmp->suffix;
|
||||
if (command_map->find(mycmd) == command_map->end()) {
|
||||
if (lmp->suffix2) {
|
||||
mycmd = command + std::string("/") + lmp->suffix2;
|
||||
if (command_map->find(mycmd) == command_map->end())
|
||||
mycmd = command;
|
||||
} else mycmd = command;
|
||||
}
|
||||
}
|
||||
if (command_map->find(mycmd) != command_map->end()) {
|
||||
CommandCreator &command_creator = (*command_map)[mycmd];
|
||||
Command *cmd = command_creator(lmp);
|
||||
cmd->command(narg,arg);
|
||||
delete cmd;
|
||||
@ -833,16 +855,6 @@ int Input::execute_command()
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
one instance per command in style_command.h
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename T>
|
||||
Command *Input::command_creator(LAMMPS *lmp)
|
||||
{
|
||||
return new T(lmp);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -1001,10 +1013,15 @@ void Input::include()
|
||||
if (nfile == maxfile)
|
||||
error->one(FLERR,"Too many nested levels of input scripts");
|
||||
|
||||
infile = fopen(arg[0],"r");
|
||||
// expand variables
|
||||
int n = strlen(arg[0]) + 1;
|
||||
if (n > maxline) reallocate(line,maxline,n);
|
||||
strcpy(line,arg[0]);
|
||||
substitute(line,work,maxline,maxwork,0);
|
||||
|
||||
infile = fopen(line,"r");
|
||||
if (infile == nullptr)
|
||||
error->one(FLERR,"Cannot open input script {}: {}",
|
||||
arg[0], utils::getsyserror());
|
||||
error->one(FLERR,"Cannot open input script {}: {}", line, utils::getsyserror());
|
||||
|
||||
infiles[nfile++] = infile;
|
||||
}
|
||||
@ -1214,7 +1231,10 @@ void Input::shell()
|
||||
if (narg < 2) error->all(FLERR,"Illegal shell mkdir command");
|
||||
if (me == 0) {
|
||||
for (int i = 1; i < narg; i++) {
|
||||
if (platform::mkdir(arg[i]) < 0)
|
||||
rv = (platform::mkdir(arg[i]) < 0) ? errno : 0;
|
||||
MPI_Reduce(&rv,&err,1,MPI_INT,MPI_MAX,0,world);
|
||||
errno = err;
|
||||
if (err != 0)
|
||||
error->warning(FLERR, "Shell command 'mkdir {}' failed with error '{}'",
|
||||
arg[i],utils::getsyserror());
|
||||
}
|
||||
@ -1222,18 +1242,30 @@ void Input::shell()
|
||||
} else if (strcmp(arg[0],"mv") == 0) {
|
||||
if (narg != 3) error->all(FLERR,"Illegal shell mv command");
|
||||
if (me == 0) {
|
||||
if (rename(arg[1],arg[2]) < 0) {
|
||||
error->warning(FLERR, "Shell command 'mv {} {}' failed with error '{}'",
|
||||
arg[1],arg[2],utils::getsyserror());
|
||||
if (platform::path_is_directory(arg[2])) {
|
||||
if (system(fmt::format("mv {} {}", arg[1], arg[2]).c_str()))
|
||||
error->warning(FLERR,"Shell command 'mv {} {}' returned with non-zero status", arg[1], arg[2]);
|
||||
} else {
|
||||
if (rename(arg[1],arg[2]) < 0) {
|
||||
error->warning(FLERR, "Shell command 'mv {} {}' failed with error '{}'",
|
||||
arg[1],arg[2],utils::getsyserror());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (strcmp(arg[0],"rm") == 0) {
|
||||
if (narg < 2) error->all(FLERR,"Illegal shell rm command");
|
||||
if (me == 0) {
|
||||
for (int i = 1; i < narg; i++) {
|
||||
int i = 1;
|
||||
bool warn = true;
|
||||
if (strcmp(arg[i], "-f") == 0) {
|
||||
warn = false;
|
||||
++i;
|
||||
}
|
||||
for (;i < narg; i++) {
|
||||
if (platform::unlink(arg[i]) < 0)
|
||||
error->warning(FLERR, "Shell command 'rm {}' failed with error '{}'",
|
||||
arg[i], utils::getsyserror());
|
||||
if (warn)
|
||||
error->warning(FLERR, "Shell command 'rm {}' failed with error '{}'",
|
||||
arg[i], utils::getsyserror());
|
||||
}
|
||||
}
|
||||
} else if (strcmp(arg[0],"rmdir") == 0) {
|
||||
@ -1257,23 +1289,20 @@ void Input::shell()
|
||||
error->warning(FLERR, "Shell command 'putenv {}' failed with error '{}'",
|
||||
arg[i], utils::getsyserror());
|
||||
}
|
||||
// use work string to concat args back into one string separated by spaces
|
||||
// invoke string in shell via system()
|
||||
|
||||
// concat arguments and invoke string in shell via system()
|
||||
|
||||
} else {
|
||||
int n = 0;
|
||||
for (int i = 0; i < narg; i++) n += strlen(arg[i]) + 1;
|
||||
if (n > maxwork) reallocate(work,maxwork,n);
|
||||
if (me == 0) {
|
||||
std::string cmd = arg[0];
|
||||
for (int i = 1; i < narg; i++) {
|
||||
cmd += " ";
|
||||
cmd += arg[i];
|
||||
}
|
||||
|
||||
strcpy(work,arg[0]);
|
||||
for (int i = 1; i < narg; i++) {
|
||||
strcat(work," ");
|
||||
strcat(work,arg[i]);
|
||||
if (system(cmd.c_str()) != 0)
|
||||
error->warning(FLERR,"Shell command {} returned with non-zero status", cmd);
|
||||
}
|
||||
|
||||
if (me == 0)
|
||||
if (system(work) != 0)
|
||||
error->warning(FLERR,"Shell command returned with non-zero status");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1929,8 +1958,25 @@ void Input::timer_command()
|
||||
void Input::timestep()
|
||||
{
|
||||
if (narg != 1) error->all(FLERR,"Illegal timestep command");
|
||||
|
||||
update->update_time();
|
||||
update->dt = utils::numeric(FLERR,arg[0],false,lmp);
|
||||
update->dt_default = 0;
|
||||
|
||||
// timestep command can be invoked between runs or by run every
|
||||
// calls to other classes that need to know timestep size changed
|
||||
// similar logic is in FixDtReset::end_of_step()
|
||||
// only need to do this if a run has already occurred
|
||||
|
||||
if (update->first_update == 0) return;
|
||||
|
||||
int respaflag = 0;
|
||||
if (utils::strmatch(update->integrate_style, "^respa")) respaflag = 1;
|
||||
if (respaflag) update->integrate->reset_dt();
|
||||
|
||||
if (force->pair) force->pair->reset_dt();
|
||||
for (auto &ifix : modify->get_fix_list()) ifix->reset_dt();
|
||||
output->reset_dt();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user