hexRef8.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-2017 OpenFOAM Foundation
9  Copyright (C) 2016-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::hexRef8
29 
30 Description
31  Refinement of (split) hexes using polyTopoChange.
32 
33 SourceFiles
34  hexRef8.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef hexRef8_H
39 #define hexRef8_H
40 
41 #include "labelIOList.H"
42 #include "face.H"
43 #include "HashSet.H"
44 #include "DynamicList.H"
45 #include "primitivePatch.H"
46 #include "removeFaces.H"
47 #include "refinementHistory.H"
48 #include "bitSet.H"
50 #include "cellShapeList.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward Declarations
58 class polyMesh;
59 class polyPatch;
60 class polyTopoChange;
61 class mapPolyMesh;
62 class mapDistributePolyMesh;
63 
64 /*---------------------------------------------------------------------------*\
65  Class hexRef8 Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class hexRef8
69 {
70  // Private Data
71 
72  //- Reference to underlying mesh.
73  const polyMesh& mesh_;
74 
75  //- Per cell the refinement level
76  labelIOList cellLevel_;
77 
78  //- Per point the refinement level
79  labelIOList pointLevel_;
80 
81  //- Typical edge length between unrefined points
83 
84  //- Refinement history
85  refinementHistory history_;
86 
87  //- Face remover engine
88  removeFaces faceRemover_;
89 
90  //- Level of saved points
91  Map<label> savedPointLevel_;
92 
93  //- Level of saved cells
94  Map<label> savedCellLevel_;
95 
96  //- Cell shapes when seen as split hexes
97  mutable autoPtr<cellShapeList> cellShapesPtr_;
98 
99 
100  // Private Member Functions
101 
102  //- Reorder according to map.
103  static void reorder
104  (
105  const labelList& map,
106  const label len,
107  const label null,
108  labelList& elems
109  );
110 
111  //- Get patch and zone info
112  void getFaceInfo
113  (
114  const label facei,
115  label& patchID,
116  label& zoneID,
117  label& zoneFlip
118  ) const;
119 
120  //- Adds a face on top of existing facei. Reverses if necessary.
121  label addFace
122  (
123  polyTopoChange& meshMod,
124  const label facei,
125  const face& newFace,
126  const label own,
127  const label nei
128  ) const;
129 
130  //- Adds internal face from point. No checks on reversal.
131  label addInternalFace
132  (
133  polyTopoChange& meshMod,
134  const label meshFacei,
135  const label meshPointi,
136  const face& newFace,
137  const label own,
138  const label nei
139  ) const;
140 
141  //- Modifies existing facei for either new owner/neighbour or new face
142  // points. Reverses if necessary.
143  void modFace
144  (
145  polyTopoChange& meshMod,
146  const label facei,
147  const face& newFace,
148  const label own,
149  const label nei
150  ) const;
151 
152  scalar getLevel0EdgeLength() const;
153 
154  //- Get cell added to point of celli (if any)
155  label getAnchorCell
156  (
157  const labelListList& cellAnchorPoints,
158  const labelListList& cellAddedCells,
159  const label celli,
160  const label facei,
161  const label pointi
162  ) const;
163 
164  //- Get new owner and neighbour (in unspecified order) of pointi
165  // on facei.
166  void getFaceNeighbours
167  (
168  const labelListList& cellAnchorPoints,
169  const labelListList& cellAddedCells,
170  const label facei,
171  const label pointi,
172 
173  label& own,
174  label& nei
175  ) const;
176 
177 
178  //- Get index of minimum pointlevel.
179  label findMinLevel(const labelList& f) const;
180  //- Get maximum pointlevel.
181  label findMaxLevel(const labelList& f) const;
182  //- Count number of vertices <= anchorLevel
183  label countAnchors(const labelList&, const label) const;
184  //- Debugging: dump cell as .obj file
185  void dumpCell(const label celli) const;
186  //- Find index of point with wantedLevel, starting from fp.
187  label findLevel
188  (
189  const label facei,
190  const face& f,
191  const label startFp,
192  const bool searchForward,
193  const label wantedLevel
194  ) const;
195 
197  //void printLevels(Ostream&, const labelList&) const;
198 
199  //- debug:check orientation of added internal face
200  static void checkInternalOrientation
201  (
202  polyTopoChange& meshMod,
203  const label celli,
204  const label facei,
205  const point& ownPt,
206  const point& neiPt,
207  const face& newFace
208  );
209 
210  //- debug:check orientation of new boundary face
211  static void checkBoundaryOrientation
212  (
213  polyTopoChange& meshMod,
214  const label celli,
215  const label facei,
216  const point& ownPt,
217  const point& boundaryPt,
218  const face& newFace
219  );
220 
221  //- If p0 and p1 are existing vertices check if edge is split and insert
222  // splitPoint.
223  void insertEdgeSplit
224  (
225  const labelList& edgeMidPoint,
226  const label p0,
227  const label p1,
228  DynamicList<label>& verts
229  ) const;
230 
231  //- Store in maps correspondence from midpoint to anchors and faces.
232  label storeMidPointInfo
233  (
234  const labelListList& cellAnchorPoints,
235  const labelListList& cellAddedCells,
236  const labelList& cellMidPoint,
237  const labelList& edgeMidPoint,
238  const label celli,
239  const label facei,
240  const bool faceOrder,
241  const label midPointi,
242  const label anchorPointi,
243  const label faceMidPointi,
244 
245  Map<edge>& midPointToAnchors,
246  Map<edge>& midPointToFaceMids,
247  polyTopoChange& meshMod
248  ) const;
249 
250  //- Create all internal faces from an unsplit face.
251  void createInternalFromSplitFace
252  (
253  const labelListList& cellAnchorPoints,
254  const labelListList& cellAddedCells,
255  const labelList& cellMidPoint,
256  const labelList& faceMidPoint,
257  const labelList& edgeMidPoint,
258  const label celli,
259  const label facei,
260 
261  Map<edge>& midPointToAnchors,
262  Map<edge>& midPointToFaceMids,
263  polyTopoChange& meshMod,
264  label& nFacesAdded
265  ) const;
266 
267  //- Create all internal faces to split celli into 8.
268  void createInternalFaces
269  (
270  const labelListList& cellAnchorPoints,
271  const labelListList& cellAddedCells,
272  const labelList& cellMidPoint,
273  const labelList& faceMidPoint,
274  const labelList& faceAnchorLevel,
275  const labelList& edgeMidPoint,
276  const label celli,
277  polyTopoChange& meshMod
278  ) const;
279 
280  //- Store vertices from startFp upto face split point.
281  // Used when splitting face into 4.
282  void walkFaceToMid
283  (
284  const labelList& edgeMidPoint,
285  const label cLevel,
286  const label facei,
287  const label startFp,
288  DynamicList<label>& faceVerts
289  ) const;
290 
291  //- Same as walkFaceToMid but now walk back.
292  void walkFaceFromMid
293  (
294  const labelList& edgeMidPoint,
295  const label cLevel,
296  const label facei,
297  const label startFp,
298  DynamicList<label>& faceVerts
299  ) const;
300 
301  //- Updates refineCell so consistent 2:1 refinement. Returns local
302  // number of cells changed.
303  label faceConsistentRefinement
304  (
305  const bool maxSet,
306  const labelUList& cellLevel,
308  ) const;
309 
310  //- Check wanted refinement for 2:1 consistency
311  void checkWantedRefinementLevels
312  (
313  const labelUList& cellLevel,
314  const labelList&
315  ) const;
316 
317 
318  // Cellshape recognition
319 
320  //- Collect all points on face of certain level
321  void collectLevelPoints
322  (
323  const labelList& f,
324  const label level,
326  ) const;
327 
328  //- Collect all points on face (in local numbering) of certain level
329  void collectLevelPoints
330  (
331  const labelList& meshPoints,
332  const labelList& f,
333  const label level,
335  ) const;
336 
337  //- Collect all faces with four corner points and return true if
338  // hex was matched (6 faces of each four corner points)
339  bool matchHexShape
340  (
341  const label celli,
342  const label cellLevel,
343  DynamicList<face>& quads
344  ) const;
345 
346 
347  //- No copy construct
348  hexRef8(const hexRef8&) = delete;
349 
350  //- No copy assignment
351  void operator=(const hexRef8&) = delete;
352 
353 
354 public:
355 
356  //- Runtime type information
357  ClassName("hexRef8");
358 
359 
360  // Constructors
361 
362  //- Construct from mesh, read_if_present refinement data
363  // (from write below). If readHistory is true does read_if_present
364  // of refinement history. If false clears all history
365  explicit hexRef8(const polyMesh& mesh, const bool readHistory=true);
366 
367  //- Construct from mesh and un/refinement data and optional size of
368  // starting cells
369  hexRef8
370  (
371  const polyMesh& mesh,
372  const labelList& cellLevel,
373  const labelList& pointLevel,
374  const refinementHistory& history,
375  const scalar level0Edge = -GREAT
376  );
377 
378  //- Construct from mesh and refinement data and optional size of
379  // starting cells
380  hexRef8
381  (
382  const polyMesh& mesh,
383  const labelList& cellLevel,
384  const labelList& pointLevel,
385  const scalar level0Edge = -GREAT
386  );
387 
388 
389  // Member Functions
390 
391  // Access
392 
393  const polyMesh& mesh() const
394  {
395  return mesh_;
396  }
397 
398  const labelIOList& cellLevel() const
399  {
400  return cellLevel_;
401  }
402 
403  const labelIOList& pointLevel() const
404  {
405  return pointLevel_;
406  }
407 
408  const refinementHistory& history() const
409  {
410  return history_;
411  }
412 
413  //- Typical edge length between unrefined points
414  scalar level0EdgeLength() const
415  {
416  return level0Edge_.value();
417  }
418 
419  // Refinement
420 
421  //- Gets level such that the face has four points <= level.
422  label faceLevel(const label facei) const;
423 
424  //- Given valid mesh and current cell level and proposed
425  // cells to refine calculate any clashes (due to 2:1) and return
426  // ok list of cells to refine.
427  // Either adds cells to refine to set (maxSet = true) or
428  // removes cells to refine (maxSet = false)
430  (
431  const labelUList& cellLevel,
432  const labelList& cellsToRefine,
433  const bool maxSet
434  ) const;
435 
436  //- Given valid mesh and current cell level and proposed
437  // cells to refine calculate any clashes (due to 2:1) and return
438  // ok list of cells to refine.
439  // Either adds cells to refine to set (maxSet = true) or
440  // removes cells to refine (maxSet = false)
442  (
443  const labelList& cellsToRefine,
444  const bool maxSet
445  ) const
446  {
447  return consistentRefinement(cellLevel_, cellsToRefine, maxSet);
448  }
449 
450  //- Like consistentRefinement but slower:
451  //
452  // - specify number of cells between consecutive refinement levels
453  // (consistentRefinement equivalent to 1)
454  // - specify max level difference between point-connected cells.
455  // (-1 to disable) Note that with normal 2:1 limitation
456  // (maxFaceDiff=1) there can be 8:1 size difference across point
457  // connected cells so maxPointDiff allows you to make that less.
458  // cellsToRefine : cells we're thinking about refining. It will
459  // extend this set. All refinement levels will be
460  // at least maxFaceDiff layers thick.
461  // facesToCheck : additional faces where to implement the
462  // maxFaceDiff thickness (usually only boundary
463  // faces)
465  (
466  const label maxFaceDiff,
467  const labelList& cellsToRefine,
468  const labelList& facesToCheck,
469  const label maxPointDiff,
470  const labelList& pointsToCheck
471  ) const;
472 
473  //- Like consistentSlowRefinement but uses different meshWave
474  // (proper distance instead of toplogical count). No point checks
475  // yet.
477  (
478  const label maxFaceDiff,
479  const labelList& cellsToRefine,
480  const labelList& facesToCheck
481  ) const;
482 
483  //- Insert refinement. All selected cells will be split into 8.
484  // Returns per element in cells the 8 cells they were split into.
485  // Guarantees that the 0th element is the original cell label.
486  // Mapping:
487  // -split cells: 7 new ones get added from original
488  // -split faces: original gets modified; 3 new ones get added
489  // from original
490  // -added internal faces: added from original cell face(if
491  // that was internal) or created out-of-nothing (so will not
492  // get mapped!). Note: could make this inflate from point but
493  // that will allocate interpolation.
494  // -points added to split edge: added from edge start()
495  // -midpoints added: added from cellPoints[0].
497  (
498  const labelList& cells,
500  );
501 
502  //- Update local numbering for changed mesh.
503  void updateMesh(const mapPolyMesh&);
504 
505 
506  // Restoring : is where other processes delete and reinsert data.
507  // These callbacks allow this to restore the cellLevel
508  // and pointLevel for reintroduced points.
509  // Is not related to undoing my refinement
510 
511  //- Signal points/face/cells for which to store data
512  void storeData
513  (
514  const labelList& pointsToStore,
515  const labelList& facesToStore,
516  const labelList& cellsToStore
517  );
518 
519  //- Update local numbering + undo
520  // Data to restore given as new pointlabel + stored pointlabel
521  // (i.e. what was in pointsToStore)
522  void updateMesh
523  (
524  const mapPolyMesh&,
525  const Map<label>& pointsToRestore,
526  const Map<label>& facesToRestore,
527  const Map<label>& cellsToRestore
528  );
529 
530 
531  //- Update local numbering for subsetted mesh.
532  // Gets new-to-old maps. Not compatible with unrefinement.
533  void subset
534  (
535  const labelList& pointMap,
536  const labelList& faceMap,
537  const labelList& cellMap
538  );
539 
540  //- Update local numbering for mesh redistribution
541  void distribute(const mapDistributePolyMesh&);
542 
543  //- Debug: Check coupled mesh for correctness
544  void checkMesh() const;
545 
546  //- Debug: Check 2:1 consistency across faces.
547  // maxPointDiff==-1 : only check 2:1 across faces
548  // maxPointDiff!=-1 : check point-connected cells.
550  (
551  const label maxPointDiff,
552  const labelList& pointsToCheck
553  ) const;
554 
555  //- Utility: get hexes as cell shapes
556  const cellShapeList& cellShapes() const;
557 
558 
559  // Unrefinement (undoing refinement, not arbitrary coarsening)
560 
561  //- Return the points at the centre of top-level split cells
562  // that can be unsplit.
563  labelList getSplitPoints() const;
564 
565  //- Given proposed
566  // splitPoints to unrefine according to calculate any clashes
567  // (due to 2:1) and return ok list of points to unrefine.
568  // Either adds points to refine to set (maxSet = true) or
569  // removes points to refine (maxSet = false)
571  (
572  const labelList& pointsToUnrefine,
573  const bool maxSet
574  ) const;
575 
576  //- Remove some refinement. Needs to be supplied output of
577  // consistentUnrefinement. Only call if undoable set.
578  // All 8 pointCells of a split point will be combined into
579  // the lowest numbered cell of those 8.
580  void setUnrefinement
581  (
582  const labelList& splitPointLabels,
584  );
585 
586  // Write
587 
588  // Set instance for mesh files
589  void setInstance(const fileName& inst);
590 
591  //- Force writing refinement+history to polyMesh directory.
592  bool write(const bool valid = true) const;
593 
594  //- Helper: remove all relevant files from mesh instance
595  static void removeFiles(const polyMesh&);
596 };
597 
598 
599 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
600 
601 } // End namespace Foam
602 
603 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
604 
605 #endif
606 
607 // ************************************************************************* //
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::hexRef8::cellLevel
const labelIOList & cellLevel() const
Definition: hexRef8.H:397
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::hexRef8::ClassName
ClassName("hexRef8")
Runtime type information.
Foam::DynamicList< label >
Foam::hexRef8::getSplitPoints
labelList getSplitPoints() const
Return the points at the centre of top-level split cells.
Definition: hexRef8.C:5070
cellShapeList.H
Foam::hexRef8::write
bool write(const bool valid=true) const
Force writing refinement+history to polyMesh directory.
Definition: hexRef8.C:5698
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
face.H
Foam::Map< label >
Foam::hexRef8::updateMesh
void updateMesh(const mapPolyMesh &)
Update local numbering for changed mesh.
Definition: hexRef8.C:4236
Foam::hexRef8::setInstance
void setInstance(const fileName &inst)
Definition: hexRef8.C:1734
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
Foam::hexRef8::removeFiles
static void removeFiles(const polyMesh &)
Helper: remove all relevant files from mesh instance.
Definition: hexRef8.C:5718
bitSet.H
Foam::hexRef8::cellShapes
const cellShapeList & cellShapes() const
Utility: get hexes as cell shapes.
Definition: hexRef8.C:5010
Foam::hexRef8::consistentRefinement
labelList consistentRefinement(const labelUList &cellLevel, const labelList &cellsToRefine, const bool maxSet) const
Given valid mesh and current cell level and proposed.
Definition: hexRef8.C:2255
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::refinementHistory
All refinement history. Used in unrefinement.
Definition: refinementHistory.H:102
Foam::hexRef8::setRefinement
labelListList setRefinement(const labelList &cells, polyTopoChange &)
Insert refinement. All selected cells will be split into 8.
Definition: hexRef8.C:3195
Foam::hexRef8::checkRefinementLevels
void checkRefinementLevels(const label maxPointDiff, const labelList &pointsToCheck) const
Debug: Check 2:1 consistency across faces.
Definition: hexRef8.C:4758
Foam::UniformDimensionedField< scalar >
Foam::removeFaces
Given list of faces to remove insert all the topology changes. Contains helper function to get consis...
Definition: removeFaces.H:64
patchID
label patchID
Definition: boundaryProcessorFaPatchPoints.H:5
Foam::hexRef8::subset
void subset(const labelList &pointMap, const labelList &faceMap, const labelList &cellMap)
Update local numbering for subsetted mesh.
Definition: hexRef8.C:4438
Foam::hexRef8::mesh
const polyMesh & mesh() const
Definition: hexRef8.H:392
HashSet.H
removeFaces.H
Foam::hexRef8::history
const refinementHistory & history() const
Definition: hexRef8.H:407
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::hexRef8::consistentSlowRefinement2
labelList consistentSlowRefinement2(const label maxFaceDiff, const labelList &cellsToRefine, const labelList &facesToCheck) const
Like consistentSlowRefinement but uses different meshWave.
Definition: hexRef8.C:2795
Foam::hexRef8::storeData
void storeData(const labelList &pointsToStore, const labelList &facesToStore, const labelList &cellsToStore)
Signal points/face/cells for which to store data.
Definition: hexRef8.C:4209
Foam::hexRef8::consistentSlowRefinement
labelList consistentSlowRefinement(const label maxFaceDiff, const labelList &cellsToRefine, const labelList &facesToCheck, const label maxPointDiff, const labelList &pointsToCheck) const
Like consistentRefinement but slower:
Definition: hexRef8.C:2311
Foam::hexRef8::setUnrefinement
void setUnrefinement(const labelList &splitPointLabels, polyTopoChange &)
Remove some refinement. Needs to be supplied output of.
Definition: hexRef8.C:5497
uniformDimensionedFields.H
Foam::hexRef8::level0EdgeLength
scalar level0EdgeLength() const
Typical edge length between unrefined points.
Definition: hexRef8.H:413
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::refineCell
Container with cells to refine. Refinement given as single direction.
Definition: refineCell.H:56
Foam::hexRef8
Refinement of (split) hexes using polyTopoChange.
Definition: hexRef8.H:67
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::hexRef8::pointLevel
const labelIOList & pointLevel() const
Definition: hexRef8.H:402
Foam::List< label >
labelIOList.H
Foam::UList< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::IOList< label >
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::hexRef8::distribute
void distribute(const mapDistributePolyMesh &)
Update local numbering for mesh redistribution.
Definition: hexRef8.C:4521
refinementHistory.H
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
DynamicList.H
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::hexRef8::checkMesh
void checkMesh() const
Debug: Check coupled mesh for correctness.
Definition: hexRef8.C:4549
p0
const volScalarField & p0
Definition: EEqn.H:36
Foam::hexRef8::faceLevel
label faceLevel(const label facei) const
Gets level such that the face has four points <= level.
Definition: hexRef8.C:799
Foam::mapDistributePolyMesh
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Definition: mapDistributePolyMesh.H:66
Foam::hexRef8::consistentUnrefinement
labelList consistentUnrefinement(const labelList &pointsToUnrefine, const bool maxSet) const
Given proposed.
Definition: hexRef8.C:5274
primitivePatch.H