From c0a8bec3c58ccb04df577f253065940ae436a510 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 2 Feb 2010 15:49:08 +0000 Subject: [PATCH] ENH: balancing before refinement if locally number of cells > maxLocalCells will switch from refinement followed by balancing to weighted balancing first. This will avoid temporary huge imbalance if all cells to be refined are on one proc. --- .../mesh/generation/snappyHexMesh/snappyHexMesh.C | 16 +- .../generation/snappyHexMesh/snappyHexMeshDict | 23 +- .../autoHexMeshDriver/autoHexMeshDriver.C | 1 + .../autoHexMeshDriver/autoLayerDriver.C | 360 ++++++++++++--------- .../autoHexMeshDriver/autoLayerDriver.H | 5 +- .../autoHexMeshDriver/autoLayerDriverShrink.C | 9 +- .../autoHexMeshDriver/autoRefineDriver.C | 119 +++++-- .../layerParameters/layerParameters.H | 10 +- .../autoHexMeshDriver/pointData/pointData.C | 2 - .../autoHexMeshDriver/pointData/pointDataI.H | 18 +- .../refinementParameters/refinementParameters.C | 22 +- .../refinementParameters/refinementParameters.H | 21 ++ .../autoHexMesh/meshRefinement/meshRefinement.C | 45 ++- .../autoHexMesh/meshRefinement/meshRefinement.H | 25 +- .../meshRefinement/meshRefinementBaffles.C | 31 +- .../meshRefinement/meshRefinementRefine.C | 203 +++++++++++- .../refinementSurfaces/refinementSurfaces.C | 252 ++++++++++----- .../refinementSurfaces/refinementSurfaces.H | 6 +- .../autoHexMesh/trackedParticle/ExactParticle.C | 2 +- .../autoHexMesh/trackedParticle/ExactParticle.H | 2 +- .../searchableSurfaceCollection.C | 15 +- .../iglooWithFridges/system/snappyHexMeshDict | 21 +- .../simpleFoam/motorBike/system/snappyHexMeshDict | 21 +- 23 files changed, 879 insertions(+), 350 deletions(-) diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C index 8fc3aaf3..b2d7acff 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C @@ -192,7 +192,7 @@ int main(int argc, char *argv[]) autoRefineDriver::debug = debug; autoSnapDriver::debug = debug; autoLayerDriver::debug = debug; - } + } // Read geometry @@ -434,6 +434,19 @@ int main(int argc, char *argv[]) // Layer addition parameters layerParameters layerParams(layerDict, mesh.boundaryMesh()); + //!!! Temporary hack to get access to maxLocalCells + bool preBalance; + { + refinementParameters refineParams(refineDict); + + preBalance = returnReduce + ( + (mesh.nCells() >= refineParams.maxLocalCells()), + orOp() + ); + } + + if (!overwrite) { const_cast(mesh.time())++; @@ -444,6 +457,7 @@ int main(int argc, char *argv[]) layerDict, motionDict, layerParams, + preBalance, decomposer, distributor ); diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict index 29c05a5f..9d2367e5 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict @@ -10,7 +10,7 @@ FoamFile version 2.0; format ascii; class dictionary; - object autoHexMeshDict; + object snappyHexMeshDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -71,10 +71,10 @@ castellatedMeshControls // Refinement parameters // ~~~~~~~~~~~~~~~~~~~~~ - // While refining maximum number of cells per processor. This is basically - // the number of cells that fit on a processor. If you choose this too small - // it will do just more refinement iterations to obtain a similar mesh. - maxLocalCells 1000000; + // If local number of cells is >= maxLocalCells on any processor + // switches from from refinement followed by balancing + // (current method) to (weighted) balancing before refinement. + maxLocalCells 100000; // Overall cell limit (approximately). Refinement will stop immediately // upon reaching this number so a refinement level might not complete. @@ -89,6 +89,13 @@ castellatedMeshControls // (unless the number of cells to refine is 0) minRefinementCells 0; + // Allow a certain level of imbalance during refining + // (since balancing is quite expensive) + // Expressed as fraction of perfect balance (= overall number of cells / + // nProcs). 0=balance always. + maxLoadUnbalance 0.10; + + // Number of buffer layers between different levels. // 1 means normal 2:1 refinement restriction, larger means slower // refinement. @@ -184,6 +191,12 @@ castellatedMeshControls // NOTE: This point should never be on a face, always inside a cell, even // after refinement. locationInMesh (5 0.28 0.43); + + + // Whether any faceZones (as specified in the refinementSurfaces) + // are only on the boundary of corresponding cellZones or also allow + // free-standing zone faces + allowFreeStandingZoneFaces true; } diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.C b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.C index cc110c1d..76e589c0 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.C +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.C @@ -539,6 +539,7 @@ void Foam::autoHexMeshDriver::doMesh() shrinkDict, motionDict, layerParams, + true, // pre-balance decomposerPtr_(), distributorPtr_() ); diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C index 425adee9..30796066 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C @@ -2515,138 +2515,159 @@ void Foam::autoLayerDriver::addLayers ( const layerParameters& layerParams, const dictionary& motionDict, + const labelList& patchIDs, const label nAllowableErrors, - motionSmoother& meshMover, decompositionMethod& decomposer, fvMeshDistribute& distributor ) { fvMesh& mesh = meshRefiner_.mesh(); - const indirectPrimitivePatch& pp = meshMover.patch(); - const labelList& meshPoints = pp.meshPoints(); - // Precalculate mesh edge labels for patch edges - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + autoPtr pp + ( + meshRefinement::makePatch + ( + mesh, + patchIDs + ) + ); - labelList meshEdges(pp.nEdges()); - forAll(pp.edges(), edgeI) - { - const edge& ppEdge = pp.edges()[edgeI]; - label v0 = meshPoints[ppEdge[0]]; - label v1 = meshPoints[ppEdge[1]]; - meshEdges[edgeI] = meshTools::findEdge + // Construct iterative mesh mover. + Info<< "Constructing mesh displacer ..." << endl; + + autoPtr meshMover + ( + new motionSmoother ( - mesh.edges(), - mesh.pointEdges()[v0], - v0, - v1 - ); - } + mesh, + pp(), + patchIDs, + meshRefinement::makeDisplacementField + ( + pointMesh::New(mesh), + patchIDs + ), + motionDict + ) + ); + + + // Point-wise extrusion data + // ~~~~~~~~~~~~~~~~~~~~~~~~~ // Displacement for all pp.localPoints. - vectorField patchDisp(pp.nPoints(), vector::one); + vectorField patchDisp(pp().nPoints(), vector::one); // Number of layers for all pp.localPoints. Note: only valid if // extrudeStatus = EXTRUDE. - labelList patchNLayers(pp.nPoints(), 0); + labelList patchNLayers(pp().nPoints(), 0); // Whether to add edge for all pp.localPoints. - List extrudeStatus(pp.nPoints(), EXTRUDE); - - - // Get number of layer per point from number of layers per patch - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + List extrudeStatus(pp().nPoints(), EXTRUDE); - setNumLayers - ( - layerParams.numLayers(), // per patch the num layers - meshMover.adaptPatchIDs(), // patches that are being moved - pp, // indirectpatch for all faces moving - - patchDisp, - patchNLayers, - extrudeStatus - ); - - // Disable extrusion on non-manifold points - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { + // Get number of layer per point from number of layers per patch + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - handleNonManifolds - ( - pp, - meshEdges, + setNumLayers + ( + layerParams.numLayers(), // per patch the num layers + meshMover().adaptPatchIDs(),// patches that are being moved + pp, // indirectpatch for all faces moving - patchDisp, - patchNLayers, - extrudeStatus - ); + patchDisp, + patchNLayers, + extrudeStatus + ); - // Disable extrusion on feature angles - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Precalculate mesh edge labels for patch edges + labelList meshEdges(pp().meshEdges(mesh.edges(), mesh.pointEdges())); - handleFeatureAngle - ( - pp, - meshEdges, - layerParams.featureAngle()*mathematicalConstant::pi/180.0, + // Disable extrusion on non-manifold points + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - patchDisp, - patchNLayers, - extrudeStatus - ); + handleNonManifolds + ( + pp, + meshEdges, - // Disable extrusion on warped faces - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + patchDisp, + patchNLayers, + extrudeStatus + ); - // Undistorted edge length - const scalar edge0Len = meshRefiner_.meshCutter().level0EdgeLength(); - const labelList& cellLevel = meshRefiner_.meshCutter().cellLevel(); + // Disable extrusion on feature angles + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - handleWarpedFaces - ( - pp, - layerParams.maxFaceThicknessRatio(), - edge0Len, - cellLevel, + handleFeatureAngle + ( + pp, + meshEdges, + layerParams.featureAngle()*mathematicalConstant::pi/180.0, - patchDisp, - patchNLayers, - extrudeStatus - ); + patchDisp, + patchNLayers, + extrudeStatus + ); - //// Disable extrusion on cells with multiple patch faces - //// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // - //handleMultiplePatchFaces - //( - // pp, - // - // patchDisp, - // patchNLayers, - // extrudeStatus - //); + // Disable extrusion on warped faces + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Undistorted edge length + const scalar edge0Len = meshRefiner_.meshCutter().level0EdgeLength(); + const labelList& cellLevel = meshRefiner_.meshCutter().cellLevel(); - // Grow out region of non-extrusion - for (label i = 0; i < layerParams.nGrow(); i++) - { - growNoExtrusion + handleWarpedFaces ( pp, + layerParams.maxFaceThicknessRatio(), + edge0Len, + cellLevel, + patchDisp, patchNLayers, extrudeStatus ); + + //// Disable extrusion on cells with multiple patch faces + //// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // + //handleMultiplePatchFaces + //( + // pp, + // + // patchDisp, + // patchNLayers, + // extrudeStatus + //); + + + // Grow out region of non-extrusion + for (label i = 0; i < layerParams.nGrow(); i++) + { + growNoExtrusion + ( + pp, + patchDisp, + patchNLayers, + extrudeStatus + ); + } } + + // Undistorted edge length + const scalar edge0Len = meshRefiner_.meshCutter().level0EdgeLength(); + const labelList& cellLevel = meshRefiner_.meshCutter().cellLevel(); + // Determine (wanted) point-wise layer thickness and expansion ratio - scalarField thickness(pp.nPoints()); - scalarField minThickness(pp.nPoints()); - scalarField expansionRatio(pp.nPoints()); + scalarField thickness(pp().nPoints()); + scalarField minThickness(pp().nPoints()); + scalarField expansionRatio(pp().nPoints()); calculateLayerThickness ( pp, - meshMover.adaptPatchIDs(), + meshMover().adaptPatchIDs(), layerParams.expansionRatio(), layerParams.relativeSizes(), // thickness relative to cellsize? @@ -2669,14 +2690,14 @@ void Foam::autoLayerDriver::addLayers // Find maximum length of a patch name, for a nicer output label maxPatchNameLen = 0; - forAll(meshMover.adaptPatchIDs(), i) + forAll(meshMover().adaptPatchIDs(), i) { - label patchI = meshMover.adaptPatchIDs()[i]; + label patchI = meshMover().adaptPatchIDs()[i]; word patchName = patches[patchI].name(); - maxPatchNameLen = max(maxPatchNameLen,label(patchName.size())); + maxPatchNameLen = max(maxPatchNameLen, label(patchName.size())); } - Info<< nl + Info<< nl << setf(ios_base::left) << setw(maxPatchNameLen) << "patch" << setw(0) << " faces layers avg thickness[m]" << nl << setf(ios_base::left) << setw(maxPatchNameLen) << " " @@ -2684,9 +2705,9 @@ void Foam::autoLayerDriver::addLayers << setf(ios_base::left) << setw(maxPatchNameLen) << "-----" << setw(0) << " ----- ------ --------- -------" << endl; - forAll(meshMover.adaptPatchIDs(), i) + forAll(meshMover().adaptPatchIDs(), i) { - label patchI = meshMover.adaptPatchIDs()[i]; + label patchI = meshMover().adaptPatchIDs()[i]; const labelList& meshPoints = patches[patchI].meshPoints(); @@ -2697,7 +2718,7 @@ void Foam::autoLayerDriver::addLayers forAll(meshPoints, patchPointI) { - label ppPointI = pp.meshPointMap()[meshPoints[patchPointI]]; + label ppPointI = pp().meshPointMap()[meshPoints[patchPointI]]; //maxThickness = max(maxThickness, thickness[ppPointI]); //minThickness = min(minThickness, thickness[ppPointI]); @@ -2767,7 +2788,7 @@ void Foam::autoLayerDriver::addLayers IOobject::NO_WRITE, false ), - meshMover.pMesh(), + meshMover().pMesh(), dimensionedScalar("pointMedialDist", dimless, 0.0) ); @@ -2782,7 +2803,7 @@ void Foam::autoLayerDriver::addLayers IOobject::NO_WRITE, false ), - meshMover.pMesh(), + meshMover().pMesh(), dimensionedVector("dispVec", dimless, vector::zero) ); @@ -2797,7 +2818,7 @@ void Foam::autoLayerDriver::addLayers IOobject::NO_WRITE, false ), - meshMover.pMesh(), + meshMover().pMesh(), dimensionedScalar("medialRatio", dimless, 0.0) ); @@ -2877,7 +2898,7 @@ void Foam::autoLayerDriver::addLayers // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { - pointField oldPatchPos(pp.localPoints()); + pointField oldPatchPos(pp().localPoints()); //// Laplacian displacement shrinking. //shrinkMeshDistance @@ -2892,7 +2913,7 @@ void Foam::autoLayerDriver::addLayers // Medial axis based shrinking shrinkMeshMedialDistance ( - meshMover, + meshMover(), meshQualityDict, layerParams.nSmoothThickness(), @@ -2914,7 +2935,7 @@ void Foam::autoLayerDriver::addLayers ); // Update patchDisp (since not all might have been honoured) - patchDisp = oldPatchPos - pp.localPoints(); + patchDisp = oldPatchPos - pp().localPoints(); } // Truncate displacements that are too small (this will do internal @@ -2922,7 +2943,7 @@ void Foam::autoLayerDriver::addLayers faceSet dummySet(mesh, "wrongPatchFaces", 0); truncateDisplacement ( - meshMover, + meshMover(), minThickness, dummySet, patchDisp, @@ -2937,7 +2958,7 @@ void Foam::autoLayerDriver::addLayers dumpDisplacement ( mesh.time().path()/"layer", - pp, + pp(), patchDisp, extrudeStatus ); @@ -2961,11 +2982,11 @@ void Foam::autoLayerDriver::addLayers // Determine per point/per face number of layers to extrude. Also // handles the slow termination of layers when going switching layers - labelList nPatchPointLayers(pp.nPoints(),-1); - labelList nPatchFaceLayers(pp.localFaces().size(),-1); + labelList nPatchPointLayers(pp().nPoints(),-1); + labelList nPatchFaceLayers(pp().localFaces().size(),-1); setupLayerInfoTruncation ( - meshMover, + meshMover(), patchNLayers, extrudeStatus, layerParams.nBufferCellsNoExtrude(), @@ -3004,7 +3025,7 @@ void Foam::autoLayerDriver::addLayers addLayer.setRefinement ( invExpansionRatio, - pp, + pp(), nPatchFaceLayers, // layers per face nPatchPointLayers, // layers per point firstDisp, // thickness of layer nearest internal mesh @@ -3055,8 +3076,8 @@ void Foam::autoLayerDriver::addLayers addLayer.updateMesh ( map, - identity(pp.size()), - identity(pp.nPoints()) + identity(pp().size()), + identity(pp().nPoints()) ); // Collect layer faces and cells for outside loop. @@ -3103,7 +3124,7 @@ void Foam::autoLayerDriver::addLayers ( addLayer, meshQualityDict, - pp, + pp(), newMesh, patchDisp, @@ -3112,7 +3133,7 @@ void Foam::autoLayerDriver::addLayers ); Info<< "Extruding " << countExtrusion(pp, extrudeStatus) - << " out of " << returnReduce(pp.size(), sumOp