From e322f20e958176b4dc442ac108c1349d3a0f35dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com>
Date: Sat, 9 Feb 2019 20:18:13 +0100
Subject: [PATCH] Added switch of periodic boundaries synchronization
 direction.

It is either from subdomain boundary to overlap or vice versa.
---
 .../DistributedGridSynchronizer.h             | 29 ++++++++-----------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h
index 3bc695c3a0..3ca8cc5f3e 100644
--- a/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h
+++ b/src/TNL/Meshes/DistributedMeshes/DistributedGridSynchronizer.h
@@ -48,7 +48,13 @@ class DistributedMeshSynchronizer< Functions::MeshFunction< Grid< MeshDimension,
       typedef typename Grid< MeshDimension, GridReal, Device, Index >::DistributedMeshType DistributedGridType; 
       typedef typename DistributedGridType::CoordinatesType CoordinatesType;
       using SubdomainOverlapsType = typename DistributedGridType::SubdomainOverlapsType;
-          
+
+      enum PeriodicBoundariesCopyDirection
+      {
+         BoundaryToOverlap,
+         OverlapToBoundary
+      };
+
       DistributedMeshSynchronizer()
       {
          isSet = false;
@@ -108,22 +114,9 @@ class DistributedMeshSynchronizer< Functions::MeshFunction< Grid< MeshDimension,
             sendBuffers[ i ].setSize( sendSize );
             recieveBuffers[ i ].setSize( sendSize);
 
-            //Periodic-BC copy from overlap into domain
-            //if Im on boundary, and i is direction of the boundary i will swap source and destination
-            //i do this only for basic 6 directions, 
-            //because this swap at conners and edges produces writing multiple values at sam place in localsubdomain
-            {
-               if(  (  i==ZzYzXm || i==ZzYzXp 
-                     ||i==ZzYmXz || i==ZzYpXz 
-                     ||i==ZmYzXz || i==ZpYzXz ) 
-                  && neighbors[ i ] == -1) 
-               {
-                  //swap begins
-                  CoordinatesType tmp = sendBegin[i];
-                  sendBegin[i]=recieveBegin[i];
-                  recieveBegin[i]=tmp;
-               }
-            }
+            if( this->periodicBoundariesCopyDirection == OverlapToBoundary &&
+               neighbors[ i ] == -1 )
+                  swap( sendBegin[i], recieveBegin[i] );
          }
      }
 
@@ -213,6 +206,8 @@ class DistributedMeshSynchronizer< Functions::MeshFunction< Grid< MeshDimension,
       Containers::Array<RealType, Device, Index> recieveBuffers[getNeighborCount()];
       Containers::StaticArray< getNeighborCount(), int > sendSizes;
 
+      PeriodicBoundariesCopyDirection periodicBoundariesCopyDirection = BoundaryToOverlap;
+
       CoordinatesType sendDimensions[getNeighborCount()];
       CoordinatesType recieveDimensions[getNeighborCount()];
       CoordinatesType sendBegin[getNeighborCount()];
-- 
GitLab