1

I am learning OpenFOAM step by step, and am currently trying to create a very simple mesh with the blockMesh tool, but keep getting a floating point exception. My blockMeshDict is written in almost exact correspondence to the meshing tutorial in the section 4.3.1 of the OF user manual:

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

scale 1.0;

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

edges
(
);

blocks
(
    hex (0 1 2 3 7 6 5 4)
    (2 1 1)               // 2 blocks in the x direction
    simpleGrading (1 1 1) // default expansion ratios
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 1 2 3) 
        );
    }

    outlet
    {
        type patch;
        faces
        (
            (4 5 6 7)
        );
    }

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

This is just a unit length "air tube" cube with two sections along the x axis, an inlet and outlet on the opposite sides and walls everywhere else:

enter image description here

This config immediately breaks with the following error:

$ blockMesh
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
Build  : 9-c8374a4890ad
Exec   : blockMesh
Date   : Nov 02 2021
Time   : 11:50:35
Host   : "artixlinux"
PID    : 10555
I/O    : uncollated
Case   : /home/andrii/foamtest
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10)
allowSystemOperations : Allowing user-supplied system call operations

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

Reading "blockMeshDict"

Creating block mesh from
    "system/blockMeshDict"
Creating block edges
No non-planar block faces defined
Creating topology blocks
#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::sigFpe::sigHandler(int) at ??:?
#2  ? in "/usr/lib/libc.so.6"
#3  Foam::face::centre(Foam::Field<Foam::Vector<double> > const&) const at ??:?
#4  Foam::blockDescriptor::check(Foam::Istream const&) at ??:?
#5  Foam::blockDescriptor::blockDescriptor(Foam::dictionary const&, int, Foam::Field<Foam::Vector<double> > const&, Foam::PtrList<Foam::blockEdge> const&, Foam::PtrList<Foam::blockFace> const&, Foam::Istream&) at ??:?
#6  Foam::block::block(Foam::dictionary const&, int, Foam::Field<Foam::Vector<double> > const&, Foam::PtrList<Foam::blockEdge> const&, Foam::PtrList<Foam::blockFace> const&, Foam::Istream&) at ??:?
#7  Foam::block::New(Foam::dictionary const&, int, Foam::Field<Foam::Vector<double> > const&, Foam::PtrList<Foam::blockEdge> const&, Foam::PtrList<Foam::blockFace> const&, Foam::Istream&) at ??:?
#8  void Foam::PtrList<Foam::block>::read<Foam::block::iNew>(Foam::Istream&, Foam::block::iNew const&) at ??:?
#9  Foam::blockMesh::createTopology(Foam::IOdictionary const&, Foam::word const&) at ??:?
#10  Foam::blockMesh::blockMesh(Foam::IOdictionary const&, Foam::word const&) at ??:?
#11  ? in "/opt/OpenFOAM/OpenFOAM-9/platforms/linux64GccDPInt32Opt/bin/blockMesh"
#12  __libc_start_main in "/usr/lib/libc.so.6"
#13  ? in "/opt/OpenFOAM/OpenFOAM-9/platforms/linux64GccDPInt32Opt/bin/blockMesh"
zsh: floating point exception  blockMesh

I am reasonably sure this is not just a broken OpenFOAM installation (I am specifically using the org version from the Arch AUR) because a different mesh dict copied in place of mine from the archive given in this tutorial works perfectly.

I'm losing my mind over this, I checked the vertices and the face descriptions multiple times and don't see any problems, yet the error persists. Is there some mistake that I'm missing?

Andrii Kozytskyi
  • 123
  • 2
  • 11
  • 1
    It shows floating point exception message in the last line. The suspect looks like `#3 Foam::face::centre(...` – kiner_shah Nov 02 '21 at 11:59
  • @kiner_shah That doesn't tell me very much unfortunately. How exactly does this relate to my config? – Andrii Kozytskyi Nov 02 '21 at 12:20
  • 1
    Maybe it relates to the input file. `Foam::face` seems like a face of the cube in the diagram. Also if you see the log, it has parsed the input file till `blocks`, so it was in process of parsing the `boundary` but there was an error. – kiner_shah Nov 02 '21 at 12:43

