| OptFEM2DP1 Toolbox 1.2b4 Matlab/Octave Optimized P1-Lagrange Finite Element Method in 2D

- Main Page
- Related Pages
- Files

- File List
- File Members

Opt/StiffAssembling2DP1OptV2.m
Go to the documentation of this file.

    00001 function R=StiffAssembling2DP1OptV2(nq,nme,q,me,areas)
    00002 % function R=StiffAssembling2DP1OptV2(nq,nme,q,me,areas)
    00003 %   Assembly of the Stiffness Matrix using `P_1`-Lagrange finite elements
    00004 %   - OptV2 version (see report).
    00005 %
    00006 %   The Stiffness Matrix `\Stiff` is given by
    00007 %   ``\Stiff_{i,j}=\int_\DOMH \DOT{\GRAD\FoncBase_i(\q)}{\GRAD\FoncBase_j(\q)}d\q,\ \forall (i,j)\in{\ENS{1}{\nq}}^2``
    00008 %   where `\FoncBase_i` are `P_1`-Lagrange basis functions.
    00009 %
    00010 % Parameters:
    00011 %  nq: total number of nodes of the mesh, also denoted by `\nq`.
    00012 %  nme: total number of triangles, also denoted by `\nme`.
    00013 %  q: Array of vertices coordinates, `2\times\nq` array. <br/>
    00014 %  `{\q}(\il,j)` is the
    00015 %  `\il`-th coordinate of the `j`-th vertex, `\il\in\{1,2\}` and
    00016 %  `j\in\ENS{1}{\nq}`
    00017 %  me: Connectivity array, `3\times\nme` array.<br/>
    00018 %  `\me(\jl,k)` is the storage index of the
    00019 %  `\jl`-th  vertex of the `k`-th triangle in the array `\q` of vertices coordinates, `\jl\in\{1,2,3\}` and
    00020 %       `k\in{\ENS{1}{\nme}}`.
    00021 %  areas: Array of areas, `1\times\nme` array. areas(k) is the area of the `k`-th triangle.
    00022 %
    00023 % Return values:
    00024 %  R: Stiffness Matrix, `\nq\times\nq` sparse matrix.
    00025 %
    00026 % Example:
    00027 %  @verbatim
    00028 %    Th=SquareMesh(10);
    00029 %    R=StiffAssembling2DP1OptV2(Th.nq,Th.nme,Th.me,Th.q,Th.areas);
    00030 %  @endverbatim
    00031 % Copyright:
    00032 %   See \ref license
    00033 Ig = me([1 2 3 1 2 3 1 2 3],:);
    00034 Jg = me([1 1 1 2 2 2 3 3 3],:);
    00035
    00036 q1 =q(:,me(1,:)); q2 =q(:,me(2,:)); q3 =q(:,me(3,:));
    00037 u = q2-q3; v=q3-q1; w=q1-q2;
    00038 clear q1 q2 q3
    00039 areas4=4*areas;
    00040 Kg=zeros(9,nme);
    00041 Kg(1,:)=sum(u.*u,1)./areas4; % K1 ou G11
    00042 Kg(2,:)=sum(v.*u,1)./areas4; % K2 ou G12
    00043 Kg(3,:)=sum(w.*u,1)./areas4; % K3 ou G13
    00044 Kg(5,:)=sum(v.*v,1)./areas4; % K5 ou G22
    00045 Kg(6,:)=sum(w.*v,1)./areas4; % K6 ou G23
    00046 Kg(9,:)=sum(w.*w,1)./areas4; % K9 ou G33
    00047 Kg([4, 7, 8],:)=Kg([2, 3, 6],:);
    00048 R = sparse(Ig,Jg,Kg,nq,nq);

All Files Functions