From 08c23685c340e87e04730d47f4f1410d7e8eca59 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 6 Feb 2024 09:26:55 +0100 Subject: [PATCH 1/5] BUG: incorrect cumulative area in triangulatedPatch (fixes #3097) BUG: bad processor selection. Failed to select anything on non-master --- .../triangulatedPatch/triangulatedPatch.C | 156 +++++++++++------- .../triangulatedPatch/triangulatedPatch.H | 19 ++- 2 files changed, 107 insertions(+), 68 deletions(-) diff --git a/src/meshTools/triangulatedPatch/triangulatedPatch.C b/src/meshTools/triangulatedPatch/triangulatedPatch.C index 513514cfbf..f80ec25595 100644 --- a/src/meshTools/triangulatedPatch/triangulatedPatch.C +++ b/src/meshTools/triangulatedPatch/triangulatedPatch.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2023 OpenCFD Ltd. + Copyright (C) 2023-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,7 +26,6 @@ License \*---------------------------------------------------------------------------*/ #include "triangulatedPatch.H" -#include "triPointRef.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -50,6 +49,8 @@ bool Foam::triangulatedPatch::randomPoint // Find corresponding decomposed face triangle // Note: triWght_ is sized nTri+1 (zero added at start) + // + // TBD: binary search with findLower(triWght_, c) ?? label trii = 0; for (label i = 0; i < triWght_.size() - 1; ++i) { @@ -62,11 +63,9 @@ bool Foam::triangulatedPatch::randomPoint // Find random point in triangle const pointField& points = patch_.points(); - const face& tf = triFace_[trii]; - const triPointRef tri(points[tf[0]], points[tf[1]], points[tf[2]]); - result = tri.randomPoint(rnd); - facei = triToFace_[trii]; + result = triFace_[trii].tri(points).randomPoint(rnd); + facei = triFace_[trii].index(); celli = patch_.faceCells()[facei]; if (perturbTol_ > 0) @@ -97,7 +96,6 @@ Foam::triangulatedPatch::triangulatedPatch patch_(patch), perturbTol_(perturbTol), triFace_(), - triToFace_(), triWght_() { update(); @@ -115,70 +113,95 @@ Foam::triangulatedPatch::triangulatedPatch {} +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +void Foam::triangulatedPatch::triangulate +( + const polyPatch& pp, + List& tris +) +{ + const pointField& points = pp.points(); + + // Triangulate the patch faces and create addressing + label nTris = 0; + for (const face& f : pp) + { + nTris += f.nTriangles(); + } + + DynamicList dynTris(nTris); + DynamicList tfaces(8); // work array + + label facei = 0; + for (const face& f : pp) + { + tfaces.clear(); + f.triangles(points, tfaces); + + for (const auto& t : tfaces) + { + dynTris.emplace_back(t[0], t[1], t[2], facei); + } + ++facei; + } + + tris.transfer(dynTris); +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::triangulatedPatch::update() { + triFace_.clear(); + triWght_.clear(); + + triangulate(patch_, triFace_); + const pointField& points = patch_.points(); - // Triangulate the patch faces and create addressing - DynamicList