54 vtkUnstructuredGrid *input= vtkUnstructuredGrid::SafeDownCast(this->GetInput());
56 if (!this->GetFileName())
58 vtkErrorMacro(<<
"FileName not set.");
62 std::ofstream out (this->GetFileName());
66 vtkErrorMacro(<<
"Could not open file for writing.");
72 int numberOfPoints = input->GetNumberOfPoints();
73 int numberOfCells = input->GetNumberOfCells();
75 vtkDataArray* boundaryDataArray = NULL;
79 if (!boundaryDataArray)
81 vtkErrorMacro(<<
"BoundaryDataArray with name specified does not exist");
94 quadraticHexahedronType,
100 const int numberOfVolumeCellTypes = 9;
115 int elementTypeLibmeshMap[numberOfVolumeCellTypes];
116 elementTypeLibmeshMap[tetraType] = tet4LibmeshType;
117 elementTypeLibmeshMap[hexahedronType] = hex8LibmeshType;
118 elementTypeLibmeshMap[wedgeType] = prism6LibmeshType;
119 elementTypeLibmeshMap[pyramidType] = pyramid5LibmeshType;
120 elementTypeLibmeshMap[quadraticTetraType] = tet10LibmeshType;
121 elementTypeLibmeshMap[quadraticHexahedronType] = hex20LibmeshType;
122 elementTypeLibmeshMap[quadraticWedgeType] = prism15LibmeshType;
123 elementTypeLibmeshMap[biquadraticWedgeType] = prism18LibmeshType;
124 elementTypeLibmeshMap[quadraticPyramidType] = -1;
126 int numberOfElementsInBlock[numberOfVolumeCellTypes];
128 for (i=0; i<numberOfVolumeCellTypes; i++)
130 numberOfElementsInBlock[i] = 0;
133 int blockVtkCellTypes[numberOfVolumeCellTypes];
134 blockVtkCellTypes[tetraType] = VTK_TETRA;
135 blockVtkCellTypes[hexahedronType] = VTK_HEXAHEDRON;
136 blockVtkCellTypes[wedgeType] = VTK_WEDGE;
137 blockVtkCellTypes[pyramidType] = VTK_PYRAMID;
138 blockVtkCellTypes[quadraticTetraType] = VTK_QUADRATIC_TETRA;
139 blockVtkCellTypes[quadraticHexahedronType] = VTK_QUADRATIC_HEXAHEDRON;
140 blockVtkCellTypes[quadraticWedgeType] = VTK_QUADRATIC_WEDGE;
141 blockVtkCellTypes[biquadraticWedgeType] = VTK_BIQUADRATIC_QUADRATIC_WEDGE;
142 blockVtkCellTypes[quadraticPyramidType] = VTK_QUADRATIC_PYRAMID;
144 int numberOfVolumeCells = 0;
146 for (i=0; i<numberOfCells; i++)
148 int cellType = input->GetCellType(i);
152 ++numberOfElementsInBlock[tetraType];
155 ++numberOfElementsInBlock[hexahedronType];
158 ++numberOfElementsInBlock[wedgeType];
161 ++numberOfElementsInBlock[pyramidType];
163 case VTK_QUADRATIC_TETRA:
164 ++numberOfElementsInBlock[quadraticTetraType];
166 case VTK_QUADRATIC_HEXAHEDRON:
167 ++numberOfElementsInBlock[quadraticHexahedronType];
169 case VTK_QUADRATIC_WEDGE:
170 ++numberOfElementsInBlock[quadraticWedgeType];
172 case VTK_BIQUADRATIC_QUADRATIC_WEDGE:
173 ++numberOfElementsInBlock[biquadraticWedgeType];
175 case VTK_QUADRATIC_PYRAMID:
176 vtkWarningMacro(<<
"Quadratic pyramid not currently supported in libmesh. Skipping element.");
182 ++numberOfVolumeCells;
183 totalWeight += input->GetCell(i)->GetNumberOfPoints();
186 int numberOfElementBlocks = 0;
188 for (i=0; i<numberOfVolumeCellTypes; i++)
190 if (numberOfElementsInBlock[i] > 0)
192 ++numberOfElementBlocks;
196 int numberOfBoundaryConditions = 0;
197 if (boundaryDataArray)
199 for (i=0; i<numberOfCells; i++)
201 int cellType = input->GetCellType(i);
206 case VTK_QUADRATIC_TRIANGLE:
207 case VTK_QUADRATIC_QUAD:
208 numberOfBoundaryConditions++;
216 out <<
"DEAL 003:003" << endl;
218 out << numberOfVolumeCells <<
"\t# Num. Elements" << endl;
219 out << numberOfPoints <<
"\t# Num. Nodes" << endl;
220 out << totalWeight <<
"\t# Sum of Element Weights" << endl;
222 out << numberOfBoundaryConditions <<
"\t# Num. Boundary Conds." << endl;
224 int stringSize = 65536;
225 out << stringSize <<
"\t# String Size (ignore)" << endl;
228 out << numberOfElementBlocks <<
"\t# Num. Element Types." << endl;
230 for (i=0; i<numberOfVolumeCellTypes; i++)
232 if (numberOfElementsInBlock[i] > 0)
234 out << elementTypeLibmeshMap[i] <<
" ";
237 out <<
"\t# Element types in each block." << endl;
239 for (i=0; i<numberOfVolumeCellTypes; i++)
241 if (numberOfElementsInBlock[i] > 0)
243 out << numberOfElementsInBlock[i] <<
" ";
246 out <<
"\t# Num. of elements in each block at each refinement level." << endl;
248 out <<
"Id String" << endl;
249 out <<
"Title String" << endl;
251 vtkIdList* volumeCellIdMap = vtkIdList::New();
252 volumeCellIdMap->SetNumberOfIds(numberOfCells);
253 int volumeCellCounter = 0;
254 for (i=0; i<numberOfVolumeCellTypes; i++)
256 if (numberOfElementsInBlock[i] == 0)
261 vtkIdTypeArray* typeCellIds = vtkIdTypeArray::New();
262 input->GetIdsOfCellsOfType(blockVtkCellTypes[i], typeCellIds);
264 vtkIdList* libmeshConnectivity = vtkIdList::New();
267 int numberOfTypeCells = typeCellIds->GetNumberOfTuples();
270 for (j=0; j<numberOfTypeCells; j++)
272 vtkIdType
id = typeCellIds->GetValue(j);
273 vtkIdList* cellPoints = vtkIdList::New();
274 input->GetCellPoints(
id,cellPoints);
276 int numberOfCellPoints = libmeshConnectivity->GetNumberOfIds();
277 for (
int k=0; k<numberOfCellPoints; k++)
279 out << cellPoints->GetId(libmeshConnectivity->GetId(k)) <<
" ";
284 volumeCellIdMap->SetId(
id,volumeCellCounter);
286 cellPoints->Delete();
289 typeCellIds->Delete();
290 libmeshConnectivity->Delete();
294 for (i=0; i<numberOfPoints; i++)
296 input->GetPoint(i,point);
297 out << point[0] <<
" " << point[1] <<
" " << point[2] << endl;
300 if (boundaryDataArray)
302 for (i=0; i<numberOfCells; i++)
304 int faceCellType = input->GetCellType(i);
305 switch (faceCellType)
309 case VTK_QUADRATIC_TRIANGLE:
310 case VTK_QUADRATIC_QUAD:
316 vtkIdList* faceCellPoints = vtkIdList::New();
317 input->GetCellPoints(i,faceCellPoints);
319 vtkIdList* cellIds = vtkIdList::New();
320 input->GetCellNeighbors(i,faceCellPoints,cellIds);
322 if (cellIds->GetNumberOfIds() != 1)
324 vtkWarningMacro(
"Boundary cell not on boundary!");
327 vtkIdType cellId = cellIds->GetId(0);
329 vtkCell* cell = input->GetCell(cellId);
331 int cellType = cell->GetCellType();
333 int numberOfFaces = cell->GetNumberOfFaces();
335 vtkIdType faceId = -1;
338 for (j=0; j<numberOfFaces; j++)
340 vtkCell* face = cell->GetFace(j);
342 vtkIdList* matchingPointIds = vtkIdList::New();
343 matchingPointIds->DeepCopy(face->GetPointIds());
345 matchingPointIds->IntersectWith(faceCellPoints);
347 int numberOfNonMatching = face->GetNumberOfPoints() - matchingPointIds->GetNumberOfIds();
349 matchingPointIds->Delete();
351 if (numberOfNonMatching==0)
358 vtkIdList* libmeshFaceOrder = vtkIdList::New();
361 vtkIdType libmeshFaceId = libmeshFaceOrder->GetId(faceId);
363 libmeshFaceOrder->Delete();
365 short int boundaryValue =
static_cast<short int>(boundaryDataArray->GetComponent(i,0));
366 out << volumeCellIdMap->GetId(cellId) <<
" " << libmeshFaceId <<
" " << boundaryValue << endl;
368 faceCellPoints->Delete();
372 volumeCellIdMap->Delete();
377 libmeshConnectivity->Initialize();
382 libmeshConnectivity->SetNumberOfIds(4);
383 libmeshConnectivity->SetId(0,0);
384 libmeshConnectivity->SetId(1,1);
385 libmeshConnectivity->SetId(2,2);
386 libmeshConnectivity->SetId(3,3);
389 libmeshConnectivity->SetNumberOfIds(8);
390 libmeshConnectivity->SetId(0,0);
391 libmeshConnectivity->SetId(1,1);
392 libmeshConnectivity->SetId(2,2);
393 libmeshConnectivity->SetId(3,3);
394 libmeshConnectivity->SetId(4,4);
395 libmeshConnectivity->SetId(5,5);
396 libmeshConnectivity->SetId(6,6);
397 libmeshConnectivity->SetId(7,7);
400 libmeshConnectivity->SetNumberOfIds(6);
401 libmeshConnectivity->SetId(0,0);
402 libmeshConnectivity->SetId(1,2);
403 libmeshConnectivity->SetId(2,1);
404 libmeshConnectivity->SetId(3,3);
405 libmeshConnectivity->SetId(4,5);
406 libmeshConnectivity->SetId(5,4);
409 libmeshConnectivity->SetNumberOfIds(5);
410 libmeshConnectivity->SetId(0,0);
411 libmeshConnectivity->SetId(1,1);
412 libmeshConnectivity->SetId(2,2);
413 libmeshConnectivity->SetId(3,3);
414 libmeshConnectivity->SetId(4,4);
416 case VTK_QUADRATIC_TETRA:
417 libmeshConnectivity->SetNumberOfIds(10);
418 libmeshConnectivity->SetId(0,0);
419 libmeshConnectivity->SetId(1,1);
420 libmeshConnectivity->SetId(2,2);
421 libmeshConnectivity->SetId(3,3);
422 libmeshConnectivity->SetId(4,4);
423 libmeshConnectivity->SetId(5,5);
424 libmeshConnectivity->SetId(6,6);
425 libmeshConnectivity->SetId(7,7);
426 libmeshConnectivity->SetId(8,8);
427 libmeshConnectivity->SetId(9,9);
429 case VTK_QUADRATIC_HEXAHEDRON:
430 libmeshConnectivity->SetNumberOfIds(20);
431 libmeshConnectivity->SetId(0,0);
432 libmeshConnectivity->SetId(1,1);
433 libmeshConnectivity->SetId(2,2);
434 libmeshConnectivity->SetId(3,3);
435 libmeshConnectivity->SetId(4,4);
436 libmeshConnectivity->SetId(5,5);
437 libmeshConnectivity->SetId(6,6);
438 libmeshConnectivity->SetId(7,7);
439 libmeshConnectivity->SetId(8,8);
440 libmeshConnectivity->SetId(9,9);
441 libmeshConnectivity->SetId(10,10);
442 libmeshConnectivity->SetId(11,11);
443 libmeshConnectivity->SetId(12,16);
444 libmeshConnectivity->SetId(13,17);
445 libmeshConnectivity->SetId(14,18);
446 libmeshConnectivity->SetId(15,19);
447 libmeshConnectivity->SetId(16,12);
448 libmeshConnectivity->SetId(17,13);
449 libmeshConnectivity->SetId(18,14);
450 libmeshConnectivity->SetId(19,15);
452 case VTK_QUADRATIC_WEDGE:
453 libmeshConnectivity->SetNumberOfIds(15);
454 libmeshConnectivity->SetId(0,0);
455 libmeshConnectivity->SetId(1,2);
456 libmeshConnectivity->SetId(2,1);
457 libmeshConnectivity->SetId(3,3);
458 libmeshConnectivity->SetId(4,5);
459 libmeshConnectivity->SetId(5,4);
460 libmeshConnectivity->SetId(6,8);
461 libmeshConnectivity->SetId(7,7);
462 libmeshConnectivity->SetId(8,6);
463 libmeshConnectivity->SetId(9,12);
464 libmeshConnectivity->SetId(10,14);
465 libmeshConnectivity->SetId(11,13);
466 libmeshConnectivity->SetId(12,11);
467 libmeshConnectivity->SetId(13,10);
468 libmeshConnectivity->SetId(14,9);
470 case VTK_BIQUADRATIC_QUADRATIC_WEDGE:
471 libmeshConnectivity->SetNumberOfIds(18);
472 libmeshConnectivity->SetId(0,0);
473 libmeshConnectivity->SetId(1,2);
474 libmeshConnectivity->SetId(2,1);
475 libmeshConnectivity->SetId(3,3);
476 libmeshConnectivity->SetId(4,5);
477 libmeshConnectivity->SetId(5,4);
478 libmeshConnectivity->SetId(6,8);
479 libmeshConnectivity->SetId(7,7);
480 libmeshConnectivity->SetId(8,6);
481 libmeshConnectivity->SetId(9,12);
482 libmeshConnectivity->SetId(10,14);
483 libmeshConnectivity->SetId(11,13);
484 libmeshConnectivity->SetId(12,11);
485 libmeshConnectivity->SetId(13,10);
486 libmeshConnectivity->SetId(14,9);
487 libmeshConnectivity->SetId(15,17);
488 libmeshConnectivity->SetId(16,16);
489 libmeshConnectivity->SetId(17,15);
492 std::cerr<<
"Element type not currently supported in libmesh. Skipping element."<<std::endl;
499 libmeshFaceOrder->Initialize();
504 libmeshFaceOrder->SetNumberOfIds(4);
505 libmeshFaceOrder->SetId(0,1);
506 libmeshFaceOrder->SetId(1,2);
507 libmeshFaceOrder->SetId(2,3);
508 libmeshFaceOrder->SetId(3,0);
511 libmeshFaceOrder->SetNumberOfIds(6);
512 libmeshFaceOrder->SetId(0,4);
513 libmeshFaceOrder->SetId(1,2);
514 libmeshFaceOrder->SetId(2,1);
515 libmeshFaceOrder->SetId(3,3);
516 libmeshFaceOrder->SetId(4,0);
517 libmeshFaceOrder->SetId(5,5);
520 libmeshFaceOrder->SetNumberOfIds(5);
521 libmeshFaceOrder->SetId(0,0);
522 libmeshFaceOrder->SetId(1,4);
523 libmeshFaceOrder->SetId(2,3);
524 libmeshFaceOrder->SetId(3,2);
525 libmeshFaceOrder->SetId(4,1);
528 libmeshFaceOrder->SetNumberOfIds(5);
529 libmeshFaceOrder->SetId(0,4);
530 libmeshFaceOrder->SetId(1,0);
531 libmeshFaceOrder->SetId(2,1);
532 libmeshFaceOrder->SetId(3,2);
533 libmeshFaceOrder->SetId(4,3);
535 case VTK_QUADRATIC_TETRA:
536 libmeshFaceOrder->SetNumberOfIds(4);
537 libmeshFaceOrder->SetId(0,1);
538 libmeshFaceOrder->SetId(1,2);
539 libmeshFaceOrder->SetId(2,3);
540 libmeshFaceOrder->SetId(3,0);
542 case VTK_QUADRATIC_HEXAHEDRON:
543 libmeshFaceOrder->SetNumberOfIds(6);
544 libmeshFaceOrder->SetId(0,4);
545 libmeshFaceOrder->SetId(1,2);
546 libmeshFaceOrder->SetId(2,1);
547 libmeshFaceOrder->SetId(3,3);
548 libmeshFaceOrder->SetId(4,0);
549 libmeshFaceOrder->SetId(5,5);
551 case VTK_QUADRATIC_WEDGE:
552 case VTK_BIQUADRATIC_QUADRATIC_WEDGE:
553 libmeshFaceOrder->SetNumberOfIds(5);
554 libmeshFaceOrder->SetId(0,0);
555 libmeshFaceOrder->SetId(1,4);
556 libmeshFaceOrder->SetId(2,3);
557 libmeshFaceOrder->SetId(3,2);
558 libmeshFaceOrder->SetId(4,1);
561 std::cerr<<
"Element type not currently supported in libmesh. Skipping element."<<std::endl;