OptFEM2DP1 Toolbox  V1.2
Matlab/Octave Optimized P1-Lagrange Finite Element Method in 2D
base/GetMesh.m
Go to the documentation of this file.
00001 function Mesh=GetMesh(cFileName)
00002 % function Mesh=GetMesh(cFileName)
00003 % Initialization of the Mesh structure from a FreeFEM++ mesh file 
00004 % - Basic version
00005 %
00006 % Parameters:
00007 %  cFileName: FreeFEM++ mesh file name (string)
00008 %
00009 % Return values:
00010 %  Mesh: mesh structure
00011 %
00012 % Generated fields of Mesh:
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 %  ql: Array of vertices labels, `1\times\nq` array.
00022 %  mel: Array of elements labels, `1\times\nme` array.
00023 %  be: Connectivity array for boundary edges, `2\times\nbe` array.<br/>
00024 % `\be(\il,l)` is the storage index of the
00025 %  `\il`-th  vertex of the `l`-th edge in the array `\q` of vertices coordinates, `\il\in\{1,2\}` and
00026 %       `l\in{\ENS{1}{\nbe}}`.
00027 %  bel: Array of boundary edges labels, `1\times\nbe` array.
00028 %  nq: total number of vertices, also denoted by `\nq`.
00029 %  nme: total number of elements, also denoted by `\nme`.
00030 %  nbe: total number of boundary edges, also denoted by `\nbe`.
00031 %  areas: Array of areas, `1\times\nme` array. areas(k) is the area of the `k`-th triangle.
00032 %  lbe: Array of edges lengths,  `1\times\nbe` array. `lbe(j)`  is the length of the `j`-th edge.
00033 %
00034 % See also
00035 %  #ComputeArea, #EdgeLength
00036 % Example:
00037 %  @verbatim 
00038 %    Th=GetMesh('carre.msh')
00039 %  @endverbatim
00040 % Copyright:
00041 %   See \ref license
00042 [fid,message]=fopen(cFileName,'r');
00043 if ( fid == -1 )
00044   error([message,' : ',cFileName]);
00045 end
00046 n=fscanf(fid,'%d',3); ; % n(1) -> number of vertices    
00047                       % n(2) -> number of triangles     
00048                       % n(3) -> number of boundary edges
00049 me=zeros(3,n(2));
00050 ql=zeros(1,n(1));
00051 q=zeros(2,n(1));
00052 mel=zeros(1,n(2));
00053 for i=1:n(1)
00054   d_tmp=fscanf(fid,'%g',2);
00055   q(1,i)=d_tmp(1);
00056   q(2,i)=d_tmp(2);
00057   ql(i)=fscanf(fid,'%d',1);
00058 end
00059 for i=1:n(2)
00060   i_tmp=fscanf(fid,'%d',4);
00061   me(1,i)=i_tmp(1);
00062   me(2,i)=i_tmp(2);
00063   me(3,i)=i_tmp(3);
00064   mel(i)=i_tmp(4);
00065 end
00066 
00067 for i=1:n(3)
00068   i_tmp=fscanf(fid,'%d',3);
00069   be(1,i)=i_tmp(1);
00070   be(2,i)=i_tmp(2);
00071   bel(i) =i_tmp(3);
00072 end
00073 
00074 fclose(fid);
00075 
00076 Mesh=struct('q',q,'me',me,'ql',ql,'mel',mel,'be',be,'bel',bel, ...
00077             'nq',size(q,2), ...
00078             'nme',size(me,2), ...
00079             'nbe',size(be,2), ...
00080             'areas',ComputeArea(q,me),...
00081             'lbe',EdgeLength(be,q));
 All Files Functions