From 17711f42b89a08f7e56ca4e673e6eecd467cf784 Mon Sep 17 00:00:00 2001
From: Anna <a.wellmann@tu-bs.de>
Date: Thu, 30 Jun 2022 13:10:32 +0000
Subject: [PATCH] Merge changes on GridGenerator from develop into open_source

---
 .../LidDrivenCavityGPU/LidDrivenCavity.cpp    |  6 +--
 .../GridGenerator/geometries/Arrow/ArrowImp.h |  1 -
 .../geometries/Cuboid/Cuboid.cpp              | 18 +++-----
 .../GridGenerator/geometries/Sphere/Sphere.h  |  1 -
 .../geometries/Triangle/Triangle.h            |  1 -
 .../TriangularMesh/TriangularMesh.h           |  1 -
 .../TriangularMesh/TriangularMeshStrategy.h   |  1 -
 .../TriangleNeighborFinder.h                  |  3 +-
 .../GridGenerator/geometries/Vertex/Vertex.h  |  2 +-
 .../VerticalCylinder/VerticalCylinder.h       |  1 -
 .../grid/BoundaryConditions/Side.cpp          |  8 +++-
 src/gpu/GridGenerator/grid/Cell.h             |  2 +-
 src/gpu/GridGenerator/grid/Field.h            |  2 +-
 src/gpu/GridGenerator/grid/Grid.h             | 10 ++---
 .../grid/GridBuilder/GridBuilder.h            |  7 ++--
 .../grid/GridBuilder/LevelGridBuilder.cpp     | 39 ++++++++---------
 .../grid/GridBuilder/LevelGridBuilder.h       | 12 ++++--
 .../grid/GridBuilder/MultipleGridBuilder.cpp  |  8 ++--
 .../grid/GridBuilder/MultipleGridBuilder.h    |  6 ++-
 src/gpu/GridGenerator/grid/GridFactory.h      | 28 ++++++++++++-
 src/gpu/GridGenerator/grid/GridImp.cpp        | 42 ++++++++++---------
 src/gpu/GridGenerator/grid/GridImp.h          | 25 ++++++-----
 src/gpu/GridGenerator/grid/GridInterface.h    |  2 +-
 .../grid/distributions/Distribution.h         |  2 +-
 .../io/STLReaderWriter/STLReader.cpp          |  2 +-
 .../SimulationFileWriter.h                    |  2 +-
 26 files changed, 131 insertions(+), 101 deletions(-)

diff --git a/apps/gpu/LidDrivenCavityGPU/LidDrivenCavity.cpp b/apps/gpu/LidDrivenCavityGPU/LidDrivenCavity.cpp
index 836374dfa..0d927d7aa 100644
--- a/apps/gpu/LidDrivenCavityGPU/LidDrivenCavity.cpp
+++ b/apps/gpu/LidDrivenCavityGPU/LidDrivenCavity.cpp
@@ -94,7 +94,7 @@ int main(int argc, char *argv[])
         //////////////////////////////////////////////////////////////////////////
         // Simulation parameters
         //////////////////////////////////////////////////////////////////////////
-        std::string path("/output/DrivenCavity");
+        std::string path("./output/DrivenCavity");
         std::string simulationName("LidDrivenCavity");
 
         const real L        = 1.0;
@@ -103,8 +103,8 @@ int main(int argc, char *argv[])
         const real dt       = (real)0.5e-3;
         const uint nx       = 64;
 
-        const uint timeStepOut = 10000;
-        const uint timeStepEnd = 250000;
+        const uint timeStepOut = 1;
+        const uint timeStepEnd = 10;
 
         // switch between LBM and GKS solver here
         // LbmOrGks lbmOrGks = GKS;
diff --git a/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.h b/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.h
index ef145b7de..1fb509e0c 100644
--- a/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.h
+++ b/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.h
@@ -36,7 +36,6 @@
 #include <memory>
 
 #include "global.h"
-#include "GridGenerator_export.h"
 
 #include "Arrow.h"
 
