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

This commit is contained in:
sjplimp
2016-04-07 21:12:44 +00:00
parent 008896a77d
commit 13c5549009
6 changed files with 110 additions and 11 deletions

View File

@ -16,6 +16,7 @@
#include "atom.h"
#include "comm.h"
#include "force.h"
#include "neighbor.h"
#include "suffix.h"
#include "atom_masks.h"
#include "memory.h"
@ -23,6 +24,8 @@
using namespace LAMMPS_NS;
enum{NONE,LINEAR,SPLINE};
/* -----------------------------------------------------------------------
set bond contribution to Vdwl energy to 0.0
a particular bond style can override this
@ -212,6 +215,74 @@ void Bond::ev_tally(int i, int j, int nlocal, int newton_bond,
}
}
/* ----------------------------------------------------------------------
write a table of bond potential energy/force vs distance to a file
------------------------------------------------------------------------- */
void Bond::write_file(int narg, char **arg)
{
if (narg != 6 && narg !=8) error->all(FLERR,"Illegal bond_write command");
// parse optional arguments
int itype = 0;
int jtype = 0;
if (narg == 8) {
itype = force->inumeric(FLERR,arg[6]);
jtype = force->inumeric(FLERR,arg[7]);
if (itype < 1 || itype > atom->ntypes || jtype < 1 || jtype > atom->ntypes)
error->all(FLERR,"Invalid atom types in bond_write command");
}
int btype = force->inumeric(FLERR,arg[0]);
int n = force->inumeric(FLERR,arg[1]);
double inner = force->numeric(FLERR,arg[2]);
double outer = force->numeric(FLERR,arg[3]);
if (inner <= 0.0 || inner >= outer)
error->all(FLERR,"Invalid rlo/rhi values in bond_write command");
double r0 = equilibrium_distance(btype);
// open file in append mode
// print header in format used by bond_style table
int me;
MPI_Comm_rank(world,&me);
FILE *fp;
if (me == 0) {
fp = fopen(arg[4],"a");
if (fp == NULL) error->one(FLERR,"Cannot open bond_write file");
}
// initialize potentials before evaluating bond potential
// insures all bond coeffs are set and force constants
// also initialize neighbor so that neighbor requests are processed
// NOTE: might be safest to just do lmp->init()
force->init();
neighbor->init();
if (me == 0) {
double r,e,f;
// evaluate energy and force at each of N distances
// note that Bond::single() takes r**2 and returns f/r.
fprintf(fp,"# Bond potential %s for bond type %d: i,r,energy,force\n",
force->bond_style,btype);
fprintf(fp,"\n%s\nN %d EQ %.15g\n\n",arg[5],n,r0);
const double dr = (outer-inner) / static_cast<double>(n-1);
for (int i = 0; i < n; i++) {
r = inner + dr * static_cast<double>(i);
e = single(btype,r*r,itype,jtype,f);
fprintf(fp,"%d %.15g %.15g %.15g\n",i+1,r,e,f*r);
}
fclose(fp);
}
}
/* ---------------------------------------------------------------------- */
double Bond::memory_usage()