From b33974cd198365c08e34395122f1c484ed133126 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 14 Jul 2020 12:44:50 -0400 Subject: [PATCH] add code to check for duplicate atom IDs in Bodies section --- src/atom.cpp | 11 +++++++++++ src/atom.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/atom.cpp b/src/atom.cpp index a0e9791e21..0ebb7c73a9 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -217,6 +217,8 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) map_bucket = NULL; map_hash = NULL; + unique_tags = nullptr; + atom_style = NULL; avec = NULL; @@ -295,6 +297,8 @@ Atom::~Atom() // delete mapping data structures map_delete(); + + delete unique_tags; } /* ---------------------------------------------------------------------- @@ -1554,6 +1558,8 @@ void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset) int *ivalues = NULL; double *dvalues = NULL; + if (!unique_tags) unique_tags = new std::set; + // loop over lines of body data // if I own atom tag, tokenize lines into ivalues/dvalues, call data_body() // else skip values @@ -1565,6 +1571,11 @@ void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset) if (tagdata <= 0 || tagdata > map_tag_max) error->one(FLERR,"Invalid atom ID in Bodies section of data file"); + if (unique_tags->find(tagdata) == unique_tags->end()) + unique_tags->insert(tagdata); + else + error->one(FLERR,"Duplicate atom ID in Bodies section of data file"); + ninteger = force->inumeric(FLERR,strtok(NULL," \t\n\r\f")); ndouble = force->inumeric(FLERR,strtok(NULL," \t\n\r\f")); diff --git a/src/atom.h b/src/atom.h index 0b0bbfc8ad..4dac15d758 100644 --- a/src/atom.h +++ b/src/atom.h @@ -16,6 +16,7 @@ #include "pointers.h" #include +#include #include namespace LAMMPS_NS { @@ -241,6 +242,7 @@ class Atom : protected Pointers { int map_user; // user requested map style: // 0 = no request, 1=array, 2=hash, 3=yes tagint map_tag_max; // max atom ID that map() is setup for + std::set *unique_tags; // set to ensure that bodies have unique tags // spatial sorting of atoms