git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8088 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2012-05-18 16:35:19 +00:00
parent 173c6e393d
commit e8308edb15
7 changed files with 196 additions and 68 deletions

View File

@ -314,9 +314,14 @@ void PRD::command(int narg, char **arg)
log_event(); log_event();
int restart_flag = 0; int restart_flag = 0;
if (output->restart_every && universe->iworld == 0) if (output->restart_flag && universe->iworld == 0) {
if (fix_event->event_number % output->restart_every == 0) if (output->restart_every_single &&
fix_event->event_number % output->restart_every_single == 0)
restart_flag = 1; restart_flag = 1;
if (output->restart_every_double &&
fix_event->event_number % output->restart_every_double == 0)
restart_flag = 1;
}
// correlated event loop // correlated event loop
// other procs could be dephasing during this time // other procs could be dephasing during this time

View File

@ -335,9 +335,14 @@ void TAD::command(int narg, char **arg)
MPI_Bcast(&(update->ntimestep),1,MPI_INT,0,universe->uworld); MPI_Bcast(&(update->ntimestep),1,MPI_INT,0,universe->uworld);
int restart_flag = 0; int restart_flag = 0;
if (output->restart_every && universe->iworld == 0) if (output->restart_flag && universe->iworld == 0) {
if (fix_event->event_number % output->restart_every == 0) if (output->restart_every_single &&
fix_event->event_number % output->restart_every_single == 0)
restart_flag = 1; restart_flag = 1;
if (output->restart_every_double &&
fix_event->event_number % output->restart_every_double == 0)
restart_flag = 1;
}
// full init/setup since are starting after event // full init/setup since are starting after event

View File

@ -56,7 +56,8 @@ int FixExternal::setmask()
void FixExternal::init() void FixExternal::init()
{ {
if (callback == NULL) error->all(FLERR,"Fix external callback function not set"); if (callback == NULL)
error->all(FLERR,"Fix external callback function not set");
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -389,7 +389,13 @@ void Min::run(int n)
for (int idump = 0; idump < output->ndump; idump++) for (int idump = 0; idump < output->ndump; idump++)
output->next_dump[idump] = update->ntimestep; output->next_dump[idump] = update->ntimestep;
output->next_dump_any = update->ntimestep; output->next_dump_any = update->ntimestep;
if (output->restart_every) output->next_restart = update->ntimestep; if (output->restart_flag) {
output->next_restart = update->ntimestep;
if (output->restart_every_single)
output->next_restart_single = update->ntimestep;
if (output->restart_every_double)
output->next_restart_double = update->ntimestep;
}
} }
output->next_thermo = update->ntimestep; output->next_thermo = update->ntimestep;

View File

@ -262,7 +262,7 @@ void Neighbor::init()
// don't check if build_once is set // don't check if build_once is set
restart_check = 0; restart_check = 0;
if (output->restart_every) restart_check = 1; if (output->restart_flag) restart_check = 1;
delete [] fixchecklist; delete [] fixchecklist;
fixchecklist = NULL; fixchecklist = NULL;

View File

