[lammps-users] Error in fix_temp_rescale.cpp

Hi Steve,

I noticed that there is a minor error in the file fix_temp_rescale.cpp.

I believe that the variable ‘energy’ in the function ‘FixTempRescale::end_of_step()’ ought to be reset to zero initially in every instance the function is called. Currently, it is only reset to zero when the temperature is outside the temperature window.

The correction is in red as shown below.

Regards,
Zhun-Yong Ong
University of Illinois at Urbana-Champaign

/* ---------------------------------------------------------------------- */

void FixTempRescale::end_of_step()
{
double t_current = temperature->compute_scalar();
if (t_current == 0.0)
error->all(“Computed temperature for fix temp/rescale cannot be 0.0”);

double delta = update->ntimestep - update->beginstep;
delta /= update->endstep - update->beginstep;
double t_target = t_start + delta * (t_stop-t_start);

// rescale velocity of appropriate atoms if outside window

if (fabs(t_current-t_target) > t_window) {
t_target = t_current - fraction*(t_current-t_target);
double factor = sqrt(t_target/t_current);

double **v = atom->v;
int *mask = atom->mask;
int nlocal = atom->nlocal;

energy = 0.0; // This line is needed to clear the previous value.

if (which == NOBIAS) {
energy += (t_current-t_target) * efactor;
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
v[i][0] *= factor;
v[i][1] *= factor;
v[i][2] *= factor;
}
}

} else if (which == BIAS) {
energy += (t_current-t_target) * efactor;
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
temperature->remove_bias(i,v[i]);
v[i][0] *= factor;
v[i][1] *= factor;
v[i][2] *= factor;
temperature->restore_bias(i,v[i]);
}
}
}

} else energy = 0.0;
}

This was meant to track cummulative energy
added/subtracted by the rescaling, similar to fix nvt and
fix npt. But that wasn't done quite right either
in temp/rescale. Just posted a patch that should fix it.

Thanks,
Steve

Hi Steve,

Is it possible to have a variable that tracks the change in energy
every the temperature is rescaled? This would be useful to people who
use heat baths to set up a temperature gradient. The changes in the
energy of the heat baths will allow them to compute the average heat
current.

Zhun-Yong

Doesn't the cummulative energy have that info in it?
If it just stores one-time energy, then the user may
or may not access it at correct times to get that info.

Steve