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-2022 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 (inflation).
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  -# Inflation:
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  Anyway this was the original idea. Inflation was meant to handle
94  conservative properties distribution without interpolation.
95  (just face sweeping through space). But problem was that
96  only if the introduced splitface was exactly the same shape as bottom face
97  (so same 2D topo or perfectly flat) the volume between them was 0.
98 
99  This meshCutting still uses anchorPoints though:
100  - the master cell is the one without the anchor points. The added cell
101  (on top of the splitFace) is the with.
102  - the splitFace is owned by the master cell (since it has the lower number)
103  - the side faces get split and get either the original cell as neighbour
104  or the added cell (if the faces contain the cell anchor points)
105 
106 SourceFiles
107  meshCutter.C
108 
109 \*---------------------------------------------------------------------------*/
110 
111 #ifndef meshCutter_H
112 #define meshCutter_H
113 
114 #include "edgeVertex.H"
115 #include "labelList.H"
116 #include "typeInfo.H"
117 #include "Map.H"
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 namespace Foam
122 {
123 
124 // Forward declaration of classes
125 class Time;
126 class polyTopoChange;
127 class cellCuts;
128 class polyMesh;
129 class face;
130 
131 /*---------------------------------------------------------------------------*\
132  Class meshCutter Declaration
133 \*---------------------------------------------------------------------------*/
135 class meshCutter
136 :
137  public edgeVertex
138 {
139  // Private Data
140 
141  //- Cells added in last setRefinement. Per splitcell label of added
142  // cell
143  Map<label> addedCells_;
144 
145  //- Faces added in last setRefinement. Per split cell label of added
146  // face
147  Map<label> addedFaces_;
148 
149  //- Points added in last setRefinement. Per split edge label of added
150  // point
151  HashTable<label, edge, Hash<edge>> addedPoints_;
152 
153 
154  // Private Static Functions
155 
156  //- Do list 1 and 2 share elements?
157  static bool uses(const labelList& elems1, const labelList& elems2);
158 
159  //- Do the elements of edge appear in consecutive order in the list
160  static bool isIn(const edge&, const labelList&);
161 
162 
163  // Private Member Functions
164 
165  //- Returns -1 or the cell in cellLabels that is cut.
166  label findCutCell(const cellCuts&, const labelList&) const;
167 
168  //- Returns first pointi in pointLabels that uses an internal
169  // face. Used to find point to inflate cell/face from (has to be
170  // connected to internal face)
171  label findInternalFacePoint(const labelList& pointLabels) const;
172 
173  //- Get new owner and neighbour of face. Checks anchor points to see if
174  // need to get original or added cell.
175  void faceCells
176  (
177  const cellCuts& cuts,
178  const label facei,
179  label& own,
180  label& nei
181  ) const;
182 
183  //- Get patch information for face.
184  void getFaceInfo
185  (
186  const label facei,
187  label& patchID,
188  label& zoneID,
189  label& zoneFlip
190  ) const;
191 
192  //- Adds a face on top of existing facei. Flips face
193  // if owner>neighbour
194  void addFace
195  (
196  polyTopoChange& meshMod,
197  const label facei,
198  const face& newFace,
199  const label owner,
200  const label neighbour
201  );
202 
203  //- Modifies existing facei for either new owner/neighbour or
204  // new face points. Checks if anything changed and flips face
205  // if owner>neighbour
206  void modFace
207  (
208  polyTopoChange& meshMod,
209  const label facei,
210  const face& newFace,
211  const label owner,
212  const label neighbour
213  );
214 
215 
216  // Copies face starting from startFp. Jumps cuts. Marks visited
217  // vertices in visited.
218  void copyFace
219  (
220  const face& f,
221  const label startFp,
222  const label endFp,
223  face& newFace
224  ) const;
225 
226  //- Split face along cut into two faces. Faces are in same point
227  // order as original face (i.e. maintain normal direction)
228  void splitFace
229  (
230  const face& f,
231  const label v0,
232  const label v1,
233 
234  face& f0,
235  face& f1
236  ) const;
237 
238  //- Add cuts of edges to face
239  face addEdgeCutsToFace(const label facei) const;
240 
241  //- Convert loop of cuts into face.
242  face loopToFace
243  (
244  const label celli,
245  const labelList& loop
246  ) const;
247 
248 
249  //- Get elements of cell.
250  void getFacesEdgesPoints
251  (
252  const label celli,
253  labelHashSet& faces,
254  labelHashSet& edges,
256  ) const;
257 
258 
259 public:
260 
261  //- Runtime type information
262  ClassName("meshCutter");
263 
264 
265  // Constructors
266 
267  //- Construct from mesh
268  meshCutter(const polyMesh& mesh);
269 
270  //- Disallow default bitwise copy construction
271  meshCutter(const meshCutter&) = delete;
272 
273 
274  //- Destructor
275  ~meshCutter();
276 
277 
278  // Member Functions
279 
280  // Edit
281 
282  //- Do actual cutting with cut description. Inserts mesh changes
283  // into meshMod.
284  void setRefinement(const cellCuts& cuts, polyTopoChange& meshMod);
285 
286  //- Force recalculation of locally stored data on topological change
287  void topoChange(const polyTopoChangeMap&);
288 
289 
290  // Access
291 
292  //- Cells added. Per split cell label of added cell
293  const Map<label>& addedCells() const
294  {
295  return addedCells_;
296  }
297 
298  //- Faces added. Per split cell label of added face
299  const Map<label>& addedFaces() const
300  {
301  return addedFaces_;
302  }
303 
304  //- Points added. Per split edge label of added point
306  {
307  return addedPoints_;
308  }
309 
310 
311  // Member Operators
312 
313  //- Disallow default bitwise assignment
314  void operator=(const meshCutter&) = delete;
315 };
316 
317 
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 
320 } // End namespace Foam
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 #endif
325 
326 // ************************************************************************* //
meshCutter(const polyMesh &mesh)
Construct from mesh.
Definition: meshCutter.C:506
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
labelList pointLabels(nPoints, -1)
Description of cuts across cells.
Definition: cellCuts.H:108
scalar f1
Definition: createFields.H:15
const pointField & points
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Cuts (splits) cells.
Definition: meshCutter.H:134
Combines edge or vertex in single label. Used to specify cuts across cell circumference.
Definition: edgeVertex.H:52
An STL-conforming hash table.
Definition: HashTable.H:61
void setRefinement(const cellCuts &cuts, polyTopoChange &meshMod)
Do actual cutting with cut description. Inserts mesh changes.
Definition: meshCutter.C:525
const polyMesh & mesh() const
Definition: edgeVertex.H:93
const Map< label > & addedCells() const
Cells added. Per split cell label of added cell.
Definition: meshCutter.H:292
labelList f(nPoints)
ClassName("meshCutter")
Runtime type information.
~meshCutter()
Destructor.
Definition: meshCutter.C:518
Direct mesh changes based on v1.3 polyTopoChange syntax.
const Map< label > & addedFaces() const
Faces added. Per split cell label of added face.
Definition: meshCutter.H:298
void topoChange(const polyTopoChangeMap &)
Force recalculation of locally stored data on topological change.
Definition: meshCutter.C:998
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
void operator=(const meshCutter &)=delete
Disallow default bitwise assignment.
Namespace for OpenFOAM.
const HashTable< label, edge, Hash< edge > > & addedPoints() const
Points added. Per split edge label of added point.
Definition: meshCutter.H:304