meshCutter.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-2024 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::meshCutter
26 
27 Description
28  Cuts (splits) cells.
29 
30  Description of cut is given as a loop of 'cuts' per cell (see cellCuts).
31  setRefinement() takes this cut description and inserts the necessary
32  topoActions (add points/faces/cells) into the polyTopoChange.
33 
34  Stores added cells/faces/points.
35 
36  Cut description gives orientation to cut by calculating 'anchorPoints'.
37  The side of the cell that contains the anchorPoints is the master cell.
38  Likewise the cells' edges will have the split added as a duplicate of the
39  master (anchor) point.
40  Think of it as the cell with the anchor points at the bottom. Add a face
41  at the bottom to split the cell and then sweep this face up to be through
42  the middle of the cell.
43 
44 
45  -# Start:
46  cell with anchor points at bottom
47  \verbatim
48  +-------+
49  | +
50  | +
51  | +
52  | +
53  | +
54  | +
55  | +
56  +-------+
57  anchor anchor
58  \endverbatim
59 
60 
61  -# Topo change:
62  splitface introduced at bottom of cell, introducing a new
63  cell and splitting the side faces into two.
64  \verbatim
65  +-------+
66  | +
67  | +
68  | + <- addedCell
69  | +
70  | +
71  | +
72  +-------+ <- splitFace
73  +-------+ <- original cell
74  anchor anchor
75  \endverbatim
76 
77 
78  -# Move face:
79  splitface shifted up to middle of cell (or wherever cut was)
80  \verbatim
81  +-------+
82  | +
83  | + <- addedCell
84  | +
85  +-------+ <- splitFace
86  | +
87  | + <- original cell
88  | +
89  +-------+
90  anchor anchor
91  \endverbatim
92 
93  This meshCutting uses anchorPoints:
94  - the master cell is the one without the anchor points. The added cell
95  (on top of the splitFace) is the with.
96  - the splitFace is owned by the master cell (since it has the lower number)
97  - the side faces get split and get either the original cell as neighbour
98  or the added cell (if the faces contain the cell anchor points)
99 
100 SourceFiles
101  meshCutter.C
102 
103 \*---------------------------------------------------------------------------*/
104 
105 #ifndef meshCutter_H
106 #define meshCutter_H
107 
108 #include "edgeVertex.H"
109 #include "labelList.H"
110 #include "typeInfo.H"
111 #include "Map.H"
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 namespace Foam
116 {
117 
118 // Forward declaration of classes
119 class Time;
120 class polyTopoChange;
121 class cellCuts;
122 class polyMesh;
123 class face;
124 
125 /*---------------------------------------------------------------------------*\
126  Class meshCutter Declaration
127 \*---------------------------------------------------------------------------*/
128 
129 class meshCutter
130 :
131  public edgeVertex
132 {
133  // Private Data
134 
135  //- Cells added in last setRefinement. Per splitcell label of added
136  // cell
137  Map<label> addedCells_;
138 
139  //- Faces added in last setRefinement. Per split cell label of added
140  // face
141  Map<label> addedFaces_;
142 
143  //- Points added in last setRefinement. Per split edge label of added
144  // point
145  HashTable<label, edge, Hash<edge>> addedPoints_;
146 
147 
148  // Private Static Functions
149 
150  //- Do list 1 and 2 share elements?
151  static bool uses(const labelList& elems1, const labelList& elems2);
152 
153  //- Do the elements of edge appear in consecutive order in the list
154  static bool isIn(const edge&, const labelList&);
155 
156 
157  // Private Member Functions
158 
159  //- Returns -1 or the cell in cellLabels that is cut.
160  label findCutCell(const cellCuts&, const labelList&) const;
161 
162  //- Returns first pointi in pointLabels that uses an internal face
163  label findInternalFacePoint(const labelList& pointLabels) const;
164 
165  //- Get new owner and neighbour of face. Checks anchor points to see if
166  // need to get original or added cell.
167  void faceCells
168  (
169  const cellCuts& cuts,
170  const label facei,
171  label& own,
172  label& nei
173  ) const;
174 
175  //- Get patch index face
176  label getPatchIndex(const label facei) const;
177 
178  //- Adds a face on top of existing facei. Flips face
179  // if owner>neighbour
180  void addFace
181  (
182  polyTopoChange& meshMod,
183  const label facei,
184  const face& newFace,
185  const label owner,
186  const label neighbour
187  );
188 
189  //- Modifies existing facei for either new owner/neighbour or
190  // new face points. Checks if anything changed and flips face
191  // if owner>neighbour
192  void modifyFace
193  (
194  polyTopoChange& meshMod,
195  const label facei,
196  const face& newFace,
197  const label owner,
198  const label neighbour
199  );
200 
201 
202  // Copies face starting from startFp. Jumps cuts. Marks visited
203  // vertices in visited.
204  void copyFace
205  (
206  const face& f,
207  const label startFp,
208  const label endFp,
209  face& newFace
210  ) const;
211 
212  //- Split face along cut into two faces. Faces are in same point
213  // order as original face (i.e. maintain normal direction)
214  void splitFace
215  (
216  const face& f,
217  const label v0,
218  const label v1,
219 
220  face& f0,
221  face& f1
222  ) const;
223 
224  //- Add cuts of edges to face
225  face addEdgeCutsToFace(const label facei) const;
226 
227  //- Convert loop of cuts into face.
228  face loopToFace
229  (
230  const label celli,
231  const labelList& loop
232  ) const;
233 
234 
235  //- Get elements of cell.
236  void getFacesEdgesPoints
237  (
238  const label celli,
239  labelHashSet& faces,
240  labelHashSet& edges,
242  ) const;
243 
244 
245 public:
246 
247  //- Runtime type information
248  ClassName("meshCutter");
249 
250 
251  // Constructors
252 
253  //- Construct from mesh
254  meshCutter(const polyMesh& mesh);
255 
256  //- Disallow default bitwise copy construction
257  meshCutter(const meshCutter&) = delete;
258 
259 
260  //- Destructor
261  ~meshCutter();
262 
263 
264  // Member Functions
265 
266  // Edit
267 
268  //- Do actual cutting with cut description. Inserts mesh changes
269  // into meshMod.
270  void setRefinement(const cellCuts& cuts, polyTopoChange& meshMod);
271 
272  //- Force recalculation of locally stored data on topological change
273  void topoChange(const polyTopoChangeMap&);
274 
275 
276  // Access
277 
278  //- Cells added. Per split cell label of added cell
279  const Map<label>& addedCells() const
280  {
281  return addedCells_;
282  }
283 
284  //- Faces added. Per split cell label of added face
285  const Map<label>& addedFaces() const
286  {
287  return addedFaces_;
288  }
289 
290  //- Points added. Per split edge label of added point
292  {
293  return addedPoints_;
294  }
295 
296 
297  // Member Operators
298 
299  //- Disallow default bitwise assignment
300  void operator=(const meshCutter&) = delete;
301 };
302 
303 
304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305 
306 } // End namespace Foam
307 
308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
309 
310 #endif
311 
312 // ************************************************************************* //
An STL-conforming hash table.
Definition: HashTable.H:127
Description of cuts across cells.
Definition: cellCuts.H:111
Combines edge or vertex in single label. Used to specify cuts across cell circumference.
Definition: edgeVertex.H:53
const polyMesh & mesh() const
Definition: edgeVertex.H:93
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:61
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Cuts (splits) cells.
Definition: meshCutter.H:131
void operator=(const meshCutter &)=delete
Disallow default bitwise assignment.
meshCutter(const polyMesh &mesh)
Construct from mesh.
Definition: meshCutter.C:451
void topoChange(const polyTopoChangeMap &)
Force recalculation of locally stored data on topological change.
Definition: meshCutter.C:916
const HashTable< label, edge, Hash< edge > > & addedPoints() const
Points added. Per split edge label of added point.
Definition: meshCutter.H:290
ClassName("meshCutter")
Runtime type information.
void setRefinement(const cellCuts &cuts, polyTopoChange &meshMod)
Do actual cutting with cut description. Inserts mesh changes.
Definition: meshCutter.C:470
const Map< label > & addedFaces() const
Faces added. Per split cell label of added face.
Definition: meshCutter.H:284
~meshCutter()
Destructor.
Definition: meshCutter.C:463
const Map< label > & addedCells() const
Cells added. Per split cell label of added cell.
Definition: meshCutter.H:278
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Direct mesh changes based on v1.3 polyTopoChange syntax.
const pointField & points
labelListList cellCuts(const cell &c, const cellEdgeAddressing &cAddr, const faceUList &fs, const List< List< labelPair >> &fCuts, const scalarField &pAlphas, const scalar isoAlpha)
Return the cuts for a given cell. This returns a list of lists of cell-edge.
Definition: cutPoly.C:121
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
labelList f(nPoints)
labelList pointLabels(nPoints, -1)
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...