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

[snappyHexMesh] How to refine mesh in SnappyHexMesh?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 29, 2022, 19:38
Default How to refine mesh in SnappyHexMesh?
  #1
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
Hello all
I am using snappyHexMesh to mesh my geometry and it works fine, but I want to reduce the "maximum mesh" further. For meshing, I am using this blockMesh and snappyHexmesh;

blockMesh
Code:
convertToMeters 1.0;  //0.1;

vertices
(
    (-0.02 -0.01 -0.03) 
    ( 0.02 -0.01 -0.03) 
    ( 0.02  0.05 -0.03) 
    (-0.02  0.05 -0.03) 
    (-0.02 -0.01  0.03) 
    ( 0.02 -0.01  0.03) 
    ( 0.02  0.05  0.03) 
    (-0.02  0.05  0.03) 
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (100 150 150) simpleGrading (1 1 1) 
);
snappyHexMesh

Code:
 refinementSurfaces
    {
       Artery 
        {
          
            level (2 4); 

          
        }
    }
This combination works fine, but it gives me maximumMesh=0.42 mm and I should reduce it to 0.20 mm. As far as I know, I should either refine the background mesh(blockMesh), or refinementSurfaces to something like this;

refinementSurfaces
{
Artery
{

level (3 5);


}
}
[/CODE]

But, both methods cause errors in meshing. For example, using below blockMesh(refined 1.5 times in all directions==>3.375 in all directions)

Code:
blocks
(
    hex (0 1 2 3 4 5 6 7) (150 225 225) simpleGrading (1 1 1)  
);
After finishing snappyHexMesh operation, I do checkMesh, I got below errors and failed meshes;

Code:
Checking geometry...
    Overall domain bounding box (-0.008525236 -8.591553e-05 -0.02356163) (0.009305119 0.039915 0.003961718)
    Mesh has 3 geometric (non-empty/wedge) directions (1 1 1)
    Mesh has 3 solution (non-empty) directions (1 1 1)
    Boundary openness (1.588389e-16 -1.49083e-15 -1.00903e-15) OK.
 ***High aspect ratio cells found, Max aspect ratio: 9.765306e+92, number of cells 5
  <<Writing 5 cells with high aspect ratio to set highAspectRatioCells
    Minimum face area = 4.653585e-15. Maximum face area = 7.584538e-08.  Face area magnitudes OK.
 ***Zero or negative cell volume detected.  Minimum negative volume: -7.012312e-16, Number of negative volume cells: 5
  <<Writing 5 zero volume cells to set zeroVolumeCells
    Mesh non-orthogonality Max: 150.5647 average: 11.85778
   *Number of severely non-orthogonal (> 70 degrees) faces: 7.
 ***Number of non-orthogonality errors: 15.
  <<Writing 22 non-orthogonal faces to set nonOrthoFaces
 ***Error in face pyramids: 16 faces are incorrectly oriented.
  <<Writing 16 faces with incorrect orientation to set wrongOrientedFaces
 ***Max skewness = 18.53282, 27 highly skew faces detected which may impair the quality of the results
  <<Writing 27 skew faces to set skewFaces
    Coupled point location match (average 0) OK.

Failed 5 mesh checks.

End

Thanks,
Farzad
farzadmech is offline   Reply With Quote

Old   August 30, 2022, 04:19
Default
  #2
Senior Member
 
M
Join Date: Dec 2017
Posts: 642
Rep Power: 12
AtoHM is on a distinguished road
Quick suggestions:

1) The entries provided in in level ( ) are min and max values for refinement. In my experience, having more then 1 level difference between min and max does not provide good meshes. So, if you want to refine, try level (3 4) or level (4 5).

2) Always look at your mesh visually. checkMesh is an indicator but I always do visual checks. Get the quality metrics as output fields and visualize them in paraview. This also provides important insight on what levels to provide for the run.
I hope this helps.
AtoHM is offline   Reply With Quote

Old   August 31, 2022, 00:17
Default
  #3
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
Dear AtoHM
I have put my blockMesh and snappyHexMesh here. Also, I did what you said, level (3 4) or level (4 5) and both failed.
Also, this is my visual illustration of my mesh;


This is my blockMesh;

Code:
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1.0;  //0.1;

