40{
41 vtkUnstructuredGrid *input= vtkUnstructuredGrid::SafeDownCast(this->GetInput());
42
43 if (!this->GetFileName())
44 {
45 vtkErrorMacro(<<"FileName not set.");
46 return;
47 }
48
49 FILE* FDNEUTFile = fopen(this->GetFileName(),"w");
50
51 if (!FDNEUTFile)
52 {
53 vtkErrorMacro(<<"Could not open file for writing.");
54 return;
55 }
56
57 int numberOfNodes, numberOfElements, numberOfGroups;
58
59 numberOfNodes = input->GetNumberOfPoints();
60 numberOfElements = input->GetNumberOfCells();
61
62 int cellType;
63 const int numberOfCellTypes = VTK_QUADRATIC_PYRAMID+1;
64 int numberOfTypeCells[numberOfCellTypes];
65 int firstCellIdOfType[numberOfCellTypes];
66 int k;
67 for (k=0; k<numberOfCellTypes; k++)
68 {
69 numberOfTypeCells[k] = 0;
70 firstCellIdOfType[k] = -1;
71 }
72 for (k=0; k<numberOfElements; k++)
73 {
74 cellType = input->GetCellType(k);
75 switch (cellType)
76 {
77 case VTK_QUAD:
78 case VTK_QUADRATIC_QUAD:
79 case VTK_BIQUADRATIC_QUAD:
80 case VTK_TRIANGLE:
81 case VTK_QUADRATIC_TRIANGLE:
82 case VTK_HEXAHEDRON:
83 case VTK_QUADRATIC_HEXAHEDRON:
84 case VTK_TRIQUADRATIC_HEXAHEDRON:
85 case VTK_WEDGE:
86 case VTK_QUADRATIC_WEDGE:
87 case VTK_TETRA:
88 case VTK_QUADRATIC_TETRA:
89 ++numberOfTypeCells[cellType];
90 firstCellIdOfType[cellType] = k;
91 break;
92 default:
93 vtkWarningMacro(<<"Unsupported cell type found");
94 break;
95 }
96 }
97 numberOfGroups = 0;
98 for (k=0; k<numberOfCellTypes; k++)
99 {
100 if (numberOfTypeCells[k] > 0)
101 {
102 ++numberOfGroups;
103 }
104 }
105
106 fprintf(FDNEUTFile,"** FIDAP NEUTRAL FILE\n");
107 fprintf(FDNEUTFile,"foo\n");
108 fprintf(FDNEUTFile,"VERSION 8.6\n");
109 fprintf(FDNEUTFile," Jan 2004 \n");
110 fprintf(FDNEUTFile," NO. OF NODES NO. ELEMENTS NO. ELT GROUPS NDFCD NDFVL\n");
111 fprintf(FDNEUTFile,"%15d%15d%15d%15d%15d\n",numberOfNodes,numberOfElements,numberOfGroups,3,3);
112 fprintf(FDNEUTFile," STEADY/TRANS TURB. FLAG FREE SURF FLAG COMPR. FLAG RESULTS ONLY\n");
113 fprintf(FDNEUTFile," 0 0 0 0 0\n");
114 fprintf(FDNEUTFile,"TEMPERATURE/SPECIES FLAGS\n");
115 fprintf(FDNEUTFile," 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n");
116 fprintf(FDNEUTFile,"PRESSURE FLAGS - IDCTS, IPENY MPDF\n");
117 fprintf(FDNEUTFile," 1 1 0\n");
118
119 fprintf(FDNEUTFile,"NODAL COORDINATES\n");
120 double point[3];
121 for (k=0; k<numberOfNodes; k++)
122 {
123 input->GetPoint(k,point);
124 fprintf(FDNEUTFile,"%10d%20.10e%20.10e%20.10e\n",k+1,point[0],point[1],point[2]);
125 }
126
127 fprintf(FDNEUTFile,"BOUNDARY CONDITIONS\n");
128 fprintf(FDNEUTFile," 0 0 0 0.0\n");
129
130 fprintf(FDNEUTFile,"ELEMENT GROUPS\n");
131
132 int cellCount = 1;
133 int groupCount = 1;
134
135
136 for (cellType=numberOfCellTypes-1; cellType>=0; cellType--)
137 {
138 if (numberOfTypeCells[cellType] == 0)
139 {
140 continue;
141 }
142
143 int fdneutElementType, fdneutElementGeometry, numberOfNodesInElement;
144 vtkIdType npts, *cellPoints;
145 const vtkIdType *pts;
146 fdneutElementType = -1;
147 fdneutElementGeometry = -1;
148
149 input->GetCellPoints(firstCellIdOfType[cellType],npts,pts);
150 numberOfNodesInElement = npts;
151 switch (cellType)
152 {
153 case VTK_QUAD:
154 case VTK_QUADRATIC_QUAD:
155 fdneutElementType = 15;
157 break;
158 case VTK_BIQUADRATIC_QUAD:
159 fdneutElementType = 15;
161 break;
162 case VTK_TRIANGLE:
163 case VTK_QUADRATIC_TRIANGLE:
164 fdneutElementType = 15;
166 break;
167 case VTK_HEXAHEDRON:
168 case VTK_QUADRATIC_HEXAHEDRON:
169 fdneutElementType =
BRICK;
170 fdneutElementGeometry =
BRICK;
171 break;
172 case VTK_TRIQUADRATIC_HEXAHEDRON:
173 fdneutElementType =
BRICK;
174 fdneutElementGeometry =
BRICK;
175 break;
176 case VTK_WEDGE:
177 case VTK_QUADRATIC_WEDGE:
178 fdneutElementType =
WEDGE;
179 fdneutElementGeometry =
WEDGE;
180 break;
181 case VTK_TETRA:
182 case VTK_QUADRATIC_TETRA:
185 break;
186 }
187
188 int groupNumber, numberOfElementsInGroup;
189 groupNumber = groupCount;
190 numberOfElementsInGroup = numberOfTypeCells[cellType];
191
192 fprintf(FDNEUTFile,"GROUP: %5d ELEMENTS:%10d NODES: %10d GEOMETRY:%5d TYPE:%4d\n",groupNumber,numberOfElementsInGroup,numberOfNodesInElement,fdneutElementGeometry,fdneutElementType);
193 fprintf(FDNEUTFile,"ENTITY NAME: Entity%d\n",groupNumber);
194
195 for (k=0; k<numberOfElements; k++)
196 {
197 if (input->GetCellType(k) != cellType)
198 {
199 continue;
200 }
201 input->GetCellPoints(k,npts,pts);
202 cellPoints = new vtkIdType[npts];
203 memcpy(cellPoints,pts,npts*sizeof(vtkIdType));
205
206 if (npts != numberOfNodesInElement)
207 {
208 vtkErrorMacro(<<"Can't handle same cell types with different number of points");
209 return;
210 }
211
212 fprintf(FDNEUTFile,"%8d",(int)cellCount);
213
214 int i;
215 switch (cellType)
216 {
217 case VTK_QUAD:
218 for (i=0; i<numberOfNodesInElement; i++)
219 {
220 fprintf(FDNEUTFile,"%8d",(int)cellPoints[i]);
221 }
222 break;
223 case VTK_QUADRATIC_QUAD:
224 fprintf(FDNEUTFile,"%8d",(int)cellPoints[0]);
225 fprintf(FDNEUTFile,"%8d",(int)cellPoints[4]);
226 fprintf(FDNEUTFile,"%8d",(int)cellPoints[1]);
227 fprintf(FDNEUTFile,"%8d",(int)cellPoints[5]);
228 fprintf(FDNEUTFile,"%8d",(int)cellPoints[2]);
229 fprintf(FDNEUTFile,"%8d",(int)cellPoints[6]);
230 fprintf(FDNEUTFile,"%8d",(int)cellPoints[3]);
231 fprintf(FDNEUTFile,"%8d",(int)cellPoints[7]);
232 if (numberOfNodesInElement==9)
233 {
234 fprintf(FDNEUTFile,"%8d",(int)cellPoints[8]);
235 }
236 break;
237 case VTK_BIQUADRATIC_QUAD:
238 fprintf(FDNEUTFile,"%8d",(int)cellPoints[0]);
239 fprintf(FDNEUTFile,"%8d",(int)cellPoints[4]);
240 fprintf(FDNEUTFile,"%8d",(int)cellPoints[1]);
241 fprintf(FDNEUTFile,"%8d",(int)cellPoints[5]);
242 fprintf(FDNEUTFile,"%8d",(int)cellPoints[2]);
243 fprintf(FDNEUTFile,"%8d",(int)cellPoints[6]);
244 fprintf(FDNEUTFile,"%8d",(int)cellPoints[3]);
245 fprintf(FDNEUTFile,"%8d",(int)cellPoints[7]);
246 fprintf(FDNEUTFile,"%8d",(int)cellPoints[8]);
247 break;
248 case VTK_TRIANGLE:
249 for (i=0; i<numberOfNodesInElement; i++)
250 {
251 fprintf(FDNEUTFile,"%8d",(int)cellPoints[i]);
252 }
253 break;
254 case VTK_QUADRATIC_TRIANGLE:
255 fprintf(FDNEUTFile,"%8d",(int)cellPoints[0]);
256 fprintf(FDNEUTFile,"%8d",(int)cellPoints[3]);
257 fprintf(FDNEUTFile,"%8d",(int)cellPoints[1]);
258 fprintf(FDNEUTFile,"%8d",(int)cellPoints[4]);
259 fprintf(FDNEUTFile,"%8d",(int)cellPoints[2]);
260 fprintf(FDNEUTFile,"%8d",(int)cellPoints[5]);
261 break;
262 case VTK_HEXAHEDRON:
263 fprintf(FDNEUTFile,"%8d",(int)cellPoints[0]);
264 fprintf(FDNEUTFile,"%8d",(int)cellPoints[1]);
265 fprintf(FDNEUTFile,"%8d",(int)cellPoints[3]);
266 fprintf(FDNEUTFile,"%8d",(int)cellPoints[2]);
267 fprintf(FDNEUTFile,"%8d",(int)cellPoints[4]);
268 fprintf(FDNEUTFile,"%8d",(int)cellPoints[5]);
269 fprintf(FDNEUTFile,"%8d",(int)cellPoints[7]);
270 fprintf(FDNEUTFile,"%8d",(int)cellPoints[6]);
271 break;
272 case VTK_TRIQUADRATIC_HEXAHEDRON:
273 if (numberOfNodesInElement != 27)
274 {
275 vtkErrorMacro(<< "Only 27-noded hexahedra are supported in FDNEUT.");
276 }
277 fprintf(FDNEUTFile,"%8d",(int)cellPoints[0]);
278 fprintf(FDNEUTFile,"%8d",(int)cellPoints[8]);
279 fprintf(FDNEUTFile,"%8d",(int)cellPoints[1]);
280
281 fprintf(FDNEUTFile,"%8d",(int)cellPoints[11]);
282 fprintf(FDNEUTFile,"%8d",(int)cellPoints[24]);
283 fprintf(FDNEUTFile,"%8d",(int)cellPoints[9]);
284
285 fprintf(FDNEUTFile,"%8d",(int)cellPoints[3]);
286 fprintf(FDNEUTFile,"%8d",(int)cellPoints[10]);
287 fprintf(FDNEUTFile,"%8d",(int)cellPoints[2]);
288
289 fprintf(FDNEUTFile,"\n");
290
291 fprintf(FDNEUTFile,"%8d",(int)cellPoints[16]);
292 fprintf(FDNEUTFile,"%8d",(int)cellPoints[20]);
293 fprintf(FDNEUTFile,"%8d",(int)cellPoints[17]);
294
295 fprintf(FDNEUTFile,"%8d",(int)cellPoints[23]);
296 fprintf(FDNEUTFile,"%8d",(int)cellPoints[26]);
297 fprintf(FDNEUTFile,"%8d",(int)cellPoints[21]);
298
299 fprintf(FDNEUTFile,"%8d",(int)cellPoints[19]);
300 fprintf(FDNEUTFile,"%8d",(int)cellPoints[22]);
301 fprintf(FDNEUTFile,"%8d",(int)cellPoints[18]);
302
303 fprintf(FDNEUTFile,"\n");
304
305 fprintf(FDNEUTFile,"%8d",(int)cellPoints[4]);
306 fprintf(FDNEUTFile,"%8d",(int)cellPoints[12]);
307 fprintf(FDNEUTFile,"%8d",(int)cellPoints[5]);
308
309 fprintf(FDNEUTFile,"%8d",(int)cellPoints[15]);
310 fprintf(FDNEUTFile,"%8d",(int)cellPoints[25]);
311 fprintf(FDNEUTFile,"%8d",(int)cellPoints[13]);
312
313 fprintf(FDNEUTFile,"%8d",(int)cellPoints[7]);
314 fprintf(FDNEUTFile,"%8d",(int)cellPoints[14]);
315 fprintf(FDNEUTFile,"%8d",(int)cellPoints[6]);
316
317 break;
318 case VTK_TETRA:
319 for (i=0; i<numberOfNodesInElement; i++)
320 {
321 fprintf(FDNEUTFile,"%8d",(int)cellPoints[i]);
322 }
323 break;
324 case VTK_QUADRATIC_TETRA:
325 fprintf(FDNEUTFile,"%8d",(int)cellPoints[0]);
326 fprintf(FDNEUTFile,"%8d",(int)cellPoints[4]);
327 fprintf(FDNEUTFile,"%8d",(int)cellPoints[1]);
328 fprintf(FDNEUTFile,"%8d",(int)cellPoints[6]);
329 fprintf(FDNEUTFile,"%8d",(int)cellPoints[5]);
330 fprintf(FDNEUTFile,"%8d",(int)cellPoints[2]);
331 fprintf(FDNEUTFile,"%8d",(int)cellPoints[7]);
332 fprintf(FDNEUTFile,"\n");
333 fprintf(FDNEUTFile,"%8d",(int)cellPoints[8]);
334 fprintf(FDNEUTFile,"%8d",(int)cellPoints[9]);
335 fprintf(FDNEUTFile,"%8d",(int)cellPoints[3]);
336 break;
338 for (i=0; i<numberOfNodesInElement; i++)
339 {
340 fprintf(FDNEUTFile,"%8d",(int)cellPoints[i]);
341 }
342 break;
343 case VTK_QUADRATIC_WEDGE:
344 if (numberOfNodesInElement==18)
345 {
346 fprintf(FDNEUTFile,"%8d",(int)cellPoints[0]);
347 fprintf(FDNEUTFile,"%8d",(int)cellPoints[6]);
348 fprintf(FDNEUTFile,"%8d",(int)cellPoints[1]);
349
350 fprintf(FDNEUTFile,"%8d",(int)cellPoints[8]);
351 fprintf(FDNEUTFile,"%8d",(int)cellPoints[7]);
352 fprintf(FDNEUTFile,"%8d",(int)cellPoints[2]);
353
354 fprintf(FDNEUTFile,"%8d",(int)cellPoints[12]);
355 fprintf(FDNEUTFile,"%8d",(int)cellPoints[15]);
356 fprintf(FDNEUTFile,"%8d",(int)cellPoints[13]);
357
358 fprintf(FDNEUTFile,"\n");
359
360 fprintf(FDNEUTFile,"%8d",(int)cellPoints[17]);
361 fprintf(FDNEUTFile,"%8d",(int)cellPoints[16]);
362 fprintf(FDNEUTFile,"%8d",(int)cellPoints[14]);
363
364 fprintf(FDNEUTFile,"%8d",(int)cellPoints[3]);
365 fprintf(FDNEUTFile,"%8d",(int)cellPoints[9]);
366 fprintf(FDNEUTFile,"%8d",(int)cellPoints[4]);
367
368 fprintf(FDNEUTFile,"%8d",(int)cellPoints[11]);
369 fprintf(FDNEUTFile,"%8d",(int)cellPoints[10]);
370 fprintf(FDNEUTFile,"%8d",(int)cellPoints[5]);
371 }
372 else if (numberOfNodesInElement==15)
373 {
374 fprintf(FDNEUTFile,"%8d",(int)cellPoints[0]);
375 fprintf(FDNEUTFile,"%8d",(int)cellPoints[6]);
376 fprintf(FDNEUTFile,"%8d",(int)cellPoints[1]);
377
378 fprintf(FDNEUTFile,"%8d",(int)cellPoints[8]);
379 fprintf(FDNEUTFile,"%8d",(int)cellPoints[7]);
380 fprintf(FDNEUTFile,"%8d",(int)cellPoints[2]);
381
382 fprintf(FDNEUTFile,"%8d",(int)cellPoints[12]);
383 fprintf(FDNEUTFile,"%8d",(int)cellPoints[13]);
384 fprintf(FDNEUTFile,"%8d",(int)cellPoints[14]);
385
386 fprintf(FDNEUTFile,"\n");
387
388 fprintf(FDNEUTFile,"%8d",(int)cellPoints[3]);
389 fprintf(FDNEUTFile,"%8d",(int)cellPoints[9]);
390 fprintf(FDNEUTFile,"%8d",(int)cellPoints[4]);
391
392 fprintf(FDNEUTFile,"%8d",(int)cellPoints[11]);
393 fprintf(FDNEUTFile,"%8d",(int)cellPoints[10]);
394 fprintf(FDNEUTFile,"%8d",(int)cellPoints[5]);
395 }
396 break;
397 }
398 fprintf(FDNEUTFile,"\n");
399 cellCount++;
400 delete[] cellPoints;
401 }
402 ++groupCount;
403 }
404
405 fclose(FDNEUTFile);
406}
static void ZeroToOneOffset(vtkIdType npts, vtkIdType *pts)