forked from lijiext/lammps
added restart capability to fix temp/csld and fix temp/csvr
This commit is contained in:
parent
383bb7f905
commit
bbcae3b20c
|
@ -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
|
||||
------------------------------------------------------------------------- */
|
||||
|
|
|
@ -34,6 +34,8 @@ class FixTempCSLD : public Fix {
|
|||
int modify_param(int, char **);
|
||||
void reset_target(double);
|
||||
virtual double compute_scalar();
|
||||
void write_restart(FILE *);
|
||||
void restart(char *buf);
|
||||
virtual void *extract(const char *, int &);
|
||||
|
||||
private:
|
||||
|
|
|
@ -331,6 +331,46 @@ double FixTempCSVR::compute_scalar()
|
|||
return energy;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
pack entire state of Fix into one write
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void FixTempCSVR::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 FixTempCSVR::restart(char *buf)
|
||||
{
|
||||
int n = 0;
|
||||
double *list = (double *) buf;
|
||||
|
||||
energy = list[0];
|
||||
int nprocs = (int) list[1];
|
||||
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
|
||||
------------------------------------------------------------------------- */
|
||||
|
|
|
@ -34,6 +34,8 @@ class FixTempCSVR : public Fix {
|
|||
int modify_param(int, char **);
|
||||
void reset_target(double);
|
||||
virtual double compute_scalar();
|
||||
void write_restart(FILE *);
|
||||
void restart(char *buf);
|
||||
virtual void *extract(const char *, int &);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue