correction to d4edb38234db8268907f04836d49bb93461b8a88
[OpenFOAM-1.5.x.git] / src / meshTools / cellClassification / cellClassification.H
blobd1c3a8e2d667dbd6277f1167b50daa068dabd5ac
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 Class
26     Foam::cellClassification
28 Description
29     'Cuts' a mesh with a surface.
31     Divides cells into three types
32     - cut, i.e. any of the edges of the cell is split or any edge of the
33       surface pierces any of the faces of the cell.
34     - outside: cell can be reached by Meshwave from any of the supplied
35                outside points (without crossing any cut cell)
36     - inside:  all other.
38     Used in various meshing programs.
40     Has various utility functions to deal with 'features' on this level
41     where the mesh still has all inside and outside cells.
43     @par Concepts
45     - point classification:
46         - point used by meshType cells only
47         - point used by non-meshType cells only
48         - point used by both types ('mixed')
50     - hanging cells: meshType cells using mixed points only.
51       These cells would have all their vertices on the surface when
52       extracting the meshType cells.
54     - regionEdges: edges where the cells using it are of mixed type.
55       Or more precise when walking around the edge and looking at the
56       different types of the cells there are more than two regions with
57       same type.
59     Seen from above:
60     @verbatim
61     Ok:
62          A | A
63            |
64          --+---
65            |
66          B | B
68     Not ok:
69          A | B
70            |
71         ---+---
72            |
73          B | A
74     @endverbatim
76     because this latter situation would cause the surface after subsetting
77     type A or B to be multiply connected across this edge. And also when
78     snapping the edge end points to the surface it might cause some twisted
79     faces if the surface is normal to the edge (and smoothing the surface
80     would not help since the points on the edge would be 'pulled' from two
81     different sides)
83     - regionPoints: like regionEdges but now for points.
84       Points where subsetting the mesh would cause a multiply connected
85       outside surface (connected across point, not edge)
88 SourceFiles
89     cellClassification.C
91 \*---------------------------------------------------------------------------*/
93 #ifndef cellClassification_H
94 #define cellClassification_H
96 #include "pointField.H"
97 #include "Map.H"
98 #include "boolList.H"
99 #include "labelList.H"
100 #include "faceList.H"
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 namespace Foam
107 // Forward declaration of classes
108 class triSurfaceSearch;
109 class meshSearch;
110 class polyMesh;
111 class polyMesh;
112 class primitiveMesh;
113 class triSurface;
115 /*---------------------------------------------------------------------------*\
116                            Class cellClassification Declaration
117 \*---------------------------------------------------------------------------*/
119 class cellClassification
121     public labelList
124 public:
126     // Public data types
128         //- Type of cell.
129         enum cType
130         {
131             NOTSET,
132             INSIDE,     // Inside of surface
133             OUTSIDE,    // Outside ,,
134             CUT         // cut by surface
135         };
138         //- Enumeration defining the whether points are use by cells of
139         //  a certain type.
140         enum pointStatus
141         {
142             UNSET,
143             MESH,       // points used by meshType cells
144             NONMESH,    //    ,,          non-mesh type cells
145             MIXED       //    ,,          both types of cell
146         };
148 private:
150     // Private data
152         //- Reference to mesh
153         const polyMesh& mesh_;
156     // Private Static Functions
158         //- Count number of occurrences of elem in list
159         static label count(const labelList& elems, const label elem);
161     // Private Member Functions
163         //- Mark all faces intersected by or intersecting surface
164         boolList markFaces(const triSurfaceSearch&) const;
166         //- Divide cells into cut/inside/outside by using MeshWave from cut
167         //  faces. No check is done on whether outsidePts are in different
168         //  domains.
169         void markCells
170         (
171             const meshSearch& queryMesh,
172             const boolList& piercedFace,
173             const pointField& outsidePts
174         );
176         //- Use cell status to classify points as being internal to meshType,
177         //  internal to non-meshType or on border of both.
178         void classifyPoints
179         (
180             const label meshType,
181             const labelList& cellType,
182             List<pointStatus>& pointSide
183         ) const;
185         //- Return true if cell uses only points with status=mixed
186         bool usesMixedPointsOnly
187         (
188             const List<pointStatus>&,
189             const label cellI
190         ) const;
192         //- Get faces (and its 'owner') inbetween cells of differing type
193         // (meshType and non-meshType).
194         void getMeshOutside(const label meshType, faceList&, labelList&) const;
196 public:
198     // Static data members
199     ClassName("cellClassification");
201     // Constructors
203         //- Construct from mesh and surface and point(s) on outside
204         cellClassification
205         (
206             const polyMesh& mesh,
207             const meshSearch& meshQuery,
208             const triSurfaceSearch& surfQuery,
209             const pointField& outsidePoints
210         );
212         //- Construct from mesh and type for every cell.
213         //  Used to be able to reuse filling routines below.
214         cellClassification(const polyMesh& mesh, const labelList& cellType);
216         //- Construct as copy
217         cellClassification(const cellClassification&);
220     // Member Functions
222         const polyMesh& mesh() const
223         {
224             return mesh_;
225         }
227         label trimCutCells
228         (
229             const label nLayers,
230             const label meshType,
231             const label fillType
232         );
234         //- Sets vertex neighbours of meshType cells to fillType
235         label growSurface(const label meshType, const label fillType);
237         //- Find hanging cells (cells with all points on outside) and set their
238         //  type to fillType.
239         //  Iterate until nothing changed. Returns total number of cells
240         //  changed (in all iterations)
241         label fillHangingCells
242         (
243             const label meshType,
244             const label fillType,
245             const label maxIter
246         );
248         //- Find regionEdges and fill one neighbour. Iterate until nothing
249         //  changes. Returns total number of cells changed.
250         label fillRegionEdges
251         (
252             const label meshType,
253             const label fillType,
254             const label maxIter
255         );
257         //- Find regionPoints and fill all neighbours. Iterate until nothing
258         //  changes. Returns total number of cells changed.
259         label fillRegionPoints
260         (
261             const label meshType,
262             const label fillType,
263             const label maxIter
264         );
266         //- Write statistics on cell types to Ostream
267         void writeStats(Ostream& os) const;
270     // Member Operators
272         void operator=(const cellClassification&);
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 } // End namespace Foam
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 #endif
285 // ************************************************************************* //