From 736b551ae2546c42cf31d36bafcf3d9cb1fbd2dd Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 30 Sep 2014 17:20:27 +0100 Subject: [PATCH] ENH: mappedPatch: survive neg-tet volume cells In case of point not being found re-search for nearest --- .../mappedPolyPatch/mappedPatchBase.C | 87 +++++++++++++------ .../mappedPolyPatch/mappedPatchBase.H | 12 ++- 2 files changed, 70 insertions(+), 29 deletions(-) diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C index 6ab8930a42..ea24a1c80e 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C @@ -41,6 +41,7 @@ License #include "triPointRef.H" #include "syncTools.H" #include "treeDataCell.H" +#include "DynamicField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -52,14 +53,15 @@ namespace Foam const char* Foam::NamedEnum < Foam::mappedPatchBase::sampleMode, - 5 + 6 >::names[] = { "nearestCell", "nearestPatchFace", "nearestPatchFaceAMI", "nearestPatchPoint", - "nearestFace" + "nearestFace", + "nearestOnlyCell" }; template<> @@ -76,7 +78,7 @@ namespace Foam } -const Foam::NamedEnum +const Foam::NamedEnum Foam::mappedPatchBase::sampleModeNames_; const Foam::NamedEnum @@ -187,6 +189,7 @@ void Foam::mappedPatchBase::collectSamples // for samples being found in two processors. void Foam::mappedPatchBase::findSamples ( + const sampleMode mode, const pointField& samples, labelList& sampleProcs, labelList& sampleIndices, @@ -199,7 +202,7 @@ void Foam::mappedPatchBase::findSamples // All the info for nearest. Construct to miss List nearest(samples.size()); - switch (mode_) + switch (mode) { case NEARESTCELL: { @@ -210,7 +213,7 @@ void Foam::mappedPatchBase::findSamples "mappedPatchBase::findSamples(const pointField&," " labelList&, labelList&, pointField&) const" ) << "No need to supply a patch name when in " - << sampleModeNames_[mode_] << " mode." << exit(FatalError); + << sampleModeNames_[mode] << " mode." << exit(FatalError); } //- Note: face-diagonal decomposition @@ -244,6 +247,36 @@ void Foam::mappedPatchBase::findSamples break; } + case NEARESTONLYCELL: + { + if (samplePatch_.size() && samplePatch_ != "none") + { + FatalErrorIn + ( + "mappedPatchBase::findSamples(const pointField&," + " labelList&, labelList&, pointField&) const" + ) << "No need to supply a patch name when in " + << sampleModeNames_[mode] << " mode." << exit(FatalError); + } + + //- Note: face-diagonal decomposition + const indexedOctree& tree = mesh.cellTree(); + + forAll(samples, sampleI) + { + const point& sample = samples[sampleI]; + + nearest[sampleI].first() = tree.findNearest(sample, sqr(GREAT)); + nearest[sampleI].second().first() = magSqr + ( + nearest[sampleI].first().hitPoint() + -sample + ); + nearest[sampleI].second().second() = Pstream::myProcNo(); + } + break; + } + case NEARESTPATCHFACE: { Random rndGen(123456); @@ -398,7 +431,7 @@ void Foam::mappedPatchBase::findSamples "mappedPatchBase::findSamples(const pointField&," " labelList&, labelList&, pointField&) const" ) << "No need to supply a patch name when in " - << sampleModeNames_[mode_] << " mode." << exit(FatalError); + << sampleModeNames_[mode] << " mode." << exit(FatalError); } //- Note: face-diagonal decomposition @@ -565,7 +598,7 @@ void Foam::mappedPatchBase::calcMapping() const labelList sampleProcs; labelList sampleIndices; pointField sampleLocations; - findSamples(samples, sampleProcs, sampleIndices, sampleLocations); + findSamples(mode_, samples, sampleProcs, sampleIndices, sampleLocations); // Check for samples that were not found. This will only happen for // NEARESTCELL since finds cell containing a location @@ -607,32 +640,36 @@ void Foam::mappedPatchBase::calcMapping() const hasWarned = true; } - // Reset the samples that cannot be found to the cell centres. - pointField patchCc; - { - List globalCc(Pstream::nProcs()); - globalCc[Pstream::myProcNo()] = patch_.faceCellCentres(); - Pstream::gatherList(globalCc); - Pstream::scatterList(globalCc); - patchCc = ListListOps::combine - ( - globalCc, - accessOp() - ); - } + // Collect the samples that cannot be found + DynamicList