From 1b19e1dbc0f29e52bb8914925140201391f6f10e Mon Sep 17 00:00:00 2001 From: laurence <laurence> Date: Mon, 19 Mar 2012 11:29:34 +0000 Subject: [PATCH] ENH: cvMesh: Initial code for required cell size in the style of required alignment --- .../conformalVoronoiMesh.C | 141 +++++++++++++++++- .../conformalVoronoiMesh.H | 3 + 2 files changed, 140 insertions(+), 4 deletions(-) diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C index 09d27dfa362..de23690ea43 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C @@ -44,6 +44,142 @@ const Foam::scalar Foam::conformalVoronoiMesh::tolParallel = 1e-3; // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // +Foam::scalar Foam::conformalVoronoiMesh::requiredSize +( + const Foam::point& pt +) const +{ + pointIndexHit surfHit; + label hitSurface; + + DynamicList<scalar> cellSizeHits; + + geometryToConformTo_.findSurfaceNearest + ( + pt, + sqr(GREAT), + surfHit, + hitSurface + ); + + if (!surfHit.hit()) + { + FatalErrorIn + ( + "Foam::tensor Foam::conformalVoronoiMesh::requiredAlignment" + ) + << "findSurfaceNearest did not find a hit across the surfaces." + << exit(FatalError) << endl; + } + + cellSizeHits.append(cellSizeControl().cellSize(pt)); + + // Primary alignment + + vectorField norm(1); + + allGeometry_[hitSurface].getNormal + ( + List<pointIndexHit>(1, surfHit), + norm + ); + + const vector np = norm[0]; + + // Generate equally spaced 'spokes' in a circle normal to the + // direction from the vertex to the closest point on the surface + // and look for a secondary intersection. + + const vector d = surfHit.hitPoint() - pt; + + const tensor Rp = rotationTensor(vector(0,0,1), np); + + const label s = cvMeshControls().alignmentSearchSpokes(); + + const scalar spanMag = geometryToConformTo_.globalBounds().mag(); + + scalar totalDist = 0; + + for (label i = 0; i < s; i++) + { + vector spoke + ( + Foam::cos(i*constant::mathematical::twoPi/s), + Foam::sin(i*constant::mathematical::twoPi/s), + 0 + ); + + spoke *= spanMag; + + spoke = Rp & spoke; + + pointIndexHit spokeHit; + + label spokeSurface = -1; + + // internal spoke + + geometryToConformTo_.findSurfaceNearestIntersection + ( + pt, + pt + spoke, + spokeHit, + spokeSurface + ); + + if (spokeHit.hit()) + { + const Foam::point& hitPt = spokeHit.hitPoint(); + + scalar spokeHitDistance = mag(hitPt - pt); + + cellSizeHits.append + ( + cellSizeControl().cellSize(hitPt) + ); + + totalDist += spokeHitDistance; + } + + //external spoke + + Foam::point mirrorPt = pt + 2*d; + + geometryToConformTo_.findSurfaceNearestIntersection + ( + mirrorPt, + mirrorPt + spoke, + spokeHit, + spokeSurface + ); + + if (spokeHit.hit()) + { + const Foam::point& hitPt = spokeHit.hitPoint(); + + scalar spokeHitDistance = mag(hitPt - mirrorPt); + + cellSizeHits.append + ( + cellSizeControl().cellSize(hitPt) + ); + + totalDist += spokeHitDistance; + } + } + + scalar cellSize = 0; + + forAll(cellSizeHits, hitI) + { + cellSize += cellSizeHits[hitI]; + } + + return cellSize/cellSizeHits.size(); + //return cellSizeControl().cellSize(pt); +} + + Foam::tensor Foam::conformalVoronoiMesh::requiredAlignment ( const Foam::point& pt @@ -828,10 +964,7 @@ void Foam::conformalVoronoiMesh::storeSizesAndAlignments { sizeAndAlignmentLocations_[i] = topoint(*pit); - storedSizes_[i] = cellSizeControl().cellSize - ( - sizeAndAlignmentLocations_[i] - ); + storedSizes_[i] = requiredSize(sizeAndAlignmentLocations_[i]); storedAlignments_[i] = requiredAlignment(sizeAndAlignmentLocations_[i]); diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H index 81ce496c717..cde15d06621 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H @@ -268,6 +268,9 @@ private: //- Return the local maximum surface protrusion distance inline scalar maxSurfaceProtrusion(const Foam::point& pt) const; + //- Return the required cell size at the given location + scalar requiredSize(const Foam::point& pt) const; + //- Return the required alignment directions at the given location tensor requiredAlignment(const Foam::point& pt) const; -- GitLab