From 6520f35f1e9fa325094cc93d725b883a78cf7ddf Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 28 Oct 2008 21:07:05 +0000 Subject: [PATCH 01/10] nearestToPoint --- src/meshTools/Make/files | 1 + .../nearestToPoint/nearestToPoint.C | 154 ++++++++++++++++++ .../nearestToPoint/nearestToPoint.H | 122 ++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.C create mode 100644 src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.H diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index 64437bdda8..99587f8d3c 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -107,6 +107,7 @@ $(pointSources)/faceToPoint/faceToPoint.C $(pointSources)/boxToPoint/boxToPoint.C $(pointSources)/surfaceToPoint/surfaceToPoint.C $(pointSources)/zoneToPoint/zoneToPoint.C +$(pointSources)/nearestToPoint/nearestToPoint.C surfaceSets/surfaceSets.C diff --git a/src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.C b/src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.C new file mode 100644 index 0000000000..f4b759c6fe --- /dev/null +++ b/src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.C @@ -0,0 +1,154 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "nearestToPoint.H" +#include "polyMesh.H" +#include "meshSearch.H" + +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + +defineTypeNameAndDebug(nearestToPoint, 0); + +addToRunTimeSelectionTable(topoSetSource, nearestToPoint, word); + +addToRunTimeSelectionTable(topoSetSource, nearestToPoint, istream); + +} + + +Foam::topoSetSource::addToUsageTable Foam::nearestToPoint::usage_ +( + nearestToPoint::typeName, + "\n Usage: nearestToPoint (pt0 .. ptn)\n\n" + " Select the nearest point for each of the points pt0 ..ptn\n\n" +); + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::nearestToPoint::combine(topoSet& set, const bool add) const +{ + // Do linear search since usually just a few points. + + forAll(points_, pointI) + { + const pointField& pts = mesh_.points(); + + if (pts.size() > 0) + { + label minPointI = 0; + scalar minDistSqr = magSqr(pts[minPointI] - points_[pointI]); + + for (label i = 1; i < pts.size(); i++) + { + scalar distSqr = magSqr(pts[i] - points_[pointI]); + + if (distSqr < minDistSqr) + { + minDistSqr = distSqr; + minPointI = i; + } + } + + addOrDelete(set, minPointI, add); + } + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +// Construct from components +Foam::nearestToPoint::nearestToPoint +( + const polyMesh& mesh, + const pointField& points +) +: + topoSetSource(mesh), + points_(points) +{} + + +// Construct from dictionary +Foam::nearestToPoint::nearestToPoint +( + const polyMesh& mesh, + const dictionary& dict +) +: + topoSetSource(mesh), + points_(dict.lookup("points")) +{} + + +// Construct from Istream +Foam::nearestToPoint::nearestToPoint +( + const polyMesh& mesh, + Istream& is +) +: + topoSetSource(mesh), + points_(checkIs(is)) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::nearestToPoint::~nearestToPoint() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::nearestToPoint::applyToSet +( + const topoSetSource::setAction action, + topoSet& set +) const +{ + if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD)) + { + Info<< " Adding points nearest to " << points_ << endl; + + combine(set, true); + } + else if (action == topoSetSource::DELETE) + { + Info<< " Removing points nearest to " << points_ << endl; + + combine(set, false); + } +} + + +// ************************************************************************* // diff --git a/src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.H b/src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.H new file mode 100644 index 0000000000..ba63cc14f2 --- /dev/null +++ b/src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.H @@ -0,0 +1,122 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::nearestToPoint + +Description + A topoSetSource to select points nearest to points. + +SourceFiles + nearestToPoint.C + +\*---------------------------------------------------------------------------*/ + +#ifndef nearestToPoint_H +#define nearestToPoint_H + +#include "topoSetSource.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class nearestToPoint Declaration +\*---------------------------------------------------------------------------*/ + +class nearestToPoint +: + public topoSetSource +{ + + // Private data + + //- Add usage string + static addToUsageTable usage_; + + //- points to select nearest to + pointField points_; + + + // Private Member Functions + + void combine(topoSet& set, const bool add) const; + + +public: + + //- Runtime type information + TypeName("nearestToPoint"); + + // Constructors + + //- Construct from components + nearestToPoint + ( + const polyMesh& mesh, + const pointField& points + ); + + //- Construct from dictionary + nearestToPoint + ( + const polyMesh& mesh, + const dictionary& dict + ); + + //- Construct from Istream + nearestToPoint + ( + const polyMesh& mesh, + Istream& + ); + + + // Destructor + + virtual ~nearestToPoint(); + + + // Member Functions + + virtual void applyToSet + ( + const topoSetSource::setAction action, + topoSet& + ) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // From b5ee8b6dc111b77d94d1a27e35714701f9791611 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 28 Oct 2008 21:07:37 +0000 Subject: [PATCH 02/10] detect only option --- .../mergeOrSplitBaffles/mergeOrSplitBaffles.C | 134 ++++++++++-------- 1 file changed, 78 insertions(+), 56 deletions(-) diff --git a/applications/utilities/mesh/manipulation/mergeOrSplitBaffles/mergeOrSplitBaffles.C b/applications/utilities/mesh/manipulation/mergeOrSplitBaffles/mergeOrSplitBaffles.C index cbd2d9e419..d8d12c0845 100644 --- a/applications/utilities/mesh/manipulation/mergeOrSplitBaffles/mergeOrSplitBaffles.C +++ b/applications/utilities/mesh/manipulation/mergeOrSplitBaffles/mergeOrSplitBaffles.C @@ -154,10 +154,77 @@ void insertDuplicateMerge } +labelList findBaffles(const polyMesh& mesh, const labelList& boundaryFaces) +{ + // Get all duplicate face labels (in boundaryFaces indices!). + labelList duplicates = localPointRegion::findDuplicateFaces + ( + mesh, + boundaryFaces + ); + + + // Check that none are on processor patches + const polyBoundaryMesh& patches = mesh.boundaryMesh(); + + forAll(duplicates, bFaceI) + { + if (duplicates[bFaceI] != -1) + { + label faceI = mesh.nInternalFaces() + bFaceI; + label patchI = patches.whichPatch(faceI); + + if (isA(patches[patchI])) + { + FatalErrorIn("findBaffles(const polyMesh&, const labelList&)") + << "Duplicate face " << faceI + << " is on a processorPolyPatch." + << "This is not allowed." << nl + << "Face:" << faceI + << " is on patch:" << patches[patchI].name() + << abort(FatalError); + } + } + } + + + // Write to faceSet for ease of postprocessing. + { + faceSet duplicateSet + ( + mesh, + "duplicateFaces", + (mesh.nFaces() - mesh.nInternalFaces())/256 + ); + + forAll(duplicates, bFaceI) + { + label otherFaceI = duplicates[bFaceI]; + + if (otherFaceI != -1 && otherFaceI > bFaceI) + { + duplicateSet.insert(mesh.nInternalFaces() + bFaceI); + duplicateSet.insert(mesh.nInternalFaces() + otherFaceI); + } + } + + Pout<< "Writing " << duplicateSet.size() + << " duplicate faces to faceSet " << duplicateSet.objectPath() + << nl << endl; + duplicateSet.write(); + } + + return duplicates; +} + + + + int main(int argc, char *argv[]) { argList::validOptions.insert("split", ""); argList::validOptions.insert("overwrite", ""); + argList::validOptions.insert("detectOnly", ""); # include "setRootCase.H" # include "createTime.H" runTime.functionObjects().off(); @@ -165,6 +232,7 @@ int main(int argc, char *argv[]) bool split = args.options().found("split"); bool overwrite = args.options().found("overwrite"); + bool detectOnly = args.options().found("detectOnly"); // Collect all boundary faces labelList boundaryFaces(mesh.nFaces() - mesh.nInternalFaces()); @@ -175,6 +243,15 @@ int main(int argc, char *argv[]) } + if (detectOnly) + { + findBaffles(mesh, boundaryFaces); + + return 0; + } + + + // Read objects in time directory IOobjectList objects(mesh, runTime.timeName()); @@ -238,62 +315,7 @@ int main(int argc, char *argv[]) << nl << endl; // Get all duplicate face labels (in boundaryFaces indices!). - labelList duplicates = localPointRegion::findDuplicateFaces - ( - mesh, - boundaryFaces - ); - - - // Check that none are on processor patches - const polyBoundaryMesh& patches = mesh.boundaryMesh(); - - forAll(duplicates, bFaceI) - { - if (duplicates[bFaceI] != -1) - { - label faceI = mesh.nInternalFaces() + bFaceI; - label patchI = patches.whichPatch(faceI); - - if (isA(patches[patchI])) - { - FatalErrorIn(args.executable()) - << "Duplicate face " << faceI - << " is on a processorPolyPatch." - << "This is not allowed." << nl - << "Face:" << faceI - << " is on patch:" << patches[patchI].name() - << abort(FatalError); - } - } - } - - - // Write to faceSet for ease of postprocessing. - { - faceSet duplicateSet - ( - mesh, - "duplicateFaces", - (mesh.nFaces() - mesh.nInternalFaces())/256 - ); - - forAll(duplicates, bFaceI) - { - label otherFaceI = duplicates[bFaceI]; - - if (otherFaceI != -1 && otherFaceI > bFaceI) - { - duplicateSet.insert(mesh.nInternalFaces() + bFaceI); - duplicateSet.insert(mesh.nInternalFaces() + otherFaceI); - } - } - - Pout<< "Writing " << duplicateSet.size() - << " duplicate faces to faceSet " << duplicateSet.objectPath() - << nl << endl; - duplicateSet.write(); - } + labelList duplicates(findBaffles(mesh, boundaryFaces)); // Merge into internal faces. insertDuplicateMerge(mesh, duplicates, meshMod); From 3403802282bdadb06099e9307a834926b6ca9622 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 28 Oct 2008 21:07:59 +0000 Subject: [PATCH 03/10] region option --- applications/utilities/mesh/manipulation/setSet/setSet.C | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C index f8f05747f8..c0503e5bf5 100644 --- a/applications/utilities/mesh/manipulation/setSet/setSet.C +++ b/applications/utilities/mesh/manipulation/setSet/setSet.C @@ -714,9 +714,11 @@ commandStatus parseAction(const word& actionName) int main(int argc, char *argv[]) { +# include "addRegionOption.H" +# include "addTimeOptions.H" + argList::validOptions.insert("noVTK", ""); argList::validOptions.insert("batch", "file"); -# include "addTimeOptions.H" # include "setRootCase.H" # include "createTime.H" @@ -730,7 +732,7 @@ int main(int argc, char *argv[]) runTime.setTime(Times[startTime], startTime); -# include "createPolyMesh.H" +# include "createNamedPolyMesh.H" // Print some mesh info printMesh(runTime, mesh); From 8ad016dd2c87b0dada685b82ad14885a3295115a Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 28 Oct 2008 21:11:48 +0000 Subject: [PATCH 04/10] small normal tolerance. Fixed indexing error --- .../searchableSurfaceWithGaps.C | 51 +++++++++++++++---- .../searchableSurfaceWithGaps.H | 8 ++- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C b/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C index 50e851296b..b41a4409b2 100644 --- a/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C +++ b/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C @@ -26,7 +26,6 @@ License #include "searchableSurfaceWithGaps.H" #include "addToRunTimeSelectionTable.H" -#include "SortableList.H" #include "Time.H" #include "ListOps.H" @@ -82,7 +81,7 @@ Foam::Pair Foam::searchableSurfaceWithGaps::offsetVecs // Do second offset vector perp to original edge and first offset vector offsets[1] = n ^ offsets[0]; - offsets[1] *= gap_/mag(offsets[1]); + offsets[1] *= gap_; } return offsets; @@ -207,6 +206,10 @@ void Foam::searchableSurfaceWithGaps::findLine List& info ) const { + + // Test with unperturbed vectors + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + surface().findLine(start, end, info); // Count number of misses. Determine map @@ -215,6 +218,10 @@ void Foam::searchableSurfaceWithGaps::findLine if (returnReduce(nMiss, sumOp