1
$\begingroup$

I am solving a 1D diffusion-type equation with the finite-difference Crank-Nicolson (CN) scheme, and I need to densify the spatial grid around the central point. One could change the spatial variable and re-derive the whole equation in terms of the new variable. Alternatively, in principle it should be possible to do something simpler, that is to re-write all the CN coefficients without assuming a uniform spacing. For example, for the advection term: $$ \frac{\partial f}{\partial t} = - \, u\, \frac{\partial f}{\partial x} $$ this would correspond to replacing $$ f^{n+1}_i \left[ 1 + u_i \, \frac{\Delta t}{2 \Delta x} \right] - f^{n+1}_{i-1} \cdot u_i \, \frac{\Delta t}{2 \Delta x} = f^{n}_i \left[ 1 - u_i \, \frac{\Delta t}{2 \Delta x} \right] + f^{n}_{i-1} \cdot u_i \, \frac{\Delta t}{2 \Delta x} $$ with the expression: $$ f^{n+1}_i \left[ 1 + u_i \, \frac{\Delta t}{2 (x_i - x_{i-1})} \right] - f^{n+1}_{i-1} \cdot u_i \, \frac{\Delta t}{2 (x_i - x_{i-1})} = f^{n}_i \left[ 1 - u_i \, \frac{\Delta t}{2 (x_i - x_{i-1})} \right] + f^{n}_{i-1} \cdot u_i \, \frac{\Delta t}{2 (x_i - x_{i-1})}, $$ where $n$ is the time index and $i$ is the space index. The diffusion term changes accordingly, although with a longer and a bit more complicated expression.

This way, it should be easy to control the spacing as needed based on physical reasons, according to functions that are as smooth as possible. However, this approach does not seem to work. Is there any reason for that? Or some specific constraints that are necessary?

Update: considering the grid built with the spacing in figure 1

grid spacing, around the central point of the grid, where I want it denser.

I obtain the following solutions, at different energies (figure 2), from where it shows that the low-energy solutions have problems:

solution of the full equation, for different energies.

$\endgroup$
7
  • $\begingroup$ your discretization scheme looks correct to me. to verify what you are doing is right, you could use a uniform grid in your code and verify if you get the same results as in your figure. $\endgroup$ Commented Dec 22, 2022 at 19:50
  • $\begingroup$ although, i do not know the physical significance of u in your eqn. have you tried using a first order upwind scheme (en.wikipedia.org/wiki/Upwind_scheme) for discretizing the advection term? $\endgroup$ Commented Dec 22, 2022 at 19:51
  • $\begingroup$ Hi, yes what I am doing is correct, because if I use a uniform grid with the second discretization scheme it gives the (known) analytical result. My question was: why do I encounter problems if I use a non-uniform grid? $\endgroup$
    – ottavio
    Commented Dec 26, 2022 at 14:26
  • $\begingroup$ @ottavio is your time step in any way adapted during the procedure, or do you use a fixed time step for all spatial steps in case of non-uniform grid? $\endgroup$
    – Akhaim
    Commented Jan 3, 2023 at 7:21
  • $\begingroup$ no no it's fixed, I am also not sure if Crank-Nicolson is suitable for adaptable time grids. $\endgroup$
    – ottavio
    Commented Jan 9, 2023 at 16:02

0