diff --git a/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.cpp b/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.cpp
index e64a202ca..7b0dbcdbd 100644
--- a/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.cpp
+++ b/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.cpp
@@ -113,18 +113,12 @@ double Cuboid::getMaximum(double x1, double x2)
 bool Cuboid::isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset)
 {
     //false, if 'not in Object' or 'on Boundary'!
-    if (vf::Math::lessEqual((real)x1, (real)this->getX1Minimum() + (real)minOffset))
-        return false;
-    if (vf::Math::lessEqual((real)x2, (real)this->getX2Minimum() + (real)minOffset))
-        return false;
-    if (vf::Math::lessEqual((real)x3, (real)this->getX3Minimum() + (real)minOffset))
-        return false;
-    if (vf::Math::greaterEqual((real)x1, (real)this->getX1Maximum() - (real)maxOffset))
-        return false;
-    if (vf::Math::greaterEqual((real)x2, (real)this->getX2Maximum() - (real)maxOffset))
-        return false;
-    if (vf::Math::greaterEqual((real)x3, (real)this->getX3Maximum() - (real)maxOffset))
-        return false;
+    if (vf::Math::lessEqual(   (real)x1, (real)this->getX1Minimum() + (real)minOffset))  return false;
+    if (vf::Math::lessEqual(   (real)x2, (real)this->getX2Minimum() + (real)minOffset))  return false;
+    if (vf::Math::lessEqual(   (real)x3, (real)this->getX3Minimum() + (real)minOffset))  return false;
+    if (vf::Math::greaterEqual((real)x1, (real)this->getX1Maximum() - (real)maxOffset))  return false;
+    if (vf::Math::greaterEqual((real)x2, (real)this->getX2Maximum() - (real)maxOffset))  return false;
+    if (vf::Math::greaterEqual((real)x3, (real)this->getX3Maximum() - (real)maxOffset))  return false;
 
     return true;
 }
diff --git a/src/gpu/GridGenerator/geometries/Sphere/Sphere.h b/src/gpu/GridGenerator/geometries/Sphere/Sphere.h
index ba5821f5b..03b9ef9fd 100644
--- a/src/gpu/GridGenerator/geometries/Sphere/Sphere.h
+++ b/src/gpu/GridGenerator/geometries/Sphere/Sphere.h
@@ -34,7 +34,6 @@
 #define SPHERE_H
 
 #include "global.h"
-#include "GridGenerator_export.h"
 #include "geometries/Object.h"
 
 class GRIDGENERATOR_EXPORT Sphere : public Object
diff --git a/src/gpu/GridGenerator/geometries/Triangle/Triangle.h b/src/gpu/GridGenerator/geometries/Triangle/Triangle.h
index 0017d2f71..0c62f2c0d 100644
--- a/src/gpu/GridGenerator/geometries/Triangle/Triangle.h
+++ b/src/gpu/GridGenerator/geometries/Triangle/Triangle.h
@@ -36,7 +36,6 @@
 #include <memory>
 
 #include "global.h"
-#include "GridGenerator_export.h"
 #include "geometries/Vertex/Vertex.h"
 
 class TriangleMemento;
diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.h b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.h
index 2d31de98b..beb1c3a05 100644
--- a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.h
+++ b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.h
@@ -37,7 +37,6 @@
 #include <vector>
 #include <string>
 #include <memory>
-#include "GridGenerator_export.h"
 #include "global.h"
 
 #include "geometries/Triangle/Triangle.h"
diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.h b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.h
index 573a46484..b98d53159 100644
--- a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.h
+++ b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.h
@@ -34,7 +34,6 @@
 #define TriangularMeshStrategy_H
 
 #include "global.h"
-#include "GridGenerator_export.h"
 
 class GridImp;
 class TriangularMesh;
diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.h b/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.h
index b0dda279c..2b42ff3ad 100644
--- a/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.h
+++ b/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.h
@@ -33,8 +33,7 @@
 #ifndef TriangleNeighborFinder_h
 #define TriangleNeighborFinder_h
 
-#include "GridGenerator/global.h"
-#include "GridGenerator_export.h"
+#include "global.h"
 #include <vector>
 
 struct IDS {
diff --git a/src/gpu/GridGenerator/geometries/Vertex/Vertex.h b/src/gpu/GridGenerator/geometries/Vertex/Vertex.h
index 7b27d853f..ec5fc0f1c 100644
--- a/src/gpu/GridGenerator/geometries/Vertex/Vertex.h
+++ b/src/gpu/GridGenerator/geometries/Vertex/Vertex.h
@@ -37,7 +37,7 @@
 #include <memory>
 #include <ostream>
 
-#include "global.h"
+#include "gpu/GridGenerator/global.h"
 
 struct GRIDGENERATOR_EXPORT Vertex
 {
diff --git a/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h
index 24d9383bf..e995d2ba1 100644
--- a/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h
+++ b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h
@@ -34,7 +34,6 @@
 #define VERTICAL_CYLINDER_H
 
 #include "global.h"
-#include "GridGenerator_export.h"
 #include "geometries/Object.h"
 
 class GRIDGENERATOR_EXPORT VerticalCylinder : public Object
diff --git a/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp b/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp
index 4c5161acb..330f400b3 100644
--- a/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp
+++ b/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp
@@ -53,7 +53,7 @@ void Side::addIndices(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition
                                             || grid->getFieldEntry(index) == vf::gpu::FLUID_CFC
                                             || grid->getFieldEntry(index) == vf::gpu::FLUID_CFF
                                             || grid->getFieldEntry(index) == vf::gpu::FLUID_FCC
-                                            || grid->getFieldEntry(index) == vf::gpu::FLUID_FCF ) )
+                                            || grid->getFieldEntry(index) == vf::gpu::FLUID_FCF ))
             {
                 grid->setFieldEntry(index, boundaryCondition->getType());
                 boundaryCondition->indices.push_back(index);
@@ -133,6 +133,7 @@ void Side::setQs(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition, uin
             qNode[dir] = 0.5;
         else
             qNode[dir] = -1.0;
+
     }
 
     boundaryCondition->qs.push_back(qNode);
@@ -149,6 +150,7 @@ uint Side::getIndex(SPtr<Grid> grid, std::string coord, real constant, real v1,
     return INVALID_INDEX;
 }
 
+
 void Geometry::addIndices(std::vector<SPtr<Grid> > grids, uint level, SPtr<BoundaryCondition> boundaryCondition)
 {
     auto geometryBoundaryCondition = std::dynamic_pointer_cast<GeometryBoundaryCondition>(boundaryCondition);
@@ -188,6 +190,8 @@ void Geometry::addIndices(std::vector<SPtr<Grid> > grids, uint level, SPtr<Bound
     }
 }
 
+
+
 void MX::addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCondition> boundaryCondition)
 {
     real startInner = grid[level]->getStartY();
@@ -277,6 +281,6 @@ void PZ::addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCond
     real coordinateNormal = grid[level]->getEndZ() - grid[level]->getDelta();
 
     if( coordinateNormal < grid[0]->getEndZ() - grid[0]->getDelta() ) return;
-
+    
     Side::addIndices(grid[level], boundaryCondition, "z", coordinateNormal, startInner, endInner, startOuter, endOuter);
 }
