# A simple function for generating a nonuniform mesh in 1D with fixed minimum spacing

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.

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.

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?

• +1 for the nice graphics ... do you use the TikZ package ?
Commented Sep 15, 2013 at 9:04
• 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). Commented Sep 15, 2013 at 14:56

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$.
• I'm curious about the role of $\bar{h}$. Why is it exactly an average spacing of the mesh? How should one choose it?
• 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. Commented Nov 8, 2017 at 10:16