From 0075440796cac2f41735b74bd4aae086ab88f551 Mon Sep 17 00:00:00 2001
From: Volker Springel <vspringel@mpa-garching.mpg.de>
Date: Thu, 25 Mar 2021 17:43:41 +0100
Subject: [PATCH] resurrected the RANDOMIZE_DOMAINCENTER_TYPES to allow this
 feature for zooms run without PLACEHIGHRESREGION

---
 Template-Config.sh                 |  1 +
 documentation/04_config-options.md | 12 ++++++++++++
 src/data/constants.h               |  4 ++++
 src/data/simparticles.h            |  3 +++
 src/domain/domain.h                |  2 +-
 src/domain/domain_box.cc           | 20 ++++++++++----------
 6 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/Template-Config.sh b/Template-Config.sh
index 8091e3c..49e155b 100644
--- a/Template-Config.sh
+++ b/Template-Config.sh
@@ -10,6 +10,7 @@
 #PERIODIC                                     # enables periodic boundary condistions
 #NTYPES=6                                     # number of particle types 
 #RANDOMIZE_DOMAINCENTER                       # shifts the particle distribution randomly each step to reduce correlations of force errors in time
+#RANDOMIZE_DOMAINCENTER_TYPES                 # can be used to set a zoom region via a particle type which is then never placed across large node boundaries
 #LEAN                                         # selects a special 'lean' mode of code operation, which is optimized for aggressive memory saving
 #LONG_X_BITS=2                                # can be used to reduce periodic box-dimension in x-direction relative to nominal box size
 #LONG_Y_BITS=2                                # can be used to reduce periodic box-dimension in y-direction relative to nominal box size
diff --git a/documentation/04_config-options.md b/documentation/04_config-options.md
index cf80f93..0c9bd76 100644
--- a/documentation/04_config-options.md
+++ b/documentation/04_config-options.md
@@ -324,6 +324,18 @@ recommended, and should have only positive effects.
 
 -------
 
+**RANDOMIZE_DOMAINCENTER_TYPES** = 2
+
+Can be set to select one or several types (this is a bitmask) which
+will then be used to locate the extension of a certain region. When
+the particle set is randomly translated throughout the box, the code
+will then try to avoid intersecting large oct-tree node boundaries
+with this region. When this option is not set explicitely but
+PLACEHIGHRESREGION is active, then this is automatically done
+with a default setting RANDOMIZE_DOMAINCENTER_TYPES=PLACEHIGHRESREGION.
+
+-------
+
 **EVALPOTENTIAL**
 
 When this is activated, the code also computes the gravitational
diff --git a/src/data/constants.h b/src/data/constants.h
index 2fc5303..7aa40b3 100644
--- a/src/data/constants.h
+++ b/src/data/constants.h
@@ -147,6 +147,10 @@
 #define HRPMGRID PMGRID
 #endif
 
+#if !defined(RANDOMIZE_DOMAINCENTER_TYPES) && defined(PLACEHIGHRESREGION)
+#define RANDOMIZE_DOMAINCENTER_TYPES PLACEHIGHRESREGION
+#endif
+
 #if defined(SUBFIND) && !defined(SELFGRAVITY)
 #error "Running SUBFIND without SELFGRAVITY enabled does not make sense."
 #endif
diff --git a/src/data/simparticles.h b/src/data/simparticles.h
index 6b4f227..5fcf554 100644
--- a/src/data/simparticles.h
+++ b/src/data/simparticles.h
@@ -153,6 +153,9 @@ class simparticles : public intposconvert, public setcomm
   MyIntPosType Left[2][3];
   MyIntPosType OldMeshSize[2];
   MyIntPosType ReferenceIntPos[2][3];
+#endif
+
+#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(PLACEHIGHRESREGION)
   MyIntPosType PlacingMask;
   MyIntPosType PlacingBlocksize;
 #endif
diff --git a/src/domain/domain.h b/src/domain/domain.h
index 58d4204..1ac2308 100644
--- a/src/domain/domain.h
+++ b/src/domain/domain.h
@@ -255,7 +255,7 @@ class domain : public setcomm
     return a.targetindex < b.targetindex;
   }
 
-#if defined(PLACEHIGHRESREGION) || defined(RANDOMIZE_DOMAINCENTER)
+#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(RANDOMIZE_DOMAINCENTER)
   MyIntPosType domainInnersize;
   MyIntPosType domainReferenceIntPos[3];
   MySignedIntPosType domainXmintot[3], domainXmaxtot[3];
