From 15fed04026425aaad7ecf37306661f0de8300aef Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 3 Jun 2013 13:33:02 +0100 Subject: [PATCH] ENH: autoHexMesh: added geometric problem cell removal --- .../autoHexMeshDriver/autoRefineDriver.C | 47 ++- .../autoHexMeshDriver/autoRefineDriver.H | 5 + .../autoHexMeshDriver/autoSnapDriver.C | 315 +++++++++++++- .../autoHexMeshDriver/autoSnapDriver.H | 38 +- .../refinementParameters.C | 14 +- .../refinementParameters.H | 11 + .../meshRefinement/meshRefinement.H | 19 + .../meshRefinement/meshRefinementBaffles.C | 124 ++---- .../meshRefinementProblemCells.C | 397 +++++++++++------- .../refinementSurfaces/refinementSurfaces.C | 7 +- .../refinementSurfaces/refinementSurfaces.H | 3 +- 11 files changed, 677 insertions(+), 303 deletions(-) diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C index d78866bcd7..82bfa13522 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C @@ -35,6 +35,7 @@ License #include "shellSurfaces.H" #include "mapDistributePolyMesh.H" #include "unitConversion.H" +#include "snapParameters.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -610,9 +611,16 @@ Foam::label Foam::autoRefineDriver::danglingCellRefine << " cells (out of " << mesh.globalData().nTotalCells() << ')' << endl; - // Stop when no cells to refine. No checking of minRefineCells since - // too few cells - if (nCellsToRefine == 0) + // Stop when no cells to refine. After a few iterations check if too + // few cells + if + ( + nCellsToRefine == 0 + || ( + iter >= 1 + && nCellsToRefine <= refineParams.minRefineCells() + ) + ) { Info<< "Stopping refining since too few cells selected." << nl << endl; @@ -870,6 +878,7 @@ Foam::label Foam::autoRefineDriver::shellRefine void Foam::autoRefineDriver::baffleAndSplitMesh ( const refinementParameters& refineParams, + const snapParameters& snapParams, const bool handleSnapProblems, const dictionary& motionDict ) @@ -887,10 +896,17 @@ void Foam::autoRefineDriver::baffleAndSplitMesh meshRefiner_.baffleAndSplitMesh ( handleSnapProblems, // detect&remove potential snap problem + + // Snap problem cell detection + snapParams, + refineParams.useTopologicalSnapDetection(), false, // perpendicular edge connected cells scalarField(0), // per region perpendicular angle + + // Free standing baffles !handleSnapProblems, // merge free standing baffles? refineParams.planarAngle(), + motionDict, const_cast(mesh.time()), globalToMasterPatch_, @@ -951,6 +967,7 @@ void Foam::autoRefineDriver::zonify void Foam::autoRefineDriver::splitAndMergeBaffles ( const refinementParameters& refineParams, + const snapParameters& snapParams, const bool handleSnapProblems, const dictionary& motionDict ) @@ -973,10 +990,17 @@ void Foam::autoRefineDriver::splitAndMergeBaffles meshRefiner_.baffleAndSplitMesh ( handleSnapProblems, + + // Snap problem cell detection + snapParams, + refineParams.useTopologicalSnapDetection(), handleSnapProblems, // remove perp edge connected cells perpAngle, // perp angle + + // Free standing baffles true, // merge free standing baffles? refineParams.planarAngle(), // planar angle + motionDict, const_cast(mesh.time()), globalToMasterPatch_, @@ -1081,6 +1105,7 @@ void Foam::autoRefineDriver::doRefine ( const dictionary& refineDict, const refinementParameters& refineParams, + const snapParameters& snapParams, const bool prepareForSnapping, const dictionary& motionDict ) @@ -1146,13 +1171,25 @@ void Foam::autoRefineDriver::doRefine // Introduce baffles at surface intersections. Remove sections unreachable // from keepPoint. - baffleAndSplitMesh(refineParams, prepareForSnapping, motionDict); + baffleAndSplitMesh + ( + refineParams, + snapParams, + prepareForSnapping, + motionDict + ); // Mesh is at its finest. Do optional zoning. zonify(refineParams); // Pull baffles apart - splitAndMergeBaffles(refineParams, prepareForSnapping, motionDict); + splitAndMergeBaffles + ( + refineParams, + snapParams, + prepareForSnapping, + motionDict + ); // Do something about cells with refined faces on the boundary if (prepareForSnapping) diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.H b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.H index c44a14a794..a72f3c0796 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.H +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.H @@ -43,6 +43,8 @@ namespace Foam // Forward declaration of classes class refinementParameters; +class snapParameters; + class meshRefinement; class decompositionMethod; class fvMeshDistribute; @@ -121,6 +123,7 @@ class autoRefineDriver void baffleAndSplitMesh ( const refinementParameters& refineParams, + const snapParameters& snapParams, const bool handleSnapProblems, const dictionary& motionDict ); @@ -131,6 +134,7 @@ class autoRefineDriver void splitAndMergeBaffles ( const refinementParameters& refineParams, + const snapParameters& snapParams, const bool handleSnapProblems, const dictionary& motionDict ); @@ -176,6 +180,7 @@ public: ( const dictionary& refineDict, const refinementParameters& refineParams, + const snapParameters& snapParams, const bool prepareForSnapping, const dictionary& motionDict ); diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C index 4c262bd132..3927305177 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C @@ -121,7 +121,7 @@ Foam::pointField Foam::autoSnapDriver::smoothPatchDisplacement ( const motionSmoother& meshMover, const List& baffles -) const +) { const indirectPrimitivePatch& pp = meshMover.patch(); @@ -615,14 +615,14 @@ Foam::autoPtr Foam::autoSnapDriver::mergeZoneBaffles Foam::scalarField Foam::autoSnapDriver::calcSnapDistance ( + const fvMesh& mesh, const snapParameters& snapParams, const indirectPrimitivePatch& pp -) const +) { const edgeList& edges = pp.edges(); const labelListList& pointEdges = pp.pointEdges(); const pointField& localPoints = pp.localPoints(); - const fvMesh& mesh = meshRefiner_.mesh(); scalarField maxEdgeLen(localPoints.size(), -GREAT); @@ -655,13 +655,14 @@ Foam::scalarField Foam::autoSnapDriver::calcSnapDistance void Foam::autoSnapDriver::preSmoothPatch ( + const meshRefinement& meshRefiner, const snapParameters& snapParams, const label nInitErrors, const List& baffles, motionSmoother& meshMover -) const +) { - const fvMesh& mesh = meshRefiner_.mesh(); + const fvMesh& mesh = meshRefiner.mesh(); labelList checkFaces; @@ -724,11 +725,11 @@ void Foam::autoSnapDriver::preSmoothPatch { const_cast(mesh.time())++; Info<< "Writing patch smoothed mesh to time " - << meshRefiner_.timeName() << '.' << endl; - meshRefiner_.write + << meshRefiner.timeName() << '.' << endl; + meshRefiner.write ( debug, - mesh.time().path()/meshRefiner_.timeName() + mesh.time().path()/meshRefiner.timeName() ); Info<< "Dumped mesh in = " << mesh.time().cpuTimeIncrement() << " s\n" << nl << endl; @@ -742,12 +743,11 @@ void Foam::autoSnapDriver::preSmoothPatch // Get (pp-local) indices of points that are both on zone and on patched surface Foam::labelList Foam::autoSnapDriver::getZoneSurfacePoints ( + const fvMesh& mesh, const indirectPrimitivePatch& pp, const word& zoneName -) const +) { - const fvMesh& mesh = meshRefiner_.mesh(); - label zoneI = mesh.faceZones().findZoneID(zoneName); if (zoneI == -1) @@ -755,7 +755,7 @@ Foam::labelList Foam::autoSnapDriver::getZoneSurfacePoints FatalErrorIn ( "autoSnapDriver::getZoneSurfacePoints" - "(const indirectPrimitivePatch&, const word&)" + "(const fvMesh&, const indirectPrimitivePatch&, const word&)" ) << "Cannot find zone " << zoneName << exit(FatalError); } @@ -793,17 +793,17 @@ Foam::labelList Foam::autoSnapDriver::getZoneSurfacePoints Foam::vectorField Foam::autoSnapDriver::calcNearestSurface ( + const meshRefinement& meshRefiner, const scalarField& snapDist, - motionSmoother& meshMover -) const + const indirectPrimitivePatch& pp +) { Info<< "Calculating patchDisplacement as distance to nearest surface" << " point ..." << endl; - const indirectPrimitivePatch& pp = meshMover.patch(); const pointField& localPoints = pp.localPoints(); - const refinementSurfaces& surfaces = meshRefiner_.surfaces(); - const fvMesh& mesh = meshRefiner_.mesh(); + const refinementSurfaces& surfaces = meshRefiner.surfaces(); + const fvMesh& mesh = meshRefiner.mesh(); // Displacement per patch point vectorField patchDisp(localPoints.size(), vector::zero); @@ -815,9 +815,9 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface // Divide surfaces into zoned and unzoned labelList zonedSurfaces = - meshRefiner_.surfaces().getNamedSurfaces(); + meshRefiner.surfaces().getNamedSurfaces(); labelList unzonedSurfaces = - meshRefiner_.surfaces().getUnnamedSurfaces(); + meshRefiner.surfaces().getUnnamedSurfaces(); // 1. All points to non-interface surfaces @@ -870,6 +870,7 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface ( getZoneSurfacePoints ( + mesh, pp, faceZoneNames[zoneSurfI] ) @@ -966,6 +967,254 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface } +////XXXXXXXXX +//// Get (pp-local) indices of points that are on both patches +//Foam::labelList Foam::autoSnapDriver::getPatchSurfacePoints +//( +// const fvMesh& mesh, +// const indirectPrimitivePatch& allPp, +// const polyPatch& pp +//) +//{ +// // Could use PrimitivePatch & localFaces to extract points but might just +// // as well do it ourselves. +// +// boolList pointOnZone(allPp.nPoints(), false); +// +// forAll(pp, i) +// { +// const face& f = pp[i]; +// +// forAll(f, fp) +// { +// label meshPointI = f[fp]; +// +// Map