From d08d3c27ccda228b4d41cf13212e6efc4f419b0e Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 14 Jul 2011 22:08:27 +0100 Subject: [PATCH] ENH: patchCloud: return pTraits::max for unfound points --- .../postProcessing/sampling/sample/sampleDict | 15 +++--- src/sampling/sampledSet/patchCloud/patchCloudSet.C | 60 ++++++++++++++-------- src/sampling/sampledSet/patchCloud/patchCloudSet.H | 11 ++-- .../sampledSet/sampledSets/sampledSetsTemplates.C | 31 ++++++++--- 4 files changed, 80 insertions(+), 37 deletions(-) diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index c4974f0c..8865d9d5 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -109,15 +109,18 @@ sets somePatchPoints { - // Sample nearest points on selected patches. Use with - // interpolations: + // Sample nearest points on selected patches. Looks only up to + // maxDistance away. Any sampling point not found will get value + // pTraits::max (usually VGREAT) + // Use with interpolations: // - cell (cell value) // - cellPatchConstrained (boundary value) // - cellPoint (interpolated boundary value) - type patchCloud; - axis xyz; - points ((0.049 0.099 0.005)(0.051 0.054 0.005)); - patches (".*Wall.*"); + type patchCloud; + axis xyz; + points ((0.049 0.099 0.005)(0.051 0.054 0.005)); + maxDistance 0.1; // maximum distance to search + patches (".*Wall.*"); } ); diff --git a/src/sampling/sampledSet/patchCloud/patchCloudSet.C b/src/sampling/sampledSet/patchCloud/patchCloudSet.C index f8442b72..4167c978 100644 --- a/src/sampling/sampledSet/patchCloud/patchCloudSet.C +++ b/src/sampling/sampledSet/patchCloud/patchCloudSet.C @@ -130,7 +130,7 @@ void Foam::patchCloudSet::calcSamples // Find the nearest locally if (patchFaces.size()) { - nearInfo = patchTree.findNearest(sample, magSqr(bb.span())); + nearInfo = patchTree.findNearest(sample, sqr(searchDist_)); } else { @@ -179,11 +179,14 @@ void Foam::patchCloudSet::calcSamples forAll(nearest, i) { - meshTools::writeOBJ(str, sampleCoords_[i]); - vertI++; - meshTools::writeOBJ(str, nearest[i].first().hitPoint()); - vertI++; - str << "l " << vertI-1 << ' ' << vertI << nl; + if (nearest[i].first().hit()) + { + meshTools::writeOBJ(str, sampleCoords_[i]); + vertI++; + meshTools::writeOBJ(str, nearest[i].first().hitPoint()); + vertI++; + str << "l " << vertI-1 << ' ' << vertI << nl; + } } } @@ -193,19 +196,31 @@ void Foam::patchCloudSet::calcSamples { const pointIndexHit& nearInfo = nearest[sampleI].first(); - if - ( - nearInfo.hit() - && nearest[sampleI].second().second() == Pstream::myProcNo() - ) + if (nearInfo.hit()) { - label faceI = nearInfo.index(); - - samplingPts.append(nearInfo.hitPoint()); - samplingCells.append(mesh().faceOwner()[faceI]); - samplingFaces.append(faceI); - samplingSegments.append(0); - samplingCurveDist.append(1.0 * sampleI); + if (nearest[sampleI].second().second() == Pstream::myProcNo()) + { + label faceI = nearInfo.index(); + + samplingPts.append(nearInfo.hitPoint()); + samplingCells.append(mesh().faceOwner()[faceI]); + samplingFaces.append(faceI); + samplingSegments.append(0); + samplingCurveDist.append(1.0 * sampleI); + } + } + else + { + // No processor found point near enough. Mark with special value + // which is intercepted when interpolating + if (Pstream::master()) + { + samplingPts.append(sampleCoords_[sampleI]); + samplingCells.append(-1); + samplingFaces.append(-1); + samplingSegments.append(0); + samplingCurveDist.append(1.0 * sampleI); + } } } } @@ -255,12 +270,14 @@ Foam::patchCloudSet::patchCloudSet meshSearch& searchEngine, const word& axis, const List& sampleCoords, - const labelHashSet& patchSet + const labelHashSet& patchSet, + const scalar searchDist ) : sampledSet(name, mesh, searchEngine, axis), sampleCoords_(sampleCoords), - patchSet_(patchSet) + patchSet_(patchSet), + searchDist_(searchDist) { genSamples(); @@ -287,7 +304,8 @@ Foam::patchCloudSet::patchCloudSet ( wordList(dict.lookup("patches")) ) - ) + ), + searchDist_(readScalar(dict.lookup("maxDistance"))) { genSamples(); diff --git a/src/sampling/sampledSet/patchCloud/patchCloudSet.H b/src/sampling/sampledSet/patchCloud/patchCloudSet.H index 4871519d..d43d714c 100644 --- a/src/sampling/sampledSet/patchCloud/patchCloudSet.H +++ b/src/sampling/sampledSet/patchCloud/patchCloudSet.H @@ -56,10 +56,14 @@ class patchCloudSet // Private data //- Sampling points - List sampleCoords_; + const List sampleCoords_; //- Patches to sample - labelHashSet patchSet_; + const labelHashSet patchSet_; + + //- Maximum distance to look for nearest + const scalar searchDist_; + // Private Member Functions @@ -93,7 +97,8 @@ public: meshSearch& searchEngine, const word& axis, const List& sampleCoords, - const labelHashSet& patchSet + const labelHashSet& patchSet, + const scalar searchDist ); //- Construct from dictionary diff --git a/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C b/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C index b3221d68..8769b889 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C +++ b/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C @@ -57,12 +57,20 @@ Foam::sampledSets::volFieldSampler::volFieldSampler label celli = samples.cells()[samplei]; label facei = samples.faces()[samplei]; - values[samplei] = interpolator().interpolate - ( - samplePt, - celli, - facei - ); + if (celli == -1 && facei == -1) + { + // Special condition for illegal sampling points + values[samplei] = pTraits::max; + } + else + { + values[samplei] = interpolator().interpolate + ( + samplePt, + celli, + facei + ); + } } } } @@ -86,7 +94,16 @@ Foam::sampledSets::volFieldSampler::volFieldSampler values.setSize(samples.size()); forAll(samples, samplei) { - values[samplei] = field[samples.cells()[samplei]]; + label celli = samples.cells()[samplei]; + + if (celli ==-1) + { + values[samplei] = pTraits::max; + } + else + { + values[samplei] = field[celli]; + } } } } -- 2.11.4.GIT