3 % Assembly of the Stiffness Matrix
using `P_1`-Lagrange finite elements
4 % - OptV1 version (see report).
6 % The Stiffness Matrix `\Stiff` is given by
7 % ``\Stiff_{i,j}=\int_\DOMH \DOT{\GRAD\FoncBase_i(\q)}{\GRAD\FoncBase_j(\q)}d\q,\ \forall (i,j)\in{\ENS{1}{\nq}}^2``
8 % where `\FoncBase_i` are `P_1`-Lagrange basis functions.
11 % nq: total number of nodes of the mesh, also denoted by `\nq`.
12 % nme: total number of triangles, also denoted by `\nme`.
13 % q: Array of vertices coordinates, `2\times\nq` array. <br/>
14 % `{\q}(\il,j)` is the
15 % `\il`-th coordinate of the `j`-th vertex, `\il\in\{1,2\}` and
17 % me: Connectivity array, `3\times\nme` array.<br/>
18 % `\me(\jl,k)` is the storage index of the
19 % `\jl`-th vertex of the `k`-th triangle in the array `\q` of vertices coordinates, `\jl\in\{1,2,3\}` and
20 % `k\in{\ENS{1}{\nme}}`.
21 % areas: Array of areas, `1\times\nme` array. areas(k) is the area of the `k`-th triangle.
24 % R: Stiffness Matrix, `\nq\times\nq` sparse matrix.
33 Ig=zeros(nme*9,1);Jg=zeros(nme*9,1);
36 ii=[1 2 3 1 2 3 1 2 3];
37 jj=[1 1 1 2 2 2 3 3 3];
40 Me=
ElemStiffMatP1(q(:,me(1,k)),q(:,me(2,k)),q(:,me(3,k)),areas(k));
46 R=sparse(Ig,Jg,Kg,nq,nq);