vertices
(
    (-0.02 -0.01 -0.03) //(-0.06 -0.08 -0.04)   /0.5 mm is dimension of cell 0.5*0.5*0.5 m3
    ( 0.02 -0.01 -0.03) //( 0.06 -0.08 -0.04)
    ( 0.02  0.05 -0.03) //( 0.06  0.08 -0.04)
    (-0.02  0.05 -0.03) //(-0.06  0.08 -0.04)
    (-0.02 -0.01  0.03) //(-0.06 -0.08  0.04)
    ( 0.02 -0.01  0.03) //( 0.06 -0.08  0.04)
    ( 0.02  0.05  0.03) //( 0.06  0.08  0.04)
    (-0.02  0.05  0.03) //(-0.06  0.08  0.04)
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (100 150 150) simpleGrading (1 1 1) //(90 135 135) simpleGrading (1 1 1) 
);

edges
(
);

boundary
(
    defaultFacesBlock
    {
        type wall;
        faces
        (
            (3 7 6 2)
            (0 4 7 3)
            (2 6 5 1)
            (1 5 4 0)
            (0 3 2 1)
            (4 5 6 7)
        );
    }
   
);

mergePatchPairs
(
);

// ************************************************************************* //
and this is my SnappyHexMesh;

Code:
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  6
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      snappyHexMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Which of the steps to run
castellatedMesh true;
snap            true;  //true;
addLayers       true;  //false;  //true;


// 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
{
     Artery    //FarzadAyri  //motorBike
    {
        type triSurfaceMesh;
        file "Ayri2.stl";
    }

    
/*    
     turbineRefined1    //refinementBox
    {
       type searchableCylinder;
              
       point1 (985 525 1313);     //985 - (3*250) = 985 - 750 = 235 mm
       point2 (235 525 1313);
       radius 300; 
       
    } 
*/    
    
   
};



// 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 20000000; //10e6; //5000000; //80000; //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 40000000; //20e6; //8000000; //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 5; //5; //10;

    // Allow a certain level of imbalance during refining
    // (since balancing is quite expensive)
    // Expressed as fraction of perfect balance (= overall number of cells /
    // nProcs). 0=balance always.
    maxLoadUnbalance 0.10;


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



    // 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 "Ayri2.eMesh";
            level 2;  //2; 
        }
    );
   
   
/*    features
    (
        {
            file "XTAIn.eMesh";
            level 2;    //6;
        }
    );


*/

    // 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
    {
       Artery // Aerator   
        {
          
            level (2 4); //(2 3); 

          
        }
    }
    
///////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////  
    

    // 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));
        }
    } */
    
    refinementRegions
    {
	turbineRefined1	
		 {
            mode inside;
             levels ((1E15 1));   // 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.0 0.002 0.0); //(0.01 0.0 00); 


    // 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 true;
}



// 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 2.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;

    // Feature snapping

        //- Number of feature edge snapping iterations.
        //  Leave out altogether to disable.
        nFeatureSnapIter 10;

        //- Detect (geometric only) features by sampling the surface
        //  (default=false).
        implicitFeatureSnap false;

        //- Use castellatedMeshControls::features (default = true)
        explicitFeatureSnap true;

        //- Detect points on multiple surfaces (only for explicitFeatureSnap)
        multiRegionFeatureSnap false;
}



// Settings for the layer addition.
addLayersControls
{
    // Are the thickness parameters below relative to the undistorted
    // size of the refined cell outside layer (true) or absolute sizes (false).
    relativeSizes true;

    // Per final patch (so not geometry!) the layer information
    layers
    {
		//1) Artery_InCCA|2) Artery_OutICA|3) Artery_OutECA|4) Artery_bottom|5) Artery_middle|6) Artery_intersection|7) Artery_topICA|8) Artery_topECA
        //"(Artery_InCCA|Artery_OutICA|Artery_OutECA|Artery_bottom|Artery_middle|Artery_intersection|Artery_topICA|Artery_topECA).*"   //"(lowerWall|motorBike).*"  
        "(Artery_ICAwall|Artery_ECAwall|Artery_CCAwall|Artery_ICAout|Artery_ECAout|Artery_CCAin).*"
        //"(Artery_topECA).*"
        {
            nSurfaceLayers 3; //1;
        }
    }

    // Expansion factor for layer mesh
    expansionRatio 1.0;

    // 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 0.3;

    // 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 60;

    // At non-patched sides allow mesh to slip if extrusion direction makes
    // angle larger than slipFeatureAngle.
    slipFeatureAngle 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 10;

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

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

    // 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

// Write flags
writeFlags
(
    scalarLevels
    layerSets
    layerFields     // write volScalarField for layer coverage
);


// Merge tolerance. Is fraction of overall bounding box of initial mesh.
// Note: the write tolerance needs to be higher than this.
mergeTolerance 1e-6;


// ************************************************************************* //
Thanks,
Farzad



Quote:
Originally Posted by AtoHM View Post
Quick suggestions:

1) The entries provided in in level ( ) are min and max values for refinement. In my experience, having more then 1 level difference between min and max does not provide good meshes. So, if you want to refine, try level (3 4) or level (4 5).