@ -84,10 +84,11 @@ Output::Output(LAMMPS *lmp) : Pointers(lmp)
ivar_dump = NULL; ivar_dump = NULL;
dump = NULL; dump = NULL;
restart = NULL; restart_flag = restart_flag_single = restart_flag_double = 0;
restart1 = restart2 = NULL;
restart_every = 0;
last_restart = -1; last_restart = -1;
restart1 = restart2a = restart2b = NULL;
var_restart_single = var_restart_double = NULL;
restart = NULL;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -108,9 +109,12 @@ Output::~Output()
for (int i = 0; i < ndump; i++) delete dump[i]; for (int i = 0; i < ndump; i++) delete dump[i];
memory->sfree(dump); memory->sfree(dump);
delete restart;
delete [] restart1; delete [] restart1;
delete [] restart2; delete [] restart2a;
delete [] restart2b;
delete [] var_restart_single;
delete [] var_restart_double;
delete restart;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -136,6 +140,21 @@ void Output::init()
if (!input->variable->equalstyle(ivar_dump[i])) if (!input->variable->equalstyle(ivar_dump[i]))
error->all(FLERR,"Variable for dump every is invalid style"); error->all(FLERR,"Variable for dump every is invalid style");
} }
if (restart_flag_single && restart_every_single == 0) {
ivar_restart_single = input->variable->find(var_restart_single);
if (ivar_restart_single < 0)
error->all(FLERR,"Variable name for restart does not exist");
if (!input->variable->equalstyle(ivar_restart_single))
error->all(FLERR,"Variable for restart is invalid style");
}
if (restart_flag_double && restart_every_double == 0) {
ivar_restart_double = input->variable->find(var_restart_double);
if (ivar_restart_double < 0)
error->all(FLERR,"Variable name for restart does not exist");
if (!input->variable->equalstyle(ivar_restart_double))
error->all(FLERR,"Variable for restart is invalid style");
}
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -151,7 +170,7 @@ void Output::setup(int flag)
// perform dump at start of run if current timestep is multiple of every // perform dump at start of run if current timestep is multiple of every
// and last dump was not on this timestep // and last dump was not on this timestep
// set next_dump to multiple of every // set next_dump to multiple of every
// will not write on last step of run unless multiple of every // do not write on last step of run unless multiple of every
// set next_dump_any to smallest next_dump // set next_dump_any to smallest next_dump
// if no dumps, set next_dump_any to last+1 so will not influence next // if no dumps, set next_dump_any to last+1 so will not influence next
// wrap dumps that invoke computes with clear/add // wrap dumps that invoke computes with clear/add
@ -189,14 +208,40 @@ void Output::setup(int flag)
} }
} else next_dump_any = update->laststep + 1; } else next_dump_any = update->laststep + 1;
// do not write a restart file at start of run // do not write restart files at start of run
// set next_restart to multiple of every // set next_restart values to multiple of every or variable value
// will not write on last step of run unless multiple of every // do not write on last step of run unless multiple of every
// if every = 0, set next_restart to last+1 so will not influence next // if every = 0, set next_restart to last+1 so will not influence next
if (restart_every && update->restrict_output == 0) if (restart_flag && update->restrict_output == 0) {
next_restart = (ntimestep/restart_every)*restart_every + restart_every; if (restart_flag_single) {
else next_restart = update->laststep + 1; if (restart_every_single)
next_restart_single =
(ntimestep/restart_every_single)*restart_every_single +
restart_every_single;
else {
bigint nextrestart = static_cast<bigint>
(input->variable->compute_equal(ivar_restart_single));
if (nextrestart <= ntimestep)
error->all(FLERR,"Restart variable returned a bad timestep");
next_restart_single = nextrestart;
}
} else next_restart_single = update->laststep + 1;
if (restart_flag_double) {
if (restart_every_double)
next_restart_double =
(ntimestep/restart_every_double)*restart_every_double +
restart_every_double;
else {
bigint nextrestart = static_cast<bigint>
(input->variable->compute_equal(ivar_restart_double));
if (nextrestart <= ntimestep)
error->all(FLERR,"Restart variable returned a bad timestep");
next_restart_double = nextrestart;
}
} else next_restart_double = update->laststep + 1;
next_restart = MIN(next_restart_single,next_restart_double);
} else next_restart = update->laststep + 1;
// print memory usage unless being called between multiple runs // print memory usage unless being called between multiple runs
@ -217,7 +262,7 @@ void Output::setup(int flag)
next_thermo = (ntimestep/thermo_every)*thermo_every + thermo_every; next_thermo = (ntimestep/thermo_every)*thermo_every + thermo_every;
next_thermo = MIN(next_thermo,update->laststep); next_thermo = MIN(next_thermo,update->laststep);
} else if (var_thermo) { } else if (var_thermo) {
next_thermo = static_cast<int> next_thermo = static_cast<bigint>
(input->variable->compute_equal(ivar_thermo)); (input->variable->compute_equal(ivar_thermo));
if (next_thermo <= ntimestep) if (next_thermo <= ntimestep)
error->all(FLERR,"Thermo every variable returned a bad timestep"); error->all(FLERR,"Thermo every variable returned a bad timestep");
@ -244,7 +289,6 @@ void Output::write(bigint ntimestep)
// download data from GPU if necessary // download data from GPU if necessary
if (next_dump_any == ntimestep) { if (next_dump_any == ntimestep) {
if (lmp->cuda && !lmp->cuda->oncpu) lmp->cuda->downloadAll(); if (lmp->cuda && !lmp->cuda->oncpu) lmp->cuda->downloadAll();
for (int idump = 0; idump < ndump; idump++) { for (int idump = 0; idump < ndump; idump++) {
@ -272,10 +316,9 @@ void Output::write(bigint ntimestep)
// download data from GPU if necessary // download data from GPU if necessary
if (next_restart == ntimestep && last_restart != ntimestep) { if (next_restart == ntimestep && last_restart != ntimestep) {
if (lmp->cuda && !lmp->cuda->oncpu) lmp->cuda->downloadAll(); if (lmp->cuda && !lmp->cuda->oncpu) lmp->cuda->downloadAll();
if (restart_toggle == 0) { if (next_restart_single == ntimestep) {
char *file = new char[strlen(restart1) + 16]; char *file = new char[strlen(restart1) + 16];
char *ptr = strchr(restart1,'*'); char *ptr = strchr(restart1,'*');
*ptr = '\0'; *ptr = '\0';
@ -283,15 +326,34 @@ void Output::write(bigint ntimestep)
*ptr = '*'; *ptr = '*';
restart->write(file); restart->write(file);
delete [] file; delete [] file;
} else if (restart_toggle == 1) { if (restart_every_single) next_restart_single += restart_every_single;
restart->write(restart1); else {
restart_toggle = 2; bigint nextrestart = static_cast<bigint>
} else if (restart_toggle == 2) { (input->variable->compute_equal(ivar_restart_single));
restart->write(restart2); if (nextrestart <= ntimestep)
restart_toggle = 1; error->all(FLERR,"Restart variable returned a bad timestep");
next_restart_single = nextrestart;
}
}
if (next_restart_double == ntimestep) {
if (restart_toggle == 0) {
restart->write(restart2a);
restart_toggle = 1;
} else {
restart->write(restart2b);
restart_toggle = 0;
}
if (restart_every_double) next_restart_double += restart_every_double;
else {
bigint nextrestart = static_cast<bigint>
(input->variable->compute_equal(ivar_restart_double));
if (nextrestart <= ntimestep)
error->all(FLERR,"Restart variable returned a bad timestep");
next_restart_double = nextrestart;
}
} }
last_restart = ntimestep; last_restart = ntimestep;
next_restart += restart_every; next_restart = MIN(next_restart_single,next_restart_double);
} }
// insure next_thermo forces output on last step of run // insure next_thermo forces output on last step of run
@ -303,7 +365,7 @@ void Output::write(bigint ntimestep)
last_thermo = ntimestep; last_thermo = ntimestep;
if (thermo_every) next_thermo += thermo_every; if (thermo_every) next_thermo += thermo_every;
else if (var_thermo) { else if (var_thermo) {
next_thermo = static_cast<int> next_thermo = static_cast<bigint>
(input->variable->compute_equal(ivar_thermo)); (input->variable->compute_equal(ivar_thermo));
if (next_thermo <= ntimestep) if (next_thermo <= ntimestep)
error->all(FLERR,"Thermo every variable returned a bad timestep"); error->all(FLERR,"Thermo every variable returned a bad timestep");
@ -331,12 +393,13 @@ void Output::write_dump(bigint ntimestep)
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
force a restart file to be written force restart file(s) to be written
called from PRD and TAD
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void Output::write_restart(bigint ntimestep) void Output::write_restart(bigint ntimestep)
{ {
if (restart_toggle == 0) { if (restart_flag_single) {
char *file = new char[strlen(restart1) + 16]; char *file = new char[strlen(restart1) + 16];
char *ptr = strchr(restart1,'*'); char *ptr = strchr(restart1,'*');
*ptr = '\0'; *ptr = '\0';
@ -344,12 +407,16 @@ void Output::write_restart(bigint ntimestep)
*ptr = '*'; *ptr = '*';
restart->write(file); restart->write(file);
delete [] file; delete [] file;
} else if (restart_toggle == 1) { }
restart->write(restart1);
restart_toggle = 2; if (restart_flag_double) {
} else if (restart_toggle == 2) { if (restart_toggle == 0) {
restart->write(restart2); restart->write(restart2a);
restart_toggle = 1; restart_toggle = 1;
} else {
restart->write(restart2b);
restart_toggle = 0;
}
} }
last_restart = ntimestep; last_restart = ntimestep;
@ -479,45 +546,79 @@ void Output::create_thermo(int narg, char **arg)
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
setup restart capability setup restart capability for single or double output files
if only one filename and it contains no "*", then append ".*" if only one filename and it contains no "*", then append ".*"
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void Output::create_restart(int narg, char **arg) void Output::create_restart(int narg, char **arg)
{ {
if (narg < 1) error->all(FLERR,"Illegal restart command"); if (narg < 1) error->all(FLERR,"Illegal restart command");
int every = 0;
int varflag = 0;
if (restart) delete restart; if (strstr(arg[0],"v_") == arg[0]) varflag = 1;
delete [] restart1; else every = atoi(arg[0]);
delete [] restart2;
restart = NULL;
restart1 = restart2 = NULL;
last_restart = -1;
restart_every = atoi(arg[0]); if (!varflag && every == 0) {
if (restart_every == 0) {
if (narg != 1) error->all(FLERR,"Illegal restart command"); if (narg != 1) error->all(FLERR,"Illegal restart command");
restart_flag = restart_flag_single = restart_flag_double = 0;
last_restart = -1;
delete restart;
restart = NULL;
delete [] restart1;
delete [] restart2a;
delete [] restart2b;
restart1 = restart2a = restart2b = NULL;
delete [] var_restart_single;
delete [] var_restart_double;
var_restart_single = var_restart_double = NULL;
return; return;
} }
restart = new WriteRestart(lmp);
if (narg != 2 && narg != 3) error->all(FLERR,"Illegal restart command"); if (narg != 2 && narg != 3) error->all(FLERR,"Illegal restart command");
int n = strlen(arg[1]) + 3;
restart1 = new char[n];
strcpy(restart1,arg[1]);
if (narg == 2) { if (narg == 2) {
restart_toggle = 0; restart_flag = restart_flag_single = 1;
restart2 = NULL;
if (varflag) {
delete [] var_restart_single;
int n = strlen(&arg[0][2]) + 1;
var_restart_single = new char[n];
strcpy(var_restart_single,&arg[0][2]);
restart_every_single = 0;
} else restart_every_single = every;
int n = strlen(arg[1]) + 3;
restart1 = new char[n];
strcpy(restart1,arg[1]);
if (strchr(restart1,'*') == NULL) strcat(restart1,".*"); if (strchr(restart1,'*') == NULL) strcat(restart1,".*");
} else if (narg == 3) { }
restart_toggle = 1;
if (narg == 3) {
restart_flag = restart_flag_double = 1;
if (varflag) {
delete [] var_restart_double;
int n = strlen(&arg[0][2]) + 1;
var_restart_double = new char[n];
strcpy(var_restart_double,&arg[0][2]);
restart_every_double = 0;
} else restart_every_double = every;
restart_toggle = 0;
int n = strlen(arg[1]) + 3;
restart2a = new char[n];
strcpy(restart2a,arg[1]);
n = strlen(arg[2]) + 1; n = strlen(arg[2]) + 1;
restart2 = new char[n]; restart2b = new char[n];
strcpy(restart2,arg[2]); strcpy(restart2b,arg[2]);
} else error->all(FLERR,"Illegal restart command"); }
if (restart == NULL) restart = new WriteRestart(lmp);
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------

View File

@ -39,13 +39,23 @@ class Output : protected Pointers {
int *ivar_dump; // variable index for dump frequency int *ivar_dump; // variable index for dump frequency
class Dump **dump; // list of defined Dumps class Dump **dump; // list of defined Dumps
bigint next_restart; // next timestep to write a restart file int restart_flag; // 1 if any restart files are written
int restart_every; // write a restart file every this many steps int restart_flag_single; // 1 if single restart files are written
bigint last_restart; // last timestep a restart file was output int restart_flag_double; // 1 if double restart files are written
int restart_toggle; // 0 if use restart1 as prefix bigint next_restart; // next timestep to write any restart file
// 1 if use restart1 as file, 2 for restart2 bigint next_restart_single; // next timestep to write a single restart file
char *restart1,*restart2; // names for restart files bigint next_restart_double; // next timestep to write a double restart file
class WriteRestart *restart; // Restart output int restart_every_single; // single restart file write freq, 0 if var
int restart_every_double; // double restart file write freq, 0 if var
bigint last_restart; // last timestep any restart file was output
int restart_toggle; // 0 if use restart2a as prefix, 1 if restart2b
char *var_restart_single; // variable name for single restart freq
char *var_restart_double; // variable name for double restart freq
int ivar_restart_single; // index of var_restart_single
int ivar_restart_double; // index of var_restart_double
char *restart1; // name single restart file
char *restart2a,*restart2b; // names of double restart files
class WriteRestart *restart; // class for writing restart files
Output(class LAMMPS *); Output(class LAMMPS *);
~Output(); ~Output();