initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / test / findCell-octree / findCell-octree.C
blob1a845d7029c9563886c2a614c80a31d05ece8b66
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 \*---------------------------------------------------------------------------*/
27 #include "argList.H"
28 #include "Time.H"
29 #include "fvMesh.H"
30 #include "IStringStream.H"
31 #include "octree.H"
32 #include "octreeDataCell.H"
33 #include "OFstream.H"
35 using namespace Foam;
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // Main program:
40 int main(int argc, char *argv[])
42     argList::validArgs.append("point (x y z)");
44 #   include "setRootCase.H"
45 #   include "createTime.H"
46 #   include "createMesh.H"
48     point sample(IStringStream(args.additionalArgs()[0])());
50     treeBoundBox meshBb(mesh.points());
52     // Calculate typical cell releated size to shift bb by.
53     scalar typDim = meshBb.avgDim()/(2.0*Foam::cbrt(scalar(mesh.nCells())));
55     treeBoundBox shiftedBb
56     (
57         meshBb.min(),
58         meshBb.max() + vector(typDim, typDim, typDim)
59     );
62     Info<< "Mesh" << endl;
63     Info<< "   bounding box           : " << meshBb << endl;
64     Info<< "   bounding box (shifted) : " << shiftedBb << endl;
65     Info<< "   typical dimension      : " << shiftedBb.typDim() << endl;
68     /*
69      * Now we have allBb and shiftedBb
70      */
72     // Wrap indices and mesh information into helper object
73     octreeDataCell shapes(mesh);
75     octree<octreeDataCell> oc
76     (
77         shiftedBb,  // overall bounding box
78         shapes,     // all information needed to do checks on cells
79         1,          // min. levels
80         10.0,       // max. size of leaves
81         10.0        // maximum ratio of cubes v.s. cells
82     );
84     Info<< "Point:" << sample << " is in shape "
85         << oc.find(sample) << endl;
86     Info<< "Point:" << sample << " is in cell  "
87         << mesh.findCell(sample) << endl;
90     oc.printStats(Info);
93     Info<< "End\n" << endl;
95     return 0;
99 // ************************************************************************* //