Commit aa8f5626 authored by Franjo's avatar Franjo
Browse files

Initial version of surface checks

parent 7035d077
...@@ -281,13 +281,13 @@ label checkForHoles(const triSurf& surf, labelLongList& badTriangles) ...@@ -281,13 +281,13 @@ label checkForHoles(const triSurf& surf, labelLongList& badTriangles)
return badTriangles.size(); return badTriangles.size();
} }
label checkForHoles(triSurf& surf, const word subsetPrefix) label checkForHoles(triSurf& surf, const word subsetName)
{ {
labelLongList trianglesNearHoles; labelLongList trianglesNearHoles;
if( checkForHoles(surf, trianglesNearHoles) ) if( checkForHoles(surf, trianglesNearHoles) )
{ {
const label setId = surf.addFacetSubset(subsetPrefix); const label setId = surf.addFacetSubset(subsetName);
forAll(trianglesNearHoles, i) forAll(trianglesNearHoles, i)
surf.addFacetToSubset(setId, trianglesNearHoles[i]); surf.addFacetToSubset(setId, trianglesNearHoles[i]);
...@@ -623,6 +623,13 @@ label checkSelfIntersections ...@@ -623,6 +623,13 @@ label checkSelfIntersections
{ {
const labelledTri& tri = surf[tI]; const labelledTri& tri = surf[tI];
const triangle<point, point> currTri
(
pts[tri[0]],
pts[tri[1]],
pts[tri[2]]
);
boundBox bb(pts[tri[0]], pts[tri[0]]); boundBox bb(pts[tri[0]], pts[tri[0]]);
for(label i=1;i<3;++i) for(label i=1;i<3;++i)
{ {
...@@ -649,21 +656,23 @@ label checkSelfIntersections ...@@ -649,21 +656,23 @@ label checkSelfIntersections
if( tI >= triJ ) if( tI >= triJ )
continue; continue;
point int0, int1; const triangle<point, point> neiTri
(
pts[nt[0]],
pts[nt[1]],
pts[nt[2]]
);
FixedList<point, 2> intersectionEdge;
const bool intersect = const bool intersect =
triangleFuncs::intersect help::doTrianglesIntersect
( (
pts[tri[0]], currTri,
pts[tri[1]], neiTri,
pts[tri[2]], intersectionEdge,
tol,
pts[nt[0]], Foam::cos(5.0 * M_PI / 180.0)
pts[nt[1]],
pts[nt[2]],
int0,
int1
); );
if( intersect ) if( intersect )
...@@ -728,6 +737,13 @@ label checkOverlaps ...@@ -728,6 +737,13 @@ label checkOverlaps
{ {
const labelledTri& tri = surf[tI]; const labelledTri& tri = surf[tI];
const triangle<point, point> currTri
(
pts[tri[0]],
pts[tri[1]],
pts[tri[2]]
);
boundBox bb(pts[tri[0]], pts[tri[0]]); boundBox bb(pts[tri[0]], pts[tri[0]]);
for(label i=1;i<3;++i) for(label i=1;i<3;++i)
{ {
...@@ -754,21 +770,23 @@ label checkOverlaps ...@@ -754,21 +770,23 @@ label checkOverlaps
if( tI >= triJ ) if( tI >= triJ )
continue; continue;
point int0, int1; const triangle<point, point> neiTri
(
pts[nt[0]],
pts[nt[1]],
pts[nt[2]]
);
DynList<point> intersectionPolygon;
const bool intersect = const bool intersect =
triangleFuncs::intersect help::doTrianglesOverlap
( (
pts[tri[0]], currTri,
pts[tri[1]], neiTri,
pts[tri[2]], intersectionPolygon,
tol,
pts[nt[0]], Foam::cos(angleTol * M_PI / 180.0)
pts[nt[1]],
pts[nt[2]],
int0,
int1
); );
if( intersect ) if( intersect )
......
...@@ -74,7 +74,7 @@ label checkSurfaceManifolds(triSurf&, const word subsetPrefix="manifold_"); ...@@ -74,7 +74,7 @@ label checkSurfaceManifolds(triSurf&, const word subsetPrefix="manifold_");
//- check for existence of holes in the surface mesh //- check for existence of holes in the surface mesh
label checkForHoles(const triSurf&, labelLongList&); label checkForHoles(const triSurf&, labelLongList&);
label checkForHoles(triSurf&, const word subsetPrefix="hole_"); label checkForHoles(triSurf&, const word subsetName="holes");
//- check for existence of non-manifold edges //- check for existence of non-manifold edges
label checkForNonManifoldEdges(const triSurf&, labelLongList&); label checkForNonManifoldEdges(const triSurf&, labelLongList&);
......
...@@ -30,12 +30,8 @@ Description ...@@ -30,12 +30,8 @@ Description
#include "IFstream.H" #include "IFstream.H"
#include "fileName.H" #include "fileName.H"
#include "triSurf.H" #include "triSurf.H"
#include "triSurfModifier.H" #include "triSurfaceChecks.H"
#include "helperFunctions.H" #include "boundBox.H"
#include "demandDrivenData.H"
#include "coordinateModifier.H"
#include "checkMeshDict.H"
#include "surfaceMeshGeometryModification.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:
...@@ -43,79 +39,106 @@ using namespace Foam; ...@@ -43,79 +39,106 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
# include "setRootCase.H" argList::noParallel();
# include "createTime.H" argList::validArgs.clear();
argList::validArgs.append("input surface file");
IOdictionary meshDict argList args(argc, argv);
(
IOobject fileName inFileName(args.args()[1]);
(
"meshDict", triSurf surf(inFileName);
runTime.system(),
runTime, label nFailed(0);
IOobject::MUST_READ,
IOobject::NO_WRITE boundBox bb;
) triSurfaceChecks::calculateBoundingBox(surf, bb);
); Info << "Surface bounding box is " << bb << endl;
checkMeshDict cmd(meshDict); //- calculate manifolds
const label nManifolds = triSurfaceChecks::checkSurfaceManifolds(surf);
fileName surfaceFile = meshDict.lookup("surfaceFile"); if( nManifolds > 1 )
if( Pstream::parRun() ) {
surfaceFile = ".."/surfaceFile; ++nFailed;
triSurf surface(runTime.path()/surfaceFile); Info << "Surface mesh consists of " << nManifolds
<< " manifolds." << endl;
surfaceMeshGeometryModification gMod(surface, meshDict); Warning << "You cannot mesh geometries consisting of more than"
<< " one domain, and it must not contain baffles." << endl;
//- modify points }
const triSurf* modSurfPtr = gMod.modifyGeometry(); else
Info << "Writting modified surface" << endl;
modSurfPtr->writeSurface("modifiedSurf.stl");
# ifdef DEBUGScaling
//- apply backward modification
Info << "Here" << endl;
coordinateModifier cMod(meshDict.subDict("anisotropicSources"));
Info << "Starting modifications" << endl;
forAll(surface.points(), i)
{ {
Info << "\nOrig point " << i << " coordinates " << surface.points()[i] Info << "Surface mesh consists of a single manifold." << endl;
<< " modified point " << modSurfPtr->points()[i] << endl;
const point p = cMod.backwardModifiedPoint(modSurfPtr->points()[i]);
if( mag(p - surface.points()[i]) > 1e-14 )
{
Warning << "Point " << i << " is different "
<< p
<< " from original " << surface.points()[i]
<< " modified point "
<< cMod.modifiedPoint(surface.points()[i]) << endl;
::exit(0);
}
} }
Info << "Backscaling Ok" << endl; //- find open boundary edges
::exit(0); if( triSurfaceChecks::checkForHoles(surf) )
# endif {
++nFailed;
surfaceMeshGeometryModification bgMod(*modSurfPtr, meshDict); Info << "Surface mesh has open boundaries!!" << endl;
const triSurf* backModSurfPtr = bgMod.revertGeometryModification(); Warning << "This indicates that there may be some holes in the surface"
<< " mesh. Holes in the mesh must be smaller than the specified"
<< " cell size at this location. In addition, please avoid"
<< " using automatic refinement (minCellSize)." << endl;
}
else
{
Info << "No holes found in the surface mesh." << endl;
}
Info << "Writting backward transformed surface" << endl; //- find non-manifold edges
backModSurfPtr->writeSurface("backwardModifiedSurf.stl"); if( triSurfaceChecks::checkForNonManifoldEdges(surf) )
{
++nFailed;
# ifdef DEBUGScaling Info << "Surface mesh has non-manifold edges!!" << endl;
forAll(backModSurfPtr->points(), pI) Warning << "This indicates that the surface mesh consists of multiple"
if( mag(backModSurfPtr->points()[pI] - surface.points()[pI]) > 1e-14 ) << " domains and/or baffles. Please make sure that they are not"
Warning << "Point " << pI << " is different " << " in the domain which shall be meshed." << endl;
<< backModSurfPtr->points()[pI] }
<< " from original " << surface.points()[pI] << endl; else
# endif {
Info << "Surface does not have any non-manifold edges." << endl;
}
deleteDemandDrivenData(modSurfPtr); //- check the number of disconnected parts
deleteDemandDrivenData(backModSurfPtr); if( triSurfaceChecks::checkDisconnectedParts(surf) > 1 )
{
++nFailed;
Info << "Surface mesh consists of disconnected parts." << endl;
Warning << "This is not a problem if there exists a region surrounding"
<< " the other ones! In other case, the mesher will generate"
<< " the mesh in the domains with most cells." << endl;
}
else
{
Info << "Surface mesh consists of a single region." << endl;
}
//- find triangles with small angles
if( triSurfaceChecks::checkAngles(surf, "smallAngles", 1.0) )
{
++nFailed;
Info << "Surface mesh has some bad-quality triangles." << endl;
Warning << "This may cause problems to the automatic refinement"
<< " procedure (minCellSize). " << endl;
}
else
{
Info << "No sliver triangles found." << endl;
}
if( nFailed )
{
Warning << "Found " << nFailed
<< " checks indicating potential problems." << endl;
Warning << "This does not mean that you cannot generate"
<< " a valid mesh. " << endl;
surf.writeSurface(inFileName);
}
Info << "End\n" << endl; Info << "End\n" << endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment