CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Meshing & Mesh Conversion

[snappyHexMesh] snappyHexMesh creates inverted meshes

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 27, 2017, 09:50
Default snappyHexMesh creates inverted meshes
  #1
New Member
 
Eddie
Join Date: Feb 2017
Location: Copenhagen, Denmark
Posts: 5
Rep Power: 9
emat is on a distinguished road
Hello,

I'm getting started with OpenFOAM. I've never done any CFD before - and I've spent the last few days doing a few tutorials and trying to get to grips with everything. I'm particularly interested in learning how to model the performance of heat sinks, using the conjugate flow models.

I'm modelling my geometry in SketchUp, and exporting to stl. I already discovered that the meshing wasn't good enough, which was giving me problems, but MeshFix appears to have solved these for me.

I'm now getting really nice meshes... with one problem, the names are swapped! I've uploaded two stl files, corresponding to my two geometries ("air" and "fin"). After running blockMesh, surfaceFeatureExtract, and snappyHexMesh, I get two really nice meshes, but the one that has the "fin" geometry is called "air", and the one that has the "air" geometry is called "fin"! I've search the dictionaries for areas where I might have got the naming swapped, but couldn't find anything. I am not fluent with snappyHexMesh yet. I've read a lot of the documentation and help, but I couldn't determine how to fix this issue. I'm hoping it will be much easier to get familiar with the tool once I've got a functional work flow, and I can tweak parameters and observe the results. Until then, I'd be grateful for any help offered!

The stl files are uploaded, and I'll paste in my dictionary files below. Let me know if there's anything missing you'd like to see.

blockMeshDict:
Code:
convertToMeters 1;

vertices
(
    (0     0     0)
    (0.15  0     0)
    (0.15  0.08  0)
    (0     0.08  0)
    (0     0     0.15)
    (0.15  0     0.15)
    (0.15  0.08  0.15)
    (0     0.08  0.15)
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (30 16 30) simpleGrading (1 1 1)
);

edges
(
);

boundary
(
    maxY
    {
        type patch;
        faces
        (
            (3 7 6 2)
        );
    }
    minX
    {
        type patch;
        faces
        (
            (0 4 7 3)
        );
    }
    maxX
    {
        type patch;
        faces
        (
            (2 6 5 1)
        );
    }
    minY
    {
        type patch;
        faces
        (
            (1 5 4 0)
        );
    }
    minZ
    {
        type patch;
        faces
        (
            (0 3 2 1)
        );
    }
    maxZ
    {
        type patch;
        faces
        (
            (4 5 6 7)
        );
    }
);

mergePatchPairs
(
);
surfaceFeatureExtractDict:
Code:
air.stl
{
    extractionMethod    extractFromSurface;

    extractFromSurfaceCoeffs
    {
        // Mark edges whose adjacent surface normals are at an angle less
        // than includedAngle as features
        // - 0  : selects no edges
        // - 180: selects all edges
        includedAngle   100;
    }

    // Write options
    writeFeatureEdgeMesh    yes;
}
fin.stl
{
    extractionMethod    extractFromSurface;

    extractFromSurfaceCoeffs
    {
        // Mark edges whose adjacent surface normals are at an angle less
        // than includedAngle as features
        // - 0  : selects no edges
        // - 180: selects all edges
        includedAngle   100;
    }

    // Write options
    writeFeatureEdgeMesh    yes;
}
snappyHexMeshDict:
Code:
// Which of the steps to run
castellatedMesh true;
snap            true;
addLayers       false;


// Geometry. Definition of all surfaces. All surfaces are of class
// searchableSurface.
// Surfaces are used
// - to specify refinement for any mesh cell intersecting it
// - to specify refinement for any mesh cell inside/outside/near
// - to 'snap' the mesh boundary to the surface
geometry
{
    air.stl
    {
        type triSurfaceMesh;
        name air;
    }

    fin.stl
    {
        type triSurfaceMesh;
        name fin;
    }
};



