diff --git a/src/region_intersect.cpp b/src/region_intersect.cpp index 1da6d63be7..c89ee91574 100644 --- a/src/region_intersect.cpp +++ b/src/region_intersect.cpp @@ -31,13 +31,18 @@ RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) : options(narg-(n+3),&arg[n+3]); // build list of regions to intersect + // store sub-region IDs in idsub + idsub = new char*[n]; list = new int[n]; nregion = 0; int iregion; for (int iarg = 0; iarg < n; iarg++) { - iregion = domain->find_region(arg[iarg+3]); + n = strlen(arg[iarg+3]) + 1; + idsub[nregion] = new char[n]; + strcpy(idsub[nregion],arg[iarg+3]); + iregion = domain->find_region(idsub[nregion]); if (iregion == -1) error->all(FLERR,"Region intersect region ID does not exist"); list[nregion++] = iregion; @@ -92,6 +97,8 @@ RegIntersect::RegIntersect(LAMMPS *lmp, int narg, char **arg) : RegIntersect::~RegIntersect() { + for (int ilist = 0; ilist < nregion; ilist++) delete [] idsub[ilist]; + delete [] idsub; delete [] list; delete [] contact; } @@ -101,6 +108,20 @@ RegIntersect::~RegIntersect() void RegIntersect::init() { Region::init(); + + // re-build list of sub-regions in case other regions were deleted + // error if a sub-region was deleted + + int iregion; + for (int ilist = 0; ilist < nregion; ilist++) { + iregion = domain->find_region(idsub[ilist]); + if (iregion == -1) + error->all(FLERR,"Region union region ID does not exist"); + list[ilist] = iregion; + } + + // init the sub-regions + Region **regions = domain->regions; for (int ilist = 0; ilist < nregion; ilist++) regions[list[ilist]]->init(); diff --git a/src/region_intersect.h b/src/region_intersect.h index 62946a65c0..52d3e208de 100644 --- a/src/region_intersect.h +++ b/src/region_intersect.h @@ -38,6 +38,7 @@ class RegIntersect : public Region { private: int nregion; int *list; + char **idsub; }; } diff --git a/src/region_union.cpp b/src/region_union.cpp index e9fc4ef680..83a550b5bd 100644 --- a/src/region_union.cpp +++ b/src/region_union.cpp @@ -31,14 +31,19 @@ RegUnion::RegUnion(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg) if (n < 2) error->all(FLERR,"Illegal region command"); options(narg-(n+3),&arg[n+3]); - // build list of regions to union + // build list of region indices to union + // store sub-region IDs in idsub + idsub = new char*[n]; list = new int[n]; nregion = 0; int iregion; for (int iarg = 0; iarg < n; iarg++) { - iregion = domain->find_region(arg[iarg+3]); + n = strlen(arg[iarg+3]) + 1; + idsub[nregion] = new char[n]; + strcpy(idsub[nregion],arg[iarg+3]); + iregion = domain->find_region(idsub[nregion]); if (iregion == -1) error->all(FLERR,"Region union region ID does not exist"); list[nregion++] = iregion; @@ -84,6 +89,8 @@ RegUnion::RegUnion(LAMMPS *lmp, int narg, char **arg) : Region(lmp, narg, arg) RegUnion::~RegUnion() { + for (int ilist = 0; ilist < nregion; ilist++) delete [] idsub[ilist]; + delete [] idsub; delete [] list; delete [] contact; } @@ -93,6 +100,20 @@ RegUnion::~RegUnion() void RegUnion::init() { Region::init(); + + // re-build list of sub-regions in case other regions were deleted + // error if a sub-region was deleted + + int iregion; + for (int ilist = 0; ilist < nregion; ilist++) { + iregion = domain->find_region(idsub[ilist]); + if (iregion == -1) + error->all(FLERR,"Region union region ID does not exist"); + list[ilist] = iregion; + } + + // init the sub-regions + Region **regions = domain->regions; for (int ilist = 0; ilist < nregion; ilist++) regions[list[ilist]]->init(); diff --git a/src/region_union.h b/src/region_union.h index 6d0ec063cf..664d9f3394 100644 --- a/src/region_union.h +++ b/src/region_union.h @@ -38,6 +38,7 @@ class RegUnion : public Region { private: int nregion; int *list; + char **idsub; }; }