hexRef8.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-2026 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::hexRef8
26 
27 Description
28  Refinement of (split) hexes using polyTopoChange.
29 
30 SourceFiles
31  hexRef8.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef hexRef8_H
36 #define hexRef8_H
37 
38 #include "DemandDrivenMeshObject.H"
39 #include "labelIOList.H"
40 #include "face.H"
41 #include "HashSet.H"
42 #include "DynamicList.H"
43 #include "primitivePatch.H"
44 #include "removeFaces.H"
45 #include "refinementHistory.H"
46 #include "PackedBoolList.H"
48 #include "cellShapeList.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward declaration of classes
56 class polyMesh;
57 class polyPatch;
58 class polyTopoChange;
59 class polyTopoChangeMap;
60 class polyDistributionMap;
61 
62 /*---------------------------------------------------------------------------*\
63  Class hexRef8 Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class hexRef8
67 :
69  <
70  polyMesh,
71  PermanentMeshObject,
72  hexRef8
73  >
74 {
75  // Private Data
76 
77  //- Reference to underlying mesh.
78  const polyMesh& mesh_;
79 
80  //- Per cell the refinement level
81  labelIOList cellLevel_;
82 
83  //- Per point the refinement level
84  labelIOList pointLevel_;
85 
86  //- Typical edge length between unrefined points
87  localUniformDimensionedScalarField level0Edge_;
88 
89  //- Refinement history
90  refinementHistory history_;
91 
92  //- Face remover engine
93  removeFaces faceRemover_;
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 index
111  label getPatchIndex(const label facei) const;
112 
113  //- Adds a face on top of existing facei. Reverses if necessary.
114  label addFace
115  (
116  polyTopoChange& meshMod,
117  const label facei,
118  const face& newFace,
119  const label own,
120  const label nei
121  ) const;
122 
123  //- Adds internal face from point. No checks on reversal.
124  // Adds an internal face from an edge. Assumes orientation correct.
125  // Problem is that the face is between four new vertices. So what do
126  // we provide as master? The only existing mesh item we have is the
127  // edge we have split. Have to be careful in only using it if it has
128  // internal faces since otherwise polyMeshMorph will complain (because
129  // it cannot generate a sensible mapping for the face)
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 modifyFace
143  (
144  polyTopoChange& meshMod,
145  const label facei,
146  const face& newFace,
147  const label own,
148  const label nei
149  ) const;
150 
151  //- Bit complex way to determine the unrefined edge length.
152  scalar getLevel0EdgeLength() const;
153 
154  //- Get cell added to point of celli (if any)
155  // Check whether pointi is an anchor on celli. If it is not check
156  // whether any other point on the face is an anchor cell.
157  label getAnchorCell
158  (
159  const labelListList& cellAnchorPoints,
160  const labelListList& cellAddedCells,
161  const label celli,
162  const label facei,
163  const label pointi
164  ) const;
165 
166  //- Get new owner and neighbour (in unspecified order) of pointi
167  // on facei.
168  void getFaceNeighbours
169  (
170  const labelListList& cellAnchorPoints,
171  const labelListList& cellAddedCells,
172  const label facei,
173  const label pointi,
174 
175  label& own,
176  label& nei
177  ) const;
178 
179 
180  //- Get index of minimum pointlevel.
181  label findMinLevel(const labelList& f) const;
182 
183  //- Get maximum pointlevel.
184  label findMaxLevel(const labelList& f) const;
185 
186  //- Count number of vertices <= anchorLevel
187  label countAnchors(const labelList&, const label) const;
188 
189  //- Debugging: dump cell as .obj file
190  void dumpCell(const label celli) const;
191 
192  //- Find index of point with wantedLevel, starting from fp.
193  label findLevel
194  (
195  const label facei,
196  const face& f,
197  const label startFp,
198  const bool searchForward,
199  const label wantedLevel
200  ) const;
201 
202  //- debug:check orientation of added internal face
203  static void checkInternalOrientation
204  (
205  polyTopoChange& meshMod,
206  const label celli,
207  const label facei,
208  const point& ownPt,
209  const point& neiPt,
210  const face& newFace
211  );
212 
213  //- debug:check orientation of new boundary face
214  static void checkBoundaryOrientation
215  (
216  polyTopoChange& meshMod,
217  const label celli,
218  const label facei,
219  const point& ownPt,
220  const point& boundaryPt,
221  const face& newFace
222  );
223 
224  //- If p0 and p1 are existing vertices check if edge is split and insert
225  // splitPoint.
226  void insertEdgeSplit
227  (
228  const labelList& edgeMidPoint,
229  const label p0,
230  const label p1,
231  DynamicList<label>& verts
232  ) const;
233 
234  //- Store in maps correspondence from midpoint to anchors and faces.
235  // Internal faces are one per edge between anchor points. So one per
236  // midPoint between the anchor points. Here we store the information on
237  // the midPoint and if we have enough information:
238  // - two anchors
239  // - two face mid points
240  // we add the face. Note that this routine can get called anywhere from
241  // two times (two unrefined faces) to four times (two refined faces) so
242  // the first call that adds the information creates the face.
243  label storeMidPointInfo
244  (
245  const labelListList& cellAnchorPoints,
246  const labelListList& cellAddedCells,
247  const labelList& cellMidPoint,
248  const labelList& edgeMidPoint,
249  const label celli,
250  const label facei,
251  const bool faceOrder,
252  const label midPointi,
253  const label anchorPointi,
254  const label faceMidPointi,
255 
256  Map<edge>& midPointToAnchors,
257  Map<edge>& midPointToFaceMids,
258  polyTopoChange& meshMod
259  ) const;
260 
261  //- Create all internal faces from an unsplit face.
262  void createInternalFromSplitFace
263  (
264  const labelListList& cellAnchorPoints,
265  const labelListList& cellAddedCells,
266  const labelList& cellMidPoint,
267  const labelList& faceMidPoint,
268  const labelList& edgeMidPoint,
269  const label celli,
270  const label facei,
271 
272  Map<edge>& midPointToAnchors,
273  Map<edge>& midPointToFaceMids,
274  polyTopoChange& meshMod,
275  label& nFacesAdded
276  ) const;
277 
278  //- Create all internal faces to split celli into 8.
279  void createInternalFaces
280  (
281  const labelListList& cellAnchorPoints,
282  const labelListList& cellAddedCells,
283  const labelList& cellMidPoint,
284  const labelList& faceMidPoint,
285  const labelList& faceAnchorLevel,
286  const labelList& edgeMidPoint,
287  const label celli,
288  polyTopoChange& meshMod
289  ) const;
290 
291  //- Store vertices from startFp up to face split point.
292  // Used when splitting face into 4.
293  void walkFaceToMid
294  (
295  const labelList& edgeMidPoint,
296  const label cLevel,
297  const label facei,
298  const label startFp,
299  DynamicList<label>& faceVerts
300  ) const;
301 
302  //- Same as walkFaceToMid but now walk back.
303  void walkFaceFromMid
304  (
305  const labelList& edgeMidPoint,
306  const label cLevel,
307  const label facei,
308  const label startFp,
309  DynamicList<label>& faceVerts
310  ) const;
311 
312  //- Updates refineCell so consistent 2:1 refinement. Returns local
313  // number of cells changed.
314  label faceConsistentRefinement
315  (
316  const bool maxSet,
318  ) const;
319 
320  //- Check wanted refinement for 2:1 consistency
321  void checkWantedRefinementLevels(const labelList&) const;
322 
323 
324  // Cellshape recognition
325 
326  //- Collect all points on face of certain level
327  void collectLevelPoints
328  (
329  const labelList& f,
330  const label level,
332  ) const;
333 
334  //- Collect all points on face (in local numbering) of certain level
335  void collectLevelPoints
336  (
337  const labelList& meshPoints,
338  const labelList& f,
339  const label level,
341  ) const;
342 
343  //- Collect all faces with four corner points and return true if
344  // hex was matched (6 faces of each four corner points)
345  bool matchHexShape
346  (
347  const label celli,
348  const label cellLevel,
349  DynamicList<face>& quads
350  ) const;
351 
352 
353 public:
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  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,
373  const refinementHistory& history,
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  //- Disallow default bitwise copy construction
388  hexRef8(const hexRef8&) = delete;
389 
390 
391  // Member Functions
392 
393  // Access
394 
395  const polyMesh& mesh() const
396  {
397  return mesh_;
398  }
399 
400  const labelIOList& cellLevel() const
401  {
402  return cellLevel_;
403  }
404 
405  const labelIOList& pointLevel() const
406  {
407  return pointLevel_;
408  }
409 
410  const refinementHistory& history() const
411  {
412  return history_;
413  }
414 
415  //- Typical edge length between unrefined points
416  scalar level0EdgeLength() const
417  {
418  return level0Edge_.value();
419  }
420 
421  // Refinement
422 
423  //- Gets level such that the face has four points <= level.
424  label faceLevel(const label facei) const;
425 
426  //- Given valid mesh and current cell level and proposed
427  // cells to refine calculate any clashes (due to 2:1) and return
428  // ok list of cells to refine.
429  // Either adds cells to refine to set (maxSet = true) or
430  // removes cells to refine (maxSet = false)
432  (
433  const labelList& cellsToRefine,
434  const bool maxSet
435  ) const;
436 
437  //- Like consistentRefinement but slower:
438  //
439  // - specify number of cells between consecutive refinement levels
440  // (consistentRefinement equivalent to 1)
441  // - specify max level difference between point-connected cells.
442  // (-1 to disable) Note that with normal 2:1 limitation
443  // (maxFaceDiff=1) there can be 8:1 size difference across point
444  // connected cells so maxPointDiff allows you to make that less.
445  // cellsToRefine : cells we're thinking about refining. It will
446  // extend this set. All refinement levels will be
447  // at least maxFaceDiff layers thick.
448  // facesToCheck : additional faces where to implement the
449  // maxFaceDiff thickness (usually only boundary
450  // faces)
452  (
453  const label maxFaceDiff,
454  const labelList& cellsToRefine,
455  const labelList& facesToCheck,
456  const label maxPointDiff,
457  const labelList& pointsToCheck
458  ) const;
459 
460  //- Like consistentSlowRefinement but uses different meshWave
461  // (proper distance instead of topological count). No point checks
462  // yet.
464  (
465  const label maxFaceDiff,
466  const labelList& cellsToRefine,
467  const labelList& facesToCheck
468  ) const;
469 
470  //- Insert refinement. All selected cells will be split into 8.
471  // Returns per element in cells the 8 cells they were split into.
472  // Guarantees that the 0th element is the original cell label.
473  // Mapping:
474  // -split cells: 7 new ones get added from original
475  // -split faces: original gets modified; 3 new ones get added
476  // from original
477  // -added internal faces: added from original cell face(if
478  // that was internal) or created out-of-nothing (so will not
479  // get mapped!).
480  // -points added to split edge: added from edge start()
481  // -midpoints added: added from cellPoints[0].
483  (
484  const labelList& cells,
486  );
487 
488  //- Update local numbering for changed mesh.
489  // Called after the mesh change. setRefinement will already have
490  // made sure the pointLevel_ and cellLevel_ are the size of the new
491  // mesh so we only need to account for reordering.
492  virtual void topoChange(const polyTopoChangeMap&);
493 
494  //- Update local numbering for subsetted mesh.
495  // Gets new-to-old maps. Not compatible with unrefinement.
496  void subset
497  (
498  const labelList& pointMap,
499  const labelList& faceMap,
500  const labelList& cellMap
501  );
502 
503  //- Correct weighting factors for moving mesh.
504  virtual bool movePoints();
505 
506  //- Update from another mesh using the given map
507  virtual void mapMesh(const polyMeshMap&);
508 
509  //- Update local numbering for mesh redistribution
510  virtual void distribute(const polyDistributionMap&);
511 
512  //- Reordered/removed trailing patches.
513  // If validBoundary call is parallel
514  // synced and all add the same patch with same settings
515  virtual void reorderPatches
516  (
517  const labelUList& newToOld,
518  const bool validBoundary
519  );
520 
521  //- Inserted patch at patchi
522  virtual void addPatch(const label patchi);
523 
524  //- Reset
525  // hexRef8 update must be handled explicitly
526  virtual void reset();
527 
528  //- Clear
529  virtual void clear();
530 
531  //- Debug: Check coupled mesh for correctness
532  void checkMesh() const;
533 
534  //- Debug: Check 2:1 consistency across faces.
535  // maxPointDiff==-1 : only check 2:1 across faces
536  // maxPointDiff!=-1 : check point-connected cells.
538  (
539  const label maxPointDiff,
540  const labelList& pointsToCheck
541  ) const;
542 
543  //- Utility: get hexes as cell shapes
544  const cellShapeList& cellShapes() const;
545 
546 
547  // Unrefinement (undoing refinement, not arbitrary coarsening)
548 
549  //- Return the points at the centre of top-level split cells
550  // that can be unsplit.
551  labelList getSplitPoints() const;
552 
553  //- Given proposed
554  // splitPoints to unrefine according to calculate any clashes
555  // (due to 2:1) and return ok list of points to unrefine.
556  // Either adds points to refine to set (maxSet = true) or
557  // removes points to refine (maxSet = false)
559  (
560  const labelList& pointsToUnrefine,
561  const bool maxSet
562  ) const;
563 
564  //- Remove some refinement. Needs to be supplied output of
565  // consistentUnrefinement. Only call if undoable set.
566  // All 8 pointCells of a split point will be combined into
567  // the lowest numbered cell of those 8.
568  void setUnrefinement
569  (
570  const labelList& splitPointLabels,
572  );
573 
574  // Write
575 
576  // Set instance for mesh files
577  void setInstance(const fileName& inst);
578 
579  //- Write using given format, version and compression
580  virtual bool writeObject
581  (
585  const bool write = true
586  ) const;
587 
588 
589  // Member Operators
590 
591  //- Disallow default bitwise assignment
592  void operator=(const hexRef8&) = delete;
593 };
594 
595 
596 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
597 
598 } // End namespace Foam
599 
600 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
601 
602 #endif
603 
604 // ************************************************************************* //
Templated abstract base-class for demand-driven mesh objects used to automate their allocation to the...
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
A HashTable to objects of type <T> with a label key.
Definition: Map.H:52
A bit-packed bool list.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
A class for handling file names.
Definition: fileName.H:82
Refinement of (split) hexes using polyTopoChange.
Definition: hexRef8.H:73
void checkRefinementLevels(const label maxPointDiff, const labelList &pointsToCheck) const
Debug: Check 2:1 consistency across faces.
Definition: hexRef8.C:4570
virtual bool movePoints()
Correct weighting factors for moving mesh.
Definition: hexRef8.C:4294
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:2200
hexRef8(const polyMesh &mesh, const bool readHistory=true)
Construct from mesh, read_if_present refinement data.
Definition: hexRef8.C:1789
void checkMesh() const
Debug: Check coupled mesh for correctness.
Definition: hexRef8.C:4360
scalar level0EdgeLength() const
Typical edge length between unrefined points.
Definition: hexRef8.H:415
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write=true) const
Write using given format, version and compression.
Definition: hexRef8.C:5447
labelListList setRefinement(const labelList &cells, polyTopoChange &)
Insert refinement. All selected cells will be split into 8.
Definition: hexRef8.C:3106
virtual void topoChange(const polyTopoChangeMap &)
Update local numbering for changed mesh.
Definition: hexRef8.C:4100
virtual void distribute(const polyDistributionMap &)
Update local numbering for mesh redistribution.
Definition: hexRef8.C:4309
void operator=(const hexRef8 &)=delete
Disallow default bitwise assignment.
const cellShapeList & cellShapes() const
Utility: get hexes as cell shapes.
Definition: hexRef8.C:4822
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: hexRef8.C:4300
void setUnrefinement(const labelList &splitPointLabels, polyTopoChange &)
Remove some refinement. Needs to be supplied output of.
Definition: hexRef8.C:5258
const refinementHistory & history() const
Definition: hexRef8.H:409
const labelIOList & cellLevel() const
Definition: hexRef8.H:399
const labelIOList & pointLevel() const
Definition: hexRef8.H:404
virtual void addPatch(const label patchi)
Inserted patch at patchi.
Definition: hexRef8.C:4346
labelList consistentUnrefinement(const labelList &pointsToUnrefine, const bool maxSet) const
Given proposed.
Definition: hexRef8.C:5024
labelList getSplitPoints() const
Return the points at the centre of top-level split cells.
Definition: hexRef8.C:4882
label faceLevel(const label facei) const
Gets level such that the face has four points <= level.
Definition: hexRef8.C:675
virtual void clear()
Clear.
Definition: hexRef8.C:4356
virtual void reset()
Reset.
Definition: hexRef8.C:4350
virtual void reorderPatches(const labelUList &newToOld, const bool validBoundary)
Reordered/removed trailing patches.
Definition: hexRef8.C:4339
labelList consistentRefinement(const labelList &cellsToRefine, const bool maxSet) const
Given valid mesh and current cell level and proposed.
Definition: hexRef8.C:2131
const polyMesh & mesh() const
Definition: hexRef8.H:394
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:2684
void subset(const labelList &pointMap, const labelList &faceMap, const labelList &cellMap)
Update local numbering for subsetted mesh.
Definition: hexRef8.C:4212
void setInstance(const fileName &inst)
Definition: hexRef8.C:1595
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Direct mesh changes based on v1.3 polyTopoChange syntax.
Container with cells to refine. Refinement given as single direction.
Definition: refineCell.H:57
All refinement history. Used in unrefinement.
virtual bool write(const bool write=true) const
Write using setting from DB.
Given list of faces to remove insert all the topology changes. Contains helper function to get consis...
Definition: removeFaces.H:63
label patchi
const pointField & points
const cellShapeList & cells
Typedefs for LocalUniformDimensionedField.
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
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
labelList f(nPoints)