diff --git a/src/gpu/GridGenerator/grid/Cell.h b/src/gpu/GridGenerator/grid/Cell.h
index a7a649170..f39bd4a7b 100644
--- a/src/gpu/GridGenerator/grid/Cell.h
+++ b/src/gpu/GridGenerator/grid/Cell.h
@@ -33,7 +33,7 @@
 #ifndef CELL_H
 #define CELL_H
 
-#include "global.h"
+#include "gpu/GridGenerator/global.h"
 
 struct Point
 {
diff --git a/src/gpu/GridGenerator/grid/Field.h b/src/gpu/GridGenerator/grid/Field.h
index 002c8c108..08fff6da7 100644
--- a/src/gpu/GridGenerator/grid/Field.h
+++ b/src/gpu/GridGenerator/grid/Field.h
@@ -33,7 +33,7 @@
 #ifndef FIELD_H
 #define FIELD_H
 
-#include "global.h"
+#include "gpu/GridGenerator/global.h"
 
 struct Vertex;
 
diff --git a/src/gpu/GridGenerator/grid/Grid.h b/src/gpu/GridGenerator/grid/Grid.h
index 3407b23c1..4dcc99c16 100644
--- a/src/gpu/GridGenerator/grid/Grid.h
+++ b/src/gpu/GridGenerator/grid/Grid.h
@@ -28,18 +28,18 @@
 //
 //! \file Grid.h
 //! \ingroup grid
-//! \author Soeren Peters, Stephan Lenz, Martin Schönherr
+//! \author Soeren Peters, Stephan Lenz, Martin Sch�nherr
 //=======================================================================================
 #ifndef GRID_H
 #define GRID_H
 
 #include "Core/LbmOrGks.h"
 
-#include "global.h"
+#include "gpu/GridGenerator/global.h"
 
-#include "geometries/Vertex/Vertex.h"
+#include "gpu/GridGenerator/geometries/Vertex/Vertex.h"
 
-#include "grid/Cell.h"
+#include "gpu/GridGenerator/grid/Cell.h"
 
 class TriangularMesh;
 struct Vertex;
@@ -165,7 +165,7 @@ public:
     virtual uint getSendIndex(int direction, uint index)    = 0;
     virtual uint getReceiveIndex(int direction, uint index) = 0;
 
-    virtual void repairCommunicationInices(int direction) = 0;
+    virtual void repairCommunicationIndices(int direction) = 0;
 
 };
 
diff --git a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h
index 57290025c..90713bfef 100644
--- a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h
+++ b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h
@@ -28,7 +28,7 @@
 //
 //! \file GridBuilder.h
 //! \ingroup grid
-//! \author Soeren Peters, Stephan Lenz, Martin Schönherr
+//! \author Soeren Peters, Stephan Lenz, Martin Sch�nherr
 //=======================================================================================
 #ifndef GridBuilder_H
 #define GridBuilder_H
@@ -37,7 +37,7 @@
 #include <string>
 #include <memory>
 
-#include "GridGenerator/global.h"
+#include "gpu/GridGenerator/global.h"
 
 #define GEOMQS 6
 #define INLETQS 0
@@ -124,5 +124,4 @@ public:
     virtual void getReceiveIndices(int *sendIndices, int direction, int level) = 0;
 };
 
