OptFEM3DP1 Toolbox  V1.0
Matlab/Octave Optimized P1-Lagrange Finite Element Method in 3D
 All Files Functions Variables Pages
GetMeshOpt.m
Go to the documentation of this file.
1 function Mesh=GetMeshOpt(cFileName)
2 % function Mesh=GetMeshOpt(cFileName)
3 % Initialization of the Mesh structure from a FreeFEM++ mesh file
4 % % Optimized 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 % nq: total number of vertices.
14 % q: Array of vertices coordinates, 3-by-nq array.
15 % q(il,j) is the il-th coordinate of the j-th vertex, il in {1,3}
16 % and j in {1,...,nq}.
17 % ql: Array of vertices labels, 1-by-nq array.
18 % nme: total number of elements.
19 % me: Connectivity array, 4-by-nme array.
20 % me(jl,k) is the storage index of the jl-th vertex
21 % of the k-th triangle in the array q of vertices coordinates,
22 % jl in {1,..,4} and k in {1,...,nme}.
23 % mel: Array of elements labels, 1-by-nme array.
24 % nbf: total number of boundary faces, also denoted by `\nbf`
25 % bf: Connectivity array for boundary faces, 3-by-nbf array.
26 % bf(il,l) is the storage index of the il-th vertex
27 % of the l-th boundary face in the array q of vertices coordinates,
28 % il in {1,3} and l in {1,...,nbf}.
29 % bfl: Array of boundary faces labels, 1-by-nbf array.
30 % volumes: Array of volumes, 1-by-nme array. volumes(k) is the volume
31 % of the k-th triangle.
32 % abf: Array of faces areas, 1-by-nbf array. abf(j) is
33 % the area of the j-th boundary face.
34 %
35 % Example:
36 % Th=GetMesh('cube.mesh')
37 % Copyright:
38 % See \ref license
39 
40 %
41 % Copyright (C) 2013 CJS (LAGA)
42 % see README for details
43 [fid,message]=fopen(cFileName,'r');
44 if ( fid == -1 )
45  error([message,' : ',cFileName]);
46 end
47 for i=1:5
48  tline = fgetl(fid);
49 end
50 if isOctave()
51  nq=fscanf(fid,'%d',1);
52 
53  R=fscanf(fid,'%f %f %f %d',[4,nq]);
54  q=R([1 2 3],:);
55  ql=R(4,:);
56  for i=1:3
57  tline = fgetl(fid);
58  end
59  nme=fscanf(fid,'%d',1);
60  R=fscanf(fid,'%d %d %d %d %d',[5,nme]);
61 
62  me=R([1:4],:);
63  mel=R(5,:);
64  for i=1:3
65  tline = fgetl(fid);
66  end
67  nbf=fscanf(fid,'%d',1);
68  R=fscanf(fid,'%d %d %d %d',[4,nbf]);
69 
70  bf=R([1 2 3],:);
71  bfl=R(4,:);
72 else % Matlab
73  nq=fscanf(fid,'%d',1);
74 
75  R=textscan(fid,'%f %f %f %d',nq);
76  q=[R{1},R{2},R{3}]';
77  ql=R{4}';
78 
79  for i=1:3
80  tline = fgetl(fid);
81  end
82  nme=fscanf(fid,'%ld',1);
83 
84  R=textscan(fid,'%d %d %d %d %d',nme);
85  me=[R{1},R{2},R{3},R{4}]';
86  mel=R{5}';
87  for i=1:3
88  tline = fgetl(fid);
89  end
90  nbf=fscanf(fid,'%d',1);
91 
92  R=textscan(fid,'%d %d %d %d',nbf);
93  bf=[R{1},R{2},R{3}]';
94  bfl=R{4}';
95 end
96 fclose(fid);
97 
98 Mesh=struct('q',q,'me',double(me),'ql',ql,'mel',double(mel),'bf',double(bf),'bfl',double(bfl), ...
99  'nq',nq, ...
100  'nme',nme, ...
101  'nbf',nbf, ...
102  'volumes',ComputeVolumesOpt(me,q),...
103  'abf',FaceArea(bf,q));