3D Finite Difference Matrix

2.9k Views Asked by At

I have been working with a finite difference code for the case in which my problem is axysimmetric. This means that all the code I have so far is for 2D In this case the coefficient matrix isn't hard to set up. For example, a coefficient matrix would be of the form:

$$ \begin{bmatrix} -4 & 1 & 0 & 0 & 1 \\ 1 & -4 & 1 & 0 & 0 & 1 \\ 0 & 1 & -4 & 1 & 0 & 0 & 1 \\ 0 & 0 & 1 & -4 & 1 & 0 & 0 & 1 \\ 1 & 0 & 0 &1 & -4 & 1 & 0 & 0 & 1 \\ & 1 & 0 & 0 &1 & -4 & 1 & 0 & 0 & 1 \\ && 1 & 0 & 0 &1 & -4 & 1 & 0 & 0 & 1 \\ &&& \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots \\ \end{bmatrix} $$

Here the $1$'s next to the $-4$'s are due to finite difference equations in the $x$ direction (for example) and the ones far from it are due to the equations in the $y$ direction.

Now I have to extend the code to consider 3D cases, but I'm not sure how you would build a matrix like the above for 3D. I image you end up adding two additional diagonals of $1$'s but I'm not sure exactly where.

Thanks for the help.

(Note: The $-4$'s and $1$'s are just for the example, my specific problem has variable coefficients, but this makes no difference for the structure of the matrix.)

1

There are 1 best solutions below

3
On BEST ANSWER

Let $D_k \in \mathbb{R}^{n \times n}$ with \begin{align} D_k = \begin{pmatrix} -k & 1 & 0 & 0& ... & 0\\ 1 & -k & 1 & 0& ... &0 \\ & \ddots &\ddots&\ddots&\\ 0 & 0& 0& 1 & -k&1 \end{pmatrix} \end{align} Then we know, that the $1D$ finite difference matrix is given by $D_2$. Let $I$ be the $n\times n$ identity matrix. For the $2D$ case we have the matrix $E_k\in \mathbb{R}^{n^2 \times n^2}$ defined as \begin{align} E_k=\begin{pmatrix} D_k & I & 0 & 0&... & 0 \\ I & D_k & I& 0&...&0\\ & \ddots &\ddots&\ddots&\\ 0 & 0&0&I &D_k & I \end{pmatrix} \end{align} Then the $2D$ finite difference is given by $E_4$. Now let $J$ be the $n^2 \times n^2$ identity matrix. For the $3D$ case we have the matrix $F_k\in \mathbb{R}^{n^3 \times n^3}$ defined as \begin{align} F_k=\begin{pmatrix} E_k & J & 0 & 0&... & 0 \\ J & E_k & J& 0&...&0\\ & \ddots &\ddots&\ddots&\\ 0 & 0&0&J &E_k & J \end{pmatrix} \end{align} And obviously, the $3D$ finite difference matrix is given by $F_6$