CFD for Automotive Flows

1. CAD and snappyHexMesh

a. Problem definition

The second problem we work on is a 2D flow over a car model with $ 90~\mathrm{km/h} $ ($ 25~\mathrm{m/s} $). See the 3D view of the car model we use in our computations below.

Figure: Car model used in this section


b. Pre-processing

Update your local directories

You will learn how to generate a 2D snappyHexMesh in this section on a CAD model.

The CAD model can be made in a tool such as FreeCAD, Salome, Gmsh or another alternative. For this tutorial, please update your local OpenFOAM directories using downloadSharedFiles.sh. Download the script and run as explained earlier (chmod +x downloadSharedFiles.sh & ./downloadSharedFiles.sh).

Later, you can find the CAD file in your ~/OpenFOAM/lecture03/car/constant/geometry/carModel.zip directory.


Unzip the downloaded CAD file

Unzip the compressed file using

unzip carModel.zip

If you have not unzip installed on your computer, you can install it using

sudo apt update & sudo apt install unzip

Here the carModel.stl file is downloaded from https://fetchcfd.com/. In this website, you can find several CAD, Mesh and CFD cases which can be downloadable. The carModel.stl file is downloaded in STEP format, then, read by FreeCAD and exported in STL format. This format is readeble by OpenFOAM and ParaView.

In the second step, you can open and check the file by running

paraview carModel.stl

Resize the CAD model

The sizes of the car in this file are set in $ \mathrm{mm} $. You must consider this when you use the file when you make the mesh, or you can transform the CAD geometry which I prefer to follow.

You can ''Transform'' the geometry using ParaView as shown in figure below. Briefly, you need to open the file in ParaView, click Filters > Search type Transform and fill the settings shown in figure to resize your CAD geometry.

At the end, you need to save the file as a new STL file. To do it click File > Save Data. Select the STL format and name your file as car.stl.

Figure: Transform (resize) a CAD geometry using ParaView

To transform the CAD geometry as we do above, write

Transform type Amount X Amount Y Amount Z
Translate 5 0 0
Rotate 0 -90 -90
Scale 0.001 0.001 0.001

blockMesh

Here, we calculate a 2D flow over this car model considering the computation time and file sizes in the 3D models. Because of this reason, we generate a thin (in $z$-direction) blockMesh in the center of the CAD model.

Figure: Computational domain and blockMesh size

To make the computational domain as shown above, we need a blockMeshDict file in the system folder. Go to the ~/OpenFOAM/lecture03/car/system directory and fill in the gaps in vertices and blocks functions in your blockMeshDict file.

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

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

convertToMeters 1;

vertices
(
// FILL HERE APPROPRIATELY
    (-10 0 -0.01)
    ( 35 0 -0.01)
    ( 35 5 -0.01)
    (-10 5 -0.01)
    (-10 0  0.01)
    ( 35 0  0.01)
    ( 35 5  0.01)
    (-10 5  0.01)
);

blocks
(
// COMPLETE THE LINE BELOW APPROPRIATELY
    hex (0 1 2 3 4 5 6 7) (45 5 1) simpleGrading (1 1 1)
);

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

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

Once you complete the blockMeshDict file and saving the ~/OpenFOAM/lecture03/car/constant/geometry/car.stl file after resizing the geometry, you are ready to run

blockMesh

Then run paraFoam to visualize the mesh. You can also open the car.stl file to check whether you place the blockMesh to the right position as shown in figure below.

Figure: blockMesh and car.stl


surfaceFeatures

Next, you need to run

surfaceFeatures

command. This command uses the system/surfaceFeaturesDict file and this file is used by OpenFOAM's surfaceFeatureExtract utility to extract feature edges from a surface geometry, which can then be used by snappyHexMesh for enhanced mesh refinement around those features. The settings are tailored for extracting features from your 3D car geometry (car.stl).

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

surfaces ("car.stl");

// Identify a feature when angle between faces < includedAngle
includedAngle       150;

subsetFeatures
{
    // Keep nonManifold edges (edges with >2 connected faces)
    nonManifoldEdges       no;

    // Keep open edges (edges with 1 connected face)
    openEdges       yes;
}

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

snappyHexMesh

Now, it is time to arrange the system/snappyHexMeshDict file.

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  10
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    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
{
    car
    {
        type triSurfaceMesh;
        file "car.stl";
    }

    refinementBox
    {
        type searchableBox;
        min (-1.0 0.0 -0.01);
        max (10.0 2.0  0.01);
    }
};



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



    // Explicit feature edge refinement
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    // Specifies a level for any cell intersected by its edges.
    // This is a featureEdgeMesh, read from constant/geometry for now.
    features
    (
        {
            file "car.eMesh";
            level 1;
        }
    );



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

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

    // 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
    {
        refinementBox
        {
            mode    inside;
            level   3;
        }
    }


    // 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 insidePoint is kept.
    // NOTE: This point should never be on a face, always inside a cell, even
    // after refinement.
    insidePoint (0 1 0);


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

        //- Use castellatedMeshControls::features (default = true)
        explicitFeatureSnap true;

        //- Detect points on multiple surfaces (only for explicitFeatureSnap)
        multiRegionFeatureSnap false;
}

// Generic mesh quality settings. At any undoable phase these determine
// where to undo.
meshQualityControls
{
    #include "meshQualityDict"
}


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


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

Please play with this file following the video lecture of this part.

We use the mesh shown below for the first computations. To obtain it, run

snappyHexMesh

and run

paraFoam

and click play button on ParaView to see the steps of the snappyHexMesh iterations.

Figure: snappyHexMesh on the computational domain. Whole model (top) and two zoomed views (bottom)

If you clearly understand what you did in this section, please press the 'Next' button above to jump to the next section.