From 944e2043d72323c3c85e7cfcf5ab05e0cf8ec37f Mon Sep 17 00:00:00 2001
From: Kutscher <kutscher@irmb.tu-bs.de>
Date: Mon, 7 Nov 2022 12:41:43 +0100
Subject: [PATCH] fix some problems after renaming of directions

---
 apps/cpu/FallingSphere/FallingSphere.cpp      | 16 +++++-----
 apps/cpu/FallingSphere/in.lbdem               |  2 +-
 apps/cpu/LiggghtsApp/LiggghtsApp.cpp          | 19 ++++++------
 apps/cpu/LiggghtsApp/in.lbdem                 | 31 ++++++++++---------
 apps/cpu/LiggghtsApp/in2.lbdem                |  2 +-
 apps/cpu/Nozzle/nozzle.cpp                    | 20 +++++++++---
 .../IBcumulantK17LBMKernel.cpp                |  6 ++--
 .../LiggghtsCoupling/IBcumulantK17LBMKernel.h |  2 +-
 .../LiggghtsCoupling/IBdynamicsParticleData.h |  2 +-
 .../LiggghtsCouplingCoProcessor.cpp           | 16 +++++++---
 .../LiggghtsCouplingCoProcessor.h             |  2 +-
 src/cpu/VirtualFluidsCore/Grid/Block3D.cpp    | 19 ++++++------
 .../Visitors/MetisPartitioningGridVisitor.cpp |  4 +--
 .../Visitors/SetConnectorsBlockVisitor.h      |  2 +-
 14 files changed, 80 insertions(+), 63 deletions(-)

diff --git a/apps/cpu/FallingSphere/FallingSphere.cpp b/apps/cpu/FallingSphere/FallingSphere.cpp
index 1135f7c2c..5f399c547 100644
--- a/apps/cpu/FallingSphere/FallingSphere.cpp
+++ b/apps/cpu/FallingSphere/FallingSphere.cpp
@@ -24,16 +24,16 @@ int main(int argc, char *argv[])
 
     double g_maxX1 = 1;
     double g_maxX2 = 1;
-    double g_maxX3 = 2;
+    double g_maxX3 = 10;
 
-    //int blockNX[3] = { 16, 16, 16 };
-    //double dx = 1./32.;
+    int blockNX[3] = { 16, 16, 16 };
+    double dx = 1./32.;
 
-    double d_part = 0.1;
+    double d_part = 0.25;
     double r_p    = d_part / 2.0;
 
-    int blockNX[3] = { 10, 10, 10 };
-    double dx      = 0.05;
+    //int blockNX[3] = { 10, 10, 10 };
+    //double dx      = 0.05;
 
 
     double nuLB = 1e-2;
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
     grid->setDeltaX(dx);
     grid->setBlockNX(blockNX[0], blockNX[1], blockNX[2]);
 
-    string outputPath = "d:/temp/FallingSpheres2";
+    string outputPath = "f:/temp/FallingSpheresTest";
 
     UbSystem::makeDirectory(outputPath);
     UbSystem::makeDirectory(outputPath + "/liggghts");
@@ -122,7 +122,7 @@ int main(int argc, char *argv[])
 
     wrapper.execCommand("echo none");
 
-    //wrapper.setVariable("d_part", d_part);
+    wrapper.setVariable("d_part", d_part);
     //wrapper.setVariable("r_part", d_part/2.);
     //wrapper.setVariable("v_frac", v_frac);
 
diff --git a/apps/cpu/FallingSphere/in.lbdem b/apps/cpu/FallingSphere/in.lbdem
index 180f136b8..b47a85c99 100644
--- a/apps/cpu/FallingSphere/in.lbdem
+++ b/apps/cpu/FallingSphere/in.lbdem
@@ -47,7 +47,7 @@ fix zwalls2 all wall/gran model hertz tangential history primitive type 1 zplane
 create_atoms 1 single 0.5 0.5 9.75
 #create_atoms 1 single 0.38 0.05 0.05
 
-#set group all diameter ${d_part} density 2400
+set group all diameter ${d_part} density 2400
 
 atom_modify sort 0 0.0
 
