From fe32d73d5af22623afdc8422bfa038759d494bf4 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 16 May 2013 11:17:54 +0100 Subject: [PATCH] BUG: distributedTriSurfaceMesh: handle zero sized local surfaces --- .../searchableSurface/triSurfaceMesh.C | 34 +++++++----- .../triSurfaceSearch/triSurfaceRegionSearch.C | 55 +++++++++++-------- .../triSurfaceSearch/triSurfaceSearch.C | 41 ++++++++------ .../distributedTriSurfaceMesh.C | 24 +++++++- .../distributedTriSurfaceMesh.H | 6 +- 5 files changed, 99 insertions(+), 61 deletions(-) diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index 2222981793..6009ec6670 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -433,24 +433,28 @@ Foam::triSurfaceMesh::edgeTree() const + nInternalEdges() ); - treeBoundBox bb; - label nPoints; - PatchTools::calcBounds - ( - static_cast(*this), - bb, - nPoints - ); + treeBoundBox bb(vector::zero, vector::zero); - // Random number generator. Bit dodgy since not exactly random ;-) - Random rndGen(65431); + if (bEdges.size()) + { + label nPoints; + PatchTools::calcBounds + ( + static_cast(*this), + bb, + nPoints + ); - // Slightly extended bb. Slightly off-centred just so on symmetric - // geometry there are less face/edge aligned items. + // Random number generator. Bit dodgy since not exactly random ;-) + Random rndGen(65431); - bb = bb.extend(rndGen, 1e-4); - bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); - bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + // Slightly extended bb. Slightly off-centred just so on symmetric + // geometry there are less face/edge aligned items. + + bb = bb.extend(rndGen, 1e-4); + bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + } scalar oldTol = indexedOctree::perturbTol(); indexedOctree::perturbTol() = tolerance(); diff --git a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceRegionSearch.C b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceRegionSearch.C index 738cb8dcdd..34dc89f920 100644 --- a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceRegionSearch.C +++ b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceRegionSearch.C @@ -121,33 +121,40 @@ Foam::triSurfaceRegionSearch::treeByRegion() const ); // Calculate bb without constructing local point numbering. - treeBoundBox bb; - label nPoints; - PatchTools::calcBounds - ( - indirectRegionPatches_[regionI], - bb, - nPoints - ); + treeBoundBox bb(vector::zero, vector::zero); -// if (nPoints != surface().points().size()) -// { -// WarningIn("triSurfaceRegionSearch::treeByRegion() const") -// << "Surface does not have compact point numbering. " -// << "Of " << surface().points().size() -// << " only " << nPoints -// << " are used. This might give problems in some routines." -// << endl; -// } + if (indirectRegionPatches_[regionI].size()) + { + label nPoints; + PatchTools::calcBounds + ( + indirectRegionPatches_[regionI], + bb, + nPoints + ); - // Random number generator. Bit dodgy since not exactly random ;-) - Random rndGen(65431); + // if (nPoints != surface().points().size()) + // { + // WarningIn("triSurfaceRegionSearch::treeByRegion() const") + // << "Surface does not have compact point numbering. " + // << "Of " << surface().points().size() + // << " only " << nPoints + // << " are used." + // << " This might give problems in some routines." + // << endl; + // } - // Slightly extended bb. Slightly off-centred just so on symmetric - // geometry there are fewer face/edge aligned items. - bb = bb.extend(rndGen, 1e-4); - bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); - bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + // Random number generator. Bit dodgy since not exactly + // random ;-) + Random rndGen(65431); + + // Slightly extended bb. Slightly off-centred just so + // on symmetric geometry there are fewer face/edge + // aligned items. + bb = bb.extend(rndGen, 1e-4); + bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + } treeByRegion_.set ( diff --git a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C index fbff791040..43877e3393 100644 --- a/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C +++ b/src/meshTools/triSurface/triSurfaceSearch/triSurfaceSearch.C @@ -200,28 +200,33 @@ Foam::triSurfaceSearch::tree() const if (treePtr_.empty()) { // Calculate bb without constructing local point numbering. - treeBoundBox bb; - label nPoints; - PatchTools::calcBounds(surface(), bb, nPoints); + treeBoundBox bb(vector::zero, vector::zero); - if (nPoints != surface().points().size()) + if (surface().size()) { - WarningIn("triSurfaceSearch::tree() const") - << "Surface does not have compact point numbering." - << " Of " << surface().points().size() << " only " << nPoints - << " are used. This might give problems in some routines." - << endl; + label nPoints; + PatchTools::calcBounds(surface(), bb, nPoints); + + if (nPoints != surface().points().size()) + { + WarningIn("triSurfaceSearch::tree() const") + << "Surface does not have compact point numbering." + << " Of " << surface().points().size() + << " only " << nPoints + << " are used. This might give problems in some routines." + << endl; + } + + // Random number generator. Bit dodgy since not exactly random ;-) + Random rndGen(65431); + + // Slightly extended bb. Slightly off-centred just so on symmetric + // geometry there are less face/edge aligned items. + bb = bb.extend(rndGen, 1e-4); + bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); } - // Random number generator. Bit dodgy since not exactly random ;-) - Random rndGen(65431); - - // Slightly extended bb. Slightly off-centred just so on symmetric - // geometry there are less face/edge aligned items. - bb = bb.extend(rndGen, 1e-4); - bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); - bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); - scalar oldTol = indexedOctree::perturbTol(); indexedOctree::perturbTol() = tolerance_; diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C index 80308fac5e..7c80bd1a56 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C @@ -2360,10 +2360,28 @@ bool Foam::distributedTriSurfaceMesh::writeObject // Make sure dictionary goes to same directory as surface const_cast(dict_.instance()) = searchableSurface::instance(); + // Copy of triSurfaceMesh::writeObject except for the sorting of + // triangles by region. This is done so we preserve region names, + // even if locally we have zero triangles. + { + fileName fullPath(searchableSurface::objectPath()); + + if (!mkDir(fullPath.path())) + { + return false; + } + + // Important: preserve any zero-sized patches + triSurface::write(fullPath, true); + + if (!isFile(fullPath)) + { + return false; + } + } + // Dictionary needs to be written in ascii - binary output not supported. - return - triSurfaceMesh::writeObject(fmt, ver, cmp) - && dict_.writeObject(IOstream::ASCII, ver, cmp); + return dict_.writeObject(IOstream::ASCII, ver, cmp); } diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H index 32a062a573..7e4d27ef0c 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -446,6 +446,10 @@ public: // regIOobject implementation //- Write using given format, version and compression + // Do not use the triSurfaceMesh::writeObject since it + // would filter out empty regions. These need to be preserved + // in case we want to make decisions based on the number of + // regions. virtual bool writeObject ( IOstream::streamFormat fmt,