// Settings for the castellatedMesh generation.
castellatedMeshControls
{

    // Refinement parameters
    // ~~~~~~~~~~~~~~~~~~~~~

    // If local number of cells is >= maxLocalCells on any processor
    // switches from from refinement followed by balancing
    // (current method) to (weighted) balancing before refinement.
    maxLocalCells 100000;

    // Overall cell limit (approximately). Refinement will stop immediately
    // upon reaching this number so a refinement level might not complete.
    // Note that this is the number of cells before removing the part which
    // is not 'visible' from the keepPoint. The final number of cells might
    // actually be a lot less.
    maxGlobalCells 2000000;

    // The surface refinement loop might spend lots of iterations
    // refining just a few cells. This setting will cause refinement
    // to stop if <= minimumRefine are selected for refinement. Note:
    // it will at least do one iteration (unless the number of cells
    // to refine is 0)
    minRefinementCells 10;

    // Number of buffer layers between different levels.
    // 1 means normal 2:1 refinement restriction, larger means slower
    // refinement.
    nCellsBetweenLevels 2;



    // Explicit feature edge refinement
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    // Specifies a level for any cell intersected by its edges.
    // This is a featureEdgeMesh, read from constant/triSurface for now.
    features
    (
        {
            file "air.eMesh";
            level 1;
        }
        {
            file "fin.eMesh";
            level 1;
        }
    );



    // Surface based refinement
    // ~~~~~~~~~~~~~~~~~~~~~~~~

    // Specifies two levels for every surface. The first is the minimum level,
    // every cell intersecting a surface gets refined up to the minimum level.
    // The second level is the maximum level. Cells that 'see' multiple
    // intersections where the intersections make an
    // angle > resolveFeatureAngle get refined up to the maximum level.

    refinementSurfaces
    {
        air
        {
            // Surface-wise min and max refinement level
            level (1 3);

            faceZone air;
            cellZone air;
            cellZoneInside inside;
        }

        fin
        {
            // Surface-wise min and max refinement level
            level (1 3);

            faceZone fin;
            cellZone fin;
            cellZoneInside inside;
        }

    }

    // Resolve sharp angles
    resolveFeatureAngle 30;


    // Region-wise refinement
    // ~~~~~~~~~~~~~~~~~~~~~~

    // Specifies refinement level for cells in relation to a surface. One of
    // three modes
    // - distance. 'levels' specifies per distance to the surface the
    //   wanted refinement level. The distances need to be specified in
    //   descending order.
    // - inside. 'levels' is only one entry and only the level is used. All
    //   cells inside the surface get refined up to the level. The surface
    //   needs to be closed for this to be possible.
    // - outside. Same but cells outside.

    refinementRegions
    {
        //refinementBox
        //{
        //    mode inside;
        //    levels ((1E15 4));
        //}
    }


    // Mesh selection
    // ~~~~~~~~~~~~~~

    // After refinement patches get added for all refinementSurfaces and
    // all cells intersecting the surfaces get put into these patches. The
    // section reachable from the locationInMesh is kept.
    // NOTE: This point should never be on a face, always inside a cell, even
    // after refinement.
    locationInMesh (0.0751 0.001 0.0751);


    // Whether any faceZones (as specified in the refinementSurfaces)
    // are only on the boundary of corresponding cellZones or also allow
    // free-standing zone faces. Not used if there are no faceZones.
    allowFreeStandingZoneFaces false;
}



// Settings for the snapping.
snapControls
{
    //- Number of patch smoothing iterations before finding correspondence
    //  to surface
    nSmoothPatch 3;

    //- Relative distance for points to be attracted by surface feature point
    //  or edge. True distance is this factor times local
    //  maximum edge length.
    tolerance 1.0;

    //- Number of mesh displacement relaxation iterations.
    nSolveIter 30;

    //- Maximum number of snapping relaxation iterations. Should stop
    //  before upon reaching a correct mesh.
    nRelaxIter 5;

    //- Highly experimental and wip: number of feature edge snapping
    //  iterations. Leave out altogether to disable.
    //  Of limited use in this case since faceZone faces not handled.
    nFeatureSnapIter 10;
}



// Settings for the layer addition.
addLayersControls
{
    relativeSizes true;

    // Per final patch (so not geometry!) the layer information
    layers
    {
    }

    // Expansion factor for layer mesh
    expansionRatio 1.3;

    // Wanted thickness of final added cell layer. If multiple layers
    // is the thickness of the layer furthest away from the wall.
    // Relative to undistorted size of cell outside layer.
    // See relativeSizes parameter.
    finalLayerThickness 1;

    // Minimum thickness of cell layer. If for any reason layer
    // cannot be above minThickness do not add layer.
    // Relative to undistorted size of cell outside layer.
    minThickness 0.1;

    // If points get not extruded do nGrow layers of connected faces that are
    // also not grown. This helps convergence of the layer addition process
    // close to features.
    // Note: changed(corrected) w.r.t 17x! (didn't do anything in 17x)
    nGrow 0;

    // Advanced settings

    // When not to extrude surface. 0 is flat surface, 90 is when two faces
    // are perpendicular
    featureAngle 30;

    // Maximum number of snapping relaxation iterations. Should stop
    // before upon reaching a correct mesh.
    nRelaxIter 3;

    // Number of smoothing iterations of surface normals
    nSmoothSurfaceNormals 1;

    // Number of smoothing iterations of interior mesh movement direction
    nSmoothNormals 3;

    // Smooth layer thickness over surface patches
    nSmoothThickness 2;

    // Stop layer growth on highly warped cells
    maxFaceThicknessRatio 0.5;

    // Reduce layer growth where ratio thickness to medial
    // distance is large
    maxThicknessToMedialRatio 1;

    // Angle used to pick up medial axis points
    // Note: changed(corrected) w.r.t 17x! 90 degrees corresponds to 130 in 17x.
    minMedianAxisAngle 90;

    // Create buffer region for new layer terminations
    nBufferCellsNoExtrude 0;

    // Overall max number of layer addition iterations. The mesher will exit
    // if it reaches this number of iterations; possibly with an illegal
    // mesh.
    nLayerIter 50;
}