diff --git a/src/domain/domain_box.cc b/src/domain/domain_box.cc
index 2c1520c..10bc0b0 100644
--- a/src/domain/domain_box.cc
+++ b/src/domain/domain_box.cc
@@ -119,13 +119,13 @@ void domain<simparticles>::do_box_wrapping(void)
 #ifdef RANDOMIZE_DOMAINCENTER
   /* determine new shift vector */
 
-#if defined(PLACEHIGHRESREGION)
+#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(PLACEHIGHRESREGION)
   domain_find_type_extension();
 #endif
 
   if(ThisTask == 0)
     {
-#if defined(PLACEHIGHRESREGION)
+#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(PLACEHIGHRESREGION)
       int count = 0;
 #endif
 
@@ -145,7 +145,7 @@ void domain<simparticles>::do_box_wrapping(void)
           Tp->CurrentShiftVector[j] += get_random_number() * pow(2.0, 32);
 #endif
 
-#if defined(PLACEHIGHRESREGION)
+#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(PLACEHIGHRESREGION)
           MyIntPosType boxoff   = (Tp->CurrentShiftVector[j] & Tp->PlacingMask);
           MyIntPosType inboxoff = (Tp->CurrentShiftVector[j] - boxoff) % (Tp->PlacingBlocksize - domainInnersize);
 
@@ -190,7 +190,7 @@ void domain<simparticles>::do_box_wrapping(void)
 #endif
 }
 
-#if defined(PLACEHIGHRESREGION)
+#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(PLACEHIGHRESREGION)
 
 template <typename partset>
 int domain<partset>::domain_type_extension_overlap(int j)
@@ -217,7 +217,7 @@ void domain<partset>::domain_find_type_extension(void)
 
   for(int i = 0; i < Tp->NumPart; i++)
     {
-      if(((1 << Tp->P[i].getType()) & (PLACEHIGHRESREGION)))
+      if(((1 << Tp->P[i].getType()) & (RANDOMIZE_DOMAINCENTER_TYPES)))
         {
           for(int j = 0; j < 3; j++)
             domainReferenceIntPos[j] = Tp->P[i].IntPos[j];
@@ -232,8 +232,8 @@ void domain<partset>::domain_find_type_extension(void)
   MPI_Allreduce(MPI_IN_PLACE, have_global, 1, MPI_2INT, MPI_MINLOC, Communicator);
 
   if(have_global[0] >= NTask)
-    Terminate("have_global[0]=%d  >= NTask=%d: Don't we have any particle?  Note: PLACEHIGHRESREGION=%d is a bitmask", have_global[0],
-              NTask, PLACEHIGHRESREGION);
+    Terminate("have_global[0]=%d  >= NTask=%d: Don't we have any particle?  Note: RANDOMIZE_DOMAINCENTER_TYPES=%d is a bitmask",
+              have_global[0], NTask, RANDOMIZE_DOMAINCENTER_TYPES);
 
   MPI_Bcast(domainReferenceIntPos, 3 * sizeof(MyIntPosType), MPI_BYTE, have_global[1], Communicator);
 
@@ -249,7 +249,7 @@ void domain<partset>::domain_find_type_extension(void)
 
   for(int i = 0; i < Tp->NumPart; i++)
     {
-      if(((1 << Tp->P[i].getType()) & (PLACEHIGHRESREGION)))
+      if(((1 << Tp->P[i].getType()) & (RANDOMIZE_DOMAINCENTER_TYPES)))
         {
           MyIntPosType diff[3] = {Tp->P[i].IntPos[0] - domainReferenceIntPos[0], Tp->P[i].IntPos[1] - domainReferenceIntPos[1],
                                   Tp->P[i].IntPos[2] - domainReferenceIntPos[2]};
@@ -280,10 +280,10 @@ void domain<partset>::domain_find_type_extension(void)
   if((MyIntPosType)(domainXmaxtot[2] - domainXmintot[2]) > domainInnersize)
     domainInnersize = domainXmaxtot[2] - domainXmintot[2];
 
-  domain_printf("DOMAIN: Shrink-wrap region size for PLACEHIGHRESREGION is %g\n", domainInnersize * Tp->FacIntToCoord);
+  domain_printf("DOMAIN: Shrink-wrap region size for RANDOMIZE_DOMAINCENTER_TYPES is %g\n", domainInnersize * Tp->FacIntToCoord);
 
   if(domainInnersize * Tp->FacIntToCoord >= 0.125 * All.BoxSize)
-    Terminate("inappropriately big region selection for PLACEHIGHRESREGION");
+    Terminate("inappropriately big region selection for RANDOMIZE_DOMAINCENTER_TYPES");
 
   /* increase the region by at least 1/8 of its size to still allow some randomness in placing the particles within the high-res node
    */
-- 
GitLab