Boundary conditions: specified derivative¶

Suppose our model problem $$-u''(x)=f(x)$$ features the boundary conditions $$u'(0)=C$$ and $$u(L)=D$$. As already indicated in the section Examples on variational formulations, the former condition can be incorporated through the boundary term that arises from integration by parts. This details of this method will now be illustrated in the context of finite element basis functions.

The variational formulation¶

Starting with the Galerkin method,

$\int_0^L(u''(x)+f(x)){\psi}_i(x) {\, \mathrm{d}x} = 0,\quad i\in{\mathcal{I}_s},$

integrating $$u''{\psi}_i$$ by parts results in

$\int_0^Lu'(x)'{\psi}_i'(x) {\, \mathrm{d}x} -(u'(L){\psi}_i(L) - u'(0){\psi}_i(0)) = \int_0^L f(x){\psi}_i(x) {\, \mathrm{d}x}, \quad i\in{\mathcal{I}_s}{\thinspace .}$

The first boundary term, $$u'(L){\psi}_i(L)$$, vanishes because $$u(L)=D$$. There are two arguments for this result, explained in detail below. The second boundary term, $$u'(0){\psi}_i(0)$$, can be used to implement the condition $$u'(0)=C$$, provided $${\psi}_i(0)\neq 0$$ for some $$i$$ (but with finite elements we fortunately have $${\psi}_0(0)=1$$). The variational form of the differential equation then becomes

Boundary term vanishes because of the test functions¶

At points where $$u$$ is known we may require $${\psi}_i$$ to vanish. Here, $$u(L)=D$$ and then $${\psi}_i(L)=0$$, $$i\in{\mathcal{I}_s}$$. Obviously, the boundary term $$u'(L){\psi}_i(L)$$ then vanishes.

The set of basis functions $$\left\{ {{\psi}}_i \right\}_{i\in{\mathcal{I}_s}}$$ contains in this case all the finite element basis functions on the mesh, expect the one that is 1 at $$x=L$$. The basis function that is left out is used in a boundary function $$B(x)$$ instead. With a left-to-right numbering, $${\psi}_i = {\varphi}_i$$, $$i=0,\ldots,N_n-1$$, and $$B(x)=D{\varphi}_{N_n}$$:

$u(x) = D{\varphi}_{N_n}(x) + \sum_{j=0}^{N=N_n-1} c_j{\varphi}_j(x){\thinspace .}$

Inserting this expansion for $$u$$ in the variational form (?) leads to the linear system

