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

[snappyHexMesh] Multi region snappy hex mesh

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Hawxliquid

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 30, 2024, 07:14
Question Multi region snappy hex mesh
  #1
New Member
 
Boris
Join Date: Jan 2017
Posts: 26
Rep Power: 9
Hawxliquid is on a distinguished road
Hi everyone!


I have trouble understanding how snappyhexmesh works for multi regions.
Attached is a drawing of what I am trying to do.


Basically, I am trying to mesh a 3 region mesh. I prepared the domain limits as well as each interface.

Something odd is that the mesher refines the mesh at the surfaces .stl, but does not create region.
Am I doing something wrong?
Currently, my "rock" cellzone for example is "open", in the sense that the interface fluid-rock defines its shape via stl, but to close it, it would need to have the interface rock-ground. Do I have to merge them somehow?


Here is my snappy file :


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

// Which of the steps to run
castellatedMesh true;
snap            true;//false;//true;
addLayers       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
{
    fluid
    {
        type triSurfaceMesh;
        file "domain_total.stl";

        regions
        {
            domain_bottom {name domain_bottom; }
            domain_side_air {name domain_side_air; }
            domain_side_ground {name domain_side_ground; }
            domain_top {name domain_top; }
        }
    }

    interface_air_rocks
    {
        type triSurfaceMesh;
        file "interface_air_rocks.stl";
    }

    interface_air_ground
    {
        type triSurfaceMesh;
        file "interface_air_ground.stl";
    }


    interface_ground_rock
    {
        type triSurfaceMesh;
        file "interface_ground_rock.stl";
    }




}


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

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



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

    );



// 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
    {
        fluid
        {
// Surface-wise min and max refinement level
level (11);

            regions
            {
                domain_bottom { level (11); patchInfo { type wall ; } }
                domain_side_air { level (11); patchInfo { type patch ; } }
                domain_side_ground { level (11); patchInfo { type wall ; } }
                domain_top { level (11); patchInfo { type patch ; } }

            }
        }

        interface_air_rocks
        {
level (45);
            faceZone interface_air_rocks;
            cellZone rocks;
            cellZoneInside insidePoint;
insidePoint (17-18164);
        }

        interface_air_ground
        {
level (23);
            faceZone interface_air_ground;
            cellZone ground;
            cellZoneInside insidePoint;
insidePoint (00-20);
        }

        interface_ground_rock
        {
level (23);
            faceZone interface_ground_rock;
            cellZone ground;
            cellZoneInside insidePoint;
insidePoint (00-20);
        }



    }

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

//
//        refinement_Region_2
//        {
//            mode inside;
//            levels ((1e14 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 (150150150.01);

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

}



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

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


WhatsApp Image 2024-04-30 at 12.08.10.jpg
https://imgur.com/wcFIPPo


Hawxliquid is offline   Reply With Quote

Old   April 30, 2024, 09:18
Default
  #2
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,238
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
Hello Boris,

I don't know if I properly understood your issue.
Snappy's job will be to mesh your whole domain and define a cellZone for each region.

The resulting mesh will contain all the regions (which are still only cellZones at this point).

Then you need to use the splitMeshRegions utility to split the mesh into regions and create the interfaces. For instance:

Code:
splitMeshRegions -cellZonesOnly -overwrite
Regards,
Yann
Yann is offline   Reply With Quote

Old   April 30, 2024, 11:51
Default
  #3
New Member
 
Boris
Join Date: Jan 2017
Posts: 26
Rep Power: 9
Hawxliquid is on a distinguished road
Quote:
Originally Posted by Yann View Post
Hello Boris,

I don't know if I properly understood your issue.
Snappy's job will be to mesh your whole domain and define a cellZone for each region.

The resulting mesh will contain all the regions (which are still only cellZones at this point).

Then you need to use the splitMeshRegions utility to split the mesh into regions and create the interfaces. For instance:

Code:
splitMeshRegions -cellZonesOnly -overwrite
Regards,
Yann

I am trying to do a very simple case, where a cylinder is englobing a cube, and I want to mesh both volumes and have two different zones.
The very simple example can be found here : test_multi_region.zip


Even with this, I can't seem to understand how to create different region, can you see what I am missing?

My sHM is as such :
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
classdictionary;
    object      snappyHexMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Which of the steps to run
castellatedMesh true;
snap            true;//false;//true;
addLayers       true;//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
{
    fluid
    {
        type triSurfaceMesh;
        file "cylinder.stl";


    }

    block
    {
        type triSurfaceMesh;
        file "cube.stl";


    }






}


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

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



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

    );



// 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
    {
        fluid
        {
// Surface-wise min and max refinement level
level (11);

            cellZone fluid;
            cellZoneInside insidePoint;
insidePoint (003);

        }

        block
        {
// Surface-wise min and max refinement level
level (11);
            faceZone block_to_fluid; 
            cellZone block;
            cellZoneInside insidePoint;
insidePoint (001);

        }



    }

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

//
//        refinement_Region_2
//        {
//            mode inside;
//            levels ((1e14 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 (003);

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

}



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

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


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


Hawxliquid is offline   Reply With Quote

Old   April 30, 2024, 12:10
Default
  #4
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,238
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
Which OpenFOAM version are you using?
Yann is offline   Reply With Quote

