3 % Assembly of the Weighted Mass Matrix
using `P_1`-Lagrange finite elements
4 % - OptV2 version (see report).
6 % The Weighted Mass Matrix `\MasseF{w}` is given by
7 % ``\MasseF{w}_{i,j}=\int_\DOMH w(\q)\;\FoncBase_i(\q)\; \FoncBase_j(\q)\; d\q,\ \forall (i,j)\in{\ENS{1}{\nq}}^2``
8 % where `\FoncBase_i` are `P_1`-Lagrange basis functions.
10 % nq: total number of nodes of the mesh, also denoted by `\nq`,
11 % nme: total number of triangles, also denoted by `\nme`,
12 % me: Connectivity array, `3\times\nme` array.<br/>
13 % `\me(\jl,k)` is the storage index of the
14 % `\jl`-th vertex of the `k`-th triangle in the array `\q` of vertices coordinates, `\jl\in\{1,2,3\}` and
15 % `k\in{\ENS{1}{\nme}}`.
16 % areas: Array of areas, `1\times\nme` array. areas(k) is the area of the `k`-th triangle.
17 % Tw: Array containing the values of `w` at the vertices,
18 % `1\times\nq` array.<br/>
19 % `Tw(i)=w(\q^i),` `\forall i\in\ENS{1}{\nq}`.
22 % M: Global weighted mass matrix, `\nq\times\nq` sparse matrix.
28 % Tw=w(Th.q(1,:),Th.q(2,:));
33 Ig = me([1 2 3 1 2 3 1 2 3],:);
34 Jg = me([1 1 1 2 2 2 3 3 3],:);
35 W=Tw(me).*(ones(3,1)*areas/30);
36 Kg=zeros(9,length(areas));
37 Kg(1,:)=3*W(1,:)+W(2,:)+W(3,:);
38 Kg(2,:)=W(1,:)+W(2,:)+W(3,:)/2;
39 Kg(3,:)=W(1,:)+W(2,:)/2+W(3,:);
40 Kg(5,:)=W(1,:)+3*W(2,:)+W(3,:);
41 Kg(6,:)=W(1,:)/2+W(2,:)+W(3,:);
42 Kg(9,:)=W(1,:)+W(2,:)+3*W(3,:);
43 Kg([4, 7, 8],:)=Kg([2, 3, 6],:);
44 M = sparse(Ig,Jg,Kg,nq,nq);