From e8308edb15351fd3972fbdf53b26905f7046efcf Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 18 May 2012 16:35:19 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8088 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/REPLICA/prd.cpp | 9 +- src/REPLICA/tad.cpp | 9 +- src/fix_external.cpp | 3 +- src/min.cpp | 8 +- src/neighbor.cpp | 2 +- src/output.cpp | 209 ++++++++++++++++++++++++++++++++----------- src/output.h | 24 +++-- 7 files changed, 196 insertions(+), 68 deletions(-) diff --git a/src/REPLICA/prd.cpp b/src/REPLICA/prd.cpp index 39d5aa79d7..24cd52f9e9 100644 --- a/src/REPLICA/prd.cpp +++ b/src/REPLICA/prd.cpp @@ -314,9 +314,14 @@ void PRD::command(int narg, char **arg) log_event(); int restart_flag = 0; - if (output->restart_every && universe->iworld == 0) - if (fix_event->event_number % output->restart_every == 0) + if (output->restart_flag && universe->iworld == 0) { + if (output->restart_every_single && + fix_event->event_number % output->restart_every_single == 0) restart_flag = 1; + if (output->restart_every_double && + fix_event->event_number % output->restart_every_double == 0) + restart_flag = 1; + } // correlated event loop // other procs could be dephasing during this time diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp index 29f2e4fa3f..6fb3a6cf85 100644 --- a/src/REPLICA/tad.cpp +++ b/src/REPLICA/tad.cpp @@ -335,9 +335,14 @@ void TAD::command(int narg, char **arg) MPI_Bcast(&(update->ntimestep),1,MPI_INT,0,universe->uworld); int restart_flag = 0; - if (output->restart_every && universe->iworld == 0) - if (fix_event->event_number % output->restart_every == 0) + if (output->restart_flag && universe->iworld == 0) { + if (output->restart_every_single && + fix_event->event_number % output->restart_every_single == 0) 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 diff --git a/src/fix_external.cpp b/src/fix_external.cpp index 63647b7a93..85cd2f6505 100644 --- a/src/fix_external.cpp +++ b/src/fix_external.cpp @@ -56,7 +56,8 @@ int FixExternal::setmask() 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"); } /* ---------------------------------------------------------------------- */ diff --git a/src/min.cpp b/src/min.cpp index 2f9a461ba3..945c1a2f51 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -389,7 +389,13 @@ void Min::run(int n) for (int idump = 0; idump < output->ndump; idump++) output->next_dump[idump] = 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; diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 54ead69fbd..f14188fc7a 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -262,7 +262,7 @@ void Neighbor::init() // don't check if build_once is set restart_check = 0; - if (output->restart_every) restart_check = 1; + if (output->restart_flag) restart_check = 1; delete [] fixchecklist; fixchecklist = NULL; diff --git a/src/output.cpp b/src/output.cpp index eb2da9688f..859aaa5dd1 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -84,10 +84,11 @@ Output::Output(LAMMPS *lmp) : Pointers(lmp) ivar_dump = NULL; dump = NULL; - restart = NULL; - restart1 = restart2 = NULL; - restart_every = 0; + restart_flag = restart_flag_single = restart_flag_double = 0; 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]; memory->sfree(dump); - delete restart; 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])) 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 // and last dump was not on this timestep // 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 // if no dumps, set next_dump_any to last+1 so will not influence next // wrap dumps that invoke computes with clear/add @@ -189,14 +208,40 @@ void Output::setup(int flag) } } else next_dump_any = update->laststep + 1; - // do not write a restart file at start of run - // set next_restart to multiple of every - // will not write on last step of run unless multiple of every + // do not write restart files at start of run + // set next_restart values to multiple of every or variable value + // 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 (restart_every && update->restrict_output == 0) - next_restart = (ntimestep/restart_every)*restart_every + restart_every; - else next_restart = update->laststep + 1; + if (restart_flag && update->restrict_output == 0) { + if (restart_flag_single) { + if (restart_every_single) + next_restart_single = + (ntimestep/restart_every_single)*restart_every_single + + restart_every_single; + else { + bigint nextrestart = static_cast + (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 + (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 @@ -217,7 +262,7 @@ void Output::setup(int flag) next_thermo = (ntimestep/thermo_every)*thermo_every + thermo_every; next_thermo = MIN(next_thermo,update->laststep); } else if (var_thermo) { - next_thermo = static_cast + next_thermo = static_cast (input->variable->compute_equal(ivar_thermo)); if (next_thermo <= ntimestep) 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 if (next_dump_any == ntimestep) { - if (lmp->cuda && !lmp->cuda->oncpu) lmp->cuda->downloadAll(); for (int idump = 0; idump < ndump; idump++) { @@ -272,10 +316,9 @@ void Output::write(bigint ntimestep) // download data from GPU if necessary if (next_restart == ntimestep && last_restart != ntimestep) { - 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 *ptr = strchr(restart1,'*'); *ptr = '\0'; @@ -283,15 +326,34 @@ void Output::write(bigint ntimestep) *ptr = '*'; restart->write(file); delete [] file; - } else if (restart_toggle == 1) { - restart->write(restart1); - restart_toggle = 2; - } else if (restart_toggle == 2) { - restart->write(restart2); - restart_toggle = 1; + if (restart_every_single) next_restart_single += restart_every_single; + else { + bigint nextrestart = static_cast + (input->variable->compute_equal(ivar_restart_single)); + if (nextrestart <= ntimestep) + 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 + (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; - next_restart += restart_every; + next_restart = MIN(next_restart_single,next_restart_double); } // insure next_thermo forces output on last step of run @@ -303,7 +365,7 @@ void Output::write(bigint ntimestep) last_thermo = ntimestep; if (thermo_every) next_thermo += thermo_every; else if (var_thermo) { - next_thermo = static_cast + next_thermo = static_cast (input->variable->compute_equal(ivar_thermo)); if (next_thermo <= ntimestep) 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) { - if (restart_toggle == 0) { + if (restart_flag_single) { char *file = new char[strlen(restart1) + 16]; char *ptr = strchr(restart1,'*'); *ptr = '\0'; @@ -344,12 +407,16 @@ void Output::write_restart(bigint ntimestep) *ptr = '*'; restart->write(file); delete [] file; - } else if (restart_toggle == 1) { - restart->write(restart1); - restart_toggle = 2; - } else if (restart_toggle == 2) { - restart->write(restart2); - restart_toggle = 1; + } + + if (restart_flag_double) { + if (restart_toggle == 0) { + restart->write(restart2a); + restart_toggle = 1; + } else { + restart->write(restart2b); + restart_toggle = 0; + } } 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 ".*" ------------------------------------------------------------------------- */ void Output::create_restart(int narg, char **arg) { if (narg < 1) error->all(FLERR,"Illegal restart command"); + + int every = 0; + int varflag = 0; - if (restart) delete restart; - delete [] restart1; - delete [] restart2; - restart = NULL; - restart1 = restart2 = NULL; - last_restart = -1; + if (strstr(arg[0],"v_") == arg[0]) varflag = 1; + else every = atoi(arg[0]); - restart_every = atoi(arg[0]); - if (restart_every == 0) { + if (!varflag && every == 0) { 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; } - restart = new WriteRestart(lmp); - 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) { - restart_toggle = 0; - restart2 = NULL; + restart_flag = restart_flag_single = 1; + + 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,".*"); - } 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; - restart2 = new char[n]; - strcpy(restart2,arg[2]); - } else error->all(FLERR,"Illegal restart command"); + restart2b = new char[n]; + strcpy(restart2b,arg[2]); + } + + if (restart == NULL) restart = new WriteRestart(lmp); } /* ---------------------------------------------------------------------- diff --git a/src/output.h b/src/output.h index be30236158..673ea08537 100644 --- a/src/output.h +++ b/src/output.h @@ -39,13 +39,23 @@ class Output : protected Pointers { int *ivar_dump; // variable index for dump frequency class Dump **dump; // list of defined Dumps - bigint next_restart; // next timestep to write a restart file - int restart_every; // write a restart file every this many steps - bigint last_restart; // last timestep a restart file was output - int restart_toggle; // 0 if use restart1 as prefix - // 1 if use restart1 as file, 2 for restart2 - char *restart1,*restart2; // names for restart files - class WriteRestart *restart; // Restart output + int restart_flag; // 1 if any restart files are written + int restart_flag_single; // 1 if single restart files are written + int restart_flag_double; // 1 if double restart files are written + bigint next_restart; // next timestep to write any restart file + bigint next_restart_single; // next timestep to write a single restart file + bigint next_restart_double; // next timestep to write a double restart file + 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();