12528
|
1 function nrbexport (varargin) |
9436
|
2 |
|
3 % |
|
4 % NRBEXPORT: export NURBS geometries to a format compatible with the one used in GeoPDEs (version 0.6). |
|
5 % |
|
6 % Calling Sequence: |
|
7 % |
|
8 % nrbexport (nurbs, filename); |
12528
|
9 % nrbexport (nurbs, interfaces, boundaries, filename); |
12578
|
10 % nrbexport (nurbs, interfaces, boundaries, subdomains, filename); |
9436
|
11 % |
|
12 % INPUT: |
|
13 % |
12528
|
14 % nurbs : NURBS curve, surface or volume, see nrbmak. |
|
15 % interfaces: interface information for GeoPDEs (see nrbmultipatch) |
|
16 % boundaries: boundary information for GeoPDEs (see nrbmultipatch) |
|
17 % filename : name of the output file. |
9436
|
18 % |
|
19 % |
|
20 % Description: |
|
21 % |
|
22 % The data of the nurbs structure is written in the file, in a format |
|
23 % that can be read by GeoPDEs. |
|
24 % |
12578
|
25 % Copyright (C) 2011, 2014, 2015 Rafael Vazquez |
9436
|
26 % |
|
27 % This program is free software: you can redistribute it and/or modify |
|
28 % it under the terms of the GNU General Public License as published by |
11634
|
29 % the Free Software Foundation, either version 3 of the License, or |
9436
|
30 % (at your option) any later version. |
|
31 |
|
32 % This program is distributed in the hope that it will be useful, |
|
33 % but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
34 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
35 % GNU General Public License for more details. |
|
36 % |
|
37 % You should have received a copy of the GNU General Public License |
|
38 % along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
39 |
12528
|
40 if (nargin == 2) |
|
41 nurbs = varargin{1}; |
|
42 filename = varargin{2}; |
|
43 if (numel (nurbs) > 1) |
|
44 warning ('Automatically creating the interface information with nrbmultipatch') |
|
45 [interfaces, boundaries] = nrbmultipatch (nurbs); |
12602
|
46 subdomains = []; |
12528
|
47 else |
12578
|
48 interfaces = []; boundaries = []; subdomains = []; |
12528
|
49 end |
|
50 elseif (nargin == 4) |
|
51 nurbs = varargin{1}; |
|
52 interfaces = varargin{2}; |
|
53 boundaries = varargin{3}; |
|
54 filename = varargin{4}; |
12578
|
55 subdomains = []; |
|
56 elseif (nargin == 5) |
|
57 nurbs = varargin{1}; |
|
58 interfaces = varargin{2}; |
|
59 boundaries = varargin{3}; |
|
60 subdomains = varargin{4}; |
|
61 filename = varargin{5}; |
12528
|
62 else |
|
63 error ('nrbexport: wrong number of input arguments') |
|
64 end |
|
65 |
9436
|
66 fid = fopen (filename, 'w'); |
|
67 if (fid < 0) |
|
68 error ('nrbexport: cannot open file %s', filename); |
|
69 end |
|
70 |
|
71 ndim = numel (nurbs(1).order); |
|
72 npatch = numel (nurbs); |
12576
|
73 rdim = 1; |
|
74 for iptc = 1:npatch |
|
75 if (any (abs(nurbs(iptc).coefs(3,:)) > 1e-12)) |
|
76 rdim = 3; |
|
77 break |
|
78 elseif (any (abs(nurbs(iptc).coefs(2,:)) > 1e-12)) |
|
79 rdim = 2; |
|
80 end |
|
81 end |
|
82 |
|
83 fprintf (fid, '%s\n', '# nurbs mesh v.1.0'); |
9436
|
84 fprintf (fid, '%s\n', '#'); |
|
85 fprintf (fid, '%s\n', ['# ' date]); |
|
86 fprintf (fid, '%s\n', '#'); |
|
87 |
12578
|
88 fprintf (fid, '%2i', ndim, rdim, npatch, numel(interfaces), numel(subdomains)); |
9436
|
89 fprintf (fid, '\n'); |
|
90 for iptc = 1:npatch |
12528
|
91 fprintf (fid, '%s %i \n', 'PATCH', iptc); |
10777
|
92 fprintf (fid, '%4i', nurbs(iptc).order-1); |
9436
|
93 fprintf (fid, '\n'); |
10777
|
94 fprintf (fid, '%4i', nurbs(iptc).number); |
9436
|
95 fprintf (fid, '\n'); |
|
96 for ii = 1:ndim |
|
97 fprintf (fid, '%1.7f ', nurbs(iptc).knots{ii}); |
|
98 fprintf (fid, '\n'); |
|
99 end |
|
100 |
12576
|
101 for ii = 1:rdim |
|
102 fprintf (fid, '%1.15f ', nurbs(iptc).coefs(ii,:,:)); |
9436
|
103 fprintf (fid, '\n'); |
|
104 end |
12576
|
105 fprintf (fid, '%1.15f ', nurbs(iptc).coefs(4,:,:)); |
|
106 fprintf (fid, '\n'); |
9436
|
107 end |
|
108 |
12528
|
109 for intrfc = 1:numel(interfaces) |
|
110 if (isfield (interfaces, 'ref')) |
|
111 fprintf (fid, '%s \n', interfaces(intrfc).ref); |
|
112 else |
|
113 fprintf (fid, '%s %i \n', 'INTERFACE', intrfc); |
|
114 end |
|
115 fprintf (fid, '%i %i \n', interfaces(intrfc).patch1, interfaces(intrfc).side1); |
|
116 fprintf (fid, '%i %i \n', interfaces(intrfc).patch2, interfaces(intrfc).side2); |
|
117 if (ndim == 2) |
|
118 fprintf (fid, '%i \n', interfaces(intrfc).ornt); |
|
119 elseif (ndim == 3) |
|
120 fprintf (fid, '%i %i %i \n', interfaces(intrfc).flag, interfaces(intrfc).ornt1, interfaces(intrfc).ornt2); |
|
121 end |
|
122 end |
|
123 |
12578
|
124 for isubd = 1:numel(subdomains) |
12528
|
125 % The subdomain part should be fixed |
12578
|
126 fprintf (fid, '%s \n', subdomains(isubd).name); |
|
127 fprintf (fid, '%i ', subdomains(isubd).patches); |
|
128 fprintf (fid, '\n'); |
|
129 end |
12528
|
130 |
|
131 |
|
132 for ibnd = 1:numel (boundaries) |
|
133 if (isfield (boundaries, 'name')) |
|
134 fprintf (fid, '%s \n', boundaries(ibnd).name); |
|
135 else |
|
136 fprintf (fid, '%s %i \n', 'BOUNDARY', ibnd); |
|
137 end |
|
138 fprintf (fid, '%i \n', boundaries(ibnd).nsides); |
|
139 for ii = 1:boundaries(ibnd).nsides |
|
140 fprintf (fid, '%i %i \n', boundaries(ibnd).patches(ii), boundaries(ibnd).faces(ii)); |
|
141 end |
|
142 end |
|
143 |
9436
|
144 fclose (fid); |
|
145 end |