meshOctree.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 "meshOctree.H"
29 #include "triSurf.H"
30 #include "boundBox.H"
31 #include "demandDrivenData.H"
32 
33 # ifdef USE_OMP
34 #include <omp.h>
35 # endif
36 
37 //#define DEBUGSearch
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 // Construct from surface
47 meshOctree::meshOctree(const triSurf& ts, const bool isQuadtree)
48 :
49  surface_(ts),
50  neiProcs_(),
51  neiRange_(),
52  initialCubePtr_(NULL),
53  initialCubeRotation_(0),
54  rootBox_(),
55  isRootInitialised_(false),
56  searchRange_(0.0),
57  octantVectors_(),
58  vrtLeavesPos_(),
59  regularityPositions_(),
60  dataSlots_(),
61  leaves_(),
62  isQuadtree_(isQuadtree)
63 {
65 
67 }
68 
69 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70 
72 {}
73 
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 
77 {
78  octantVectors_[0] = Vector<label>(-1, -1, -1);
79  octantVectors_[1] = Vector<label>(1, -1, -1);
80  octantVectors_[2] = Vector<label>(-1, 1, -1);
81  octantVectors_[3] = Vector<label>(1, 1, -1);
82  octantVectors_[4] = Vector<label>(-1, -1, 1);
83  octantVectors_[5] = Vector<label>(1, -1, 1);
84  octantVectors_[6] = Vector<label>(-1, 1, 1);
85  octantVectors_[7] = Vector<label>(1, 1, 1);
86 
87  # ifdef DEBUGSearch
88  Info << "Octant vectors " << octantVectors_ << endl;
89  # endif
90 
91  //- set regularity positions
92  //- neighbours over faces
99 
100  //- neighbours over edges
101  //- edges in x-direction
106 
107  //- edges in y-direction
112 
113  //- edges in z-direction
118 
119  //- neighbours over vertices
120  regularityPositions_[18] = meshOctreeCubeCoordinates(-1, -1, -1, 0);
128 
129  # ifdef DEBUGSearch
130  Info << "Regularity positions " << regularityPositions_ << endl;
131  # endif
132 
133  //- set vrtLeavesPos_
134  for(label vrtI=0;vrtI<8;++vrtI)
135  {
136  FixedList<label, 3> vc(0);
137 
138  if( vrtI & 1 )
139  vc[0] += 1;
140  if( vrtI & 2 )
141  vc[1] += 1;
142  if( vrtI & 4 )
143  vc[2] += 1;
144 
145  # ifdef DEBUGSearch
146  Info << "Vert " << vrtI << " vc " << vc << endl;
147  # endif
148 
149  for(label i=0;i<8;++i)
150  {
152 
153  for(label j=0;j<3;++j)
154  {
155  if( vc[j] == 0 && octantVectors_[i][j] == 1 )
156  {
157  pos[j] = 0;
158  }
159  else if( vc[j] == 1 && octantVectors_[i][j] == 1 )
160  {
161  pos[j] = 1;
162  }
163  else
164  {
165  pos[j] = vc[j] + octantVectors_[i][j];
166  }
167  }
168 
169  vrtLeavesPos_[vrtI][i] =
171  (
172  pos[0],
173  pos[1],
174  pos[2],
175  direction(0)
176  );
177  }
178  }
179 
180  # ifdef DEBUGSearch
181  Info << "vrtLeavesPos_ " << vrtLeavesPos_ << endl;
182  # endif
183 }
184 
186 {
187  //- create initial octree box
188  boundBox bb(surface_.points());
189  const point& min_ = bb.min();
190  const point& max_ = bb.max();
191 
192  const point c = (max_ + min_) / 2.0;
193  scalar cs = 1.5 * (max_.x() - min_.x()) / 2.0;
194  if( cs < (1.5 * (max_.y() - min_.y()) / 2.0) )
195  {
196  cs = 1.5 * (max_.y() - min_.y()) / 2.0;
197  }
198  if( cs < (1.5 * (max_.z() - min_.z()) / 2.0) )
199  {
200  cs = 1.5 * (max_.z() - min_.z()) / 2.0;
201  }
202 
203  //- create root box and initial cube
204  rootBox_ = boundBox(c - point(cs, cs, cs), c + point(cs, cs, cs));
205 
206  if( Pstream::parRun() )
207  {
210  }
211 
212  //- allocate data slots
213  # ifdef USE_OMP
214  if( omp_get_num_procs() > 0 )
215  {
216  dataSlots_.setSize(omp_get_num_procs());
217  }
218  else
219  {
220  dataSlots_.setSize(1);
221  }
222  # else
223  dataSlots_.setSize(1);
224  # endif
225 
226  meshOctreeSlot* slotPtr = &dataSlots_[0];
227 
228  if( !isQuadtree_ )
229  {
230  slotPtr->cubes_.append
231  (
233  (
234  meshOctreeCubeCoordinates(0, 0, 0, 0),
235  surface_.size(),
236  slotPtr
237  )
238  );
239  }
240  else
241  {
242  slotPtr->cubes_.append
243  (
245  (
246  meshOctreeCubeCoordinates(0, 0, -10, 0),
247  surface_.size(),
248  slotPtr
249  )
250  );
251  }
252 
253  initialCubePtr_ = &slotPtr->cubes_[0];
254 
255  leaves_.setSize(1);
257 }
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 } // End namespace Foam
262 
263 // ************************************************************************* //
Foam::meshOctree::octantVectors_
FixedList< Vector< label >, 8 > octantVectors_
Definition: meshOctree.H:81
Foam::maxOp
Definition: ops.H:172
Foam::meshOctree::regularityPositions_
FixedList< meshOctreeCubeCoordinates, 26 > regularityPositions_
Definition: meshOctree.H:83
triSurf.H
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
Foam::meshOctreeCubeCoordinates
Definition: meshOctreeCubeCoordinates.H:55
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::triSurfPoints::points
const pointField & points() const
access to points
Definition: triSurfPointsI.H:44
Foam::minOp
Definition: ops.H:173
Foam::meshOctree::setOctantVectorsAndPositions
void setOctantVectorsAndPositions()
set data needed for finding neighbours
Definition: meshOctree.C:76
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::meshOctree::dataSlots_
List< meshOctreeSlot > dataSlots_
List of slots containing data generated by each processor.
Definition: meshOctree.H:86
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::meshOctreeSlot::cubes_
LongList< meshOctreeCube > cubes_
List of octree cubes.
Definition: meshOctreeSlot.H:56
Foam::meshOctree::vrtLeavesPos_
FixedList< FixedList< meshOctreeCubeCoordinates, 8 >, 8 > vrtLeavesPos_
Definition: meshOctree.H:82
meshOctree.H
Foam::meshOctree::~meshOctree
~meshOctree()
Definition: meshOctree.C:71
Foam::meshOctreeSlot
Definition: meshOctreeSlot.H:50
Foam::meshOctree::meshOctree
meshOctree(const meshOctree &)
Disallow default bitwise copy construct.
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
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::Info
messageStream Info
Foam::meshOctree::isQuadtree_
const bool isQuadtree_
a flag whether is true if is it a quadtree
Definition: meshOctree.H:92
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam::meshOctree::leaves_
LongList< meshOctreeCube * > leaves_
list of cubes which are leaves of the octree
Definition: meshOctree.H:89
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::meshOctree::rootBox_
boundBox rootBox_
Definition: meshOctree.H:73
boundBox.H
Foam::triSurfFacets::size
label size() const
return the number of triangles
Definition: triSurfFacetsI.H:39
Foam::meshOctree::surface_
const triSurf & surface_
Reference to surface to work on.
Definition: meshOctree.H:59
Foam::Vector< label >
Foam::FixedList< label, 3 >
Foam::meshOctreeCube
Definition: meshOctreeCube.H:56
Foam::direction
unsigned char direction
Definition: direction.H:43
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::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
Foam::meshOctree::initialCubePtr_
meshOctreeCube * initialCubePtr_
Root cube of the octree structure.
Definition: meshOctree.H:71
Foam::point
vector point
Point is a vector.
Definition: point.H:41
Foam::meshOctree::createInitialOctreeBox
void createInitialOctreeBox()
create initial octree box
Definition: meshOctree.C:185
Foam::triSurf
Definition: triSurf.H:59
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:190