From 357939a77052e6410c1a14688705ceead6a56486 Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 29 Oct 2012 13:20:42 +0000 Subject: [PATCH] ENH: snappyHexMesh: refine by distance to feature --- .../snappyHexMesh/snappyHexMeshDict | 13 +- .../autoHexMeshDriver/autoRefineDriver.C | 3 + .../meshRefinement/meshRefinement.H | 9 + .../meshRefinement/meshRefinementRefine.C | 119 +++++++++++- .../refinementFeatures/refinementFeatures.C | 180 +++++++++++++++++- .../refinementFeatures/refinementFeatures.H | 34 +++- 6 files changed, 336 insertions(+), 22 deletions(-) diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict index f0cc40a8e4..4bef1736f0 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict @@ -96,20 +96,29 @@ castellatedMeshControls // refinement. nCellsBetweenLevels 1; + // Explicit feature edge refinement // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Specifies a level for any cell intersected by explicitly provided // edges. // This is a featureEdgeMesh, read from constant/triSurface for now. + // Specify 'levels' in the same way as the 'distance' mode in the + // refinementRegions (see below). The old specification + // level 2; + // is equivalent to + // levels ((0 2)); + features ( //{ // file "someLine.eMesh"; - // level 2; + // //level 2; + // levels ((0.0 2) (1.0 3)); //} ); + // Surface based refinement // ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -178,7 +187,7 @@ castellatedMeshControls // three modes // - distance. 'levels' specifies per distance to the surface the // wanted refinement level. The distances need to be specified in - // descending order. + // increasing order. // - inside. 'levels' is only one entry and only the level is used. All // cells inside the surface get refined up to the level. The surface // needs to be closed for this to be possible. diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C index 985bcfd103..dfd769fd15 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C @@ -97,6 +97,7 @@ Foam::label Foam::autoRefineDriver::featureEdgeRefine refineParams.curvature(), true, // featureRefinement + false, // featureDistanceRefinement false, // internalRefinement false, // surfaceRefinement false, // curvatureRefinement @@ -207,6 +208,7 @@ Foam::label Foam::autoRefineDriver::surfaceOnlyRefine refineParams.curvature(), false, // featureRefinement + false, // featureDistanceRefinement false, // internalRefinement true, // surfaceRefinement true, // curvatureRefinement @@ -368,6 +370,7 @@ Foam::label Foam::autoRefineDriver::shellRefine refineParams.curvature(), false, // featureRefinement + true, // featureDistanceRefinement true, // internalRefinement false, // surfaceRefinement false, // curvatureRefinement diff --git a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.H b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.H index 918aae9000..b98230e412 100644 --- a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.H +++ b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.H @@ -264,6 +264,14 @@ private: label& nRefine ) const; + //- Mark cells for distance-to-feature based refinement. + label markInternalDistanceToFeatureRefinement + ( + const label nAllowRefine, + labelList& refineCell, + label& nRefine + ) const; + //- Mark cells for refinement-shells based refinement. label markInternalRefinement ( @@ -656,6 +664,7 @@ public: const scalar curvature, const bool featureRefinement, + const bool featureDistanceRefinement, const bool internalRefinement, const bool surfaceRefinement, const bool curvatureRefinement, diff --git a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementRefine.C b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementRefine.C index 4d9d10ab80..2c15a847ea 100644 --- a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementRefine.C +++ b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementRefine.C @@ -290,7 +290,7 @@ Foam::label Foam::meshRefinement::markFeatureRefinement forAll(features_, featI) { const featureEdgeMesh& featureMesh = features_[featI]; - const label featureLevel = features_.levels()[featI]; + const label featureLevel = features_.levels()[featI][0]; const labelListList& pointEdges = featureMesh.pointEdges(); // Find regions on edgeMesh @@ -511,6 +511,90 @@ Foam::label Foam::meshRefinement::markFeatureRefinement } +// Mark cells for distance-to-feature based refinement. +Foam::label Foam::meshRefinement::markInternalDistanceToFeatureRefinement +( + const label nAllowRefine, + + labelList& refineCell, + label& nRefine +) const +{ + const labelList& cellLevel = meshCutter_.cellLevel(); + const pointField& cellCentres = mesh_.cellCentres(); + + // Detect if there are any distance shells + if (features_.maxDistance() <= 0.0) + { + return 0; + } + + label oldNRefine = nRefine; + + // Collect cells to test + pointField testCc(cellLevel.size()-nRefine); + labelList testLevels(cellLevel.size()-nRefine); + label testI = 0; + + forAll(cellLevel, cellI) + { + if (refineCell[cellI] == -1) + { + testCc[testI] = cellCentres[cellI]; + testLevels[testI] = cellLevel[cellI]; + testI++; + } + } + + // Do test to see whether cells is inside/outside shell with higher level + labelList maxLevel; + features_.findHigherLevel(testCc, testLevels, maxLevel); + + // Mark for refinement. Note that we didn't store the original cellID so + // now just reloop in same order. + testI = 0; + forAll(cellLevel, cellI) + { + if (refineCell[cellI] == -1) + { + if (maxLevel[testI] > testLevels[testI]) + { + bool reachedLimit = !markForRefine + ( + maxLevel[testI], // mark with any positive value + nAllowRefine, + refineCell[cellI], + nRefine + ); + + if (reachedLimit) + { + if (debug) + { + Pout<< "Stopped refining internal cells" + << " since reaching my cell limit of " + << mesh_.nCells()+7*nRefine << endl; + } + break; + } + } + testI++; + } + } + + if + ( + returnReduce(nRefine, sumOp