distributedTriSurface.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::searchableSurfaces::distributedTriSurface
26 
27 Description
28  IOoject and searching on distributed triSurface. All processor hold
29  (possibly overlapping) part of the overall surface. All queries are
30  distributed to the processor that can answer it and the result sent back.
31 
32  Can work in three modes:
33  - follow : makes sure each processor has all the triangles inside the
34  externally provided bounding box (usually the mesh bounding box).
35  Guarantees minimum amount of communication since mesh-local queries
36  should be answerable without any comms.
37  - independent : surface is decomposed according to the triangle centres
38  so the decomposition might be radically different from the mesh
39  decomposition. Guarantees best memory balance but at the expense of
40  more communication.
41  - frozen : no change
42 
43 SourceFiles
44  distributedTriSurface.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef distributedTriSurface_H
49 #define distributedTriSurface_H
50 
52 #include "IOdictionary.H"
53 #include "Pair.H"
54 #include "globalIndex.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 class distributionMap;
62 class decompositionMethod;
63 
64 // Typedefs
65 typedef Pair<point> segment;
66 template<>
67 inline bool contiguous<segment>() {return contiguous<point>();}
68 
69 namespace searchableSurfaces
70 {
71 
72 /*---------------------------------------------------------------------------*\
73  Class distributedTriSurface Declaration
74 \*---------------------------------------------------------------------------*/
75 
77 :
78  public triSurface
79 {
80 public:
81 
82  // Static data
83 
84  enum distributionType
85  {
86  FOLLOW = 0,
87  INDEPENDENT = 1,
88  FROZEN = 2
89  };
90 
92 
93 
94 private:
95 
96  // Private Data
97 
98  //- Merging distance
99  scalar mergeDist_;
100 
101  //- Decomposition used when independently decomposing surface.
102  autoPtr<decompositionMethod> distributor_;
103 
104  //- Bounding box settings
105  IOdictionary dict_;
106 
107  //- Bounding boxes of all processors
108  List<List<treeBoundBox>> procBb_;
109 
110  //- Global triangle numbering
111  mutable autoPtr<globalIndex> globalTris_;
112 
113  //- The distribution type.
114  distributionType distType_;
115 
116 
117  // Private Member Functions
118 
119  // Read
120 
121  //- Read my additional data
122  bool read();
123 
124 
125  // Line intersection
126 
127  static bool isLocal
128  (
129  const List<treeBoundBox>& myBbs,
130  const point& start,
131  const point& end
132  );
133 
134  //- Split segment into subsegments overlapping the processor
135  // bounding box.
136  // void Foam::distributedTriSurface::splitSegment
137  //(
138  // const label segmentI,
139  // const point& start,
140  // const point& end,
141  // const treeBoundBox& bb,
142  //
143  // DynamicList<segment>& allSegments,
144  // DynamicList<label>& allSegmentMap,
145  // DynamicList<label> sendMap
146  //) const
147 
148  //- Distribute segments into overlapping processor
149  // bounding boxes. Sort per processor.
150  void distributeSegment
151  (
152  const label,
153  const point& start,
154  const point& end,
155 
159  ) const;
160 
161  //- Divide edges into local and remote segments. Construct map to
162  // distribute and collect data.
163  autoPtr<distributionMap> distributeSegments
164  (
165  const pointField& start,
166  const pointField& end,
167 
168  List<segment>& allSegments,
169  List<label>& allSegmentMap
170  ) const;
171 
172  //- Split edges, distribute, test and collect.
173  void findLine
174  (
175  const bool nearestIntersection,
176  const pointField& start,
177  const pointField& end,
179  ) const;
180 
181 
182  // Triangle index
183 
184  //- Obtains global indices from pointIndexHit and swaps them back
185  // to their original processor. Used to calculate local region
186  // and normal.
187  autoPtr<distributionMap> calcLocalQueries
188  (
189  const List<pointIndexHit>&,
190  labelList& triangleIndex
191  ) const;
192 
193 
194  // Nearest
195 
196  label calcOverlappingProcs
197  (
198  const point& centre,
199  const scalar radiusSqr,
200  boolList& overlaps
201  ) const;
202 
203  autoPtr<distributionMap> calcLocalQueries
204  (
205  const pointField& centres,
206  const scalarField& radiusSqr,
207 
208  pointField& allCentres,
209  scalarField& allRadiusSqr,
210  labelList& allSegmentMap
211  ) const;
212 
213 
214  // Surface redistribution
215 
216  //- Finds new bounds based on an independent decomposition.
217  List<List<treeBoundBox>> independentlyDistributedBbs
218  (
219  const Foam::triSurface&
220  );
221 
222  //- Does any part of triangle overlap bb.
223  static bool overlaps
224  (
225  const List<treeBoundBox>& bb,
226  const point& p0,
227  const point& p1,
228  const point& p2
229  );
230 
231  //- Find points used in subset
232  static void subsetMeshMap
233  (
234  const Foam::triSurface& s,
235  const boolList& include,
236  const label nIncluded,
237  labelList& newToOldPoints,
238  labelList& oldToNewPoints,
239  labelList& newToOldFaces
240  );
241 
242  //- Construct subsetted surface
243  static Foam::triSurface subsetMesh
244  (
245  const Foam::triSurface& s,
246  const labelList& newToOldPoints,
247  const labelList& oldToNewPoints,
248  const labelList& newToOldFaces
249  );
250 
251  //- Subset given marked faces
252  static Foam::triSurface subsetMesh
253  (
254  const Foam::triSurface& s,
255  const boolList& include,
256  labelList& newToOldPoints,
257  labelList& newToOldFaces
258  );
259 
260  //- Subset given marked faces
261  static Foam::triSurface subsetMesh
262  (
263  const Foam::triSurface& s,
264  const labelList& newToOldFaces,
265  labelList& newToOldPoints
266  );
267 
268  //- Find triangle otherF in allFaces.
269  static label findTriangle
270  (
271  const List<labelledTri>& allFaces,
272  const labelListList& allPointFaces,
273  const labelledTri& otherF
274  );
275 
276  //- Merge triSurface (subTris, subPoints) into allTris, allPoints.
277  static void merge
278  (
279  const scalar mergeDist,
280  const List<labelledTri>& subTris,
281  const pointField& subPoints,
282 
283  List<labelledTri>& allTris,
284  pointField& allPoints,
285 
286  labelList& faceConstructMap,
287  labelList& pointConstructMap
288  );
289 
290  //- Distribute stored fields
291  template<class Type>
292  void distributeFields(const distributionMap& map);
293 
294 
295 public:
296 
297  //- Runtime type information
298  TypeName("distributedTriSurface");
299 
300 
301  // Constructors
302 
303  //- Construct from triSurface
305  (
306  const IOobject&,
307  const Foam::triSurface&,
308  const dictionary& dict
309  );
310 
311  //- Construct read. Does findInstance to find io.local().
312  distributedTriSurface(const IOobject& io);
313 
314  //- Construct from dictionary (used by searchableSurface).
315  // Does read. Does findInstance to find io.local().
317  (
318  const IOobject& io,
319  const dictionary& dict
320  );
321 
322  //- Disallow default bitwise copy construction
324 
325 
326  //- Destructor
327  virtual ~distributedTriSurface();
328 
329  //- Clear storage
330  void clearOut();
331 
332 
333  // Member Functions
334 
335  //- Triangle indexing (demand driven)
336  const globalIndex& globalTris() const;
337 
338 
339  // searchableSurface implementation
340 
341  //- Whether supports volume type below. I.e. whether is closed.
342  // Not supported.
343  virtual bool hasVolumeType() const
344  {
345  return false;
346  }
347 
348  //- Range of global indices that can be returned.
349  virtual label globalSize() const
350  {
351  return globalTris().size();
352  }
353 
354  virtual void findNearest
355  (
356  const pointField& sample,
357  const scalarField& nearestDistSqr,
359  ) const;
360 
361  virtual void findLine
362  (
363  const pointField& start,
364  const pointField& end,
366  ) const;
367 
368  virtual void findLineAny
369  (
370  const pointField& start,
371  const pointField& end,
373  ) const;
374 
375  //- Get all intersections in order from start to end.
376  virtual void findLineAll
377  (
378  const pointField& start,
379  const pointField& end,
381  ) const;
382 
383  //- From a set of points and indices get the region
384  virtual void getRegion
385  (
386  const List<pointIndexHit>&,
387  labelList& region
388  ) const;
389 
390  //- From a set of points and indices get the normal
391  virtual void getNormal
392  (
393  const List<pointIndexHit>&,
394  vectorField& normal
395  ) const;
396 
397  //- Determine type (inside/outside/mixed) for point. unknown if
398  // cannot be determined (e.g. non-manifold surface)
399  virtual void getVolumeType
400  (
401  const pointField&,
403  ) const;
404 
405  //- Set bounds of surface. Bounds currently set as list of
406  // bounding boxes. Will do redistribution of surface to locally
407  // have all triangles overlapping bounds.
408  // Larger bounds: more triangles (memory), more fully local tests
409  // (quick).
410  // keepNonLocal = true : keep triangles that do not overlap
411  // any processor bounds.
412  // Should really be split into a routine to determine decomposition
413  // and one that does actual distribution but determining
414  // decomposition with duplicate triangle merging requires
415  // same amount as work as actual distribution.
416  virtual void distribute
417  (
418  const List<treeBoundBox>&,
419  const bool keepNonLocal,
421  autoPtr<distributionMap>& pointMap
422  );
423 
424 
425  // Other
426 
427  //- WIP. From a set of hits (points and
428  // indices) get the specified field. Misses do not get set.
429  virtual void getField(const List<pointIndexHit>&, labelList&) const;
430 
431  //- Subset the part of surface that is overlapping bounds.
433  (
434  const Foam::triSurface&,
435  const List<treeBoundBox>&,
436  labelList& subPointMap,
437  labelList& subFaceMap
438  );
439 
440  //- Print some stats. Parallel aware version of
441  // triSurface::writeStats.
442  void writeStats(Ostream& os) const;
443 
444 
445  // regIOobject implementation
446 
447  //- Write using given format, version and compression
448  // Do not use the triSurface::writeObject since it
449  // would filter out empty regions. These need to be preserved
450  // in case we want to make decisions based on the number of
451  // regions.
452  virtual bool writeObject
453  (
457  const bool write = true
458  ) const;
459 
460  //- Is object global
461  virtual bool global() const
462  {
463  return false;
464  }
465 
466 
467  // Member Operators
468 
469  //- Disallow default bitwise assignment
470  void operator=(const distributedTriSurface&) = delete;
471 };
472 
473 
474 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
475 
476 } // End of namespace searchableSurfaces
477 
478 //- Trait for obtaining global status
479 template<>
480 struct typeGlobal<searchableSurfaces::distributedTriSurface>
481 {
482  static const bool global = false;
483 };
484 
485 } // End namespace Foam
486 
487 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
488 
489 #ifdef NoRepository
491 #endif
492 
493 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
494 
495 #endif
496 
497 // ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:485
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An ordered pair of two objects of type <Type> with first() and second() elements.
Definition: Pair.H:66
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Class containing processor-to-processor mapping information.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:64
label size() const
Global sum of localSizes.
Definition: globalIndexI.H:66
Triangle with additional region number.
Definition: labelledTri.H:60
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.
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.
void operator=(const distributedTriSurface &)=delete
Disallow default bitwise assignment.
static Foam::triSurface overlappingSurface(const Foam::triSurface &, const List< treeBoundBox > &, labelList &subPointMap, labelList &subFaceMap)
Subset the part of surface that is overlapping bounds.
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write using given format, version and compression.
distributedTriSurface(const IOobject &, const Foam::triSurface &, const dictionary &dict)
Construct from triSurface.
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
static const NamedEnum< distributionType, 3 > distributionTypeNames_
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
virtual void distribute(const List< treeBoundBox > &, const bool keepNonLocal, autoPtr< distributionMap > &faceMap, autoPtr< distributionMap > &pointMap)
Set bounds of surface. Bounds currently set as list of.
virtual bool hasVolumeType() const
Whether supports volume type below. I.e. whether is closed.
TypeName("distributedTriSurface")
Runtime type information.
A surface geometry formed of discrete facets, e.g. triangles and/or quadrilaterals,...
Triangulated surface description with patch information.
Definition: triSurface.H:69
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
bool contiguous< segment >()
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Pair< point > segment
dictionary dict
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
Trait for obtaining global status.
Definition: IOobject.H:503
static const bool global
Definition: IOobject.H:504