Skip to content

Commit

Permalink
add function to assign unique molecule IDs to atoms
Browse files Browse the repository at this point in the history
atoms are supposed to get a unique dummy molecule ID <= 0 upon creation;
this dummy molecule ID is replaced by a real unique molecul ID > 0
similar to atom tags;
  • Loading branch information
danielque committed Mar 16, 2018
1 parent 512e0ad commit fb73586
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/atom.cpp
Expand Up @@ -47,6 +47,8 @@
#include "memory.h"
#include "error.h"
#include <vector>
#include <set>
#include <map>
#include <algorithm>

// defining NDEBUG disables assertions
Expand Down Expand Up @@ -570,6 +572,36 @@ void Atom::modify_params(int narg, char **arg)
}
}

/* ----------------------------------------------------------------------
add unique mol ids to any atoms with mol <= 0
new mol ids are grouped by proc and start after max current mol id
called after creating new bonded atoms
------------------------------------------------------------------------- */

void Atom::mol_extend()
{
int maxmol = 0;
for (int i = 0; i < nlocal; ++i) maxmol = MAX(maxmol,molecule[i]);
int maxmol_all;
MPI_Allreduce(&maxmol,&maxmol_all,1,MPI_INT,MPI_MAX,world);

// nomol = # of molecules I own with no mol id (molecule <= 0)
// nomol_sum = # of total molecules on procs <= me with no mol id

std::set<int> uniquemol;
for (int i = 0; i < nlocal; i++) if (molecule[i] <= 0) uniquemol.insert(molecule[i]);
int nomol = uniquemol.size();
int nomol_sum;
MPI_Scan(&nomol,&nomol_sum,1,MPI_INT,MPI_SUM,world);

// imol = 1st new mol id that my untagged molecules should use

int imol = maxmol_all + nomol_sum - nomol + 1;
std::map<int, int> dummy2mol;
for (std::set<int>::iterator it=uniquemol.begin(); it!=uniquemol.end(); ++it) dummy2mol[*it] = imol++;
for (int i = 0; i < nlocal; ++i) if (molecule[i] <= 0) molecule[i] = dummy2mol[molecule[i]];
}

/* ----------------------------------------------------------------------
add unique tags to any atoms with tag = 0
new tags are grouped by proc and start after max current tag
Expand Down
1 change: 1 addition & 0 deletions src/atom.h
Expand Up @@ -164,6 +164,7 @@ class Atom : protected Pointers {
void tag_extend();
int tag_consecutive();
int tag_max(); //NP modified C.K.
void mol_extend();

int parse_data(const char *);
int count_words(const char *);
Expand Down

0 comments on commit fb73586

Please sign in to comment.