10635
|
1 ## Copyright (C) 2004-2008,2009 Carlo de Falco, Massimiliano Culpo |
|
2 ## |
|
3 ## This file is part of |
|
4 ## |
|
5 ## FPL - Fem PLotting package for octave |
|
6 ## |
|
7 ## FPL is free software; you can redistribute it and/or modify |
|
8 ## it under the terms of the GNU General Public License as published by |
10655
|
9 ## the Free Software Foundation; either version 3 of the License, or |
10635
|
10 ## (at your option) any later version. |
|
11 ## |
|
12 ## FPL is distributed in the hope that it will be useful, |
|
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 ## GNU General Public License for more details. |
|
16 ## |
|
17 ## You should have received a copy of the GNU General Public License |
|
18 ## along with FPL; If not, see <http://www.gnu.org/licenses/>. |
|
19 ## |
|
20 ## |
|
21 ## AUTHORS: |
|
22 ## Carlo de Falco <cdf _AT_ users.sourceforge.net> |
|
23 ## |
|
24 ## Culpo Massimiliano |
|
25 ## Bergische Universitaet Wuppertal |
|
26 ## Fachbereich C - Mathematik und Naturwissenschaften |
|
27 ## Arbeitsgruppe fuer Angewandte MathematD-42119 Wuppertal Gaussstr. 20 |
|
28 ## D-42119 Wuppertal, Germany |
|
29 |
|
30 ## -*- texinfo -*- |
|
31 ## @deftypefn {Function File} {} FPL3dxoutputmesh ( @var{filename}, @ |
|
32 ## @var{mesh} ) |
|
33 ## |
|
34 ## Outputs data in DX form. |
|
35 ## |
|
36 ## Variable must be a scalar, vector or tensor of doubles |
|
37 ## |
|
38 ## @itemize @minus |
|
39 ## @item @var{filename} = name of file to save (type string) |
|
40 ## @item @var{mesh} = PDE-tool like mesh |
|
41 ## @end itemize |
|
42 ## @end deftypefn |
|
43 |
|
44 |
|
45 function FPL3dxoutputmesh(filename,mesh) |
|
46 |
|
47 nodes = mesh.p'; |
|
48 elem = mesh.t(1:4,:)'; |
|
49 |
|
50 fid = fopen (filename,"w"); |
|
51 nnodes = columns(mesh.p); |
|
52 nelem = columns(mesh.t); |
|
53 |
|
54 fprintf(fid,"object ""pos""\nclass array type float rank 1 shape 3 items %d data follows",nnodes); |
|
55 for ii = 1:nnodes |
|
56 fprintf(fid,"\n"); |
|
57 fprintf(fid," %e",nodes(ii,:)); |
|
58 endfor |
|
59 |
|
60 ## In DX format nodes are numbered starting from zero, |
|
61 ## instead we want to number them starting from 1. |
|
62 if (min(min(elem))==1) |
|
63 elem = elem - 1; |
|
64 elseif(min(min(elem))~=0) |
|
65 error("WARNING: check tetrahedra structure"); |
|
66 end |
|
67 |
|
68 fprintf(fid,"\n\nobject ""con""\nclass array type int rank 1 shape 4 items %d data follows",nelem); |
|
69 for ii = 1:nelem |
|
70 fprintf(fid,"\n"); |
|
71 fprintf(fid," %d",elem(ii,:)); |
|
72 endfor |
|
73 |
|
74 fprintf(fid,"\nattribute ""element type"" string ""tetrahedra""\nattribute ""ref"" string ""positions""\n\n"); |
|
75 |
|
76 fprintf(fid,"object ""themesh"" class field\n"); |
|
77 fprintf(fid,"component ""positions"" value ""pos""\n"); |
|
78 fprintf(fid,"component ""connections"" value ""con""\n"); |
|
79 |
|
80 fprintf(fid,"\nend\n"); |
|
81 fclose (fid); |
|
82 |
|
83 endfunction |
|
84 |
|
85 %!test |
|
86 %! msh.p =[ 0 0 1 1 0 0 1 1 |
|
87 %! 0 1 0 1 0 1 0 1 |
|
88 %! 0 0 0 0 1 1 1 1]; |
|
89 %! msh.e =[1 5 7 8 5 5 6 8 1 3 5 7 |
|
90 %! 2 6 3 3 7 3 2 6 3 2 6 6 |
|
91 %! 6 1 8 4 3 1 4 4 2 4 7 8 |
|
92 %! 0 0 0 0 0 0 0 0 0 0 0 0 |
|
93 %! 0 0 0 0 0 0 0 0 0 0 0 0 |
|
94 %! 0 0 0 0 0 0 0 0 0 0 0 0 |
|
95 %! 0 0 0 0 0 0 0 0 0 0 0 0 |
|
96 %! 0 0 0 0 0 0 0 0 0 0 0 0 |
|
97 %! 1 1 1 1 1 1 1 1 1 1 1 1 |
|
98 %! 1 1 2 2 3 3 4 4 5 5 6 6]; |
|
99 %! msh.t =[ 1 5 5 6 7 8 |
|
100 %! 3 6 6 3 3 3 |
|
101 %! 2 7 3 2 6 6 |
|
102 %! 6 3 1 4 8 4 |
|
103 %! 1 1 1 1 1 1]; |
|
104 %! testfile = "object ""pos""\nclass array type float rank 1 shape 3 items 8 data follows\n 0.000000e+00 0.000000e+00 0.000000e+00\n 0.000000e+00 1.000000e+00 0.000000e+00\n 1.000000e+00 0.000000e+00 0.000000e+00\n 1.000000e+00 1.000000e+00 0.000000e+00\n 0.000000e+00 0.000000e+00 1.000000e+00\n 0.000000e+00 1.000000e+00 1.000000e+00\n 1.000000e+00 0.000000e+00 1.000000e+00\n 1.000000e+00 1.000000e+00 1.000000e+00\n\nobject ""con""\nclass array type int rank 1 shape 4 items 6 data follows\n 0 2 1 5\n 4 5 6 2\n 4 5 2 0\n 5 2 1 3\n 6 2 5 7\n 7 2 5 3\nattribute ""element type"" string ""tetrahedra""\nattribute ""ref"" string ""positions""\n\nobject ""themesh"" class field\ncomponent ""positions"" value ""pos""\ncomponent ""connections"" value ""con""\n\nend\n"; |
|
105 %! FPL3dxoutputmesh ("__FPL3dxoutputmesh__test__.dx",msh); |
|
106 %! fid = fopen("__FPL3dxoutputmesh__test__.dx","r"); |
|
107 %! s = fread(fid); |
|
108 %! fclose(fid); |
|
109 %! assert (char(s'), testfile); |
|
110 %! delete __FPL3dxoutputmesh__test__.dx |