CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [blockMesh] Box in a box? Two regions (https://www.cfd-online.com/Forums/openfoam-meshing/250009-box-box-two-regions.html)

Edoardo1993 May 21, 2023 20:34

Box in a box? mergePatchPairs error
 
1 Attachment(s)
Hello, I am new with OF and I need to use blockMesh to create a domain with 2 regions: one external and one internal with finer mesh. In particular, the domain is formed by two blocks:

1) internally a parallelepiped with fine mesh;

2) externally a parallelepiped with a less dense mesh;
(Look at the attached picture).


Here it is my blockMeshDict.


Code:

vertices
(

    (0 0 0)          //0
    (10 0 0)        //1
    (10 10 0)      //2
    (0 10 0)        //3
    (0 0 10)        //4
    (10 0 10)      //5
    (10 10 10)    //6
    (0 10 10)      //7

    (0 4 4)        //8
    (10 4 4)      //9
    (10 6 4)      //10
    (0 6 4)        //11
    (0 4 6)        //12
    (10 4 6)        //13
    (10 6 6)        //14
    (0 6 6)        //15
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (20 20 20) simpleGrading (1 1 1)
    hex (8 9 10 11 12 13 14 15) (100 100 100) simpleGrading (1 1 1)
);



edges
(
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (7 3 0 4)
            (15 11 8 12)
   
        );
    }

    outlet
    {
        type patch;
        faces
        (
            (1 2 6 5)
            (9 10 14 13)
   
        );
    }

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

);

mergePatchPairs
(
);


My problems are:
1) Why the inner block has 4 external faces? I want those faces (13 14 15 12) (15 14 10 11) (9 8 11 10) (12 8 9 13) to be internal.
2) How to joint the mesh at the interface to have continuity?



Thank you for your help

AtoHM May 22, 2023 01:51

Can you not split that face 1 2 6 5 into 9 smaller pieces with 8 of them around the central 9 10 14 13 face?
I was not aware blockMesh would run with a setting like you have, but it probably just creates two unconnected regions and that is why your faces are external. With my suggestion above, the mesh is conformal, non-intersecting and your faces are internal.

Edoardo1993 May 22, 2023 19:14

Quote:

Originally Posted by AtoHM (Post 850578)
Can you not split that face 1 2 6 5 into 9 smaller pieces with 8 of them around the central 9 10 14 13 face?
I was not aware blockMesh would run with a setting like you have, but it probably just creates two unconnected regions and that is why your faces are external. With my suggestion above, the mesh is conformal, non-intersecting and your faces are internal.

Thank you for your answer. Do I need to add new blocks or just to split the face in the boundary section?
Do I split in 9 pieces the inlet face (0 3 7 4) also?

AtoHM May 23, 2023 01:25

Right now I assume, you end up with two disconnected regions, it does not help to split a face. You will need 9 individual blocks like the yellow one, just sharing the respective faces. Then you need to give the same grading parameters to shared directions and it should come out as described.

Edoardo1993 May 24, 2023 09:44

Quote:

Originally Posted by AtoHM (Post 850651)
Right now I assume, you end up with two disconnected regions, it does not help to split a face. You will need 9 individual blocks like the yellow one, just sharing the respective faces. Then you need to give the same grading parameters to shared directions and it should come out as described.




Really thank you for your answer.
With your suggestion, I ended up with 5 individual blocks (see the attached picture) but BlockMesh gives me the following error:



Code:

