From da8e668d0a19db2f8372eeaa2a91143d772b2ccb Mon Sep 17 00:00:00 2001
From: graham <g.macpherson@opencfd.co.uk>
Date: Thu, 25 Nov 2010 16:35:50 +0000
Subject: [PATCH] ENH: Don't always fatalError on a bad tet.

Some commented out debug code.  Smaller tolerance on tet quality.
---
 .../polyMeshTetDecomposition.C                | 16 +++----
 src/lagrangian/basic/Cloud/Cloud.H            |  6 ++-
 src/lagrangian/basic/Particle/Particle.C      | 42 +++++++++++++++++++
 src/lagrangian/basic/Particle/ParticleI.H     |  6 +--
 4 files changed, 59 insertions(+), 11 deletions(-)

diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.C b/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.C
index 4187da2d937..893a2996321 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.C
+++ b/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.C
@@ -29,8 +29,9 @@ License
 
 // Note: the use of this tolerance is ad-hoc, there may be extreme
 // cases where the resulting tetrahedra still have particle tracking
-// problems.
-const Foam::scalar Foam::polyMeshTetDecomposition::minTetQuality = SMALL;
+// problems, or tets with lower quality may track OK.
+// const Foam::scalar Foam::polyMeshTetDecomposition::minTetQuality = SMALL;
+const Foam::scalar Foam::polyMeshTetDecomposition::minTetQuality = ROOTVSMALL;
 
 
 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@@ -104,11 +105,10 @@ Foam::label Foam::polyMeshTetDecomposition::findSharedBasePoint
         {
             return faceBasePtI;
         }
-
     }
 
     // If a base point hasn't triggered a return by now, then there is
-    // non that can produce a good decomposition
+    // none that can produce a good decomposition
     return -1;
 }
 
@@ -554,15 +554,17 @@ Foam::List<Foam::tetIndices> Foam::polyMeshTetDecomposition::faceTetIndices
 
     if (tetBasePtI == -1)
     {
-        FatalErrorIn
+        WarningIn
         (
             "Foam::List<Foam::FixedList<Foam::label, 4> >"
             "Foam::Cloud<ParticleType>::"
             "faceTetIndices(label fI, label cI) const"
         )
-        << "No base point for face " << fI << ", " << f
+            << "No base point for face " << fI << ", " << f
             << ", produces a valid tet decomposition."
-            << abort(FatalError);
+            << endl;
+
+        tetBasePtI = 0;
     }
 
     for (label tetPtI = 1; tetPtI < f.size() - 1; tetPtI++)
diff --git a/src/lagrangian/basic/Cloud/Cloud.H b/src/lagrangian/basic/Cloud/Cloud.H
index 502dda53f71..43c423e42fa 100644
--- a/src/lagrangian/basic/Cloud/Cloud.H
+++ b/src/lagrangian/basic/Cloud/Cloud.H
@@ -253,7 +253,11 @@ public:
             //- Increment the nTrackingRescues counter
             void trackingRescue() const
             {
-                nTrackingRescues_++;
+                if (++nTrackingRescues_ % size() == 0)
+                {
+                    Info<< "    " << nTrackingRescues_
+                        << " tracking rescues " << endl;
+                }
             }
 
             //- Whether each cell has any wall faces (demand driven data)
diff --git a/src/lagrangian/basic/Particle/Particle.C b/src/lagrangian/basic/Particle/Particle.C
index fd0540a827d..1fb312298ec 100644
--- a/src/lagrangian/basic/Particle/Particle.C
+++ b/src/lagrangian/basic/Particle/Particle.C
@@ -264,6 +264,17 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
 
     faceI_ = -1;
 
+    // Pout<< "Particle " << origId_ << " " << origProc_
+    //     << " Tracking from " << position_
+    //     << " to " << endPosition
+    //     << endl;
+
+    // Pout<< "stepFraction " << stepFraction_ << nl
+    //     << "cellI " << cellI_ << nl
+    //     << "tetFaceI " << tetFaceI_ << nl
+    //     << "tetPtI " << tetPtI_
+    //     << endl;
+
     scalar trackFraction = 0.0;
 
     // Minimum tetrahedron decomposition of each cell of the mesh into
@@ -405,6 +416,8 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
         triI = -1;
         lambdaMin = VGREAT;
 
+        // Pout<< "tris " << tris << endl;
+
         // Sets a value for lambdaMin and faceI_ if a wall face is hit
         // by the track.
         hitWallFaces(position_, endPosition, lambdaMin, faceHitTetIs);
@@ -469,6 +482,35 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
             faceI_ = -1;
         }
 
+        // Pout<< "track loop " << position_ << " " << endPosition << nl
+        //     << "    " << cellI_
+        //     << "    " << faceI_
+        //     << " " << tetFaceI_
+        //     << " " << tetPtI_
+        //     << " " << triI
+        //     << " " << lambdaMin
+        //     << " " << trackFraction
+        //     << endl;
+
+        // Pout<< "# Tracking loop tet "
+        //     << origId_ << " " << origProc_<< nl
+        //     << "# face: " << tetFaceI_ << nl
+        //     << "# tetPtI: " << tetPtI_ << nl
+        //     << "# tetBasePtI: " << mesh.tetBasePtIs()[tetFaceI_] << nl
+        //     << "# tet.mag(): " << tet.mag() << nl
+        //     << "# tet.quality(): " << tet.quality()
+        //     << endl;
+
+        // meshTools::writeOBJ(Pout, tet.a());
+        // meshTools::writeOBJ(Pout, tet.b());
+        // meshTools::writeOBJ(Pout, tet.c());
+        // meshTools::writeOBJ(Pout, tet.d());
+
+        // Pout<< "f 1 3 2" << nl
+        //     << "f 2 3 4" << nl
+        //     << "f 1 4 3" << nl
+        //     << "f 1 2 4" << endl;
+
         // The particle can be 'outside' the tet.  This will yield a
         // lambda larger than 1, or smaller than 0.  For values < 0,
         // the particle travels away from the tet and we don't move
diff --git a/src/lagrangian/basic/Particle/ParticleI.H b/src/lagrangian/basic/Particle/ParticleI.H
index 0ef468ea2fe..cf135b3229a 100644
--- a/src/lagrangian/basic/Particle/ParticleI.H
+++ b/src/lagrangian/basic/Particle/ParticleI.H
@@ -343,9 +343,6 @@ inline void Foam::Particle<ParticleType>::tetNeighbour(label triI)
 
     label tetBasePtI = mesh.tetBasePtIs()[tetFaceI_];
 
-    label facePtI = (tetPtI_ + tetBasePtI) % f.size();
-    label otherFacePtI = f.fcIndex(facePtI);
-
     if (tetBasePtI == -1)
     {
         FatalErrorIn
@@ -357,6 +354,9 @@ inline void Foam::Particle<ParticleType>::tetNeighbour(label triI)
             << abort(FatalError);
     }
 
+    label facePtI = (tetPtI_ + tetBasePtI) % f.size();
+    label otherFacePtI = f.fcIndex(facePtI);
+
     switch (triI)
     {
         case 0:
-- 
GitLab