From 1be29879c7269081d1950f1d5852ea69d00fc94b Mon Sep 17 00:00:00 2001
From: Henry <Henry>
Date: Wed, 4 Feb 2015 23:06:31 +0000
Subject: [PATCH] isoSurfaceCellTemplates: Skip undefined tets Resolves
 bug-report http://www.openfoam.org/mantisbt/view.php?id=1506

---
 .../isoSurface/isoSurfaceCellTemplates.C      | 25 +++++++++++++++----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/sampling/sampledSurface/isoSurface/isoSurfaceCellTemplates.C b/src/sampling/sampledSurface/isoSurface/isoSurfaceCellTemplates.C
index 4a88c3d968e..c78aafeee50 100644
--- a/src/sampling/sampledSurface/isoSurface/isoSurfaceCellTemplates.C
+++ b/src/sampling/sampledSurface/isoSurface/isoSurfaceCellTemplates.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -117,7 +117,7 @@ void Foam::isoSurfaceCell::generateTriPoints
         triIndex |= 8;
     }
 
-    /* Form the vertices of the triangles for each case */
+    // Form the vertices of the triangles for each case
     switch (triIndex)
     {
         case 0x00:
@@ -303,6 +303,7 @@ void Foam::isoSurfaceCell::generateTriPoints
 ) const
 {
     tetMatcher tet;
+    label countNotFoundTets = 0;
 
     forAll(mesh_.cells(), cellI)
     {
@@ -395,16 +396,22 @@ void Foam::isoSurfaceCell::generateTriPoints
             }
             else
             {
-                const cell& cFaces = mesh_.cells()[cellI];
-
                 forAll(cFaces, cFaceI)
                 {
                     label faceI = cFaces[cFaceI];
                     const face& f = mesh_.faces()[faceI];
 
-                    const label fp0 = mesh_.tetBasePtIs()[faceI];
+                    label fp0 = mesh_.tetBasePtIs()[faceI];
+
+                    // Skip undefined tets
+                    if (fp0 < 0)
+                    {
+                        fp0 = 0;
+                        countNotFoundTets++;
+                    }
 
                     label fp = f.fcIndex(fp0);
+
                     for (label i = 2; i < f.size(); i++)
                     {
                         label nextFp = f.fcIndex(fp);
@@ -486,6 +493,14 @@ void Foam::isoSurfaceCell::generateTriPoints
         }
     }
 
+    if (countNotFoundTets > 0)
+    {
+        WarningIn("Foam::isoSurfaceCell::generateTriPoints")
+            << "Could not find " << countNotFoundTets
+            << " tet base points, which may lead to inverted triangles."
+            << endl;
+    }
+
     triPoints.shrink();
     triMeshCells.shrink();
 }
-- 
GitLab