meshOctreeCubeRecursiveFunctions.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "meshOctreeCube.H"
29 #include "demandDrivenData.H"
30 #include "Ostream.H"
31 #include "meshOctree.H"
32 
33 //#define DEBUGSearch
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
43 (
44  const boundBox& rootBox,
45  const boundBox& searchingBox,
47 ) const
48 {
49  boundBox cubeBox;
50  this->cubeBox(rootBox, cubeBox.min(), cubeBox.max());
51 
52  if( cubeBox.overlaps(searchingBox) )
53  {
54  if( this->isLeaf() )
55  {
56  leaves.append(this);
57  }
58  else
59  {
60  for(label scI=0;scI<8;++scI)
61  {
62  meshOctreeCube* scPtr = subCubesPtr_[scI];
63 
64  if( scPtr )
65  {
66  scPtr->leavesInBox
67  (
68  rootBox,
69  searchingBox,
70  leaves
71  );
72  }
73  else if( Pstream::parRun() )
74  {
75  meshOctreeCubeCoordinates cc = refineForPosition(scI);
76 
77  boundBox bb;
78  cc.cubeBox(rootBox, bb.min(), bb.max());
79 
80  if( bb.overlaps(searchingBox) )
81  leaves.append(this);
82  }
83  }
84  }
85  }
86 }
87 
89 (
90  const boundBox& rootBox,
91  const point& c,
92  const scalar r,
93  DynList<label>& containedLeaves
94 ) const
95 {
96  const point cubeCentre = this->centre(rootBox);
97  const scalar size = 1.732 * this->size(rootBox);
98 
99  if( magSqr(cubeCentre - c) < sqr(r+size) )
100  {
101  if( this->isLeaf() )
102  {
103  containedLeaves.append(this->cubeLabel());
104  }
105  else
106  {
107  for(label scI=0;scI<8;++scI)
108  {
109  meshOctreeCube* scPtr = subCubesPtr_[scI];
110 
111  if( scPtr )
112  {
113  scPtr->leavesInSphere
114  (
115  rootBox,
116  c,
117  r,
118  containedLeaves
119  );
120  }
121  else if( Pstream::parRun() )
122  {
123  meshOctreeCubeCoordinates cc = refineForPosition(scI);
124  const point sc = cc.centre(rootBox);
125 
126  if( magSqr(sc - c) < sqr(r+size) )
127  containedLeaves.append(meshOctreeCube::OTHERPROC);
128  }
129  }
130  }
131  }
132 }
133 
135 (
136  const boundBox& rootBox,
137  const point& c,
138  const scalar r,
139  labelList& markedLeaves,
140  bool& atProcessorBnd
141 ) const
142 {
143  const point cubeCentre = this->centre(rootBox);
144  const scalar size = 1.732 * this->size(rootBox);
145 
146  if( magSqr(cubeCentre - c) < sqr(r+size) )
147  {
148  if( this->isLeaf() )
149  {
150  markedLeaves[this->cubeLabel()] |= 2;
151  }
152  else
153  {
154  for(label scI=0;scI<8;++scI)
155  {
156  meshOctreeCube* scPtr = subCubesPtr_[scI];
157 
158  if( scPtr )
159  {
160  scPtr->markLeavesInSphere
161  (
162  rootBox,
163  c,
164  r,
165  markedLeaves,
166  atProcessorBnd
167  );
168  }
169  else if( Pstream::parRun() )
170  {
171  meshOctreeCubeCoordinates cc = refineForPosition(scI);
172  const point sc = cc.centre(rootBox);
173 
174  if( magSqr(sc - c) < sqr(r+size) )
175  {
176  atProcessorBnd = true;
177  }
178  }
179  }
180  }
181  }
182 }
183 
185 {
186  if( this->isLeaf() )
187  {
188  meshOctreeCube* oc = const_cast<meshOctreeCube*>(this);
189  cubeLabel_ = leaves.size();
190  leaves.append(oc);
191  }
192  else
193  {
194  cubeLabel_ = -1;
195 
196  for(label scI=0;scI<8;++scI)
197  {
198  const meshOctreeCube* scPtr = subCubesPtr_[scI];
199 
200  if( scPtr )
201  scPtr->findLeaves(leaves);
202  }
203  }
204 }
205 
207 (
209 ) const
210 {
211  if( this->isLeaf() )
212  return;
213 
214  for(label scI=0;scI<8;++scI)
215  {
216  meshOctreeCube* scPtr = subCubesPtr_[scI];
217 
218  if( scPtr )
219  {
221  }
222  else
223  {
224  coordinates.append(this->refineForPosition(scI));
225  }
226  }
227 }
228 
230 {
231  ++counter;
232 
233  if( !this->isLeaf() )
234  {
235  for(label scI=0;scI<8;++scI)
236  {
237  meshOctreeCube* scPtr = subCubesPtr_[scI];
238 
239  if( scPtr )
240  {
241  scPtr->countChildCubes(counter);
242  }
243  }
244  }
245 }
246 
247 bool meshOctreeCube::purgeProcessorCubes(const short procNo)
248 {
249  if( this->procNo() == ALLPROCS )
250  {
251  this->setProcNo(procNo);
252  }
253 
254  if( this->isLeaf() )
255  {
256  if( this->procNo() != procNo )
257  {
258  return true;
259  }
260 
261  return false;
262  }
263  else
264  {
265  label mergedSubcubes = 0;
266  for(label scI=0;scI<8;++scI)
267  {
268  if( !subCubesPtr_[scI] )
269  {
270  mergedSubcubes |= 1 << scI;
271  continue;
272  }
273 
275  {
276  subCubesPtr_[scI] = NULL;
277  mergedSubcubes |= 1 << scI;
278  }
279  }
280 
281  if( mergedSubcubes == 255 )
282  {
283  subCubesPtr_ = NULL;
284 
285  return true;
286  }
287  else
288  {
289  return false;
290  }
291  }
292 
293  return false;
294 }
295 
296 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 
298 } // End namespace Foam
299 
300 // ************************************************************************* //
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
Foam::meshOctreeCubeBasic::ALLPROCS
@ ALLPROCS
Definition: meshOctreeCubeBasic.H:92
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
Foam::PtrList::append
void append(T *)
Append an element at the end of the list.
Foam::meshOctreeCubeCoordinates
Definition: meshOctreeCubeCoordinates.H:55
Foam::meshOctreeCubeCoordinates::centre
point centre(const boundBox &) const
return centre
Definition: meshOctreeCubeCoordinatesI.H:203
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::meshOctreeCube::findCoordinatesOfMissingCubes
void findCoordinatesOfMissingCubes(LongList< meshOctreeCubeCoordinates > &coordinates) const
find coordinates of cubes which are located on other processors
Definition: meshOctreeCubeRecursiveFunctions.C:207
meshOctreeCube.H
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::meshOctreeCube::leavesInSphere
void leavesInSphere(const boundBox &rootBox, const point &, const scalar, DynList< label > &) const
find leaves within a sphere
Definition: meshOctreeCubeRecursiveFunctions.C:89
meshOctree.H
Foam::meshOctreeCube::countChildCubes
void countChildCubes(label &nCubes) const
count number of originating from this cube
Definition: meshOctreeCubeRecursiveFunctions.C:229
Foam::LongList
Definition: LongList.H:55
Foam::label
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
Foam::meshOctreeCube::cubeLabel_
label cubeLabel_
position of the cube in the list of leaves
Definition: meshOctreeCube.H:67
Foam::boundBox::overlaps
bool overlaps(const boundBox &) const
Overlaps/touches boundingBox?
Definition: boundBoxI.H:120
Foam::meshOctreeCube::subCubesPtr_
meshOctreeCube ** subCubesPtr_
pointer to the first child element
Definition: meshOctreeCube.H:64
Foam::meshOctreeCube::isLeaf
bool isLeaf() const
check if the cube is a leaf
Definition: meshOctreeCubeI.H:63
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
Foam::meshOctreeCube::leavesInBox
void leavesInBox(const boundBox &rootBox, const boundBox &searchingBox, DynList< const meshOctreeCube *, 256 > &) const
leaves contained in the given box
Definition: meshOctreeCubeRecursiveFunctions.C:43
coordinates
PtrList< coordinateSystem > coordinates(solidRegions.size())
Foam::meshOctreeCubeBasic::setProcNo
void setProcNo(const short)
set processor number
Definition: meshOctreeCubeBasicI.H:85
Foam::meshOctreeCube::markLeavesInSphere
void markLeavesInSphere(const boundBox &rootBox, const point &, const scalar, labelList &, bool &) const
mark leaves within a sphere
Definition: meshOctreeCubeRecursiveFunctions.C:135
Foam::meshOctreeCube::purgeProcessorCubes
bool purgeProcessorCubes(const short procNo)
delete boxes which are not local to the given processor
Definition: meshOctreeCubeRecursiveFunctions.C:247
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynList
Definition: DynList.H:53
Foam::meshOctreeCubeBasic::OTHERPROC
@ OTHERPROC
Definition: meshOctreeCubeBasic.H:93
Ostream.H
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::meshOctreeCube
Definition: meshOctreeCube.H:56
Foam::meshOctreeCubeBasic::procNo
short procNo() const
return processor number
Definition: meshOctreeCubeBasicI.H:80
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::meshOctreeCubeCoordinates::cubeBox
void cubeBox(const boundBox &, point &, point &) const
return min and max points
Definition: meshOctreeCubeCoordinatesI.H:174
Foam::meshOctreeCube::findLeaves
void findLeaves(LongList< meshOctreeCube * > &leaves) const
find leaves for a given cube
Definition: meshOctreeCubeRecursiveFunctions.C:184
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304