| OptFEM2D Toolbox for Matlab V1.2b1 Matlab/Octave Optimized P1-Lagrange Finite Element Method in 2D

- Main Page
- Related Pages
- Files

- File List
- File Members

All Files Functions Pages
GetMeshOpt.m
Go to the documentation of this file.
1 function Mesh=GetMeshOpt(cFileName)
2 % function Mesh=GetMesh(cFileName)
3 % Initialization of the Mesh structure from a FreeFEM++ mesh file -
4 % Optimized version
5 %
6 %
7 % Parameters:
8 % cFileName: FreeFEM++ mesh file name (string)
9 %
10 % Return values:
11 % Mesh: mesh structure
12 %
13 % Generated fields of Mesh:
14 % q: Array of vertices coordinates, `2\times\nq` array. <br/>
15 % `{\q}(\il,j)` is the
16 % `\il`-th coordinate of the `j`-th vertex, `\il\in\{1,2\}` and
17 % `j\in\ENS{1}{\nq}`
18 % me: Connectivity array, `3\times\nme` array. <br/>
19 % `\me(\jl,k)` is the storage index of the
20 % `\jl`-th vertex of the `k`-th triangle in the array `\q` of vertices coordinates, `\jl\in\{1,2,3\}` and
21 % `k\in{\ENS{1}{\nme}}`.
22 % ql: Array of vertices labels, `1\times\nq` array.
23 % mel: Array of elements labels, `1\times\nme` array.
24 % be: Connectivity array for boundary edges, `2\times\nbe` array.<br/>
25 % `\be(\il,l)` is the storage index of the
26 % `\il`-th vertex of the `l`-th edge in the array `\q` of vertices coordinates, `\il\in\{1,2\}` and
27 % `l\in{\ENS{1}{\nbe}}`.
28 % bel: Array of boundary edges labels, `1\times\nbe` array.
29 % nq: total number of vertices, also denoted by `\nq`
30 % nme: total number of elements, also denoted by `\nme`
31 % nbe: total number of boundary edges, also denoted by `\nbe`
32 % areas: Array of areas, `1\times\nme` array. areas(k) is the area of the `k`-th triangle.
33 % lbe: Array of edges lengths, `1\times\nbe` array. `\lbe(j)` is the length of the `j`-th edge.
34 %
35 % Example:
36 % @verbatim
37 % Th=GetMeshOpt('disk.msh')
38 % @endverbatim
39 %
40 % OptFEM2DP1 [V1.2b1] - Copyright (C) 2013 CJS (LAGA)
41 %
42 % This file is part of OptFEM2DP1.
43 % OptFEM2DP1 is free software: you can redistribute it and/or modify
44 % it under the terms of the GNU General Public License as published by
45 % the Free Software Foundation, either version 3 of the License, or
46 % (at your option) any later version.
47 %
48 % OptFEM2DP1 is distributed in the hope that it will be useful,
49 % but WITHOUT ANY WARRANTY; without even the implied warranty of
50 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 % GNU General Public License for more details.
52 %
53 % You should have received a copy of the GNU General Public License
54 % along with this program. If not, see <http://www.gnu.org/licenses/>.
55
56 % Example:
57 % @verbatim
58 % Th=GetMeshOpt('carre.msh')
59 % @endverbatim
60 % @author François Cuvelier
61 %
62
63 [fid,message]=fopen(cFileName,'r');
64 if ( fid == -1 )
65 error([message,' : ',cFileName]);
66 end
67 if isOctave()
68 [n]=fscanf(fid,'%d %d %d',3);
69
70 R=fscanf(fid,'%f %f %d',[3,n(1)]);
71 q=R([1 2],:);
72 ql=R(3,:);
73 R=fscanf(fid,'%d %d %d %d',[4,n(2)]);
74
75 me=R([1:3],:);
76 mel=R(4,:);
77 R=fscanf(fid,'%d %d %d',[3,n(3)]);
78
79 be=R([1 2],:);
80 bel=R(3,:);
81 else % Matlab
82 n=textscan(fid,'%d %d %d',1); % n(1) -> number of vertices
83 % n(2) -> number of triangles
84 % n(3) -> number of boundary edges
85
86 R=textscan(fid,'%f %f %d',n{1});
87 q=[R{1},R{2}]';
88 ql=R{3}';
89 R=textscan(fid,'%d %d %d %d',n{2});
90 me=[R{1},R{2},R{3}]';
91 mel=R{4}';
92
93 R=textscan(fid,'%d %d %d',n{3});
94 be=[R{1},R{2}]';
95 bel=R{3}';
96 end
97 fclose(fid);
98
99 Mesh=struct('q',q,'me',double(me),'ql',ql,'mel',double(mel), ...
100 'be',double(be),'bel',double(bel), ...
101 'nq',size(q,2), ...
102 'nme',size(me,2), ...
103 'nbe',size(be,2), ...
104 'areas',ComputeAreaOpt(q,me),...
105 'lbe',EdgeLength(be,q));
106