// Generic mesh quality settings. At any undoable phase these determine
// where to undo.
meshQualityControls
{
    #include "meshQualityDict"

    // Advanced

    //- Number of error distribution iterations
    nSmoothScale 4;
    //- Amount to scale back displacement at error points
    errorReduction 0.75;
}


// Advanced

// Merge tolerance. Is fraction of overall bounding box of initial mesh.
// Note: the write tolerance needs to be higher than this.
mergeTolerance 1e-6;
These dictionary files were taken from the "chtMultiRegionFoam" tutorial and I have tried to modify them for my own case correctly, but there's a good chance I have failed in that respect! I confess that I've not tried all of the measures described in Tobi's sticky post, but my instinct was that (especially since I've run MeshFix on my stls), the cause of this had a rather simple explanation. So I thought I'd see if a second pair of eyes would help!

Many thanks in advance for any help offered.

Best,

Eddie
Attached Files
File Type: zip stl files.zip (3.1 KB, 4 views)
emat is offline   Reply With Quote

Old   February 28, 2017, 03:28
Default
  #2
j91
New Member
 
Join Date: Jan 2017
Posts: 4
Rep Power: 9
j91 is on a distinguished road
At a glance - would you possibly be trying to mesh the inside of the fin as well as the air domain? The idea of snappyHexMesh is to take the uniform blockMesh, remove the cells that are inside a solid object (like your heatsink), snap the cells outside of it to its surface and then refine them, a la the pictures on this page http://www.openfoam.com/documentatio...ppyHexMesh.php

Apologies if this wasn't the mistake you made, I suddenly realised I'm out of time at the moment (I'm also far from an expert myself, I'm sure someone else will be able to offer you much better advice)
j91 is offline   Reply With Quote

Old   February 28, 2017, 03:44
Default
  #3
New Member
 
Eddie
Join Date: Feb 2017
Location: Copenhagen, Denmark
Posts: 5
Rep Power: 9
emat is on a distinguished road
Hello j91. Thanks for the reply. Yes, assuming that I haven't overlooked a name-swap somewhere, this is also what I imagine is happening. But I don't understand where, or how. As I said in my original post, I haven't got down to the intricacies of how snappyHexMesh works -- getting a non-tutorial functional case that I can play with before getting really stuck in the details is my first step in that direction -- but I know enough to have a crack at supplanting the stl models in the chtMultiRegionHeater tutorial with my own. And so that is what I did. So I suppose I'm trying to find out what I did that turned my meshes inside-out, having (not-purposely) changed anything in the chtMultiRegionHeater setup.

I forgot to mention in my original post that both chtMultiRegionHeater, and my own workflow, include running the following command after snappyHexMesh:
Code:
splitMeshRegions -cellZones -overwrite
But - to my understanding - there are no config files for splitMeshRegions, so probably the discrepancy I've created somewhere in my set up is not to be found here.
emat is offline   Reply With Quote

Old   March 27, 2017, 09:50
Default
  #4
New Member
 
Eddie
Join Date: Feb 2017
Location: Copenhagen, Denmark
Posts: 5
Rep Power: 9
emat is on a distinguished road
I guess I had better close this by saying simply that I could not find the problem. I started again from scratch with a different approach, and the problem dissapeared so I guess I must have messed up somewhere! Thanks j91 for the help anyway
emat is offline   Reply With Quote

Reply

Tags
domains, mesh 3d, snappyhexmesh


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[snappyHexMesh] Running snappyHexMesh in parallel creates new time directories hconel OpenFOAM Meshing & Mesh Conversion 5 September 27, 2022 16:20
[snappyHexMesh] Problems with scaling meshes when meshing with SnappyHexmesh Bnitter OpenFOAM Meshing & Mesh Conversion 1 November 15, 2018 09:26
[snappyHexMesh] SnappyHexMesh castellation stage creates hole in surface where mesh flows into domain Dav3dum OpenFOAM Meshing & Mesh Conversion 0 August 30, 2017 05:19
[snappyHexMesh] Surface Meshes Merged in SnappyHexMesh (Pictures Inlcuded) sda OpenFOAM Meshing & Mesh Conversion 3 December 3, 2012 14:01
[snappyHexMesh] SnappyHexMesh meshes inside and outside of an STL geometry villier OpenFOAM Meshing & Mesh Conversion 17 June 15, 2010 20:51


All times are GMT -4. The time now is 10:41.