Search code examples
c++openfoam

OpenFOAM simple blockMesh floating point exception


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?


Solution

  • 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.