From 25907cddb86c4fbdcc87ea62c6215c231cd8f144 Mon Sep 17 00:00:00 2001
From: Rene Halver <r.halver@fz-juelich.de>
Date: Tue, 27 Jul 2021 14:40:10 +0200
Subject: [PATCH] update the outline used for VTK output when balance is called

---
 include/ALL.hpp           |  4 ++++
 include/ALL_Staggered.hpp | 14 ++++++++------
 include/ALL_Tensor.hpp    |  9 +++++----
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/include/ALL.hpp b/include/ALL.hpp
index 78e7651..32aca6f 100644
--- a/include/ALL.hpp
+++ b/include/ALL.hpp
@@ -299,6 +299,7 @@ public:
     switch (method) {
     case LB_t::TENSOR:
       balancer->balance(loadbalancing_step);
+      calculate_outline();
       break;
     case LB_t::STAGGERED:
 
@@ -373,9 +374,11 @@ public:
       ((Staggered_LB<T,W>*)balancer.get())->setVertices(outline->data());
       */
       balancer->balance(loadbalancing_step);
+      calculate_outline();
       break;
     case LB_t::FORCEBASED:
       balancer->balance(loadbalancing_step);
+      calculate_outline();
       break;
 #ifdef ALL_VORONOI_ACTIVE
     case LB_t::VORONOI:
@@ -384,6 +387,7 @@ public:
 #endif
     case LB_t::HISTOGRAM:
       balancer->balance(loadbalancing_step);
+      calculate_outline();
       break;
     default:
       throw InvalidArgumentException(
diff --git a/include/ALL_Staggered.hpp b/include/ALL_Staggered.hpp
index 75c38de..ecbe3c3 100644
--- a/include/ALL_Staggered.hpp
+++ b/include/ALL_Staggered.hpp
@@ -207,6 +207,7 @@ template <class T, class W> void Staggered_LB<T, W>::setup() {
 }
 
 template <class T, class W> void Staggered_LB<T, W>::balance(int) {
+  std::vector<Point<T>> newVertices = this->vertices;
   int dimension = this->getDimension();
 
   // store original vertices
@@ -306,28 +307,29 @@ template <class T, class W> void Staggered_LB<T, W>::balance(int) {
 
     // for now: test case for simple program
 
-    // if a left neighbor exists: shift left border
     // if a left neighbor exists: shift left border
     if (rank_left != MPI_PROC_NULL && this->local_coords[i] != 0)
-      this->vertices.at(0)[i] = this->prevVertices.at(0)[i] + remote_shift;
+      newVertices.at(0)[i] = this->prevVertices.at(0)[i] + remote_shift;
     else
-      this->vertices.at(0)[i] = this->prevVertices.at(0)[i];
+      newVertices.at(0)[i] = this->prevVertices.at(0)[i];
 
     // if a right neighbor exists: shift right border
     if (rank_right != MPI_PROC_NULL &&
         this->local_coords[i] != this->global_dims[i] - 1)
-      this->vertices.at(1)[i] = this->prevVertices.at(1)[i] + shift;
+      newVertices.at(1)[i] = this->prevVertices.at(1)[i] + shift;
     else
-      this->vertices.at(1)[i] = this->prevVertices.at(1)[i];
+      newVertices.at(1)[i] = this->prevVertices.at(1)[i];
 
     // check if vertices are crossed and throw exception if something went wrong
-    if (this->vertices.at(1)[i] < this->vertices.at(0)[i]) {
+    if (newVertices.at(1)[i] < newVertices.at(0)[i]) {
       std::cout << "ERROR on process: " << this->localRank << std::endl;
       throw InternalErrorException(
           __FILE__, __func__, __LINE__,
           "Lower border of process larger than upper border of process!");
     }
 
+    this->setVertices(newVertices);
+
 #ifdef ALL_DEBUG_ENABLED
     MPI_Barrier(this->globalComm);
     if (this->localRank == 0)
diff --git a/include/ALL_Tensor.hpp b/include/ALL_Tensor.hpp
index a328d64..f7655fc 100644
--- a/include/ALL_Tensor.hpp
+++ b/include/ALL_Tensor.hpp
@@ -175,6 +175,7 @@ template <class T, class W> void Tensor_LB<T, W>::setup() {
 
 template <class T, class W> void Tensor_LB<T, W>::balance(int) {
   int dim = this->getDimension();
+  std::vector<Point<T>> newVertices = this->vertices;
   this->prevVertices = this->vertices;
 
   // loop over all available dimensions
@@ -238,16 +239,16 @@ template <class T, class W> void Tensor_LB<T, W>::balance(int) {
 
     // if a left neighbor exists: shift left border
     if (rank_left != MPI_PROC_NULL && this->local_coords[i] != 0)
-      this->vertices.at(0)[i] = this->prevVertices.at(0)[i] + remote_shift;
+      newVertices.at(0)[i] = this->prevVertices.at(0)[i] + remote_shift;
     else
-      this->vertices.at(0)[i] = this->prevVertices.at(0)[i];
+      newVertices.at(0)[i] = this->prevVertices.at(0)[i];
 
     // if a right neighbor exists: shift right border
     if (rank_right != MPI_PROC_NULL &&
         this->local_coords[i] != this->global_dims[i] - 1)
-      this->vertices.at(1)[i] = this->prevVertices.at(1)[i] + shift;
+      newVertices.at(1)[i] = this->prevVertices.at(1)[i] + shift;
     else
-      this->vertices.at(1)[i] = this->prevVertices.at(1)[i];
+      newVertices.at(1)[i] = this->prevVertices.at(1)[i];
   }
 }
 
-- 
GitLab