diff --git a/apps/cpu/TPMSRow/TPMSRow.cpp b/apps/cpu/TPMSRow/TPMSRow.cpp
index df5c8c88db5b084f1c4f000b10ae5ddfce6a24cd..045739ad3989365ec8b8ad026c23900c1b7c29c0 100644
--- a/apps/cpu/TPMSRow/TPMSRow.cpp
+++ b/apps/cpu/TPMSRow/TPMSRow.cpp
@@ -163,6 +163,9 @@ void run(string configname)
         SPtr<BCProcessor> bcProc(new BCProcessor());
         kernel->setBCProcessor(bcProc);
 
+       
+
+        
 
             SPtr<Grid3DVisitor> metisVisitor(new MetisPartitioningGridVisitor(
                 comm, MetisPartitioningGridVisitor::LevelIntersected, DIR_00M, MetisPartitioner::RECURSIVE));
@@ -177,6 +180,8 @@ void run(string configname)
         //////////////////////////////////////////////////////////////////////////
 
         if (newStart) {
+
+        
             //GbGyroidThirdOrderPtr tpms;
             // // tpms = GbGyroidThirdOrderPtr(new GbGyroidThirdOrder(0, 0, 0, TPMSL[0], TPMSL[1], TPMSL[2], UnitEdgeLength,
             // // dx));
@@ -255,11 +260,25 @@ void run(string configname)
             GenBlocksGridVisitor genBlocks(gridCube);
             grid->accept(genBlocks);
 
+        if (refineLevel > 0)
+         {
+             //refinement area
+            //SPtr<GbObject3D> refCube(new  GbCuboid3D(TPMSOrigin[0],TPMSOrigin[1],TPMSOrigin[2],TPMSL[0],TPMSL[1],TPMSL[2]));
+            //if (myid == 0) GbSystem3D::writeGeoObject(refCube.get(), pathname + "/geo/refCube", WbWriterVtkXmlASCII::getInstance());
+            
+            if (myid == 0) UBLOG(logINFO, "Refinement - start");
+            RefineCrossAndInsideGbObjectHelper refineHelper(grid, refineLevel, comm);
+            //refineHelper.addGbObject(sphere, refineLevel);
+            refineHelper.addGbObject(tpms, refineLevel);
+            refineHelper.refine();
+            if (myid == 0) UBLOG(logINFO, "Refinement - end");
+         }
+
             SPtr<CoProcessor> ppblocks(new WriteBlocksCoProcessor(grid, SPtr<UbScheduler>(new UbScheduler(1)), pathname,
                                                                   WbWriterVtkXmlBinary::getInstance(), comm));
 
             ppblocks->process(0);
-
+            
             // GbObject3DPtr solidcube(new GbCuboid3D(0, g_minX2, g_minX3, TPMSL[0], g_maxX2, g_maxX3));
             // if (myid == 0) GbSystem3D::writeGeoObject(solidcube.get(), pathname + "/geo/solidcube",
             // WbWriterVtkXmlBinary::getInstance());
diff --git a/src/basics/geometry3d/GbGeneralThirdOrderImplicitSurface.cpp b/src/basics/geometry3d/GbGeneralThirdOrderImplicitSurface.cpp
index 7eff6f215eda72b049d615395737c7dd9c0bf1a7..61078464ebc46c26142ad5289d167f83aa4919f3 100644
--- a/src/basics/geometry3d/GbGeneralThirdOrderImplicitSurface.cpp
+++ b/src/basics/geometry3d/GbGeneralThirdOrderImplicitSurface.cpp
@@ -192,14 +192,27 @@ bool GbGeneralThirdOrderImplicitSurface::isPointInGbObject3D(const double& x1, c
 	// 	if (f < 10.0E-15 && f > -10.0E-15)
 		//if (fabs(f) <= 10e-15)
 	 //if (f <= 0)
-	if (f1 <= 0. && f2 >= 0.)
-{
-	return true;
-}
-else
-{
-	return false;
-}
+	 if (UbMath::less(x1, this->getX1Minimum()))
+        return false;
+    else if (UbMath::less(x2, this->getX2Minimum()))
+        return false;
+    else if (UbMath::less(x3, this->getX3Minimum()))
+        return false;
+    else if (UbMath::greater(x1, this->getX1Maximum()))
+        return false;
+    else if (UbMath::greater(x2, this->getX2Maximum()))
+        return false;
+    else if (UbMath::greater(x3, this->getX3Maximum()))
+        return false;
+	 if (UbMath::lessEqual(f1,0.) && UbMath::greaterEqual(f2,0.) )
+		{
+			return true;
+		}
+		else
+		{
+			return false;
+		} 
+
 }
 
 /*==========================================================*/