## 6 Numerical Methods and Algorithms
### Models at the Macro-Scale
#### 6.1.1 Discretization in the Space-Time Domain
If \(u^{h}\) is just an approximation of the true solution function \(u\) of (86), then an error or residual will exist such that \[R(x)=L\Big{(}u^{h}(x)\Big{)}-f(x)\
eq 0\] (87) The idea at the basis of WRM is to force the residual to zero in some average sense over the domain \(\Omega\), namely, \[\int_{\Omega}R(x)w_{i}(x)dx=0,\text{ }i=1,\dots,l,\] (88) where \(w_{i}(x)\) values are the so-called _weight functions_. Depending upon the nature of the weight function, different types of Weighted Residual Methods can be used. The Point Collocation Method, Subdomain Collocation Method, Least Square Method, and Galerkin Method are a few of the common ones. The trial functions themselves are selected as the weight functions in the Galerkin variant of the Weighted Residual Method. So, in the Galerkin method, we set \(w_{i}=\phi_{i}\), \(\forall i=1,\ldots,l\) and the weak-form Galerkin model, for each element \(e\) is the following set of algebraic relations obtained from (88) and (85):  
\[\sum_{j=1}^{l}c_{j}\bigg{[}\int_{\Omega}L\big{(}\phi_{i}(x)\big{)}\phi_{i}(x)dx \bigg{]}=\int_{\Omega}f(x)\phi_{i}(x)dx,\;\;i=1,\ldots,l. \tag{89}\]  
or, in matrix form,  
\[{}^{c}\mathbf{M}^{e}\mathbf{c}={}^{e}\mathbf{f}, \tag{90}\]  
where  
\[{}^{e}\mathbf{M} = \bigg{[}\int_{\Omega}L\big{(}\phi_{i}(x)\big{)}\phi_{i}(x)dx\bigg{]} _{i,j=1,\ldots,n},\] \[{}^{e}\mathbf{c} = [c_{1},\ldots,c_{l}]^{T},\] \[{}^{e}\mathbf{f} = \bigg{[}\int_{\Omega}f(x)\phi_{i}(x)dx\bigg{]}_{i=1,\ldots,l}^{T},\]  
are, respectively, an \(l\times l\) matrix and two vectors of length \(l\). We assume that the vectors \({}^{e}\mathbf{f}\) also include both the \"essential\" and the \"natural\" boundary conditions (see [125] for details). The drawback of this model for second- and higher-order differential equations is that the approximation functions should be differentiable as many times as the actual solution \(u(x)\). The weak form in Equation (86) requires that the approximation chosen for \(u(x)\) should be at least linear in \(x\). In addition, it requires that \(u(x)\) be made continuous across the elements. The approximation functions \(\phi_{i}(x)_{i=1,\ldots,l}\), in each element \(e\), are chosen to have the so-called _interpolation property_, that is,  
\[\phi_{i}({}^{e}x_{j})=\delta_{ij},\forall i,j=1,\ldots,l, \tag{91}\]  
where \(\big{\{}{}^{e}\mathbf{x}_{j}\big{\}}_{j=1,\ldots,l}\) are the nodal points of the element \(e\). The scalar \(\delta_{ij}\) is defined as follows :  
\[\delta_{ij}=\left\{ \begin{array}{ll}1&\text{if}\quad i=j\\ 0&\text{if}\quad i\
eq j\end{array} \right.\]  
Then, the values of \(c_{j}\) in Equation (85) coincide with the values that \(u^{h}\) takes on at the same nodal points:  
\[c_{j}=u^{h}({}^{e}\mathbf{x}_{i}).\]  
Therefore, solving the Equation (90) allows one to identify the values that the approximation \(u^{h}\) takes on in the nodal points of each element \(e\). Functions that satisfy the interpolation property (91) are known as the Lagrange interpolation functions. The shape and number of nodes of the element are determined by the number \(l\) of linearly independent terms in the representation of \(u^{h}\). Not all geometric shapes qualify as finite element domains. It turns out that triangle- and quadrilateral-like shapes, with an appropriate number of nodes, qualify as elements. 3. Finite element assembly to produce the global system of algebraic equations of the form  
\[{}^{S}\mathbf{M}^{S}\mathbf{c}={}^{\delta}\mathbf{f}, \tag{92}\]  
where \({}^{\delta}\mathbf{M}_{s}\mathbf{c}\), and \({}^{\delta}\mathbf{f}\) are, respectively, am \(N_{nodes}\times N_{nodes}\) matrix and two vectors of length \(N_{nodes}\) and where \(N_{nodes}\) denotes the number of the nodes (the global grid node) of all the \(N_{elements}\) elements composing the finite element mesh. Therefore, the assembly procedure represents the realization of the global displacement boundary conditions as well as the inter-element compatibility of the approximation functions and the displacement field.