(2)$\sum_{j=0}^{N}\left( \int_0^L {\varphi}_i'(x){\varphi}_j'(x) {\, \mathrm{d}x} \right)c_j = \int_0^L\left(f(x){\varphi}_i(x) -D{\varphi}_{N_n}'(x){\varphi}_i(x)\right) {\, \mathrm{d}x} - C{\varphi}_i(0),$

for $$i=0,\ldots,N=N_n-1$$.

Boundary term vanishes because of linear system modifications¶

We may, as an alternative to the approach in the previous section, use a basis $$\left\{ {{\psi}}_i \right\}_{i\in{\mathcal{I}_s}}$$ which contains all the finite element functions on the mesh: $${\psi}_i={\varphi}_i$$, $$i=0,\ldots,N_n=N$$. In this case, $$u'(L){\psi}_i(L)=u'(L){\varphi}_i(L)\neq 0$$ for the $$i$$ corresponding to the boundary node at $$x=L$$ (where $${\varphi}_i=1$$). The number of this node is $$i=N_n=N$$ if a left-to-right numbering of nodes is utilized.

However, even though $$u'(L){\varphi}_N(L)\neq 0$$, we do not need to compute this term. For $$i<N$$ we realize that $${\varphi}_i(L)=0$$. The only nonzero contribution to the right-hand side from the affects $$b_N$$ ($$i=N$$). Without a boundary function we must implement the condition $$u(L)=D$$ by the equivalent statement $$c_N=D$$ and modify the linear system accordingly. This modification will earse the last row and replace $$b_N$$ by another value. Any attempt to compute the boundary term $$u'(L){\varphi}_N(L)$$ and store it in $$b_N$$ will be lost. Therefore, we can safely forget about boundary terms corresponding to Dirichlet boundary conditions also when we use the methods from the section Modification of the linear system (1) or the section Symmetric modification of the linear system.

The expansion for $$u$$ reads

$u(x) = \sum_{j\in{\mathcal{I}_s}} c_j{\varphi}_j(x), \quad B(x) = D{\varphi}_N(x),$

with $$N=N_n$$. Insertion in the variational form (?) leads to the linear system

(3)$\sum_{j\in{\mathcal{I}_s}}\left( \int_0^L {\varphi}_i'(x){\varphi}_j'(x) {\, \mathrm{d}x} \right)c_j = \int_0^L\left(f(x){\varphi}_i(x)\right) {\, \mathrm{d}x} - C{\varphi}_i(0),\quad i\in{\mathcal{I}_s} {\thinspace .}$

After having computed the system, we replace the last row by $$c_N=D$$, either straightforwardly as in Section ref:ref:fem:deq:1D:fem:essBC:Bfunc:modsys or in a symmetric fashion as in Section ref:ref:fem:deq:1D:fem:essBC:Bfunc:modsys:symm. These modifications can also be performed in the element matrix and vector for the right-most cell.

Direct computation of the global linear system¶

We now turn to actual computations with P1 finite elements. The focus is on how the linear system and the element matrices and vectors are modified by the condition $$u'(0)=C$$.

Consider first the approach where Dirichlet conditions are incorporated by a $$B(x)$$ function and the known degree of freedom $$C_{N_n}$$ is left out from the linear system (see the section Boundary term vanishes because of the test functions). The relevant formula for the linear system is given by (2). There are three differences compared to the extensively computed case where $$u(0)=0$$ in the sections Computation in the global physical domain and Cellwise computations (1). First, because we do not have a Dirichlet condition at the left boundary, we need to extend the linear system (14.3) with an equation associated with the node $$x_{0}=0$$. According to the section Modification of the linear system (1), this extension consists of including $$A_{0,0}=1/h$$, $$A_{0,1}=-1/h$$, and $$b_0=h$$. For $$i>0$$ we have $$A_{i,i}=2/h$$, $$A_{i-1,i}=A_{i,i+1}=-1/h$$. Second, we need to include the extra term $$-C{\varphi}_i(0)$$ on the right-hand side. Since all $${\varphi}_i(0)=0$$ for $$i=1,\ldots,N$$, this term reduces to $$-C{\varphi}_0(0)=-C$$ and affects only the first equation ($$i=0$$). We simply add $$-C$$ to $$b_0$$ such that $$b_0=h - C$$. Third, the boundary term $$-\int_0^L D{\varphi}_{N_n}(x){\varphi}_i{\, \mathrm{d}x}$$ must be computed. Since $$i=0,\ldots,N=N_n-1$$, this integral can only get a nonzero contribution with $$i=N_n-1$$ over the last cell. The result becomes $$-Dh/6$$. The resulting linear system can be summarized in the form

(4)$\begin{split} \frac{1}{h}\left( \begin{array}{ccccccccc} 1 & -1 & 0 &\cdots & \cdots & \cdots & \cdots & \cdots & 0 \\ -1 & 2 & -1 & \ddots & & & & & \vdots \\ 0 & -1 & 2 & -1 & \ddots & & & & \vdots \\ \vdots & \ddots & & \ddots & \ddots & 0 & & & \vdots \\ \vdots & & \ddots & \ddots & \ddots & \ddots & \ddots & & \vdots \\ \vdots & & & 0 & -1 & 2 & -1 & \ddots & \vdots \\ \vdots & & & & \ddots & \ddots & \ddots &\ddots & 0 \\ \vdots & & & & &\ddots & \ddots &\ddots & -1 \\ 0 &\cdots & \cdots &\cdots & \cdots & \cdots & 0 & -1 & 2 \end{array} \right) \left( \begin{array}{c} c_0 \\ \vdots\\ \vdots\\ \vdots \\ \vdots \\ \vdots \\ \vdots \\ \vdots\\ c_{N} \end{array} \right) = \left( \begin{array}{c} h - C \\ 2h\\ \vdots\\ \vdots \\ \vdots \\ \vdots \\ \vdots \\ \vdots\\ 2h - Dh/6 \end{array} \right){\thinspace .}\end{split}$

Next we consider the technique where we modify the linear system to incorporate Dirichlet conditions (see the section Boundary term vanishes because of linear system modifications). Now $$N=N_n$$. The two differences from the case above is that the $$-\int_0^LD{\varphi}_{N_n}{\varphi}_i{\, \mathrm{d}x}$$ term is left out of the right-hand side and an extra last row associated with the node $$x_{N_n}=L$$ where the Dirichlet condition applies is appended to the system. This last row is anyway replaced by the condition $$C_N=D$$ or this condition can be incorporated in a symmetric fashion. Using the simplest, former approach gives

(5)$\begin{split} \frac{1}{h}\left( \begin{array}{ccccccccc} 1 & -1 & 0 &\cdots & \cdots & \cdots & \cdots & \cdots & 0 \\ -1 & 2 & -1 & \ddots & & & & & \vdots \\ 0 & -1 & 2 & -1 & \ddots & & & & \vdots \\ \vdots & \ddots & & \ddots & \ddots & 0 & & & \vdots \\ \vdots & & \ddots & \ddots & \ddots & \ddots & \ddots & & \vdots \\ \vdots & & & 0 & -1 & 2 & -1 & \ddots & \vdots \\ \vdots & & & & \ddots & \ddots & \ddots &\ddots & 0 \\ \vdots & & & & &\ddots & -1 & 2 & -1 \\ 0 &\cdots & \cdots &\cdots & \cdots & \cdots & 0 & 0 & 1 \end{array} \right) \left( \begin{array}{c} c_0 \\ \vdots\\ \vdots\\ \vdots \\ \vdots \\ \vdots \\ \vdots \\ \vdots\\ c_{N} \end{array} \right) = \left( \begin{array}{c} h - C \\ 2h\\ \vdots\\ \vdots \\ \vdots \\ \vdots \\ \vdots \\ 2h \\ D \end{array} \right){\thinspace .}\end{split}$

Cellwise computations (2)¶

Now we compute with one element at a time, working in the reference coordinate system $$X\in [-1,1]$$. We need to see how the $$u'(0)=C$$ condition affects the element matrix and vector. The extra term $$-C{\varphi}_i(0)$$ in the variational formulation only affects the element vector in the first cell. On the reference cell, $$-C{\varphi}_i(0)$$ is transformed to $$-C{\tilde{\varphi}}_r(-1)$$, where $$r$$ counts local degrees of freedom. We have $${\tilde{\varphi}}_0(-1)=1$$ and $${\tilde{\varphi}}_1(-1)=0$$ so we are left with the contribution $$-C{\tilde{\varphi}}_0(-1)=-C$$ to $$\tilde b^{(0)}_0$$:

(6)$\begin{split} \tilde A^{(0)} = A = \frac{1}{h}\left(\begin{array}{rr} 1 & 1\\ -1 & 1 \end{array}\right),\quad \tilde b^{(0)} = \left(\begin{array}{c} h - C\\ h \end{array}\right){\thinspace .}\end{split}$

No other element matrices or vectors are affected by the $$-C{\varphi}_i(0)$$ boundary term.

There are two alternative ways of incorporating the Dirichlet condition. Following the section Boundary term vanishes because of the test functions, we get a $$1\times 1$$ element matrix in the last cell and an element vector with an extra term containing $$D$$:

(7)$\tilde A^{(e)} =\frac{1}{h}\left(\begin{array}{r} 1 \end{array}\right),\quad \tilde b^{(e)} = h\left(\begin{array}{c} 1 - D/6 \end{array}\right),$

Alternatively, we include the degree of freedom at the node with $$u$$ specified. The element matrix and vector must then be modified to constrain the $$\tilde c_1 = c_N$$ value at local node $$r=1$$:

(8)$\begin{split} \tilde A^{(N_e)} = A = \frac{1}{h}\left(\begin{array}{rr} 1 & 1\\ 0 & 1 \end{array}\right),\quad \tilde b^{(N_e)} = \left(\begin{array}{c} h\\ D \end{array}\right){\thinspace .}\end{split}$