distributedTriSurfaceMesh.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2015-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::distributedTriSurfaceMesh
29
30Description
31 IOoject and searching on distributed triSurface. All processor hold
32 (possibly overlapping) part of the overall surface. All queries are
33 distributed to the processor that can answer it and the result sent back.
34
35 Can work in three modes:
36 - follow : makes sure each processor has all the triangles inside the
37 externally provided bounding box (usually the mesh bounding box).
38 Guarantees minimum amount of communication since mesh-local queries
39 should be answerable without any comms.
40 - independent : surface is decomposed according to the triangle centres
41 so the decomposition might be radically different from the mesh
42 decomposition. Guarantees best memory balance but at the expense of
43 more communication.
44 - frozen : no change
45
46 Note: addressing used:
47 distributedTriSurfaceMesh: none
48
49 triSurfaceMesh:
50 - surf.pointFaces() : edge addressing (for volume tests only)
51 - surf.edges() : edgeTree
52 - surf.faceFaces() : only if minQuality > 0
53
54
55SourceFiles
56 distributedTriSurfaceMesh.C
57
58\*---------------------------------------------------------------------------*/
59
60#ifndef distributedTriSurfaceMesh_H
61#define distributedTriSurfaceMesh_H
62
63#include "triSurfaceMesh.H"
64#include "localIOdictionary.H"
65#include "IOdictionary.H"
66#include "Pair.H"
67#include "globalIndex.H"
68#include "DynamicField.H"
69
70// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71
72namespace Foam
73{
74
75class mapDistribute;
76class decompositionMethod;
77
78// Typedefs
79typedef Pair<point> segment;
80
81
82/*---------------------------------------------------------------------------*\
83 Class distributedTriSurfaceMesh Declaration
84\*---------------------------------------------------------------------------*/
87:
88 public triSurfaceMesh
89{
90public:
91
92 // Static data
95 {
96 FOLLOW = 0,
98 DISTRIBUTED = 2,
100 };
103
104private:
105
106 // Private member data
107
108 //- Merging distance
109 scalar mergeDist_;
110
111 autoPtr<IOdictionary> decomposeParDict_;
112
113 //- Decomposition used when independently decomposing surface.
115
116 //- Bounding box settings
117 localIOdictionary dict_;
118
119 //- Bounding boxes of all processors
121
122 //- Global triangle numbering
123 mutable autoPtr<globalIndex> globalTris_;
124
125 //- The (wanted) distribution type.
126 distributionType distType_;
127
128 //- The (current) distribution type. Used to trigger re-distribution
129 // when starting from undecomposed surface.
130 distributionType currentDistType_;
131
132
133 // Private Member Functions
134
135 // Read
136
137 //- Search for io.local directory (=triSurface) either in case
138 // directory or in parent directory
139 static word findLocalInstance(const IOobject& io);
140
141 //- Read my additional data
142 bool read();
143
144
145 // Line intersection
146
147 static bool isLocal
148 (
149 const List<treeBoundBox>& myBbs,
150 const point& start,
151 const point& end
152 );
153
154 //- Split segment into subsegments overlapping the processor
155 // bounding box.
156 //void Foam::distributedTriSurfaceMesh::splitSegment
157 //(
158 // const label segmentI,
159 // const point& start,
160 // const point& end,
161 // const treeBoundBox& bb,
162 //
163 // DynamicList<segment>& allSegments,
164 // DynamicList<label>& allSegmentMap,
165 // DynamicList<label> sendMap
166 //) const
167
168 //- Distribute segments into overlapping processor
169 // bounding boxes. Sort per processor.
170 void distributeSegment
171 (
172 const label,
173 const point& start,
174 const point& end,
175
179 ) const;
180
181 //- Divide edges into local and remote segments. Construct map to
182 // distribute and collect data.
183 autoPtr<mapDistribute> distributeSegments
184 (
185 const pointField& start,
186 const pointField& end,
187
188 List<segment>& allSegments,
189 List<label>& allSegmentMap
190 ) const;
191
192 //- Split edges, distribute, test and collect.
193 void findLine
194 (
195 const bool nearestIntersection,
196 const pointField& start,
197 const pointField& end,
199 ) const;
200
201
202 // Triangle index
203
204
205 //- Helper: convert local triangle indices to global ones
206 void convertTriIndices(List<pointIndexHit>& info) const;
207
208 //- Obtains global indices from pointIndexHit and swaps them back
209 // to their original processor. Used to calculate local region
210 // and normal.
211 autoPtr<mapDistribute> calcLocalQueries
212 (
213 const List<pointIndexHit>&,
214 labelList& triangleIndex
215 ) const;
216
217
218 // Nearest
219
220 //- Is location inside any of the bounding boxes
221 bool contains
222 (
223 const List<treeBoundBox>& bbs,
224 const point& sample
225 ) const;
226
227 //- Is location inside any of the processors bb or if not
228 // does it overlap
229 Tuple2<label, scalar> findBestProcs
230 (
231 const point& centre,
232 const scalar radiusSqr,
233 boolList& procContains,
234 boolList& procOverlaps,
235 label& minProci
236 ) const;
237
238 label calcOverlappingProcs
239 (
240 const point& centre,
241 const scalar radiusSqr,
242 boolList& overlaps
243 ) const;
244
245 //- Calculate map to send centres+radius to processors
246 autoPtr<mapDistribute> calcLocalQueries
247 (
248 const bool includeLocalProcessor,
249 const pointField& centres,
250 const scalarField& radiusSqr,
251
252 pointField& allCentres,
253 scalarField& allRadiusSqr,
254 labelList& allSegmentMap
255 ) const;
256
257
258 // Side
259
260 //- Side of nearest point w.r.t. edge between face0 and face1
261 volumeType edgeSide
262 (
263 const point& sample,
264 const point& nearestPoint,
265 const label face0,
266 const label face1
267 ) const;
268
269 //- Find edge-connected face
270 label findOtherFace
271 (
273 const label nearFacei,
274 const label nearLabel
275 ) const;
276
277 //- Side of nearest point on faces w.r.t. samples. Handles nearest
278 // on edge/point
279 void surfaceSide
280 (
281 const pointField& samples,
282 const List<pointIndexHit>& nearestInfo,
283 List<volumeType>& region
284 ) const;
285
286
287 // Caching of volume type (based on indexedOctree)
288
289 //- Collect mid points of tree boxes
290 void collectLeafMids
291 (
292 const label nodeI,
293 DynamicField<point>& midPoints
294 ) const;
295
296 //- Find volume type of tree boxes
297 volumeType calcVolumeType
298 (
299 const List<volumeType>& midPointTypes,
300 label& index,
301 PackedList<2>& nodeTypes,
302 const label nodeI
303 ) const;
304
305 //- Look up any cached data. Return unknown if cannot be determined.
306 volumeType cachedVolumeType
307 (
308 const label nodeI,
309 const point& sample
310 ) const;
311
312
313 // Surface redistribution
314
315 //- Calculate face-faces
316 static void calcFaceFaces
317 (
318 const triSurface& s,
321 );
322
323 //- Finds new bounds based on an independent decomposition.
324 List<List<treeBoundBox>> independentlyDistributedBbs
325 (
326 const triSurface&
327 );
328
329 //- Does any part of triangle overlap bb.
330 static bool overlaps
331 (
332 const List<treeBoundBox>& bb,
333 const point& p0,
334 const point& p1,
335 const point& p2
336 );
337
338 //- Find points used in subset
339 static void subsetMeshMap
340 (
341 const triSurface& s,
342 const boolList& include,
343 const label nIncluded,
344 labelList& newToOldPoints,
345 labelList& oldToNewPoints,
346 labelList& newToOldFaces
347 );
348
349 //- Construct subsetted surface
350 static triSurface subsetMesh
351 (
352 const triSurface& s,
353 const labelList& newToOldPoints,
354 const labelList& oldToNewPoints,
355 const labelList& newToOldFaces
356 );
357
358 //- Subset given marked faces
359 static triSurface subsetMesh
360 (
361 const triSurface& s,
362 const boolList& include,
363 labelList& newToOldPoints,
364 labelList& newToOldFaces
365 );
366
367 //- Subset given marked faces
368 static triSurface subsetMesh
369 (
370 const triSurface& s,
371 const labelList& newToOldFaces,
372 labelList& newToOldPoints
373 );
374
375 //- Find triangle otherF in allFaces.
376 static label findTriangle
377 (
378 const List<labelledTri>& allFaces,
379 const labelListList& allPointFaces,
380 const labelledTri& otherF
381 );
382
383 //- Merge triSurface (subTris, subPoints) into allTris, allPoints.
384 static void merge
385 (
386 const scalar mergeDist,
387 const List<labelledTri>& subTris,
388 const pointField& subPoints,
389
390 List<labelledTri>& allTris,
391 pointField& allPoints,
392
393 labelList& faceConstructMap,
394 labelList& pointConstructMap
395 );
396
397 //- Distribute stored fields
398 template<class Type>
399 void distributeFields(const mapDistribute& map);
400
401
402 //- No copy construct
404
405 //- No copy assignment
406 void operator=(const distributedTriSurfaceMesh&) = delete;
407
408
409public:
410
411 //- Runtime type information
412 TypeName("distributedTriSurfaceMesh");
413
414
415 // Constructors
416
417 //- Construct from triSurface
419 (
420 const IOobject&,
421 const triSurface&,
422 const dictionary& dict
423 );
424
425 //- Construct read. Does findInstance to find io.local().
427
428 //- Construct from dictionary (used by searchableSurface).
429 // Does read. Does findInstance to find io.local().
431 (
432 const IOobject& io,
433 const dictionary& dict
434 );
435
436
437 //- Destructor
439
440 //- Clear storage
441 void clearOut();
442
443
444 // Member Functions
445
446 //- Triangle indexing (demand driven)
447 const globalIndex& globalTris() const;
448
449
450 // searchableSurface implementation
451
452 //- Range of global indices that can be returned.
453 virtual label globalSize() const
454 {
455 return globalTris().totalSize();
456 }
457
458 virtual void findNearest
459 (
460 const pointField& sample,
461 const scalarField& nearestDistSqr,
463 ) const;
464
465 //- Find the nearest locations for the supplied points to a
466 // particular region in the searchable surface.
467 virtual void findNearest
468 (
469 const pointField& samples,
470 const scalarField& nearestDistSqr,
471 const labelList& regionIndices,
473 ) const;
474
475 virtual void findLine
476 (
477 const pointField& start,
478 const pointField& end,
480 ) const;
481
482 virtual void findLineAny
483 (
484 const pointField& start,
485 const pointField& end,
487 ) const;
488
489 //- Get all intersections in order from start to end.
490 virtual void findLineAll
491 (
492 const pointField& start,
493 const pointField& end,
495 ) const;
496
497 //- From a set of points and indices get the region
498 virtual void getRegion
499 (
500 const List<pointIndexHit>&,
501 labelList& region
502 ) const;
503
504 //- From a set of points and indices get the normal
505 virtual void getNormal
506 (
507 const List<pointIndexHit>&,
508 vectorField& normal
509 ) const;
510
511 //- Determine type (inside/outside/mixed) for point. unknown if
512 // cannot be determined (e.g. non-manifold surface)
513 virtual void getVolumeType
514 (
515 const pointField&,
517 ) const;
518
519 //- Set bounds of surface. Bounds currently set as list of
520 // bounding boxes. Will do redistribution of surface to locally
521 // have all triangles overlapping bounds.
522 // Larger bounds: more triangles (memory), more fully local tests
523 // (quick).
524 // keepNonLocal = true : keep triangles that do not overlap
525 // any processor bounds.
526 // Should really be split into a routine to determine decomposition
527 // and one that does actual distribution but determining
528 // decomposition with duplicate triangle merging requires
529 // same amount as work as actual distribution.
530 virtual void distribute
531 (
532 const List<treeBoundBox>&,
533 const bool keepNonLocal,
535 autoPtr<mapDistribute>& pointMap
536 );
537
538
539 // Other
540
541 //- WIP. From a set of hits (points and
542 // indices) get the specified field. Misses do not get set.
543 virtual void getField(const List<pointIndexHit>&, labelList&) const;
544
545 //- Calculate the triangles that are overlapping bounds.
546 static void overlappingSurface
547 (
548 const triSurface&,
549 const List<treeBoundBox>&,
550 boolList& includedFace
551 );
552
553 //- Subset the part of surface that is overlapping bounds.
555 (
556 const triSurface&,
557 const List<treeBoundBox>&,
558 labelList& subPointMap,
559 labelList& subFaceMap
560 );
561
562
563 //- Obtains global indices from pointIndexHit and swaps them back
564 // to their original processor. Used to calculate local region
565 // and normal.
567 (
568 const List<pointIndexHit>&,
569 labelList& triangleIndex
570 ) const;
571
572
573 //- Print some stats. Parallel aware version of
574 // triSurface::writeStats.
575 void writeStats(Ostream& os) const;
576
577
578 // regIOobject implementation
579
580 //- Write using stream options
581 // Do not use the triSurfaceMesh::writeObject since it
582 // would filter out empty regions. These need to be preserved
583 // in case we want to make decisions based on the number of
584 // regions.
585 virtual bool writeObject
586 (
587 IOstreamOption streamOpt,
588 const bool valid
589 ) const;
590
591 //- Is object global
592 virtual bool global() const
593 {
594 return false;
595 }
596
597 //- Return complete path + object name if the file exists
598 // either in the case/processor or case otherwise null
599 virtual fileName filePath() const
600 {
602 }
603};
604
605
606//- Template function for obtaining global status
607template<>
609{
610 return false;
611}
612
613
614// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
615
616} // End namespace Foam
617
618// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
619
620#ifdef NoRepository
622#endif
623
624// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
625
626#endif
627
628// ************************************************************************* //
Dynamically sized Field.
Definition: DynamicField.H:65
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
Minimal example by using system/controlDict.functions:
iterator end() noexcept
iterator to signal the end (for any HashTable)
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
fileName localFilePath(const word &typeName, const bool search=true) const
Helper for filePath that searches locally.
Definition: IOobject.C:582
InfoProxy< IOobject > info() const
Return info proxy, for printing information to a stream.
Definition: IOobject.H:690
The IOstreamOption is a simple container for options an IOstream can normally have.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
Definition: PackedList.H:129
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:69
const labelListList & faceFaces() const
Return face-face addressing.
const labelListList & pointFaces() const
Return point-face addressing.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:58
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
IOoject and searching on distributed triSurface. All processor hold (possibly overlapping) part of th...
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
static const Enum< distributionType > distributionTypeNames_
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 findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit > > &) const
Get all intersections in order from start to end.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
virtual bool global() const
Is object global.
static void overlappingSurface(const triSurface &, const List< treeBoundBox > &, boolList &includedFace)
Calculate the triangles that are overlapping bounds.
TypeName("distributedTriSurfaceMesh")
Runtime type information.
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.
virtual autoPtr< mapDistribute > localQueries(const List< pointIndexHit > &, labelList &triangleIndex) const
Obtains global indices from pointIndexHit and swaps them back.
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
virtual fileName filePath() const
Return complete path + object name if the file exists.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
const globalIndex & globalTris() const
Triangle indexing (demand driven)
void writeStats(Ostream &os) const
Print some stats. Parallel aware version of.
virtual label globalSize() const
Range of global indices that can be returned.
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
A class for handling file names.
Definition: fileName.H:76
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
label totalSize() const
Global sum of localSizes.
Definition: globalIndexI.H:125
A triFace with additional (region) index.
Definition: labelledTri.H:60
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
Class containing processor-to-processor mapping information.
IOoject and searching on triSurface.
Triangulated surface description with patch information.
Definition: triSurface.H:79
An enumeration wrapper for classification of a location as being inside/outside of a volume.
Definition: volumeType.H:61
A class for handling words, derived from Foam::string.
Definition: word.H:68
const volScalarField & p0
Definition: EEqn.H:36
OBJstream os(runTime.globalPath()/outputName)
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))
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
bool typeGlobal< distributedTriSurfaceMesh >()
Template function for obtaining global status.
Pair< point > segment
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73
scalarField samples(nIntervals, Zero)