meshCutter.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::meshCutter
29 
30 Description
31  Cuts (splits) cells.
32 
33  Description of cut is given as a loop of 'cuts' per cell (see cellCuts).
34  setRefinement() takes this cut description and inserts the necessary
35  topoActions (add points/faces/cells) into the polyTopoChange.
36 
37  Stores added cells/faces/points.
38 
39  Cut description gives orientation to cut by calculating 'anchorPoints'.
40  The side of the cell that contains the anchorPoints is the master cell.
41  Likewise the cells' edges will have the split added as a duplicate of the
42  master (anchor) point.
43  Think of it as the cell with the anchor points at the bottom. Add a face
44  at the bottom to split the cell and then sweep this face up to be through
45  the middle of the cell (inflation).
46 
47 
48  -# Start:
49  cell with anchor points at bottom
50  \verbatim
51  +-------+
52  | +
53  | +
54  | +
55  | +
56  | +
57  | +
58  | +
59  +-------+
60  anchor anchor
61  \endverbatim
62 
63 
64  -# Topo change:
65  splitface introduced at bottom of cell, introducing a new
66  cell and splitting the side faces into two.
67  \verbatim
68  +-------+
69  | +
70  | +
71  | + <- addedCell
72  | +
73  | +
74  | +
75  +-------+ <- splitFace
76  +-------+ <- original cell
77  anchor anchor
78  \endverbatim
79 
80 
81  -# Inflation:
82  splitface shifted up to middle of cell (or wherever cut was)
83  \verbatim
84  +-------+
85  | +
86  | + <- addedCell
87  | +
88  +-------+ <- splitFace
89  | +
90  | + <- original cell
91  | +
92  +-------+
93  anchor anchor
94  \endverbatim
95 
96  Anyway this was the original idea. Inflation was meant to handle
97  conservative properties distribution without interpolation.
98  (just face sweeping through space). But problem was that
99  only if the introduced splitface was exactly the same shape as bottom face
100  (so same 2D topo or perfectly flat) the volume between them was 0.
101 
102  This meshCutting still uses anchorPoints though:
103  - the master cell is the one without the anchor points. The added cell
104  (on top of the splitFace) is the with.
105  - the splitFace is owned by the master cell (since it has the lower number)
106  - the side faces get split and get either the original cell as neighbour
107  or the added cell (if the faces contain the cell anchor points)
108 
109 SourceFiles
110  meshCutter.C
111 
112 \*---------------------------------------------------------------------------*/
113 
114 #ifndef meshCutter_H
115 #define meshCutter_H
116 
117 #include "edgeVertex.H"
118 #include "labelList.H"
119 #include "typeInfo.H"
120 #include "Map.H"
121 #include "edgeHashes.H"
122 
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 
125 namespace Foam
126 {
127 
128 // Forward Declarations
129 class Time;
130 class polyTopoChange;
131 class cellCuts;
132 class polyMesh;
133 class face;
134 
135 /*---------------------------------------------------------------------------*\
136  Class meshCutter Declaration
137 \*---------------------------------------------------------------------------*/
138 
139 class meshCutter
140 :
141  public edgeVertex
142 {
143  // Private data
144 
145  //- Cells added in last setRefinement. Per splitcell label of added
146  // cell
147  Map<label> addedCells_;
148 
149  //- Faces added in last setRefinement. Per split cell label of added
150  // face
151  Map<label> addedFaces_;
152 
153  //- Points added in last setRefinement. Per split edge label of added
154  // point
155  EdgeMap<label> addedPoints_;
156 
157 
158  // Private Static Functions
159 
160  //- Do list 1 and 2 share elements?
161  static bool uses(const labelList& elems1, const labelList& elems2);
162 
163  //- Do the elements of edge appear in consecutive order in the list
164  static bool isIn(const edge&, const labelList&);
165 
166 
167  // Private Member Functions
168 
169  //- Returns -1 or the cell in cellLabels that is cut.
170  label findCutCell(const cellCuts&, const labelList&) const;
171 
172  //- Returns first pointi in pointLabels that uses an internal
173  // face. Used to find point to inflate cell/face from (has to be
174  // connected to internal face)
175  label findInternalFacePoint(const labelList& pointLabels) const;
176 
177  //- Get new owner and neighbour of face. Checks anchor points to see if
178  // need to get original or added cell.
179  void faceCells
180  (
181  const cellCuts& cuts,
182  const label facei,
183  label& own,
184  label& nei
185  ) const;
186 
187  //- Get patch information for face.
188  void getFaceInfo
189  (
190  const label facei,
191  label& patchID,
192  label& zoneID,
193  label& zoneFlip
194  ) const;
195 
196  //- Adds a face on top of existing facei. Flips face
197  // if owner>neighbour
198  void addFace
199  (
200  polyTopoChange& meshMod,
201  const label facei,
202  const face& newFace,
203  const label owner,
204  const label neighbour
205  );
206 
207  //- Modifies existing facei for either new owner/neighbour or
208  // new face points. Checks if anything changed and flips face
209  // if owner>neighbour
210  void modFace
211  (
212  polyTopoChange& meshMod,
213  const label facei,
214  const face& newFace,
215  const label owner,
216  const label neighbour
217  );
218 
219 
220  // Copies face starting from startFp. Jumps cuts. Marks visited
221  // vertices in visited.
222  void copyFace
223  (
224  const face& f,
225  const label startFp,
226  const label endFp,
227  face& newFace
228  ) const;
229 
230  //- Split face along cut into two faces. Faces are in same point
231  // order as original face (i.e. maintain normal direction)
232  void splitFace
233  (
234  const face& f,
235  const label v0,
236  const label v1,
237 
238  face& f0,
239  face& f1
240  ) const;
241 
242  //- Add cuts of edges to face
243  face addEdgeCutsToFace(const label facei) const;
244 
245  //- Convert loop of cuts into face.
246  face loopToFace
247  (
248  const label celli,
249  const labelList& loop
250  ) const;
251 
252 
253  //- Get elements of cell.
254  void getFacesEdgesPoints
255  (
256  const label celli,
257  labelHashSet& faces,
258  labelHashSet& edges,
260  ) const;
261 
262 
263 
264  //- No copy construct
265  meshCutter(const meshCutter&) = delete;
266 
267  //- No copy assignment
268  void operator=(const meshCutter&) = delete;
269 
270 
271 public:
272 
273  //- Runtime type information
274  ClassName("meshCutter");
275 
276 
277  // Constructors
278 
279  //- Construct from mesh
280  explicit meshCutter(const polyMesh& mesh);
281 
282 
283  //- Destructor
284  ~meshCutter() = default;
285 
286 
287  // Member Functions
288 
289  // Edit
290 
291  //- Do actual cutting with cut description. Inserts mesh changes
292  // into meshMod.
293  void setRefinement(const cellCuts& cuts, polyTopoChange& meshMod);
294 
295  //- Force recalculation of locally stored data on topological change
296  void updateMesh(const mapPolyMesh&);
297 
298 
299  // Access
300 
301  //- Cells added. Per split cell label of added cell
302  const Map<label>& addedCells() const
303  {
304  return addedCells_;
305  }
306 
307  //- Faces added. Per split cell label of added face
308  const Map<label>& addedFaces() const
309  {
310  return addedFaces_;
311  }
312 
313  //- Points added. Per split edge label of added point
314  const EdgeMap<label>& addedPoints() const
315  {
316  return addedPoints_;
317  }
318 };
319 
320 
321 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 
323 } // End namespace Foam
324 
325 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
326 
327 #endif
328 
329 // ************************************************************************* //
Foam::meshCutter
Cuts (splits) cells.
Definition: meshCutter.H:138
typeInfo.H
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::edgeVertex
Combines edge or vertex in single label. Used to specify cuts across cell circumference.
Definition: edgeVertex.H:55
Foam::Map< label >
Foam::meshCutter::addedCells
const Map< label > & addedCells() const
Cells added. Per split cell label of added cell.
Definition: meshCutter.H:301
Foam::meshCutter::updateMesh
void updateMesh(const mapPolyMesh &)
Force recalculation of locally stored data on topological change.
Definition: meshCutter.C:995
Foam::HashSet< label, Hash< label > >
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::meshCutter::ClassName
ClassName("meshCutter")
Runtime type information.
Map.H
labelList.H
patchID
label patchID
Definition: boundaryProcessorFaPatchPoints.H:5
Foam::meshCutter::~meshCutter
~meshCutter()=default
Destructor.
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::EdgeMap< label >
edgeHashes.H
f
labelList f(nPoints)
Foam::meshCutter::setRefinement
void setRefinement(const cellCuts &cuts, polyTopoChange &meshMod)
Do actual cutting with cut description. Inserts mesh changes.
Definition: meshCutter.C:522
Foam::List< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::meshCutter::addedPoints
const EdgeMap< label > & addedPoints() const
Points added. Per split edge label of added point.
Definition: meshCutter.H:313
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56
pointLabels
labelList pointLabels(nPoints, -1)
edgeVertex.H
Foam::meshCutter::addedFaces
const Map< label > & addedFaces() const
Faces added. Per split cell label of added face.
Definition: meshCutter.H:307
Foam::cellCuts
Description of cuts across cells.
Definition: cellCuts.H:110
Foam::edgeVertex::mesh
const polyMesh & mesh() const
Definition: edgeVertex.H:101