diff --git a/src/fix_spring_self.cpp b/src/fix_spring_self.cpp index 1e84ca31b4..2ce9542331 100644 --- a/src/fix_spring_self.cpp +++ b/src/fix_spring_self.cpp @@ -35,6 +35,9 @@ FixSpringSelf::FixSpringSelf(LAMMPS *lmp, int narg, char **arg) : if (narg != 4) error->all("Illegal fix spring/self command"); restart_peratom = 1; + scalar_flag = 1; + scalar_vector_freq = 1; + extscalar = 1; k = atof(arg[3]); if (k <= 0.0) error->all("Illegal fix spring/self command"); @@ -92,6 +95,7 @@ int FixSpringSelf::setmask() int mask = 0; mask |= POST_FORCE; mask |= POST_FORCE_RESPA; + mask |= MIN_POST_FORCE; return mask; } @@ -131,6 +135,7 @@ void FixSpringSelf::post_force(int vflag) double zprd = domain->zprd; int xbox,ybox,zbox; double dx,dy,dz; + double espring = 0.0; for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { @@ -143,6 +148,7 @@ void FixSpringSelf::post_force(int vflag) f[i][0] -= k*dx; f[i][1] -= k*dy; f[i][2] -= k*dz; + espring += k * (dx*dx + dy*dy + dz*dz); } } @@ -153,6 +159,24 @@ void FixSpringSelf::post_force_respa(int vflag, int ilevel, int iloop) if (ilevel == nlevels_respa-1) post_force(vflag); } +/* ---------------------------------------------------------------------- + energy of stretched springs +------------------------------------------------------------------------- */ + +double FixSpringSelf::compute_scalar() +{ + double all; + MPI_Allreduce(&espring,&all,1,MPI_DOUBLE,MPI_SUM,world); + return all; +} + +/* ---------------------------------------------------------------------- */ + +void FixSpringSelf::min_post_force(int vflag) +{ + post_force(vflag); +} + /* ---------------------------------------------------------------------- memory usage of local atom-based array ------------------------------------------------------------------------- */ diff --git a/src/fix_spring_self.h b/src/fix_spring_self.h index 7eed32e10b..d217f0a89b 100644 --- a/src/fix_spring_self.h +++ b/src/fix_spring_self.h @@ -27,6 +27,8 @@ class FixSpringSelf : public Fix { void setup(int); void post_force(int); void post_force_respa(int, int, int); + void min_post_force(int); + double compute_scalar(); double memory_usage(); void grow_arrays(int); @@ -39,7 +41,7 @@ class FixSpringSelf : public Fix { int maxsize_restart(); private: - double k; + double k,espring; double **xoriginal; // original coords of atoms int nlevels_respa; };