Commit d95f9ac1 authored by graham's avatar graham
Browse files

Incorported CV3DMesher into dev version. Added CGAL and Boost to ThirdParty,...

Incorported CV3DMesher into dev version.  Added CGAL and Boost to ThirdParty, altered template-depth
parent 26ef8829
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Typedefs
CGALTriangulation3Ddefs
Description
CGAL data structures used for 3D Delaunay meshing.
Define CGAL_INEXACT to use Exact_predicates_inexact_constructions kernel
otherwise the more robust but much less efficient
Exact_predicates_exact_constructions will be used.
Define CGAL_HIERARCHY to use hierarchical Delaunay triangulation which is
faster but uses more memory than the standard Delaunay triangulation.
\*---------------------------------------------------------------------------*/
#ifndef CGALTriangulation3Ddefs_H
#define CGALTriangulation3Ddefs_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "CGAL/Delaunay_triangulation_3.h"
#include "indexedVertex.H"
#include "indexedCell.H"
#ifdef CGAL_INEXACT
// Fast kernel using a double as the storage type but the triangulation
// may fail
#include "CGAL/Exact_predicates_inexact_constructions_kernel.h"
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
#else
// Very robust but expensive kernel
#include "CGAL/Exact_predicates_exact_constructions_kernel.h"
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
#endif
typedef CGAL::indexedVertex<K> Vb;
typedef CGAL::indexedCell<K> Cb;
#ifdef CGAL_HIERARCHY
// Data structures for hierarchical Delaunay triangulation which is more
// efficient but also uses more storage
#include "CGAL/Triangulation_hierarchy_3.h"
typedef CGAL::Triangulation_hierarchy_vertex_base_3<Vb> Vbh;
typedef CGAL::Triangulation_data_structure_3<Vbh, Cb> Tds;
typedef CGAL::Delaunay_triangulation_3<K, Tds> Triangulation;
typedef CGAL::Triangulation_hierarchy_3<Triangulation> HTriangulation;
#else
// Data structures for standard Delaunay triangulation
typedef CGAL::Triangulation_data_structure_3<Vb, Cb> Tds;
typedef CGAL::Delaunay_triangulation_3<K, Tds> Triangulation;
typedef Triangulation HTriangulation;
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "CV3D.H"
#include "Random.H"
#include "IFstream.H"
#include "uint.H"
#include "ulong.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::CV3D::insertBoundingBox()
{
Info<< "insertBoundingBox: creating bounding mesh" << nl << endl;
scalar bigSpan = 10*tols_.span;
insertPoint(point(-bigSpan, -bigSpan, -bigSpan), Vb::FAR_POINT);
insertPoint(point(-bigSpan, -bigSpan, bigSpan), Vb::FAR_POINT);
insertPoint(point(-bigSpan, bigSpan, -bigSpan), Vb::FAR_POINT);
insertPoint(point(-bigSpan, bigSpan, bigSpan), Vb::FAR_POINT);
insertPoint(point( bigSpan, -bigSpan, -bigSpan), Vb::FAR_POINT);
insertPoint(point( bigSpan, -bigSpan, bigSpan), Vb::FAR_POINT);
insertPoint(point( bigSpan, bigSpan, -bigSpan), Vb::FAR_POINT);
insertPoint(point( bigSpan, bigSpan , bigSpan), Vb::FAR_POINT);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::CV3D::CV3D
(
const dictionary& controlDict,
const querySurface& qSurf
)
:
HTriangulation(),
qSurf_(qSurf),
controls_(controlDict),
tols_(controlDict, controls_.minCellSize, qSurf.bb()),
startOfInternalPoints_(0),
startOfSurfacePointPairs_(0)
{
// insertBoundingBox();
insertFeaturePoints();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::CV3D::~CV3D()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::CV3D::insertPoints
(
const pointField& points,
const scalar nearness
)
{
Info<< "insertInitialPoints(const pointField& points): ";
startOfInternalPoints_ = number_of_vertices();
label nVert = startOfInternalPoints_;
// Add the points and index them
forAll(points, i)
{
const point& p = points[i];
if (qSurf_.wellInside(p, nearness))
{
insert(toPoint(p))->index() = nVert++;
}
else
{
Warning
<< "Rejecting point " << p << " outside surface" << endl;
}
}
Info<< nVert << " vertices inserted" << endl;
if (controls_.writeInitialTriangulation)
{
// Checking validity of triangulation
assert(is_valid());
writeTriangles("initial_triangles.obj", true);
// writeFaces("initial_faces.obj", true);
}
}
void Foam::CV3D::insertPoints(const fileName& pointFileName)
{
IFstream pointsFile(pointFileName);
if (pointsFile.good())
{
insertPoints(pointField(pointsFile), 0.5*controls_.minCellSize2);
}
else
{
FatalErrorIn("insertInitialPoints")
<< "Could not open pointsFile " << pointFileName
<< exit(FatalError);
}
}
void Foam::CV3D::insertGrid()
{
Info<< "insertInitialGrid: ";
startOfInternalPoints_ = number_of_vertices();
label nVert = startOfInternalPoints_;
scalar x0 = qSurf_.bb().min().x();
scalar xR = qSurf_.bb().max().x() - x0;
int ni = int(xR/controls_.minCellSize) + 1;
scalar y0 = qSurf_.bb().min().y();
scalar yR = qSurf_.bb().max().y() - y0;
int nj = int(yR/controls_.minCellSize) + 1;
scalar z0 = qSurf_.bb().min().z();
scalar zR = qSurf_.bb().max().z() - z0;
int nk = int(zR/controls_.minCellSize) + 1;
vector delta(xR/ni, yR/nj, zR/nk);
delta *= pow((1.0/2.0),-(1.0/3.0));
Random rndGen(1321);
scalar pert = controls_.randomPerturbation*cmptMin(delta);
for (int i=0; i<ni; i++)
{
for (int j=0; j<nj; j++)
{
for (int k=0; k<nk; k++)
{
point p1
(
x0 + i*delta.x(),
y0 + j*delta.y(),
z0 + k*delta.z()
);
point p2 = p1 + 0.5*delta;
if (controls_.randomiseInitialGrid)
{
p1.x() += pert*(rndGen.scalar01() - 0.5);
p1.y() += pert*(rndGen.scalar01() - 0.5);
p1.z() += pert*(rndGen.scalar01() - 0.5);
}
if (qSurf_.wellInside(p1, 0.5*controls_.minCellSize2))
{
insert(Point(p1.x(), p1.y(), p1.z()))->index() = nVert++;
}
if (controls_.randomiseInitialGrid)
{
p2.x() += pert*(rndGen.scalar01() - 0.5);
p2.y() += pert*(rndGen.scalar01() - 0.5);
p2.z() += pert*(rndGen.scalar01() - 0.5);
}
if (qSurf_.wellInside(p2, 0.5*controls_.minCellSize2))
{
insert(Point(p2.x(), p2.y(), p2.z()))->index() = nVert++;
}
}
}
}
Info<< nVert << " vertices inserted" << nl << endl;
if (controls_.writeInitialTriangulation)
{
// Checking validity of triangulation
assert(is_valid());
writePoints("initial_points.obj", true);
writeTriangles("initial_triangles.obj", true);
// writeFaces("initial_faces.obj", true);
}
}
void Foam::CV3D::insertSurfacePointPairs()
{
startOfSurfacePointPairs_ = number_of_vertices();
if (controls_.insertSurfaceNearestPointPairs)
{
insertSurfaceNearestPointPairs();
}
// if (controls_.writeNearestTriangulation)
// {
// writeFaces("near_allFaces.obj", false);
// writeFaces("near_faces.obj", true);
// writeTriangles("near_triangles.obj", true);
// }
if (controls_.insertSurfaceNearPointPairs)
{
insertSurfaceNearPointPairs();
}
}
void Foam::CV3D::boundaryConform()
{
}
void Foam::CV3D::removeSurfacePointPairs()
{
}
void Foam::CV3D::write() const
{
if (controls_.writeFinalTriangulation)
{
writePoints("allPoints.obj", false);
writePoints("points.obj", true);
// writeFaces("allFaces.obj", false);
// writeFaces("faces.obj", true);
writeTriangles("allTriangles.obj", false);
writeTriangles("triangles.obj", true);
// writeMesh();
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
CV3D
Description
SourceFiles
CV3DI.H
CV3D.C
CV3DIO.C
controls.C
tolerances.C
insertFeaturePoints.C
insertSurfaceNearestPointPairs.C
insertSurfaceNearPointPairs.C
\*---------------------------------------------------------------------------*/
#ifndef CV3D_H
#define CV3D_H
#define CGAL_INEXACT
#define CGAL_HIERARCHY
#include "CGALTriangulation3Ddefs.H"
#include "querySurface.H"
#include "dictionary.H"
#include "DynamicList.H"
#include "Switch.H"
#include "Time.H"
#include "polyMesh.H"
#include "SortableList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class CV3D Declaration
\*---------------------------------------------------------------------------*/
class CV3D
:
public HTriangulation
{
public:
class controls
{
public:
//- Minimum cell size below which protusions through the surface are
// not split
scalar minCellSize;
//- Square of minCellSize
scalar minCellSize2;
//- The feature angle used to select corners to be
// explicitly represented in the mesh.
// 0 = all features, 180 = no features
scalar featAngle;
//- Maximum quadrant angle allowed at a concave corner before
// additional "mitering" lines are added
scalar maxQuadAngle;
//- Insert near-boundary point mirror or point-pairs
Switch insertSurfaceNearestPointPairs;
//- Insert point-pairs for dual-cell vertices very near the surface
Switch insertSurfaceNearPointPairs;
Switch writeInitialTriangulation;
Switch writeFeatureTriangulation;
Switch writeNearestTriangulation;
Switch writeInsertedPointPairs;
Switch writeFinalTriangulation;
Switch randomiseInitialGrid;
scalar randomPerturbation;
controls(const dictionary& controlDict);
};
class tolerances
{
public:
//- Maximum cartesian span of the geometry
scalar span;
//- Distance between boundary conforming point-pairs
scalar ppDist;
//- Square of ppDist
scalar ppDist2;
tolerances
(
const dictionary& controlDict,
scalar minCellSize,
const boundBox&
);
};
private:
// Private data
//- The surface to mesh
const querySurface& qSurf_;
//- Meshing controls
controls controls_;
//- Meshing tolerances
tolerances tols_;
//- Keep track of the start of the internal points
label startOfInternalPoints_;
//- Keep track of the start of the surface point-pairs
label startOfSurfacePointPairs_;
// Private Member Functions
//- Disallow default bitwise copy construct
CV3D(const CV3D&);
//- Disallow default bitwise assignment
void operator=(const CV3D&);
//- Insert point and return it's index
inline label insertPoint
(
const point& pt,
const label type
);
//- Create the initial mesh from the bounding-box
void insertBoundingBox();
//- Insert point-pairs at the nearest points on the surface to the
// control vertex of dual-cells which intersect the boundary in order
// to provide a boundary-layer mesh.
// NB: This is not guaranteed to close the boundary
void insertSurfaceNearestPointPairs();
//- Insert point-pairs at small dual-cell edges on the surface in order
// to improve the boundary-layer mesh generated by
// insertSurfaceNearestPointPairs.
void insertSurfaceNearPointPairs();
//- Dual calculation
void calcDualMesh
(
pointField& points,
faceList& faces,
labelList& owner,
labelList& neighbour,
wordList& patchNames,
labelList& patchSizes,
labelList& patchStarts
);
public:
// Constructors
//- Construct for given surface
CV3D(const dictionary& controlDict, const querySurface& qSurf);
// Destructor
~CV3D();
// Member Functions
// Access
const controls& meshingControls() const
{
return controls_;
}
// Conversion functions between point and Point
# ifdef CGAL_INEXACT
typedef const point& pointFromPoint;
typedef const Point& PointFrompoint;
# else
typedef point pointFromPoint;
typedef Point PointFrompoint;
# endif
inline pointFromPoint topoint(const Point&) const;
inline PointFrompoint toPoint(const point&) const;
// Point insertion
//- Create the initial mesh from the given internal points.
// Points must be inside the boundary by at least nearness
// otherwise they are ignored.
void insertPoints
(
const pointField& points,
const scalar nearness
);
//- Create the initial mesh from the internal points in the given
// file. Points outside the geometry are ignored.
void insertPoints(const fileName& pointFileName);
//- Create the initial mesh as a regular grid of points.
// Points outside the geometry are ignored.
void insertGrid();
//- Insert point groups at the feature points.
void insertFeaturePoints();
//- Insert all surface point-pairs from
// insertSurfaceNearestPointPairs and
// findIntersectionForOutsideCentroid
void insertSurfacePointPairs();
//- Insert point-pairs where there are protrusions into
// or out of the surface
void boundaryConform();
// Point removal