-#endif
-
+#endif
\ No newline at end of file
diff --git a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp
index aa593ad7f..41d2cf5af 100644
--- a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp
+++ b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp
@@ -34,6 +34,7 @@
 
 #include <stdio.h>
 #include <iostream>
+#include <algorithm>
 
 #include "geometries/Arrow/ArrowImp.h"
 #include "geometries/BoundingBox/BoundingBox.h"
@@ -84,7 +85,6 @@ void LevelGridBuilder::setSlipBoundaryCondition(SideType sideType, real nomalX,
     slipBoundaryCondition->side->addIndices(grids, 0, slipBoundaryCondition);
 
     slipBoundaryCondition->fillSlipNormalLists();
-
     boundaryConditions[0]->slipBoundaryConditions.push_back(slipBoundaryCondition);
 
     *logging::out << logging::Logger::INFO_INTERMEDIATE << "Set Slip BC on level " << 0 << " with " << (int)slipBoundaryCondition->indices.size() << "\n";
@@ -96,38 +96,41 @@ void LevelGridBuilder::setVelocityBoundaryCondition(SideType sideType, real vx,
         setVelocityGeometryBoundaryCondition(vx, vy, vz);
     else
     {
-        SPtr<VelocityBoundaryCondition> velocityBoundaryCondition = VelocityBoundaryCondition::make(vx, vy, vz);
+        for (uint level = 0; level < getNumberOfGridLevels(); level++)
+        {
+            SPtr<VelocityBoundaryCondition> velocityBoundaryCondition = VelocityBoundaryCondition::make(vx, vy, vz);
 
-        auto side = SideFactory::make(sideType);
+            auto side = SideFactory::make(sideType);
 
-        velocityBoundaryCondition->side = side;
-        velocityBoundaryCondition->side->addIndices(grids, 0, velocityBoundaryCondition);
+            velocityBoundaryCondition->side = side;
+            velocityBoundaryCondition->side->addIndices(grids, level, velocityBoundaryCondition);
 
-        velocityBoundaryCondition->fillVelocityLists();
+            velocityBoundaryCondition->fillVelocityLists();
 
-        boundaryConditions[0]->velocityBoundaryConditions.push_back(velocityBoundaryCondition);
+            boundaryConditions[level]->velocityBoundaryConditions.push_back(velocityBoundaryCondition);
 
-        *logging::out << logging::Logger::INFO_INTERMEDIATE << "Set Velocity BC on level " << 0 << " with " << (int)velocityBoundaryCondition->indices.size() <<"\n";
+            *logging::out << logging::Logger::INFO_INTERMEDIATE << "Set Velocity BC on level " << level << " with " << (int)velocityBoundaryCondition->indices.size() <<"\n";
+        }
     }
 }
 
 void LevelGridBuilder::setVelocityGeometryBoundaryCondition(real vx, real vy, real vz)
 {
     geometryHasValues = true;
-    
+
     for (uint level = 0; level < getNumberOfGridLevels(); level++)
     {
-        if (boundaryConditions[level]->geometryBoundaryCondition != nullptr)
-        {
-            boundaryConditions[level]->geometryBoundaryCondition->vx = vx;
-            boundaryConditions[level]->geometryBoundaryCondition->vy = vy;
-            boundaryConditions[level]->geometryBoundaryCondition->vz = vz;
-            boundaryConditions[level]->geometryBoundaryCondition->side->addIndices(grids, level, boundaryConditions[level]->geometryBoundaryCondition);
+		if (boundaryConditions[level]->geometryBoundaryCondition != nullptr)
+		{
+			boundaryConditions[level]->geometryBoundaryCondition->vx = vx;
+			boundaryConditions[level]->geometryBoundaryCondition->vy = vy;
+			boundaryConditions[level]->geometryBoundaryCondition->vz = vz;
+			boundaryConditions[level]->geometryBoundaryCondition->side->addIndices(grids, level, boundaryConditions[level]->geometryBoundaryCondition);
 
             boundaryConditions[level]->geometryBoundaryCondition->fillVelocityLists();
 
             *logging::out << logging::Logger::INFO_INTERMEDIATE << "Set Geometry Velocity BC on level " << level << " with " << (int)boundaryConditions[level]->geometryBoundaryCondition->indices.size() <<"\n";
-        }
+		}
     }
 }
 
@@ -166,8 +169,7 @@ void LevelGridBuilder::setNoSlipBoundaryCondition(SideType sideType)
 
         noSlipBoundaryCondition->fillVelocityLists();
 
-        // effectively just a wrapper for velocityBC with zero velocity. No distinction in GridGenerator.
-        boundaryConditions[level]->velocityBoundaryConditions.push_back(noSlipBoundaryCondition);
+        boundaryConditions[level]->velocityBoundaryConditions.push_back(noSlipBoundaryCondition); //now effectively just a wrapper for velocityBC with zero velocity. No distinction in Gridgenerator.
     }
 }
 