2 Answers2

2

The problem with your blockMeshDict file is that you are not following these rules:

The local coordinate system is defined by the order in which the vertices are presented in the block definition according to:

  • the axis origin is the first entry in the block definition, vertex 0

  • the x direction is described by moving from vertex 0 to vertex 1;

  • the y direction is described by moving from vertex 1 to vertex 2;

  • vertices 0, 1, 2, 3 define the plane z = 0.

  • vertex 4 is found by moving from vertex 0 in the z direction.

  • vertices 5,6 and 7 are similarly found by moving in the z direction from vertices 1,2 and 3 respectively.

  • You must follow the right-hand rule when you specify the faces.


Here is a version of blockMesh that works correctly:

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

scale 1.0;

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

edges
(
);

blocks
(
    hex (0 4 7 3 1 5 6 2) //>>>> Follow the rules above <<<<
    (2 1 1)               // 2 blocks in the x direction
    simpleGrading (1 1 1) // default expansion ratios
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 1 2 3) 
        );
    }

    outlet
    {
        type patch;
        faces
        (
            (4 7 6 5)
        );
    }

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

Using:

blockMesh
paraFoam -block

you will get:

view of the block

Side note: You are referring to openfoam.com documentation while you are using the OpenFOAM foundation version (openfoam.org). Be careful, because they are not necessarily compatible.

s.ouchene
  • 1,682
  • 13
  • 31
  • Thank you! I was in fact using the org version, and I will probably switch to the com version if that is what the manual is for. Can you refer me to where you found these rules? I cannot find this ordering in the manual itself. – Andrii Kozytskyi Nov 02 '21 at 18:55
  • 1
    @AndriiKozytskyi: Notice that I have said they are not "necessarily" compatible. That doesn't mean they are not compatible but the compatibility is not guaranteed. You can find more instructions about blockMesh in the link you have provided (the first paragraphs). Of course, for complex geometries it's very unlikely to use blockMesh. You can use snappyHexMesh, or cfMesh or any mesh software you like then convert your mesh to OpenFOAM format. – s.ouchene Nov 02 '21 at 21:22
1

In most cases you can get the quickest help directly from the command-line with blockMesh -help. You will get this type of ASCII art:

...
Block mesh generator.
  The ordering of vertex and face labels within a block as shown below.
  For the local vertex numbering in the sequence 0 to 7:
    Faces 0, 1 (x-direction) are left, right.
    Faces 2, 3 (y-direction) are front, back.
    Faces 4, 5 (z-direction) are bottom, top.
                        7 ---- 6
                 f5     |\     |\     f3
                 |      | 4 ---- 5     \
                 |      3 |--- 2 |      \
                 |       \|     \|      f2
                 f4       0 ---- 1
    Y  Z
     \ |                f0 ------ f1
      \|
       O--- X

Using: OpenFOAM-v2106 (2106) - visit www.openfoam.com
Build: f815a12bba-20210902
Arch:  LSB;label=32;scalar=64

This is the fastest cheat sheet for remembering the vertex ordering.

Note that blockMesh also has a -write-vtk option which is really quick. It writes out the base blocks in a .vtu format, which you can display in any version of paraview (no extra plugin required). I usually use the hover on point function within paraview to interrogate the vertex numbers.

Once you have defined your blocks like this, you will probably be happy to know that you can also define the boundary faces in terms of block id and local face id. Thus your boundary might be something like this:

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 0)  // x-min
        );
    }
    outlet
    {
        type patch;
        faces
        (
            (0 1)  // x-max
        );
    }
...
);
Mark.O
  • 94
  • 6