Commit 075e47ea authored by laurence's avatar laurence
Browse files

ENH: Merge cvMesh functionality into cv2DMesh

- Added conformationSurface and searchableSurface classes in place
  of querySurface.
- Added cellSizeControl class.
- Change cvMesh argument of relaxation model constructor to Time.
- Add writePrecision option to surfaceConvert.
- Add onLine function to surfaceFeatureExtract.
- Remove querySurface.
- Move createShellMesh and extrude2DMesh to their own libraries.
- Replace controls and tolerances with a cv2DControls object.
- Add patchToPoly2DMesh class to extrude2DMesh.
parent b69f513f
......@@ -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
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
set -x
wclean libso conformalVoronoi2DMesh
wclean
# ----------------------------------------------------------------- end-of-file
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
set -x
wmake libso conformalVoronoi2DMesh
wmake
# ----------------------------------------------------------------- end-of-file
......@@ -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; i<ni; i++)
{
......@@ -237,13 +248,13 @@ void Foam::CV2D::insertGrid()
{
point p(x0 + i*deltax, y0 + j*deltay, 0);
if (controls_.randomiseInitialGrid)
if (meshControls().randomiseInitialGrid())
{
p.x() += pert*(rndGen.scalar01() - 0.5);
p.y() += pert*(rndGen.scalar01() - 0.5);
}
if (qSurf_.wellInside(p, 0.5*controls_.minCellSize2))
if (qSurf_.wellInside(p, 0.5*meshControls().minCellSize2()))
{
insert(Point(p.x(), p.y()))->index() = 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<vector2D> 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<point2D> pointsToInsert;
std::list<Point> 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()])
{
remove(vit);
}
else
if (pointToBeRetained[vit->index()])
{
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
);
}
}
// ************************************************************************* //
......@@ -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<Vb> 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<point2D>& nearSurfacePoints,
const DynamicList<point2D>& surfacePoints,
const DynamicList<label>& surfaceTris,
const DynamicList<label>& surfaceHits,
const fileName fName
);
......@@ -266,7 +288,8 @@ private:
(
Triangulation::Finite_vertices_iterator& vit,
const point2D& p,
const label trii
const label trii,
const label hitSurface
);
//- Insert point-pair at the best intersection point between the lines
......@@ -292,9 +315,16 @@ private:
void external_flip(Face_handle& f, int i);
bool internal_flip(Face_handle& f, int i);
//- Write all the faces and all the triangles at a particular stage.
void write(const word& stage) const;
public:
//- Runtime type information
ClassName("CV2D");
// Constructors
//- Construct for given surface
......@@ -313,15 +343,13 @@ public:
// Access
const controls& meshingControls() const
{
return controls_;
}
inline const cv2DControls& meshControls() const;
// Conversion functions between point2D, point and Point
inline const point2D& toPoint2D(const point&) const;
inline const point2DField toPoint2D(const pointField&) const;
inline point toPoint3D(const point2D&) const;
#ifdef CGAL_INEXACT
......
......@@ -33,16 +33,40 @@ inline Foam::label Foam::CV2D::insertPoint
{
uint nVert = number_of_vertices();
Vertex_handle vh = insert(toPoint(p));
return insertPoint(toPoint(p), nVert, type);
}
inline Foam::label Foam::CV2D::insertPoint
(
const point2D& p,
const label index,
const label type
)
{
return insertPoint(toPoint(p), index, type);
}
inline Foam::label Foam::CV2D::insertPoint
(
const Point& p,
const label index,
const label type
)
{
uint nVert = number_of_vertices();
Vertex_handle vh = insert(p);
if (nVert == number_of_vertices())
{
WarningIn("Foam::CV2D::insertPoint")
<< "Failed to insert point " << p << endl;
<< "Failed to insert point " << toPoint2D(p) << endl;
}
else
{
vh->index() = nVert;
vh->index() = index;
vh->type() = type;