OptFEM2DP1 Toolbox  V1.2
Matlab/Octave Optimized P1-Lagrange Finite Element Method in 2D
base/SquareMesh.m
Go to the documentation of this file.
00001 function Th=SquareMesh(N)
00002 % function Th=SquareMesh(N)
00003 % Initialization of the Mesh structure for a square domain
00004 %
00005 % Square domain is `[0,1]\times[0,1]`.<br/>
00006 %
00007 % This mesh has 4 boundary labels :
00008 %   - label 1 : boundary `y=0`
00009 %   - label 2 : boundary `x=1`
00010 %   - label 3 : boundary `y=1`
00011 %   - label 4 : boundary `x=0` <br/>
00012 % There are N+1 points on each boundary.
00013 %
00014 % Parameters:
00015 %  N: integer, number of elements on a boundary
00016 %
00017 % Return values:
00018 %  Th: mesh structure
00019 %
00020 % Generated fields of mesh structure:
00021 %  q: Array of vertices coordinates, `2\times\nq` array. <br/>
00022 %  `{\q}(\il,j)` is the
00023 %  `\il`-th coordinate of the `j`-th vertex, `\il\in\{1,2\}` and
00024 %  `j\in\ENS{1}{\nq}`
00025 %  me: Connectivity array, `3\times\nme` array. <br/>
00026 %  `\me(\jl,k)` is the storage index of the
00027 %  `\jl`-th  vertex of the `k`-th triangle in the array `\q` of vertices coordinates, `\jl\in\{1,2,3\}` and
00028 %       `k\in{\ENS{1}{\nme}}`.
00029 %  ql: Array of vertices labels, `1\times\nq` array.
00030 %  mel: Array of elements labels, `1\times\nme` array.
00031 %  be: Connectivity array for boundary edges, `2\times\nbe` array.<br/>
00032 % `\be(\il,l)` is the storage index of the
00033 %  `\il`-th  vertex of the `l`-th edge in the array `\q` of vertices coordinates, `\il\in\{1,2\}` and
00034 %       `l\in{\ENS{1}{\nbe}}`.
00035 %  bel: Array of boundary edges labels, `1\times\nbe` array.
00036 %  nq: total number of vertices, also denoted by `\nq`
00037 %  nme: total number of elements, also denoted by `\nme`
00038 %  nbe: total number of boundary edges, also denoted by `\nbe`
00039 %  areas: Array of areas, `1\times\nme` array. areas(k) is the area of the `k`-th triangle.
00040 %  lbe: Array of edges lengths,  `1\times\nbe` array. `\lbe(j)`  is the length of the `j`-th edge.
00041 %
00042 % See also
00043 %  #ComputeAreaOpt, #EdgeLengthOpt, #GetMeshOpt
00044 % Copyright:
00045 %   See \ref license
00046   h=1/N;t=0:h:1;
00047   if isOctave()
00048     mesh=msh2m_structured_mesh(t,t,1,1:4); % package msh
00049     me=mesh.t(1:3,:);
00050     q=mesh.p;
00051   else
00052     [x,y] = meshgrid(t,t);
00053     q=[x(:) y(:)]';
00054     tri = delaunay(x,y);
00055     me=tri';
00056   end
00057   
00058   nq=length(q);
00059   nme=length(me);
00060   
00061   ql=zeros(1,nq);
00062   be=zeros(2,4*N);
00063   bel=zeros(1,4*N);
00064   % Points du bord
00065   ql=zeros(1,nq);
00066   I=find(q(2,:)==0);
00067   ql(I)=1;
00068   be(:,1:N)=[I(1:end-1);I(2:end)];
00069   bel(:,1:N)=1;
00070   I=find(q(1,:)==1);
00071   ql(I)=2;
00072   be(:,N+1:2*N)=[I(1:end-1);I(2:end)];
00073   bel(:,N+1:2*N)=2;
00074   I=find(q(2,:)==1);
00075   ql(I)=3;
00076   I=fliplr(I);
00077   be(:,2*N+1:3*N)=[I(1:end-1);I(2:end)];
00078   bel(:,2*N+1:3*N)=3;
00079   I=find(q(1,:)==0);
00080   ql(I)=4;
00081   I=fliplr(I);
00082   be(:,3*N+1:4*N)=[I(1:end-1);I(2:end)];
00083   bel(:,3*N+1:4*N)=4;
00084   
00085   Th=struct('q',q,'me',me,'ql',ql,'mel',zeros(1,nme),'be',be,'bel',bel, ...
00086             'nq',size(q,2), ...
00087             'nme',size(me,2), ...
00088             'nbe',size(be,2), ...
00089             'areas',ComputeAreaOpt(q,me),...
00090             'lbe',EdgeLengthOpt(be,q));
00091   
 All Files Functions