![]() |
OptFEM2DP1 Toolbox
V1.2
Matlab/Octave Optimized P1-Lagrange Finite Element Method in 2D
|
00001 function Mesh=GetMeshOpt(cFileName) 00002 % function Mesh=GetMesh(cFileName) 00003 % Initialization of the Mesh structure from a FreeFEM++ mesh file - 00004 % Optimized version 00005 % 00006 % 00007 % Parameters: 00008 % cFileName: FreeFEM++ mesh file name (string) 00009 % 00010 % Return values: 00011 % Mesh: mesh structure 00012 % 00013 % Generated fields of Mesh: 00014 % q: Array of vertices coordinates, `2\times\nq` array. <br/> 00015 % `{\q}(\il,j)` is the 00016 % `\il`-th coordinate of the `j`-th vertex, `\il\in\{1,2\}` and 00017 % `j\in\ENS{1}{\nq}` 00018 % me: Connectivity array, `3\times\nme` array. <br/> 00019 % `\me(\jl,k)` is the storage index of the 00020 % `\jl`-th vertex of the `k`-th triangle in the array `\q` of vertices coordinates, `\jl\in\{1,2,3\}` and 00021 % `k\in{\ENS{1}{\nme}}`. 00022 % ql: Array of vertices labels, `1\times\nq` array. 00023 % mel: Array of elements labels, `1\times\nme` array. 00024 % be: Connectivity array for boundary edges, `2\times\nbe` array.<br/> 00025 % `\be(\il,l)` is the storage index of the 00026 % `\il`-th vertex of the `l`-th edge in the array `\q` of vertices coordinates, `\il\in\{1,2\}` and 00027 % `l\in{\ENS{1}{\nbe}}`. 00028 % bel: Array of boundary edges labels, `1\times\nbe` array. 00029 % nq: total number of vertices, also denoted by `\nq` 00030 % nme: total number of elements, also denoted by `\nme` 00031 % nbe: total number of boundary edges, also denoted by `\nbe` 00032 % areas: Array of areas, `1\times\nme` array. areas(k) is the area of the `k`-th triangle. 00033 % lbe: Array of edges lengths, `1\times\nbe` array. `\lbe(j)` is the length of the `j`-th edge. 00034 % 00035 % See also 00036 % #ComputeAreaOpt, #EdgeLength 00037 % Example: 00038 % @verbatim 00039 % Th=GetMeshOpt('disk.msh') 00040 % @endverbatim 00041 % Copyright: 00042 % See \ref license 00043 00044 % Example: 00045 % @verbatim 00046 % Th=GetMeshOpt('carre.msh') 00047 % @endverbatim 00048 % @author François Cuvelier 00049 % 00050 00051 [fid,message]=fopen(cFileName,'r'); 00052 if ( fid == -1 ) 00053 error([message,' : ',cFileName]); 00054 end 00055 if isOctave() 00056 [n]=fscanf(fid,'%d %d %d',3); 00057 00058 R=fscanf(fid,'%f %f %d',[3,n(1)]); 00059 q=R([1 2],:); 00060 ql=R(3,:); 00061 R=fscanf(fid,'%d %d %d %d',[4,n(2)]); 00062 00063 me=R([1:3],:); 00064 mel=R(4,:); 00065 R=fscanf(fid,'%d %d %d',[3,n(3)]); 00066 00067 be=R([1 2],:); 00068 bel=R(3,:); 00069 else % Matlab 00070 n=textscan(fid,'%d %d %d',1); % n(1) -> number of vertices 00071 % n(2) -> number of triangles 00072 % n(3) -> number of boundary edges 00073 00074 R=textscan(fid,'%f %f %d',n{1}); 00075 q=[R{1},R{2}]'; 00076 ql=R{3}'; 00077 R=textscan(fid,'%d %d %d %d',n{2}); 00078 me=[R{1},R{2},R{3}]'; 00079 mel=R{4}'; 00080 00081 R=textscan(fid,'%d %d %d',n{3}); 00082 be=[R{1},R{2}]'; 00083 bel=R{3}'; 00084 end 00085 fclose(fid); 00086 00087 Mesh=struct('q',q,'me',double(me),'ql',ql,'mel',double(mel), ... 00088 'be',double(be),'bel',double(bel), ... 00089 'nq',size(q,2), ... 00090 'nme',size(me,2), ... 00091 'nbe',size(be,2), ... 00092 'areas',ComputeAreaOpt(q,me),... 00093 'lbe',EdgeLength(be,q)); 00094