From 95d6f05a764ef646e733818301f0fd8c0d1e08bb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 5 Jun 2017 12:41:37 -0400 Subject: [PATCH] add 3 APIs to Modify for checking if atoms overlap with any rigid fixes --- src/modify.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/modify.h | 3 ++ 2 files changed, 95 insertions(+) diff --git a/src/modify.cpp b/src/modify.cpp index 7af4576038..4422ee6890 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -23,6 +23,7 @@ #include "group.h" #include "update.h" #include "domain.h" +#include "region.h" #include "input.h" #include "variable.h" #include "memory.h" @@ -995,6 +996,97 @@ int Modify::check_package(const char *package_fix_name) return 1; } + +/* ---------------------------------------------------------------------- + check if the group indicated by groupbit overlaps with any + currently existing rigid fixes. return 1 in this case otherwise 0 +------------------------------------------------------------------------- */ + +int Modify::check_rigid_group_overlap(int groupbit) +{ + const int * const mask = atom->mask; + const int nlocal = atom->nlocal; + + int n = 0; + for (int ifix = 0; ifix < nfix; ifix++) { + if (strncmp("rigid",fix[ifix]->style,5) == 0) { + const int bothbits = groupbit | fix[ifix]->groupbit; + for (int i=0; i < nlocal; ++i) + if (mask[i] & bothbits) {++n; break;} + if (n > 0) break; + } + } + + int n_all = 0; + MPI_Allreduce(&n,&n_all,1,MPI_INT,MPI_SUM,world); + + if (n_all > 0) return 1; + return 0; +} + +/* ---------------------------------------------------------------------- + check if the atoms in the region indicated by regionid overlap with any + currently existing rigid fixes. return 1 in this case otherwise 0 +------------------------------------------------------------------------- */ + +int Modify::check_rigid_region_overlap(Region *reg) +{ + const int * const mask = atom->mask; + const double * const * const x = atom->x; + const int nlocal = atom->nlocal; + + int n = 0; + reg->prematch(); + for (int ifix = 0; ifix < nfix; ifix++) { + if (strncmp("rigid",fix[ifix]->style,5) == 0) { + const int groupbit = fix[ifix]->groupbit; + for (int i=0; i < nlocal; ++i) + if ((mask[i] & groupbit) && reg->match(x[i][0],x[i][1],x[i][2])) { + ++n; + break; + } + if (n > 0) break; + } + } + + int n_all = 0; + MPI_Allreduce(&n,&n_all,1,MPI_INT,MPI_SUM,world); + + if (n_all > 0) return 1; + return 0; +} + +/* ---------------------------------------------------------------------- + check if the atoms in the selection list (length atom->nlocal, + content: 1 if atom is contained, 0 if not) overlap with currently + existing rigid fixes. return 1 in this case otherwise 0 +------------------------------------------------------------------------- */ + +int Modify::check_rigid_list_overlap(int *select) +{ + const int * const mask = atom->mask; + const int nlocal = atom->nlocal; + + int n = 0; + for (int ifix = 0; ifix < nfix; ifix++) { + if (strncmp("rigid",fix[ifix]->style,5) == 0) { + const int groupbit = fix[ifix]->groupbit; + for (int i=0; i < nlocal; ++i) + if ((mask[i] & groupbit) && select[i]) { + ++n; + break; + } + if (n > 0) break; + } + } + + int n_all = 0; + MPI_Allreduce(&n,&n_all,1,MPI_INT,MPI_SUM,world); + + if (n_all > 0) return 1; + return 0; +} + /* ---------------------------------------------------------------------- add a new compute ------------------------------------------------------------------------- */ diff --git a/src/modify.h b/src/modify.h index 3ded3cbab6..2ad244f8fb 100644 --- a/src/modify.h +++ b/src/modify.h @@ -98,6 +98,9 @@ class Modify : protected Pointers { int find_fix(const char *); int find_fix_by_style(const char *); int check_package(const char *); + int check_rigid_group_overlap(int); + int check_rigid_region_overlap(class Region *); + int check_rigid_list_overlap(int *); void add_compute(int, char **, int trysuffix=1); void modify_compute(int, char **);