cellClassification.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::cellClassification
26 
27 Description
28  'Cuts' a mesh with a surface.
29 
30  Divides cells into three types
31  - cut, i.e. any of the edges of the cell is split or any edge of the
32  surface pierces any of the faces of the cell.
33  - outside: cell can be reached by Meshwave from any of the supplied
34  outside points (without crossing any cut cell)
35  - inside: all other.
36 
37  Used in various meshing programs.
38 
39  Has various utility functions to deal with 'features' on this level
40  where the mesh still has all inside and outside cells.
41 
42  \par Concepts
43 
44  - point classification:
45  - point used by meshType cells only
46  - point used by non-meshType cells only
47  - point used by both types ('mixed')
48 
49  - hanging cells: meshType cells using mixed points only.
50  These cells would have all their vertices on the surface when
51  extracting the meshType cells.
52 
53  - regionEdges: edges where the cells using it are of mixed type.
54  Or more precise when walking around the edge and looking at the
55  different types of the cells there are more than two regions with
56  same type.
57 
58  Seen from above:
59  \verbatim
60  Ok:
61  A | A
62  |
63  --+---
64  |
65  B | B
66 
67  Not ok:
68  A | B
69  |
70  ---+---
71  |
72  B | A
73  \endverbatim
74 
75  because this latter situation would cause the surface after subsetting
76  type A or B to be multiply connected across this edge. And also when
77  snapping the edge end points to the surface it might cause some twisted
78  faces if the surface is normal to the edge (and smoothing the surface
79  would not help since the points on the edge would be 'pulled' from two
80  different sides)
81 
82  - regionPoints: like regionEdges but now for points.
83  Points where subsetting the mesh would cause a multiply connected
84  outside surface (connected across point, not edge)
85 
86 
87 SourceFiles
88  cellClassification.C
89 
90 \*---------------------------------------------------------------------------*/
91 
92 #ifndef cellClassification_H
93 #define cellClassification_H
94 
95 #include "boolList.H"
96 #include "labelList.H"
97 #include "faceList.H"
98 
99 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
100 
101 namespace Foam
102 {
103 
104 // Forward declaration of classes
105 class triSurfaceSearch;
106 class polyMesh;
107 class primitiveMesh;
108 
109 /*---------------------------------------------------------------------------*\
110  Class cellClassification Declaration
111 \*---------------------------------------------------------------------------*/
112 
113 class cellClassification
114 :
115  public labelList
116 {
117 
118 public:
119 
120  // Public data types
121 
122  //- Type of cell.
123  enum cType
124  {
126  INSIDE, // Inside of surface
127  OUTSIDE, // Outside ,,
128  CUT // cut by surface
129  };
130 
131 
132  //- Enumeration defining the whether points are use by cells of
133  // a certain type.
134  enum pointStatus
135  {
137  MESH, // points used by meshType cells
138  NONMESH, // ,, non-mesh type cells
139  MIXED // ,, both types of cell
140  };
141 
142 private:
143 
144  // Private Data
145 
146  //- Reference to mesh
147  const polyMesh& mesh_;
148 
149 
150  // Private Static Functions
151 
152  //- Count number of occurrences of elem in list
153  static label count(const labelList& elems, const label elem);
154 
155 
156  // Private Member Functions
157 
158  //- Mark all faces intersected by or intersecting surface
159  boolList markFaces(const triSurfaceSearch&) const;
160 
161  //- Divide cells into cut/inside/outside by using FaceCellWave from cut
162  // faces. No check is done on whether outsidePts are in different
163  // domains.
164  void markCells
165  (
166  const boolList& piercedFace,
167  const List<point>& outsidePts
168  );
169 
170  //- Use cell status to classify points as being internal to meshType,
171  // internal to non-meshType or on border of both.
172  void classifyPoints
173  (
174  const label meshType,
175  const labelList& cellType,
176  List<pointStatus>& pointSide
177  ) const;
178 
179  //- Return true if cell uses only points with status=mixed
180  bool usesMixedPointsOnly
181  (
182  const List<pointStatus>&,
183  const label celli
184  ) const;
185 
186  //- Get faces (and its 'owner') in between cells of differing type
187  // (meshType and non-meshType).
188  void getMeshOutside(const label meshType, faceList&, labelList&) const;
189 
190 
191 public:
192 
193  // Static Data Members
194  ClassName("cellClassification");
195 
196  // Constructors
197 
198  //- Construct from mesh and surface and point(s) on outside
200  (
201  const polyMesh& mesh,
202  const triSurfaceSearch& surfQuery,
203  const List<point>& outsidePoints
204  );
205 
206  //- Construct from mesh and type for every cell.
207  // Used to be able to reuse filling routines below.
208  cellClassification(const polyMesh& mesh, const labelList& cellType);
209 
210  //- Copy constructor
212 
213 
214  // Member Functions
215 
216  const polyMesh& mesh() const
217  {
218  return mesh_;
219  }
220 
222  (
223  const label nLayers,
224  const label meshType,
225  const label fillType
226  );
227 
228  //- Sets vertex neighbours of meshType cells to fillType
229  label growSurface(const label meshType, const label fillType);
230 
231  //- Find hanging cells (cells with all points on outside) and set their
232  // type to fillType.
233  // Iterate until nothing changed. Returns total number of cells
234  // changed (in all iterations)
236  (
237  const label meshType,
238  const label fillType,
239  const label maxIter
240  );
241 
242  //- Find regionEdges and fill one neighbour. Iterate until nothing
243  // changes. Returns total number of cells changed.
245  (
246  const label meshType,
247  const label fillType,
248  const label maxIter
249  );
250 
251  //- Find regionPoints and fill all neighbours. Iterate until nothing
252  // changes. Returns total number of cells changed.
254  (
255  const label meshType,
256  const label fillType,
257  const label maxIter
258  );
259 
260  //- Write statistics on cell types to Ostream
261  void writeStats(Ostream& os) const;
262 
263 
264  // Member Operators
265 
266  void operator=(const cellClassification&);
267 
268 };
269 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 } // End namespace Foam
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #endif
278 
279 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
'Cuts' a mesh with a surface.
label fillRegionPoints(const label meshType, const label fillType, const label maxIter)
Find regionPoints and fill all neighbours. Iterate until nothing.
cellClassification(const polyMesh &mesh, const triSurfaceSearch &surfQuery, const List< point > &outsidePoints)
Construct from mesh and surface and point(s) on outside.
label fillHangingCells(const label meshType, const label fillType, const label maxIter)
Find hanging cells (cells with all points on outside) and set their.
label growSurface(const label meshType, const label fillType)
Sets vertex neighbours of meshType cells to fillType.
void operator=(const cellClassification &)
label trimCutCells(const label nLayers, const label meshType, const label fillType)
pointStatus
Enumeration defining the whether points are use by cells of.
ClassName("cellClassification")
void writeStats(Ostream &os) const
Write statistics on cell types to Ostream.
const polyMesh & mesh() const
label fillRegionEdges(const label meshType, const label fillType, const label maxIter)
Find regionEdges and fill one neighbour. Iterate until nothing.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
Helper class to search on triSurface.
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59