# 2.9 Introduction to Finite Elements

## 2.9.5 Calculation of the Finite Element Weighted Residual

Measurable Outcome 2.12, Measurable Outcome 2.14, Measurable Outcome 2.15, Measurable Outcome 2.16, Measurable Outcome 2.17, Measurable Outcome 2.20

The implementation of the finite element method requires finding the weak form of the residual for each weight function \(\phi _ j(x)\). For the diffusion problem the \(j^{th}\) weighted residual is

\[r(\tilde{T}, \phi _ j) \equiv \left[\phi _ j\, k \tilde{T}_ x\right]^{L/2}_{-L/2} - \int _{-L/2}^{L/2} {\phi _ j}_ x\, k \tilde{T}_ x\, dx + \int _{-L/2}^{L/2} \phi _ j f\, dx. \label{equ:Rj_ dif1d}\] | (2.211)

We will consider the evaluation of the term \(\int _{-L/2}^{L/2} \phi _{j_ x}k\tilde{T}_{x} dx\) below. The approximation of \(\int _{-L/2}^{L/2} \phi _{j_ x} f dx\) will be discussed in Section 2.10.1; for now, we assume that this integral can be calculated analytically. For now, consider the term \(\int _{-L/2}^{L/2} {\phi _ j}_ x\, k \tilde{T}_ x\, dx\). While it is a global integral (i.e., an integral over the entire domain), in reality \(\phi _ j(x)\) is non-zero only over the two elements that include node \(j\):

\[\Rightarrow \int _{-L/2}^{L/2} {\phi _ j}_ x\, k \tilde{T}_ x\, dx = \int _{x_{j-1}}^{x_{j+1}} {\phi _ j}_ x\, k \tilde{T}_ x\, dx.\] | (2.212)

The derivative of basis function \(j\) is

\[{\phi _ j}_ x(x) = \left\{ \begin{array}{cl} 0, & \mbox{for } x < x_{j-1}, \\[0.1in] \frac{1}{\Delta x_{j-1}}, & \mbox{for } x_{j-1} < x < x_{j},\\[0.1in] \frac{-1}{\Delta x_{j}}, & \mbox{for } x_{j} < x < x_{j+1},\\[0.1in] 0, & \mbox{for } x > x_{j+1}. \end{array}\right. \label{equ:phi_ x_ linear}\] | (2.213)

Thus,

\[\int _{x_{j-1}}^{x_{j+1}} {\phi _ j}_ x\, k \tilde{T}_ x\, dx = \frac{1}{\Delta x_{j-1}} \int _{x_{j-1}}^{x_{j }} k \tilde{T}_ x\, dx - \frac{1}{\Delta x_{j }} \int _{x_{j }}^{x_{j+1}} k \tilde{T}_ x\, dx.\] | (2.214)

Next, take the derivative of \(\tilde{T}\):

\[\tilde{T}_ x(x) = \sum _{i=1}^{N+1} a_ i {\phi _ i}_ x(x).\] | (2.215)

For the integral in element \(j-1\), the only non-zero contributions to \(\tilde{T}_ x\) are from \(\phi _{j-1}\) and \(\phi _{j}\), specifically,

\[\mbox{In element }j-1: \qquad \tilde{T}_ x = a_{j-1}{\phi _{j-1}}_ x + a_{j}{\phi _{i}}_ x = \frac{a_ j - a_{j-1}}{\Delta x_{j-1}}.\] | (2.216)

Similarly,

\[\mbox{In element }j: \qquad \tilde{T}_ x = a_{j}{\phi _{j}}_ x + a_{j+1}{\phi _{j+1}}_ x = \frac{a_{j+1}-a_ j}{\Delta x_{j}}.\] | (2.217)

Substituting these expressions for the derivatives into the integral gives

\[\int _{x_{j-1}}^{x_{j+1}} {\phi _ j}_ x\, k \tilde{T}_ x\, dx = \frac{a_{j}-a_{j-1}}{(\Delta x_{j-1})^2} \int _{x_{j-1}}^{x_{j }} k \, dx - \frac{a_{j+1}-a_{j}}{(\Delta x_{j })^2} \int _{x_{j }}^{x_{j+1}} k \, dx.\] | (2.218)

At this point, we must integrate \(k(x)\) in each element. Efficient numerical methods to approximate this integral are discussed in Section 2.10.1. For the situation in which \(k\) is constant throughout the domain the integral reduces to the following expression.

\[\mbox{For }k = \mbox{constant}: \qquad \int _{x_{j-1}}^{x_{j+1}} {\phi _ j}_ x\, k \tilde{T}_ x\, dx = k\frac{a_{j}-a_{j-1}}{\Delta x_{j-1}}- k\frac{a_{j+1}-a_{j}}{\Delta x_{j }}.\] | (2.219)

## Exercise

For constant spacing \(\Delta x\), what does the integral \(\int _{x_{j-1}}^{x_{j+1}} {\phi _ j}_ x\, \tilde{T}_ x\, dx\) equal?

Exercise 1
\(k\frac{-a_{j-1} - a_{j+1}}{\Delta x}\)
\(k\frac{-a_{j-1} + 2a_ j - a_{j+1}}{\Delta x}\)
\(k\frac{-a_{j-1} - a_{j+1}}{2\Delta x}\)
\(k\frac{ a_{j-1} + 2a_ j + a_{j+1}}{\Delta x}\)

Answer: Setting \(\Delta x_{j-1} = \Delta x_{j+1} = \Delta x\), we get the same approximation for the second derivative that we saw in the section of finite differences. Is that a coincidence?