FreeFOAM The Cross-Platform CFD Toolkit
octreeDataCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "octreeDataCell.H"
29 #include <OpenFOAM/polyMesh.H>
30 #include <OpenFOAM/primitiveMesh.H>
31 #include "treeNode.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 // Construct from components
37 (
38  const polyMesh& mesh,
39  const labelList& cellLabels,
40  const treeBoundBoxList& bbs
41 )
42 :
43  mesh_(mesh),
44  cellLabels_(cellLabels),
45  bbs_(bbs)
46 {}
47 
48 
49 // Construct from mesh (assumes all cells)
51 (
52  const polyMesh& mesh
53 )
54 :
55  mesh_(mesh),
56  cellLabels_(mesh_.nCells()),
57  bbs_
58  (
59  mesh_.nCells(),
60  treeBoundBox::invertedBox
61  )
62 {
63  // Set one-one indexing
64  for (label i=0; i < mesh_.nCells(); i++)
65  {
66  cellLabels_[i] = i;
67  }
68 
69  const pointField& points = mesh_.points();
70  const faceList& faces = mesh_.faces();
71  const cellList& cells = mesh_.cells();
72 
73  forAll(cells, celli)
74  {
75  const labelList& facesi = cells[celli];
76 
77  forAll(facesi, facei)
78  {
79  const labelList& pointsi = faces[facesi[facei]];
80 
81  forAll(pointsi, pointi)
82  {
83  const point& p = points[pointsi[pointi]];
84 
85  bbs_[celli].min() = min(bbs_[celli].min(), p);
86  bbs_[celli].max() = max(bbs_[celli].max(), p);
87  }
88  }
89  }
90 }
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
96 (
98  const point&
99 ) const
100 {
102 }
103 
104 
106 (
107  const label index,
108  const treeBoundBox& cubeBb
109 ) const
110 {
111  return cubeBb.overlaps(bbs_[index]);
112 }
113 
114 
116 (
117  const label index,
118  const point& sample
119 ) const
120 {
121  return mesh_.pointInCell(sample, cellLabels_[index]);
122 }
123 
124 
126 (
127  const label,
128  const point&,
129  const point&,
130  point&
131 ) const
132 {
133  //Hack: don't know what to do here.
134 
136  (
137  "octreeDataCell::intersects(const label, const point&,"
138  "const point&, point&)"
139  );
140 
141  return false;
142 }
143 
144 
146 (
147  const label index,
148  const point& sample,
149  treeBoundBox& tightest
150 ) const
151 {
152 
153  // get nearest and furthest away vertex
154  point myNear, myFar;
155  bbs_[index].calcExtremities(sample, myNear, myFar);
156 
157  const point dist = myFar - sample;
158  scalar myFarDist = mag(dist);
159 
160  point tightestNear, tightestFar;
161  tightest.calcExtremities(sample, tightestNear, tightestFar);
162 
163  scalar tightestFarDist = mag(tightestFar - sample);
164 
165  if (tightestFarDist < myFarDist)
166  {
167  // Keep current tightest.
168  return false;
169  }
170  else
171  {
172  // Construct bb around sample and myFar
173  const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));
174 
175  tightest.min() = sample - dist2;
176  tightest.max() = sample + dist2;
177 
178  return true;
179  }
180 }
181 
182 
183 // Determine numerical value of sign of sample compared to shape at index
185 (
186  const label,
187  const point&,
188  vector& n
189 ) const
190 {
191  n = vector::zero;
192 
193  return GREAT;
194 }
195 
196 
197 // Calculate nearest point on/in shapei
199 (
200  const label index,
201  const point& sample,
202  point& nearest
203 ) const
204 {
205  nearest = mesh_.cellCentres()[cellLabels_[index]];
206 
207  return mag(nearest - sample);
208 }
209 
210 
211 // Calculate nearest point on/in shapei
213 (
214  const label index,
215  const linePointRef& ln,
216  point& linePt,
217  point& shapePt
218 ) const
219 {
221  (
222  "octreeDataCell::calcNearest(const label, const linePointRef&"
223  ", point& linePt, point&)"
224  );
225  return GREAT;
226 }
227 
228 
230 (
231  Ostream& os,
232  const label index
233 ) const
234 {
235  os << cellLabels_[index] << " " << bbs_[index];
236 }
237 
238 
239 // ************************ vim: set sw=4 sts=4 et: ************************ //