53{
54 vtkUnstructuredGrid *input= vtkUnstructuredGrid::SafeDownCast(this->GetInput());
55
56 if (!this->GetFileName())
57 {
58 vtkErrorMacro(<<"FileName not set.");
59 return;
60 }
61
62 std::ofstream out (this->GetFileName());
63
64 if (!out.good())
65 {
66 vtkErrorMacro(<<"Could not open file for writing.");
67 return;
68 }
69
70 input->BuildLinks();
71
72 int numberOfPoints = input->GetNumberOfPoints();
73 int numberOfCells = input->GetNumberOfCells();
74
75 vtkDataArray* boundaryDataArray = NULL;
77 {
79 if (!boundaryDataArray)
80 {
81 vtkErrorMacro(<<"BoundaryDataArray with name specified does not exist");
82 }
83 }
84
85 int totalWeight = 0;
86
87 enum
88 {
89 tetraType = 0,
90 hexahedronType,
91 wedgeType,
92 pyramidType,
93 quadraticTetraType,
94 quadraticHexahedronType,
95 quadraticWedgeType,
96 biquadraticWedgeType,
97 quadraticPyramidType
98 };
99
100 const int numberOfVolumeCellTypes = 9;
101
102 enum
103 {
104 tet4LibmeshType = 8,
105 tet10LibmeshType,
106 hex8LibmeshType,
107 hex20LibmeshType,
108 hex27LibmeshType,
109 prism6LibmeshType,
110 prism15LibmeshType,
111 prism18LibmeshType,
112 pyramid5LibmeshType
113 };
114
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;
125
126 int numberOfElementsInBlock[numberOfVolumeCellTypes];
127 int i;
128 for (i=0; i<numberOfVolumeCellTypes; i++)
129 {
130 numberOfElementsInBlock[i] = 0;
131 }
132
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;
143
144 int numberOfVolumeCells = 0;
145
146 for (i=0; i<numberOfCells; i++)
147 {
148 int cellType = input->GetCellType(i);
149 switch (cellType)
150 {
151 case VTK_TETRA:
152 ++numberOfElementsInBlock[tetraType];
153 break;
154 case VTK_HEXAHEDRON:
155 ++numberOfElementsInBlock[hexahedronType];
156 break;
157 case VTK_WEDGE:
158 ++numberOfElementsInBlock[wedgeType];
159 break;
160 case VTK_PYRAMID:
161 ++numberOfElementsInBlock[pyramidType];
162 break;
163 case VTK_QUADRATIC_TETRA:
164 ++numberOfElementsInBlock[quadraticTetraType];
165 break;
166 case VTK_QUADRATIC_HEXAHEDRON:
167 ++numberOfElementsInBlock[quadraticHexahedronType];
168 break;
169 case VTK_QUADRATIC_WEDGE:
170 ++numberOfElementsInBlock[quadraticWedgeType];
171 break;
172 case VTK_BIQUADRATIC_QUADRATIC_WEDGE:
173 ++numberOfElementsInBlock[biquadraticWedgeType];
174 break;
175 case VTK_QUADRATIC_PYRAMID:
176 vtkWarningMacro(<<"Quadratic pyramid not currently supported in libmesh. Skipping element.");
177 continue;
178 default:
179 continue;
180 }
181
182 ++numberOfVolumeCells;
183 totalWeight += input->GetCell(i)->GetNumberOfPoints();
184 }
185
186 int numberOfElementBlocks = 0;
187
188 for (i=0; i<numberOfVolumeCellTypes; i++)
189 {
190 if (numberOfElementsInBlock[i] > 0)
191 {
192 ++numberOfElementBlocks;
193 }
194 }
195
196 int numberOfBoundaryConditions = 0;
197 if (boundaryDataArray)
198 {
199 for (i=0; i<numberOfCells; i++)
200 {
201 int cellType = input->GetCellType(i);
202 switch (cellType)
203 {
204 case VTK_TRIANGLE:
205 case VTK_QUAD:
206 case VTK_QUADRATIC_TRIANGLE:
207 case VTK_QUADRATIC_QUAD:
208 numberOfBoundaryConditions++;
209 break;
210 default:
211 continue;
212 }
213 }
214 }
215
216 out << "DEAL 003:003" << endl;
217
218 out << numberOfVolumeCells << "\t# Num. Elements" << endl;
219 out << numberOfPoints << "\t# Num. Nodes" << endl;
220 out << totalWeight << "\t# Sum of Element Weights" << endl;
221
222 out << numberOfBoundaryConditions << "\t# Num. Boundary Conds." << endl;
223
224 int stringSize = 65536;
225 out << stringSize << "\t# String Size (ignore)" << endl;
226
227
228 out << numberOfElementBlocks << "\t# Num. Element Types." << endl;
229
230 for (i=0; i<numberOfVolumeCellTypes; i++)
231 {
232 if (numberOfElementsInBlock[i] > 0)
233 {
234 out << elementTypeLibmeshMap[i] << " ";
235 }
236 }
237 out << "\t# Element types in each block." << endl;
238
239 for (i=0; i<numberOfVolumeCellTypes; i++)
240 {
241 if (numberOfElementsInBlock[i] > 0)
242 {
243 out << numberOfElementsInBlock[i] << " ";
244 }
245 }
246 out << "\t# Num. of elements in each block at each refinement level." << endl;
247
248 out << "Id String" << endl;
249 out << "Title String" << endl;
250
251 vtkIdList* volumeCellIdMap = vtkIdList::New();
252 volumeCellIdMap->SetNumberOfIds(numberOfCells);
253 int volumeCellCounter = 0;
254 for (i=0; i<numberOfVolumeCellTypes; i++)
255 {
256 if (numberOfElementsInBlock[i] == 0)
257 {
258 continue;
259 }
260
261 vtkIdTypeArray* typeCellIds = vtkIdTypeArray::New();
262 input->GetIdsOfCellsOfType(blockVtkCellTypes[i], typeCellIds);
263
264 vtkIdList* libmeshConnectivity = vtkIdList::New();
266
267 int numberOfTypeCells = typeCellIds->GetNumberOfTuples();
268
269 int j;
270 for (j=0; j<numberOfTypeCells; j++)
271 {
272 vtkIdType id = typeCellIds->GetValue(j);
273 vtkIdList* cellPoints = vtkIdList::New();
274 input->GetCellPoints(id,cellPoints);
275
276 int numberOfCellPoints = libmeshConnectivity->GetNumberOfIds();
277 for (int k=0; k<numberOfCellPoints; k++)
278 {
279 out << cellPoints->GetId(libmeshConnectivity->GetId(k)) << " ";
280 }
281
282 out << endl;
283
284 volumeCellIdMap->SetId(id,volumeCellCounter);
285 volumeCellCounter++;
286 cellPoints->Delete();
287 }
288
289 typeCellIds->Delete();
290 libmeshConnectivity->Delete();
291 }
292
293 double point[3];
294 for (i=0; i<numberOfPoints; i++)
295 {
296 input->GetPoint(i,point);
297 out << point[0] << " " << point[1] << " " << point[2] << endl;
298 }
299
300 if (boundaryDataArray)
301 {
302 for (i=0; i<numberOfCells; i++)
303 {
304 int faceCellType = input->GetCellType(i);
305 switch (faceCellType)
306 {
307 case VTK_TRIANGLE:
308 case VTK_QUAD:
309 case VTK_QUADRATIC_TRIANGLE:
310 case VTK_QUADRATIC_QUAD:
311 break;
312 default:
313 continue;
314 }
315
316 vtkIdList* faceCellPoints = vtkIdList::New();
317 input->GetCellPoints(i,faceCellPoints);
318
319 vtkIdList* cellIds = vtkIdList::New();
320 input->GetCellNeighbors(i,faceCellPoints,cellIds);
321
322 if (cellIds->GetNumberOfIds() != 1)
323 {
324 vtkWarningMacro("Boundary cell not on boundary!");
325 }
326
327 vtkIdType cellId = cellIds->GetId(0);
328
329 vtkCell* cell = input->GetCell(cellId);
330
331 int cellType = cell->GetCellType();
332
333 int numberOfFaces = cell->GetNumberOfFaces();
334
335 vtkIdType faceId = -1;
336
337 int j;
338 for (j=0; j<numberOfFaces; j++)
339 {
340 vtkCell* face = cell->GetFace(j);
341
342 vtkIdList* matchingPointIds = vtkIdList::New();
343 matchingPointIds->DeepCopy(face->GetPointIds());
344
345 matchingPointIds->IntersectWith(faceCellPoints);
346
347 int numberOfNonMatching = face->GetNumberOfPoints() - matchingPointIds->GetNumberOfIds();
348
349 matchingPointIds->Delete();
350
351 if (numberOfNonMatching==0)
352 {
353 faceId = j;
354 break;
355 }
356 }
357
358 vtkIdList* libmeshFaceOrder = vtkIdList::New();
359
361 vtkIdType libmeshFaceId = libmeshFaceOrder->GetId(faceId);
362
363 libmeshFaceOrder->Delete();
364
365 short int boundaryValue = static_cast<short int>(boundaryDataArray->GetComponent(i,0));
366 out << volumeCellIdMap->GetId(cellId) << " " << libmeshFaceId << " " << boundaryValue << endl;
367
368 faceCellPoints->Delete();
369 }
370 }
371
372 volumeCellIdMap->Delete();
373}
static void GetLibmeshFaceOrder(int cellType, vtkIdList *libmeshFaceOrder)
static void GetLibmeshConnectivity(int cellType, vtkIdList *libmeshConnectivity)