3
$\begingroup$

I have the following problem in 1-D: \begin{equation} \partial_t u(t,x) = v(x)\partial_x u(t,x) + \kappa(x) \partial_{xx} u(t,x),\,x\in\Omega;\quad \partial_{\nu}u(t,x) = 0, \,x\in\partial\Omega. \end{equation} I use the standard 3-point stencil for $\partial_{xx}$: $\frac{1}{h^2}\begin{bmatrix} 1 & -2 & 1 \end{bmatrix}$, and I would like to use central differences for the first derivative: $\partial_x \approx \frac{1}{2h} \begin{bmatrix} -1 & 0 & 1 \end{bmatrix}$. Let $\Omega = (0,1)$ and $\partial\Omega = \{0,1\}$, then I choose the interior nodes to be $\{1,\ldots,n\}$ and the boundary ones to be $\{0,n+1\}$. I am not sure how I should handle the boundary conditions for the first derivative however. I could for instance discretise the boundary conditions as follows: \begin{align} \partial_{\nu} u_0 &= -\partial_x u_0 \approx\frac{u_{0}-u_1}{h} = 0 \implies u_0 = u_1, \\ \partial_{\nu} u_{n+1} &= \partial_x u_{n+1} \approx \frac{u_{n+1}-u_n}{h} = 0 \implies u_{n+1} = u_n. \end{align} then by substituting in the second derivative and first derivative approximations I get: \begin{align} \partial_{xx}u_1 &\approx \frac{u_0-2u_1+u_2}{h^2} = \frac{-u_1+u_2}{h^2}, \\ \partial_x u_1 &\approx \frac{u_2-u_{0}}{2h}=\frac{u_2-u_1}{2h}, \\ \partial_x u_n &= \frac{u_{n+1}-u_{n-1}}{2h} = \frac{u_{n}-u_{n-1}}{2h}. \end{align} The latter worries me a bit since it looks like a standard forward difference except it is divided by two. Should I instead just use a forward and backward difference there that is not divided by two: \begin{equation} \partial_x u_1 \approx \frac{u_2-u_1}{h}, \quad \partial_x u_n \approx \frac{u_n-u_{n-1}}{h}? \end{equation}

I haven't tackled diffusion-advection problems or used central differences for first derivatives previously, so I am not sure what I should do. I could for instance also use a forward or backward difference for $\partial_x u_i$ instead of a central one, which I guess would make more sense if the process is advection dominated (e.g. if $v\gg\kappa$), but I wanted to try using central differences. I am just not sure what the proper approach is to handle the boundaries.

$\endgroup$

1 Answer 1

1
$\begingroup$

The factor 2 arising in the approximation of $\partial_x u_1$ and $\partial_x u_{n+1}$ is correct. It is correct because you are discretizing your boundary conditions ($\partial_x u_0$ and $\partial_x u_{n+1}$) with an approximation which is first-order accurate only.

If you discretize your boundary conditions with second-order accurate approximations such as, $\partial_x u_0 = \frac{1}{h}\left(-\frac{3}{2}u_0 + 2 u_1 - \frac{1}{2}u_2\right)$ and $\partial_x u_{n+1} = \frac{1}{h}\left(\frac{3}{2}u_{n+1} - 2 u_n + \frac{1}{2}u_{n-1}\right)$, you get $u_0 = \frac{2}{3}\left(2u_1 - \frac{u_2}{2}\right)$ and $u_{n+1} = \frac{2}{3}\left(2u_n - \frac{u_{n-1}}{2}\right)$. Substituting $u_0$ and $u_{n+1}$ in the first derivative approximations (central difference) of $\partial_x u_1$ and $\partial_x u_n$ gives you $\partial_x u_1 = \frac{2}{3h} (u_2 - u_1)$ and $\partial_x u_n = \frac{2}{3h} (u_n - u_{n-1})$.

$\endgroup$
3
  • 1
    $\begingroup$ What stops me from using $\partial_ xu_1 \approx \frac{u_2 - u_1}{h}$ instead? Then I could frame it as a first order difference at $u_1$ (regardless of the fact that I use second order differences at the rest). Would this mean that both $\frac{u_2-u_1}{2h}$ and $\frac{u_2-u_1}{h}$ are valid? This seems somewhat dubious. $\endgroup$
    – lightxbulb
    Aug 28, 2023 at 8:35
  • $\begingroup$ if you decide to use central differencing scheme for $\partial_x u_i$ (i = 1 to n), then what you wrote in the question is correct. If you decide to use forward differencing scheme for $\partial_x u_i$, then what you wrote in your earlier comment is correct. $\endgroup$ Aug 30, 2023 at 18:43
  • 1
    $\begingroup$ What stops me from mixing the two? They are both consistent discretisations of the derivative. $\endgroup$
    – lightxbulb
    Aug 30, 2023 at 20:22

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.