| OptFEM2DP1 Toolbox V1.2b3 Matlab/Octave Optimized P1-Lagrange Finite Element Method in 2D

- Main Page
- Related Pages
- Files

- File List
- File Members

All Files Functions Pages
GetMesh.m
Go to the documentation of this file.
1 function Mesh=GetMesh(cFileName)
2 % function Mesh=GetMesh(cFileName)
3 % Initialization of the Mesh structure from a FreeFEM++ mesh file
4 % - Basic version
5 %
6 % Parameters:
7 % cFileName: FreeFEM++ mesh file name (string)
8 %
9 % Return values:
10 % Mesh: mesh structure
11 %
12 % Generated fields of Mesh:
13 % q: Array of vertices coordinates, `2\times\nq` array. <br/>
14 % `{\q}(\il,j)` is the
15 % `\il`-th coordinate of the `j`-th vertex, `\il\in\{1,2\}` and
16 % `j\in\ENS{1}{\nq}`
17 % me: Connectivity array, `3\times\nme` array. <br/>
18 % `\me(\jl,k)` is the storage index of the
19 % `\jl`-th vertex of the `k`-th triangle in the array `\q` of vertices coordinates, `\jl\in\{1,2,3\}` and
20 % `k\in{\ENS{1}{\nme}}`.
21 % ql: Array of vertices labels, `1\times\nq` array.
22 % mel: Array of elements labels, `1\times\nme` array.
23 % be: Connectivity array for boundary edges, `2\times\nbe` array.<br/>
24 % `\be(\il,l)` is the storage index of the
25 % `\il`-th vertex of the `l`-th edge in the array `\q` of vertices coordinates, `\il\in\{1,2\}` and
26 % `l\in{\ENS{1}{\nbe}}`.
27 % bel: Array of boundary edges labels, `1\times\nbe` array.
28 % nq: total number of vertices, also denoted by `\nq`.
29 % nme: total number of elements, also denoted by `\nme`.
30 % nbe: total number of boundary edges, also denoted by `\nbe`.
31 % areas: Array of areas, `1\times\nme` array. areas(k) is the area of the `k`-th triangle.
32 % lbe: Array of edges lengths, `1\times\nbe` array. `lbe(j)` is the length of the `j`-th edge.
33 %
34 % See also
35 % #ComputeArea, #EdgeLength
36 % Example:
37 % @verbatim
38 % Th=GetMesh('carre.msh')
39 % @endverbatim
40 % Copyright:
41 % See \ref license
42 [fid,message]=fopen(cFileName,'r');
43 if ( fid == -1 )
44 error([message,' : ',cFileName]);
45 end
46 n=fscanf(fid,'%d',3); ; % n(1) -> number of vertices
47 % n(2) -> number of triangles
48 % n(3) -> number of boundary edges
49 me=zeros(3,n(2));
50 ql=zeros(1,n(1));
51 q=zeros(2,n(1));
52 mel=zeros(1,n(2));
53 for i=1:n(1)
54 d_tmp=fscanf(fid,'%g',2);
55 q(1,i)=d_tmp(1);
56 q(2,i)=d_tmp(2);
57 ql(i)=fscanf(fid,'%d',1);
58 end
59 for i=1:n(2)
60 i_tmp=fscanf(fid,'%d',4);
61 me(1,i)=i_tmp(1);
62 me(2,i)=i_tmp(2);
63 me(3,i)=i_tmp(3);
64 mel(i)=i_tmp(4);
65 end
66
67 for i=1:n(3)
68 i_tmp=fscanf(fid,'%d',3);
69 be(1,i)=i_tmp(1);
70 be(2,i)=i_tmp(2);
71 bel(i) =i_tmp(3);
72 end
73
74 fclose(fid);
75
76 Mesh=struct('q',q,'me',me,'ql',ql,'mel',mel,'be',be,'bel',bel, ...
77 'nq',size(q,2), ...
78 'nme',size(me,2), ...
79 'nbe',size(be,2), ...
80 'areas',ComputeArea(q,me),...
81 'lbe',EdgeLength(be,q));