diff --git a/src/GRANULAR/fix_pour.cpp b/src/GRANULAR/fix_pour.cpp index 4dc0c5cbef..55411a735d 100644 --- a/src/GRANULAR/fix_pour.cpp +++ b/src/GRANULAR/fix_pour.cpp @@ -832,7 +832,10 @@ void FixPour::options(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); int imol = atom->find_molecule(arg[iarg+1]); if (imol == -1) - error->all(FLERR,"Molecule ID for fix pour does not exist"); + error->all(FLERR,"Molecule template ID for fix pour does not exist"); + if (atom->molecules[imol]->nset > 1 && comm->me == 0) + error->warning(FLERR,"Molecule template for " + "fix pour has multiple molecules"); mode = MOLECULE; onemol = atom->molecules[imol]; iarg += 2; diff --git a/src/MISC/fix_deposit.cpp b/src/MISC/fix_deposit.cpp index f83af6d7d6..f1f16a424f 100644 --- a/src/MISC/fix_deposit.cpp +++ b/src/MISC/fix_deposit.cpp @@ -577,10 +577,13 @@ void FixDeposit::options(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal fix deposit command"); int imol = atom->find_molecule(arg[iarg+1]); if (imol == -1) - error->all(FLERR,"Molecule ID for fix deposit does not exist"); + error->all(FLERR,"Molecule template ID for fix deposit does not exist"); + if (atom->molecules[imol]->nset > 1 && comm->me == 0) + error->warning(FLERR,"Molecule template for " + "fix deposit has multiple molecules"); mode = MOLECULE; onemol = atom->molecules[imol]; - iarg += 2; + iarg += 2; } else if (strcmp(arg[iarg],"rigid") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix deposit command"); int n = strlen(arg[iarg+1]) + 1; diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index 78ef0ed0f2..4d411db49a 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -152,7 +152,11 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal fix rigid/small command"); int imol = atom->find_molecule(arg[iarg+1]); if (imol == -1) - error->all(FLERR,"Molecule ID for fix rigid/small does not exist"); + error->all(FLERR,"Molecule template ID for " + "fix rigid/small does not exist"); + if (atom->molecules[imol]->nset > 1 && comm->me == 0) + error->warning(FLERR,"Molecule template for " + "fix rigid/small has multiple molecules"); onemol = atom->molecules[imol]; iarg += 2; } else error->all(FLERR,"Illegal fix rigid/small command"); diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index 7024f0281b..fa8ae3b496 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -155,7 +155,10 @@ FixShake::FixShake(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal fix shake command"); int imol = atom->find_molecule(arg[iarg+1]); if (imol == -1) - error->all(FLERR,"Molecule ID for fix shake does not exist"); + error->all(FLERR,"Molecule template ID for fix shake does not exist"); + if (atom->molecules[imol]->nset > 1 && comm->me == 0) + error->warning(FLERR,"Molecule template for " + "fix shake has multiple molecules"); onemol = atom->molecules[imol]; iarg += 2; } else error->all(FLERR,"Illegal fix shake command"); @@ -164,7 +167,7 @@ FixShake::FixShake(LAMMPS *lmp, int narg, char **arg) : // error check for Molecule template if (onemol && onemol->shakeflag == 0) - error->all(FLERR,"Fix shake molecule must have shake info"); + error->all(FLERR,"Fix shake molecule template must have shake info"); // allocate bond and angle distance arrays, indexed from 1 to n diff --git a/src/atom.cpp b/src/atom.cpp index aba59b819a..f25a8af453 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -42,7 +42,6 @@ using namespace LAMMPS_NS; using namespace MathConst; #define DELTA 1 -#define DELTA_MOLECULE 1 #define DELTA_MEMSTR 1024 #define EPSILON 1.0e-6 #define CUDA_CHUNK 3000 @@ -117,7 +116,7 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) // user-defined molecules - nmolecule = maxmol = 0; + nmolecule = 0; molecules = NULL; // custom atom arrays @@ -1293,27 +1292,30 @@ int Atom::shape_consistency(int itype, } /* ---------------------------------------------------------------------- - add a new molecule template + add a new molecule template = set of molecules ------------------------------------------------------------------------- */ void Atom::add_molecule(int narg, char **arg) { - if (narg < 1) error->all(FLERR,"Illegal molecule command"); - if (find_molecule(arg[0]) >= 0) error->all(FLERR,"Reuse of molecule ID"); + if (narg < 2) error->all(FLERR,"Illegal molecule command"); + if (find_molecule(arg[0]) >= 0) + error->all(FLERR,"Reuse of molecule template ID"); - // extend molecule list if necessary + int nprevious = nmolecule; + nmolecule += narg-1; + molecules = (Molecule **) + memory->srealloc(molecules,nmolecule*sizeof(Molecule *),"atom::molecules"); - if (nmolecule == maxmol) { - maxmol += DELTA_MOLECULE; - molecules = (Molecule **) - memory->srealloc(molecules,maxmol*sizeof(Molecule *),"atom::molecules"); + for (int i = 1; i < narg; i++) { + molecules[nprevious] = new Molecule(lmp,arg[0],arg[i]); + if (i == 1) molecules[nprevious]->nset = narg-1; + else molecules[nprevious]->nset = 0; + nprevious++; } - - molecules[nmolecule++] = new Molecule(lmp,narg,arg); } /* ---------------------------------------------------------------------- - find which molecule has molecule ID + find first molecule in set with template ID return -1 if does not exist ------------------------------------------------------------------------- */ @@ -1328,6 +1330,7 @@ int Atom::find_molecule(char *id) /* ---------------------------------------------------------------------- add info to current atom ilocal from molecule template onemol and its iatom offset = atom ID preceeding IDs of atoms in this molecule + called by fixes and commands that add molecules ------------------------------------------------------------------------- */ void Atom::add_molecule_atom(Molecule *onemol, int iatom, diff --git a/src/atom.h b/src/atom.h index c552cad6c2..d4c07f81fb 100644 --- a/src/atom.h +++ b/src/atom.h @@ -113,9 +113,12 @@ class Atom : protected Pointers { int cs_flag,csforce_flag,vforce_flag,ervelforce_flag,etag_flag; int rho_flag,e_flag,cv_flag,vest_flag; - // molecules + // molecule templates + // each template can be a set of consecutive molecules + // each with same ID (stored in molecules) + // 1st molecule in template stores nset = # in set - int nmolecule,maxmol; + int nmolecule; class Molecule **molecules; // extra peratom info in restart file destined for fix & diag diff --git a/src/create_atoms.cpp b/src/create_atoms.cpp index 40c7fe4ec4..0f6fbe6d56 100644 --- a/src/create_atoms.cpp +++ b/src/create_atoms.cpp @@ -124,8 +124,11 @@ void CreateAtoms::command(int narg, char **arg) } else if (strcmp(arg[iarg],"mol") == 0) { if (iarg+3 > narg) error->all(FLERR,"Illegal create_atoms command"); int imol = atom->find_molecule(arg[iarg+1]); - if (imol == -1) - error->all(FLERR,"Molecule ID for create_atoms does not exist"); + if (imol == -1) error->all(FLERR,"Molecule template ID for " + "create_atoms does not exist"); + if (atom->molecules[imol]->nset > 1 && comm->me == 0) + error->warning(FLERR,"Molecule template for " + "create_atoms has multiple molecules"); mode = MOLECULE; onemol = atom->molecules[imol]; molseed = force->inumeric(FLERR,arg[iarg+2]); diff --git a/src/molecule.cpp b/src/molecule.cpp index 389a9cf797..27a4a1237d 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -33,22 +33,18 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ -Molecule::Molecule(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) +Molecule::Molecule(LAMMPS *lmp, char *idarg, char *file) : Pointers(lmp) { me = comm->me; - if (narg != 2) error->all(FLERR,"Illegal molecule command"); - - int n = strlen(arg[0]) + 1; + int n = strlen(idarg) + 1; id = new char[n]; - strcpy(id,arg[0]); + strcpy(id,idarg); for (int i = 0; i < n-1; i++) if (!isalnum(id[i]) && id[i] != '_') - error->all(FLERR, - "Molecule ID must be alphanumeric or underscore characters"); - - char *file = arg[1]; + error->all(FLERR,"Molecule template ID must be " + "alphanumeric or underscore characters"); // initialize all fields to empty diff --git a/src/molecule.h b/src/molecule.h index 7b35f77d1f..d5b406f54a 100644 --- a/src/molecule.h +++ b/src/molecule.h @@ -20,7 +20,9 @@ namespace LAMMPS_NS { class Molecule : protected Pointers { public: - char *id; + char *id; // template id of this molecule, same for all molecules in set + int nset; // if first in set, # of molecules in this set + // else 0 if not first in set // number of atoms,bonds,etc in molecule @@ -97,7 +99,7 @@ class Molecule : protected Pointers { double **dxbody; // displacement of each atom relative to COM // in body frame (diagonalized interia tensor) - Molecule(class LAMMPS *, int, char **); + Molecule(class LAMMPS *, char *, char *); ~Molecule(); void compute_center(); void compute_mass();