Skip to content

Commit d08d3c2

Browse files
author
mattijs
committed
ENH: patchCloud: return pTraits<Type>::max for unfound points
1 parent 4385da9 commit d08d3c2

File tree

4 files changed

+80
-37
lines changed

4 files changed

+80
-37
lines changed

applications/utilities/postProcessing/sampling/sample/sampleDict

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,18 @@ sets
109109

110110
somePatchPoints
111111
{
112-
// Sample nearest points on selected patches. Use with
113-
// interpolations:
112+
// Sample nearest points on selected patches. Looks only up to
113+
// maxDistance away. Any sampling point not found will get value
114+
// pTraits<Type>::max (usually VGREAT)
115+
// Use with interpolations:
114116
// - cell (cell value)
115117
// - cellPatchConstrained (boundary value)
116118
// - cellPoint (interpolated boundary value)
117-
type patchCloud;
118-
axis xyz;
119-
points ((0.049 0.099 0.005)(0.051 0.054 0.005));
120-
patches (".*Wall.*");
119+
type patchCloud;
120+
axis xyz;
121+
points ((0.049 0.099 0.005)(0.051 0.054 0.005));
122+
maxDistance 0.1; // maximum distance to search
123+
patches (".*Wall.*");
121124
}
122125
);
123126

src/sampling/sampledSet/patchCloud/patchCloudSet.C

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void Foam::patchCloudSet::calcSamples
130130
// Find the nearest locally
131131
if (patchFaces.size())
132132
{
133-
nearInfo = patchTree.findNearest(sample, magSqr(bb.span()));
133+
nearInfo = patchTree.findNearest(sample, sqr(searchDist_));
134134
}
135135
else
136136
{
@@ -179,11 +179,14 @@ void Foam::patchCloudSet::calcSamples
179179

180180
forAll(nearest, i)
181181
{
182-
meshTools::writeOBJ(str, sampleCoords_[i]);
183-
vertI++;
184-
meshTools::writeOBJ(str, nearest[i].first().hitPoint());
185-
vertI++;
186-
str << "l " << vertI-1 << ' ' << vertI << nl;
182+
if (nearest[i].first().hit())
183+
{
184+
meshTools::writeOBJ(str, sampleCoords_[i]);
185+
vertI++;
186+
meshTools::writeOBJ(str, nearest[i].first().hitPoint());
187+
vertI++;
188+
str << "l " << vertI-1 << ' ' << vertI << nl;
189+
}
187190
}
188191
}
189192

@@ -193,19 +196,31 @@ void Foam::patchCloudSet::calcSamples
193196
{
194197
const pointIndexHit& nearInfo = nearest[sampleI].first();
195198

196-
if
197-
(
198-
nearInfo.hit()
199-
&& nearest[sampleI].second().second() == Pstream::myProcNo()
200-
)
199+
if (nearInfo.hit())
201200
{
202-
label faceI = nearInfo.index();
203-
204-
samplingPts.append(nearInfo.hitPoint());
205-
samplingCells.append(mesh().faceOwner()[faceI]);
206-
samplingFaces.append(faceI);
207-
samplingSegments.append(0);
208-
samplingCurveDist.append(1.0 * sampleI);
201+
if (nearest[sampleI].second().second() == Pstream::myProcNo())
202+
{
203+
label faceI = nearInfo.index();
204+
205+
samplingPts.append(nearInfo.hitPoint());
206+
samplingCells.append(mesh().faceOwner()[faceI]);
207+
samplingFaces.append(faceI);
208+
samplingSegments.append(0);
209+
samplingCurveDist.append(1.0 * sampleI);
210+
}
211+
}
212+
else
213+
{
214+
// No processor found point near enough. Mark with special value
215+
// which is intercepted when interpolating
216+
if (Pstream::master())
217+
{
218+
samplingPts.append(sampleCoords_[sampleI]);
219+
samplingCells.append(-1);
220+
samplingFaces.append(-1);
221+
samplingSegments.append(0);
222+
samplingCurveDist.append(1.0 * sampleI);
223+
}
209224
}
210225
}
211226
}
@@ -255,12 +270,14 @@ Foam::patchCloudSet::patchCloudSet
255270
meshSearch& searchEngine,
256271
const word& axis,
257272
const List<point>& sampleCoords,
258-
const labelHashSet& patchSet
273+
const labelHashSet& patchSet,
274+
const scalar searchDist
259275
)
260276
:
261277
sampledSet(name, mesh, searchEngine, axis),
262278
sampleCoords_(sampleCoords),
263-
patchSet_(patchSet)
279+
patchSet_(patchSet),
280+
searchDist_(searchDist)
264281
{
265282
genSamples();
266283

@@ -287,7 +304,8 @@ Foam::patchCloudSet::patchCloudSet
287304
(
288305
wordList(dict.lookup("patches"))
289306
)
290-
)
307+
),
308+
searchDist_(readScalar(dict.lookup("maxDistance")))
291309
{
292310
genSamples();
293311

src/sampling/sampledSet/patchCloud/patchCloudSet.H

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ class patchCloudSet
5656
// Private data
5757

5858
//- Sampling points
59-
List<point> sampleCoords_;
59+
const List<point> sampleCoords_;
6060

6161
//- Patches to sample
62-
labelHashSet patchSet_;
62+
const labelHashSet patchSet_;
63+
64+
//- Maximum distance to look for nearest
65+
const scalar searchDist_;
66+
6367

6468
// Private Member Functions
6569

@@ -93,7 +97,8 @@ public:
9397
meshSearch& searchEngine,
9498
const word& axis,
9599
const List<point>& sampleCoords,
96-
const labelHashSet& patchSet
100+
const labelHashSet& patchSet,
101+
const scalar searchDist
97102
);
98103

99104
//- Construct from dictionary

src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,20 @@ Foam::sampledSets::volFieldSampler<Type>::volFieldSampler
5757
label celli = samples.cells()[samplei];
5858
label facei = samples.faces()[samplei];
5959

60-
values[samplei] = interpolator().interpolate
61-
(
62-
samplePt,
63-
celli,
64-
facei
65-
);
60+
if (celli == -1 && facei == -1)
61+
{
62+
// Special condition for illegal sampling points
63+
values[samplei] = pTraits<Type>::max;
64+
}
65+
else
66+
{
67+
values[samplei] = interpolator().interpolate
68+
(
69+
samplePt,
70+
celli,
71+
facei
72+
);
73+
}
6674
}
6775
}
6876
}
@@ -86,7 +94,16 @@ Foam::sampledSets::volFieldSampler<Type>::volFieldSampler
8694
values.setSize(samples.size());
8795
forAll(samples, samplei)
8896
{
89-
values[samplei] = field[samples.cells()[samplei]];
97+
label celli = samples.cells()[samplei];
98+
99+
if (celli ==-1)
100+
{
101+
values[samplei] = pTraits<Type>::max;
102+
}
103+
else
104+
{
105+
values[samplei] = field[celli];
106+
}
90107
}
91108
}
92109
}

0 commit comments

Comments
 (0)