# How to treat corners in a finite-difference solution to a PDE

### The Problem

Suppose I wish to solve the following PDE

$$\vec{\nabla} \cdot \vec{u} = \frac{\partial u_x}{\partial x} + \frac{\partial u_z}{\partial z} = 0$$

on the 2D domain ($0 \le x \le L$ and $0 \le z \le H$) with impermeable boundary conditions. This can be expressed as

$$\vec{u} \cdot \hat{n} = 0$$

where $\hat{n}$ is a unit vector pointing outward on the boundary (i.e. there is no flow in or out of the domain).

Suppose further that the flow field $\vec{u}(x,z)$ is a function of other variables and source terms which together prevent the naïve $\vec{u}=0$ solution.

### The Approach

I have set up a vertex-centered, finite-difference grid as shown in Figure (a) below:

(Note that Figure (b) shows a cell-centered grid, which may be related to my confusion....)

At all grid points (including side boundaries and corners), I solve $\vec{\nabla} \cdot \vec{u} = 0$. At the min-X ($x=0$) and max-X ($x=L$) boundaries, I simultaneously enforce $u_x=0$ by substitution and ghost points. In the same way, I enforce $u_z=0$ at the min-Z ($z=0$) and max-Z ($z=H$) boundaries. At the corners, I enforce both boundary conditions at once.

### My Results

The following figure shows part of the flow field I calculated for this PDE. The arrows have been normalized to show direction and the color indicates the magnitude. As mentioned before, I use a vertex-centered grid, so the cell-centered plot is perhaps misleading.

All boundary conditions have been enforced, even at the corners.

### My Question

I'm second-guessing myself!

Does the impermeable boundary condition I insist on mean that the corner point really should have zero flow?

In a finite-volume (or cell-centered) approach, the corner would enforce "inflow" from below to equal "outflow" to the left. In that case, the flow at the corner would not be zero. I recognize that my vertex-centered approach is different, but should there be any flow at the corner?

The presence of a "stagnation point" where $\mathbb{u} = 0$ is entirely possible in the solution of such problems.
For example, on the domain $\{(x,y): x \geqslant0, y \geqslant0 \}$ the velocity field $\mathbb{u} =(u(x,y),v(x,y)) = (x,-y)$ solves the Euler equations for inviscid flow and satisfies $\nabla \cdot \mathbb{u} = 0.$ The condition $\mathbb{u} \cdot \mathbb{n}$ is satisfied on the boundary $\{ (x,y): x = 0\} \cup \{(x,y): y =0 \},$ regardless of how $\mathbb{n}$ is defined at the corner. At the corner we have $u(0,0) = v(0,0) = 0$ -- approached smoothly by $u(x,y)$ and $v(x,y)$ as $(x,y) \to (0,0)$ from any direction. This would present no problem in solving the governing PDE numerically with finite differences.
In solving Navier-Stokes along with the incompressibility condition $\nabla \cdot \mathbb{u} = 0,$ a stronger boundary condition $\mathbb{u} = 0$ is enforced at solid walls. The sharp corner introduces a singularity leading to complex behavior in the velocity field near the corner -- and which can never be satisfactorily resolved numerically with a coarse mesh. For example, see here.