box.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) 2017-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::processorLODs::box
28 
29 Description
30  Creates the parallel distribution map by describing the source and target
31  objects using box shapes.
32 
33  A single box is created for the source object, which is then split using
34  2x2x2 refinement based on the number of remote target objects that overlap.
35  The refinement is local between communicating processor pairs, where the
36  refinement continues until a threshold number of remote target objects per
37  source box is achieved.
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef processorLODs_box
42 #define processorLODs_box
43 
44 #include "processorLOD.H"
45 #include "treeBoundBox.H"
46 #include "HashSet.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 namespace processorLODs
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class Box Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 class box
60 :
61  public processorLOD
62 {
63 protected:
64 
65  // Protected data
66 
67  // Flags to indicate what to do with a box
68 
69  //- Drop/discard
70  static const label DROP;
71 
72  //- Refine
73  static const label REFINE;
74 
75  //- Fixed - do not touch
76  static const label FIXED;
77 
78 
79  //- Reference to the source points
80  const UList<point>& srcPoints_;
81 
82  //- Reference to the target points
83  const UList<point>& tgtPoints_;
84 
85  //- Per processor, the list of src bound boxes
86  // Note: using treeBoundBox to take advantage of subBbox() method
88 
89  //- Maximum number of refinement iterations
90  label nRefineIterMax_;
91 
92 
93  // Caching controls
94 
95  //- Number of iterations before element indices are cached
96  static const label nStartUpIter;
97 
98  //- Addressing per proc of new to old bound boxes
100 
101  //- Indices of elements in the src boxes
103 
104 
105  // Private Member Functions
107  //- Helper function to write the boxes in OBJ format
108  void writeBoxes
109  (
110  const List<DynamicList<treeBoundBox>>& fixedBoxes,
111  const label iter
112  ) const;
113 
114 
115  virtual boundBox calcSrcBox(const label srcObji) const = 0;
116  virtual boundBox calcTgtBox(const label tgtObji) const = 0;
117 
118  //- Set the box refinement flags
119  void setRefineFlags
120  (
121  const label refineIter,
122  const label nTgtObjects,
123  List<labelHashSet>& fixedSendElems,
124  List<List<labelList>>& localTgtElems,
125  List<labelList>& refineFlags,
126  labelList& nElems
127  ) const;
128 
129  void refineBox
130  (
131  const label boxi,
132  const label refineIter,
133  const label nSrcElem,
134  const treeBoundBox& origBox,
135  DynamicList<treeBoundBox>& procBoxes,
136  DynamicList<labelList>& procBoxElems,
137  DynamicList<label>& procNewToOld
138  ) const;
139 
140  void refineBox
141  (
142  const label boxi,
143  const labelList& srcAddr,
144  const treeBoundBox& origBox,
145  DynamicList<treeBoundBox>& procBoxes,
146  DynamicList<labelList>& procBoxElems,
147  DynamicList<label>& procNewToOld
148  ) const;
149 
150 
151  //- Apply the box refinements
152  // \return true if still refining
153  bool doRefineBoxes
154  (
155  const label refineIter,
156  const label nSrcFaces,
157  const List<labelList>& refineFlags,
158  List<DynamicList<treeBoundBox>>& fixedBoxes
159  );
160 
162  (
163  const label nSrcElems,
164  const label nTgtElems
165  );
166 
167 
168 public:
169 
170  //- Runtime type information
171  TypeName("box");
172 
173  //- Construct from list of points
174  box
175  (
176  const UList<point>& srcPoints,
177  const UList<point>& tgtPoints,
178  const label maxObjectsPerLeaf,
179  const label nObjectsOfType,
180  const label nRefineIterMax = 100
181  );
182 
183  //- Destructor
184  virtual ~box() = default;
185 };
186 
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 } // End namespace processorLODs
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
void writeBoxes(const List< DynamicList< treeBoundBox >> &fixedBoxes, const label iter) const
Helper function to write the boxes in OBJ format.
Definition: box.C:42
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
label nRefineIterMax_
Maximum number of refinement iterations.
Definition: box.H:98
TypeName("box")
Runtime type information.
List< labelList > newToOld_
Addressing per proc of new to old bound boxes.
Definition: box.H:111
List< List< treeBoundBox > > boxes_
Per processor, the list of src bound boxes.
Definition: box.H:93
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
static const label REFINE
Refine.
Definition: box.H:70
virtual ~box()=default
Destructor.
Base class to generate a parallel distribution map for sending sufficient target objects to cover a d...
Definition: processorLOD.H:46
bool doRefineBoxes(const label refineIter, const label nSrcFaces, const List< labelList > &refineFlags, List< DynamicList< treeBoundBox >> &fixedBoxes)
Apply the box refinements.
Definition: box.C:307
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
static const label nStartUpIter
Number of iterations before element indices are cached.
Definition: box.H:106
box(const UList< point > &srcPoints, const UList< point > &tgtPoints, const label maxObjectsPerLeaf, const label nObjectsOfType, const label nRefineIterMax=100)
Construct from list of points.
Definition: box.C:531
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:99
Creates the parallel distribution map by describing the source and target objects using box shapes...
Definition: box.H:52
virtual boundBox calcTgtBox(const label tgtObji) const =0
virtual boundBox calcSrcBox(const label srcObji) const =0
void refineBox(const label boxi, const label refineIter, const label nSrcElem, const treeBoundBox &origBox, DynamicList< treeBoundBox > &procBoxes, DynamicList< labelList > &procBoxElems, DynamicList< label > &procNewToOld) const
Definition: box.C:212
List< List< labelList > > boxSrcElems_
Indices of elements in the src boxes.
Definition: box.H:116
const UList< point > & srcPoints_
Reference to the source points.
Definition: box.H:81
void setRefineFlags(const label refineIter, const label nTgtObjects, List< labelHashSet > &fixedSendElems, List< List< labelList >> &localTgtElems, List< labelList > &refineFlags, labelList &nElems) const
Set the box refinement flags.
Definition: box.C:92
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:90
static const label FIXED
Fixed - do not touch.
Definition: box.H:75
static const label DROP
Drop/discard.
Definition: box.H:65
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
const UList< point > & tgtPoints_
Reference to the target points.
Definition: box.H:86
Namespace for OpenFOAM.
autoPtr< mapDistribute > createMap(const label nSrcElems, const label nTgtElems)
Definition: box.C:412