~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to src/group.cpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "domain.h"
21
21
#include "atom.h"
22
22
#include "force.h"
 
23
#include "comm.h"
23
24
#include "region.h"
24
25
#include "modify.h"
25
26
#include "fix.h"
31
32
#include "memory.h"
32
33
#include "error.h"
33
34
 
 
35
#include <map>
 
36
 
34
37
using namespace LAMMPS_NS;
35
38
 
36
39
#define MAX_GROUP 32
40
43
 
41
44
#define BIG 1.0e20
42
45
 
 
46
// allocate space for static class variable
 
47
 
 
48
Group *Group::cptr;
 
49
 
43
50
/* ----------------------------------------------------------------------
44
51
   initialize group memory
45
52
------------------------------------------------------------------------- */
133
140
    return;
134
141
  }
135
142
 
 
143
  // clear the group
 
144
 
 
145
  if (strcmp(arg[1],"clear") == 0) {
 
146
    int igroup = find(arg[0]);
 
147
    if (igroup == -1) error->all (FLERR,"Could not find group clear group ID");
 
148
    if (igroup == 0) error->all (FLERR,"Cannot clear group all");
 
149
 
 
150
    int *mask = atom->mask;
 
151
    int nlocal = atom->nlocal;
 
152
    int bits = inversemask[igroup];
 
153
    for (i = 0; i < nlocal; i++) mask[i] &= bits;
 
154
 
 
155
    return;
 
156
  }
 
157
 
136
158
  // find group in existing list
137
159
  // add a new group if igroup = -1
138
160
 
186
208
    if (narg > 3 &&
187
209
        (strcmp(arg[2],"<") == 0 || strcmp(arg[2],">") == 0 ||
188
210
         strcmp(arg[2],"<=") == 0 || strcmp(arg[2],">=") == 0 ||
 
211
         strcmp(arg[2],"==") == 0 || strcmp(arg[2],"!=") == 0 ||
189
212
         strcmp(arg[2],"<>") == 0)) {
190
213
 
191
214
      int condition = -1;
329
352
 
330
353
    memory->destroy(aflag);
331
354
 
 
355
  // style = include
 
356
 
 
357
  } else if (strcmp(arg[1],"include") == 0) {
 
358
 
 
359
    if (narg != 3) error->all(FLERR,"Illegal group command");
 
360
    if (strcmp(arg[2],"molecule") != 0) 
 
361
      error->all(FLERR,"Illegal group command");
 
362
 
 
363
    add_molecules(igroup,bit);
 
364
 
332
365
  // style = subtract
333
366
 
334
367
  } else if (strcmp(arg[1],"subtract") == 0) {
567
600
}
568
601
 
569
602
/* ----------------------------------------------------------------------
 
603
   add atoms to group that are in same molecules as atoms already in group
 
604
   do not include molID = 0
 
605
------------------------------------------------------------------------- */
 
606
 
 
607
void Group::add_molecules(int igroup, int bit)
 
608
{
 
609
  // hash = unique molecule IDs of atoms already in group
 
610
 
 
611
  hash = new std::map<tagint,int>();
 
612
 
 
613
  tagint *molecule = atom->molecule;
 
614
  int *mask = atom->mask;
 
615
  int nlocal = atom->nlocal;
 
616
 
 
617
  for (int i = 0; i < nlocal; i++)
 
618
    if (mask[i] & bit) {
 
619
      if (molecule[i] == 0) continue;
 
620
      if (hash->find(molecule[i]) == hash->end()) (*hash)[molecule[i]] = 1;
 
621
    }
 
622
 
 
623
  // list = set of unique molecule IDs for atoms to add
 
624
  // pass list to all other procs via comm->ring()
 
625
 
 
626
  int n = hash->size();
 
627
  tagint *list;
 
628
  memory->create(list,n,"group:list");
 
629
 
 
630
  n = 0;
 
631
  std::map<tagint,int>::iterator pos;
 
632
  for (pos = hash->begin(); pos != hash->end(); ++pos) list[n++] = pos->first;
 
633
 
 
634
  cptr = this;
 
635
  molbit = bit;
 
636
  comm->ring(n,sizeof(tagint),list,1,molring,NULL);
 
637
 
 
638
  delete hash;
 
639
  memory->destroy(list);
 
640
}
 
641
 
 
642
/* ----------------------------------------------------------------------
 
643
   callback from comm->ring()
 
644
   cbuf = list of N molecule IDs, put them in hash
 
645
   loop over my atoms, if matches molecule ID in hash,
 
646
     add atom to group flagged by molbit
 
647
------------------------------------------------------------------------- */
 
648
 
 
649
void Group::molring(int n, char *cbuf)
 
650
{
 
651
  tagint *list = (tagint *) cbuf;
 
652
  std::map<tagint,int> *hash = cptr->hash;
 
653
  int nlocal = cptr->atom->nlocal;
 
654
  tagint *molecule = cptr->atom->molecule;
 
655
  int *mask = cptr->atom->mask;
 
656
  int molbit = cptr->molbit;
 
657
 
 
658
  hash->clear();
 
659
  for (int i = 0; i < n; i++) (*hash)[list[i]] = 1;
 
660
 
 
661
  for (int i = 0; i < nlocal; i++)
 
662
    if (hash->find(molecule[i]) != hash->end()) mask[i] |= molbit;
 
663
}
 
664
 
 
665
/* ----------------------------------------------------------------------
570
666
   write group info to a restart file
571
667
   only called by proc 0
572
668
------------------------------------------------------------------------- */