Skip to content
Snippets Groups Projects
Commit a087813d authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

incorporate bugfix for fix ave/correlate/long from jorge ramirez

parent 48e42a4e
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "compute.h" #include "compute.h"
#include "input.h" #include "input.h"
#include "variable.h" #include "variable.h"
#include "citeme.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "force.h" #include "force.h"
...@@ -45,11 +46,24 @@ enum{AUTO,UPPER,LOWER,AUTOUPPER,AUTOLOWER,FULL}; ...@@ -45,11 +46,24 @@ enum{AUTO,UPPER,LOWER,AUTOUPPER,AUTOLOWER,FULL};
#define INVOKED_VECTOR 2 #define INVOKED_VECTOR 2
#define INVOKED_ARRAY 4 #define INVOKED_ARRAY 4
static const char cite_fix_ave_correlate_long[] =
"fix ave/correlate/long command:\n\n"
"@Article{Ramirez10,\n"
" author = {Jorge Rami{\'}rez and Sathish K. Sukumaran and Bart Vorselaars and Alexei E. Likhtman},\n"
" title = {Efficient on the fly calculation of time correlation functions in computer simulations},"
" journal = {J.~Chem.~Phys.},\n"
" year = 2010,\n"
" volume = 133,\n"
" pages = {154103}\n"
"}\n\n";
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
FixAveCorrelateLong::FixAveCorrelateLong(LAMMPS * lmp, int narg, char **arg): FixAveCorrelateLong::FixAveCorrelateLong(LAMMPS * lmp, int narg, char **arg):
Fix (lmp, narg, arg) Fix (lmp, narg, arg)
{ {
if (lmp->citeme) lmp->citeme->add(cite_fix_ave_correlate_long);
// At least nevery nfrez and one value are needed // At least nevery nfrez and one value are needed
if (narg < 6) error->all(FLERR,"Illegal fix ave/correlate/long command"); if (narg < 6) error->all(FLERR,"Illegal fix ave/correlate/long command");
...@@ -321,6 +335,8 @@ FixAveCorrelateLong::FixAveCorrelateLong(LAMMPS * lmp, int narg, char **arg): ...@@ -321,6 +335,8 @@ FixAveCorrelateLong::FixAveCorrelateLong(LAMMPS * lmp, int narg, char **arg):
nvalid_last = -1; nvalid_last = -1;
nvalid = nextvalid(); nvalid = nextvalid();
modify->addstep_compute_all(nvalid); modify->addstep_compute_all(nvalid);
last_accumulated_step = -1;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
...@@ -479,7 +495,7 @@ void FixAveCorrelateLong::end_of_step() ...@@ -479,7 +495,7 @@ void FixAveCorrelateLong::end_of_step()
fprintf(fp,"# Timestep: " BIGINT_FORMAT "\n", ntimestep); fprintf(fp,"# Timestep: " BIGINT_FORMAT "\n", ntimestep);
for (unsigned int i=0;i<npcorr;++i) { for (unsigned int i=0;i<npcorr;++i) {
fprintf(fp, "%lg ", t[i]*update->dt); fprintf(fp, "%lg ", t[i]*update->dt);
for (unsigned int j=0;j<npair;++j) { for (int j=0;j<npair;++j) {
fprintf(fp, "%lg ", f[j][i]); fprintf(fp, "%lg ", f[j][i]);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
...@@ -499,7 +515,7 @@ void FixAveCorrelateLong::evaluate() { ...@@ -499,7 +515,7 @@ void FixAveCorrelateLong::evaluate() {
unsigned int jm=0; unsigned int jm=0;
// First correlator // First correlator
for (unsigned int j=0;j<p;++j) { for (int j=0;j<p;++j) {
if (ncorrelation[0][j] > 0) { if (ncorrelation[0][j] > 0) {
t[jm] = j; t[jm] = j;
for (int i=0;i<npair;++i) for (int i=0;i<npair;++i)
...@@ -532,7 +548,7 @@ void FixAveCorrelateLong::accumulate() ...@@ -532,7 +548,7 @@ void FixAveCorrelateLong::accumulate()
{ {
int i,j,ipair; int i,j,ipair;
//printf("DEBUG %i %i\n", nvalues, npair); if (update->ntimestep <= last_accumulated_step) return;
if (type == AUTO) { if (type == AUTO) {
for (i=0; i<nvalues;i++) add(i,values[i]); for (i=0; i<nvalues;i++) add(i,values[i]);
...@@ -566,13 +582,14 @@ void FixAveCorrelateLong::accumulate() ...@@ -566,13 +582,14 @@ void FixAveCorrelateLong::accumulate()
else add(ipair++,values[i],values[j]); else add(ipair++,values[i],values[j]);
} }
} }
last_accumulated_step = update->ntimestep;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
Add a scalar value to the autocorrelator k of pair i Add a scalar value to the autocorrelator k of pair i
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void FixAveCorrelateLong::add(const int i, const double w, const unsigned int k){ void FixAveCorrelateLong::add(const int i, const double w, const int k){
// If we exceed the correlator side, the value is discarded // If we exceed the correlator side, the value is discarded
if (k == numcorrelators) return; if (k == numcorrelators) return;
if (k > kmax) kmax=k; if (k > kmax) kmax=k;
...@@ -593,7 +610,7 @@ void FixAveCorrelateLong::add(const int i, const double w, const unsigned int k) ...@@ -593,7 +610,7 @@ void FixAveCorrelateLong::add(const int i, const double w, const unsigned int k)
unsigned int ind1=insertindex[k]; unsigned int ind1=insertindex[k];
if (k==0) { // First correlator is different if (k==0) { // First correlator is different
int ind2=ind1; int ind2=ind1;
for (unsigned int j=0;j<p;++j) { for (int j=0;j<p;++j) {
if (shift[i][k][ind2] > -1e10) { if (shift[i][k][ind2] > -1e10) {
correlation[i][k][j]+= shift[i][k][ind1]*shift[i][k][ind2]; correlation[i][k][j]+= shift[i][k][ind1]*shift[i][k][ind2];
if (i==0) ++ncorrelation[k][j]; if (i==0) ++ncorrelation[k][j];
...@@ -603,7 +620,7 @@ void FixAveCorrelateLong::add(const int i, const double w, const unsigned int k) ...@@ -603,7 +620,7 @@ void FixAveCorrelateLong::add(const int i, const double w, const unsigned int k)
} }
} else { } else {
int ind2=ind1-dmin; int ind2=ind1-dmin;
for (unsigned int j=dmin;j<p;++j) { for (int j=dmin;j<p;++j) {
if (ind2<0) ind2+=p; if (ind2<0) ind2+=p;
if (shift[i][k][ind2] > -1e10) { if (shift[i][k][ind2] > -1e10) {
correlation[i][k][j]+= shift[i][k][ind1]*shift[i][k][ind2]; correlation[i][k][j]+= shift[i][k][ind1]*shift[i][k][ind2];
...@@ -624,7 +641,7 @@ void FixAveCorrelateLong::add(const int i, const double w, const unsigned int k) ...@@ -624,7 +641,7 @@ void FixAveCorrelateLong::add(const int i, const double w, const unsigned int k)
Add 2 scalar values to the cross-correlator k of pair i Add 2 scalar values to the cross-correlator k of pair i
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void FixAveCorrelateLong::add(const int i, const double wA, const double wB, void FixAveCorrelateLong::add(const int i, const double wA, const double wB,
const unsigned int k) { const int k) {
if (k == numcorrelators) return; if (k == numcorrelators) return;
if (k > kmax) kmax=k; if (k > kmax) kmax=k;
...@@ -644,7 +661,7 @@ void FixAveCorrelateLong::add(const int i, const double wA, const double wB, ...@@ -644,7 +661,7 @@ void FixAveCorrelateLong::add(const int i, const double wA, const double wB,
unsigned int ind1=insertindex[k]; unsigned int ind1=insertindex[k];
if (k==0) { if (k==0) {
int ind2=ind1; int ind2=ind1;
for (unsigned int j=0;j<p;++j) { for (int j=0;j<p;++j) {
if (shift[i][k][ind2] > -1e10) { if (shift[i][k][ind2] > -1e10) {
correlation[i][k][j]+= shift[i][k][ind1]*shift2[i][k][ind2]; correlation[i][k][j]+= shift[i][k][ind1]*shift2[i][k][ind2];
if (i==0) ++ncorrelation[k][j]; if (i==0) ++ncorrelation[k][j];
...@@ -655,7 +672,7 @@ void FixAveCorrelateLong::add(const int i, const double wA, const double wB, ...@@ -655,7 +672,7 @@ void FixAveCorrelateLong::add(const int i, const double wA, const double wB,
} }
else { else {
int ind2=ind1-dmin; int ind2=ind1-dmin;
for (unsigned int j=dmin;j<p;++j) { for (int j=dmin;j<p;++j) {
if (ind2<0) ind2+=p; if (ind2<0) ind2+=p;
if (shift[i][k][ind2] > -1e10) { if (shift[i][k][ind2] > -1e10) {
correlation[i][k][j]+= shift[i][k][ind1]*shift2[i][k][ind2]; correlation[i][k][j]+= shift[i][k][ind1]*shift2[i][k][ind2];
...@@ -699,8 +716,8 @@ double FixAveCorrelateLong::memory_usage() { ...@@ -699,8 +716,8 @@ double FixAveCorrelateLong::memory_usage() {
// ncorrelation: numcorrelators x p // ncorrelation: numcorrelators x p
// naccumulator: numcorrelators // naccumulator: numcorrelators
// insertindex: numcorrelators // insertindex: numcorrelators
// t: numcorrelators x p // t: numcorrelators x p
// f: npair x numcorrelators x p // f: npair x numcorrelators x p
double bytes = (4*npair*numcorrelators*p + 2*npair*numcorrelators double bytes = (4*npair*numcorrelators*p + 2*npair*numcorrelators
+ numcorrelators*p)*sizeof(double) + numcorrelators*p)*sizeof(double)
+ numcorrelators*p*sizeof(unsigned long int) + numcorrelators*p*sizeof(unsigned long int)
...@@ -723,8 +740,7 @@ void FixAveCorrelateLong::write_restart(FILE *fp) { ...@@ -723,8 +740,7 @@ void FixAveCorrelateLong::write_restart(FILE *fp) {
list[n++]=numcorrelators; list[n++]=numcorrelators;
list[n++]=p; list[n++]=p;
list[n++]=m; list[n++]=m;
list[n++]=nvalid; list[n++] = last_accumulated_step;
list[n++]=nvalid_last;
for (int i=0;i<npair;i++) for (int i=0;i<npair;i++)
for (int j=0;j<numcorrelators;j++) { for (int j=0;j<numcorrelators;j++) {
for (int k=0;k<p;k++) { for (int k=0;k<p;k++) {
...@@ -760,8 +776,7 @@ void FixAveCorrelateLong::restart(char *buf) ...@@ -760,8 +776,7 @@ void FixAveCorrelateLong::restart(char *buf)
int numcorrelatorsin = static_cast<int> (list[n++]); int numcorrelatorsin = static_cast<int> (list[n++]);
int pin = static_cast<int> (list[n++]); int pin = static_cast<int> (list[n++]);
int min = static_cast<int> (list[n++]); int min = static_cast<int> (list[n++]);
nvalid = static_cast<int> (list[n++]); last_accumulated_step = static_cast<int> (list[n++]);
nvalid_last = static_cast<int> (list[n++]);
if ((npairin!=npair) || (numcorrelatorsin!=numcorrelators) if ((npairin!=npair) || (numcorrelatorsin!=numcorrelators)
|| (pin!=p) || (min!=m)) || (pin!=p) || (min!=m))
......
...@@ -51,17 +51,17 @@ class FixAveCorrelateLong : public Fix { ...@@ -51,17 +51,17 @@ class FixAveCorrelateLong : public Fix {
unsigned int *naccumulator; unsigned int *naccumulator;
unsigned int *insertindex; unsigned int *insertindex;
unsigned int numcorrelators; // Recommended 20 int numcorrelators; // Recommended 20
unsigned int p; // Points per correlator (recommended 16) int p; // Points per correlator (recommended 16)
unsigned int m; // Num points for average (recommended 2; p mod m = 0) unsigned int m; // Num points for average (recommended 2; p mod m = 0)
unsigned int dmin; // Min distance between ponts for correlators k>0; dmin=p/m unsigned int dmin; // Min distance between ponts for correlators k>0; dmin=p/m
unsigned int length; // Length of result arrays int length; // Length of result arrays
unsigned int kmax; // Maximum correlator attained during simulation int kmax; // Maximum correlator attained during simulation
int me,nvalues; int me,nvalues;
int nfreq; int nfreq;
bigint nvalid,nvalid_last; bigint nvalid,nvalid_last,last_accumulated_step;
int *which,*argindex,*value2index; int *which,*argindex,*value2index;
char **ids; char **ids;
FILE *fp; FILE *fp;
...@@ -76,8 +76,8 @@ class FixAveCorrelateLong : public Fix { ...@@ -76,8 +76,8 @@ class FixAveCorrelateLong : public Fix {
void evaluate(); void evaluate();
bigint nextvalid(); bigint nextvalid();
void add(const int i, const double w, const unsigned int k = 0); void add(const int i, const double w, const int k = 0);
void add(const int i, const double wA, const double wB, const unsigned int k = 0); void add(const int i, const double wA, const double wB, const int k = 0);
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment