Home / Insights

CFD series · Part 3 of 6

The CFD Mesh: Why the Same Problem Gives Different Answers

Contents
  1. What a mesh is
  2. Wall layers and y+ in plain words
  3. The test case: a lid-driven cavity
  4. Six meshes, one problem
  5. Where the cells go matters as much as how many
  6. Mesh quality
  7. How to check mesh independence
  8. What it costs: cells against hours
  9. What to demand from a CFD supplier
  10. Common mistakes
  11. Key points
  12. Sources

Part 1 of this series explained what CFD is and when it pays, and Part 2 how to read the coloured pictures it produces. This part is about the one setting that most often decides whether those pictures can be trusted: the mesh. Two engineers can model the same vessel with the same software and get answers 20% apart, and the reason is usually the mesh.

To show it, we solved one flow six times on six different meshes and compared every answer with a published benchmark. The results, the files behind them and the run times are all below. The method is the one to ask any CFD supplier for.

What a mesh is

A CFD solver cannot work on a continuous fluid. It cuts the space the fluid fills into small cells and solves the equations for mass and momentum (and heat, if it matters) as a balance on each cell: what flows in through its faces, what flows out, and what changes inside. The set of cells is the mesh.

Inside each cell the solver keeps one value of velocity, one of pressure, one of temperature. Anything that varies inside a cell is smoothed away. So a mesh that is too coarse cannot hold a thin boundary layer, a jet or a small eddy, and the answer is wrong in a way the colourful picture will not show. Finer cells hold more detail, and the answer moves toward the true solution of the equations. That approach is called mesh convergence, and checking it is called a mesh independence study.

Quadrilaterals(hexahedra in 3D)Triangles(tetrahedra in 3D)Polygons(polyhedra in 3D)Wall layers(prism layers in 3D)WallFirstcellheight
Figure 1. The common cell types. Ordered quadrilaterals (hexahedra in 3D) give the most accuracy per cell. Triangles and polygons (tetrahedra and polyhedra in 3D) fill any shape automatically. Thin wall layers resolve the flow where it changes fastest, next to the wall.
Cell typeWhere it is usedStrengthWeakness
Quadrilaterals (hexahedra)Pipes, ducts, channels, simple vessels, wall layersMost accurate per cell; cells line up with the flowSlow to build by hand around complex shapes
Triangles (tetrahedra)Complex parts: valve bodies, manifolds, impellersGenerated automatically for any shapeNeeds more cells for the same accuracy, poor in thin wall layers
Polygons (polyhedra)Same complex parts, in solvers that support themAutomatic like triangles, with fewer cells and better gradientsNot every solver or mesher offers them
Wall layers (prisms)Against every wall where friction or heat transfer mattersResolve the thin layer where velocity and temperature change fastestThe first cell height has to match the turbulence model's wall treatment

Wall layers and y+ in plain words

Next to a wall the fluid sticks to the surface, and its speed rises from zero to the main flow speed across a thin layer. In a pipe or a stirred vessel that layer can be a fraction of a millimetre thick, yet it sets the friction, the pressure drop and the heat transfer. A mesh needs either enough thin cells inside the layer to resolve it, or a deliberate shortcut called a wall function that models the layer instead.

Which one you have is measured by y+, the height of the first cell above the wall in "wall units":

\[y^{+} = \frac{y\,u_\tau}{\nu}, \qquad u_\tau = \sqrt{\tau_w/\rho}\]

where \(y\) is the first cell height, \(\tau_w\) the wall shear stress, \(\rho\) the density and \(\nu\) the kinematic viscosity. Below a \(y^{+}\) of about 5 the cell sits in the viscous sublayer and the layer is resolved; from about 30 upward the cell sits in the log-law region, where wall functions are designed to work (Pope, 2000). A first cell between the two is in the buffer region and suits neither, unless the turbulence model has a wall treatment built for it. Part 4 returns to this with the turbulence models. For now: a supplier should state the \(y^{+}\) range on every wall, and it should match the wall treatment they chose.

The test case: a lid-driven cavity

A square box of liquid, 1 m a side, with its lid sliding to the right at 1 m/s. The lid drags the liquid with it and sets up one large vortex, with small slow eddies in the bottom corners. With a kinematic viscosity of 0.001 m²/s the Reynolds number is

\[Re = \frac{U L}{\nu} = \frac{1 \times 1}{0.001} = 1{,}000\]

