meshTools.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) 2011-2016 OpenFOAM Foundation
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 Namespace
27  Foam::meshTools
28 
29 Description
30  Collection of static functions to do various simple mesh related things.
31 
32 SourceFiles
33  meshTools.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef meshTools_H
38 #define meshTools_H
39 
40 #include "label.H"
41 #include "vector.H"
42 #include "triad.H"
43 #include "labelList.H"
44 #include "pointField.H"
45 #include "faceList.H"
46 #include "cellList.H"
47 #include "primitivePatch.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 class polyMesh;
55 class primitiveMesh;
56 class treeBoundBox;
57 
58 /*---------------------------------------------------------------------------*\
59  Namespace meshTools Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 namespace meshTools
63 {
64  // Bit identifiers for octants (p=plus, m=min e.g. plusXminYminZ)
65 
66  static const label mXmYmZ = 0;
67  static const label pXmYmZ = 1;
68  static const label mXpYmZ = 2;
69  static const label pXpYmZ = 3;
70 
71  static const label mXmYpZ = 4;
72  static const label pXmYpZ = 5;
73  static const label mXpYpZ = 6;
74  static const label pXpYpZ = 7;
75 
76  static const label mXmYmZMask = 1 << mXmYmZ;
77  static const label pXmYmZMask = 1 << pXmYmZ;
78  static const label mXpYmZMask = 1 << mXpYmZ;
79  static const label pXpYmZMask = 1 << pXpYmZ;
80 
81  static const label mXmYpZMask = 1 << mXmYpZ;
82  static const label pXmYpZMask = 1 << pXmYpZ;
83  static const label mXpYpZMask = 1 << mXpYpZ;
84  static const label pXpYpZMask = 1 << pXpYpZ;
85 
86 
87  // Normal handling
88 
89  //- Check if n is in same direction as normals of all faceLabels
90  bool visNormal
91  (
92  const vector& n,
93  const vectorField& faceNormals,
94  const labelList& faceLabels
95  );
96 
97  //- Calculate point normals on a 'box' mesh (all edges aligned with
98  // coordinate axes)
100 
101  //- Normalized edge vector
102  vector normEdgeVec(const primitiveMesh&, const label edgeI);
103 
104 
105  // OBJ writing
106 
107  //- Write obj representation of a point
108  void writeOBJ
109  (
110  Ostream& os,
111  const point& pt
112  );
113 
114  //- Write obj representation of points
115  void writeOBJ
116  (
117  Ostream& os,
118  const UList<point>& pts
119  );
120 
121  //- Write obj representation of a triad. Requires the origin of the
122  // triad to be supplied
123  void writeOBJ
124  (
125  Ostream& os,
126  const triad& t,
127  const point& origin
128  );
129 
130  //- Write obj representation of a line connecting two points.
131  // Need to keep track of points that have been added. count starts at 0
132  void writeOBJ
133  (
134  Ostream& os,
135  const point& p1,
136  const point& p2,
137  label& count
138  );
139 
140  //- Write obj representation of a point p1 with a vector from p1 to p2
141  void writeOBJ
142  (
143  Ostream& os,
144  const point& p1,
145  const point& p2
146  );
147 
148  //- Write obj representation of tree-bounding box as a series of lines
149  void writeOBJ
150  (
151  Ostream& os,
152  const treeBoundBox& bb
153  );
154 
155  //- Write obj representation of faces subset
156  template<class FaceType>
157  void writeOBJ
158  (
159  Ostream& os,
160  const UList<FaceType>& faces,
161  const UList<point>& points,
162  const labelList& faceLabels
163  );
164 
165  //- Write obj representation of faces
166  template<class FaceType>
167  void writeOBJ
168  (
169  Ostream& os,
170  const UList<FaceType>& faces,
171  const UList<point>& points
172  );
173 
174  //- Write obj representation of cell subset
175  void writeOBJ
176  (
177  Ostream& os,
178  const cellList& cells,
179  const faceList& faces,
180  const UList<point>& points,
181  const labelList& cellLabels
182  );
183 
184 
185  // Cell/face/edge walking
186 
187  //- Is edge used by cell
188  bool edgeOnCell
189  (
190  const primitiveMesh& mesh,
191  const label celli,
192  const label edgeI
193  );
194 
195  //- Is edge used by face
196  bool edgeOnFace
197  (
198  const primitiveMesh& mesh,
199  const label facei,
200  const label edgeI
201  );
202 
203  //- Is face used by cell
204  bool faceOnCell
205  (
206  const primitiveMesh& mesh,
207  const label celli,
208  const label facei
209  );
210 
211  //- Return edge among candidates that uses the two vertices.
212  label findEdge
213  (
214  const edgeList& edges,
215  const labelList& candidates,
216  const label v0,
217  const label v1
218  );
219 
220  //- Return edge between two mesh vertices. Returns -1 if no edge.
221  label findEdge
222  (
223  const primitiveMesh& mesh,
224  const label v0,
225  const label v1
226  );
227 
228  //- Return edge shared by two faces. Throws error if no edge found.
229  label getSharedEdge
230  (
231  const primitiveMesh& mesh,
232  const label f0,
233  const label f1
234  );
235 
236  //- Return face shared by two cells. Throws error if none found.
237  label getSharedFace
238  (
239  const primitiveMesh& mesh,
240  const label cell0,
241  const label cell1
242  );
243 
244  //- Get faces on cell using edgeI. Throws error if no two found.
245  void getEdgeFaces
246  (
247  const primitiveMesh& mesh,
248  const label celli,
249  const label edgeI,
250  label& face0,
251  label& face1
252  );
253 
254  //- Return label of other edge (out of candidates edgeLabels)
255  // connected to vertex but not edgeI. Throws error if none found.
256  label otherEdge
257  (
258  const primitiveMesh& mesh,
259  const labelList& edgeLabels,
260  const label thisEdgeI,
261  const label thisVertI
262  );
263 
264  //- Return face on cell using edgeI but not facei. Throws error
265  // if none found.
266  label otherFace
267  (
268  const primitiveMesh& mesh,
269  const label celli,
270  const label facei,
271  const label edgeI
272  );
273 
274  //- Return cell on other side of face. Throws error
275  // if face not internal.
276  label otherCell
277  (
278  const primitiveMesh& mesh,
279  const label celli,
280  const label facei
281  );
282 
283  //- Returns label of edge nEdges away from startEdge (in the direction
284  // of startVertI)
285  label walkFace
286  (
287  const primitiveMesh& mesh,
288  const label facei,
289  const label startEdgeI,
290  const label startVertI,
291  const label nEdges
292  );
293 
294 
295  // Constraints on position
296 
297  //- Set the constrained components of position to mesh centre
299  (
300  const polyMesh& mesh,
301  point& pt
302  );
304  (
305  const polyMesh& mesh,
306  pointField& pt
307  );
308 
309  //- Set the constrained components of directions/velocity to zero
310  void constrainDirection
311  (
312  const polyMesh& mesh,
313  const Vector<label>& dirs,
314  vector& d
315  );
316  void constrainDirection
317  (
318  const polyMesh& mesh,
319  const Vector<label>& dirs,
320  vectorField& d
321  );
322 
323 
324  // Hex only functionality.
325 
326  //- Given edge on hex find other 'parallel', non-connected edges.
327  void getParallelEdges
328  (
329  const primitiveMesh& mesh,
330  const label celli,
331  const label e0,
332  label& e1,
333  label& e2,
334  label& e3
335  );
336 
337  //- Given edge on hex find all 'parallel' (i.e. non-connected)
338  // edges and average direction of them
340  (
341  const primitiveMesh& mesh,
342  const label celli,
343  const label edgeI
344  );
345 
346  //- Reverse of edgeToCutDir: given direction find edge bundle and
347  // return one of them.
348  label cutDirToEdge
349  (
350  const primitiveMesh& mesh,
351  const label celli,
352  const vector& cutDir
353  );
354 
355 } // End namespace meshTools
356 
357 
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 
360 } // End namespace Foam
361 
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 
364 #ifdef NoRepository
365  #include "meshToolsTemplates.C"
366 #endif
367 
368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
369 
370 #endif
371 
372 // ************************************************************************* //
Foam::meshTools::mXpYmZMask
static const label mXpYmZMask
Definition: meshTools.H:78
Foam::meshTools::constrainDirection
void constrainDirection(const polyMesh &mesh, const Vector< label > &dirs, vector &d)
Set the constrained components of directions/velocity to zero.
Definition: meshTools.C:687
Foam::meshTools::getSharedEdge
label getSharedEdge(const primitiveMesh &mesh, const label f0, const label f1)
Return edge shared by two faces. Throws error if no edge found.
Definition: meshTools.C:408
Foam::meshTools::mXmYpZ
static const label mXmYpZ
Definition: meshTools.H:71
Foam::meshTools::mXmYpZMask
static const label mXmYpZMask
Definition: meshTools.H:81
Foam::meshTools::otherFace
label otherFace(const primitiveMesh &mesh, const label celli, const label facei, const label edgeI)
Return face on cell using edgeI but not facei. Throws error.
Definition: meshTools.C:555
Foam::meshTools::getParallelEdges
void getParallelEdges(const primitiveMesh &mesh, const label celli, const label e0, label &e1, label &e2, label &e3)
Given edge on hex find other 'parallel', non-connected edges.
Definition: meshTools.C:737
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:203
Foam::meshTools::pXpYmZ
static const label pXpYmZ
Definition: meshTools.H:69
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:86
triad.H
Foam::meshTools::pXpYpZMask
static const label pXpYpZMask
Definition: meshTools.H:84
Foam::meshTools::edgeOnCell
bool edgeOnCell(const primitiveMesh &mesh, const label celli, const label edgeI)
Is edge used by cell.
Definition: meshTools.C:308
Foam::meshTools::mXpYpZ
static const label mXpYpZ
Definition: meshTools.H:73
Foam::meshTools::otherCell
label otherCell(const primitiveMesh &mesh, const label celli, const label facei)
Return cell on other side of face. Throws error.
Definition: meshTools.C:579
Foam::meshTools::pXmYmZ
static const label pXmYmZ
Definition: meshTools.H:67
faceList.H
Foam::meshTools::pXmYpZMask
static const label pXmYpZMask
Definition: meshTools.H:82
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::meshTools::walkFace
label walkFace(const primitiveMesh &mesh, const label facei, const label startEdgeI, const label startVertI, const label nEdges)
Returns label of edge nEdges away from startEdge (in the direction.
Definition: meshTools.C:603
Foam::meshTools::faceOnCell
bool faceOnCell(const primitiveMesh &mesh, const label celli, const label facei)
Is face used by cell.
Definition: meshTools.C:330
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::meshTools::pXmYmZMask
static const label pXmYmZMask
Definition: meshTools.H:77
meshToolsTemplates.C
Foam::meshTools::findEdge
label findEdge(const edgeList &edges, const labelList &candidates, const label v0, const label v1)
Return edge among candidates that uses the two vertices.
Definition: meshTools.C:359
faceNormals
surfaceVectorField faceNormals(mesh.Sf()/mesh.magSf())
labelList.H
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::meshTools::pXmYpZ
static const label pXmYpZ
Definition: meshTools.H:72
Foam::meshTools::cutDirToEdge
label cutDirToEdge(const primitiveMesh &mesh, const label celli, const vector &cutDir)
Reverse of edgeToCutDir: given direction find edge bundle and.
Definition: meshTools.C:810
Foam::meshTools::getEdgeFaces
void getEdgeFaces(const primitiveMesh &mesh, const label celli, const label edgeI, label &face0, label &face1)
Get faces on cell using edgeI. Throws error if no two found.
Definition: meshTools.C:479
cellList.H
Foam::meshTools::calcBoxPointNormals
vectorField calcBoxPointNormals(const primitivePatch &pp)
Calculate point normals on a 'box' mesh (all edges aligned with.
Definition: meshTools.C:56
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::meshTools::otherEdge
label otherEdge(const primitiveMesh &mesh, const labelList &edgeLabels, const label thisEdgeI, const label thisVertI)
Return label of other edge (out of candidates edgeLabels)
Definition: meshTools.C:521
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::meshTools::mXmYmZMask
static const label mXmYmZMask
Definition: meshTools.H:76
Foam::meshTools::mXpYmZ
static const label mXpYmZ
Definition: meshTools.H:68
Foam::triad
Representation of a 3D Cartesian coordinate system as a Vector of row vectors.
Definition: triad.H:64
Foam::meshTools::edgeOnFace
bool edgeOnFace(const primitiveMesh &mesh, const label facei, const label edgeI)
Is edge used by face.
Definition: meshTools.C:319
pointField.H
Foam::meshTools::normEdgeVec
vector normEdgeVec(const primitiveMesh &, const label edgeI)
Normalized edge vector.
Definition: meshTools.C:193
Foam::meshTools::mXmYmZ
static const label mXmYmZ
Definition: meshTools.H:66
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::Vector< scalar >
label.H
Foam::List< label >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::meshTools::constrainToMeshCentre
void constrainToMeshCentre(const polyMesh &mesh, point &pt)
Set the constrained components of position to mesh centre.
Definition: meshTools.C:629
vector.H
Foam::meshTools::edgeToCutDir
vector edgeToCutDir(const primitiveMesh &mesh, const label celli, const label edgeI)
Given edge on hex find all 'parallel' (i.e. non-connected)
Definition: meshTools.C:763
Foam::meshTools::getSharedFace
label getSharedFace(const primitiveMesh &mesh, const label cell0, const label cell1)
Return face shared by two cells. Throws error if none found.
Definition: meshTools.C:441
Foam::meshTools::pXpYmZMask
static const label pXpYmZMask
Definition: meshTools.H:79
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::meshTools::visNormal
bool visNormal(const vector &n, const vectorField &faceNormals, const labelList &faceLabels)
Check if n is in same direction as normals of all faceLabels.
Definition: meshTools.C:37
primitivePatch.H
Foam::meshTools::mXpYpZMask
static const label mXpYpZMask
Definition: meshTools.H:83
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79
Foam::meshTools::pXpYpZ
static const label pXpYpZ
Definition: meshTools.H:74
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78