3 % Assembling Stiff Matrix by `P_1`-Lagrange finite elements
4 % using "OptV2" version (see report).
6 % The Stiff Matrix 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 noted `\nq`.
12 % nme: number of triangles, also noted `\nme`.
13 % 'q': `2\times\nq` array, `{\q}(\il,j)` is the `\il`-th coordinate of the `j`-th vertex, `\il\in\{1,2\}` and `j\in\{1,\hdots,n_q\}.`
15 % me: `3\times\nme`
'int32' array,`\me(\jl,k)` index of storage, in the array `\q`, of the `\jl`-th
16 % vertex of the triangle of index `k`, `\jl\in\{1,2,3\}` and `k\in\{1,\hdots,\nme\}.`
18 % areas: `1\times\nme` array, areas(k) is the area of triangle k.
21 % R: `\nq\times\nq` sparse matrix
30 % @author Francois Cuvelier @date 2011-11-18
32 % @new{1,1,fc,2012-11-22} Added doxygen documentation
using mtoc++ tool
34 % Copyright (c) 2012, Francois Cuvelier, Gilles Scarella
35 % All rights reserved.
37 % Redistribution and use in source and binary forms, with or without
38 % modification, are permitted only in compliance with the BSD license, see
41 Ig = me([1 2 3 1 2 3 1 2 3],:);
42 Jg = me([1 1 1 2 2 2 3 3 3],:);
44 q1 =q(:,me(1,:)); q2 =q(:,me(2,:)); q3 =q(:,me(3,:));
45 u = q2-q3; v=q3-q1; w=q1-q2;
49 Kg(1,:)=sum(u.*u,1)./areas4; % K1 ou G11
50 Kg(2,:)=sum(v.*u,1)./areas4; % K2 ou G12
51 Kg(3,:)=sum(w.*u,1)./areas4; % K3 ou G13
52 Kg(5,:)=sum(v.*v,1)./areas4; % K5 ou G22
53 Kg(6,:)=sum(w.*v,1)./areas4; % K6 ou G23
54 Kg(9,:)=sum(w.*w,1)./areas4; % K9 ou G33
55 Kg([4, 7, 8],:)=Kg([2, 3, 6],:);
56 R = sparse(Ig,Jg,Kg,nq,nq);