-1e10) {
correlation[i][k][j]+= shift[i][k][ind1]*shift[i][k][ind2];
if (i == 0) ++ncorrelation[k][j];
}
--ind2;
}
}
if (i == npair-1) {
++insertindex[k];
if (insertindex[k]==p) insertindex[k]=0;
}
}
/* ----------------------------------------------------------------------
Add 2 scalar values to the cross-correlator k of pair i
------------------------------------------------------------------------- */
void FixAveCorrelateLong::add(const int i, const double wA, const double wB, const int k) {
if (k == numcorrelators) return;
if (k > kmax) kmax=k;
shift[i][k][insertindex[k]] = wA;
shift2[i][k][insertindex[k]] = wB;
accumulator[i][k] += wA;
accumulator2[i][k] += wB;
if (i == 0) ++naccumulator[k];
if (naccumulator[k] == m) {
add(i,accumulator[i][k]/m, accumulator2[i][k]/m,k+1);
accumulator[i][k]=0;
accumulator2[i][k]=0;
if (i == npair-1) naccumulator[k]=0;
}
unsigned int ind1=insertindex[k];
if (k == 0) {
int ind2=ind1;
for (unsigned int j=0; j < p; ++j) {
if (shift[i][k][ind2] > -1e10) {
correlation[i][k][j]+= shift[i][k][ind1]*shift2[i][k][ind2];
if (i == 0) ++ncorrelation[k][j];
}
--ind2;
if (ind2<0) ind2+=p;
}
}
else {
int ind2=ind1-dmin;
for (unsigned int j=dmin; j < p; ++j) {
if (ind2 < 0) ind2+=p;
if (shift[i][k][ind2] > -1e10) {
correlation[i][k][j]+= shift[i][k][ind1]*shift2[i][k][ind2];
if (i == 0) ++ncorrelation[k][j];
}
--ind2;
}
}
if (i == npair-1) {
++insertindex[k];
if (insertindex[k] == p) insertindex[k]=0;
}
}
/* ----------------------------------------------------------------------
nvalid = next step on which end_of_step does something
this step if multiple of nevery, else next multiple
startstep is lower bound
------------------------------------------------------------------------- */
bigint FixAveCorrelateLong::nextvalid()
{
bigint nvalid = update->ntimestep;
if (startstep > nvalid) nvalid = startstep;
if (nvalid % nevery) nvalid = (nvalid/nevery)*nevery + nevery;
return nvalid;
}
/* ----------------------------------------------------------------------
memory_usage
------------------------------------------------------------------------- */
double FixAveCorrelateLong::memory_usage() {
// shift: npair x numcorrelators x p
// shift2: npair x numcorrelators x p
// correlation: npair x numcorrelators x p
// accumulator: npair x numcorrelators
// accumulator2: npair x numcorrelators
// ncorrelation: numcorrelators x p
// naccumulator: numcorrelators
// insertindex: numcorrelators
// t: numcorrelators x p
// f: npair x numcorrelators x p
double bytes = (4*npair*numcorrelators*p + 2*npair*numcorrelators
+ numcorrelators*p)*sizeof(double)
+ (double)numcorrelators*p*sizeof(unsigned long int)
+ 2.0*numcorrelators*sizeof(unsigned int);
return bytes;
}
/* ----------------------------------------------------------------------
Write Restart data to restart file
------------------------------------------------------------------------- */
// Save everything except t and f
void FixAveCorrelateLong::write_restart(FILE *fp) {
if (comm->me == 0) {
int nsize = 3*npair*numcorrelators*p + 2*npair*numcorrelators
+ numcorrelators*p + 2*numcorrelators + 7;
int n=0;
double *list;
memory->create(list,nsize,"correlator:list");
list[n++] = npair;
list[n++] = numcorrelators;
list[n++] = p;
list[n++] = m;
list[n++] = kmax;
list[n++] = last_accumulated_step;
for (int i=0; i < npair; i++)
for (int j=0; j < numcorrelators; j++) {
for (unsigned int k=0; k < p; k++) {
list[n++]=shift[i][j][k];
list[n++]=shift2[i][j][k];
list[n++]=correlation[i][j][k];
}
list[n++]=accumulator[i][j];
list[n++]=accumulator2[i][j];
}
for (int i=0; i (list[n++]);
naccumulator[i] = static_cast