OptFEM2DP1 Toolbox  V1.2b3
Matlab/Octave Optimized P1-Lagrange Finite Element Method in 2D
 All Files Functions Pages
MassWAssemblingP1OptV1.m
Go to the documentation of this file.
1 function M=MassWAssemblingP1OptV1(nq,nme,me,areas,Tw)
2 % function M=MassWAssemblingP1OptV1(nq,nme,me,areas,Tw)
3 % Assembly of the Weighted Mass Matrix using `P_1`-Lagrange finite elements
4 % - OptV1 version (see report).
5 %
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.
9 % Parameters:
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 (double).<br/>
19 % `Tw(i)=w(\q^i),` `\forall i\in\ENS{1}{\nq}`.
20 %
21 % Return values:
22 % M: Global weighted mass matrix, `\nq\times\nq` sparse matrix.
23 %
24 % Example:
25 % @verbatim
26 % Th=SquareMesh(10);
27 % w=@(x,y) cos(x+y);
28 % Tw=w(Th.q(1,:),Th.q(2,:));
29 % Mw=MassWAssemblingP1OptV1(Th.nq,Th.nme,Th.me,Th.areas,Tw);
30 % @endverbatim
31 % Copyright:
32 % See \ref license
33 Ig=zeros(9*nme,1);Jg=zeros(9*nme,1);Kg=zeros(9*nme,1);
34 
35 ii=[1 2 3 1 2 3 1 2 3];
36 jj=[1 1 1 2 2 2 3 3 3];
37 kk=1:9;
38 for k=1:nme
39  E=ElemMassWMatP1(areas(k),Tw(me(:,k)));
40  Ig(kk)=me(ii,k);
41  Jg(kk)=me(jj,k);
42  Kg(kk)=E(:);
43  kk=kk+9;
44 end
45 M=sparse(Ig,Jg,Kg,nq,nq);
46