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

[snappyHexMesh] Error in the refinement region generation

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 2, 2022, 17:45
Thumbs up Error in the refinement region generation
  #1
New Member
 
Rahul S Parameswaran
Join Date: Feb 2022
Posts: 2
Rep Power: 0
rahulcfd10 is on a distinguished road
Hello!


I have tried to use snappyHexMesh to generate 2 refinement zones (cuboids) around my object with different refinement levels. After generating the castellated mesh, my refinement regions do not match with the refinement region I have specified on my code.



Kindly find the images of the error and my code attached.
Let me know your thoughts


Thank you
Rahul


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

// 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
{
    sphere35cmswv2.stl
    {
        type triSurfaceMesh;
        name stl1; //patch name
    }
    refinementBox1
    {
        type searchableBox;
        min (-0.4875 -0.4375 -0.4375); //(-0.4875 -0.6125 -0.6125); //(-1.0 -0.7 0.0);
        max (3.4625 0.7875 0.7875); //(1.4875 0.7875 0.7875); //(1.4875 0.6125 0.6125); //( 8.0  0.7 2.5);
    }
    refinementBox2
    {
        type searchableBox;
        min (-0.875 -1.05 -1.05); //(-0.875 -1.225 -1.225); //(-1.0 -0.7 0.0);
        max (6.825 1.4 1.4); //(2.975 1.4 1.4); //(2.975 1.225 1.225); //( 8.0  0.7 2.5);
    }
};



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

    // 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; //3; //10; 



    // 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 "sphere35cmswv2.eMesh";
            level 3;
        }
    );



    // 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
    {
        stl1
        {
            // Surface-wise min and max refinement level
            level (2 2); //(2 3); //(5 6);

            // Optional specification of patch type (default is wall). No
            // constraint types (cyclic, symmetry) etc. are allowed.
            
            patchInfo
            {
                type wall;
                inGroups (stl1);
            }
            
        }
    }

    // Resolve sharp angles
    resolveFeatureAngle 30;

    planarAngle 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
    {
        refinementBox1
        {
            mode inside;
            levels ((3 3));//((3 3)); //((3 2)); //((1E15 4));
        }
        refinementBox2
        {
            mode inside;
            levels ((2 2)); //((3 2)); //((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 (1 2 2);    //(3.0001 3.0001 0.43);


    // 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 true; //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
    {
        "(stl1|sphere35cmswv2).*"
        {
            nSurfaceLayers 10; //1;
        }
    }

       expansionRatio 1.0;
    finalLayerThickness 0.1;
    finalLayerRatio 0.01;
    minThickness 0.002;
    nGrow 0;
    featureAngle 30;
    nRelaxIter 10;
    nSmoothSurfaceNormals 1;
    nSmoothNormals 3;
    nSmoothThickness 10;
    maxFaceThicknessRatio 0.5;
    maxThicknessToMedialRatio 0.3;
    minMedianAxisAngle 40;
    nBufferCellsNoExtrude 0;
    nLayerIter 100;
    nRelaxedIter 20;
}



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


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

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;

/*vertices
(
    (-5 -4 0)
    (15 -4 0)
    (15  4 0)
    (-5  4 0)
    (-5 -4 8)
    (15 -4 8)
    (15  4 8)
    (-5  4 8)
);
*/
xmin    -2.1; //-2.275;
xmax    17.5; //8.75; //8.575;
ymin    -3.15; //-3.325;
ymax    3.5; //3.325;
zmin    -3.15; //-3.325;
zmax    3.5; //3.325;

deltax    0.1;
deltay    0.1;
deltaz    0.1;

lnx #calc "abs(($xmax) - ($xmin))";
lny #calc "abs(($ymax) - ($ymin))";
lnz #calc "abs(($zmax) - ($zmin))";

xcells #calc "round(abs(($lnx)/$deltax))";
ycells #calc "round(abs(($lny)/$deltay))";
zcells #calc "round(abs(($lnz)/$deltaz))";

vertices
(
//BLOCK1
    ($xmin    $ymin    $zmin)    //0
    ($xmax    $ymin    $zmin)    //1
    ($xmax    $ymax    $zmin)    //2
    ($xmin    $ymax    $zmin)    //3
    ($xmin    $ymin    $zmax)    //4
    ($xmax    $ymin    $zmax)    //5
    ($xmax    $ymax    $zmax)    //6
    ($xmin    $ymax    $zmax)    //7
);

blocks
(
    hex (0 1 2 3 4 5 6 7) ($xcells $ycells $zcells) simpleGrading (1 1 1)
);

edges
(
);

boundary
(
    frontAndBack
    {
        type wall;
        faces
        (
            (3 7 6 2)
            (1 5 4 0)
        );
    }
    inlet
    {
        type patch;
        faces
        (
            (0 4 7 3)
        );
    }
    outlet
    {
        type patch;
        faces
        (
            (2 6 5 1)
        );
    }
    leftWall //lowerWall
    {
        type wall;
        faces
        (
            (0 3 2 1)
        );
    }
    rightWall //upperWall
    {
        type wall;
        faces
        (
            (4 5 6 7)
        );
    }
);

// ************************************************************************* //
Attached Images
File Type: png Screenshot from 2022-01-17 10-32-34.png (161.7 KB, 22 views)
rahulcfd10 is offline   Reply With Quote

Old   March 3, 2022, 03:03
Default
  #2
Senior Member
 
M
Join Date: Dec 2017
Posts: 642
Rep Power: 12
AtoHM is on a distinguished road
Hi, would you add in the image what you expect the regions to look like? Are the levels wrong or the spatial covering?



Tip: its good practise to not use locationInMesh with integers as input. If that coordinate hits a node on the generated mesh, it can cause problems in snappy. Better to use slightly off floats like shown in your commented part of that line. Although this is probably not the reason for your problem here.
AtoHM is offline   Reply With Quote

Old   March 3, 2022, 16:47
Default
  #3
New Member
 
Rahul S Parameswaran
Join Date: Feb 2022
Posts: 2
Rep Power: 0
rahulcfd10 is on a distinguished road
Quote:
Originally Posted by AtoHM View Post
Hi, would you add in the image what you expect the regions to look like? Are the levels wrong or the spatial covering?



Tip: its good practise to not use locationInMesh with integers as input. If that coordinate hits a node on the generated mesh, it can cause problems in snappy. Better to use slightly off floats like shown in your commented part of that line. Although this is probably not the reason for your problem here.
Thank you for your suggestion.

Kindly find the attached image according to which I require the mesh to be. I generated that mesh without the addition of layers but with the combination of refinement layers as ((3 3)) and ((2 2)) for refinementBox1 and refinementBox 2 respectively but the refinementBox sizes are smaller than the ones that I have mentioned in the code in my post.

I also tried to change the locationInMesh with integers but the output still remains the same.
Let me know if any other suggestions would work.

Thank you
Rahul
Attached Images
File Type: png Screenshot from 2021-11-16 02-02-59.png (122.3 KB, 10 views)
rahulcfd10 is offline   Reply With Quote

Reply

Tags
castellatedmeshcontrols, refinement regions, snappyhexmesh 3d

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 sticking point natty_king OpenFOAM Meshing & Mesh Conversion 11 February 20, 2024 09:12
SimpleFoam & Theater jipai OpenFOAM Running, Solving & CFD 3 June 18, 2019 10:11
[snappyHexMesh] sHM refinement away from surface nholt OpenFOAM Meshing & Mesh Conversion 1 June 14, 2016 14:36
[snappyHexMesh] snappyHexMesh refinement regions ignored guitarbren OpenFOAM Meshing & Mesh Conversion 2 April 9, 2013 03:59
[Other] StarToFoam error Kart OpenFOAM Meshing & Mesh Conversion 1 February 4, 2010 04:38


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