voxelMeshSearch.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::voxelMeshSearch
28 
29 Description
30  Fast, non-parallel searching in mesh without use of octree.
31 
32 SourceFiles
33  voxelMeshSearch.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef voxelMeshSearch_H
38 #define voxelMeshSearch_H
39 
40 #include "boundBox.H"
41 #include "labelVector.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of friend functions and operators
49 class polyMesh;
50 class OBJstream;
51 class IOobject;
52 class fvMesh;
53 
54 /*---------------------------------------------------------------------------*\
55  Class voxelMeshSearch Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class voxelMeshSearch
59 {
60  // Private data
61 
62  const polyMesh& mesh_;
63 
64  //- Local mesh bounding box
65  boundBox localBb_;
66 
67  //- Number of voxels in all directions (for local mesh only)
68  labelVector nDivs_;
69 
70  //- Voxel to seed cell
71  labelList seedCell_;
72 
73  //- Cells visited
74  mutable DynamicList<label> track_;
75 
76 
77  // Private Member Functions
78 
79  //- Find nearest cell (on same processor patch as seed face)
80  label searchProcPatch(const label seedFacei, const point&) const;
81 
82  //- Find the face on the cell that gets intersected
83  label findIntersectedFace(const label celli, const point&) const;
84 
85 
86 public:
87 
88  // Declare name of the class and its debug switch
89  ClassName("voxelMeshSearch");
90 
91 
92  // Constructors
93 
94  //- Construct from mesh; voxels estimated from local number of cells
95  voxelMeshSearch(const polyMesh&, const bool doUpdate = true);
96 
97  //- Construct from mesh and voxel discretisation
99  (
100  const polyMesh&,
101  const boundBox& bb,
102  const labelVector& nDivs,
103  const bool doUpdate = true
104  );
105 
106 
107  // Member functions
108 
109  //- Number of voxels for local mesh
110  const labelVector& nDivs() const
111  {
112  return nDivs_;
113  }
114 
115  //- Update lookup tables for geometry changes
116  bool update();
117 
118  //- Find a cell
119  label findCell(const point&) const;
120 
121  //- Find cells. Returns number of cells found
122  //label findCells(const UList<point>&, labelList&) const;
123 
124 
125  //Voxel helper functions
126 
127  //- Voxel indices to combined voxel index
128  static label index
129  (
130  const labelVector& nDivs,
131  const labelVector& voxel
132  );
133 
134  //- Change in combined voxel index for change in components
135  static labelVector offset
136  (
137  const labelVector& nDivs
138  );
139 
140  //- Combined voxel index to individual indices
141  static labelVector index3
142  (
143  const labelVector& nDivs,
144  const label voxeli
145  );
146 
147  //- Coordinate to voxel indices
148  static labelVector index3
149  (
150  const boundBox& bb,
151  const labelVector& nDivs,
152  const point& p
153  );
154 
155  //- Voxel index to voxel centre
156  static point centre
157  (
158  const boundBox& bb,
159  const labelVector& nDivs,
160  const labelVector& voxel
161  );
162 
163  //- Coordinate to combined voxel index. If clip makes sure
164  // components are all inside. If not clip returns -1 if outside bb.
165  static label index
166  (
167  const boundBox& bb,
168  const labelVector& nDivs,
169  const point& p,
170  const bool clip
171  );
172 
173  //- Fill voxels indicated by bounding box
174  template<class Container, class Type>
175  static void fill
176  (
177  Container& elems,
178  const boundBox& bb,
179  const labelVector& nDivs,
180  const boundBox& subBb,
181  const Type val
182  );
183 
184  //- Fill voxels indicated by bounding box
185  template<class Container, class Type, class CombineOp>
186  static void fill
187  (
188  Container& elems,
189  const boundBox& bb,
190  const labelVector& nDivs,
191  const boundBox& subBb,
192  const Type val,
193  const CombineOp& cop = eqOp<Type>()
194  );
195 
196  //- Check if any voxel inside bounding box is set to val or
197  // not set to val (isNot = true)
198  template<class Container, class Type>
199  static bool overlaps
200  (
201  const boundBox& bb,
202  const labelVector& nDivs,
203  const boundBox& subBb,
204  const Container& elems,
205  const Type val,
206  const bool isNot = false
207  );
208 
209  //- Debug: write points for every set element
210  template<class Container, class Type>
211  static void write
212  (
213  OBJstream&,
214  const boundBox& bb,
215  const labelVector& nDivs,
216  const Container& elems,
217  const Type val,
218  const bool isNot = false
219  );
220 
221  //- Debug: write all edges
222  static void writeGrid
223  (
224  OBJstream&,
225  const boundBox&,
226  const labelVector&
227  );
228 
229  //- Debug: construct fvMesh. Note: writes a dummy mesh to
230  // io.timeName()! TBD.
231  autoPtr<fvMesh> makeMesh(const IOobject&) const;
232 };
233 
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 } // End namespace Foam
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 #ifdef NoRepository
242  #include "voxelMeshSearchTemplates.C"
243 #endif
244 
245 #endif
246 
247 // ************************************************************************* //
Foam::voxelMeshSearch::update
bool update()
Update lookup tables for geometry changes.
Definition: voxelMeshSearch.C:365
Foam::voxelMeshSearch::write
static void write(OBJstream &, const boundBox &bb, const labelVector &nDivs, const Container &elems, const Type val, const bool isNot=false)
Debug: write points for every set element.
Definition: voxelMeshSearchTemplates.C:184
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::OBJstream
OFstream that keeps track of vertices.
Definition: OBJstream.H:58
Foam::voxelMeshSearch::voxelMeshSearch
voxelMeshSearch(const polyMesh &, const bool doUpdate=true)
Construct from mesh; voxels estimated from local number of cells.
Definition: voxelMeshSearch.C:287
Foam::voxelMeshSearch::nDivs
const labelVector & nDivs() const
Number of voxels for local mesh.
Definition: voxelMeshSearch.H:109
Foam::DynamicList< label >
Foam::voxelMeshSearch::index
static label index(const labelVector &nDivs, const labelVector &voxel)
Find cells. Returns number of cells found.
Definition: voxelMeshSearch.C:57
Foam::voxelMeshSearch::findCell
label findCell(const point &) const
Find a cell.
Definition: voxelMeshSearch.C:409
labelVector.H
Foam::voxelMeshSearch::writeGrid
static void writeGrid(OBJstream &, const boundBox &, const labelVector &)
Debug: write all edges.
Definition: voxelMeshSearch.C:158
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::voxelMeshSearch::ClassName
ClassName("voxelMeshSearch")
Foam::voxelMeshSearch::fill
static void fill(Container &elems, const boundBox &bb, const labelVector &nDivs, const boundBox &subBb, const Type val)
Fill voxels indicated by bounding box.
Definition: voxelMeshSearchTemplates.C:35
Foam::eqOp
Definition: ops.H:71
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::voxelMeshSearch::makeMesh
autoPtr< fvMesh > makeMesh(const IOobject &) const
Debug: construct fvMesh. Note: writes a dummy mesh to.
Definition: voxelMeshSearch.C:495
boundBox.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::voxelMeshSearch
Fast, non-parallel searching in mesh without use of octree.
Definition: voxelMeshSearch.H:57
Foam::clip
dimensionSet clip(const dimensionSet &ds1, const dimensionSet &ds2)
Definition: dimensionSet.C:278
Foam::Vector< label >
Foam::List< label >
Foam::voxelMeshSearch::offset
static labelVector offset(const labelVector &nDivs)
Change in combined voxel index for change in components.
Definition: voxelMeshSearch.C:48
Foam::voxelMeshSearch::overlaps
static bool overlaps(const boundBox &bb, const labelVector &nDivs, const boundBox &subBb, const Container &elems, const Type val, const bool isNot=false)
Check if any voxel inside bounding box is set to val or.
Definition: voxelMeshSearchTemplates.C:124
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::voxelMeshSearch::centre
static point centre(const boundBox &bb, const labelVector &nDivs, const labelVector &voxel)
Voxel index to voxel centre.
Definition: voxelMeshSearch.C:145
Foam::voxelMeshSearch::index3
static labelVector index3(const labelVector &nDivs, const label voxeli)
Combined voxel index to individual indices.
Definition: voxelMeshSearch.C:67
voxelMeshSearchTemplates.C