OptFEM2D  0.1
Matlab optimized FEM2D
 All Files Functions 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 the square domain `[0,1]\times[0,1]`.
4 % This mesh have 4 boundaries label :
5 % - label 1 : boundary `y=0`
6 % - label 2 : boundary `x=1`
7 % - label 3 : boundary `y=1`
8 % - label 4 : boundary `x=0`
9 % There is N+1 points on each boundary
10 %
11 % Parameters:
12 % N: integer
13 %
14 % Return values:
15 % Th: mesh structure
16 %
17  h=1/N;t=0:h:1;
18  if isOctave()
19  mesh=msh2m_structured_mesh(t,t,1,1:4); % package msh
20  me=mesh.t(1:3,:);
21  q=mesh.p;
22  else
23  [x,y] = meshgrid(t,t);
24  q=[x(:) y(:)]';
25  tri = delaunay(x,y);
26  me=tri';
27  end
28 
29  nq=length(q);
30  nme=length(me);
31 
32  ql=zeros(1,nq);
33  be=zeros(2,4*N);
34  bel=zeros(1,4*N);
35  % Points du bord
36  ql=zeros(1,nq);
37  I=find(q(2,:)==0);
38  ql(I)=1;
39  be(:,1:N)=[I(1:end-1);I(2:end)];
40  bel(:,1:N)=1;
41  I=find(q(1,:)==1);
42  ql(I)=2;
43  be(:,N+1:2*N)=[I(1:end-1);I(2:end)];
44  bel(:,N+1:2*N)=2;
45  I=find(q(2,:)==1);
46  ql(I)=3;
47  I=fliplr(I);
48  be(:,2*N+1:3*N)=[I(1:end-1);I(2:end)];
49  bel(:,2*N+1:3*N)=3;
50  I=find(q(1,:)==0);
51  ql(I)=4;
52  I=fliplr(I);
53  be(:,3*N+1:4*N)=[I(1:end-1);I(2:end)];
54  bel(:,3*N+1:4*N)=4;
55 
56  Th=struct('q',q,'me',me,'ql',ql,'mel',zeros(1,nme),'be',be,'bel',bel, ...
57  'nq',size(q,2), ...
58  'nme',size(me,2), ...
59  'nbe',size(be,2), ...
60  'areas',ComputeAreaOpt(q,me),...
61  'lbe',EdgeLengthOpt(be,q));
62