2) Always look at your mesh visually. checkMesh is an indicator but I always do visual checks. Get the quality metrics as output fields and visualize them in paraview. This also provides important insight on what levels to provide for the run.
I hope this helps.
Attached Images
File Type: jpg Screenshot 2022-08-30 231704.jpg (57.8 KB, 103 views)
farzadmech is offline   Reply With Quote

Old   August 31, 2022, 01:16
Default
  #4
Senior Member
 
M
Join Date: Dec 2017
Posts: 642
Rep Power: 12
AtoHM is on a distinguished road
An aspect ratio like the one you get is quite rare but I had it in some cases as well. In almost all of them it was caused by the layer addition phase. Unfortunately, I am not aware of a general fix for that.

If you are using the ESI version of snappy, you can try the alternative mesh shrinker described here. That avoided it in some of my cases.
Check if the quality improves without layers and work from there.
AtoHM is offline   Reply With Quote

Old   August 31, 2022, 01:35
Default
  #5
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
I reduced refinement level to below one;
Code:
 refinementSurfaces
    {
       Artery // Aerator   
        {
            level (1 3);  
        }
    }
and use a refinement region covering whole artery as below;

Code:
refinementRegions
      {
	turbineRefined1	
		 {
            mode inside;
             levels ((1E15 1));   // levels ((1E15 4));
                 }
      }
and results are much better compare to previous one.


Thanks,
Farzad

Quote:
Originally Posted by AtoHM View Post
An aspect ratio like the one you get is quite rare but I had it in some cases as well. In almost all of them it was caused by the layer addition phase. Unfortunately, I am not aware of a general fix for that.

If you are using the ESI version of snappy, you can try the alternative mesh shrinker described here. That avoided it in some of my cases.
Check if the quality improves without layers and work from there.
Attached Images
File Type: jpg ffff.jpg (45.7 KB, 58 views)
farzadmech is offline   Reply With Quote

Old   August 31, 2022, 02:47
Default
  #6
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
I increased level to level (2 4) with the same refinement region and this time I have the desired results(maximum mesh decreased) which I attached the figure to this post.

Quote:
Originally Posted by farzadmech View Post
I reduced refinement level to below one;
Code:
 refinementSurfaces
    {
       Artery // Aerator   
        {
            level (1 3);  
        }
    }
and use a refinement region covering whole artery as below;

Code:
refinementRegions
      {
	turbineRefined1	
		 {
            mode inside;
             levels ((1E15 1));   // levels ((1E15 4));
                 }
      }
and results are much better compare to previous one.


Thanks,
Farzad
Attached Images
File Type: jpg 3.jpg (42.8 KB, 46 views)
farzadmech is offline   Reply With Quote

Old   April 17, 2023, 07:45
Default can i draw a conclusion
  #7
New Member
 
wangjikang
Join Date: Apr 2022
Posts: 4
Rep Power: 4
sciFoam is on a distinguished road
can i draw a conclusion that you specify the refine levle of the whole refineregion which will limited the automaticlly-added surfacelayer。
so no ba surfacelayer cell will be created
sciFoam is offline   Reply With Quote

Old   April 19, 2023, 00:40
Default
  #8
Senior Member
 
Farzad Faraji
Join Date: Nov 2019
Posts: 204
Rep Power: 7
farzadmech is on a distinguished road
What do you mean by surface layer? do you mean boundary layer? I have boundary layer here.

Farzad
Quote:
Originally Posted by sciFoam View Post
can i draw a conclusion that you specify the refine levle of the whole refineregion which will limited the automaticlly-added surfacelayer。
so no ba surfacelayer cell will be created
farzadmech is offline   Reply With Quote

Reply

Tags
blockmesh, openfoam, refinement, snappyhexmesh

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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] SnappyHexMesh/splitMeshRegion : region1 in zone "-1" GuiMagyar OpenFOAM Meshing & Mesh Conversion 3 August 4, 2023 12:38
[snappyHexMesh] non uniform mesh near the stl object vava10 OpenFOAM Meshing & Mesh Conversion 0 January 31, 2021 14:41
how to set periodic boundary conditions Ganesh FLUENT 15 November 18, 2020 06:09
[snappyHexMesh] snappyHexMesh does not create any mesh except one for the reference cell Arman_N OpenFOAM Meshing & Mesh Conversion 1 May 20, 2019 17:16
[snappyHexMesh] SnappyHexMesh no layers and no decent mesh for complex geometry pizzaspinate OpenFOAM Meshing & Mesh Conversion 1 February 25, 2015 07:05


All times are GMT -4. The time now is 16:55.