From 4b9f2ae6fcc531241ffef72781a99cbbf3d8516f Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 27 May 2013 11:15:39 +0100 Subject: [PATCH] ENH: snappyHexMesh: added proximity refinement --- .../autoHexMeshDriver/autoRefineDriver.C | 404 +++++++++++++- .../autoHexMeshDriver/autoRefineDriver.H | 17 +- .../meshRefinement/meshRefinement.H | 44 ++ .../meshRefinement/meshRefinementBaffles.C | 4 +- .../meshRefinement/meshRefinementRefine.C | 502 ++++++++++++++++++ .../refinementSurfaces/refinementSurfaces.C | 176 +++++- .../refinementSurfaces/refinementSurfaces.H | 27 +- 7 files changed, 1147 insertions(+), 27 deletions(-) diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C index 75ea461102..d78866bcd7 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C @@ -46,9 +46,6 @@ defineTypeNameAndDebug(autoRefineDriver, 0); } // End namespace Foam -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Construct from components @@ -97,12 +94,14 @@ Foam::label Foam::autoRefineDriver::featureEdgeRefine ( refineParams.keepPoints()[0], // For now only use one. refineParams.curvature(), + refineParams.planarAngle(), true, // featureRefinement false, // featureDistanceRefinement false, // internalRefinement false, // surfaceRefinement false, // curvatureRefinement + false, // gapRefinement refineParams.maxGlobalCells(), refineParams.maxLocalCells() ) @@ -208,12 +207,14 @@ Foam::label Foam::autoRefineDriver::surfaceOnlyRefine ( refineParams.keepPoints()[0], refineParams.curvature(), + refineParams.planarAngle(), false, // featureRefinement false, // featureDistanceRefinement false, // internalRefinement true, // surfaceRefinement true, // curvatureRefinement + false, // gapRefinement refineParams.maxGlobalCells(), refineParams.maxLocalCells() ) @@ -294,6 +295,371 @@ Foam::label Foam::autoRefineDriver::surfaceOnlyRefine } +Foam::label Foam::autoRefineDriver::gapOnlyRefine +( + const refinementParameters& refineParams, + const label maxIter +) +{ + const fvMesh& mesh = meshRefiner_.mesh(); + + // Determine the maximum refinement level over all surfaces. This + // determines the minumum number of surface refinement iterations. + + label maxIncrement = 0; + const labelList& maxLevel = meshRefiner_.surfaces().maxLevel(); + const labelList& gapLevel = meshRefiner_.surfaces().gapLevel(); + + forAll(maxLevel, i) + { + maxIncrement = max(maxIncrement, gapLevel[i]-maxLevel[i]); + } + + label iter = 0; + + if (maxIncrement == 0) + { + return iter; + } + + for (iter = 0; iter < maxIter; iter++) + { + Info<< nl + << "Gap refinement iteration " << iter << nl + << "--------------------------" << nl + << endl; + + + // Determine cells to refine + // ~~~~~~~~~~~~~~~~~~~~~~~~~ + // Only look at surface intersections (minLevel and surface curvature), + // do not do internal refinement (refinementShells) + + labelList candidateCells + ( + meshRefiner_.refineCandidates + ( + refineParams.keepPoints()[0], + refineParams.curvature(), + refineParams.planarAngle(), + + false, // featureRefinement + false, // featureDistanceRefinement + false, // internalRefinement + false, // surfaceRefinement + false, // curvatureRefinement + true, // gapRefinement + refineParams.maxGlobalCells(), + refineParams.maxLocalCells() + ) + ); + + if (debug&meshRefinement::MESH) + { + Pout<< "Dumping " << candidateCells.size() + << " cells to cellSet candidateCellsFromGap." << endl; + cellSet c(mesh, "candidateCellsFromGap", candidateCells); + c.instance() = meshRefiner_.timeName(); + c.write(); + } + + // Grow by one layer to make sure we're covering the gap + { + boolList isCandidateCell(mesh.nCells(), false); + forAll(candidateCells, i) + { + isCandidateCell[candidateCells[i]] = true; + } + + for (label i=0; i<1; i++) + { + boolList newIsCandidateCell(isCandidateCell); + + // Internal faces + for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++) + { + label own = mesh.faceOwner()[faceI]; + label nei = mesh.faceNeighbour()[faceI]; + + if (isCandidateCell[own] != isCandidateCell[nei]) + { + newIsCandidateCell[own] = true; + newIsCandidateCell[nei] = true; + } + } + + // Get coupled boundary condition values + boolList neiIsCandidateCell; + syncTools::swapBoundaryCellList + ( + mesh, + isCandidateCell, + neiIsCandidateCell + ); + + // Boundary faces + for + ( + label faceI = mesh.nInternalFaces(); + faceI < mesh.nFaces(); + faceI++ + ) + { + label own = mesh.faceOwner()[faceI]; + label bFaceI = faceI-mesh.nInternalFaces(); + + if (isCandidateCell[own] != neiIsCandidateCell[bFaceI]) + { + newIsCandidateCell[own] = true; + } + } + + isCandidateCell.transfer(newIsCandidateCell); + } + + label n = 0; + forAll(isCandidateCell, cellI) + { + if (isCandidateCell[cellI]) + { + n++; + } + } + candidateCells.setSize(n); + n = 0; + forAll(isCandidateCell, cellI) + { + if (isCandidateCell[cellI]) + { + candidateCells[n++] = cellI; + } + } + } + + + if (debug&meshRefinement::MESH) + { + Pout<< "Dumping " << candidateCells.size() + << " cells to cellSet candidateCellsFromGapPlusBuffer." << endl; + cellSet c(mesh, "candidateCellsFromGapPlusBuffer", candidateCells); + c.instance() = meshRefiner_.timeName(); + c.write(); + } + + + 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