I am solving an advection-diffusion problem where the solution variable is mostly flat apart from a small region near the centre of the domain where there are shape gradients. I would like to generate mesh faces for 1D finite volume cells (see below) where the cells are clustered towards the centre of the domain.

Cell centered grid

I have not attempted moving or adaptive meshing because, for this application, it will be overkill. I simply want a static but non-uniform mesh. This would seems simple on the surface but I've found it tricky and would like some advice.

I am using the following approach. A uniform distribution of cell faces is defined by, $$x_{j+1/2} = \sum\limits_{j=0}^N hn$$ where $h$ is the constant mesh spacing.

To generate clustered non-uniform cell faces I plan on simply dividing the uniform mesh sequence by a mesh density function $\rho$. For example, $$x_{j+1/2} = \sum\limits_{j=0}^N \frac{hn}{\rho}$$

Choosing a Gaussian mesh density function, with constant added so it doesn't become singular when used as a denominator, allows the mesh density to increase near the peak of the curve,

$$\rho = ae^{\frac{(x-b)^2}{2c^2}}+1$$

With this approach I can then generate the following mesh. Notice how the mesh points start off constant spacing (because $\rho=1$, then initially begin to expand, and then contracts around the centre points. I have plotted the distance between points (blue line) to highlight the issue.

Non-uniform grid

I would prefer if the mesh spacing didn't increase above the minimum $h$ value. Is there a way to preserve this property? It seems that I may need a peak function a zero second derivative. Can you suggest a better mesh density function for this problem?

  • $\begingroup$ +1 for the nice graphics ... do you use the TikZ package ? $\endgroup$
    – SAAD
    Commented Sep 15, 2013 at 9:04
  • $\begingroup$ TikZ looks interesting, I will have to take a closer look. Thanks for the nice comment. In this post the graph was matplotlib and the diagram was made is Omnigraffle (OSX only). $\endgroup$
    – boyfarrell
    Commented Sep 15, 2013 at 14:56

1 Answer 1


I suggest the following simple algorithm:

  1. Depending on whether you want symmetry of the mesh, either start at a point $x_0$ at the left end of your interval, or in the center. In the latter case, just mirror the mesh you obtain.

  2. Having performed the algorithm to $x_k$, compute $x_{k+1}$ as $x_k+h_k$, where \begin{gather} h_k = \min \left\{ h_{\max}, \frac{\bar h}{\rho(x_k)}\right\}, \end{gather} where $h_{\max}$ is your maximal allowed interval size, $\bar h$ is a control parameter determining the average spacing of the mesh, and $\rho$ is your density function. If you want this more fancy, you could use a denominator of $\rho(x_k+h_k/2)$, but that involves solving a nonlinear problem for $h_k$.

  • $\begingroup$ I'm curious about the role of $\bar{h}$. Why is it exactly an average spacing of the mesh? How should one choose it? $\endgroup$
    – math
    Commented Nov 3, 2017 at 10:35
  • $\begingroup$ For large $\rho$, the mesh spacing is $\overline h/\rho$. Thus, the number of intervals, which is the inverse of the average length, is roughly proportional to $1/\overline h$. Thus, with given $\rho$, $\overline h$ allows to construct a sequence of meshes of different average resolution. $\endgroup$ Commented Nov 8, 2017 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.