From b9daa7b26551954a654450c99e91739ad90ac77b Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 21 Jan 2011 14:48:18 +0000 Subject: [PATCH] ENH: sampledTriSurfaceMesh : allow boundary-value sampling --- .../postProcessing/sampling/sample/sampleDict | 1 + .../sampledTriSurfaceMesh.C | 284 +++++++++++++++--- .../sampledTriSurfaceMesh.H | 29 +- .../sampledTriSurfaceMeshTemplates.C | 76 ++++- 4 files changed, 337 insertions(+), 53 deletions(-) diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index 2c7bbe35af..cd0ae63fe4 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -231,6 +231,7 @@ surfaces // Sampling on triSurface type sampledTriSurfaceMesh; surface integrationPlane.stl; + source boundaryFaces; // sample cells or boundaryFaces interpolate true; } ); diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C index 9a58dc41c2..859db2f9af 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,6 +28,7 @@ License #include "Tuple2.H" #include "globalIndex.H" #include "treeDataCell.H" +#include "treeDataFace.H" #include "addToRunTimeSelectionTable.H" @@ -43,6 +44,17 @@ namespace Foam word ); + template<> + const char* NamedEnum::names[] = + { + "cells", + "boundaryFaces" + }; + + const NamedEnum + sampledTriSurfaceMesh::samplingSourceNames_; + + //- Private class for finding nearest // - global index // - sqr(distance) @@ -70,7 +82,8 @@ Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh ( const word& name, const polyMesh& mesh, - const word& surfaceName + const word& surfaceName, + const samplingSource sampleSource ) : sampledSurface(name, mesh), @@ -78,7 +91,7 @@ Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh ( IOobject ( - name, + surfaceName, mesh.time().constant(), // instance "triSurface", // local mesh, // registry @@ -87,9 +100,10 @@ Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh false ) ), + sampleSource_(sampleSource), needsUpdate_(true), - cellLabels_(0), - pointToFace_(0) + sampleElements_(0), + samplePoints_(0) {} @@ -114,9 +128,10 @@ Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh false ) ), + sampleSource_(samplingSourceNames_[dict.lookup("source")]), needsUpdate_(true), - cellLabels_(0), - pointToFace_(0) + sampleElements_(0), + samplePoints_(0) {} @@ -144,8 +159,8 @@ bool Foam::sampledTriSurfaceMesh::expire() sampledSurface::clearGeom(); MeshStorage::clear(); - cellLabels_.clear(); - pointToFace_.clear(); + sampleElements_.clear(); + samplePoints_.clear(); needsUpdate_ = true; return true; @@ -164,43 +179,79 @@ bool Foam::sampledTriSurfaceMesh::update() // Does approximation by looking at the face centres only const pointField& fc = surface_.faceCentres(); + // Mesh search engine, no triangulation of faces. meshSearch meshSearcher(mesh(), false); - const indexedOctree& cellTree = meshSearcher.cellTree(); - - // Global numbering for cells - only used to uniquely identify local cells. - globalIndex globalCells(mesh().nCells()); List nearest(fc.size()); + + // Global numbering for cells/faces - only used to uniquely identify local + // elements + globalIndex globalCells + ( + sampleSource_ == cells + ? mesh().nCells() + : mesh().nFaces() + ); + forAll(nearest, i) { nearest[i].first() = GREAT; nearest[i].second() = labelMax; } - // Search triangles using nearest on local mesh - forAll(fc, triI) + if (sampleSource_ == cells) { - pointIndexHit nearInfo = cellTree.findNearest - ( - fc[triI], - sqr(GREAT) - ); - if (nearInfo.hit()) + // Search for nearest cell + + const indexedOctree& cellTree = meshSearcher.cellTree(); + + forAll(fc, triI) { - nearest[triI].first() = magSqr(nearInfo.hitPoint()-fc[triI]); - nearest[triI].second() = globalCells.toGlobal(nearInfo.index()); + pointIndexHit nearInfo = cellTree.findNearest + ( + fc[triI], + sqr(GREAT) + ); + if (nearInfo.hit()) + { + nearest[triI].first() = magSqr(nearInfo.hitPoint()-fc[triI]); + nearest[triI].second() = globalCells.toGlobal(nearInfo.index()); + } + } + } + else + { + // Search for nearest boundaryFace + + const indexedOctree& bTree = meshSearcher.boundaryTree(); + + forAll(fc, triI) + { + pointIndexHit nearInfo = bTree.findNearest + ( + fc[triI], + sqr(GREAT) + ); + if (nearInfo.hit()) + { + nearest[triI].first() = magSqr(nearInfo.hitPoint()-fc[triI]); + nearest[triI].second() = globalCells.toGlobal + ( + bTree.shapes().faceLabels()[nearInfo.index()] + ); + } } } - // See which processor has the nearest. + + // See which processor has the nearest. Mark and subset + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Pstream::listCombineGather(nearest, nearestEqOp()); Pstream::listCombineScatter(nearest); - boolList include(surface_.size(), false); - - cellLabels_.setSize(fc.size()); - cellLabels_ = -1; + labelList cellOrFaceLabels(fc.size(), -1); label nFound = 0; forAll(nearest, triI) @@ -211,9 +262,10 @@ bool Foam::sampledTriSurfaceMesh::update() } else if (globalCells.isLocal(nearest[triI].second())) { - cellLabels_[triI] = globalCells.toLocal(nearest[triI].second()); - - include[triI] = true; + cellOrFaceLabels[triI] = globalCells.toLocal + ( + nearest[triI].second() + ); nFound++; } } @@ -221,7 +273,7 @@ bool Foam::sampledTriSurfaceMesh::update() if (debug) { - Pout<< "Local out of faces:" << cellLabels_.size() + Pout<< "Local out of faces:" << cellOrFaceLabels.size() << " keeping:" << nFound << endl; } @@ -243,7 +295,7 @@ bool Foam::sampledTriSurfaceMesh::update() forAll(s, faceI) { - if (include[faceI]) + if (cellOrFaceLabels[faceI] != -1) { faceMap[newFaceI++] = faceI; @@ -262,11 +314,12 @@ bool Foam::sampledTriSurfaceMesh::update() pointMap.setSize(newPointI); } - // Subset cellLabels - cellLabels_ = UIndirectList