It is a toy, but a useful one. It has thin layers along the walls, a strong vortex and corner eddies, and its answer is known to about seven significant figures: Botella and Peyret (1998) solved it with a highly accurate spectral method. The number we track is the strongest backward flow on the vertical centreline, the most negative horizontal velocity on the line \(x = 0.5\), which the benchmark gives as \(u_{min} = -0.3886\ \text{m/s}\) at a height of 0.1717 m. We also check the strongest upward and downward flow on the horizontal centreline.

We solved it with the steady laminar solver simpleFoam in OpenFOAM v1912, second-order schemes (linear-upwind for the convection term), and the SIMPLEC pressure–velocity method. Every run was taken to residuals below \(10^{-8}\) for pressure and \(10^{-9}\) for velocity, so the differences between meshes are mesh error, not unfinished iterations. Each run used one core, and the run times quoted are the solver's CPU time.

Six meshes, one problem

Four meshes are uniform squares, each with twice the cells per side of the one before: 20 × 20, 40 × 40, 80 × 80 and 160 × 160. Two more have 40 × 40 cells each but spend them differently. One makes the cells small near the walls and larger in the middle. The other does the opposite. Pick a mesh in Figure 2 and watch the answer change.

20 × 20 · 400 cells
Cells400
Iterations606
CPU time, 1 core0.25 s
Strongest backflow0.319 m/s
Off the benchmark−17.9%

20 × 20 mesh: 400 cells. The vortex is there, but the strongest backward flow on the centreline is 0.319 m/s, 17.9% short of the benchmark.

Figure 2. The same lid-driven cavity (Reynolds number 1,000) solved in OpenFOAM v1912 on six meshes. Each colour block is one cell of the solved field, and the tracers move with the solved velocity, slowed down. The chart compares the strongest backward velocity on the vertical centreline with the published benchmark of Botella and Peyret (1998), −0.3886 m/s, and shows the grid convergence index band on the finest mesh and the extrapolated value. Times are the solver's CPU time on one core of the computer used for this article; yours will differ, but the ratios between meshes are what matter.
MeshCellsIterationsCPU time, 1 core (s)Backflow (m/s)Error: backflow / upflow / downflow
Uniform 20 × 204006060.250.3191−17.9 / −21.4 / −24.4%
Uniform 40 × 401,6006530.910.3712−4.5 / −5.3 / −7.3%
Uniform 80 × 806,4001,2326.30.3836−1.3 / −1.4 / −1.7%
Uniform 160 × 16025,6003,231870.3872−0.34 / −0.39 / −0.44%
40 × 40, fine at the walls1,6005710.790.3768−3.0 / −3.2 / −3.0%
40 × 40, fine in the middle1,6007801.10.3497−10.0 / −13.9 / −17.8%
Ghia, Ghia and Shin (1982), 129 × 12916,641 points––0.3829−1.5 / −1.6 / −2.2%
Benchmark (Botella and Peyret, 1998)–––0.38860

Read across the table. On the coarsest mesh the vortex is there but too weak: the backflow is 17.9% short. Each step to four times the cells cuts the error to about a quarter: 4.5%, then 1.3%, then 0.34%. That is what a second-order method should do, and Figure 3 shows all three quantities falling on parallel straight lines.

Note the row for Ghia, Ghia and Shin (1982). Their table is the most cited reference for this flow, and it was computed on a 129 × 129 mesh. Its backflow is 1.5% short of the spectral benchmark, about as far off as our 80 × 80 mesh. Even the reference everyone compares with carries mesh error.

0.1%0.3%1%3%10%30%4001,6006,40025,600Cells (log scale)Error against the benchmark (log scale)Dashed: second order,error ÷ 4 for 4 × the cellsFine at walls 3.0%Fine in middle 10.0%Strongest backflow, vertical centrelineStrongest upflow, horizontal centrelineStrongest downflow, horizontal centrelineDiamonds: graded 40 × 40 meshes, backflow
Figure 3. Error against the benchmark for the three centreline quantities, on the four uniform meshes. Each fourfold increase in cells cuts the error by about four, the slope of a second-order method. The diamonds are the two graded 40 × 40 meshes: the same 1,600 cells give a smaller error when the small cells sit at the walls, and a much larger one when they sit in the middle.

Where the cells go matters as much as how many

The two graded meshes have exactly the same 1,600 cells as the uniform 40 × 40. With small cells packed against the walls, the backflow error falls from 4.5% to 3.0%, and the whole centreline profile comes almost as close to Ghia's points as the uniform 80 × 80 mesh with four times the cells (root-mean-square difference 0.0076 m/s, against 0.0059 for 80 × 80 and 0.0264 for the uniform 40 × 40). With the small cells packed in the middle instead, where the flow changes slowly, the error rises to 10.0%, and the downflow error to 17.8%: worse than not grading at all.

Both graded meshes pass every quality check. Their cells are square to each other and grow by only 7.6% from one to the next. A quality report cannot tell you the cells are in the wrong place. Only the physics can: put the small cells where the velocity or temperature changes fastest, which in process equipment is almost always at the walls, at the impeller tips, in jets and in shear layers.

Mesh quality

Quality measures the shape of the cells, not their placement. Badly shaped cells add error of their own and can stop a solution converging at all. These are the checks a mesh report should show:

MeasureWhat it meansCommon limitMeshes in this article
Non-orthogonalityAngle between the line joining two cell centres and the normal to the face between them (0° is ideal)OpenFOAM's checkMesh flags faces over 70°0° on every mesh
SkewnessHow far the face centre sits from the line joining the two cell centrescheckMesh flags values over 40 on every mesh
Aspect ratioLongest side of a cell over its shortestHigh values are fine in wall layers, harmful where the flow crosses the long side1 uniform, 4 graded
Growth (expansion) ratioSize of a cell over its neighbour'sRule of thumb: within 1.2 to 1.31.076 in both graded meshes

How to check mesh independence

"Mesh independent" does not mean the mesh stops mattering. It means the mesh error in the number you care about is known and small enough. The standard way to show it is Richardson extrapolation and the Grid Convergence Index, GCI (Roache, 1994), as set out for engineering use by Celik and co-authors (2008) in the procedure the ASME Journal of Fluids Engineering recommends to its authors.

  1. Solve on three meshes, each refined by the same ratio \(r\) (here \(r = 2\) per direction). Call the results \(\phi_1\) (fine), \(\phi_2\) and \(\phi_3\) (coarse).
  2. Check the change is monotonic: \(\phi_3 \to \phi_2 \to \phi_1\) moves the same way each time. If it oscillates, the meshes are too coarse for the method below.
  3. Work out the order of accuracy the meshes actually show:

    \[p = \frac{\ln\left|(\phi_3-\phi_2)/(\phi_2-\phi_1)\right|}{\ln r}\]

  4. Extrapolate to an infinitely fine mesh, and turn the change between the two finest meshes into an uncertainty band with a safety factor of 1.25:

    \[\phi_{ext} = \frac{r^p\phi_1-\phi_2}{r^p-1}, \qquad GCI_{fine} = \frac{1.25\,\left|(\phi_1-\phi_2)/\phi_1\right|}{r^p-1}\]

Applied to the 160, 80 and 40 meshes:

Quantity160 × 160 result, m/sObserved order pExtrapolated, m/sGCI, fine meshBenchmark, m/sExtrapolated vs benchmark (size)
Strongest backflow (vertical centreline)0.38721.780.38870.48%0.3886+0.04%
Strongest upflow (horizontal centreline)0.37551.860.37700.50%0.3769+0.01%
Strongest downflow (horizontal centreline)0.52472.100.52680.50%0.5271−0.04%

The observed orders, 1.78 to 2.10, are close to the theoretical 2 of the schemes, which says the meshes are fine enough for the method to apply. The peak value on each mesh is read from a parabola through the three cells at the peak; reading it with a spline instead moves \(p\) by about 0.1 and the extrapolated value by about 0.02%, which does not change the conclusion. The extrapolated backflow, 0.3887 m/s, is within 0.04% of the spectral benchmark, and for all three quantities the benchmark sits inside the GCI band around the fine-mesh result. Three affordable runs predicted the answer of the expensive spectral solution to better than a tenth of a percent, and told us how far the fine mesh itself was from it, without needing to know the benchmark.

That last point is the useful one. On a real vessel there is no benchmark. The GCI is how you put an error bar on the mesh anyway.

What it costs: cells against hours

Accuracy is bought with run time, and the price rises faster than the cell count. Going from 80 × 80 to 160 × 160 multiplied the cells by 4 and the CPU time by 13.8: the solver needed 2.6 times as many iterations to converge, and each iteration took 5.3 times as long, four times the work and more. Over that step the CPU time grew roughly as the cell count to the power 1.9.

This case is 2D. In a 3D model each halving of the cell size multiplies the cells by eight, not four, so one refinement step can be expected to cost ten times the computer hours or more before you add cores. That is why the mesh study is the first thing to be skipped when a budget is tight, and why it matters to ask for it: the single mesh a supplier can afford to run may be the coarse one. Part 6 puts numbers on what that computing costs a small company.

What to demand from a CFD supplier

Ask forWhy
Results on at least three meshes, each with about twice the cells per directionOne mesh tells you nothing about mesh error
The change in the number you care about (pressure drop, power, heat duty), mesh to mesh, and a GCIA colour plot that "looks the same" is not a mesh study
Cell count, cell types and run time for each meshShows whether the fine mesh was affordable and what a design change will cost
The checkMesh or quality report: worst non-orthogonality, skewness, growth ratioBad cells can stop convergence or bend the answer locally
A picture of the mesh at the walls, and the range of first-cell height in wall units (y+)Most of the friction and heat transfer happen in the wall layer
Residuals and a monitored quantity against iterationsShows the solution has stopped changing on each mesh

Common mistakes

  • Running one mesh. There is then no way to know the mesh error, however good the picture looks.
  • Refining by too little. Meshes only 10% apart give differences so small that iteration and round-off error can swamp them. Celik and co-authors recommend a ratio above 1.3 per direction; use 2 where you can afford it.
  • Judging by the pictures. Contours on the 40 × 40 and 160 × 160 meshes look alike; the backflow error differs by 4.1 percentage points (4.5% against 0.34%). Compare the number you will design with.
  • Trusting the quality report alone. Our worst graded mesh had perfect quality figures.
  • Stopping iterations early. If the residuals have not fallen far, the mesh study measures unfinished iterations, not the mesh.
  • Ignoring the walls. A first cell in the wrong y+ band for the wall treatment spoils friction and heat transfer whatever the cell count.

Key points

  • CFD solves a balance on each cell of the mesh. Detail smaller than a cell is lost, so a coarse mesh gives a smooth, confident and wrong answer.
  • Refine systematically, at least three meshes with the same ratio, and track the number you will design with.
  • Richardson extrapolation and the GCI turn three runs into an estimate of the mesh-free answer and an error bar on the fine mesh. Here they matched a seven-figure benchmark to 0.04%.
  • Where the cells go matters as much as how many: the same 1,600 cells gave 3.0% or 10.0% error depending on placement.
  • Quality checks find badly shaped cells, not badly placed ones.
  • Run time rises faster than the cell count, and much faster in 3D. Budget for the mesh study from the start.

Next, Part 4: turbulence models in plain language, and why the same mesh can still give different answers with different models.

Sources

  • O. Botella and R. Peyret (1998), "Benchmark spectral results on the lid-driven cavity flow", Computers & Fluids 27(4), 421–433, doi:10.1016/S0045-7930(98)00002-4 (the benchmark values, as tabulated by Marchi and co-authors)
  • C. H. Marchi, R. Suero and L. K. Araki (2009), "The lid-driven square cavity flow: numerical solution with a 1024 × 1024 grid", Journal of the Brazilian Society of Mechanical Sciences and Engineering 31(3), 186–198, full text
  • U. Ghia, K. N. Ghia and C. T. Shin (1982), "High-Re solutions for incompressible flow using the Navier–Stokes equations and a multigrid method", Journal of Computational Physics 48, 387–411, doi:10.1016/0021-9991(82)90058-4 (centreline velocity table, Re = 1,000)
  • P. J. Roache (1994), "Perspective: a method for uniform reporting of grid refinement studies", Journal of Fluids Engineering 116(3), 405–413, doi:10.1115/1.2910291
  • I. B. Celik, U. Ghia, P. J. Roache, C. J. Freitas, H. Coleman and P. E. Raad (2008), "Procedure for estimation and reporting of uncertainty due to discretization in CFD applications", Journal of Fluids Engineering 130(7), 078001, doi:10.1115/1.2960953
  • S. B. Pope (2000), Turbulent Flows, Cambridge University Press (wall regions and y+)
  • OpenFOAM v1912 (simpleFoam, blockMesh, checkMesh), used for every run in this article

All six cases were solved for this article in OpenFOAM v1912 on one core of a cloud workstation. CPU times depend on the computer; their ratios are the useful part. The cavity is a 2D laminar test case chosen because its exact answer is known; real equipment is 3D and usually turbulent, so its meshes are larger and its mesh studies cost more.

Test what you have read

Free Process / ChemEng practice exams

Interactive exams with an explanation for every answer. No sign-up.

Keep reading

Related articles

All 214 articles

Ready to find your next improvement?

Book a strategy call. We will talk through your goals, pain points and where AI, systems or process work can make the biggest difference.