added restart capability to fix temp/csld and fix temp/csvr
This commit is contained in:
@ -49,6 +49,7 @@ FixTempCSLD::FixTempCSLD(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
// CSLD thermostat should be applied every step
|
||||
|
||||
restart_global = 1;
|
||||
nevery = 1;
|
||||
scalar_flag = 1;
|
||||
global_freq = nevery;
|
||||
@ -297,6 +298,48 @@ double FixTempCSLD::compute_scalar()
|
||||
return energy;
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
pack entire state of Fix into one write
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void FixTempCSLD::write_restart(FILE *fp)
|
||||
{
|
||||
int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy
|
||||
double *list;
|
||||
if (comm->me == 0) list = new double[nsize];
|
||||
list[0] = energy;
|
||||
list[1] = comm->nprocs;
|
||||
double state[103];
|
||||
random->get_state(state);
|
||||
MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world);
|
||||
|
||||
if (comm->me == 0) {
|
||||
int size = nsize * sizeof(double);
|
||||
fwrite(&size,sizeof(int),1,fp);
|
||||
fwrite(list,sizeof(double),nsize,fp);
|
||||
}
|
||||
if (comm->me == 0) delete[] list;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
use state info from restart file to restart the Fix
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void FixTempCSLD::restart(char *buf)
|
||||
{
|
||||
int n = 0;
|
||||
double *list = (double *) buf;
|
||||
|
||||
energy = list[n++];
|
||||
int nprocs = (int) list[n++];
|
||||
if (nprocs != comm->nprocs) {
|
||||
if (comm->me == 0)
|
||||
error->warning(FLERR,"Different number of procs. Cannot restore RNG state.");
|
||||
} else random->set_state(list+n+comm->me*103);
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
extract thermostat properties
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user