OptFEM2D  0.1
Matlab optimized FEM2D
 All Files Functions Groups Pages
MassWAssemblingP1OptV2.m
Go to the documentation of this file.
1 function M=MassWAssemblingP1OptV2(nq,nme,me,areas,Tw)
2 % function M=MassWAssemblingP1OptV2(nq,nme,me,areas,Tw)
3 % Assembling Mass Weight Matrix by `P_1`-Lagrange finite elements
4 % using "OptV2" version (see report).
5 %
6 % The Mass Weight Matrix 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 noted `\nq`,
11 % nme: number of triangles, also noted `\nme`,
12 % me: `3\times\nme` 'int32' array,`\me(\jl,k)` index of storage, in the array `q`, of the `\jl`-th
13 % vertex of the triangle of index `k`, `\jl\in\{1,2,3\}` and `k\in\{1,\hdots,\nme\}.`
14 % Also noted `\me`.
15 % areas: `1\times\nme` array, areas(k) is the area of triangle k.
16 % Tw: `\nme` 'double' array, `Tw(i)=w(\q^i),` `\forall i\in\ENS{1}{\nq}`.
17 %
18 % Return values:
19 % M: `\nq\times\nq` sparse matrix
20 %
21 % Example:
22 % @verbatim
23 % Th=SquareMesh(10);
24 % w=@(x,y) cos(x+y);
25 % Tw=w(Th.q(1,:),Th.q(2,:));
26 % Mw=MassWAssemblingP1OptV2(Th.nq,Th.nme,Th.me,Th.areas,Tw);
27 % @endverbatim
28 %
29 % See also:
30 % #SquareMesh
31 %
32 %% @author Francois Cuvelier @date 2012-03-09
33 %
34 % Copyright (c) 2012, Francois Cuvelier, Gilles Scarella
35 % All rights reserved.
36 %
37 % Redistribution and use in source and binary forms, with or without
38 % modification, are permitted only in compliance with the BSD license, see
39 % http://www.opensource.org/licenses/bsd-license.php
40 Ig = me([1 2 3 1 2 3 1 2 3],:);
41 Jg = me([1 1 1 2 2 2 3 3 3],:);
42 W=Tw(me).*(ones(3,1)*areas/30);
43 Kg=zeros(9,length(areas));
44 Kg(1,:)=3*W(1,:)+W(2,:)+W(3,:);
45 Kg(2,:)=W(1,:)+W(2,:)+W(3,:)/2;
46 Kg(3,:)=W(1,:)+W(2,:)/2+W(3,:);
47 Kg(5,:)=W(1,:)+3*W(2,:)+W(3,:);
48 Kg(6,:)=W(1,:)/2+W(2,:)+W(3,:);
49 Kg(9,:)=W(1,:)+W(2,:)+3*W(3,:);
50 Kg([4, 7, 8],:)=Kg([2, 3, 6],:);
51 M = sparse(Ig,Jg,Kg,nq,nq);