00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef meshRefinement_H
00044 #define meshRefinement_H
00045
00046 #include <dynamicMesh/hexRef8.H>
00047 #include <OpenFOAM/mapPolyMesh.H>
00048 #include <OpenFOAM/autoPtr.H>
00049 #include <OpenFOAM/labelPair.H>
00050 #include <OpenFOAM/indirectPrimitivePatch.H>
00051 #include <OpenFOAM/pointFieldsFwd.H>
00052 #include <OpenFOAM/Tuple2.H>
00053 #include <meshTools/pointIndexHit.H>
00054
00055
00056
00057 namespace Foam
00058 {
00059
00060
00061 class fvMesh;
00062 class mapDistributePolyMesh;
00063 class decompositionMethod;
00064 class refinementSurfaces;
00065 class shellSurfaces;
00066 class removeCells;
00067 class featureEdgeMesh;
00068 class fvMeshDistribute;
00069 class searchableSurface;
00070 class regionSplit;
00071 class globalIndex;
00072
00073
00074
00075
00076
00077 class meshRefinement
00078 {
00079
00080 public:
00081
00082
00083
00084
00085 enum writeFlag
00086 {
00087 MESH = 1,
00088 SCALARLEVELS = 2,
00089 OBJINTERSECTIONS = 4
00090 };
00091
00092
00093
00094 enum mapType
00095 {
00096 MASTERONLY = 1,
00097 KEEPALL = 2,
00098 REMOVE = 4
00099 };
00100
00101
00102 private:
00103
00104
00105
00106
00107 fvMesh& mesh_;
00108
00109
00110 const scalar mergeDistance_;
00111
00112
00113 const bool overwrite_;
00114
00115
00116 const word oldInstance_;
00117
00118
00119 const refinementSurfaces& surfaces_;
00120
00121
00122 const shellSurfaces& shells_;
00123
00124
00125 hexRef8 meshCutter_;
00126
00127
00128 labelIOList surfaceIndex_;
00129
00130
00131 List<Tuple2<mapType, labelList> > userFaceData_;
00132
00133
00134
00135 wordList meshedPatches_;
00136
00137
00138
00139
00140
00141 template<class T>
00142 static void updateList
00143 (
00144 const labelList& newToOld,
00145 const T& nullValue,
00146 List<T>& elems
00147 );
00148
00149
00150 template<class GeoField>
00151 static void addPatchFields(fvMesh&, const word& patchFieldType);
00152
00153
00154 template<class GeoField>
00155 static void reorderPatchFields(fvMesh&, const labelList& oldToNew);
00156
00157
00158
00159 static labelList getChangedFaces
00160 (
00161 const mapPolyMesh&,
00162 const labelList& oldCellsToRefine
00163 );
00164
00165
00166 void calcNeighbourData
00167 (
00168 labelList& neiLevel,
00169 pointField& neiCc
00170 ) const;
00171
00172
00173 void updateIntersections(const labelList& changedFaces);
00174
00175
00176 autoPtr<mapPolyMesh> doRemoveCells
00177 (
00178 const labelList& cellsToRemove,
00179 const labelList& exposedFaces,
00180 const labelList& exposedPatchIDs,
00181 removeCells& cellRemover
00182 );
00183
00184
00185
00186
00187 labelList getInsideCells(const word&) const;
00188
00189
00190 autoPtr<mapPolyMesh> removeInsideCells
00191 (
00192 const string& msg,
00193 const label exposedPatchI
00194 );
00195
00196
00197
00198
00199
00200
00201 void getCoupledRegionMaster
00202 (
00203 const globalIndex& globalCells,
00204 const boolList& blockedFace,
00205 const regionSplit& globalRegion,
00206 Map<label>& regionToMaster
00207 ) const;
00208
00209
00210
00211 void calcLocalRegions
00212 (
00213 const globalIndex& globalCells,
00214 const labelList& globalRegion,
00215 const Map<label>& coupledRegionToMaster,
00216 const scalarField& cellWeights,
00217
00218 Map<label>& globalToLocalRegion,
00219 pointField& localPoints,
00220 scalarField& localWeights
00221 ) const;
00222
00223
00224 static label getShiftedRegion
00225 (
00226 const globalIndex& indexer,
00227 const Map<label>& globalToLocalRegion,
00228 const Map<label>& coupledRegionToShifted,
00229 const label globalRegion
00230 );
00231
00232
00233 static void addUnique(const label, labelList&);
00234
00235
00236 void calcRegionRegions
00237 (
00238 const labelList& globalRegion,
00239 const Map<label>& globalToLocalRegion,
00240 const Map<label>& coupledRegionToMaster,
00241 labelListList& regionRegions
00242 ) const;
00243
00244
00245
00246
00247
00248
00249
00250 static bool markForRefine
00251 (
00252 const label markValue,
00253 const label nAllowRefine,
00254 label& cellValue,
00255 label& nRefine
00256 );
00257
00258
00259
00260 label markFeatureRefinement
00261 (
00262 const point& keepPoint,
00263 const PtrList<featureEdgeMesh>& featureMeshes,
00264 const labelList& featureLevels,
00265 const label nAllowRefine,
00266
00267 labelList& refineCell,
00268 label& nRefine
00269 ) const;
00270
00271
00272 label markInternalRefinement
00273 (
00274 const label nAllowRefine,
00275 labelList& refineCell,
00276 label& nRefine
00277 ) const;
00278
00279
00280
00281 labelList getRefineCandidateFaces
00282 (
00283 const labelList& refineCell
00284 ) const;
00285
00286
00287 label markSurfaceRefinement
00288 (
00289 const label nAllowRefine,
00290 const labelList& neiLevel,
00291 const pointField& neiCc,
00292 labelList& refineCell,
00293 label& nRefine
00294 ) const;
00295
00296
00297
00298
00299 bool checkCurvature
00300 (
00301 const scalar curvature,
00302 const label nAllowRefine,
00303 const label surfaceLevel,
00304 const vector& surfaceNormal,
00305 const label cellI,
00306 label& cellMaxLevel,
00307 vector& cellMaxNormal,
00308 labelList& refineCell,
00309 label& nRefine
00310 ) const;
00311
00312
00313
00314
00315
00316 label markSurfaceCurvatureRefinement
00317 (
00318 const scalar curvature,
00319 const label nAllowRefine,
00320 const labelList& neiLevel,
00321 const pointField& neiCc,
00322 labelList& refineCell,
00323 label& nRefine
00324 ) const;
00325
00326
00327
00328
00329 void getBafflePatches
00330 (
00331 const labelList& globalToPatch,
00332 const labelList& neiLevel,
00333 const pointField& neiCc,
00334 labelList& ownPatch,
00335 labelList& neiPatch
00336 ) const;
00337
00338
00339
00340 label getBafflePatch
00341 (
00342 const labelList& facePatch,
00343 const label faceI
00344 ) const;
00345
00346
00347
00348
00349 label createBaffle
00350 (
00351 const label faceI,
00352 const label ownPatch,
00353 const label neiPatch,
00354 polyTopoChange& meshMod
00355 ) const;
00356
00357
00358
00359
00360
00361 void markBoundaryFace
00362 (
00363 const label faceI,
00364 boolList& isBoundaryFace,
00365 boolList& isBoundaryEdge,
00366 boolList& isBoundaryPoint
00367 ) const;
00368
00369 void findNearest
00370 (
00371 const labelList& meshFaces,
00372 List<pointIndexHit>& nearestInfo,
00373 labelList& nearestSurface,
00374 labelList& nearestRegion,
00375 vectorField& nearestNormal
00376 ) const;
00377
00378 Map<label> findEdgeConnectedProblemCells
00379 (
00380 const scalarField& perpendicularAngle,
00381 const labelList&
00382 ) const;
00383
00384 bool isCollapsedFace
00385 (
00386 const pointField&,
00387 const pointField& neiCc,
00388 const scalar minFaceArea,
00389 const scalar maxNonOrtho,
00390 const label faceI
00391 ) const;
00392
00393 bool isCollapsedCell
00394 (
00395 const pointField&,
00396 const scalar volFraction,
00397 const label cellI
00398 ) const;
00399
00400
00401
00402
00403 labelList markFacesOnProblemCells
00404 (
00405 const dictionary& motionDict,
00406 const bool removeEdgeConnectedCells,
00407 const scalarField& perpendicularAngle,
00408 const labelList& globalToPatch
00409 ) const;
00410
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422 List<labelPair> filterDuplicateFaces(const List<labelPair>&) const;
00423
00424
00425
00426
00427
00428
00429
00430
00431 void findCellZoneGeometric
00432 (
00433 const labelList& closedNamedSurfaces,
00434 labelList& namedSurfaceIndex,
00435 const labelList& surfaceToCellZone,
00436 labelList& cellToZone
00437 ) const;
00438
00439
00440 bool calcRegionToZone
00441 (
00442 const label surfZoneI,
00443 const label ownRegion,
00444 const label neiRegion,
00445
00446 labelList& regionToCellZone
00447 ) const;
00448
00449
00450
00451 void findCellZoneTopo
00452 (
00453 const point& keepPoint,
00454 const labelList& namedSurfaceIndex,
00455 const labelList& surfaceToCellZone,
00456 labelList& cellToZone
00457 ) const;
00458
00459 void makeConsistentFaceIndex
00460 (
00461 const labelList& cellToZone,
00462 labelList& namedSurfaceIndex
00463 ) const;
00464
00465
00466
00467 meshRefinement(const meshRefinement&);
00468
00469
00470 void operator=(const meshRefinement&);
00471
00472 public:
00473
00474
00475 ClassName("meshRefinement");
00476
00477
00478
00479
00480
00481 meshRefinement
00482 (
00483 fvMesh& mesh,
00484 const scalar mergeDistance,
00485 const bool overwrite,
00486 const refinementSurfaces&,
00487 const shellSurfaces&
00488 );
00489
00490
00491
00492
00493
00494
00495
00496 const fvMesh& mesh() const
00497 {
00498 return mesh_;
00499 }
00500 fvMesh& mesh()
00501 {
00502 return mesh_;
00503 }
00504
00505 scalar mergeDistance() const
00506 {
00507 return mergeDistance_;
00508 }
00509
00510
00511 bool overwrite() const
00512 {
00513 return overwrite_;
00514 }
00515
00516
00517 const word& oldInstance() const
00518 {
00519 return oldInstance_;
00520 }
00521
00522
00523 const refinementSurfaces& surfaces() const
00524 {
00525 return surfaces_;
00526 }
00527
00528
00529 const shellSurfaces& shells() const
00530 {
00531 return shells_;
00532 }
00533
00534
00535 const hexRef8& meshCutter() const
00536 {
00537 return meshCutter_;
00538 }
00539
00540
00541 const labelList& surfaceIndex() const
00542 {
00543 return surfaceIndex_;
00544 }
00545
00546 labelList& surfaceIndex()
00547 {
00548 return surfaceIndex_;
00549 }
00550
00551
00552
00553
00554
00555 const List<Tuple2<mapType, labelList> >& userFaceData() const
00556 {
00557 return userFaceData_;
00558 }
00559
00560 List<Tuple2<mapType, labelList> >& userFaceData()
00561 {
00562 return userFaceData_;
00563 }
00564
00565
00566
00567
00568
00569 label countHits() const;
00570
00571
00572
00573
00574
00575
00576 labelList decomposeCombineRegions
00577 (
00578 const scalarField& cellWeights,
00579 const boolList& blockedFace,
00580 const List<labelPair>& explicitConnections,
00581 decompositionMethod&
00582 ) const;
00583
00584
00585
00586
00587
00588 autoPtr<mapDistributePolyMesh> balance
00589 (
00590 const bool keepZoneFaces,
00591 const bool keepBaffles,
00592 const scalarField& cellWeights,
00593 decompositionMethod& decomposer,
00594 fvMeshDistribute& distributor
00595 );
00596
00597
00598 labelList intersectedFaces() const;
00599
00600
00601 labelList intersectedPoints() const;
00602
00603
00604 static autoPtr<indirectPrimitivePatch> makePatch
00605 (
00606 const polyMesh&,
00607 const labelList&
00608 );
00609
00610
00611
00612
00613
00614
00615
00616 static tmp<pointVectorField> makeDisplacementField
00617 (
00618 const pointMesh& pMesh,
00619 const labelList& adaptPatchIDs
00620 );
00621
00622
00623 static void checkCoupledFaceZones(const polyMesh&);
00624
00625
00626
00627
00628
00629 labelList refineCandidates
00630 (
00631 const point& keepPoint,
00632 const scalar curvature,
00633
00634 const PtrList<featureEdgeMesh>& featureMeshes,
00635 const labelList& featureLevels,
00636
00637 const bool featureRefinement,
00638 const bool internalRefinement,
00639 const bool surfaceRefinement,
00640 const bool curvatureRefinement,
00641 const label maxGlobalCells,
00642 const label maxLocalCells
00643 ) const;
00644
00645
00646 autoPtr<mapPolyMesh> refine(const labelList& cellsToRefine);
00647
00648
00649 autoPtr<mapDistributePolyMesh> refineAndBalance
00650 (
00651 const string& msg,
00652 decompositionMethod& decomposer,
00653 fvMeshDistribute& distributor,
00654 const labelList& cellsToRefine,
00655 const scalar maxLoadUnbalance
00656 );
00657
00658
00659 autoPtr<mapDistributePolyMesh> balanceAndRefine
00660 (
00661 const string& msg,
00662 decompositionMethod& decomposer,
00663 fvMeshDistribute& distributor,
00664 const labelList& cellsToRefine,
00665 const scalar maxLoadUnbalance
00666 );
00667
00668
00669
00670
00671
00672 void baffleAndSplitMesh
00673 (
00674 const bool handleSnapProblems,
00675 const bool removeEdgeConnectedCells,
00676 const scalarField& perpendicularAngle,
00677 const bool mergeFreeStanding,
00678 const dictionary& motionDict,
00679 Time& runTime,
00680 const labelList& globalToPatch,
00681 const point& keepPoint
00682 );
00683
00684
00685
00686 autoPtr<mapPolyMesh> splitMesh
00687 (
00688 const label nBufferLayers,
00689 const labelList& globalToPatch,
00690 const point& keepPoint
00691 );
00692
00693
00694
00695 autoPtr<mapPolyMesh> dupNonManifoldPoints();
00696
00697
00698
00699
00700 autoPtr<mapPolyMesh> createBaffles
00701 (
00702 const labelList& ownPatch,
00703 const labelList& neiPatch
00704 );
00705
00706
00707
00708 List<labelPair> getDuplicateFaces(const labelList& testFaces) const;
00709
00710
00711 autoPtr<mapPolyMesh> mergeBaffles(const List<labelPair>&);
00712
00713
00714
00715
00716 autoPtr<mapPolyMesh> zonify
00717 (
00718 const point& keepPoint,
00719 const bool allowFreeStandingZoneFaces
00720 );
00721
00722
00723
00724
00725
00726
00727 static label addPatch(fvMesh&, const word& name, const word& type);
00728
00729
00730 label addMeshedPatch(const word& name, const word& type);
00731
00732
00733 labelList meshedPatches() const;
00734
00735
00736 autoPtr<mapPolyMesh> splitMeshRegions(const point& keepPoint);
00737
00738
00739 void distribute(const mapDistributePolyMesh&);
00740
00741
00742
00743 void updateMesh
00744 (
00745 const mapPolyMesh&,
00746 const labelList& changedFaces
00747 );
00748
00749
00750
00751
00752
00753 void storeData
00754 (
00755 const labelList& pointsToStore,
00756 const labelList& facesToStore,
00757 const labelList& cellsToStore
00758 );
00759
00760
00761
00762
00763 void updateMesh
00764 (
00765 const mapPolyMesh&,
00766 const labelList& changedFaces,
00767 const Map<label>& pointsToRestore,
00768 const Map<label>& facesToRestore,
00769 const Map<label>& cellsToRestore
00770 );
00771
00772
00773
00774
00775 label mergePatchFaces
00776 (
00777 const scalar minCos,
00778 const scalar concaveCos,
00779 const labelList& patchIDs
00780 );
00781
00782
00783
00784 autoPtr<mapPolyMesh> mergeEdges(const scalar minCos);
00785
00786
00787
00788
00789
00790 void checkData();
00791
00792
00793 template<class T>
00794 void testSyncBoundaryFaceList
00795 (
00796 const scalar mergeDistance,
00797 const string&,
00798 const UList<T>&,
00799 const UList<T>&
00800 ) const;
00801
00802
00803 void printMeshInfo(const bool, const string&) const;
00804
00805
00806
00807 word timeName() const;
00808
00809
00810 void setInstance(const fileName&);
00811
00812
00813 bool write() const;
00814
00815
00816 void dumpRefinementLevel() const;
00817
00818
00819 void dumpIntersections(const fileName& prefix) const;
00820
00821
00822
00823 void write(const label flag, const fileName&) const;
00824 };
00825
00826
00827
00828
00829 }
00830
00831
00832
00833 #ifdef NoRepository
00834 # include <autoMesh/meshRefinementTemplates.C>
00835 #endif
00836
00837
00838
00839 #endif
00840
00841