Go to the documentation of this file.
46 const scalar initDistSqr
62 const scalar initDistSqr,
68 forAll(surfacesToTest, testI)
70 label surfI = surfacesToTest[testI];
74 tempFindNearest(allSurfaces[surfI], pt, initDistSqr)
91 const scalar initDistSqr,
99 scalar fac1 = (1.0-fac)/vector::nComponents;
100 scalar fac2 = fac1-fac;
102 vector ptry = pSum*fac1-
p[ihi]*fac2;
104 scalar ytry = sumDistSqr(allSurfaces, surfacesToTest, initDistSqr, ptry);
109 pSum += ptry -
p[ihi];
120 const scalar initDistSqr,
121 const scalar convergenceDistSqr,
136 names[i] = allSurfaces[surfacesToTest[i]].name();
138 Pout<<
"searchableSurfacesQueries::morphTet : intersection of "
139 << names <<
" starting from points:" <<
p <<
endl;
145 for (
label iter = 0; iter < maxIter; iter++)
148 label ilo, ihi, inhi;
152 ilo = sortedIndices[0];
153 ihi = sortedIndices[sortedIndices.
size()-1];
154 inhi = sortedIndices[sortedIndices.
size()-2];
159 Pout<<
"Iteration:" << iter
160 <<
" lowest:" <<
y[ilo] <<
" highest:" <<
y[ihi]
161 <<
" points:" <<
p <<
endl;
165 str()<<
"l " << vertI-1 <<
' ' << vertI <<
nl;
168 if (
y[ihi] < convergenceDistSqr)
177 scalar ytry = tryMorphTet
204 else if (ytry >=
y[inhi])
208 scalar ysave =
y[ihi];
229 p[i] = 0.5*(
p[i] +
p[ilo]);
248 str()<<
"l " << vertI-1 <<
' ' << vertI <<
nl;
340 surfDistSqr[i] =
magSqr(surfHits[i].hitPoint() - start);
359 label next = index + 1;
361 if (next < allDistSqr.
size())
376 for (
label j = sz-1; j > index; --j)
378 allSurfaces[j+1] = allSurfaces[j];
379 allInfo[j+1] = allInfo[j];
380 allDistSqr[j+1] = allDistSqr[j];
383 allSurfaces[index+1] = testI;
384 allInfo[index+1] = surfHits[i];
385 allDistSqr[index+1] = surfDistSqr[i];
405 hitSurfaces.
setSize(start.size());
415 forAll(surfacesToTest, testI)
418 allSurfaces[surfacesToTest[testI]].findLineAny(p0, p1, intersectInfo);
424 if (intersectInfo[i].hit())
426 hitInfo[hitMap[i]] = intersectInfo[i];
427 hitSurfaces[hitMap[i]] = testI;
433 hitMap[newI] = hitMap[i];
473 hitSurfaces.
setSize(start.size());
476 if (surfacesToTest.empty())
482 allSurfaces[surfacesToTest[0]].findLineAll(start, end, hitInfo);
490 labelList& pSurfaces = hitSurfaces[pointI];
498 pDistSqr[i] =
magSqr(pHits[i].hitPoint() - start[pointI]);
503 if (surfacesToTest.
size() > 1)
506 for (
label testI = 1; testI < surfacesToTest.
size(); testI++)
509 allSurfaces[surfacesToTest[testI]].findLineAll
552 surface1.
setSize(start.size());
561 forAll(surfacesToTest, testI)
564 allSurfaces[surfacesToTest[testI]].findLine
571 forAll(nearestInfo, pointI)
573 if (nearestInfo[pointI].hit())
575 hit1[pointI] = nearestInfo[pointI];
576 surface1[pointI] = testI;
577 nearest[pointI] = hit1[pointI].hitPoint();
594 if (hit1[pointI].hit())
596 nearest[pointI] = hit1[pointI].hitPoint();
601 nearest[pointI] = end[pointI];
605 forAll(surfacesToTest, testI)
608 allSurfaces[surfacesToTest[testI]].findLine(end, nearest, nearestInfo);
610 forAll(nearestInfo, pointI)
612 if (nearestInfo[pointI].hit())
614 hit2[pointI] = nearestInfo[pointI];
615 surface2[pointI] = testI;
616 nearest[pointI] = hit2[pointI].hitPoint();
636 nearestSurfaces = -1;
643 forAll(surfacesToTest, testI)
645 allSurfaces[surfacesToTest[testI]].findNearest
655 if (hitInfo[pointI].hit())
657 minDistSqr[pointI] =
magSqr
659 hitInfo[pointI].hitPoint()
662 nearestInfo[pointI] = hitInfo[pointI];
663 nearestSurfaces[pointI] = testI;
684 if (regionIndices.empty())
699 nearestSurfaces = -1;
706 forAll(surfacesToTest, testI)
708 allSurfaces[surfacesToTest[testI]].findNearest
712 regionIndices[testI],
719 if (hitInfo[pointI].hit())
721 minDistSqr[pointI] =
magSqr
723 hitInfo[pointI].hitPoint()
726 nearestInfo[pointI] = hitInfo[pointI];
727 nearestSurfaces[pointI] = testI;
765 forAll(surfacesToTest, testI)
770 forAll(nearestSurfaces, i)
772 if (nearestSurfaces[i] == testI)
781 allSurfaces[surfacesToTest[testI]].getVolumeType(surfPoints, volType);
786 label pointI = surfIndices[i];
787 scalar dist =
mag(
samples[pointI] - nearestInfo[pointI].hitPoint());
791 if (vT == volumeType::OUTSIDE)
795 else if (vT == volumeType::INSIDE)
801 switch (illegalHandling)
803 case volumeType::OUTSIDE:
808 case volumeType::INSIDE:
816 <<
"getVolumeType failure,"
817 <<
" neither INSIDE or OUTSIDE."
818 <<
" point:" << surfPoints[i]
820 << allSurfaces[surfacesToTest[testI]].name()
822 << volumeType::names[vT]
841 forAll(surfacesToTest, testI)
845 bbPoints[2*testI] =
surface.bounds().min();
847 bbPoints[2*testI + 1] =
surface.bounds().max();
859 const scalar initDistSqr,
860 const scalar convergenceDistSqr,
868 point sumNearest = vector::zero;
874 tempFindNearest(allSurfaces[surfacesToTest[i]], start, initDistSqr)
880 sumNearest += nearest[i];
885 <<
"Did not find point within distance "
886 << initDistSqr <<
" of starting point " << start
888 << allSurfaces[surfacesToTest[i]].IOobject::name()
893 nearest.last() = sumNearest / surfacesToTest.
size();
901 nearestDist[i] = sumDistSqr
913 bool converged = morphTet
932 allSurfaces[surfacesToTest[0]],
void clear()
Clear the addressed list, i.e. set the size to zero.
#define forAll(list, i)
Loop across all elements in list.
void writeOBJ(Ostream &os, label &vertI, const tetPoints &tet)
bool hit() const
Is there a hit.
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
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.
dimensioned< scalar > mag(const dimensioned< Type > &)
static void mergeHits(const point &start, const label surfI, const List< pointIndexHit > &surfHits, labelList &allSurfaces, List< pointIndexHit > &allInfo, scalarList &allDistSqr)
scalarField samples(nIntervals, 0)
label findMin(const ListType &, const label start=0)
Find index of min element (and less than given element).
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
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)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Pre-declare SubField and related Field type.
const Point & hitPoint() const
Return hit point.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
void clear()
Clear the addressed list, i.e. set the size to zero.
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.
DynamicField< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
static boundBox bounds(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest)
Find the boundBox of the selected surfaces.
label findLower(const ListType &, typename ListType::const_reference, const label start, const BinaryOp &bop)
Find last element < given value in sorted list and return index,.
static scalar tryMorphTet(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const scalar initialDistSqr, List< vector > &p, List< scalar > &y, vector &pSum, const label ihi, const scalar fac)
Takes the tet (points p) and reflects the point with the.
static pointIndexHit facesIntersection(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest, const scalar initDistSqr, const scalar convergenceDistSqr, const point &start)
Calculate point which is on a set of surfaces. WIP.
static scalar sumDistSqr(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const scalar initialDistSqr, const point &pt)
Calculate sum of distances to nearest point on surfaces. Is used.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const =0
errorManip< error > abort(error &err)
scalar distance(const vector &p1, const vector &p2)
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void setSize(const label)
Reset size of List.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static bool morphTet(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const scalar initialDistSqr, const scalar convergenceDistSqr, const label maxIter, List< vector > &p, List< scalar > &y)
Downhill simplex method: find the point with min cumulative.
prefixOSstream Pout(cout, "Pout")
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
A bounding box defined in terms of the points at its extremities.
static pointIndexHit tempFindNearest(const searchableSurface &, const point &pt, const scalar initDistSqr)
Temporary wrapper around findNearest. Used in facesIntersection only.
void reset(T *=0)
If object pointer already set, delete object and set to given.
Various functions to operate on Lists.
void size(const label)
Override size to be inconsistent with allocated storage.
defineTypeNameAndDebug(combustionModel, 0)
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.
dimensioned< scalar > magSqr(const dimensioned< Type > &)