diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C index c62a340a02..508bdcb2d8 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C @@ -1342,6 +1342,17 @@ int main(int argc, char *argv[]) const snapParameters snapParams(snapDict, dryRun); + Info<< "Setting refinement level of surface to be consistent" + << " with curvature." << endl; + surfaces.setCurvatureMinLevelFields + ( + refineParams.curvature(), + meshRefiner.meshCutter().level0EdgeLength() + ); + Info<< "Checked curvature refinement in = " + << mesh.time().cpuTimeIncrement() << " s" << nl << endl; + + // Add all the cellZones and faceZones // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/etc/caseDicts/annotated/snappyHexMeshDict b/etc/caseDicts/annotated/snappyHexMeshDict index e4d319f8f0..b66214a74e 100644 --- a/etc/caseDicts/annotated/snappyHexMeshDict +++ b/etc/caseDicts/annotated/snappyHexMeshDict @@ -230,6 +230,21 @@ castellatedMeshControls // outside locations. Default is only after all refinement has // been done. //leakLevel 10; + + // Additional refinement for regions of high curvature. Expressed + // (bit similar to gapLevel) as: + // - number of cells per radius of curvature. (usually 1 is + // good enough) + // - starting cell level? Not used at the moment. + // - maximum cell level. This can be smaller or larger than the + // max 'surface' level + // - minumum curvature radius to ignore (expressed as a cell level). + // This can be used to avoid detecting small sharp surface + // features. Set to -1 to ignore. + // (sometimes you want more refinement than sharp features since + // these can be done with feature edge snapping (so can leave + // level (0 0)) + //curvatureLevel (10 0 10 -1); } } diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H index fb0d7305d0..2e985707b7 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H @@ -471,6 +471,19 @@ private: label& nRefine ) const; + //- Refine cells containing triangles with high refinement level + // (currently due to high curvature or being inside shell with + // high level) + label markSurfaceFieldRefinement + ( + const label nAllowRefine, + const labelList& neiLevel, + const pointField& neiCc, + + labelList& refineCell, + label& nRefine + ) const; + //- Helper: count number of normals1 that are in normals2 label countMatches ( @@ -479,6 +492,18 @@ private: const scalar tol = 1e-6 ) const; + //- Detect if two intersection points are high curvature (w.r.t. + // lengthscale + bool highCurvature + ( + const scalar minCosAngle, + const scalar lengthScale, + const point& p0, + const vector& n0, + const point& p1, + const vector& n1 + ) const; + //- Mark cells for surface curvature based refinement. Marks if // local curvature > curvature or if on different regions // (markDifferingRegions) diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementGapRefine.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementGapRefine.C index 01af062032..a4e26a976b 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementGapRefine.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementGapRefine.C @@ -1833,4 +1833,120 @@ Foam::label Foam::meshRefinement::markSmallFeatureRefinement } +////XXXXXXXX +Foam::label Foam::meshRefinement::markSurfaceFieldRefinement +( + const label nAllowRefine, + const labelList& neiLevel, + const pointField& neiCc, + + labelList& refineCell, + label& nRefine +) const +{ + const labelList& cellLevel = meshCutter_.cellLevel(); + const labelList& surfaceIndices = surfaces_.surfaces(); + + label oldNRefine = nRefine; + + //- Force calculation of tetBasePt + (void)mesh_.tetBasePtIs(); + (void)mesh_.cellTree(); + const indexedOctree& tree = mesh_.cellTree(); + + + forAll(surfaceIndices, surfI) + { + label geomI = surfaceIndices[surfI]; + const searchableSurface& geom = surfaces_.geometry()[geomI]; + + // Get the element index in a roundabout way. Problem is e.g. + // distributed surface where local indices differ from global + // ones (needed for getRegion call) + + pointField ctrs; + labelList region; + labelList minLevelField; + { + // Representative local coordinates and bounding sphere + scalarField radiusSqr; + geom.boundingSpheres(ctrs, radiusSqr); + + List info; + geom.findNearest(ctrs, radiusSqr, info); + + forAll(info, i) + { + if (!info[i].hit()) + { + FatalErrorInFunction + << "fc:" << ctrs[i] + << " radius:" << radiusSqr[i] + << exit(FatalError); + } + } + + geom.getRegion(info, region); + geom.getField(info, minLevelField); + } + + if (minLevelField.size() != geom.size()) + { + Pout<< "** no minLevelField" << endl; + continue; + } + + + label nOldRefine = 0; + + forAll(ctrs, i) + { + label cellI = -1; + if (tree.nodes().size() && tree.bb().contains(ctrs[i])) + { + cellI = tree.findInside(ctrs[i]); + } + + if + ( + cellI != -1 + && refineCell[cellI] == -1 + && minLevelField[i] > cellLevel[cellI] + ) + { + if + ( + !markForRefine + ( + surfI, + nAllowRefine, + refineCell[cellI], + nRefine + ) + ) + { + break; + } + } + } + + Info<< "For surface " << geom.name() << " found " + << returnReduce(nRefine-nOldRefine, sumOp