@@ -293,7 +295,6 @@ uint LevelGridBuilder::getNumberOfNodes(unsigned int level) const
     return grids[level]->getSparseSize();
 }
 
-
 std::shared_ptr<Grid> LevelGridBuilder::getGrid(int level, int box)
 {
     return this->grids[level];
diff --git a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h
index b4a461ec7..8be699c09 100644
--- a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h
+++ b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h
@@ -38,11 +38,12 @@
 #include <memory>
 #include <array>
 
-#include "global.h"
+#include "gpu/GridGenerator/global.h"
 
-#include "grid/GridBuilder/GridBuilder.h"
-#include "grid/Grid.h"
-#include "grid/NodeValues.h"
+#include "gpu/GridGenerator/grid/GridBuilder/GridBuilder.h"
+#include "gpu/GridGenerator/grid/Grid.h"
+#include "gpu/GridGenerator/grid/GridInterface.h"
+#include "gpu/GridGenerator/grid/NodeValues.h"
 
 struct Vertex;
 class  Grid;
@@ -54,6 +55,7 @@ class BoundingBox;
 class Side;
 class VelocityBoundaryCondition;
 class SlipBoundaryCondition;
+class StressBoundaryCondition;
 class PressureBoundaryCondition;
 class GeometryBoundaryCondition;
 enum class SideType;
@@ -127,6 +129,8 @@ protected:
 
         std::vector<SPtr<SlipBoundaryCondition>> slipBoundaryConditions;
 
+        std::vector<SPtr<StressBoundaryCondition>> stressBoundaryConditions;
+
         std::vector<SPtr<VelocityBoundaryCondition>> velocityBoundaryConditions;
 
         std::vector<SPtr<PressureBoundaryCondition>> pressureBoundaryConditions;
diff --git a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp
index c36a8cb70..da18a8831 100644
--- a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp
+++ b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp
@@ -49,14 +49,14 @@
 #include "io/GridVTKWriter/GridVTKWriter.h"
 #include "io/STLReaderWriter/STLWriter.h"
 
-MultipleGridBuilder::MultipleGridBuilder() : LevelGridBuilder(), numberOfLayersFine(12), numberOfLayersBetweenLevels(8), subDomainBox(nullptr)
+MultipleGridBuilder::MultipleGridBuilder(SPtr<GridFactory> gridFactory) : LevelGridBuilder(), gridFactory(gridFactory), numberOfLayersFine(12), numberOfLayersBetweenLevels(8), subDomainBox(nullptr)
 {
 
 }
 
-SPtr<MultipleGridBuilder> MultipleGridBuilder::makeShared()
+SPtr<MultipleGridBuilder> MultipleGridBuilder::makeShared(SPtr<GridFactory> gridFactory)
 {
-    return SPtr<MultipleGridBuilder>(new MultipleGridBuilder());
+    return SPtr<MultipleGridBuilder>(new MultipleGridBuilder(gridFactory));
 }
 
 void MultipleGridBuilder::addCoarseGrid(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta)
@@ -195,7 +195,7 @@ void MultipleGridBuilder::addGridToListIfValid(SPtr<Grid> grid)
 
 SPtr<Grid> MultipleGridBuilder::makeGrid(Object* gridShape, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, uint level) const
 {
-    return GridImp::makeShared(gridShape, startX, startY, startZ, endX, endY, endZ, delta, "D3Q27", level);
+    return gridFactory->makeGrid(gridShape, startX, startY, startZ, endX, endY, endZ, delta, level);
 }
 
 bool MultipleGridBuilder::coarseGridExists() const
diff --git a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h
index 839e0036b..9627fb0bf 100644
--- a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h
+++ b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h
@@ -41,6 +41,7 @@
 #include "global.h"
 
 #include "grid/GridBuilder/LevelGridBuilder.h"
+#include "grid/GridFactory.h"
 #include "grid/distributions/Distribution.h"
 
 class Object;
@@ -49,10 +50,10 @@ class BoundingBox;
 class MultipleGridBuilder : public LevelGridBuilder
 {
 private:
-    GRIDGENERATOR_EXPORT MultipleGridBuilder();
+    GRIDGENERATOR_EXPORT MultipleGridBuilder(SPtr<GridFactory> gridFactory);
 
 public:
-    GRIDGENERATOR_EXPORT static SPtr<MultipleGridBuilder> makeShared();
+    GRIDGENERATOR_EXPORT static SPtr<MultipleGridBuilder> makeShared(SPtr<GridFactory> gridFactory);
 
     GRIDGENERATOR_EXPORT void addCoarseGrid(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta);
     GRIDGENERATOR_EXPORT void addGrid(Object *gridShape);
@@ -103,6 +104,7 @@ private:
     static void emitNoCoarseGridExistsWarning();
     static void emitGridIsNotInCoarseGridWarning();
 
+    SPtr<GridFactory> gridFactory;
     Object *solidObject = nullptr;
 
     uint numberOfLayersFine;
diff --git a/src/gpu/GridGenerator/grid/GridFactory.h b/src/gpu/GridGenerator/grid/GridFactory.h
index b525596fa..53d358d53 100644
--- a/src/gpu/GridGenerator/grid/GridFactory.h
+++ b/src/gpu/GridGenerator/grid/GridFactory.h
@@ -36,6 +36,7 @@
 #include "global.h"
 
 #include "geometries/Cuboid/Cuboid.h"
+#include "geometries/TriangularMesh/TriangularMeshStrategy.h"
 
 #include "grid/GridImp.h"
 
@@ -54,8 +55,33 @@ public:
 
     SPtr<Grid> makeGrid(Object* gridShape, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, uint level, const std::string& d3Qxx = "D3Q27")
     {
-        return GridImp::makeShared(gridShape, startX, startY, startZ, endX, endY, endZ, delta, d3Qxx, level);
+        SPtr<GridImp> grid;
+        
+        grid = GridImp::makeShared(gridShape, startX, startY, startZ, endX, endY, endZ, delta, d3Qxx, level);
+
+        grid->setTriangularMeshDiscretizationStrategy(new PointInObjectDiscretizationStrategy());
+
+        return grid;
+    }
+
+    void setTriangularMeshDiscretizationMethod(TriangularMeshDiscretizationMethod triangularMeshDiscretizationMethod)
+    {
+        switch (triangularMeshDiscretizationMethod)
+        {
+        case TriangularMeshDiscretizationMethod::POINT_UNDER_TRIANGLE:
+            triangularMeshDiscretizationStrategy = new PointUnderTriangleStrategy();
+            break;
+        case TriangularMeshDiscretizationMethod::RAYCASTING:
+            triangularMeshDiscretizationStrategy = new RayCastingDiscretizationStrategy();
+            break;
+        case TriangularMeshDiscretizationMethod::POINT_IN_OBJECT:
+            triangularMeshDiscretizationStrategy = new PointInObjectDiscretizationStrategy();
+            break;
+        }
     }
+
+private:
+    TriangularMeshDiscretizationStrategy* triangularMeshDiscretizationStrategy;
 };
 
 
diff --git a/src/gpu/GridGenerator/grid/GridImp.cpp b/src/gpu/GridGenerator/grid/GridImp.cpp
index 0d1a6c347..66d90b82d 100644
--- a/src/gpu/GridGenerator/grid/GridImp.cpp
+++ b/src/gpu/GridGenerator/grid/GridImp.cpp
@@ -37,6 +37,7 @@
 #include <iostream>
 #include <omp.h>
 #include <sstream>
+# include <algorithm>
 #include <cmath>
 
 #include "global.h"
@@ -160,24 +161,24 @@ void GridImp::inital(const SPtr<Grid> fineGrid, uint numberOfLayers)
 #pragma omp parallel for
         for (int xIdx = 0; xIdx < (int)this->nx; xIdx++) {
             for (uint yIdx = 0; yIdx < this->ny; yIdx++) {
-                this->fixRefinementIntoWall(xIdx, yIdx, 0, 3);
-                this->fixRefinementIntoWall(xIdx, yIdx, this->nz - 1, -3);
+                this->fixRefinementIntoWall( xIdx, yIdx, 0           ,  3 );
+                this->fixRefinementIntoWall( xIdx, yIdx, this->nz - 1, -3 );
             }
         }
 
 #pragma omp parallel for
         for (int xIdx = 0; xIdx < (int)this->nx; xIdx++) {
             for (uint zIdx = 0; zIdx < this->nz; zIdx++) {
-                this->fixRefinementIntoWall(xIdx, 0, zIdx, 2);
-                this->fixRefinementIntoWall(xIdx, this->ny - 1, zIdx, -2);
+                this->fixRefinementIntoWall( xIdx, 0           , zIdx,  2 );
+                this->fixRefinementIntoWall( xIdx, this->ny - 1, zIdx, -2 );
             }
         }
 
 #pragma omp parallel for
         for (int yIdx = 0; yIdx < (int)this->ny; yIdx++) {
             for (uint zIdx = 0; zIdx < this->nz; zIdx++) {
-                this->fixRefinementIntoWall(0, yIdx, zIdx, 1);
-                this->fixRefinementIntoWall(this->nx - 1, yIdx, zIdx, -1);
+                this->fixRefinementIntoWall( 0           , yIdx, zIdx,  1 );
+                this->fixRefinementIntoWall( this->nx - 1, yIdx, zIdx, -1 );
             }
         }
     }
