diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict index cc975eb970..205c767600 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict @@ -274,6 +274,14 @@ addLayersControls // Create buffer region for new layer terminations nBufferCellsNoExtrude 0; + + + // Overall max number of layer addition iterations + nLayerIter 50; + + // Max number of iterations after which relaxed meshQuality controls + // get used. + nRelaxedIter 20; } @@ -335,6 +343,16 @@ meshQualityControls nSmoothScale 4; //- amount to scale back displacement at error points errorReduction 0.75; + + + + // Optional : some meshing phases allow usage of relaxed rules. + // See e.g. addLayersControls::nRelaxedIter. + relaxed + { + //- Maximum non-orthogonality allowed. Set to 180 to disable. + maxNonOrtho 75; + } } diff --git a/applications/utilities/surface/surfaceCheck/surfaceCheck.C b/applications/utilities/surface/surfaceCheck/surfaceCheck.C index e7b7890074..4731ed3ec2 100644 --- a/applications/utilities/surface/surfaceCheck/surfaceCheck.C +++ b/applications/utilities/surface/surfaceCheck/surfaceCheck.C @@ -171,11 +171,11 @@ int main(int argc, char *argv[]) argList::validArgs.clear(); argList::validArgs.append("surface file"); - argList::validOptions.insert("noSelfIntersection", ""); + argList::validOptions.insert("checkSelfIntersection", ""); argList::validOptions.insert("verbose", ""); argList args(argc, argv); - bool checkSelfIntersection = !args.options().found("noSelfIntersection"); + bool checkSelfIntersection = args.options().found("checkSelfIntersection"); bool verbose = args.options().found("verbose"); fileName surfFileName(args.additionalArgs()[0]); diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H index e41b6efa46..38b852ef66 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.H +++ b/src/OpenFOAM/meshes/boundBox/boundBox.H @@ -174,7 +174,7 @@ public: // Query - //- Completely contains other boundingBox? (inside or on edge) + //- Overlaps/touches boundingBox? bool overlaps(const boundBox& bb) const { return diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index 07dd39f93f..25a4f8fbce 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -222,16 +222,16 @@ public: ) const; //- Fast intersection with a ray. - // For a hit, the pointHit.distance() is the line parameter t : - // intersection=p+t*q. Only defined for FULL_RAY or - // HALF_RAY. + // Does face-center decomposition and returns triangle intersection + // point closest to p. See triangle::intersection for details. pointHit intersection ( const point& p, const vector& q, const point& ctr, const pointField& meshPoints, - const intersection::algorithm alg + const intersection::algorithm alg, + const scalar tol = 0.0 ) const; //- Return nearest point to face diff --git a/src/OpenFOAM/meshes/meshShapes/face/faceIntersection.C b/src/OpenFOAM/meshes/meshShapes/face/faceIntersection.C index b514af7749..c5f9a80250 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/faceIntersection.C +++ b/src/OpenFOAM/meshes/meshShapes/face/faceIntersection.C @@ -136,7 +136,8 @@ Foam::pointHit Foam::face::intersection const vector& q, const point& ctr, const pointField& meshPoints, - const intersection::algorithm alg + const intersection::algorithm alg, + const scalar tol ) const { scalar nearestHitDist = VGREAT; @@ -154,7 +155,7 @@ Foam::pointHit Foam::face::intersection meshPoints[f[pI]], meshPoints[f[fcIndex(pI)]], ctr - ).intersection(p, q, alg); + ).intersection(p, q, alg, tol); if (curHit.hit()) { diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H index b24149300f..1165046636 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H @@ -153,7 +153,7 @@ public: inline scalar sweptVol(const triangle& t) const; //- Return point intersection with a ray. - // For a hit, the distance is signed. Positive number + // For a hit, the distance is signed. Positive number // represents the point in front of triangle. // In case of miss pointHit is set to nearest point // on triangle and its distance to the distance between @@ -166,15 +166,20 @@ public: const intersection::direction dir = intersection::VECTOR ) const; - //- Fast intersection with a ray. - // For a hit, the pointHit.distance() is the line parameter t : - // intersection=p+t*q. Only defined for VISIBLE, FULL_RAY or - // HALF_RAY. + //- Fast intersection with a ray. Distance is normalised distance + // to the intersection (normalised with the vector magnitude). + // For a hit, the distance is signed. Positive number + // represents the point in front of triangle. In case of miss + // pointHit position is undefined. + // Only defined for VISIBLE, FULL_RAY or + // HALF_RAY. tol increases the virtual size of the triangle + // by a relative factor. inline pointHit intersection ( const point& p, const vector& q, - const intersection::algorithm alg + const intersection::algorithm alg, + const scalar tol = 0.0 ) const; //- Return nearest point to p on triangle diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H index ad7ed2ea8b..33b3cab15e 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H @@ -439,7 +439,8 @@ inline pointHit triangle::intersection ( const point& orig, const vector& dir, - const intersection::algorithm alg + const intersection::algorithm alg, + const scalar tol ) const { const vector edge1 = b_ - a_; @@ -457,99 +458,61 @@ inline pointHit triangle::intersection if (alg == intersection::VISIBLE) { // Culling branch - if (det < SMALL) + if (det < ROOTVSMALL) { - // return miss + // Ray on wrong side of triangle. Return miss return intersection; } - /* calculate distance from a_ to ray origin */ - const vector tVec = orig-a_; - - /* calculate U parameter and test bounds */ - scalar u = tVec & pVec; - - if (u < 0.0 || u > det) - { - // return miss - return intersection; - } - - /* prepare to test V parameter */ - const vector qVec = tVec ^ edge1; - - /* calculate V parameter and test bounds */ - scalar v = dir & qVec; - - if (v < 0.0 || u + v > det) - { - // return miss - return intersection; - } - - /* calculate t, scale parameters, ray intersects triangle */ - scalar t = edge2 & qVec; - scalar inv_det = 1.0 / det; - t *= inv_det; - u *= inv_det; - v *= inv_det; - - intersection.setHit(); - intersection.setPoint(a_ + u*edge1 + v*edge2); - intersection.setDistance(t); } else if (alg == intersection::HALF_RAY || alg == intersection::FULL_RAY) { // Non-culling branch - if (det > -SMALL && det < SMALL) + if (det > -ROOTVSMALL && det < ROOTVSMALL) { - // return miss + // Ray parallel to triangle. Return miss return intersection; } - const scalar inv_det = 1.0 / det; - - /* calculate distance from a_ to ray origin */ - const vector tVec = orig - a_; - /* calculate U parameter and test bounds */ - const scalar u = (tVec & pVec)*inv_det; - - if (u < 0.0 || u > 1.0) - { - // return miss - return intersection; - } - /* prepare to test V parameter */ - const vector qVec = tVec ^ edge1; - /* calculate V parameter and test bounds */ - const scalar v = (dir & qVec) * inv_det; - - if (v < 0.0 || u + v > 1.0) - { - // return miss - return intersection; - } - /* calculate t, ray intersects triangle */ - const scalar t = (edge2 & qVec) * inv_det; - - if (alg == intersection::HALF_RAY && t < 0) - { - // return miss - return intersection; - } - - intersection.setHit(); - intersection.setPoint(a_ + u*edge1 + v*edge2); - intersection.setDistance(t); } - else + + const scalar inv_det = 1.0 / det; + + /* calculate distance from a_ to ray origin */ + const vector tVec = orig-a_; + + /* calculate U parameter and test bounds */ + const scalar u = (tVec & pVec)*inv_det; + + if (u < -tol || u > 1.0+tol) { - FatalErrorIn - ( - "triangle::intersection(const point&" - ", const vector&, const intersection::algorithm)" - ) << "intersection only defined for VISIBLE, FULL_RAY or HALF_RAY" - << abort(FatalError); + // return miss + return intersection; } + /* prepare to test V parameter */ + const vector qVec = tVec ^ edge1; + + /* calculate V parameter and test bounds */ + const scalar v = (dir & qVec) * inv_det; + + if (v < -tol || u + v > 1.0+tol) + { + // return miss + return intersection; + } + + /* calculate t, scale parameters, ray intersects triangle */ + const scalar t = (edge2 & qVec) * inv_det; + + if (alg == intersection::HALF_RAY && t < -tol) + { + // Wrong side of orig. Return miss + return intersection; + } + + intersection.setHit(); + intersection.setPoint(a_ + u*edge1 + v*edge2); + intersection.setDistance(t); + return intersection; } @@ -622,7 +585,7 @@ inline bool triangle::classify bool hit = false; - if (Foam::mag(u1) < SMALL) + if (Foam::mag(u1) < ROOTVSMALL) { beta = u0/u2; diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.H b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.H index 9ae910b5a7..c0b7668d0a 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.H +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.H @@ -38,7 +38,6 @@ SourceFiles #include "autoPtr.H" #include "dictionary.H" -#include "boolList.H" #include "wallPoint.H" #include "searchableSurfaces.H" #include "refinementSurfaces.H" diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C index 8d3c0e1e76..0859e37d33 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C @@ -2292,7 +2292,7 @@ bool Foam::autoLayerDriver::cellsUseFace Foam::label Foam::autoLayerDriver::checkAndUnmark ( const addPatchCellLayer& addLayer, - const dictionary& motionDict, + const dictionary& meshQualityDict, const indirectPrimitivePatch& pp, const fvMesh& newMesh, @@ -2304,7 +2304,7 @@ Foam::label Foam::autoLayerDriver::checkAndUnmark // Check the resulting mesh for errors Info<< nl << "Checking mesh with layer ..." << endl; faceSet wrongFaces(newMesh, "wrongFaces", newMesh.nFaces()/1000); - motionSmoother::checkMesh(false, newMesh, motionDict, wrongFaces); + motionSmoother::checkMesh(false, newMesh, meshQualityDict, wrongFaces); Info<< "Detected " << returnReduce(wrongFaces.size(), sumOp