OptFEM2DP1  1.0
Matlab/Octave Optimized P1-Lagrange Finite Element Method in 2D
 All Files Functions Variables Groups Pages
SquareMesh.m
Go to the documentation of this file.
1 function Th=SquareMesh(N)
2 % function Th=SquareMesh(N)
3 % Initialization of the Mesh structure for a square domain
4 %
5 % Square domain is `[0,1]\times[0,1]`.<br/>
6 %
7 % This mesh has 4 boundary labels :
8 % - label 1 : boundary `y=0`
9 % - label 2 : boundary `x=1`
10 % - label 3 : boundary `y=1`
11 % - label 4 : boundary `x=0` <br/>
12 % There are N+1 points on each boundary.
13 %
14 % Parameters:
15 % N: integer, number of elements on a boundary
16 %
17 % Return values:
18 % Th: mesh structure
19 %
20 % See also
21 % #ComputeAreaOpt, EdgeLengthOpt
22 %
23 % OptFEM2DP1 [V1.0d] - Copyright (C) 2013 CJS (LAGA)
24 %
25 % This file is part of OptFEM2DP1.
26 % OptFEM2DP1 is free software: you can redistribute it and/or modify
27 % it under the terms of the GNU General Public License as published by
28 % the Free Software Foundation, either version 3 of the License, or
29 % (at your option) any later version.
30 %
31 % OptFEM2DP1 is distributed in the hope that it will be useful,
32 % but WITHOUT ANY WARRANTY; without even the implied warranty of
33 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 % GNU General Public License for more details.
35 %
36 % You should have received a copy of the GNU General Public License
37 % along with this program. If not, see <http://www.gnu.org/licenses/>.
38  h=1/N;t=0:h:1;
39  if isOctave()
40  mesh=msh2m_structured_mesh(t,t,1,1:4); % package msh
41  me=mesh.t(1:3,:);
42  q=mesh.p;
43  else
44  [x,y] = meshgrid(t,t);
45  q=[x(:) y(:)]';
46  tri = delaunay(x,y);
47  me=tri';
48  end
49 
50  nq=length(q);
51  nme=length(me);
52 
53  ql=zeros(1,nq);
54  be=zeros(2,4*N);
55  bel=zeros(1,4*N);
56  % Points du bord
57  ql=zeros(1,nq);
58  I=find(q(2,:)==0);
59  ql(I)=1;
60  be(:,1:N)=[I(1:end-1);I(2:end)];
61  bel(:,1:N)=1;
62  I=find(q(1,:)==1);
63  ql(I)=2;
64  be(:,N+1:2*N)=[I(1:end-1);I(2:end)];
65  bel(:,N+1:2*N)=2;
66  I=find(q(2,:)==1);
67  ql(I)=3;
68  I=fliplr(I);
69  be(:,2*N+1:3*N)=[I(1:end-1);I(2:end)];
70  bel(:,2*N+1:3*N)=3;
71  I=find(q(1,:)==0);
72  ql(I)=4;
73  I=fliplr(I);
74  be(:,3*N+1:4*N)=[I(1:end-1);I(2:end)];
75  bel(:,3*N+1:4*N)=4;
76 
77  Th=struct('q',q,'me',me,'ql',ql,'mel',zeros(1,nme),'be',be,'bel',bel, ...
78  'nq',size(q,2), ...
79  'nme',size(me,2), ...
80  'nbe',size(be,2), ...
81  'areas',ComputeAreaOpt(q,me),...
82  'lbe',EdgeLengthOpt(be,q));
83