OptFEM2D  0.1
Matlab optimized FEM2D
 All Files Functions Groups Pages
StiffAssemblingP1OptV2.m
Go to the documentation of this file.
1 function R=StiffAssemblingP1OptV2(nq,nme,q,me,areas)
2 % function R=StiffAssemblingP1OptV2(nq,nme,q,me,areas)
3 % Assembling Stiff Matrix by `P_1`-Lagrange finite elements
4 % using "OptV2" version (see report).
5 %
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.
9 %
10 % Parameters:
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\}.`
14 % Also noted `\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\}.`
17 % Also noted `\me`.
18 % areas: `1\times\nme` array, areas(k) is the area of triangle k.
19 %
20 % Return values:
21 % R: `\nq\times\nq` sparse matrix
22 %
23 % Example:
24 % @verbatim
25 % Th=SquareMesh(10);
26 % R=StiffAssemblingP1OptV2(Th.nq,Th.nme,Th.me,Th.q,Th.areas);@endverbatim
27 %
28 % See also:
29 % #SquareMesh
30 % @author Francois Cuvelier @date 2011-11-18
31 %
32 % @new{1,1,fc,2012-11-22} Added doxygen documentation using mtoc++ tool
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 me=double(me);
41 Ig = me([1 2 3 1 2 3 1 2 3],:);
42 Jg = me([1 1 1 2 2 2 3 3 3],:);
43 
44 q1 =q(:,me(1,:)); q2 =q(:,me(2,:)); q3 =q(:,me(3,:));
45 u = q2-q3; v=q3-q1; w=q1-q2;
46 clear q1 q2 q3
47 areas4=4*areas;
48 Kg=zeros(9,nme);
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);