git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@14789 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -16,7 +16,7 @@
|
||||
#include "compute_bond.h"
|
||||
#include "update.h"
|
||||
#include "force.h"
|
||||
#include "bond.h"
|
||||
#include "bond_hybrid.h"
|
||||
#include "error.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
@ -26,64 +26,55 @@ using namespace LAMMPS_NS;
|
||||
ComputeBond::ComputeBond(LAMMPS *lmp, int narg, char **arg) :
|
||||
Compute(lmp, narg, arg)
|
||||
{
|
||||
if (narg < 4 || narg > 5) error->all(FLERR,"Illegal compute bond command");
|
||||
if (igroup) error->all(FLERR,"Compute bond must use group all");
|
||||
if (narg != 3) error->all(FLERR,"Illegal compute bond command");
|
||||
|
||||
scalar_flag = 1;
|
||||
extscalar = 1;
|
||||
vector_flag = 1;
|
||||
extvector = 1;
|
||||
peflag = 1;
|
||||
timeflag = 1;
|
||||
|
||||
int n = strlen(arg[3]) + 1;
|
||||
if (lmp->suffix) n += strlen(lmp->suffix) + 1;
|
||||
bstyle = new char[n];
|
||||
strcpy(bstyle,arg[3]);
|
||||
// check if bond style hybrid exists
|
||||
|
||||
// check if bond style with and without suffix exists
|
||||
|
||||
bond = force->bond_match(bstyle);
|
||||
if (!bond && lmp->suffix) {
|
||||
strcat(bstyle,"/");
|
||||
strcat(bstyle,lmp->suffix);
|
||||
bond = force->bond_match(bstyle);
|
||||
}
|
||||
bond = (BondHybrid *) force->bond_match("hybrid");
|
||||
if (!bond)
|
||||
error->all(FLERR,"Unrecognized bond style in compute bond command");
|
||||
|
||||
vector = NULL;
|
||||
error->all(FLERR,"Bond style for compute bond command is not hybrid");
|
||||
size_vector = nsub = bond->nstyles;
|
||||
|
||||
emine = new double[nsub];
|
||||
vector = new double[nsub];
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
ComputeBond::~ComputeBond()
|
||||
{
|
||||
delete [] bstyle;
|
||||
delete [] emine;
|
||||
delete [] vector;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeBond::init()
|
||||
{
|
||||
// recheck for bond style in case it has been deleted
|
||||
|
||||
bond = force->bond_match(bstyle);
|
||||
// recheck bond style in case it has been changed
|
||||
|
||||
bond = (BondHybrid *) force->bond_match("hybrid");
|
||||
if (!bond)
|
||||
error->all(FLERR,"Unrecognized bond style in compute bond command");
|
||||
error->all(FLERR,"Bond style for compute bond command is not hybrid");
|
||||
if (bond->nstyles != nsub)
|
||||
error->all(FLERR,"Bond style for compute bond command has changed");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
double ComputeBond::compute_scalar()
|
||||
void ComputeBond::compute_vector()
|
||||
{
|
||||
invoked_scalar = update->ntimestep;
|
||||
if (update->eflag_global != invoked_scalar)
|
||||
invoked_vector = update->ntimestep;
|
||||
if (update->eflag_global != invoked_vector)
|
||||
error->all(FLERR,"Energy was not tallied on needed timestep");
|
||||
|
||||
double eng;
|
||||
eng = bond->energy;
|
||||
for (int i = 0; i < nsub; i++)
|
||||
emine[i] = bond->styles[i]->energy;
|
||||
|
||||
MPI_Allreduce(&eng,&scalar,1,MPI_DOUBLE,MPI_SUM,world);
|
||||
return scalar;
|
||||
MPI_Allreduce(emine,vector,nsub,MPI_DOUBLE,MPI_SUM,world);
|
||||
}
|
||||
|
||||
|
||||
@ -29,11 +29,12 @@ class ComputeBond : public Compute {
|
||||
ComputeBond(class LAMMPS *, int, char **);
|
||||
~ComputeBond();
|
||||
void init();
|
||||
double compute_scalar();
|
||||
void compute_vector();
|
||||
|
||||
private:
|
||||
char *bstyle;
|
||||
class Bond *bond;
|
||||
int nsub;
|
||||
class BondHybrid *bond;
|
||||
double *emine;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -29,7 +29,6 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) :
|
||||
Compute(lmp, narg, arg)
|
||||
{
|
||||
if (narg < 4 || narg > 5) error->all(FLERR,"Illegal compute pair command");
|
||||
if (igroup) error->all(FLERR,"Compute pair must use group all");
|
||||
|
||||
scalar_flag = 1;
|
||||
extscalar = 1;
|
||||
|
||||
@ -389,6 +389,21 @@ Angle *Force::new_angle(const char *style, int trysuffix, int &sflag)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
return ptr to current angle class or hybrid sub-class if matches style
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Angle *Force::angle_match(const char *style)
|
||||
{
|
||||
if (strcmp(angle_style,style) == 0) return angle;
|
||||
else if (strcmp(angle_style,"hybrid") == 0) {
|
||||
AngleHybrid *hybrid = (AngleHybrid *) angle;
|
||||
for (int i = 0; i < hybrid->nstyles; i++)
|
||||
if (strcmp(hybrid->keywords[i],style) == 0) return hybrid->styles[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
create a dihedral style, called from input script or restart file
|
||||
------------------------------------------------------------------------- */
|
||||
@ -455,6 +470,21 @@ Dihedral *Force::new_dihedral(const char *style, int trysuffix, int &sflag)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
return ptr to current angle class or hybrid sub-class if matches style
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Dihedral *Force::dihedral_match(const char *style)
|
||||
{
|
||||
if (strcmp(dihedral_style,style) == 0) return dihedral;
|
||||
else if (strcmp(dihedral_style,"hybrid") == 0) {
|
||||
DihedralHybrid *hybrid = (DihedralHybrid *) dihedral;
|
||||
for (int i = 0; i < hybrid->nstyles; i++)
|
||||
if (strcmp(hybrid->keywords[i],style) == 0) return hybrid->styles[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
create an improper style, called from input script or restart file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
@ -89,9 +89,11 @@ class Force : protected Pointers {
|
||||
|
||||
void create_angle(const char *, int);
|
||||
class Angle *new_angle(const char *, int, int &);
|
||||
class Angle *angle_match(const char *);
|
||||
|
||||
void create_dihedral(const char *, int);
|
||||
class Dihedral *new_dihedral(const char *, int, int &);
|
||||
class Dihedral *dihedral_match(const char *);
|
||||
|
||||
void create_improper(const char *, int);
|
||||
class Improper *new_improper(const char *, int, int &);
|
||||
|
||||
Reference in New Issue
Block a user