From f6fe554b475ef51e2ec88feabad07b7fc9cd7010 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Fri, 29 Jan 2021 22:38:33 -0500 Subject: [PATCH] basic support for auxiliary label maps can be created with labelmap via mapID keyword referenced like mymapID::C where C is an atom type, for example --- src/atom.cpp | 30 ++++++++++++++++++++++++++---- src/atom.h | 3 ++- src/input.cpp | 18 +++++++++++++++++- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 5d3b960731..d80984bd1a 100755 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -204,6 +204,7 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) // type labels + nlmap = 0; lmaps = nullptr; // custom atom arrays @@ -1990,7 +1991,7 @@ void Atom::add_molecule_atom(Molecule *onemol, int iatom, allocate space for type label map ------------------------------------------------------------------------- */ -void Atom::add_label_map(std::string mapID) +int Atom::add_label_map(std::string mapID) { labelmapflag = 1; lmaps = (LabelMap **) @@ -2005,6 +2006,7 @@ void Atom::add_label_map(std::string mapID) lmaps[nlmap]->nimpropertypes = nimpropertypes; lmaps[nlmap]->allocate_type_labels(); nlmap++; + return nlmap - 1; } /* ---------------------------------------------------------------------- @@ -2014,13 +2016,33 @@ void Atom::add_label_map(std::string mapID) int Atom::find_label(std::string label, int mode) { - // find label map ... in progress - int ilmap; - ilmap = 0; + int ilmap = 0; + + // check for auxiliary map prefix + + int pos = label.find("::"); + if (pos != std::string::npos) { + ilmap = find_labelmap(label.substr(0,pos)); + if (ilmap == -1) return -1; + label = label.substr(pos+2); + } return lmaps[ilmap]->find(label,mode); } +/* ---------------------------------------------------------------------- + find first label map in set with ID + return -1 if does not exist +------------------------------------------------------------------------- */ + +int Atom::find_labelmap(std::string id) +{ + int ilmap; + for (ilmap = 0; ilmap < nlmap; ilmap++) + if (id == lmaps[ilmap]->id) return ilmap; + return -1; +} + /* ---------------------------------------------------------------------- reorder owned atoms so those in firstgroup appear first called by comm->exchange() if atom_modify first group is set diff --git a/src/atom.h b/src/atom.h index 4eb62bdfe4..e65b755a3c 100755 --- a/src/atom.h +++ b/src/atom.h @@ -329,8 +329,9 @@ class Atom : protected Pointers { int find_molecule(char *); void add_molecule_atom(class Molecule *, int, int, tagint); - void add_label_map(std::string mapID = ""); + int add_label_map(std::string mapID = ""); int find_label(std::string, int); + int find_labelmap(std::string); void first_reorder(); virtual void sort(); diff --git a/src/input.cpp b/src/input.cpp index e51643fbfa..f80f7d9415 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -1592,10 +1592,26 @@ void Input::kspace_style() void Input::labelmap() { + if (narg < 2 || (narg % 2 == 0)) error->all(FLERR,"Illegal labelmap command"); if (domain->box_exist == 0) error->all(FLERR,"Labelmap command before simulation box is defined"); + if (!atom->labelmapflag) atom->add_label_map(); - atom->lmaps[0]->modify_lmap(narg,arg); + + int ilmap = 0; + std::string mapid; + for (int i = 1; i < narg; i++) { + if (strcmp(arg[i],"mapID") == 0) { + mapid = arg[i+1]; + ilmap = atom->find_labelmap(mapid); + if (ilmap == -1) ilmap = atom->add_label_map(mapid); + if (narg > i+2) error->all(FLERR,"Illegal labelmap command"); + narg = i - 2; + break; + } + i++; + } + atom->lmaps[ilmap]->modify_lmap(narg,arg); } /* ---------------------------------------------------------------------- */