initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / meshTools / meshTools.H
blobb252f93b34c75dfd3026ee78af487505bcaef65a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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;
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     //- Check if n is in same direction as normals of all faceLabels
85     bool visNormal
86     (
87         const vector& n,
88         const vectorField& faceNormals,
89         const labelList& faceLabels
90     );
92     //- Calculate point normals on a 'box' mesh (all edges aligned with
93     //  coordinate axes)
94     vectorField calcBoxPointNormals(const primitivePatch& pp);
96     //- Normalized edge vector
97     vector normEdgeVec(const primitiveMesh&, const label edgeI);
99     //- Write obj representation of point
100     void writeOBJ
101     (
102         Ostream& os,
103         const point& pt
104     );
107     //- Write obj representation of faces subset
108     void writeOBJ
109     (
110         Ostream& os,
111         const faceList&,
112         const pointField&,
113         const labelList& faceLabels
114     );
116     //- Write obj representation of faces
117     void writeOBJ
118     (
119         Ostream& os,
120         const faceList&,
121         const pointField&
122     );
124     //- Write obj representation of cell subset
125     void writeOBJ
126     (
127         Ostream& os,
128         const cellList&,
129         const faceList&,
130         const pointField&,
131         const labelList& cellLabels
132     );
134     //- Is edge used by cell
135     bool edgeOnCell
136     (
137         const primitiveMesh&,
138         const label cellI,
139         const label edgeI
140     );
142     //- Is edge used by face
143     bool edgeOnFace
144     (
145         const primitiveMesh&,
146         const label faceI,
147         const label edgeI
148     );
149     
150     //- Is face used by cell
151     bool faceOnCell
152     (
153         const primitiveMesh&,
154         const label cellI,
155         const label faceI
156     );
158     //- Return edge among candidates that uses the two vertices.
159     label findEdge
160     (
161         const edgeList& edges,
162         const labelList& candidates,
163         const label v0,
164         const label v1
165     );
167     //- Return edge between two vertices. Returns -1 if no edge.
168     label findEdge
169     (
170         const primitiveMesh&,
171         const label v0,
172         const label v1
173     );
175     //- Return edge shared by two faces. Throws error if no edge found.
176     label getSharedEdge
177     (
178         const primitiveMesh&,
179         const label f0,
180         const label f1
181     );
182     
183     //- Return face shared by two cells. Throws error if none found.
184     label getSharedFace
185     (
186         const primitiveMesh&,
187         const label cell0,
188         const label cell1
189     );
191     //- Get faces on cell using edgeI. Throws error if no two found.
192     void getEdgeFaces
193     (
194         const primitiveMesh&,
195         const label cellI,
196         const label edgeI,
197         label& face0,
198         label& face1
199     );
201     //- Return label of other edge (out of candidates edgeLabels)
202     //  connected to vertex but not edgeI. Throws error if none found.
203     label otherEdge
204     (
205         const primitiveMesh&,
206         const labelList& edgeLabels,
207         const label edgeI,
208         const label vertI
209     );
210     
211     //- Return face on cell using edgeI but not faceI. Throws error 
212     //  if none found.
213     label otherFace
214     (
215         const primitiveMesh&,
216         const label cellI,
217         const label faceI,
218         const label edgeI
219     );
221     //- Return cell on other side of face. Throws error 
222     //  if face not internal.
223     label otherCell
224     (
225         const primitiveMesh&,
226         const label cellI,
227         const label faceI
228     );
229     
230     //- Returns label of edge nEdges away from startEdge (in the direction
231     // of startVertI)
232     label walkFace
233     (
234         const primitiveMesh&,
235         const label faceI,
236         const label startEdgeI,
237         const label startVertI,
238         const label nEdges
239     );
241     
242     //
243     // Hex only functionality.
244     //
246     //- Given edge on hex find other 'parallel', non-connected edges.
247     void getParallelEdges
248     (
249         const primitiveMesh&,
250         const label cellI,
251         const label e0,
252         label&,
253         label&,
254         label&
255     );
257     //- Given edge on hex find all 'parallel' (i.e. non-connected)
258     //  edges and average direction of them
259     vector edgeToCutDir
260     (
261         const primitiveMesh&,
262         const label cellI,
263         const label edgeI
264     );
266     //- Reverse of edgeToCutDir: given direction find edge bundle and
267     //  return one of them.
268     label cutDirToEdge
269     (
270         const primitiveMesh&,
271         const label cellI,
272         const vector& cutDir
273     );
274     
275 } // End namespace meshTools
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 } // End namespace Foam
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 #endif
286 // ************************************************************************* //