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 Declarations
49 class polyMesh;
50 class fvMesh;
51 class OBJstream;
52 class IOobject;
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;
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 // ************************************************************************* //
static labelVector offset(const labelVector &nDivs)
Change in combined voxel index for change in components.
Definition: ops.H:67
static void writeGrid(OBJstream &, const boundBox &, const labelVector &)
Debug: write all edges.
void clip(Field< Type > &result, const UList< Type > &f1, const MinMax< Type > &s2)
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
bool update()
Update lookup tables for geometry changes.
const labelVector & nDivs() const
Number of voxels for local mesh.
static label index(const labelVector &nDivs, const labelVector &voxel)
Find cells. Returns number of cells found.
voxelMeshSearch(const polyMesh &, const bool doUpdate=true)
Construct from mesh; voxels estimated from local number of cells.
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.
static labelVector index3(const labelVector &nDivs, const label voxeli)
Combined voxel index to individual indices.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
An OFstream that keeps track of vertices and provides convenience output methods for OBJ files...
Definition: OBJstream.H:55
static point centre(const boundBox &bb, const labelVector &nDivs, const labelVector &voxel)
Voxel index to voxel centre.
ClassName("voxelMeshSearch")
static void fill(Container &elems, const boundBox &bb, const labelVector &nDivs, const boundBox &subBb, const Type val)
Fill voxels indicated by bounding box.
Fast, non-parallel searching in mesh without use of octree.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
autoPtr< fvMesh > makeMesh(const IOobject &) const
Debug: construct fvMesh. Note: writes a dummy mesh to.
label findCell(const point &) const
Find a cell.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Namespace for OpenFOAM.
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.