42 searchableSurfaceCollection,
48 searchableSurfaceCollection,
57 void Foam::searchableSurfaceCollection::findNearest
61 List<pointIndexHit>& nearestInfo,
66 nearestInfo.setSize(
samples.size());
68 nearestSurf.setSize(
samples.size());
71 List<pointIndexHit> hitInfo(
samples.size());
77 subGeom_[surfI].findNearest
81 transform_[surfI].localPosition(
samples),
90 if (hitInfo[pointi].hit())
94 point globalPt = transform_[surfI].globalPosition
98 hitInfo[pointi].
point(),
103 scalar distSqr = globalPt.distSqr(
samples[pointi]);
105 if (distSqr < minDistSqr[pointi])
107 minDistSqr[pointi] = distSqr;
108 nearestInfo[pointi].hitPoint(globalPt);
109 nearestInfo[pointi].setIndex
111 hitInfo[pointi].index()
112 + indexOffset_[surfI]
114 nearestSurf[pointi] = surfI;
124 void Foam::searchableSurfaceCollection::sortHits
126 const List<pointIndexHit>& info,
127 List<List<pointIndexHit>>& surfInfo,
136 if (info[pointi].hit())
138 label index = info[pointi].index();
139 label surfI =
findLower(indexOffset_, index+1);
145 surfInfo.setSize(subGeom_.size());
147 infoMap.setSize(subGeom_.size());
151 surfInfo[surfI].setSize(nHits[surfI]);
152 infoMap[surfI].setSize(nHits[surfI]);
158 if (info[pointi].hit())
160 label index = info[pointi].index();
161 label surfI =
findLower(indexOffset_, index+1);
165 label localI = nHits[surfI]++;
169 index-indexOffset_[surfI]
171 infoMap[surfI][localI] = pointi;
179 Foam::searchableSurfaceCollection::searchableSurfaceCollection
182 const dictionary&
dict 185 searchableSurface(
io),
186 instance_(
dict.size()),
188 transform_(
dict.size()),
189 subGeom_(
dict.size()),
190 mergeSubRegions_(
dict.
get<bool>(
"mergeSubRegions")),
191 indexOffset_(
dict.size()+1)
196 label startIndex = 0;
197 for (
const entry& dEntry :
dict)
201 instance_[surfI] = dEntry.keyword();
205 sDict.readEntry(
"scale", scale_[surfI]);
211 new coordSystem::cartesian(sDict,
"transform")
214 const word subGeomName(sDict.get<word>(
"surface"));
217 searchableSurface&
s =
218 io.db().lookupObjectRef<searchableSurface>(subGeomName);
223 if (
s.size() !=
s.globalSize())
226 <<
"Cannot use a distributed surface in a collection." 230 subGeom_.set(surfI, &
s);
232 indexOffset_[surfI] = startIndex;
233 startIndex += subGeom_[surfI].size();
235 Info<<
" instance : " << instance_[surfI] <<
endl;
236 Info<<
" surface : " <<
s.name() <<
endl;
237 Info<<
" scale : " << scale_[surfI] <<
endl;
238 Info<<
" transform: " << transform_[surfI] <<
endl;
243 indexOffset_[surfI] = startIndex;
247 transform_.setSize(surfI);
248 subGeom_.setSize(surfI);
256 const boundBox& surfBb = subGeom_[surfI].bounds();
259 const point surfBbMin = transform_[surfI].globalPosition
267 const point surfBbMax = transform_[surfI].globalPosition
292 if (regions_.empty())
294 regionOffset_.
setSize(subGeom_.size());
299 regionOffset_[surfI] = allRegions.
size();
301 if (mergeSubRegions_)
308 const wordList& subRegions = subGeom_[surfI].regions();
316 regions_.transfer(allRegions);
324 return indexOffset_.last();
332 auto& ctrs = tctrs.ref();
343 ctrs[coordI++] = transform_[surfI].globalPosition
364 centres.setSize(size());
365 radiusSqr.setSize(centres.size());
372 scalar maxScale =
cmptMax(scale_[surfI]);
376 subGeom_[surfI].boundingSpheres(subCentres, subRadiusSqr);
380 centres[coordI] = transform_[surfI].globalPosition
388 radiusSqr[coordI] = maxScale*subRadiusSqr[i];
403 nPoints += subGeom_[surfI].points()().size();
407 auto&
pts = tpts.ref();
418 pts[
nPoints++] = transform_[surfI].globalPosition
433 void Foam::searchableSurfaceCollection::findNearest
437 List<pointIndexHit>& nearestInfo
474 transform_[surfI].localPosition
484 transform_[surfI].localPosition
491 subGeom_[surfI].findLine(e0, e1, hitInfo);
495 if (hitInfo[pointi].hit())
498 nearest[pointi] = transform_[surfI].globalPosition
502 hitInfo[pointi].
point(),
506 info[pointi] = hitInfo[pointi];
507 info[pointi].point() = nearest[pointi];
508 info[pointi].setIndex
510 hitInfo[pointi].index()
511 + indexOffset_[surfI]
523 if (info[pointi].hit())
526 scalar magN =
mag(
n);
532 scalar
s = ((info[pointi].point()-start[pointi])&
n);
537 <<
"point:" << info[pointi]
539 <<
" outside vector " 540 <<
" start:" << start[pointi]
541 <<
" end:" <<
end[pointi]
555 List<pointIndexHit>& info
559 findLine(start,
end, info);
572 findLine(start,
end, nearestInfo);
577 if (nearestInfo[pointi].hit())
580 info[pointi][0] = nearestInfo[pointi];
592 const List<pointIndexHit>& info,
596 if (subGeom_.size() == 0)
598 else if (subGeom_.size() == 1)
600 if (mergeSubRegions_)
602 region.setSize(info.size());
603 region = regionOffset_[0];
607 subGeom_[0].getRegion(info, region);
615 List<List<pointIndexHit>> surfInfo;
617 List<List<label>> infoMap;
618 sortHits(info, surfInfo, infoMap);
620 region.setSize(info.size());
625 if (mergeSubRegions_)
633 region[map[i]] = regionOffset_[surfI];
642 subGeom_[surfI].getRegion(surfInfo[surfI], surfRegion);
647 region[map[i]] = regionOffset_[surfI] + surfRegion[i];
657 const List<pointIndexHit>& info,
661 if (subGeom_.size() == 0)
663 else if (subGeom_.size() == 1)
665 subGeom_[0].getNormal(info, normal);
672 List<List<pointIndexHit>> surfInfo;
674 List<List<label>> infoMap;
675 sortHits(info, surfInfo, infoMap);
677 normal.setSize(info.size());
683 subGeom_[surfI].getNormal(surfInfo[surfI], surfNormal);
686 surfNormal = transform_[surfI].globalVector(surfNormal);
691 normal[map[i]] = surfNormal[i];
701 List<volumeType>& volType
705 <<
"Volume type not supported for collection." 713 const bool keepNonLocal,
730 subGeom_[surfI].distribute
745 subGeom_[surfI].setField
747 static_cast<const labelList&>
752 subGeom_[surfI].size(),
763 const List<pointIndexHit>& info,
767 if (subGeom_.size() == 0)
769 else if (subGeom_.size() == 1)
771 subGeom_[0].getField(info,
values);
778 List<List<pointIndexHit>> surfInfo;
780 List<List<label>> infoMap;
781 sortHits(info, surfInfo, infoMap);
787 subGeom_[surfI].getField(surfInfo[surfI], surfValues);
789 if (surfValues.size())
792 values.setSize(info.size());
797 values[map[i]] = surfValues[i];
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
virtual ~searchableSurfaceCollection()
Destructor.
void size(const label n)
Older name for setAddressableSize.
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
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...
virtual void distribute(const List< treeBoundBox > &, const bool keepNonLocal, autoPtr< mapDistribute > &faceMap, autoPtr< mapDistribute > &pointMap)
Set bounds of surface. Bounds currently set as list of.
virtual void boundingSpheres(pointField ¢res, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
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.
const word & name() const noexcept
Return the object name.
virtual void getRegion(const List< pointIndexHit > &, labelList ®ion) const
From a set of points and indices get the region.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
scalarField samples(nIntervals, Zero)
Ostream & endl(Ostream &os)
Add newline and flush stream.
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
const point & min() const noexcept
Minimum describing the bounding box.
virtual const boundBox & bounds() const
Return const reference to boundBox.
List< labelList > labelListList
List of labelList.
Macros for easy insertion into run-time selection tables.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
const point & max() const noexcept
Maximum describing the bounding box.
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Find first intersection on segment from start to end.
vectorField pointField
pointField is a vectorField.
void setSize(const label n)
Alias for resize()
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
virtual tmp< pointField > points() const
Get the points that define the surface.
void clear()
Clear the list, i.e. set size to zero.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
virtual label size() const
Range of local indices that can be returned.
void append(const T &val)
Copy append an element to the end of this list.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
defineTypeNameAndDebug(combustionModel, 0)
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.
virtual void setField(const labelList &values)
WIP. Store element-wise field.
List< word > wordList
List of word.
PtrList< coordinateSystem > coordinates(solidRegions.size())
vector point
Point is a vector.
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< vector > vectorField
Specialisation of Field<T> for vector.
void reset()
Reset to an inverted box.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
virtual void getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside/mixed) for point.
List< label > labelList
A List of labels.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
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))
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
virtual const wordList & regions() const
Names of regions.
static constexpr const zero Zero
Global zero (0)