Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ENH: patchCloud: return pTraits<Type>::max for unfound points

  • Loading branch information...
commit d08d3c27ccda228b4d41cf13212e6efc4f419b0e 1 parent 4385da9
mattijs authored
15 applications/utilities/postProcessing/sampling/sample/sampleDict
View
@@ -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<Type>::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.*");
}
);
60 src/sampling/sampledSet/patchCloud/patchCloudSet.C
View
@@ -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<point>& 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();
11 src/sampling/sampledSet/patchCloud/patchCloudSet.H
View
@@ -56,10 +56,14 @@ class patchCloudSet
// Private data
//- Sampling points
- List<point> sampleCoords_;
+ const List<point> 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<point>& sampleCoords,
- const labelHashSet& patchSet
+ const labelHashSet& patchSet,
+ const scalar searchDist
);
//- Construct from dictionary
31 src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C
View
@@ -57,12 +57,20 @@ Foam::sampledSets::volFieldSampler<Type>::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<Type>::max;
+ }
+ else
+ {
+ values[samplei] = interpolator().interpolate
+ (
+ samplePt,
+ celli,
+ facei
+ );
+ }
}
}
}
@@ -86,7 +94,16 @@ Foam::sampledSets::volFieldSampler<Type>::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<Type>::max;
+ }
+ else
+ {
+ values[samplei] = field[celli];
+ }
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.