Old   May 3, 2024, 04:57
Default
  #5
New Member
 
Boris
Join Date: Jan 2017
Posts: 26
Rep Power: 9
Hawxliquid is on a distinguished road
Quote:
Originally Posted by Yann View Post
Which OpenFOAM version are you using?

Version 2312. But I think I found the issue!
Running the command splitMeshRegions -cellZones -overwrite seems to work
Hawxliquid is offline   Reply With Quote

Old   May 3, 2024, 06:21
Default
  #6
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,238
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
Alright, glad to know you solved your issue!

In the example your posted before, the fluid cellZone was not properly defined, I think because it was missing a faceZone definition:

Code:
fluid
        {
            // Surface-wise min and max refinement level
            level (1 1);
            faceZone fluid;
            cellZone fluid;
            cellZoneInside insidePoint;
            insidePoint (0 0 3);
        }
However, this leads to snappy keeping also the outer part of the mesh (from blockMesh) in addition to the fluid and block cellZones, so it would require some extra steps to properly define the mesh.
Using topoSet to fix the cellZones before running splitMeshRegions might do the trick. There are also some resources here: https://openfoamwiki.net/index.php/S...-region_meshes (but everything might not be up to date)

I was asking about the version you are using, because in the OpenCFD branch (openfoam.com), there is another way to define cellZones since OpenFOAM-v1612+.
Instead of defining cellZones in the refinementSurfaces section, you can use the locationsInMesh parameter to define a point and a name in each region.
So your refinementSurfaces section would be like this:

Code:
    refinementSurfaces
    {
        fluid
        {
            level (1 1);
        }

        block
        {
            level (1 1);
        }	
    }
And your locationInMesh parameter would be replaced by a locationsInMesh:

Code:
    locationsInMesh
	(
		((0 0 3) fluid)
		((0 0 1) block)
	);
Snappy will only keep the regions defined in locationsInMesh, and define a cellZone for it.
You will just need to run splitMeshRegions -cellZones -overwrite afterward to split the mesh into regions meshes.
It also allows to easily define layers on the fluid side. (check this post SnappyHexMesh do not add layers)

For other users who might read this thread, please note this feature is not available in the foundation branch (openfoam.org)

I hope this will be helpful!
Yann
Yann is offline   Reply With Quote

Old   May 3, 2024, 06:26
Default
  #7
New Member
 
Boris
Join Date: Jan 2017
Posts: 26
Rep Power: 9
Hawxliquid is on a distinguished road
Quote:
Originally Posted by Yann View Post
Alright, glad to know you solved your issue!

In the example your posted before, the fluid cellZone was not properly defined, I think because it was missing a faceZone definition:

Code:
fluid
        {
            // Surface-wise min and max refinement level
            level (1 1);
            faceZone fluid;
            cellZone fluid;
            cellZoneInside insidePoint;
            insidePoint (0 0 3);
        }
However, this leads to snappy keeping also the outer part of the mesh (from blockMesh) in addition to the fluid and block cellZones, so it would require some extra steps to properly define the mesh.
Using topoSet to fix the cellZones before running splitMeshRegions might do the trick. There are also some resources here: https://openfoamwiki.net/index.php/S...-region_meshes (but everything might not be up to date)

I was asking about the version you are using, because in the OpenCFD branch (openfoam.com), there is another way to define cellZones since OpenFOAM-v1612+.
Instead of defining cellZones in the refinementSurfaces section, you can use the locationsInMesh parameter to define a point and a name in each region.
So your refinementSurfaces section would be like this:

Code:
    refinementSurfaces
    {
        fluid
        {
            level (1 1);
        }

        block
        {
            level (1 1);
        }    
    }
And your locationInMesh parameter would be replaced by a locationsInMesh:

Code:
    locationsInMesh
    (
        ((0 0 3) fluid)
        ((0 0 1) block)
    );
Snappy will only keep the regions defined in locationsInMesh, and define a cellZone for it.
You will just need to run splitMeshRegions -cellZones -overwrite afterward to split the mesh into regions meshes.
It also allows to easily define layers on the fluid side. (check this post SnappyHexMesh do not add layers)

For other users who might read this thread, please note this feature is not available in the foundation branch (openfoam.org)

I hope this will be helpful!
Yann
Thanks for the really useful post!
Indeed, I forgot to mention I also fixed the faceZone mistake.


Regarding the locationsInMesh, it seems indeed quite a simpler way to do things!
That also explains why I saw several methods around on the internet.
Yann likes this.
Hawxliquid is offline   Reply With Quote

Reply


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 13:38
[snappyHexMesh] Multi Region Mesh of a car filter Zephiro88 OpenFOAM Meshing & Mesh Conversion 3 September 11, 2019 20:34
[Other] preserveFaceZones constraint on a multi region mesh ViktorKL OpenFOAM Meshing & Mesh Conversion 5 May 21, 2019 12:45
[snappyHexMesh] Creating multiple multiple cell zones with snappyHexMesh - a newbie in deep water! divergence OpenFOAM Meshing & Mesh Conversion 0 January 23, 2019 05:17
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Meshing & Mesh Conversion 2 July 15, 2005 05:15


All times are GMT -4. The time now is 02:45.