47 void Foam::searchableSurfacesQueries::mergeHits
52 const List<pointIndexHit>& surfHits,
55 List<pointIndexHit>& allInfo,
66 surfDistSqr[i] = surfHits[i].hitPoint().distSqr(start);
71 label index =
findLower(allDistSqr, surfDistSqr[i]);
85 label next = index + 1;
87 if (next < allDistSqr.size())
97 label sz = allSurfaces.size();
98 allSurfaces.setSize(sz+1);
99 allInfo.setSize(allSurfaces.size());
100 allDistSqr.setSize(allSurfaces.size());
102 for (label j = sz-1; j > index; --j)
104 allSurfaces[j+1] = allSurfaces[j];
105 allInfo[j+1] = allInfo[j];
106 allDistSqr[j+1] = allDistSqr[j];
109 allSurfaces[index+1] = testI;
110 allInfo[index+1] = surfHits[i];
111 allDistSqr[index+1] = surfDistSqr[i];
141 forAll(surfacesToTest, testI)
144 allSurfaces[surfacesToTest[testI]].findLineAny(
p0, p1, intersectInfo);
150 if (intersectInfo[i].hit())
152 hitInfo[hitMap[i]] = intersectInfo[i];
153 hitSurfaces[hitMap[i]] = testI;
159 hitMap[newI] = hitMap[i];
177 intersectInfo.setSize(newI);
184 const PtrList<searchableSurface>& allSurfaces,
189 List<List<pointIndexHit>>& hitInfo
199 hitSurfaces.setSize(start.size());
202 if (surfacesToTest.empty())
208 allSurfaces[surfacesToTest[0]].findLineAll(start,
end, hitInfo);
211 List<scalarList> hitDistSqr(hitInfo.
size());
214 const List<pointIndexHit>& pHits = hitInfo[pointi];
216 labelList& pSurfaces = hitSurfaces[pointi];
217 pSurfaces.
setSize(pHits.size());
221 pDistSqr.
setSize(pHits.size());
224 pDistSqr[i] = pHits[i].hitPoint().distSqr(start[pointi]);
229 if (surfacesToTest.size() > 1)
232 for (label testI = 1; testI < surfacesToTest.size(); testI++)
234 List<List<pointIndexHit>> surfHits;
235 allSurfaces[surfacesToTest[testI]].findLineAll
263 const PtrList<searchableSurface>& allSurfaces,
268 List<pointIndexHit>& hit1,
270 List<pointIndexHit>& hit2
277 surface1.setSize(start.size());
279 hit1.setSize(start.size());
284 List<pointIndexHit> nearestInfo(start.size());
286 forAll(surfacesToTest, testI)
289 allSurfaces[surfacesToTest[testI]].findLine
296 forAll(nearestInfo, pointi)
298 if (nearestInfo[pointi].hit())
300 hit1[pointi] = nearestInfo[pointi];
301 surface1[pointi] = testI;
302 nearest[pointi] = hit1[pointi].point();
319 if (hit1[pointi].hit())
321 nearest[pointi] = hit1[pointi].point();
326 nearest[pointi] =
end[pointi];
330 forAll(surfacesToTest, testI)
333 allSurfaces[surfacesToTest[testI]].findLine(
end, nearest, nearestInfo);
335 forAll(nearestInfo, pointi)
337 if (nearestInfo[pointi].hit())
339 hit2[pointi] = nearestInfo[pointi];
340 surface2[pointi] = testI;
341 nearest[pointi] = hit2[pointi].point();
350 const PtrList<searchableSurface>& allSurfaces,
355 List<pointIndexHit>& nearestInfo
363 <<
" search-radius:" << nearestDistSqr.size()
369 nearestSurfaces = -1;
376 forAll(surfacesToTest, testI)
378 allSurfaces[surfacesToTest[testI]].findNearest
388 if (hitInfo[pointi].hit())
391 hitInfo[pointi].point().distSqr(
samples[pointi]);
393 nearestInfo[pointi] = hitInfo[pointi];
394 nearestSurfaces[pointi] = testI;
403 const PtrList<searchableSurface>& allSurfaces,
411 List<pointIndexHit>& nearestInfo
419 <<
" search-radius:" << nearestDistSqr.size()
424 if (regionIndices.empty())
439 nearestSurfaces = -1;
446 forAll(surfacesToTest, testI)
448 allSurfaces[surfacesToTest[testI]].findNearest
452 regionIndices[testI],
459 if (hitInfo[pointi].hit())
462 hitInfo[pointi].point().distSqr(
samples[pointi]);
464 nearestInfo[pointi] = hitInfo[pointi];
465 nearestSurfaces[pointi] = testI;
474 const PtrList<searchableSurface>& allSurfaces,
479 List<pointConstraint>& constraint,
486 if (start.size() != distSqr.size())
489 <<
" search-radius:" << distSqr.size()
495 List<pointIndexHit> info;
497 allSurfaces[surfacesToTest[0]].findNearest(start, distSqr, info);
498 allSurfaces[surfacesToTest[0]].getNormal(info, normal);
506 near[i] = info[i].point();
511 constraint.setSize(near.size());
512 constraint = pointConstraint();
517 constraint[i].applyConstraint(normal[i]);
521 if (surfacesToTest.size() >= 2)
528 for (label iter = 0; iter < nIter; iter++)
531 const searchableSurface&
s = allSurfaces[surfacesToTest[surfi]];
534 s.findNearest(near, distSqr, info);
535 s.getNormal(info, normal1);
544 if (normal[i] != vector::zero)
547 if (
mag(normal[i]&normal1[i]) < 1.0-1
e-6)
549 plane pl0(near[i], normal[i],
false);
550 plane pl1(info[i].
point(), normal1[i],
false);
552 plane::ray r(pl0.planeIntersect(pl1));
556 vector d(r.refPoint()-near[i]);
560 scalar magD =
mag(d);
572 normal[i] = normal1[i];
573 constraint[i].applyConstraint(normal1[i]);
580 near[i] = info[i].point();
581 normal[i] = normal1[i];
582 constraint[i].applyConstraint(normal1[i]);
588 surfi = surfacesToTest.fcIndex(surfi);
596 const PtrList<searchableSurface>& allSurfaces,
600 const volumeType illegalHandling,
610 List<pointIndexHit> nearestInfo;
625 forAll(surfacesToTest, testI)
630 forAll(nearestSurfaces, i)
632 if (nearestSurfaces[i] == testI)
635 surfIndices.append(i);
640 List<volumeType> volType;
641 allSurfaces[surfacesToTest[testI]].getVolumeType(surfPoints, volType);
646 label pointi = surfIndices[i];
647 scalar dist =
samples[pointi].dist(nearestInfo[pointi].hitPoint());
649 volumeType vT = volType[i];
661 switch (illegalHandling)
676 <<
"getVolumeType failure," 677 <<
" neither INSIDE or OUTSIDE." 678 <<
" point:" << surfPoints[i]
680 << allSurfaces[surfacesToTest[testI]].name()
681 <<
" volType:" << vT.str()
694 const PtrList<searchableSurface>& allSurfaces,
700 for (
const label surfi : surfacesToTest)
702 bb.
add(allSurfaces[surfi].bounds());
List< scalar > scalarList
List of scalar.
void size(const label n)
Older name for setAddressableSize.
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Binary search to find the index of the last element in a sorted list that is less than value...
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static void findNearest(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &, const scalarField &nearestDistSqr, labelList &surfaces, List< pointIndexHit > &)
Find nearest. Return -1 (and a miss()) or surface and nearest.
scalarField samples(nIntervals, Zero)
dimensionedScalar sqrt(const dimensionedScalar &ds)
scalar distance(const vector &p1, const vector &p2)
A bounding box defined in terms of min/max extrema points.
static void findAllIntersections(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &start, const pointField &end, labelListList &surfaces, List< List< pointIndexHit >> &surfaceHits)
Find all intersections in order from start to end. Returns for.
List< labelList > labelListList
List of labelList.
UList< label > labelUList
A UList of labels.
static void signedDistance(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest, const pointField &samples, const scalarField &nearestDistSqr, const volumeType illegalHandling, labelList &nearestSurfaces, scalarField &distance)
Find signed distance to nearest surface. Outside is positive.
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
void add(const boundBox &bb)
Extend to include the second box.
vectorField pointField
pointField is a vectorField.
const dimensionedScalar e
Elementary charge.
void setSize(const label n)
Alias for resize()
static void findNearestIntersection(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest, const pointField &start, const pointField &end, labelList &surface1, List< pointIndexHit > &hit1, labelList &surface2, List< pointIndexHit > &hit2)
Find intersections of edge nearest to both endpoints.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
A location inside the volume.
static void findAnyIntersection(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &start, const pointField &end, labelList &surfaces, List< pointIndexHit > &)
Find any intersection. Return hit point information and.
A location outside the volume.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
defineTypeNameAndDebug(combustionModel, 0)
vector point
Point is a vector.
Field< vector > vectorField
Specialisation of Field<T> for vector.
List< label > labelList
A List of labels.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Vector< Cmpt > & removeCollinear(const Vector< Cmpt > &unitVec)
Inplace removal of components that are collinear to the given unit vector.
const volScalarField & p0
static boundBox bounds(const PtrList< searchableSurface > &allSurfaces, const labelUList &surfacesToTest)
Find the boundBox of the selected surfaces.