diff --git a/src/angle_zero.cpp b/src/angle_zero.cpp index a63f787840..50bdc88fb3 100644 --- a/src/angle_zero.cpp +++ b/src/angle_zero.cpp @@ -17,9 +17,11 @@ #include #include +#include #include "angle_zero.h" #include "atom.h" #include "force.h" +#include "comm.h" #include "memory.h" #include "error.h" @@ -27,7 +29,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -AngleZero::AngleZero(LAMMPS *lmp) : Angle(lmp) {} +AngleZero::AngleZero(LAMMPS *lmp) : Angle(lmp), check_coeffs(1) {} /* ---------------------------------------------------------------------- */ @@ -35,6 +37,7 @@ AngleZero::~AngleZero() { if (allocated && !copymode) { memory->destroy(setflag); + memory->destroy(theta0); } } @@ -48,11 +51,25 @@ void AngleZero::compute(int eflag, int vflag) /* ---------------------------------------------------------------------- */ +void AngleZero::settings(int narg, char **arg) +{ + if ((narg != 0) && (narg != 1)) + error->all(FLERR,"Illegal angle_style command"); + + if (narg == 1) { + if (strcmp("nocoeffs",arg[0]) == 0) check_coeffs=0; + else error->all(FLERR,"Illegal angle_style command"); + } +} + +/* ---------------------------------------------------------------------- */ + void AngleZero::allocate() { allocated = 1; int n = atom->nangletypes; + memory->create(theta0,n+1,"angle:theta0"); memory->create(setflag,n+1,"angle:setflag"); for (int i = 1; i <= n; i++) setflag[i] = 0; } @@ -63,15 +80,23 @@ void AngleZero::allocate() void AngleZero::coeff(int narg, char **arg) { - if (narg != 1) error->all(FLERR,"Incorrect args for angle coefficients"); + if ((narg < 1) || (check_coeffs && narg > 2)) + error->all(FLERR,"Incorrect args for angle coefficients"); + if (!allocated) allocate(); int ilo,ihi; force->bounds(arg[0],atom->nangletypes,ilo,ihi); + double theta0_one = 0.0; + if (check_coeffs && (narg == 2)) + theta0_one = force->numeric(FLERR,arg[1]); + + int count = 0; for (int i = ilo; i <= ihi; i++) { setflag[i] = 1; + theta0[i] = theta0_one; count++; } @@ -82,14 +107,16 @@ void AngleZero::coeff(int narg, char **arg) double AngleZero::equilibrium_angle(int i) { - return 0.0; + return theta0[i]; } /* ---------------------------------------------------------------------- proc 0 writes out coeffs to restart file ------------------------------------------------------------------------- */ -void AngleZero::write_restart(FILE *fp) {} +void AngleZero::write_restart(FILE *fp) { + fwrite(&theta0[1],sizeof(double),atom->nangletypes,fp); +} /* ---------------------------------------------------------------------- proc 0 reads coeffs from restart file, bcasts them @@ -98,8 +125,23 @@ void AngleZero::write_restart(FILE *fp) {} void AngleZero::read_restart(FILE *fp) { allocate(); + + if (comm->me == 0) { + fread(&theta0[1],sizeof(double),atom->nangletypes,fp); + } + MPI_Bcast(&theta0[1],atom->nangletypes,MPI_DOUBLE,0,world); + for (int i = 1; i <= atom->nangletypes; i++) setflag[i] = 1; } +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void AngleZero::write_data(FILE *fp) +{ + for (int i = 1; i <= atom->nangletypes; i++) + fprintf(fp,"%d %g\n",i,theta0[i]); +} /* ---------------------------------------------------------------------- */ diff --git a/src/angle_zero.h b/src/angle_zero.h index 8d8d966b55..eda5311088 100644 --- a/src/angle_zero.h +++ b/src/angle_zero.h @@ -31,12 +31,19 @@ class AngleZero : public Angle { virtual ~AngleZero(); virtual void compute(int, int); virtual void coeff(int, char **); + virtual void settings(int, char **); + double equilibrium_angle(int); void write_restart(FILE *); void read_restart(FILE *); + void write_data(FILE *); + double single(int, int, int, int); protected: + double *theta0; + int check_coeffs; + void allocate(); }; diff --git a/src/bond_zero.cpp b/src/bond_zero.cpp index e8f50deec2..58ed807482 100644 --- a/src/bond_zero.cpp +++ b/src/bond_zero.cpp @@ -17,9 +17,11 @@ #include #include +#include #include "bond_zero.h" #include "atom.h" #include "force.h" +#include "comm.h" #include "memory.h" #include "error.h" @@ -27,7 +29,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -BondZero::BondZero(LAMMPS *lmp) : Bond(lmp) {} +BondZero::BondZero(LAMMPS *lmp) : Bond(lmp), check_coeffs(1) {} /* ---------------------------------------------------------------------- */ @@ -35,6 +37,7 @@ BondZero::~BondZero() { if (allocated && !copymode) { memory->destroy(setflag); + memory->destroy(r0); } } @@ -48,11 +51,25 @@ void BondZero::compute(int eflag, int vflag) /* ---------------------------------------------------------------------- */ +void BondZero::settings(int narg, char **arg) +{ + if ((narg != 0) && (narg != 1)) + error->all(FLERR,"Illegal bond_style command"); + + if (narg == 1) { + if (strcmp("nocoeffs",arg[0]) == 0) check_coeffs=0; + else error->all(FLERR,"Illegal bond_style command"); + } +} + +/* ---------------------------------------------------------------------- */ + void BondZero::allocate() { allocated = 1; int n = atom->nbondtypes; + memory->create(r0,n+1,"bond:r0"); memory->create(setflag,n+1,"bond:setflag"); for (int i = 1; i <= n; i++) setflag[i] = 0; } @@ -63,15 +80,22 @@ void BondZero::allocate() void BondZero::coeff(int narg, char **arg) { - if (narg != 1) error->all(FLERR,"Incorrect args for bond coefficients"); + if ((narg < 1) || (check_coeffs && narg > 2)) + error->all(FLERR,"Incorrect args for bond coefficients"); + if (!allocated) allocate(); int ilo,ihi; force->bounds(arg[0],atom->nbondtypes,ilo,ihi); + double r0_one = 0.0; + if (check_coeffs && (narg == 2)) + r0_one = force->numeric(FLERR,arg[1]); + int count = 0; for (int i = ilo; i <= ihi; i++) { setflag[i] = 1; + r0[i] = r0_one; count++; } @@ -84,14 +108,16 @@ void BondZero::coeff(int narg, char **arg) double BondZero::equilibrium_distance(int i) { - return 0.0; + return r0[i]; } /* ---------------------------------------------------------------------- proc 0 writes out coeffs to restart file ------------------------------------------------------------------------- */ -void BondZero::write_restart(FILE *fp) {} +void BondZero::write_restart(FILE *fp) { + fwrite(&r0[1],sizeof(double),atom->nbondtypes,fp); +} /* ---------------------------------------------------------------------- proc 0 reads coeffs from restart file, bcasts them @@ -100,9 +126,27 @@ void BondZero::write_restart(FILE *fp) {} void BondZero::read_restart(FILE *fp) { allocate(); + + if (comm->me == 0) { + fread(&r0[1],sizeof(double),atom->nbondtypes,fp); + } + MPI_Bcast(&r0[1],atom->nbondtypes,MPI_DOUBLE,0,world); + for (int i = 1; i <= atom->nbondtypes; i++) setflag[i] = 1; } +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void BondZero::write_data(FILE *fp) +{ + for (int i = 1; i <= atom->nbondtypes; i++) + fprintf(fp,"%d %g\n",i,r0[i]); +} + + + /* ---------------------------------------------------------------------- */ double BondZero::single(int type, double rsq, int i, int j, diff --git a/src/bond_zero.h b/src/bond_zero.h index b9c9a06d98..157262c27a 100644 --- a/src/bond_zero.h +++ b/src/bond_zero.h @@ -30,13 +30,20 @@ class BondZero : public Bond { BondZero(class LAMMPS *); virtual ~BondZero(); virtual void compute(int, int); + virtual void settings(int, char **); + void coeff(int, char **); double equilibrium_distance(int); void write_restart(FILE *); void read_restart(FILE *); + void write_data(FILE *); + double single(int, double, int, int, double &); protected: + double *r0; + int check_coeffs; + virtual void allocate(); }; diff --git a/src/dihedral_zero.cpp b/src/dihedral_zero.cpp index 3dc9508cf4..d0cea2cecc 100644 --- a/src/dihedral_zero.cpp +++ b/src/dihedral_zero.cpp @@ -15,12 +15,13 @@ Contributing author: Carsten Svaneborg (SDU) ------------------------------------------------------------------------- */ -#include #include #include +#include #include "dihedral_zero.h" #include "atom.h" #include "force.h" +#include "comm.h" #include "memory.h" #include "error.h" @@ -28,13 +29,13 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -DihedralZero::DihedralZero(LAMMPS *lmp) : Dihedral(lmp) {} +DihedralZero::DihedralZero(LAMMPS *lmp) : Dihedral(lmp), check_coeffs(1) {} /* ---------------------------------------------------------------------- */ DihedralZero::~DihedralZero() { - if (allocated) { + if (allocated && !copymode) { memory->destroy(setflag); } } @@ -49,6 +50,19 @@ void DihedralZero::compute(int eflag, int vflag) /* ---------------------------------------------------------------------- */ +void DihedralZero::settings(int narg, char **arg) +{ + if ((narg != 0) && (narg != 1)) + error->all(FLERR,"Illegal dihedral_style command"); + + if (narg == 1) { + if (strcmp("nocoeffs",arg[0]) == 0) check_coeffs=0; + else error->all(FLERR,"Illegal dihedral_style command"); + } +} + +/* ---------------------------------------------------------------------- */ + void DihedralZero::allocate() { allocated = 1; @@ -59,12 +73,14 @@ void DihedralZero::allocate() } /* ---------------------------------------------------------------------- - set coeffs for one type + set coeffs for one or more types ------------------------------------------------------------------------- */ void DihedralZero::coeff(int narg, char **arg) { - if (narg != 1) error->all(FLERR,"Incorrect args for dihedral coefficients"); + if ((narg < 1) || (check_coeffs && narg > 1)) + error->all(FLERR,"Incorrect args for dihedral coefficients"); + if (!allocated) allocate(); int ilo,ihi; @@ -95,3 +111,12 @@ void DihedralZero::read_restart(FILE *fp) for (int i = 1; i <= atom->ndihedraltypes; i++) setflag[i] = 1; } +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void DihedralZero::write_data(FILE *fp) { + for (int i = 1; i <= atom->ndihedraltypes; i++) + fprintf(fp,"%d\n",i); +} + diff --git a/src/dihedral_zero.h b/src/dihedral_zero.h index b075f84989..3fd9444536 100644 --- a/src/dihedral_zero.h +++ b/src/dihedral_zero.h @@ -24,7 +24,7 @@ DihedralStyle(zero,DihedralZero) #ifndef LMP_DIHEDRAL_ZERO_H #define LMP_DIHEDRAL_ZERO_H -#include "stdio.h" +#include #include "dihedral.h" namespace LAMMPS_NS { @@ -34,13 +34,17 @@ class DihedralZero : public Dihedral { DihedralZero(class LAMMPS *); virtual ~DihedralZero(); virtual void compute(int, int); - void coeff(int, char **); + virtual void coeff(int, char **); + virtual void settings(int, char **); + void write_restart(FILE *); void read_restart(FILE *); + void write_data(FILE *); protected: + int check_coeffs; - void allocate(); + virtual void allocate(); }; } diff --git a/src/improper_zero.cpp b/src/improper_zero.cpp index 438388e10a..ac07a87aef 100644 --- a/src/improper_zero.cpp +++ b/src/improper_zero.cpp @@ -15,12 +15,13 @@ Contributing author: Carsten Svaneborg (SDU) ------------------------------------------------------------------------- */ -#include #include #include +#include #include "improper_zero.h" #include "atom.h" #include "force.h" +#include "comm.h" #include "memory.h" #include "error.h" @@ -28,7 +29,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -ImproperZero::ImproperZero(LAMMPS *lmp) : Improper(lmp) {} +ImproperZero::ImproperZero(LAMMPS *lmp) : Improper(lmp), check_coeffs(1) {} /* ---------------------------------------------------------------------- */ @@ -49,6 +50,19 @@ void ImproperZero::compute(int eflag, int vflag) /* ---------------------------------------------------------------------- */ +void ImproperZero::settings(int narg, char **arg) +{ + if ((narg != 0) && (narg != 1)) + error->all(FLERR,"Illegal improper_style command"); + + if (narg == 1) { + if (strcmp("nocoeffs",arg[0]) == 0) check_coeffs=0; + else error->all(FLERR,"Illegal improper_style command"); + } +} + +/* ---------------------------------------------------------------------- */ + void ImproperZero::allocate() { allocated = 1; @@ -59,12 +73,14 @@ void ImproperZero::allocate() } /* ---------------------------------------------------------------------- - set coeffs for one type + set coeffs for one or more types ------------------------------------------------------------------------- */ void ImproperZero::coeff(int narg, char **arg) { - if (narg != 1) error->all(FLERR,"Incorrect args for improper coefficients"); + if ((narg < 1) || (check_coeffs && narg > 1)) + error->all(FLERR,"Incorrect args for improper coefficients"); + if (!allocated) allocate(); int ilo,ihi; @@ -94,3 +110,13 @@ void ImproperZero::read_restart(FILE *fp) allocate(); for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1; } + +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void ImproperZero::write_data(FILE *fp) { + for (int i = 1; i <= atom->nimpropertypes; i++) + fprintf(fp,"%d\n",i); +} + diff --git a/src/improper_zero.h b/src/improper_zero.h index 7283e858fb..f0eec1e01d 100644 --- a/src/improper_zero.h +++ b/src/improper_zero.h @@ -31,10 +31,15 @@ class ImproperZero : public Improper { virtual ~ImproperZero(); virtual void compute(int, int); virtual void coeff(int, char **); + virtual void settings(int, char **); + void write_restart(FILE *); void read_restart(FILE *); + void write_data(FILE *); protected: + int check_coeffs; + virtual void allocate(); }; @@ -45,11 +50,6 @@ class ImproperZero : public Improper { /* ERROR/WARNING messages: -W: Improper problem: %d %ld %d %d %d %d - -Conformation of the 4 listed improper atoms is extreme; you may want -to check your simulation geometry. - E: Incorrect args for improper coefficients Self-explanatory. Check the input script or data file. diff --git a/src/pair_zero.cpp b/src/pair_zero.cpp index c3af3f0efe..67f4a15ae3 100644 --- a/src/pair_zero.cpp +++ b/src/pair_zero.cpp @@ -30,7 +30,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -PairZero::PairZero(LAMMPS *lmp) : Pair(lmp) {} +PairZero::PairZero(LAMMPS *lmp) : Pair(lmp), check_coeffs(1) {} /* ---------------------------------------------------------------------- */ @@ -77,13 +77,17 @@ void PairZero::allocate() void PairZero::settings(int narg, char **arg) { - if (narg != 1) error->all(FLERR,"Illegal pair_style command"); + if ((narg != 1) && (narg != 2)) + error->all(FLERR,"Illegal pair_style command"); cut_global = force->numeric(FLERR,arg[0]); + if (narg == 2) { + if (strcmp("nocoeffs",arg[1]) == 0) check_coeffs=0; + else error->all(FLERR,"Illegal pair_style command"); + } // reset cutoffs that have been explicitly set - allocate(); int i,j; for (i = 1; i <= atom->ntypes; i++) for (j = i+1; j <= atom->ntypes; j++) @@ -96,8 +100,9 @@ void PairZero::settings(int narg, char **arg) void PairZero::coeff(int narg, char **arg) { - if (narg < 2 || narg > 3) + if ((narg < 2) || (check_coeffs && narg > 3)) error->all(FLERR,"Incorrect args for pair coefficients"); + if (!allocated) allocate(); int ilo,ihi,jlo,jhi; @@ -105,7 +110,7 @@ void PairZero::coeff(int narg, char **arg) force->bounds(arg[1],atom->ntypes,jlo,jhi); double cut_one = cut_global; - if (narg == 3) cut_one = force->numeric(FLERR,arg[2]); + if (check_coeffs && (narg == 3)) cut_one = force->numeric(FLERR,arg[2]); int count = 0; for (int i = ilo; i <= ihi; i++) { @@ -180,6 +185,7 @@ void PairZero::read_restart(FILE *fp) void PairZero::write_restart_settings(FILE *fp) { fwrite(&cut_global,sizeof(double),1,fp); + fwrite(&check_coeffs,sizeof(int),1,fp); } /* ---------------------------------------------------------------------- @@ -191,7 +197,9 @@ void PairZero::read_restart_settings(FILE *fp) int me = comm->me; if (me == 0) { fread(&cut_global,sizeof(double),1,fp); + fread(&check_coeffs,sizeof(int),1,fp); } MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world); + MPI_Bcast(&check_coeffs,1,MPI_INT,0,world); } diff --git a/src/pair_zero.h b/src/pair_zero.h index e6cfb32579..962a059458 100644 --- a/src/pair_zero.h +++ b/src/pair_zero.h @@ -50,6 +50,7 @@ class PairZero : public Pair { protected: double cut_global; double **cut; + int check_coeffs; virtual void allocate(); };