diff --git a/apps/cpu/LiggghtsApp/LiggghtsApp.cpp b/apps/cpu/LiggghtsApp/LiggghtsApp.cpp
index 0f3d2ca13..b3c49ccae 100644
--- a/apps/cpu/LiggghtsApp/LiggghtsApp.cpp
+++ b/apps/cpu/LiggghtsApp/LiggghtsApp.cpp
@@ -19,6 +19,8 @@ using namespace std;
 
 int main(int argc, char *argv[])
 {
+    //Sleep(30000);
+
     std::shared_ptr<vf::mpi::Communicator> comm = vf::mpi::MPICommunicator::getInstance();
     int myid                                        = comm->getProcessID();
 
@@ -30,7 +32,7 @@ int main(int argc, char *argv[])
 
     double g_maxX1 = 1;
     double g_maxX2 = 1;
-    double g_maxX3 = 10;
+    double g_maxX3 = 2;
 
     int blockNX[3] = { 16, 16, 16 };
 
@@ -71,7 +73,9 @@ int main(int argc, char *argv[])
     grid->setDeltaX(dx);
     grid->setBlockNX(blockNX[0], blockNX[1], blockNX[2]);
 
-    string outputPath = "d:/temp/lll8";
+    string outputPath = "d:/temp/LiggghtsCoupling";
+    UbSystem::makeDirectory(outputPath);
+    UbSystem::makeDirectory(outputPath + "/liggghts");
 
     SPtr<Grid3DVisitor> metisVisitor(new MetisPartitioningGridVisitor(comm, MetisPartitioningGridVisitor::LevelBased, D3Q27System::DIR_MMM, MetisPartitioner::RECURSIVE));
     
@@ -113,19 +117,13 @@ int main(int argc, char *argv[])
     grid->accept(initVisitor);
 
     SPtr<UbScheduler> lScheduler                    = make_shared<UbScheduler>(1);
-    string inFile1                                   = "d:/Projects/VirtualFluids_LIGGGHTS_coupling/apps/cpu/LiggghtsApp/in.lbdem";
+    string inFile1                                   = "d:/Projects/VirtualFluids_Develop/apps/cpu/LiggghtsApp/in.lbdem";
     //string inFile1 = "d:/Tools/LIGGGHTS/examples/LIGGGHTS/Tutorials_public/chute_wear/in.chute_wear2";
-    string inFile2                                   = "d:/Projects/VirtualFluids_LIGGGHTS_coupling/apps/cpu/LiggghtsApp/in2.lbdem";
+    string inFile2                                   = "d:/Projects/VirtualFluids_Develop/apps/cpu/LiggghtsApp/in2.lbdem";
     MPI_Comm mpi_comm       = *(MPI_Comm*)(comm->getNativeCommunicator());
     LiggghtsCouplingWrapper wrapper(argv, mpi_comm);
 
 
-
-
-
-
-    //return 0;
-
     double v_frac = 0.1;
     double dt_phys   = units->getFactorTimeLbToW();
     int demSubsteps = 10;
@@ -140,6 +138,7 @@ int main(int argc, char *argv[])
 
     wrapper.execFile((char*)inFile1.c_str());
 
+ 
     //// set timestep and output directory
     wrapper.setVariable("t_step", dt_dem);
     wrapper.setVariable("dmp_stp", vtkSteps * demSubsteps);
diff --git a/apps/cpu/LiggghtsApp/in.lbdem b/apps/cpu/LiggghtsApp/in.lbdem
index c356a2f6b..4c38d7926 100644
--- a/apps/cpu/LiggghtsApp/in.lbdem
+++ b/apps/cpu/LiggghtsApp/in.lbdem
@@ -12,7 +12,7 @@ boundary	f f f
 newton		off
 
 processors * * 1
-region		box block 0. 1. 0. 1. 0. 10. units box
+region		box block 0. 1. 0. 1. 0. 2. units box
 create_box	1 box
 
 variable	skin equal 0.01
@@ -44,31 +44,32 @@ fix ywalls2 all wall/gran model hertz tangential history primitive type 1 yplane
 fix zwalls1 all wall/gran model hertz tangential history primitive type 1 zplane 0.
 fix zwalls2 all wall/gran model hertz tangential history primitive type 1 zplane 2.
 
-create_atoms 1 single 0.5 0.5 9.75
+#create_atoms 1 single 0.5 0.5 9.75
 #create_atoms 1 single 0.38 0.05 0.05
 
-set group all diameter 0.25 density 2400
+#set group all diameter 0.25 density 2400
 
-atom_modify sort 0 0.0
+#atom_modify sort 0 0.0
 
 #fix pts1 all particletemplate/sphere 1 atom_type 1 density constant 1000 radius constant 0.015 
 #fix pts2 all particletemplate/sphere 1 atom_type 1 density constant 1000 radius constant 0.01 
 #fix pts1 all particletemplate/sphere 1 atom_type 1 density constant 1100 radius constant ${r_part} 
+fix  pts1 all particletemplate/sphere 15485863 atom_type 1 density constant 2500 radius constant 0.01
 
-# fix pdd1 all particledistribution/discrete 6778  1 pts1 1.0
-# #fix pdd2 all particledistribution/discrete 6778  2 pts2 0.2 pts3 0.8
+fix pdd1 all particledistribution/discrete 32452843  1 pts1 1.0
+#fix pdd2 all particledistribution/discrete 6778  2 pts2 0.2 pts3 0.8
 
-# # region  insreg block 0.1 0.9 0.1 0.9 1.3 1.9 units box
+region  insreg block 0.1 0.9 0.1 0.9 1.3 1.9 units box
 
 
-# #fix ins all insert/pack seed 1001 distributiontemplate pdd1 insert_every once &
-# #                         overlapcheck yes particles_in_region 350 region insreg ntry_mc 10000 
-# fix ins all insert/pack seed 1001 distributiontemplate pdd1 insert_every once &
-#                         overlapcheck yes volumefraction_region ${v_frac} region insreg ntry_mc 10000 
-# #fix ins all insert/pack seed 1001 distributiontemplate pdd2 insert_every once &
-# #                        overlapcheck yes volumefraction_region 0.05 region insreg ntry_mc 10000 
-# #fix ins all insert/pack seed 1001 distributiontemplate pdd1 insert_every once &
-# #                        overlapcheck yes particles_in_region 1 region insreg ntry_mc 10000 
+#fix ins all insert/pack seed 1001 distributiontemplate pdd1 insert_every once &
+#                         overlapcheck yes particles_in_region 350 region insreg ntry_mc 10000 
+#fix ins all insert/pack seed 1001 distributiontemplate pdd1 insert_every once &
+#                        overlapcheck yes volumefraction_region ${v_frac} region insreg ntry_mc 10000 
+fix ins all insert/pack seed 32452867 distributiontemplate pdd1 insert_every once &
+                        overlapcheck yes volumefraction_region 0.1 region insreg ntry_mc 1001 
+#fix ins all insert/pack seed 1001 distributiontemplate pdd1 insert_every once &
+#                        overlapcheck yes particles_in_region 1 region insreg ntry_mc 10000 
 
 echo none
 
diff --git a/apps/cpu/LiggghtsApp/in2.lbdem b/apps/cpu/LiggghtsApp/in2.lbdem
index 229fe747f..aee0cc8db 100644
--- a/apps/cpu/LiggghtsApp/in2.lbdem
+++ b/apps/cpu/LiggghtsApp/in2.lbdem
@@ -22,6 +22,6 @@ variable dmp_fname string ${dmp_dir}d_*.liggghts
 
 
 	
-dump   dmp all custom/vtk ${dmp_stp} ${dmp_dir}/post/atom_*.vtk id type type x y z ix iy iz vx vy vz fx fy fz omegax omegay omegaz radius 	
+dump   dmp all custom/vtk ${dmp_stp} ${dmp_dir}/liggghts/atom_*.vtk id type type x y z ix iy iz vx vy vz fx fy fz omegax omegay omegaz radius 	
 
 echo none
\ No newline at end of file
diff --git a/apps/cpu/Nozzle/nozzle.cpp b/apps/cpu/Nozzle/nozzle.cpp
index 17b806e91..81ab57a73 100644
--- a/apps/cpu/Nozzle/nozzle.cpp
+++ b/apps/cpu/Nozzle/nozzle.cpp
@@ -13,6 +13,8 @@ using namespace std;
 
 int main(int argc, char *argv[])
 {
+    //Sleep(30000);
+
     std::shared_ptr<vf::mpi::Communicator> comm = vf::mpi::MPICommunicator::getInstance();
     int myid = comm->getProcessID();
 
@@ -74,10 +76,16 @@ int main(int argc, char *argv[])
 
     string geoPath = "d:/Projects/TRR277/Project/WP4/NozzleGeo";
 
-    string outputPath = "d:/temp/NozzleFlow";
+    string outputPath = "f:/temp/NozzleFlowTestSerial";
     UbSystem::makeDirectory(outputPath);
     UbSystem::makeDirectory(outputPath + "/liggghts");
 
+    if (myid == 0) {
+        stringstream logFilename;
+        logFilename << outputPath + "/logfile" + UbSystem::toString(UbSystem::getTimeStamp()) + ".txt";
+        UbLog::output_policy::setStream(logFilename.str());
+    }
+
     SPtr<Grid3DVisitor> metisVisitor(new MetisPartitioningGridVisitor(comm, MetisPartitioningGridVisitor::LevelBased, D3Q27System::DIR_MMM, MetisPartitioner::RECURSIVE));
     
     SPtr<GbObject3D> gridCube = make_shared <GbCuboid3D>(g_minX1, g_minX2, g_minX3, g_maxX1, g_maxX2, g_maxX3);
@@ -186,7 +194,7 @@ int main(int argc, char *argv[])
     grid->accept(initVisitor);
 
   
-    string inFile1 = "d:/Projects/VirtualFluids_LIGGGHTS_coupling/apps/cpu/Nozzle/in.nozzle";
+    string inFile1 = "d:/Projects/VirtualFluids_Develop/apps/cpu/Nozzle/in.nozzle";
     //string inFile2 = "d:/Projects/VirtualFluids_LIGGGHTS_coupling/apps/cpu/LiggghtsApp/in2.lbdem";
     MPI_Comm mpi_comm = *(MPI_Comm*)(comm->getNativeCommunicator());
     LiggghtsCouplingWrapper wrapper(argv, mpi_comm);
@@ -197,7 +205,7 @@ int main(int argc, char *argv[])
     // SPtr<LBMUnitConverter> units = std::make_shared<LBMUnitConverter>(r_p, 1.480, 2060, r_p/dx);
     //SPtr<LBMUnitConverter> units = std::make_shared<LBMUnitConverter>(r_p, LBMUnitConverter::AIR_20C, r_p / dx);
     SPtr<LBMUnitConverter> units = std::make_shared<LBMUnitConverter>(d_part, 1., 1000, d_part / dx, 0.01);
-    std::cout << units->toString() << std::endl;
+    if (myid == 0) std::cout << units->toString() << std::endl;
 
     //return 0;
 
@@ -246,13 +254,15 @@ int main(int argc, char *argv[])
     SPtr<NUPSCounterCoProcessor> nupsCoProcessor = make_shared<NUPSCounterCoProcessor>(grid, nupsSch, numOfThreads, comm);
 
     //// write data for visualization of macroscopic quantities
-    SPtr<UbScheduler> visSch(new UbScheduler(vtkSteps));
+    SPtr < UbScheduler> visSch(new UbScheduler(vtkSteps));
+    //SPtr<UbScheduler> visSch(new UbScheduler(1, 8700, 8800));
+    visSch->addSchedule(1, 8700, 8800);
     SPtr<WriteMacroscopicQuantitiesCoProcessor> writeMQCoProcessor(
         new WriteMacroscopicQuantitiesCoProcessor(grid, visSch, outputPath, WbWriterVtkXmlBinary::getInstance(),
                                                   SPtr<LBMUnitConverter>(new LBMUnitConverter()), comm));
     writeMQCoProcessor->process(0);
 
-    int endTime = 1000000; //20;
+    int endTime = 10000000; //20;
     SPtr<Calculator> calculator(new BasicCalculator(grid, lScheduler, endTime));
     calculator->addCoProcessor(nupsCoProcessor);
     calculator->addCoProcessor(lcCoProcessor);
diff --git a/src/cpu/LiggghtsCoupling/IBcumulantK17LBMKernel.cpp b/src/cpu/LiggghtsCoupling/IBcumulantK17LBMKernel.cpp
index 0ab0f8a67..7e36c2b9c 100644
--- a/src/cpu/LiggghtsCoupling/IBcumulantK17LBMKernel.cpp
+++ b/src/cpu/LiggghtsCoupling/IBcumulantK17LBMKernel.cpp
@@ -47,6 +47,9 @@ using namespace UbMath;
 IBcumulantK17LBMKernel::IBcumulantK17LBMKernel()
 {
     this->compressible = true;
+    forcingX1 = 0.0;
+    forcingX2 = 0.0;
+    forcingX3 = 0.0;
 }
 //////////////////////////////////////////////////////////////////////////
 void IBcumulantK17LBMKernel::initDataSet()
@@ -54,8 +57,7 @@ void IBcumulantK17LBMKernel::initDataSet()
     SPtr<DistributionArray3D> d(new D3Q27EsoTwist3DSplittedVector(nx[0] + 2, nx[1] + 2, nx[2] + 2, -999.9));
     dataSet->setFdistributions(d);
 
-    particleData =
-        std::make_shared<CbArray3D<SPtr<IBdynamicsParticleData>, IndexerX3X2X1>>(nx[0] + 2, nx[1] + 2, nx[2] + 2);
+    particleData = std::make_shared<CbArray3D<SPtr<IBdynamicsParticleData>, IndexerX3X2X1>>(nx[0] + 2, nx[1] + 2, nx[2] + 2);
 
     int minX1 = 0;
     int minX2 = 0;
diff --git a/src/cpu/LiggghtsCoupling/IBcumulantK17LBMKernel.h b/src/cpu/LiggghtsCoupling/IBcumulantK17LBMKernel.h
index 503d19709..2d5216d36 100644
--- a/src/cpu/LiggghtsCoupling/IBcumulantK17LBMKernel.h
+++ b/src/cpu/LiggghtsCoupling/IBcumulantK17LBMKernel.h
@@ -27,7 +27,7 @@
 //  with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
 //
 //! \file IBcumulantK17LBMKernel.h
-//! \ingroup LBM
+//! \ingroup LiggghtsCoupling
 //! \author Konstantin Kutscher, Martin Geier
 //=======================================================================================
 
diff --git a/src/cpu/LiggghtsCoupling/IBdynamicsParticleData.h b/src/cpu/LiggghtsCoupling/IBdynamicsParticleData.h
index 28f11bf2e..6593a9654 100644
--- a/src/cpu/LiggghtsCoupling/IBdynamicsParticleData.h
+++ b/src/cpu/LiggghtsCoupling/IBdynamicsParticleData.h
@@ -27,7 +27,7 @@
 //  with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
 //
 //! \file DataSet3D.h
-//! \ingroup Data
+//! \ingroup LiggghtsCoupling
 //! \author Konstantin Kutscher
 //=======================================================================================
 
diff --git a/src/cpu/LiggghtsCoupling/LiggghtsCouplingCoProcessor.cpp b/src/cpu/LiggghtsCoupling/LiggghtsCouplingCoProcessor.cpp
index db29726c9..51d451064 100644
--- a/src/cpu/LiggghtsCoupling/LiggghtsCouplingCoProcessor.cpp
+++ b/src/cpu/LiggghtsCoupling/LiggghtsCouplingCoProcessor.cpp
@@ -27,13 +27,22 @@ LiggghtsCouplingCoProcessor::~LiggghtsCouplingCoProcessor()
 
 void LiggghtsCouplingCoProcessor::process(double actualTimeStep)
 { 
-    std::cout << "step: " << actualTimeStep << "\n";
+    if (comm->getProcessID() == 0)
+        std::cout << "LiggghtsCouplingCoProcessor step: " << actualTimeStep << "\n";
     
+    //comm->barrier();
+
     getForcesFromLattice();
 
+    //comm->barrier();
+    
     wrapper.run(demSteps);
+
+    //comm->barrier();
     
     setSpheresOnLattice();
+
+    //comm->barrier();
 }
 
 void LiggghtsCouplingCoProcessor::setSpheresOnLattice()
@@ -88,9 +97,6 @@ void LiggghtsCouplingCoProcessor::setSingleSphere3D(double *x, double *v, double
     
     std::vector<SPtr<Block3D>> blocks;
     grid->getBlocksByCuboid(level, x[0] - r, x[1] - r, x[2] - r, x[0] + r, x[1] + r, x[2] + r, blocks);
-    
-
-
 
     for (SPtr<Block3D> block : blocks) {
         if (block) {
@@ -319,7 +325,7 @@ void LiggghtsCouplingCoProcessor::SumForceTorque3D(ParticleData::ParticleDataArr
 
     std::vector < SPtr < Block3D > > blocks;
     int level = 0;
-    grid->getBlocks(level, gridRank, true, blocks);
+    grid->getBlocks(level, grid->getRank(), true, blocks);
 
         
     for (SPtr<Block3D> block : blocks) {
diff --git a/src/cpu/LiggghtsCoupling/LiggghtsCouplingCoProcessor.h b/src/cpu/LiggghtsCoupling/LiggghtsCouplingCoProcessor.h
index 4788e892a..3e87c89d2 100644
--- a/src/cpu/LiggghtsCoupling/LiggghtsCouplingCoProcessor.h
+++ b/src/cpu/LiggghtsCoupling/LiggghtsCouplingCoProcessor.h
@@ -95,7 +95,7 @@ private:
     //std::vector<std::vector<SPtr<Block3D>>> blockVector;
     //int minInitLevel;
     //int maxInitLevel;
-    int gridRank;
+    //int gridRank;
 
     double *force, *torque;
 };
diff --git a/src/cpu/VirtualFluidsCore/Grid/Block3D.cpp b/src/cpu/VirtualFluidsCore/Grid/Block3D.cpp
index 3a55c6ad7..c6a751870 100644
--- a/src/cpu/VirtualFluidsCore/Grid/Block3D.cpp
+++ b/src/cpu/VirtualFluidsCore/Grid/Block3D.cpp
@@ -262,28 +262,27 @@ int Block3D::getNumberOfLocalConnectorsForSurfaces()
     if (connectors.size() < 6)
         return count;
 
-    for (int dir = 0; dir <= 5; dir++) // Hard coding. It works if you have 0...5 for E, N ... B
-    {
-        SPtr<Block3DConnector> connector = this->connectors[dir];
-        if (this->connectors[dir]) {
-            if (connector->isLocalConnector())
+    for (SPtr<Block3DConnector> c : connectors) {
+        if (c) {
+            if (c->getSendDir() >= D3Q27System::DIR_P00 && c->getSendDir() <= D3Q27System ::DIR_00M && c->isLocalConnector())
                 count++;
         }
     }
+
     return count;
 }
 //////////////////////////////////////////////////////////////////////////
 int Block3D::getNumberOfRemoteConnectorsForSurfaces()
 {
     int count = 0;
-    for (int dir = 0; dir <= 5; dir++) // Hard coding. It works if you have 0...5 for E, N ... B
-    {
-        SPtr<Block3DConnector> connector = this->connectors[dir];
-        if (this->connectors[dir]) {
-            if (connector->isRemoteConnector())
+
+    for (SPtr<Block3DConnector> c : connectors) {
+        if (c) {
+            if (c->getSendDir() >= D3Q27System::DIR_P00 && c->getSendDir() <= D3Q27System ::DIR_00M && c->isRemoteConnector())
                 count++;
         }
     }
+
     return count;
 }
 void Block3D::setCollectionOfInterpolationFlagCF(int flags) { interpolationFlagCF = flags; }
diff --git a/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.cpp
index 8cd256a9b..7546aa307 100644
--- a/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.cpp
+++ b/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.cpp
@@ -133,7 +133,7 @@ void MetisPartitioningGridVisitor::buildMetisGraphLevelIntersected(SPtr<Grid3D>
             // the weights of the vertices are 2^level of grid (1, 2, 4, 8 .....) 1<<level
             metis.vwgt.push_back((idx_t)(1 << block->getLevel()));
 
-            for (int dir = 0; dir <= numOfDirs; dir++) {
+            for (int dir = D3Q27System::DIR_P00; dir <= numOfDirs; dir++) {
                 SPtr<Block3D> neighBlock = grid->getNeighborBlock(dir, block);
                 if (neighBlock) {
                     if (this->getPartitionCondition(neighBlock, level)) {
@@ -200,7 +200,7 @@ void MetisPartitioningGridVisitor::buildMetisGraphLevelBased(SPtr<Grid3D> grid,
             metis.xadj.push_back(edges);
             metis.vwgt.push_back(vertexWeight);
 
-            for (int dir = 0; dir <= numOfDirs; dir++) {
+            for (int dir = D3Q27System::DIR_P00; dir <= numOfDirs; dir++) {
                 SPtr<Block3D> neighBlock = grid->getNeighborBlock(dir, block);
                 if (neighBlock) {
                     if (this->getPartitionCondition(neighBlock, level)) {
diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.h
index c47c275cf..53068df96 100644
--- a/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.h
+++ b/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.h
@@ -126,7 +126,7 @@ void SetConnectorsBlockVisitor<T1, T2>::setSameLevelConnectors(SPtr<Grid3D> grid
                 } else if (blockRank != neighBlockRank && neighBlock->isActive()) {
                     setRemoteConnectors(block, neighBlock, dir);
 
-                    if (dir >= 0 && dir <= 5) {
+                    if (dir >= D3Q27System::DIR_P00 && dir <= D3Q27System::DIR_00M) {
                         int weight = block->getWeight(neighBlockRank);
                         weight++;
                         block->setWeight(neighBlockRank, weight);
-- 
GitLab