# FEM: which is the correct way to impose Dirichlet B.C

I know the Neumann B.C. is implicit in FEM language. However, I have seen at least two ways to impose Dirichlet B.C.

e.g. for the following problem 1D,

$$\nabla^2 u + \nabla u= 0, u_{left}= 1, u_{right}=0$$

1) set first and last row of assembled "A" to "0" at left hand side, set A(1,1)=1,A(end,end)=1, and specify the boundary value "1" and "0" in right hand side vector "b".

2) set first row&column, last row&column of assembled "A" to "0" at left hand side, then do the same thing as above.

these two methods are different, the first is more intuitive(probably preferred by finite difference user), while the second sounds more rigorous because we are setting the boundary "element".

I know these two ways may generate different results for some specific case. Could any body give some insight?

• What exactly is your question? Do you note that the above PDE does not have a solution? – shuhalo May 4 '14 at 12:43
• If they give different results, one of them has to be wrong... (@Martin: What about $u(x) = 1-x$ (assuming the domain is $(0,1)$?) – Christian Clason May 4 '14 at 12:56
• Less facetiously, the second approach usually removes the rows and columns from $A$ (and $b$) entirely, so one solves for the interior degrees of freedom only. In 1D, this doesn't make much difference, but in 3D the reduced matrix may be noticeably smaller, saving computational effort. – Christian Clason May 4 '14 at 12:59
• Something else to note is that, for problems that give a symmetric A matrix (eg, parabolic/elliptic pde like heat equation), method 2 preserves the symmetry, whereas method 1 will not. This can inform your choice of linear system solver, so it's good to keep in mind. – Tyler Olsen May 5 '14 at 4:11
• Possible duplicate of How to properly apply non-homogeneous Dirichlet boundary conditions with FEM? – osolmaz Apr 4 '18 at 6:51

I think the typical approach is 1), which can then be reformulated into a smaller system.

Using the approach in https://scicomp.stackexchange.com/a/5073/1804, suppose your finite element basis coefficients make up a vector $\xi$, and that you can partition them into the vectors $\xi_{int}$ and $\xi_{bc}$. Then you should be able to permute your system into something like

\begin{align} \left[\begin{array}{cc} A_{int} & A_{int-bc} \\ 0 & I \end{array}\right] \left[\begin{array}{c} \xi_{int} \\ \xi_{bc}\end{array}\right] = \left[\begin{array}{c} b_{int} \\ b_{bc}\end{array}\right] \end{align}

where $A_{int}$ and $A_{int-bc}$ are stiffness-like matrices, $b_{int}$ is the load vector for your system (in this case, a zero vector), and $b_{bc}$ contains your discretized boundary conditions.

From this formulation, you can reformulate into a smaller system.

The second approach sounds like it would give you a singular system, and the smaller system that results would only govern the interior degrees of freedom, which would only work if you had zero Dirichlet conditions.

• I think you are right in saying "which would only work if you had zero Dirichlet conditions", but why you think it results in a singular system? since we still put "I" there in the matrix – lorniper May 5 '14 at 11:51
• And this reformulation (taking the Schur complement of $I$ in your matrix) is exactly what I thought the second approach referred to (for $b_{bc}=0$, the corresponding complement of the right-hand side is just $b_{int}$, but in general you need to solve $A_{int}\xi_{int} = b_{int}-A_{int-bc} b_{bc}$). The only difference between the two approaches should be the size of the matrix you need to invert. – Christian Clason May 5 '14 at 19:10
• @lorniper: The description seemed to read "set the first row, first column, last row, and last column to zero", and "then do the same thing as above" seemed to refer to the right-hand side part, which didn't make a whole lot of sense to me. If you could clarify what you mean, I can revise my answer. – Geoff Oxberry May 5 '14 at 20:58
• @ChristianClason thanks, now I understand, I just simply did wrong with the right hand side in the second approach, and I agree they are equivalent – lorniper May 6 '14 at 8:03