1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
29 #include "IStringStream.H"
31 #include "octreeDataCell.H"
32 #include "indexedOctree.H"
33 #include "treeDataCell.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 int main(int argc, char *argv[])
43 argList::validArgs.append("point (x y z)");
45 # include "setRootCase.H"
46 # include "createTime.H"
47 # include "createMesh.H"
51 const point sample = args.argRead<point>(1);
53 treeBoundBox meshBb(mesh.bounds());
55 // Calculate typical cell related size to shift bb by.
56 scalar typDim = meshBb.avgDim()/(2.0*Foam::cbrt(scalar(mesh.nCells())));
58 treeBoundBox shiftedBb
61 meshBb.max() + vector(typDim, typDim, typDim)
64 Info<< "Mesh" << endl;
65 Info<< " bounding box : " << meshBb << endl;
66 Info<< " bounding box (shifted) : " << shiftedBb << endl;
67 Info<< " typical dimension : " << shiftedBb.typDim() << endl;
69 Info<< "Initialised mesh in "
70 << runTime.cpuTimeIncrement() << " s" << endl;
72 // Wrap indices and mesh information into helper object
73 octreeDataCell shapes(mesh);
75 octree<octreeDataCell> oc
77 shiftedBb, // overall bounding box
78 shapes, // all information needed to do checks on cells
80 10.0, // max. size of leaves
81 10.0 // maximum ratio of cubes v.s. cells
84 for (label i = 0; i < nReps - 1 ; i++)
89 Info<< "Point:" << sample << " is in shape "
90 << oc.find(sample) << endl;
94 Info<< "Found in octree " << nReps << " times in "
95 << runTime.cpuTimeIncrement() << " s" << endl;
97 indexedOctree<treeDataCell> ioc
99 treeDataCell(true, mesh),
106 for (label i = 0; i < nReps - 1 ; i++)
108 ioc.findInside(sample);
111 Info<< "Point:" << sample << " is in shape "
112 << ioc.findInside(sample)
113 << ", where the possible cells were:" << nl
114 << ioc.findIndices(sample)
117 Info<< "Found in indexedOctree " << nReps << " times in "
118 << runTime.cpuTimeIncrement() << " s" << endl;
120 for (label i = 0; i < nReps - 1 ; i++)
122 mesh.findCell(sample);
125 Info<< "Point:" << sample << " is in cell "
126 << mesh.findCell(sample) << endl;
128 Info<< "Found in mesh.findCell " << nReps << " times in "
129 << runTime.cpuTimeIncrement() << " s" << endl;
131 Info<< "End\n" << endl;
137 // ************************************************************************* //