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-------------------------------------------------------------------------------
10License
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
26Namespace
27 Foam::meshTools
28
29Description
30 Collection of static functions to do various simple mesh related things.
31
32SourceFiles
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
51namespace Foam
52{
53
54class polyMesh;
55class primitiveMesh;
56class treeBoundBox;
57
58/*---------------------------------------------------------------------------*\
59 Namespace meshTools Declaration
60\*---------------------------------------------------------------------------*/
61
62namespace 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,
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
311 (
312 const polyMesh& mesh,
313 const Vector<label>& dirs,
314 vector& d
315 );
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.
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// ************************************************************************* //
label n
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of faces which address into the list of points.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:79
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:89
Representation of a 3D Cartesian coordinate system as a Vector of row vectors.
Definition: triad.H:67
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
const labelList nEdges(UPstream::listGatherValues< label >(aMesh.nEdges()))
const pointField & points
const cellShapeList & cells
surfaceVectorField faceNormals(mesh.Sf()/mesh.magSf())
bool faceOnCell(const primitiveMesh &mesh, const label celli, const label facei)
Is face used by cell.
Definition: meshTools.C:330
static const label mXmYpZMask
Definition: meshTools.H:81
void constrainDirection(const polyMesh &mesh, const Vector< label > &dirs, vector &d)
Set the constrained components of directions/velocity to zero.
Definition: meshTools.C:687
static const label mXpYmZ
Definition: meshTools.H:68
void constrainToMeshCentre(const polyMesh &mesh, point &pt)
Set the constrained components of position to mesh centre.
Definition: meshTools.C:629
bool edgeOnCell(const primitiveMesh &mesh, const label celli, const label edgeI)
Is edge used by cell.
Definition: meshTools.C:308
label otherCell(const primitiveMesh &mesh, const label celli, const label facei)
Return cell on other side of face. Throws error.
Definition: meshTools.C:579
static const label pXmYpZ
Definition: meshTools.H:72
static const label mXpYpZ
Definition: meshTools.H:73
vectorField calcBoxPointNormals(const primitivePatch &pp)
Calculate point normals on a 'box' mesh (all edges aligned with.
Definition: meshTools.C:56
static const label mXpYmZMask
Definition: meshTools.H:78
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
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
static const label pXpYmZ
Definition: meshTools.H:69
static const label pXpYpZ
Definition: meshTools.H:74
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
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
static const label pXpYmZMask
Definition: meshTools.H:79
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
static const label pXmYpZMask
Definition: meshTools.H:82
static const label pXmYmZ
Definition: meshTools.H:67
vector normEdgeVec(const primitiveMesh &, const label edgeI)
Normalized edge vector.
Definition: meshTools.C:193
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
static const label pXmYmZMask
Definition: meshTools.H:77
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
static const label mXmYmZ
Definition: meshTools.H:66
static const label mXmYmZMask
Definition: meshTools.H:76
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
static const label pXpYpZMask
Definition: meshTools.H:84
bool edgeOnFace(const primitiveMesh &mesh, const label facei, const label edgeI)
Is edge used by face.
Definition: meshTools.C:319
static const label mXpYpZMask
Definition: meshTools.H:83
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
static const label mXmYpZ
Definition: meshTools.H:71
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
label cutDirToEdge(const primitiveMesh &mesh, const label celli, const vector &cutDir)
Reverse of edgeToCutDir: given direction find edge bundle and.
Definition: meshTools.C:810
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:203
Namespace for OpenFOAM.