Test-findCell-octree.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) 2011-2015 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
25 
26 #include "argList.H"
27 #include "Time.H"
28 #include "fvMesh.H"
29 #include "IStringStream.H"
30 #include "indexedOctree.H"
31 #include "treeDataCell.H"
32 #include "OFstream.H"
33 
34 using namespace Foam;
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // Main program:
38 
39 int main(int argc, char *argv[])
40 {
41  argList::validArgs.append("point (x y z)");
42 
43  #include "setRootCase.H"
44  #include "createTime.H"
45  #include "createMesh.H"
46 
47  label nReps = 10000;
48 
49  const point sample = args.argRead<point>(1);
50 
52 
54 
55  // Calculate typical cell related size to shift bb by.
56  scalar typDim = meshBb.avgDim()/(2.0*Foam::cbrt(scalar(mesh.nCells())));
57 
58  treeBoundBox shiftedBb
59  (
60  meshBb.min(),
61  meshBb.max() + vector(typDim, typDim, typDim)
62  );
63 
64  Info<< "Mesh" << endl;
65  Info<< " bounding box : " << meshBb << endl;
66  Info<< " bounding box (shifted) : " << shiftedBb << endl;
67  Info<< " typical dimension : " << shiftedBb.typDim() << endl;
68 
69  Info<< "Initialised mesh in "
70  << runTime.cpuTimeIncrement() << " s" << endl;
71 
72  {
74  (
75  treeDataCell(true, mesh, decompMode), //FACEDIAGTETS),
76  shiftedBb,
77  10, // maxLevel
78  100, // leafsize
79  10.0 // duplicity
80  );
81 
82  for (label i = 0; i < nReps - 1 ; i++)
83  {
84  if ((i % 100) == 0)
85  {
86  Info<< "indexed octree for " << i << endl;
87  }
88  ioc.findInside(sample);
89  }
90 
91  Info<< "Point:" << sample << " is in shape "
92  << ioc.findInside(sample)
93  << ", where the possible cells were:" << nl
94  << ioc.findIndices(sample)
95  << endl;
96 
97  Info<< "Found in indexedOctree " << nReps << " times in "
98  << runTime.cpuTimeIncrement() << " s" << endl;
99  }
100 
101  {
102  for (label i = 0; i < nReps - 1 ; i++)
103  {
104  if ((i % 100) == 0)
105  {
106  Info<< "linear search for " << i << endl;
107  }
108  mesh.findCell(sample, decompMode);
109  }
110 
111  Info<< "Point:" << sample << " is in cell "
112  << mesh.findCell(sample, decompMode) << endl;
113 
114  Info<< "Found in mesh.findCell " << nReps << " times in "
115  << runTime.cpuTimeIncrement() << " s" << endl;
116  }
117 
118  Info<< "End\n" << endl;
119 
120  return 0;
121 }
122 
123 
124 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
Foam::polyMesh::cellDecomposition
cellDecomposition
Enumeration defining the decomposition of the cell for.
Definition: polyMesh.H:98
Foam::treeBoundBox
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:75
indexedOctree.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
meshBb
List< treeBoundBox > meshBb(1, treeBoundBox(boundBox(coarseMesh.points(), false)).extend(rndGen, 1e-3))
IStringStream.H
OFstream.H
Foam::primitiveMesh::nCells
label nCells() const
Definition: primitiveMeshI.H:64
Foam::treeDataCell
Encapsulation of data needed to search in/for cells. Used to find the cell containing a point (e....
Definition: treeDataCell.H:54
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::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::treeBoundBox::typDim
scalar typDim() const
Typical dimension length,height,width.
Definition: treeBoundBoxI.H:57
argList.H
Foam::indexedOctree
Non-pointer based hierarchical recursive searching.
Definition: treeDataTriSurface.H:47
Foam::indexedOctree::findInside
label findInside(const point &) const
Find shape containing point. Only implemented for certain.
Definition: indexedOctree.C:2828
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
treeDataCell.H
Foam::polyMesh::bounds
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:427
main
int main(int argc, char *argv[])
Definition: Test-findCell-octree.C:39
setRootCase.H
Foam::polyMesh::findCell
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
Definition: polyMesh.C:1411
Foam::polyMesh::CELL_TETS
@ CELL_TETS
Definition: polyMesh.H:107
Foam::Vector< scalar >
createMesh.H
Foam::indexedOctree::findIndices
const labelList & findIndices(const point &) const
Find the shape indices that occupy the result of findNode.
Definition: indexedOctree.C:2858
createTime.H
Foam::argList::argRead
T argRead(const label index) const
Read a value from the argument at index.
Definition: argListI.H:177
Foam::cbrt
dimensionedScalar cbrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:153
args
Foam::argList args(argc, argv)