# 2.11 The Finite Element Method for Two-Dimensional Diffusion

## 2.11.4 Construction of the Stiffness Matrix

The stiffness matrix arises in the calculation of $$\int _{\Omega } \nabla \phi _ i \cdot \left(k\nabla \tilde{T}\right)\, dA$$. As in the one-dimensional case, the $$i$$-th row of the stiffness matrix $$K$$ corresponds to the weighted residual of $$\phi _ i$$. The $$j$$-th column in the $$i$$-th row corresponds to the dependence of the $$i$$-th weighted residual on $$a_ j$$. Further drawing on the one-dimensional example, the weighted residuals are assembled by calculating the contribution to all of the residuals from within a single element. In the two-dimensional linear element situation, three weighted residuals are impacted by a given element, specifically, the weighted residuals corresponding to the nodal basis functions of the three nodes of the triangle. For example, in each element we must calculate

 $\int _{\Omega _ e} \nabla \phi _1 \cdot \left(k\nabla \tilde{T}\right)\, dA, \qquad \int _{\Omega _ e} \nabla \phi _2 \cdot \left(k\nabla \tilde{T}\right)\, dA, \qquad \int _{\Omega _ e} \nabla \phi _3 \cdot \left(k\nabla \tilde{T}\right)\, dA,$ (2.281)

where $$\Omega _ e$$ is spatial domain for a specific element. As described in Section 2.11.3, the gradient of $$\tilde{T}$$ can be written,

 $\nabla \tilde{T}(x,y)= \sum _{j=1}^{3} a_ j\nabla \phi _ j(x,y),$ (2.282)

thus the weighted residuals expand to,

 $\int _{\Omega } \nabla \phi _ i \cdot \left(k\nabla \tilde{T}\right)\, dA = \sum _{j=1}^{3} a_ j K_{i,j}, \qquad \mbox{where } \qquad K_{i,j} \equiv \int _{\Omega } \nabla \phi _ i \cdot \left(k\nabla \phi _ j\right)\, dA.$ (2.283)

For the situation in which $$k$$ is constant and linear elements are used, then this reduces to

 $K_{i,j} \equiv k \nabla \phi _ i \cdot \nabla \phi _ j A_ e,$ (2.284)

where $$A_ e$$ is the area of element $$e$$.