diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index ca79e6aa47..bc7a3fb32f 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -119,15 +119,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 85877da3b8..5e5e4b912c 100644 --- a/src/sampling/sampledSet/patchCloud/patchCloudSet.C +++ b/src/sampling/sampledSet/patchCloud/patchCloudSet.C @@ -26,13 +26,12 @@ License #include "patchCloudSet.H" #include "polyMesh.H" #include "addToRunTimeSelectionTable.H" -#include "pointIndexHit.H" -#include "Tuple2.H" #include "treeBoundBox.H" -#include "indexedOctree.H" #include "treeDataFace.H" #include "Time.H" #include "meshTools.H" +// For 'nearInfo' helper class only +#include "directMappedPatchBase.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -40,35 +39,6 @@ namespace Foam { defineTypeNameAndDebug(patchCloudSet, 0); addToRunTimeSelectionTable(sampledSet, patchCloudSet, word); - - - //- Helper class for finding nearest - // Nearest: - // - point+local index - // - sqr(distance) - // - processor - typedef Tuple2 > nearInfo; - - class nearestEqOp - { - - public: - - void operator()(nearInfo& x, const nearInfo& y) const - { - if (y.first().hit()) - { - if (!x.first().hit()) - { - x = y; - } - else if (y.second().first() < x.second().first()) - { - x = y; - } - } - } - }; } @@ -114,7 +84,8 @@ void Foam::patchCloudSet::calcSamples patchFaces[sz++] = pp.start()+i; } - const boundBox patchBb(pp.points(), pp.meshPoints()); + // Do not do reduction. + const boundBox patchBb(pp.points(), pp.meshPoints(), false); bb.min() = min(bb.min(), patchBb.min()); bb.max() = max(bb.max(), patchBb.max()); @@ -125,6 +96,7 @@ void Foam::patchCloudSet::calcSamples // Make bb asymetric just to avoid problems on symmetric meshes bb = bb.extend(rndGen, 1E-4); + // Make sure bb is 3D. bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); @@ -146,7 +118,7 @@ void Foam::patchCloudSet::calcSamples // All the info for nearest. Construct to miss - List nearest(sampleCoords_.size()); + List nearest(sampleCoords_.size()); forAll(sampleCoords_, sampleI) { @@ -155,7 +127,15 @@ void Foam::patchCloudSet::calcSamples pointIndexHit& nearInfo = nearest[sampleI].first(); // Find the nearest locally - nearInfo = patchTree.findNearest(sample, magSqr(bb.span())); + if (patchFaces.size()) + { + nearInfo = patchTree.findNearest(sample, sqr(searchDist_)); + } + else + { + nearInfo.setMiss(); + } + // Fill in the distance field and the processor field if (!nearInfo.hit()) @@ -179,7 +159,7 @@ void Foam::patchCloudSet::calcSamples // Find nearest. - Pstream::listCombineGather(nearest, nearestEqOp()); + Pstream::listCombineGather(nearest, directMappedPatchBase::nearestEqOp()); Pstream::listCombineScatter(nearest); @@ -198,11 +178,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; + } } } @@ -210,17 +193,33 @@ void Foam::patchCloudSet::calcSamples // Store the sampling locations on the nearest processor forAll(nearest, sampleI) { - if (nearest[sampleI].second().second() == Pstream::myProcNo()) + const pointIndexHit& nearInfo = nearest[sampleI].first(); + + if (nearInfo.hit()) { - const pointIndexHit& nearInfo = nearest[sampleI].first(); + if (nearest[sampleI].second().second() == Pstream::myProcNo()) + { + label faceI = nearInfo.index(); - label faceI = nearInfo.index(); - - samplingPts.append(nearInfo.hitPoint()); - samplingCells.append(mesh().faceOwner()[faceI]); - samplingFaces.append(faceI); - samplingSegments.append(0); - samplingCurveDist.append(1.0 * sampleI); + 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); + } } } } @@ -270,12 +269,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(); @@ -302,7 +303,8 @@ Foam::patchCloudSet::patchCloudSet ( wordReList(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 fd0ce606b7..12d59d94fc 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 f00561003c..ef7202b5d5 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C +++ b/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C @@ -51,18 +51,26 @@ Foam::sampledSets::volFieldSampler::volFieldSampler const sampledSet& samples = samplers[setI]; values.setSize(samples.size()); - forAll(samples, samplei) + forAll(samples, sampleI) { - const point& samplePt = samples[samplei]; - label celli = samples.cells()[samplei]; - label facei = samples.faces()[samplei]; + const point& samplePt = samples[sampleI]; + 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 + ); + } } } } @@ -84,9 +92,18 @@ Foam::sampledSets::volFieldSampler::volFieldSampler const sampledSet& samples = samplers[setI]; values.setSize(samples.size()); - forAll(samples, samplei) + 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]; + } } } }