From cf0ffa19336475e4e9850030aca1f28ad6a7ac5d Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Thu, 17 Aug 2017 10:58:56 +0100
Subject: [PATCH] BUG: nearWallFields: point on the face is inside/outside any
 tet.

Now we directly releate the intersected face triangle to the tet of the
cell the point is on/in. We hope that the tracking handles this ok. Fixes #549.
---
 .../field/nearWallFields/nearWallFields.C     | 65 +++++++++++++------
 1 file changed, 44 insertions(+), 21 deletions(-)

diff --git a/src/functionObjects/field/nearWallFields/nearWallFields.C b/src/functionObjects/field/nearWallFields/nearWallFields.C
index 2744a95919b..abf2e0d4002 100644
--- a/src/functionObjects/field/nearWallFields/nearWallFields.C
+++ b/src/functionObjects/field/nearWallFields/nearWallFields.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -77,6 +77,7 @@ void Foam::functionObjects::nearWallFields::calcAddressing()
 
         vectorField nf(patch.nf());
         vectorField faceCellCentres(patch.patch().faceCellCentres());
+        const labelUList& faceCells = patch.patch().faceCells();
 
         forAll(patch, patchFacei)
         {
@@ -95,40 +96,62 @@ void Foam::functionObjects::nearWallFields::calcAddressing()
             );
 
 
+            // Starting point and tet
             point start;
+            label tetFacei = -1;
+            label tetPti = -1;
+            const label celli = faceCells[patchFacei];
+
             if (startInfo.hit())
             {
+                // Move start point slightly in so it is inside the tet
+                const face& f = mesh_.faces()[meshFacei];
+
+                tetFacei = meshFacei;
+                tetPti = (startInfo.index()+1) % f.size();
+
                 start = startInfo.hitPoint();
+                //// Uncomment below to shift slightly in:
+                //tetIndices tet(celli, meshFacei, tetPti, mesh_);
+                //start =
+                //    (1.0-1e-6)*startInfo.hitPoint()
+                //  + 1e-6*tet.tet(mesh_).centre();
             }
             else
             {
                 // Fallback: start tracking from neighbouring cell centre
                 start = faceCellCentres[patchFacei];
+                mesh_.findTetFacePt(celli, start, tetFacei, tetPti);
             }
 
             const point end = start-distance_*nf[patchFacei];
 
-            // Find tet for starting location
-            label celli = -1;
-            label tetFacei = -1;
-            label tetPti = -1;
-            mesh_.findCellFacePt(start, celli, tetFacei, tetPti);
-
-            // Add to cloud. Add originating face as passive data
-            cloud.addParticle
-            (
-                new findCellParticle
+            if (tetFacei == -1)
+            {
+                WarningInFunction << "Did not find point " << start
+                    << " inside cell " << celli
+                    << ". Not seeding particle originating from face centre "
+                    << mesh_.faceCentres()[meshFacei]
+                    << " with cell centre " << mesh_.cellCentres()[celli]
+                    << endl;
+            }
+            else
+            {
+                // Add to cloud. Add originating face as passive data
+                cloud.addParticle
                 (
-                    mesh_,
-                    start,
-                    celli,
-                    tetFacei,
-                    tetPti,
-                    end,
-                    globalWalls.toGlobal(nPatchFaces)    // passive data
-                )
-            );
-
+                    new findCellParticle
+                    (
+                        mesh_,
+                        start,
+                        celli,
+                        tetFacei,
+                        tetPti,
+                        end,
+                        globalWalls.toGlobal(nPatchFaces)    // passive data
+                    )
+                );
+            }
             nPatchFaces++;
         }
     }
-- 
GitLab