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.
Starting with the Galerkin method,
integrating \(u''{\psi}_i\) by parts results in
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
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}\):
Inserting this expansion for \(u\) in the variational form (?) leads to the linear system
for \(i=0,\ldots,N=N_n-1\).
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
with \(N=N_n\). Insertion in the variational form (?) leads to the linear system
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.
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
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
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\):
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\):
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\):