@@ -186,7 +187,7 @@ void GridImp::inital(const SPtr<Grid> fineGrid, uint numberOfLayers)
 #pragma omp parallel for
     for (int index = 0; index < (int)this->size; index++)
         this->findEndOfGridStopperNode(index);
-
+    
     *logging::out << logging::Logger::INFO_INTERMEDIATE
         << "Grid created: " << "from (" << this->startX << ", " << this->startY << ", " << this->startZ << ") to (" << this->endX << ", " << this->endY << ", " << this->endZ << ")\n"
         << "nodes: " << this->nx << " x " << this->ny << " x " << this->nz << " = " << this->size << "\n";
@@ -440,7 +441,7 @@ void GridImp::findEndOfGridStopperNode(uint index)
         else
             this->field.setFieldEntryToStopperOutOfGridBoundary(index);
     }
-
+    
 	if (isValidEndOfGridBoundaryStopper(index))
 		this->field.setFieldEntryToStopperOutOfGridBoundary(index);
 }
@@ -1167,7 +1168,7 @@ void GridImp::findInvalidBoundaryNodes(uint index)
 // --------------------------------------------------------- //
 void GridImp::mesh(Object* object)
 {
-    TriangularMesh* triangularMesh = dynamic_cast<TriangularMesh*>(object);
+    TriangularMesh *triangularMesh = dynamic_cast<TriangularMesh *>(object);
     if (triangularMesh)
         triangularMeshDiscretizationStrategy->discretize(triangularMesh, this, INVALID_SOLID, FLUID);
     else
@@ -1234,6 +1235,7 @@ void GridImp::closeNeedleCells()
     uint numberOfClosedNeedleCells = 0;
 
     do{
+        numberOfClosedNeedleCells = 0;
 #pragma omp parallel for reduction(+ : numberOfClosedNeedleCells)
         for (int index = 0; index < (int)this->size; index++) {
             if (this->closeCellIfNeedle(index))
@@ -1274,6 +1276,7 @@ void GridImp::closeNeedleCellsThinWall()
     uint numberOfClosedNeedleCells = 0;
 
     do{
+        numberOfClosedNeedleCells = 0;
 #pragma omp parallel for reduction(+ : numberOfClosedNeedleCells)
         for (int index = 0; index < (int)this->size; index++) {
             if (this->closeCellIfNeedleThinWall(index))
@@ -1457,7 +1460,6 @@ void GridImp::calculateQs(const uint index, const Vertex &point, Object* object)
                     
                 this->qPatches[ this->qIndices[index] ] = 0;
 
-				//printf("%d %f \n", this->qIndices[index], subdistance);
 			}
 		}
 	}
@@ -1657,7 +1659,7 @@ uint GridImp::getReceiveIndex(int direction, uint index)
     return this->communicationIndices[direction].receiveIndices[ index ];
 }
 
-void GridImp::repairCommunicationInices(int direction )
+void GridImp::repairCommunicationIndices(int direction)
 {
     this->communicationIndices[direction].sendIndices.insert( this->communicationIndices[direction].sendIndices.end(), 
                                                               this->communicationIndices[direction+1].sendIndices.begin(), 
@@ -1772,18 +1774,18 @@ real GridImp::getMaximumOnNodes(const real &maxExact, const real &decimalStart,
 }
 
 uint GridImp::getXIndex(real x) const 
-{
-    return std::lround((x - startX) / delta);
+{ 
+    return std::lround((x - startX) / delta); 
 }
 
 uint GridImp::getYIndex(real y) const
-{
-    return std::lround((y - startY) / delta);
+{ 
+    return std::lround((y - startY) / delta); 
 }
 
 uint GridImp::getZIndex(real z) const
-{
-	return std::lround((z - startZ) / delta);
+{ 
+    return std::lround((z - startZ) / delta); 
 }
 
 real GridImp::getDelta() const
@@ -1798,7 +1800,7 @@ uint GridImp::getSize() const
 
 uint GridImp::getSparseSize() const
 {
-    return this->sparseSize;
+    return this->sparseSize; 
 }
 
 Field GridImp::getField() const
@@ -1955,7 +1957,7 @@ void GridImp::getNodeValues(real *xCoords, real *yCoords, real *zCoords, uint *n
     geo[0] = GEOSOLID;
 
     int nodeNumber = 0;
-    for (uint i = 0; i < this->getSize(); i++)
+    for (uint i = 0; i < this->size; i++)
     {
         if (this->sparseIndices[i] == -1)
             continue;
@@ -1991,4 +1993,4 @@ void GridImp::print() const
            endX, endY, endZ, size, delta);
     if(this->gridInterface)
         this->gridInterface->print();
-}
\ No newline at end of file
+}
diff --git a/src/gpu/GridGenerator/grid/GridImp.h b/src/gpu/GridGenerator/grid/GridImp.h
index 6d6000b67..2101d5517 100644
--- a/src/gpu/GridGenerator/grid/GridImp.h
+++ b/src/gpu/GridGenerator/grid/GridImp.h
@@ -37,12 +37,12 @@
 
 #include "Core/LbmOrGks.h"
 
-#include "global.h"
+#include "gpu/GridGenerator/global.h"
 
-#include "grid/distributions/Distribution.h"
-#include "grid/Grid.h"
-#include "grid/Cell.h"
-#include "grid/Field.h" 
+#include "gpu/GridGenerator/grid/distributions/Distribution.h"
+#include "gpu/GridGenerator/grid/Grid.h"
+#include "gpu/GridGenerator/grid/Cell.h"
+#include "gpu/GridGenerator/grid/Field.h" 
 
 class TriangularMesh;
 struct Vertex;
@@ -70,7 +70,7 @@ extern int DIRECTIONS[DIR_END_MAX][DIMENSION];
 
 class GRIDGENERATOR_EXPORT GridImp : public enableSharedFromThis<GridImp>, public Grid
 {
-private:
+protected:
     GridImp() = default;
     GridImp(Object* object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, Distribution d, uint level);
 
@@ -126,7 +126,7 @@ private:
 
     TriangularMeshDiscretizationStrategy *triangularMeshDiscretizationStrategy;
 
-    uint numberOfSolidBoundaryNodes;
+    uint numberOfSolidBoundaryNodes = 0;
 
     bool enableFixRefinementIntoTheWall;
 
@@ -209,7 +209,7 @@ public:
     bool isNode(uint index, char type) const;
     bool nodeInNextCellIs(int index, char type) const;
     bool hasAllNeighbors(uint index) const;
-    bool hasNeighborOfType(uint index, char type)const;
+    bool hasNeighborOfType(uint index, char type) const;
     bool cellContainsOnly(Cell &cell, char type) const;
     bool cellContainsOnly(Cell &cell, char typeA, char typeB) const;
 
@@ -246,6 +246,7 @@ public:
     uint getNumberOfNodesCF() const override;
     uint getNumberOfNodesFC() const override;
     void getGridInterfaceIndices(uint *iCellCfc, uint *iCellCff, uint *iCellFcc, uint *iCellFcf) const override;
+
     static void getGridInterface(uint *gridInterfaceList, const uint *oldGridInterfaceList, uint size);
 
     int *getNeighborsX() const override;
@@ -305,7 +306,11 @@ public:
     void findQsPrimitive(Object *object);
 
 private:
-    enum class qComputationStageType { FindSolidBoundaryNodes, ComputeQs } qComputationStage;
+
+    enum class qComputationStageType{
+        FindSolidBoundaryNodes,
+        ComputeQs
+    } qComputationStage;
 
 public:
     void enableFindSolidBoundaryNodes() override
@@ -336,7 +341,7 @@ public:
     uint getSendIndex(int direction, uint index) override;
     uint getReceiveIndex(int direction, uint index) override;
 
-    void repairCommunicationInices(int direction) override;
+    void repairCommunicationIndices(int direction) override;
 
 public:
     struct CommunicationIndices {
diff --git a/src/gpu/GridGenerator/grid/GridInterface.h b/src/gpu/GridGenerator/grid/GridInterface.h
index 303d79d49..b5f71317e 100644
--- a/src/gpu/GridGenerator/grid/GridInterface.h
+++ b/src/gpu/GridGenerator/grid/GridInterface.h
@@ -33,7 +33,7 @@
 #ifndef GRID_INTERFACE_H
 #define GRID_INTERFACE_H
 
-#include "global.h"
+#include "gpu/GridGenerator/global.h"
 
 class GridImp;
 
diff --git a/src/gpu/GridGenerator/grid/distributions/Distribution.h b/src/gpu/GridGenerator/grid/distributions/Distribution.h
index abc6d8105..7982abc23 100644
--- a/src/gpu/GridGenerator/grid/distributions/Distribution.h
+++ b/src/gpu/GridGenerator/grid/distributions/Distribution.h
@@ -36,7 +36,7 @@
 #include <vector>
 #include <string>
 
-#include "global.h"
+#include "gpu/GridGenerator/global.h"
 
 #define DIR_END_MAX 27
 
diff --git a/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.cpp b/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.cpp
index 173f79c18..d3eb22126 100644
--- a/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.cpp
+++ b/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.cpp
@@ -118,7 +118,7 @@ std::vector<Triangle> STLReader::readASCIISTLWithPatches(const std::string& name
     std::ifstream file;
     file.open(name.c_str(), std::ifstream::in);
 
-    if( !file.is_open() ) throw std::runtime_error(name + "cannot be opened!");
+    if( !file.is_open() ) throw std::runtime_error(name + " cannot be opened!");
 
     uint currentPatchIndex = 0;
 
diff --git a/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h b/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h
index d5d2a377b..4a4552f74 100644
--- a/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h
+++ b/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h
@@ -42,7 +42,7 @@
 
 #include "Core/NonCreatable.h"
 
-#include "global.h"
+#include "gpu/GridGenerator/global.h"
 
 class UnstructuredGridBuilder;
 class GridBuilder;
-- 
GitLab