diff --git a/applications/utilities/mesh/generation/CV3DMesher/Make/files b/applications/utilities/mesh/generation/CV3DMesher/Make/files index fc4326559c..653d445ede 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/Make/files +++ b/applications/utilities/mesh/generation/CV3DMesher/Make/files @@ -1,5 +1,8 @@ + #include CGAL_FILES +plane.C + querySurface.C CV3D.C controls.C diff --git a/applications/utilities/mesh/generation/CV3DMesher/insertFeaturePoints.C b/applications/utilities/mesh/generation/CV3DMesher/insertFeaturePoints.C index a9f111e049..767a9beb95 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/insertFeaturePoints.C +++ b/applications/utilities/mesh/generation/CV3DMesher/insertFeaturePoints.C @@ -317,9 +317,12 @@ void Foam::CV3D::insertFeaturePoints() + tols_.ppDist*edgeDirection * concaveEdge.vec(localPts)/concaveEdge.mag(localPts); - plane planeF(concaveEdgeLocalFeatPt, concaveEdge.vec(localPts)); + // Finding the nearest point on the intersecting line to the edge point. + // Floating point errors often encountered using planePlaneIntersect + plane planeF(concaveEdgeLocalFeatPt, concaveEdge.vec(localPts)); point concaveEdgeExternalPt = planeF.planePlaneIntersect(planeA,planeB); + label concaveEdgeExternalPtI = number_of_vertices() + 4; // Redefine planes to be on the feature surfaces to project through @@ -485,8 +488,11 @@ void Foam::CV3D::insertFeaturePoints() + tols_.ppDist*edgeDirection * convexEdge.vec(localPts)/convexEdge.mag(localPts); - plane planeF(convexEdgeLocalFeatPt, convexEdge.vec(localPts)); + // Finding the nearest point on the intersecting line to the edge point. + // Floating point errors often encountered using planePlaneIntersect + + plane planeF(convexEdgeLocalFeatPt, convexEdge.vec(localPts)); point convexEdgeInternalPt = planeF.planePlaneIntersect(planeA,planeB); planeA = plane(featPt, convexEdgePlaneANormal); diff --git a/applications/utilities/mesh/generation/CV3DMesher/insertSurfaceNearestPointPairs.C b/applications/utilities/mesh/generation/CV3DMesher/insertSurfaceNearestPointPairs.C index 41caf8db1b..c4909619e7 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/insertSurfaceNearestPointPairs.C +++ b/applications/utilities/mesh/generation/CV3DMesher/insertSurfaceNearestPointPairs.C @@ -322,13 +322,13 @@ void Foam::CV3D::smoothEdge if ( edgeDist < tols_.featurePointGuard - && !startGuardPlaced + && !startGuardPlaced ) { tempEdgePoints.append ( eStart + (edgePoint - eStart) - * tols_.featurePointGuard/edgeDist + * tols_.featurePointGuard/edgeDist ); startGuardPlaced = true; @@ -336,7 +336,7 @@ void Foam::CV3D::smoothEdge else if ( edgeDist > (edgeLength - tols_.featurePointGuard) - && !endGuardPlaced + && !endGuardPlaced ) { tempEdgePoints.append @@ -359,6 +359,7 @@ void Foam::CV3D::smoothEdge edgePoints.transfer(tempEdgePoints.shrink()); } + // Recalculate edge distances. edgeDistances.setSize(edgePoints.size()); @@ -419,244 +420,173 @@ void Foam::CV3D::smoothEdge edgePoints.transfer(tempEdgePoints.shrink()); } + + // Recalculate edge distances. + + edgeDistances.setSize(edgePoints.size()); + + forAll(edgeDistances, eD) + { + edgeDistances[eD] = mag(eStart - edgePoints[eD]); + } + + // part 3 + { + // Special treatment for gaps between closest point to start + + DynamicList tempEdgePoints; + + if (edgeDistances[0] - tols_.featurePointGuard > tols_.maxEdgeSpacing) + { + scalar gap = edgeDistances[0] - tols_.featurePointGuard; + + label nInsertions = label(gap/tols_.maxEdgeSpacing); + + Info<< "Gap at start of edge of " << gap + << ". Inserting " << nInsertions << " points" << endl; + + scalar spacing = gap / (nInsertions + 1); + + for (label nI = 1; nI <= nInsertions; nI++) + { + tempEdgePoints.append + ( + eStart + (eEnd - eStart) + * (nI * spacing + tols_.featurePointGuard) /edgeLength + ); + } + } + + // Identify gaps in middle of edges. + // Insert first point by default. + + tempEdgePoints.append(edgePoints[0]); + + for (label eP = 1; eP < edgePoints.size(); eP++) + { + const scalar& edgeDist = edgeDistances[eP]; + const scalar& previousEdgeDist = edgeDistances[eP - 1]; + + if ((edgeDist - previousEdgeDist) > tols_.maxEdgeSpacing) + { + scalar gap = edgeDist - previousEdgeDist; + + label nInsertions = label(gap/tols_.maxEdgeSpacing); + + Info<< "Gap in edge of " << gap + << ". Inserting " << nInsertions << " points" << endl; + + scalar spacing = gap / (nInsertions + 1); + + for (label nI = 1; nI<= nInsertions; nI++) + { + tempEdgePoints.append + ( + eStart + (eEnd - eStart) + * (nI * spacing + previousEdgeDist) /edgeLength + ); + } + + + } + + tempEdgePoints.append(edgePoints[eP]); + } + + // Special treatment for gaps between closest point to start + + if + ( + (edgeLength - edgeDistances[edgeDistances.size() - 1] + - tols_.featurePointGuard) + > tols_.maxEdgeSpacing + ) + { + scalar lastPointDist = edgeDistances[edgeDistances.size() - 1]; + + const point& lastPoint = edgePoints[edgePoints.size() - 1]; + + scalar gap = edgeLength - lastPointDist - tols_.featurePointGuard; + + label nInsertions = label(gap/tols_.maxEdgeSpacing); + + Info<< "Gap at end of edge of " << gap + << ". Inserting " << nInsertions << " points" << endl; + + scalar spacing = gap / (nInsertions + 1); + + for (label nI = 1; nI <= nInsertions; nI++) + { + tempEdgePoints.append + ( + lastPoint + (eEnd - lastPoint) + * nI * spacing / gap + ); + } + } + + edgePoints.transfer(tempEdgePoints.shrink()); + + // Remove pairs of points that are too close together. + + label nPointsRemoved = 1; + + while (nPointsRemoved > 0) + { + nPointsRemoved = 0; + + // Recalculate edge distances. + + edgeDistances.setSize(edgePoints.size()); + + forAll(edgeDistances, eD) + { + edgeDistances[eD] = mag(eStart - edgePoints[eD]); + } + + // Insert first point + tempEdgePoints.append(edgePoints[0]); + + bool previousPointMustBeKept = false; + + for (label eP = 1; eP < edgePoints.size(); eP++) + { + const scalar& edgeDist = edgeDistances[eP]; + const scalar& previousEdgeDist = edgeDistances[eP - 1]; + + if ((edgeDist - previousEdgeDist) < tols_.minEdgeSpacing) + { + if (!previousPointMustBeKept) + { + tempEdgePoints.remove(); + } + + const point& currentPoint = edgePoints[eP]; + + const point& previousPoint = edgePoints[eP - 1]; + + tempEdgePoints.append(0.5*(previousPoint + currentPoint)); + + nPointsRemoved++; + + previousPointMustBeKept = true; + } + else + { + tempEdgePoints.append(edgePoints[eP]); + + previousPointMustBeKept = false; + } + } + + Info<< edgeI << tab << nPointsRemoved << " points removed." << endl; + + edgePoints.transfer(tempEdgePoints.shrink()); + } + } } -// { -// DynamicList tempEdgePoints(edgePoints.size()); - -// DynamicList