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