/*---------------------------------------------------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  v2012                                |
|  \\  /    A nd          | Website:  www.openfoam.com                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
Build  : _7bdb509494-20201222 OPENFOAM=2012
Arch  : "LSB;label=32;scalar=64"
Exec  : blockMesh
Date  : May 24 2023
Time  : 15:25:09
Host  : DESKTOP-R70FIVH
PID    : 532
I/O    : uncollated
Case  : /mnt/c/ubuntu/openfoam/runs/reactingFoam/prova/1prova
nProcs : 1
trapFpe: Floating point exception trapping enabled (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 5, maxFileModificationPolls 20)
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Creating block mesh from "system/blockMeshDict"
Creating block edges
No non-planar block faces defined
Creating topology blocks
Creating topology patches

Creating block mesh topology

Check topology

        Basic statistics
                Number of internal faces : 0
                Number of boundary faces : 30
                Number of defined boundary faces : 30
                Number of undefined boundary faces : 0
        Checking patch -> block consistency

Creating block offsets
Creating merge list (topological search)...

Creating polyMesh from blockMesh
Creating patches
Creating cells
Creating points with scale 1
    Block 0 cell size :
        i : 0.5 .. 0.5
        j : 0.1 .. 0.1
        k : 0.1 .. 0.1

    Block 1 cell size :
        i : 0.5 .. 0.5
        j : 0.5 .. 0.5
        k : 0.2828427125 .. 0.2828427125

    Block 2 cell size :
        i : 0.5 .. 0.5
        j : 0.2828427125 .. 0.2828427125
        k : 0.1 .. 0.1

    Block 3 cell size :
        i : 0.5 .. 0.5
        j : 0.2828427125 .. 0.2828427125
        k : 0.5 .. 0.5

    Block 4 cell size :
        i : 0.5 .. 0.5
        j : 0.1 .. 0.1
        k : 0.2828427125 .. 0.2828427125

Creating merge patch pairs

Adding point and face zones
Creating attachPolyTopoChanger


--> FOAM FATAL ERROR: (openfoam-2012)
Face 114799 reduced to less than 3 points.  Topological/cutting error A.
Old face: 2(18039 18060) new face: 2(18039 18060)

    From void Foam::slidingInterface::coupleInterface(Foam::polyTopoChange&) const
    in file slidingInterface/coupleSlidingInterface.C at line 1450.

FOAM aborting

#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::error::exitOrAbort(int, bool) at ??:?
#2  Foam::slidingInterface::coupleInterface(Foam::polyTopoChange&) const at ??:?
#3  Foam::slidingInterface::setRefinement(Foam::polyTopoChange&) const at ??:?
#4  Foam::polyTopoChanger::topoChangeRequest() const at ??:?
#5  Foam::polyTopoChanger::changeMesh(bool, bool, bool, bool) at ??:?
#6  Foam::attachPolyTopoChanger::attach(bool) at ??:?
#7  ? at ??:?
#8  ? in /lib/x86_64-linux-gnu/libc.so.6
#9  __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
#10  ? at ??:?
Aborted (core dumped)

I think something is wrong with mergePatchPairs. My blockMeshDict is:
Code:

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

scale  1;

vertices
(
//block 0
    (0 4 4)            //0
    (10 4 4)          //1
    (10 6 4)          //2
    (0 6 4)            //3
    (0 4 6)            //4
    (10 4 6)          //5
    (10 6 6)          //6
    (0 6 6)            //7

//block 1
    (0 0 0)            //8
    (10 0 0)          //9
    (10 10 0)        //10
    (0 10 0)          //11
    (0 4 4)            //12=0
    (10 4 4)          //13=1
    (10 6 4)          //14=2
    (0 6 4)            //15=3

//block 2
    (0 6 4)            //16=3
    (10 6 4)          //17=2
    (10 10 0)        //18=10
    (0 10 0)          //19=11
    (0 6 6)            //20=7
    (10 6 6)          //21=6
    (10 10 10)      //22
    (0 10 10)        //23

//block 3
    (0 0 0)            //24=8
    (10 0 0)          //25=9
    (10 4 4)          //26=1
    (0 4 4)            //27=0
    (0 0 10)          //28
    (10 0 10)        //29
    (10 4 6)          //30=5
    (0 4 6)            //31=4

//block 4
    (0 4 6)            //32=4
    (10 4 6)          //33=5
    (10 6 6)          //34=6
    (0 6 6)            //35=7
    (0 0 10)          //36=28
    (10 0 10)        //37=29
    (10 10 10)      //38=22
    (0 10 10)        //39=23




);

blocks
(
    hex (0 1 2 3 4 5 6 7) (20 20 20) simpleGrading (1 1 1)
    hex (8 9 10 11 12 13 14 15) (20 20 20) simpleGrading (1 1 1)
    hex (16 17 18 19 20 21 22 23) (20 20 20) simpleGrading (1 1 1)
    hex (24 25 26 27 28 29 30 31) (20 20 20) simpleGrading (1 1 1)
    hex (32 33 34 35 36 37 38 39) (20 20 20) simpleGrading (1 1 1)


);

edges
(
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (3 0 4 7)        //B0   
            (11 8 12 15)    //B1   
            (23 19 16 20)    //B2   
            (27 24 28 31)    //B3
            (39 35 32 36)    //B4   


   
        );
    }

    outlet
    {
        type patch;
        faces
        (
            (1 2 6 5)        //B0   
            (9 10 14 13)    //B1
            (17 18 22 21)    //B2   
            (25 26 30 29)    //B3
            (37 33 34 38)    //B4   


        );
    }

    walls
    {
        type wall;
        faces
        (
            (9 10 11 8)        //B1
            (22 18 19 23)    //B2
            (29 28 24 25)    //B3
            (37 38 39 36)    //B4



        );
    }

    interfaceB0-B1
    {
        type wall;
        faces
        (
            (1 0 3 2)       
        );
    }
    interfaceB0-B2
    {
        type wall;
        faces
        (
            (3 7 6 2)       
        );
    }
    interfaceB0-B3
    {
        type wall;
        faces
        (
            (5 4 0 1)       
        );
    }
    interfaceB0-B4
    {
        type wall;
        faces
        (
            (5 6 7 4)       
        );
    }
    interfaceB1-B0
    {
        type wall;
        faces
        (
            (13 14 15 12)   
        );
    }
    interfaceB1-B2
    {
        type wall;
        faces
        (
            (14 10 11 15)   
        );
    }
    interfaceB1-B3
    {
        type wall;
        faces
        (
            (9 13 12 8)       
        );
    }
    interfaceB2-B0
    {
        type wall;
        faces
        (
            (21 20 16 17)   
        );
    }
    interfaceB2-B1
    {
        type wall;
        faces
        (
            (17 16 19 18)   
        );
    }
    interfaceB2-B4
    {
        type wall;
        faces
        (
            (22 23 20 21)   
        );
    }
    interfaceB3-B0
    {
        type wall;
        faces
        (
            (30 26 27 31)   
        );
    }
    interfaceB3-B1
    {
        type wall;
        faces
        (
            (26 25 24 27)   
        );
    }
    interfaceB3-B4
    {
        type wall;
        faces
        (
            (29 30 31 28)   
        );
    }
    interfaceB4-B0
    {
        type wall;
        faces
        (
            (32 35 34 33)   
        );
    }
    interfaceB4-B2
    {
        type wall;
        faces
        (
            (39 38 34 35)   
        );
    }
    interfaceB4-B3
    {
        type wall;
        faces
        (
            (37 36 32 33)   
        );
    }



);

mergePatchPairs
(
    (interfaceB0-B1 interfaceB1-B0)
    (interfaceB0-B2 interfaceB2-B0)
    (interfaceB0-B3 interfaceB3-B0)
    (interfaceB0-B4 interfaceB4-B0)

    (interfaceB1-B2 interfaceB2-B1)
    (interfaceB1-B3 interfaceB3-B1)

    (interfaceB2-B4 interfaceB4-B2)

    (interfaceB3-B4 interfaceB4-B3)

);

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


Edoardo1993 May 24, 2023 09:51

1 Attachment(s)
Here it is the picture with the blocks
Attachment 94767

Edoardo1993 May 24, 2023 13:54

2 Attachment(s)
I tried adding one block at a time and using mergePatchPairs.


1)Try #1
Blocks B0 and B1 merged correctly. (look attached)


2)Try #2
Blocks B0 B1 B4 merged correctly. In this case, B1 and B2 are opposites with respect to the faces of B0. (look attached)




3)Try #3
I tried to merge Blocks B0 B1 B2 (neighboring blocks) but I got the following blockMeshDict error:
Code:

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Creating block mesh from "system/blockMeshDict"
Creating block edges
No non-planar block faces defined
Creating topology blocks
Creating topology patches

Creating block mesh topology

Check topology

        Basic statistics
                Number of internal faces : 0
                Number of boundary faces : 18
                Number of defined boundary faces : 18
                Number of undefined boundary faces : 0
        Checking patch -> block consistency

Creating block offsets
Creating merge list (topological search)...

Creating polyMesh from blockMesh
Creating patches
Creating cells
Creating points with scale 1
    Block 0 cell size :
        i : 0.5 .. 0.5
        j : 0.1 .. 0.1
        k : 0.1 .. 0.1

    Block 1 cell size :
        i : 0.5 .. 0.5
        j : 0.5 .. 0.5
        k : 0.2828427125 .. 0.2828427125

    Block 2 cell size :
        i : 0.5 .. 0.5
        j : 0.2828427125 .. 0.2828427125
        k : 0.1 .. 0.1

Creating merge patch pairs

Adding point and face zones
Creating attachPolyTopoChanger


--> FOAM FATAL ERROR: (openfoam-2012)
Face 74019 reduced to less than 3 points.  Topological/cutting error A.
Old face: 0() new face: 0()

    From void Foam::slidingInterface::coupleInterface(Foam::polyTopoChange&) const
    in file slidingInterface/coupleSlidingInterface.C at line 1450.

FOAM aborting

#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::error::exitOrAbort(int, bool) at ??:?
#2  Foam::slidingInterface::coupleInterface(Foam::polyTopoChange&) const at ??:?
#3  Foam::slidingInterface::setRefinement(Foam::polyTopoChange&) const at ??:?
#4  Foam::polyTopoChanger::topoChangeRequest() const at ??:?
#5  Foam::polyTopoChanger::changeMesh(bool, bool, bool, bool) at ??:?
#6  Foam::attachPolyTopoChanger::attach(bool) at ??:?
#7  ? at ??:?
#8  ? in /lib/x86_64-linux-gnu/libc.so.6
#9  __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
#10  ? at ??:?
 Aborted (core dumped)

Thank you if you can help me.

AtoHM May 25, 2023 10:01

I never used the mergePatchPairs part, so I cannot help there. Probably an indexing error somewhere?



If I had your problem at hand, I would build 1 big blockMesh block and use snappyHexMesh with a refinementRegion to build the inner, refined block. Then if you need the as separate regions, use topoSet to select them. This will result in a better quality mesh and would be easier to do as it limits user input to a minimum.

Edoardo1993 May 25, 2023 10:21

You are really helping me a lot, thank you.

I found another thread not solved with the exact same problem with mergePatchpairs: https://www.cfd-online.com/Forums/op...tch-pairs.html ... there should not be index errors

Anyway, I will try to follow your tip with snappyhexmesh, I never used It. Could you please make a summarize list with the right order of commands to create the mesh?

AtoHM May 26, 2023 02:20

Welcome, I do not feel like helping much until now ... just pointing elsewhere.



The process depends a bit on what exactly you need/want to do with the mesh. If you need for example the front/back faces of the yellow block as BCs, then there are two ways: build 9 blocks in blockMesh as I said earlier and apply the BCs to the faces right there. Then refine with snappyHexMesh (uh, I realise now, I am not sure it preserves the BCs there, I hope it does). Or: build a single bigger block in blockMesh and a closed stl file of your domain containing the named faces which you can then use to apply the BCs in snappyHexMesh/createPatch utility. I usually prefer the second way as it involves less fiddling with blockMesh.
If you tell us what BCs you need I can whip up a quick template for you to work with, but probably not before/during the weekend.

Edoardo1993 May 26, 2023 05:29

Quote:

Originally Posted by AtoHM (Post 850868)
If you need for example the front/back faces of the yellow block as BCs, then there are two ways: build 9 blocks in blockMesh as I said earlier and apply the BCs to the faces right there. Then refine with snappyHexMesh (uh, I realise now, I am not sure it preserves the BCs there, I hope it does). Or: build a single bigger block in blockMesh and a closed stl file of your domain containing the named faces which you can then use to apply the BCs in snappyHexMesh/createPatch utility. I usually prefer the second way as it involves less fiddling with blockMesh.
If you tell us what BCs you need I can whip up a quick template for you to work with, but probably not before/during the weekend.




AtoHM thank you for answering me again.


I don'nt need BCs in the front and back of the yellow block. I want to simulate a 3D gas release inside a room, so I will have one left inlet, one right outlet and four walls (just like a pipe). The fluid jet is a lot smaller than the size of room, so I need that yellow block to be more meshed than the others and with multigrading as well... therefore, faceMatching cells and blocks can be a problem.. isn't it?


Futhermore, cause my thesis work has to be done in OpenFOAM only (the reason is to compare OpenFOAM's results to other softwares), I could not use third party software like CADs. Do the SnappyHexMesh way need third-party software?

Edoardo1993 May 28, 2023 22:35

Ignore my last post because I finally figured out that SnappyHexMesh is the solution to create my mesh and these days I've been trying to understand how snappyHexMesh works.


In order to create my mesh, I don't need a .STL or .OBJ file. It's enough to create a preliminary 10x10x10 box with blockMesh and, after that, set the geometry (i.e. the inner box with fine mesh) in snappyHexMesh in the refinementSurfaces section.


Is this the right way?
And what's the parameter to improve to thicken the mesh inside the inner box? With paraview I see a fine mesh in the boundary faces of the inner box but, putting a slice inside, the mesh is rather coarse..

Code:

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

 
castellatedMesh true;

snap false;

addLayers false;



 
geometry
{
    box

    {
        type searchableBox;
              min (0 4 4);
          max (10 6 6);
    }
}       





castellatedMeshControls


{

    maxLocalCells 100000;

    maxGlobalCells 2000000;

    minRefinementCells 0;

    maxLoadUnbalance 0.10;

    nCellsBetweenLevels 1;

    features
    (
    );

  refinementSurfaces
    {
        box
        {
            level (4 6);
            faceZone box;
            cellZone box;
            cellZoneInside inside;
        }
    }

    resolveFeatureAngle 95;

    refinementRegions
    {
    }

    locationInMesh (1.1 1.1 1.1);

    allowFreeStandingZoneFaces true;
}


snapControls
{

    nSmoothPatch 3;

    tolerance 4.0;

    nSolveIter 30;

    nRelaxIter 5;
}

addLayersControls
{

    relativeSizes true;

    layers
    {
    }

    expansionRatio 1.0;

    finalLayerThickness 0.3;

    minThickness 0.25;

    nGrow 0;

    featureAngle 60;

    nRelaxIter 5;

    nSmoothSurfaceNormals 1;

    nSmoothNormals 3;

    nSmoothThickness 10;

    maxFaceThicknessRatio 0.5;

    maxThicknessToMedialRatio 0.3;

    minMedianAxisAngle 90;

    nBufferCellsNoExtrude 0;

    nLayerIter 50;

    nRelaxedIter 20;
}

meshQualityControls
{

    maxNonOrtho 65;

    maxBoundarySkewness 20;
    maxInternalSkewness 4;

    maxConcave 80;

    minVol 1e-13;

    minTetQuality 1e-30;

    minArea -1;

    minTwist 0.05;

    minDeterminant 0.001;

    minFaceWeight 0.05;

    minVolRatio 0.01;

    minTriangleTwist -1;

    nSmoothScale 4;

    errorReduction 0.75;

    relaxed
    {
        //- Maximum non-orthogonality allowed. Set to 180 to disable.
        maxNonOrtho 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;


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

Code:

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

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

scale  1;

vertices
(
    (0 0 0)
    (10 0 0)
    (10 10 0)
    (0 10 0)
    (0 0 10)
    (10 0 10)
    (10 10 10)
    (0 10 10)
);

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

edges
(
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 4 7 3)
        );
    }

    outlet
    {
        type patch;
        faces
        (
            (2 6 5 1)
        );
    }

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

);

mergePatchPairs
(
);

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


AtoHM May 30, 2023 01:17

Great you figured out how to use snappy for this. Its really much more straight forward this way. Regarding your question, please be more specific, what do you mean by "thicken" the mesh?


Some background on the refinementSurfaces part: if you mention a region there, snappy will snap the cells to fit the boundary of the region and refine the boundary to the specified level. Also, as used by you, adding the region in the refinementSurfaces part allows you to create a face/cellZone. It does not refine the volume inside.
If you just want a uniform refinement inside the box, you can additionally add it in the refinementRegions part like this
Code:

refinementRegions
    {

        box
        {
            mode inside;
            levels ((1.0 2));        // refinement level (1.0 entry ignored)
        }
    }

where the "2" is the target level inside the volume. The 1.0 is ignored, as stated in the comment.


All times are GMT -4. The time now is 09:59.