From 9dd6a5b00300006cf249fba309415841c04eedb9 Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 28 Oct 2015 13:28:32 +0000 Subject: [PATCH 01/12] ENH: snappyHexMesh: add automatic gap-level detection and refinement --- .../generation/snappyHexMesh/snappyHexMesh.C | 23 +- .../snappyHexMesh/snappyHexMeshDict | 15 +- .../algorithms/indexedOctree/volumeType.H | 10 +- src/mesh/autoMesh/Make/files | 1 + .../autoHexMeshDriver/autoRefineDriver.C | 283 +++ .../autoHexMeshDriver/autoRefineDriver.H | 14 + .../meshRefinement/meshRefinement.C | 53 +- .../meshRefinement/meshRefinement.H | 120 +- .../meshRefinement/meshRefinementBaffles.C | 45 +- .../meshRefinement/meshRefinementGapRefine.C | 1546 +++++++++++++++++ .../meshRefinement/meshRefinementRefine.C | 229 ++- .../refinementSurfaces/refinementSurfaces.C | 175 +- .../refinementSurfaces/refinementSurfaces.H | 36 + .../autoHexMesh/shellSurfaces/shellSurfaces.C | 409 ++++- .../autoHexMesh/shellSurfaces/shellSurfaces.H | 90 +- src/meshTools/Make/files | 2 + .../hierarchGeomDecomp/hierarchGeomDecomp.C | 11 +- 17 files changed, 2926 insertions(+), 136 deletions(-) create mode 100644 src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementGapRefine.C diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C index 67a9c3a944..7b4d8577c4 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C @@ -1075,6 +1075,26 @@ int main(int argc, char *argv[]) << mesh.time().cpuTimeIncrement() << " s" << nl << endl; + // Optionally read limit shells + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + const dictionary limitDict(refineDict.subOrEmptyDict("limitRegions")); + + if (!limitDict.empty()) + { + Info<< "Reading limit shells." << endl; + } + + shellSurfaces limitShells(allGeometry, limitDict); + + if (!limitDict.empty()) + { + Info<< "Read refinement shells in = " + << mesh.time().cpuTimeIncrement() << " s" << nl << endl; + } + + + // Read feature meshes // ~~~~~~~~~~~~~~~~~~~ @@ -1105,7 +1125,8 @@ int main(int argc, char *argv[]) overwrite, // overwrite mesh files? surfaces, // for surface intersection refinement features, // for feature edges/point based refinement - shells // for volume (inside/outside) refinement + shells, // for volume (inside/outside) refinement + limitShells // limit of volume refinement ); Info<< "Calculated surface intersections in = " << mesh.time().cpuTimeIncrement() << " s" << nl << endl; diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict index 9b759b5ca4..ea073cd9f0 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict @@ -95,10 +95,10 @@ castellatedMeshControls // actually be a lot less. maxGlobalCells 2000000; - // The surface refinement loop might spend lots of iterations refining just a - // few cells. This setting will cause refinement to stop if <= minimumRefine - // are selected for refinement. Note: it will at least do one iteration - // (unless the number of cells to refine is 0) + // The surface refinement loop might spend lots of iterations refining just + // a few cells. This setting will cause refinement to stop if + // <= minimumRefine cells are selected for refinement. Note: it will + // at least do one iteration (unless the number of cells to refine is 0) minRefinementCells 0; // Allow a certain level of imbalance during refining @@ -249,6 +249,13 @@ castellatedMeshControls //} } + + // Limit refinement in geometric region + limitRegions + { + } + + // Mesh selection // ~~~~~~~~~~~~~~ diff --git a/src/OpenFOAM/algorithms/indexedOctree/volumeType.H b/src/OpenFOAM/algorithms/indexedOctree/volumeType.H index 7bdfc043e6..3d845c414b 100644 --- a/src/OpenFOAM/algorithms/indexedOctree/volumeType.H +++ b/src/OpenFOAM/algorithms/indexedOctree/volumeType.H @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -95,6 +95,12 @@ public: t_(t) {} + //- Construct from integer + explicit volumeType(const int t) + : + t_(static_cast(t)) + {} + // Member Functions diff --git a/src/mesh/autoMesh/Make/files b/src/mesh/autoMesh/Make/files index 081d70afbd..29001bafb7 100644 --- a/src/mesh/autoMesh/Make/files +++ b/src/mesh/autoMesh/Make/files @@ -15,6 +15,7 @@ $(autoHexMesh)/meshRefinement/meshRefinement.C $(autoHexMesh)/meshRefinement/meshRefinementMerge.C $(autoHexMesh)/meshRefinement/meshRefinementProblemCells.C $(autoHexMesh)/meshRefinement/meshRefinementRefine.C +$(autoHexMesh)/meshRefinement/meshRefinementGapRefine.C $(autoHexMesh)/meshRefinement/patchFaceOrientation.C $(autoHexMesh)/refinementFeatures/refinementFeatures.C diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C index be908b76bb..e7e2217f27 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C @@ -105,7 +105,9 @@ Foam::label Foam::autoRefineDriver::featureEdgeRefine false, // internalRefinement false, // surfaceRefinement false, // curvatureRefinement + false, // smallFeatureRefinement false, // gapRefinement + false, // bigGapRefinement refineParams.maxGlobalCells(), refineParams.maxLocalCells() ) @@ -179,6 +181,127 @@ Foam::label Foam::autoRefineDriver::featureEdgeRefine } +Foam::label Foam::autoRefineDriver::smallFeatureRefine +( + const refinementParameters& refineParams, + const label maxIter +) +{ + const fvMesh& mesh = meshRefiner_.mesh(); + + + label iter = 0; + + // See if any surface has an extendedGapLevel + labelList surfaceMaxLevel(meshRefiner_.surfaces().maxGapLevel()); + labelList shellMaxLevel(meshRefiner_.shells().maxGapLevel()); + + if (max(surfaceMaxLevel) == 0 && max(shellMaxLevel) == 0) + { + return iter; + } + + for (; iter < maxIter; iter++) + { + Info<< nl + << "Small surface feature refinement iteration " << iter << nl + << "--------------------------------------------" << nl + << endl; + + + // Determine cells to refine + // ~~~~~~~~~~~~~~~~~~~~~~~~~ + + labelList candidateCells + ( + meshRefiner_.refineCandidates + ( + refineParams.locationsInMesh(), + refineParams.curvature(), + refineParams.planarAngle(), + + false, // featureRefinement + false, // featureDistanceRefinement + false, // internalRefinement + false, // surfaceRefinement + false, // curvatureRefinement + true, // smallFeatureRefinement + false, // gapRefinement + false, // bigGapRefinement + refineParams.maxGlobalCells(), + refineParams.maxLocalCells() + ) + ); + + labelList cellsToRefine + ( + meshRefiner_.meshCutter().consistentRefinement + ( + candidateCells, + true + ) + ); + Info<< "Determined cells to refine in = " + << mesh.time().cpuTimeIncrement() << " s" << endl; + + + label nCellsToRefine = cellsToRefine.size(); + reduce(nCellsToRefine, sumOp