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

This commit is contained in:
sjplimp
2007-02-21 00:15:29 +00:00
parent e85be07e18
commit 64b10074dc
14 changed files with 455 additions and 202 deletions

View File

@ -40,6 +40,9 @@
using namespace LAMMPS_NS;
#define MIN(A,B) ((A) < (B)) ? (A) : (B)
#define MAX(A,B) ((A) > (B)) ? (A) : (B)
/* ---------------------------------------------------------------------- */
Respa::Respa(LAMMPS *lmp, int narg, char **arg) : Integrate(lmp, narg, arg)
@ -273,25 +276,30 @@ void Respa::init()
if (force->pair && force->pair->respa_enable == 0)
error->all("Pair style does not support rRESPA inner/middle/outer");
// set flags for how virial should be computed when needed
// pressure_flag is 1 if NPT,NPH
// virial_every is how virial should be computed every timestep
// 0 = not computed, 1 = computed explicity by pair
// virial_thermo is how virial should be computed on thermo timesteps
// 1 = computed explicity by pair
// unlike Verlet, virial is never computed implicitly
// setup virial computations for timestepping
// virial_style = 1 (explicit) since never computed implicitly like Verlet
// virial_every = 1 if computed every timestep (NPT,NPH)
// fix arrays store info on fixes that need virial computed occasionally
int pressure_flag = 0;
for (int i = 0; i < modify->nfix; i++) {
if (strcmp(modify->fix[i]->style,"npt") == 0) pressure_flag = 1;
if (strcmp(modify->fix[i]->style,"nph") == 0) pressure_flag = 1;
virial_style = 1;
virial_every = 0;
nfix_virial = 0;
for (int i = 0; i < modify->nfix; i++)
if (modify->fix[i]->pressure_every == 1) virial_every = 1;
else if (modify->fix[i]->pressure_every > 1) nfix_virial++;
if (nfix_virial) {
delete [] fix_virial_every;
delete [] next_fix_virial;
fix_virial_every = new int[nfix_virial];
next_fix_virial = new int[nfix_virial];
nfix_virial = 0;
for (int i = 0; i < modify->nfix; i++)
if (modify->fix[i]->pressure_every > 1)
fix_virial_every[nfix_virial++] = modify->fix[i]->pressure_every;
}
if (pressure_flag) virial_every = 1;
else virial_every = 0;
virial_thermo = 1;
// step[] = timestep for each level
step[nlevels-1] = update->dt;
@ -338,8 +346,8 @@ void Respa::setup()
// compute all forces
int eflag = 1;
int vflag = virial_thermo;
eflag = 1;
vflag = virial_style;
for (int ilevel = 0; ilevel < nlevels; ilevel++) {
force_clear(newton[ilevel]);
@ -370,6 +378,21 @@ void Respa::setup()
modify->setup();
sum_flevel_f();
output->setup(1);
// setup virial computations for timestepping
int ntimestep = update->ntimestep;
next_virial = 0;
if (virial_every) next_virial = ntimestep + 1;
else {
for (int ivirial = 0; ivirial < nfix_virial; ivirial++) {
next_fix_virial[ivirial] =
(ntimestep/fix_virial_every[ivirial])*fix_virial_every[ivirial] +
fix_virial_every[ivirial];
if (ivirial) next_virial = MIN(next_virial,next_fix_virial[ivirial]);
else next_virial = next_fix_virial[0];
}
}
}
/* ----------------------------------------------------------------------
@ -378,22 +401,28 @@ void Respa::setup()
void Respa::iterate(int n)
{
int ntimestep;
for (int i = 0; i < n; i++) {
update->ntimestep++;
ntimestep = ++update->ntimestep;
eflag = 0;
vflag = virial_every;
if (output->next_thermo == update->ntimestep) {
eflag = 1;
vflag = virial_thermo;
}
// eflag/vflag = 0/1 for energy/virial computation
if (ntimestep == output->next_thermo) eflag = 1;
else eflag = 0;
if (ntimestep == output->next_thermo || ntimestep == next_virial) {
vflag = virial_style;
if (virial_every) next_virial++;
else next_virial = fix_virial(ntimestep);
} else vflag = 0;
recurse(nlevels-1);
if (modify->n_end_of_step) modify->end_of_step();
if (output->next == update->ntimestep) {
if (ntimestep == output->next) {
timer->stamp();
sum_flevel_f();
output->write(update->ntimestep);
@ -582,3 +611,20 @@ void Respa::sum_flevel_f()
}
}
}
/* ----------------------------------------------------------------------
return next timestep virial should be computed
based on one or more fixes that need virial computed periodically
------------------------------------------------------------------------- */
int Respa::fix_virial(int ntimestep)
{
int next;
for (int ivirial = 0; ivirial < nfix_virial; ivirial++) {
if (ntimestep == next_fix_virial[ivirial])
next_fix_virial[ivirial] += fix_virial_every[ivirial];
if (ivirial) next = MIN(next,next_fix_virial[ivirial]);
else next = next_fix_virial[0];
}
return next;
}