initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / meshTools / meshTools.H
blob0bd033b8893dbbbf4a412a31710762d77f806010
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Namespace
26     Foam::meshTools
28 Description
29     Collection of static functions to do various simple mesh related things.
31 SourceFiles
32     meshTools.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef meshTools_H
37 #define meshTools_H
39 #include "label.H"
40 #include "vector.H"
41 #include "labelList.H"
42 #include "pointField.H"
43 #include "faceList.H"
44 #include "cellList.H"
45 #include "primitivePatch.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 namespace Foam
52 class primitiveMesh;
53 class polyMesh;
55 /*---------------------------------------------------------------------------*\
56                         Namespace meshTools Declaration
57 \*---------------------------------------------------------------------------*/
59 namespace meshTools
61     // Bit identifiers for octants (p=plus, m=min e.g. plusXminYminZ)
63     static const label mXmYmZ = 0;
64     static const label pXmYmZ = 1;
65     static const label mXpYmZ = 2;
66     static const label pXpYmZ = 3;
68     static const label mXmYpZ = 4;
69     static const label pXmYpZ = 5;
70     static const label mXpYpZ = 6;
71     static const label pXpYpZ = 7;
73     static const label mXmYmZMask = 1 << mXmYmZ;
74     static const label pXmYmZMask = 1 << pXmYmZ;
75     static const label mXpYmZMask = 1 << mXpYmZ;
76     static const label pXpYmZMask = 1 << pXpYmZ;
78     static const label mXmYpZMask = 1 << mXmYpZ;
79     static const label pXmYpZMask = 1 << pXmYpZ;
80     static const label mXpYpZMask = 1 << mXpYpZ;
81     static const label pXpYpZMask = 1 << pXpYpZ;
84     // Normal handling
86         //- Check if n is in same direction as normals of all faceLabels
87         bool visNormal
88         (
89             const vector& n,
90             const vectorField& faceNormals,
91             const labelList& faceLabels
92         );
94         //- Calculate point normals on a 'box' mesh (all edges aligned with
95         //  coordinate axes)
96         vectorField calcBoxPointNormals(const primitivePatch& pp);
98         //- Normalized edge vector
99         vector normEdgeVec(const primitiveMesh&, const label edgeI);
102     // OBJ writing
104         //- Write obj representation of point
105         void writeOBJ
106         (
107             Ostream& os,
108             const point& pt
109         );
111         //- Write obj representation of faces subset
112         void writeOBJ
113         (
114             Ostream& os,
115             const faceList&,
116             const pointField&,
117             const labelList& faceLabels
118         );
120         //- Write obj representation of faces
121         void writeOBJ
122         (
123             Ostream& os,
124             const faceList&,
125             const pointField&
126         );
128         //- Write obj representation of cell subset
129         void writeOBJ
130         (
131             Ostream& os,
132             const cellList&,
133             const faceList&,
134             const pointField&,
135             const labelList& cellLabels
136         );
139     // Cell/face/edge walking
141         //- Is edge used by cell
142         bool edgeOnCell
143         (
144             const primitiveMesh&,
145             const label cellI,
146             const label edgeI
147         );
149         //- Is edge used by face
150         bool edgeOnFace
151         (
152             const primitiveMesh&,
153             const label faceI,
154             const label edgeI
155         );
157         //- Is face used by cell
158         bool faceOnCell
159         (
160             const primitiveMesh&,
161             const label cellI,
162             const label faceI
163         );
165         //- Return edge among candidates that uses the two vertices.
166         label findEdge
167         (
168             const edgeList& edges,
169             const labelList& candidates,
170             const label v0,
171             const label v1
172         );
174         //- Return edge between two vertices. Returns -1 if no edge.
175         label findEdge
176         (
177             const primitiveMesh&,
178             const label v0,
179             const label v1
180         );
182         //- Return edge shared by two faces. Throws error if no edge found.
183         label getSharedEdge
184         (
185             const primitiveMesh&,
186             const label f0,
187             const label f1
188         );
190         //- Return face shared by two cells. Throws error if none found.
191         label getSharedFace
192         (
193             const primitiveMesh&,
194             const label cell0,
195             const label cell1
196         );
198         //- Get faces on cell using edgeI. Throws error if no two found.
199         void getEdgeFaces
200         (
201             const primitiveMesh&,
202             const label cellI,
203             const label edgeI,
204             label& face0,
205             label& face1
206         );
208         //- Return label of other edge (out of candidates edgeLabels)
209         //  connected to vertex but not edgeI. Throws error if none found.
210         label otherEdge
211         (
212             const primitiveMesh&,
213             const labelList& edgeLabels,
214             const label edgeI,
215             const label vertI
216         );
218         //- Return face on cell using edgeI but not faceI. Throws error
219         //  if none found.
220         label otherFace
221         (
222             const primitiveMesh&,
223             const label cellI,
224             const label faceI,
225             const label edgeI
226         );
228         //- Return cell on other side of face. Throws error
229         //  if face not internal.
230         label otherCell
231         (
232             const primitiveMesh&,
233             const label cellI,
234             const label faceI
235         );
237         //- Returns label of edge nEdges away from startEdge (in the direction
238         // of startVertI)
239         label walkFace
240         (
241             const primitiveMesh&,
242             const label faceI,
243             const label startEdgeI,
244             const label startVertI,
245             const label nEdges
246         );
249     // Constraints on position
251         //- Set the constrained components of position to mesh centre
252         void constrainToMeshCentre
253         (
254             const polyMesh& mesh,
255             point& pt
256         );
257         void constrainToMeshCentre
258         (
259             const polyMesh& mesh,
260             pointField& pt
261         );
263         //- Set the constrained components of directions/velocity to zero
264         void constrainDirection
265         (
266             const polyMesh& mesh,
267             const Vector<label>& dirs,
268             vector& d
269         );
270         void constrainDirection
271         (
272             const polyMesh& mesh,
273             const Vector<label>& dirs,
274             vectorField& d
275         );
278     // Hex only functionality.
280         //- Given edge on hex find other 'parallel', non-connected edges.
281         void getParallelEdges
282         (
283             const primitiveMesh&,
284             const label cellI,
285             const label e0,
286             label&,
287             label&,
288             label&
289         );
291         //- Given edge on hex find all 'parallel' (i.e. non-connected)
292         //  edges and average direction of them
293         vector edgeToCutDir
294         (
295             const primitiveMesh&,
296             const label cellI,
297             const label edgeI
298         );
300         //- Reverse of edgeToCutDir: given direction find edge bundle and
301         //  return one of them.
302         label cutDirToEdge
303         (
304             const primitiveMesh&,
305             const label cellI,
306             const vector& cutDir
307         );
309 } // End namespace meshTools
312 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
314 } // End namespace Foam
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
318 #endif
320 // ************************************************************************* //