diff --git a/applications/utilities/mesh/generation/Allwmake b/applications/utilities/mesh/generation/Allwmake index ef28f9aaf5..48ca530c96 100755 --- a/applications/utilities/mesh/generation/Allwmake +++ b/applications/utilities/mesh/generation/Allwmake @@ -4,12 +4,15 @@ set -x wmake blockMesh wmake all extrude -wmake extrude2DMesh + +extrude2DMesh/Allwmake + wmake snappyHexMesh if [ -d "$CGAL_ARCH_PATH" ] then - cd cvMesh && ./Allwmake + cvMesh/Allwmake + cv2DMesh/Allwmake fi # ----------------------------------------------------------------- end-of-file diff --git a/applications/utilities/mesh/generation/cv2DMesh/Allwclean b/applications/utilities/mesh/generation/cv2DMesh/Allwclean new file mode 100755 index 0000000000..d0ae53e415 --- /dev/null +++ b/applications/utilities/mesh/generation/cv2DMesh/Allwclean @@ -0,0 +1,8 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # run from this directory +set -x + +wclean libso conformalVoronoi2DMesh +wclean + +# ----------------------------------------------------------------- end-of-file diff --git a/applications/utilities/mesh/generation/cv2DMesh/Allwmake b/applications/utilities/mesh/generation/cv2DMesh/Allwmake new file mode 100755 index 0000000000..5486849957 --- /dev/null +++ b/applications/utilities/mesh/generation/cv2DMesh/Allwmake @@ -0,0 +1,8 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # run from this directory +set -x + +wmake libso conformalVoronoi2DMesh +wmake + +# ----------------------------------------------------------------- end-of-file diff --git a/applications/utilities/mesh/generation/cv2DMesh/CV2D.C b/applications/utilities/mesh/generation/cv2DMesh/CV2D.C index f6ab73cc3f..c95a61573e 100644 --- a/applications/utilities/mesh/generation/cv2DMesh/CV2D.C +++ b/applications/utilities/mesh/generation/cv2DMesh/CV2D.C @@ -30,12 +30,19 @@ License #include "uint.H" #include "ulong.H" +namespace Foam +{ + +defineTypeNameAndDebug(CV2D, 0); + +} + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::CV2D::insertBoundingBox() { Info<< "insertBoundingBox: creating bounding mesh" << endl; - scalar bigSpan = 10*tols_.span; + scalar bigSpan = 10*meshControls().span(); insertPoint(point2D(-bigSpan, -bigSpan), Vb::FAR_POINT); insertPoint(point2D(-bigSpan, bigSpan), Vb::FAR_POINT); insertPoint(point2D(bigSpan, -bigSpan), Vb::FAR_POINT); @@ -125,22 +132,26 @@ Foam::CV2D::CV2D allGeometry_, cvMeshDict.subDict("surfaceConformation") ), - controls_(cvMeshDict), + controls_(cvMeshDict, qSurf_.globalBounds()), cellSizeControl_ ( allGeometry_, cvMeshDict.subDict("motionControl") ), - tols_(cvMeshDict, controls_.minCellSize, qSurf_.globalBounds()), z_ ( - (1.0/3.0) - *(qSurf_.globalBounds().min().z() + qSurf_.globalBounds().max().z()) + point + ( + cvMeshDict.subDict("surfaceConformation").lookup("locationInMesh") + ).z() ), startOfInternalPoints_(0), startOfSurfacePointPairs_(0), - startOfBoundaryConformPointPairs_(0) + startOfBoundaryConformPointPairs_(0), + featurePoints_() { + Info<< meshControls() << endl; + insertBoundingBox(); insertFeaturePoints(); } @@ -183,7 +194,7 @@ void Foam::CV2D::insertPoints Info<< nVert << " vertices inserted" << endl; - if (controls_.writeInitialTriangulation) + if (meshControls().objOutput()) { // Checking validity of triangulation assert(is_valid()); @@ -200,7 +211,7 @@ void Foam::CV2D::insertPoints(const fileName& pointFileName) if (pointsFile.good()) { - insertPoints(point2DField(pointsFile), 0.5*controls_.minCellSize2); + insertPoints(point2DField(pointsFile), 0.5*meshControls().minCellSize2()); } else { @@ -220,16 +231,16 @@ void Foam::CV2D::insertGrid() scalar x0 = qSurf_.globalBounds().min().x(); scalar xR = qSurf_.globalBounds().max().x() - x0; - int ni = int(xR/controls_.minCellSize) + 1; + int ni = int(xR/meshControls().minCellSize()) + 1; scalar deltax = xR/ni; scalar y0 = qSurf_.globalBounds().min().y(); scalar yR = qSurf_.globalBounds().max().y() - y0; - int nj = int(yR/controls_.minCellSize) + 1; + int nj = int(yR/meshControls().minCellSize()) + 1; scalar deltay = yR/nj; Random rndGen(1321); - scalar pert = controls_.randomPurturbation*min(deltax, deltay); + scalar pert = meshControls().randomPerturbation()*min(deltax, deltay); for (int i=0; iindex() = nVert++; } @@ -252,7 +263,7 @@ void Foam::CV2D::insertGrid() Info<< nVert << " vertices inserted" << endl; - if (controls_.writeInitialTriangulation) + if (meshControls().objOutput()) { // Checking validity of triangulation assert(is_valid()); @@ -267,21 +278,16 @@ void Foam::CV2D::insertSurfacePointPairs() { startOfSurfacePointPairs_ = number_of_vertices(); - if (controls_.insertSurfaceNearestPointPairs) + if (meshControls().insertSurfaceNearestPointPairs()) { insertSurfaceNearestPointPairs(); } - if (controls_.writeNearestTriangulation) - { - writeFaces("near_allFaces.obj", false); - writeFaces("near_faces.obj", true); - writeTriangles("near_triangles.obj", true); - } + write("nearest"); // Insertion of point-pairs for near-points may cause protrusions // so insertBoundaryConformPointPairs must be executed last - if (controls_.insertSurfaceNearPointPairs) + if (meshControls().insertSurfaceNearPointPairs()) { insertSurfaceNearPointPairs(); } @@ -292,7 +298,7 @@ void Foam::CV2D::insertSurfacePointPairs() void Foam::CV2D::boundaryConform() { - if (!controls_.insertSurfaceNearestPointPairs) + if (!meshControls().insertSurfaceNearestPointPairs()) { markNearBoundaryPoints(); } @@ -308,7 +314,7 @@ void Foam::CV2D::boundaryConform() fit->faceIndex() = Fb::SAVE_CHANGED; } - for (label iter=1; iter<=controls_.maxBoundaryConformingIter; iter++) + for (label iter=1; iter<=meshControls().maxBoundaryConformingIter(); iter++) { label nIntersections = insertBoundaryConformPointPairs ( @@ -347,6 +353,8 @@ void Foam::CV2D::boundaryConform() } Info<< nl; + + write("boundary"); } @@ -412,7 +420,7 @@ void Foam::CV2D::newPoints(const scalar relaxation) scalarField sizes ( number_of_vertices(), - controls_.minCellSize + meshControls().minCellSize() ); Field alignments @@ -439,14 +447,13 @@ void Foam::CV2D::newPoints(const scalar relaxation) qSurf_.findSurfaceNearest ( toPoint3D(vert), - tols_.span2, + meshControls().span2(), pHit, hitSurface ); if (pHit.hit()) { - vectorField norm(1); allGeometry_[hitSurface].getNormal ( @@ -456,23 +463,8 @@ void Foam::CV2D::newPoints(const scalar relaxation) alignments[vit->index()] = toPoint2D(norm[0]); - scalar surfDist = mag(toPoint3D(vert) - pHit.hitPoint()); - - /*if (surfDist < 0.2) - { - sizes[vit->index()] *= 0.4; - }*/ - - if (surfDist < 0.2) - { - sizes[vit->index()] *= (1 - 0.1)*surfDist/0.2 + 0.1; - } + sizes[vit->index()] = cellSizeControl_.cellSize(toPoint3D(vit->point())); } - - // if (vert.x() > 0) - // { - // sizes[vit->index()] *= 0.5; - // } } } @@ -486,7 +478,7 @@ void Foam::CV2D::newPoints(const scalar relaxation) PackedBoolList pointToBeRetained(startOfSurfacePointPairs_, true); - DynamicList pointsToInsert; + std::list pointsToInsert; for ( @@ -621,7 +613,7 @@ void Foam::CV2D::newPoints(const scalar relaxation) ) { // Point insertion - pointsToInsert.append(0.5*(dVA + dVB)); + pointsToInsert.push_back(toPoint(0.5*(dVA + dVB))); } else if ( @@ -640,7 +632,7 @@ void Foam::CV2D::newPoints(const scalar relaxation) && pointToBeRetained[vB->index()] == true ) { - pointsToInsert.append(0.5*(dVA + dVB)); + pointsToInsert.push_back(toPoint(0.5*(dVA + dVB))); } if (vA->internalPoint()) @@ -675,6 +667,8 @@ void Foam::CV2D::newPoints(const scalar relaxation) // Relax the calculated displacement displacementAccumulator *= relaxation; + label numberOfNewPoints = pointsToInsert.size(); + for ( Triangulation::Finite_vertices_iterator vit = finite_vertices_begin(); @@ -684,62 +678,66 @@ void Foam::CV2D::newPoints(const scalar relaxation) { if (vit->internalPoint()) { - if (!pointToBeRetained[vit->index()]) + if (pointToBeRetained[vit->index()]) { - remove(vit); - } - else - { - movePoint + pointsToInsert.push_front ( - vit, - vit->point() - + K::Vector_2 + toPoint ( - displacementAccumulator[vit->index()].x(), - displacementAccumulator[vit->index()].y() + toPoint2D(vit->point()) + + displacementAccumulator[vit->index()] ) ); } } } - removeSurfacePointPairs(); + // Clear the triangulation and reinsert the bounding box and feature points. + // This is faster than removing and moving points. + this->clear(); - // Re-index internal points + insertBoundingBox(); + + reinsertFeaturePoints(); + + startOfInternalPoints_ = number_of_vertices(); label nVert = startOfInternalPoints_; + Info<< "Inserting " << numberOfNewPoints << " new points" << endl; + + // Use the range insert as it is faster than individually inserting points. + insert(pointsToInsert.begin(), pointsToInsert.end()); + for ( - Triangulation::Finite_vertices_iterator vit = finite_vertices_begin(); + Delaunay::Finite_vertices_iterator vit = finite_vertices_begin(); vit != finite_vertices_end(); ++vit ) { - if (vit->internalPoint()) + if + ( + vit->type() == Vb::INTERNAL_POINT + && vit->index() == Vb::INTERNAL_POINT + ) { vit->index() = nVert++; } } - // Insert new points - - Info<< "Inserting " << pointsToInsert.size() << " new points" << endl; - - forAll(pointsToInsert, i) - { - insertPoint(pointsToInsert[i], Vb::INTERNAL_POINT); - } - Info<< " Total displacement = " << totalDisp << nl << " Total distance = " << totalDist << nl << " Points added = " << pointsToInsert.size() << endl; + write("internal"); + insertSurfacePointPairs(); + boundaryConform(); + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Old Method // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -816,19 +814,19 @@ void Foam::CV2D::newPoints(const scalar relaxation) // // in in the x-y directions // vector2D cd0(1, 0); - // if (controls_.relaxOrientation) + // if (meshControls().relaxOrientation()) // { // // Get the longest edge from the array and use as the primary // // direction of the coordinate system of the "square" cell // cd0 = edges[edgecd0i]; // } - // if (controls_.nearWallAlignedDist > 0) + // if (meshControls().nearWallAlignedDist() > 0) // { // pointIndexHit pHit = qSurf_.tree().findNearest // ( // toPoint3D(defVert0), - // controls_.nearWallAlignedDist2 + // meshControls().nearWallAlignedDist2() // ); // if (pHit.hit()) @@ -871,7 +869,7 @@ void Foam::CV2D::newPoints(const scalar relaxation) // // Set the weight for this edge contribution // scalar w = 1; - // if (controls_.squares) + // if (meshControls().squares()) // { // w = magSqr(deltai.x()*ei.y() - deltai.y()*ei.x()); // // alternative weights @@ -1014,7 +1012,7 @@ void Foam::CV2D::extractPatches void Foam::CV2D::write() const { - if (controls_.writeFinalTriangulation) + if (meshControls().objOutput()) { writeFaces("allFaces.obj", false); writeFaces("faces.obj", true); @@ -1025,4 +1023,32 @@ void Foam::CV2D::write() const } +void Foam::CV2D::write(const word& stage) const +{ + if (meshControls().objOutput()) + { + Foam::mkDir(stage + "Faces"); + Foam::mkDir(stage + "Triangles"); + + writeFaces + ( + stage + + "Faces/allFaces_" + + runTime_.timeName() + + ".obj", + false + ); + + writeTriangles + ( + stage + + "Triangles/allTriangles_" + + runTime_.timeName() + + ".obj", + false + ); + } +} + + // ************************************************************************* // diff --git a/applications/utilities/mesh/generation/cv2DMesh/CV2D.H b/applications/utilities/mesh/generation/cv2DMesh/CV2D.H index e295300b12..c875ed3a87 100644 --- a/applications/utilities/mesh/generation/cv2DMesh/CV2D.H +++ b/applications/utilities/mesh/generation/cv2DMesh/CV2D.H @@ -125,7 +125,7 @@ SourceFiles #include "Switch.H" #include "PackedBoolList.H" #include "EdgeMap.H" -#include "controls.H" +#include "cv2DControls.H" #include "tolerances.H" #include "meshTools.H" #include "triSurface.H" @@ -165,14 +165,11 @@ private: conformationSurfaces qSurf_; //- Meshing controls - controls controls_; + cv2DControls controls_; //- The cell size control object cellSizeControlSurfaces cellSizeControl_; - //- Meshing tolerances - tolerances tols_; - //- z-level scalar z_; @@ -188,6 +185,9 @@ private: // removing and insertin the surface point-pairs label startOfBoundaryConformPointPairs_; + //- Store the feature points + std::list featurePoints_; + //- Temporary storage for a dual-cell static const label maxNvert = 20; mutable point2D vertices[maxNvert+1]; @@ -210,6 +210,21 @@ private: const label type ); + //- Insert point and return it's index + inline label insertPoint + ( + const point2D& pt, + const label index, + const label type + ); + + inline label insertPoint + ( + const Point& p, + const label index, + const label type + ); + inline bool insertMirrorPoint ( const point2D& nearSurfPt, @@ -228,9 +243,15 @@ private: //- Create the initial mesh from the bounding-box void insertBoundingBox(); + //- Check if a point is within a line. + bool on2DLine(const point2D& p, const linePointRef& line); + //- Insert point groups at the feature points. void insertFeaturePoints(); + //- Re-insert point groups at the feature points. + void reinsertFeaturePoints(); + //- Insert point-pairs at the given set of points using the surface // normals corresponding to the given set of surface triangles // and write the inserted point locations to the given file. @@ -239,6 +260,7 @@ private: const DynamicList& nearSurfacePoints, const DynamicList& surfacePoints, const DynamicList