From bb4a1820811ddf1438c8746d9186334a470df4f2 Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 6 Apr 2009 13:27:51 +0100 Subject: [PATCH 01/50] comment --- src/OpenFOAM/meshes/boundBox/boundBox.H | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 1f19d13b5a6f4dbb622ba2d4eac8e7e571d53914 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 7 Apr 2009 13:49:33 +0100 Subject: [PATCH 02/50] tolerance to triangle intersection --- .../primitiveShapes/triangle/triangle.H | 7 +- .../primitiveShapes/triangle/triangleI.H | 123 ++++++------------ 2 files changed, 48 insertions(+), 82 deletions(-) diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H index b24149300f..ecc04cbb8b 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H @@ -169,12 +169,15 @@ public: //- 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. + // HALF_RAY. tol increases the virtual size of the triangle + // by a relative factor - can be used to compensate for + // limited precision. 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..876389057e 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; } From bbaa0d57e3a3b94a5d5aa3cbd50a2a6761734f58 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 9 Apr 2009 13:00:21 +0100 Subject: [PATCH 03/50] missing debug symbol --- src/meshTools/indexedOctree/treeDataEdge.C | 5 ++--- src/meshTools/indexedOctree/treeDataPoint.C | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/meshTools/indexedOctree/treeDataEdge.C b/src/meshTools/indexedOctree/treeDataEdge.C index c4bb08f374..12f347c164 100644 --- a/src/meshTools/indexedOctree/treeDataEdge.C +++ b/src/meshTools/indexedOctree/treeDataEdge.C @@ -22,16 +22,15 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -Description - \*---------------------------------------------------------------------------*/ #include "treeDataEdge.H" #include "indexedOctree.H" -#include "polyMesh.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +defineTypeNameAndDebug(Foam::treeDataEdge, 0); + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // diff --git a/src/meshTools/indexedOctree/treeDataPoint.C b/src/meshTools/indexedOctree/treeDataPoint.C index c64fc04ee5..5303156518 100644 --- a/src/meshTools/indexedOctree/treeDataPoint.C +++ b/src/meshTools/indexedOctree/treeDataPoint.C @@ -32,6 +32,11 @@ Description #include "polyMesh.H" #include "triangleFuncs.H" +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(Foam::treeDataPoint, 0); + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Construct from components From db3b8bafdb45cf6ab20fbd39474617f2a704ca1a Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 9 Apr 2009 13:03:33 +0100 Subject: [PATCH 04/50] example of feature edge refinement --- .../constant/triSurface/fridgeA.eMesh | 58 +++++++++++++++++++ .../iglooWithFridges/system/snappyHexMeshDict | 12 ++-- 2 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 tutorials/mesh/snappyHexMesh/iglooWithFridges/constant/triSurface/fridgeA.eMesh diff --git a/tutorials/mesh/snappyHexMesh/iglooWithFridges/constant/triSurface/fridgeA.eMesh b/tutorials/mesh/snappyHexMesh/iglooWithFridges/constant/triSurface/fridgeA.eMesh new file mode 100644 index 0000000000..ff7aab4b8f --- /dev/null +++ b/tutorials/mesh/snappyHexMesh/iglooWithFridges/constant/triSurface/fridgeA.eMesh @@ -0,0 +1,58 @@ +/*---------------------------------------------------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: 1.3.1 | +| \\ / A nd | Web: http://www.openfoam.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ + +FoamFile +{ + version 2.0; + format ascii; + + root ".."; + case "cavity"; + instance ""constant""; + local "polyMesh"; + + class featureEdgeMesh; + object points; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Points +( +(1.99 1.99 0.01) //0 +(3.01 1.99 0.01) //1 +(3.01 3.01 0.01) //2 +(1.99 3.01 0.01) //3 + +(1.99 1.99 2.01) //4 +(3.01 1.99 2.01) //5 +(3.01 3.01 2.01) //6 +(1.99 3.01 2.01) //7 +) + +// Edges +( +(0 1) +(1 2) +(2 3) +(3 0) + +(4 5) +(5 6) +(6 7) +(7 4) + +(0 4) +(1 5) +(2 6) +(3 7) +) + + + +// ************************************************************************* // diff --git a/tutorials/mesh/snappyHexMesh/iglooWithFridges/system/snappyHexMeshDict b/tutorials/mesh/snappyHexMesh/iglooWithFridges/system/snappyHexMeshDict index 19ef2afec1..be30045c6d 100644 --- a/tutorials/mesh/snappyHexMesh/iglooWithFridges/system/snappyHexMeshDict +++ b/tutorials/mesh/snappyHexMesh/iglooWithFridges/system/snappyHexMeshDict @@ -143,10 +143,10 @@ castellatedMeshControls // This is a featureEdgeMesh, read from constant/triSurface for now. features ( -// { -// file "fridgeA.eMesh"; -// level 3; -// } + { + file "fridgeA.eMesh"; + level 3; + } ); @@ -308,6 +308,10 @@ addLayersControls // Create buffer region for new layer terminations nBufferCellsNoExtrude 0; + + + // Overall max number of layer addition iterations + nLayerIter 50; } From c203c3d6fdd12f26700591468cb87ec9764eb9e5 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 9 Apr 2009 13:04:23 +0100 Subject: [PATCH 05/50] fixed layer addition iterations --- .../snappyHexMesh/snappyHexMeshDict | 18 +++ .../autoHexMeshDriver/autoLayerDriver.C | 15 ++- .../layerParameters/layerParameters.C | 38 +++++- .../layerParameters/layerParameters.H | 50 +++++-- .../motionSmoother/motionSmoother.C | 28 +++- .../motionSmoother/motionSmoother.H | 18 ++- .../motionSmoother/motionSmootherCheck.C | 123 +++++++++++++----- 7 files changed, 229 insertions(+), 61 deletions(-) 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/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C index 8d3c0e1e76..c19e0163d4 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