1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 \*---------------------------------------------------------------------------*/
30 #include "IStringStream.H"
32 #include "myBoundBox.H"
33 #include "myBoundBoxList.H"
35 #include "octreeData.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 int main(int argc, char *argv[])
44 argList::validOptions.insert("x1", "X1");
45 argList::validOptions.insert("y1", "Y1");
46 argList::validOptions.insert("z1", "Z1");
48 argList::validOptions.insert("x2", "X2");
49 argList::validOptions.insert("y2", "Y2");
50 argList::validOptions.insert("z2", "Z2");
52 # include "setRootCase.H"
53 # include "createTime.H"
54 # include "createMesh.H"
56 // Calculate BB of all cells
59 myBoundBoxList allBb(mesh.nCells());
61 const pointField& allPoints = mesh.points();
63 vectorField bbMin(mesh.nCells());
64 bbMin = vector(GREAT, GREAT, GREAT);
65 vectorField bbMax(mesh.nCells());
66 bbMax = vector(-GREAT, -GREAT, -GREAT);
68 const labelListList& pCells = mesh.pointCells();
70 forAll(pCells, pointi)
72 const point& vertCoord = allPoints[pointi];
74 const labelList& cells = pCells[pointi];
78 label cellNum = cells[celli];
80 bbMin[cellNum].x() = min(bbMin[cellNum].x(), vertCoord.x());
81 bbMin[cellNum].y() = min(bbMin[cellNum].y(), vertCoord.y());
82 bbMin[cellNum].z() = min(bbMin[cellNum].z(), vertCoord.z());
84 bbMax[cellNum].x() = max(bbMax[cellNum].x(), vertCoord.x());
85 bbMax[cellNum].y() = max(bbMax[cellNum].y(), vertCoord.y());
86 bbMax[cellNum].z() = max(bbMax[cellNum].z(), vertCoord.z());
93 allBb[celli] = myBoundBox(bbMin[celli], bbMax[celli]);
97 myBoundBox meshBb(allPoints);
99 scalar typDim = meshBb.minDim()/111;
106 meshBb.max().x() + typDim,
107 meshBb.max().y() + typDim,
108 meshBb.max().z() + typDim
113 Info<< "Mesh" << endl;
114 Info<< " bounding box :" << shiftedBb << endl;
115 Info<< " typical dimension:" << shiftedBb.typDim() << endl;
119 * Now we have allBb and shiftedBb
124 // Construct table of subset of cells
126 labelList cellIndices(10);
128 cellIndices[0] = 1433;
129 cellIndices[1] = 1434;
130 cellIndices[2] = 1435;
131 cellIndices[3] = 1436;
132 cellIndices[4] = 1437;
133 cellIndices[5] = 1438;
134 cellIndices[6] = 1439;
135 cellIndices[7] = 1440;
136 cellIndices[8] = 1441;
137 cellIndices[9] = 1442;
139 // Get the corresponding bounding boxes
141 forAll(cellIndices, i)
143 allBb[i] = allBb[cellIndices[i]];
145 allBb.setSize(cellIndices.size());
149 // Wrap indices and mesh information into helper object
150 octreeData shapes(mesh, cellIndices);
154 shiftedBb, // overall bounding box
155 shapes, // all information needed to do checks on cells
156 allBb, // bounding boxes of cells
157 10.0 // maximum ratio of cubes v.s. cells
160 // scalar x1(readScalar(IStringStream(args.options()["x1"])()));
161 // scalar y1(readScalar(IStringStream(args.options()["y1"])()));
162 // scalar z1(readScalar(IStringStream(args.options()["z1"])()));
164 // scalar x2(readScalar(IStringStream(args.options()["x2"])()));
165 // scalar y2(readScalar(IStringStream(args.options()["y2"])()));
166 // scalar z2(readScalar(IStringStream(args.options()["z2"])()));
173 for(int i = 0; i < 100; i++)
176 for(int j = 0; j < 10; j++)
179 for (int k = 0; k < 10; k++)
181 point sample(x, y, z);
183 label index = oc.find(sample);
185 // Convert index into shapes back into cellindex.
189 cell = cellIndices[index];
195 Info<< "Point:" << sample
196 << " is in cell " << cell << "(octree) "
197 << mesh.findCell(sample) << "(linear)"
208 Info<< "nFound=" << nFound << endl;
210 Info<< "End\n" << endl;
213 Info<< "Statistics:" << endl
214 << " nCells :" << allBb.size() << endl
215 << " nNodes :" << oc.nNodes() << endl
216 << " nLeaves :" << oc.nLeaves() << endl
217 << " nEntries :" << oc.nEntries() << endl
218 << " Cells per leaf :"
219 << oc.nEntries()/oc.nLeaves()
221 << " Every cell in :"
222 << oc.nEntries()/allBb.size() << " cubes"
229 // ************************************************************************* //