66 vtkUnstructuredGrid* grid,
bool const compute_element_neighbors,
67 std::string
const& mesh_name)
75 const std::size_t nNodes = grid->GetPoints()->GetNumberOfPoints();
76 std::vector<MeshLib::Node*> nodes(nNodes);
77 double* coords =
nullptr;
78 for (std::size_t i = 0; i < nNodes; i++)
80 coords = grid->GetPoints()->GetPoint(i);
81 nodes[i] =
new MeshLib::Node(coords[0], coords[1], coords[2], i);
85 const std::size_t nElems = grid->GetNumberOfCells();
86 std::vector<MeshLib::Element*> elements(nElems);
87 auto node_ids = vtkSmartPointer<vtkIdList>::New();
88 for (std::size_t i = 0; i < nElems; i++)
91 grid->GetCellPoints(i, node_ids);
93 int cell_type = grid->GetCellType(i);
123 quad_nodes[0] = nodes[node_ids->GetId(0)];
124 quad_nodes[1] = nodes[node_ids->GetId(1)];
125 quad_nodes[2] = nodes[node_ids->GetId(3)];
126 quad_nodes[3] = nodes[node_ids->GetId(2)];
145 voxel_nodes[0] = nodes[node_ids->GetId(0)];
146 voxel_nodes[1] = nodes[node_ids->GetId(1)];
147 voxel_nodes[2] = nodes[node_ids->GetId(3)];
148 voxel_nodes[3] = nodes[node_ids->GetId(2)];
149 voxel_nodes[4] = nodes[node_ids->GetId(4)];
150 voxel_nodes[5] = nodes[node_ids->GetId(5)];
151 voxel_nodes[6] = nodes[node_ids->GetId(7)];
152 voxel_nodes[7] = nodes[node_ids->GetId(6)];
165 for (
unsigned j = 0; j < 3; ++j)
167 prism_nodes[j] = nodes[node_ids->GetId(j + 3)];
168 prism_nodes[j + 3] = nodes[node_ids->GetId(j)];
173 case VTK_QUADRATIC_EDGE:
179 case VTK_QUADRATIC_TRIANGLE:
185 case VTK_QUADRATIC_QUAD:
191 case VTK_BIQUADRATIC_QUAD:
197 case VTK_QUADRATIC_TETRA:
203 case VTK_QUADRATIC_HEXAHEDRON:
209 case VTK_QUADRATIC_PYRAMID:
216 case VTK_QUADRATIC_WEDGE:
224 ERR(
"VtkMeshConverter::convertUnstructuredGrid(): Unknown mesh "
225 "element type '{:d}'.",
234 compute_element_neighbors);
243 vtkPointData* point_data = grid.GetPointData();
244 auto const n_point_arrays =
245 static_cast<unsigned>(point_data->GetNumberOfArrays());
246 for (
unsigned i = 0; i < n_point_arrays; ++i)
253 vtkCellData* cell_data = grid.GetCellData();
254 auto const n_cell_arrays =
255 static_cast<unsigned>(cell_data->GetNumberOfArrays());
256 for (
unsigned i = 0; i < n_cell_arrays; ++i)
263 vtkFieldData* field_data = grid.GetFieldData();
264 auto const n_field_arrays =
265 static_cast<unsigned>(field_data->GetNumberOfArrays());
266 for (
unsigned i = 0; i < n_field_arrays; ++i)
269 *vtkDataArray::SafeDownCast(field_data->GetAbstractArray(i)),
279 if (vtkDoubleArray::SafeDownCast(&array))
285 if (vtkFloatArray::SafeDownCast(&array))
291 if (vtkBitArray::SafeDownCast(&array))
299 if (vtkCharArray::SafeDownCast(&array) ||
300 vtkSignedCharArray::SafeDownCast(&array))
302 if constexpr (
sizeof(std::int8_t) !=
sizeof(
char))
305 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
306 "not convertible to char.",
307 array.GetName(), array.GetDataTypeAsString());
315 if (vtkShortArray::SafeDownCast(&array))
317 if constexpr (
sizeof(std::int16_t) !=
sizeof(
short))
320 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
321 "not convertible to short.",
322 array.GetName(), array.GetDataTypeAsString());
330 if (vtkIntArray::SafeDownCast(&array))
332 if constexpr (
sizeof(std::int32_t) !=
sizeof(
int))
335 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
336 "not convertible to int.",
337 array.GetName(), array.GetDataTypeAsString());
345 if (vtkLongArray::SafeDownCast(&array))
347 if constexpr (
sizeof(long) ==
sizeof(
int))
352 if constexpr (
sizeof(
long long) ==
sizeof(
long))
359 "Array '{:s}' in VTU file uses unsupported data type '{:s}' ({:d}) "
360 "not convertible to int ({:d}), or long ({:d}) types.",
361 array.GetName(), array.GetDataTypeAsString(),
362 array.GetDataTypeSize(),
sizeof(
int),
sizeof(
long));
366 static_assert(
sizeof(std::int64_t) ==
sizeof(
long long));
371 if (vtkLongLongArray::SafeDownCast(&array))
373 if constexpr (
sizeof(
long long) ==
sizeof(
long))
388 if (vtkUnsignedCharArray::SafeDownCast(&array))
390 if constexpr (
sizeof(std::uint8_t) !=
sizeof(
unsigned char))
393 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
394 "not convertible to unsigned char.",
395 array.GetName(), array.GetDataTypeAsString());
404 if (vtkUnsignedShortArray::SafeDownCast(&array))
406 if constexpr (
sizeof(std::uint16_t) !=
sizeof(
unsigned short))
409 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
410 "not convertible to unsigned short.",
411 array.GetName(), array.GetDataTypeAsString());
420 if (vtkUnsignedIntArray::SafeDownCast(&array))
422 if constexpr (
sizeof(std::uint32_t) !=
sizeof(
unsigned))
425 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
426 "not convertible to unsigned.",
427 array.GetName(), array.GetDataTypeAsString());
431 if (std::strncmp(array.GetName(),
"MaterialIDs", 11) == 0)
447 if (vtkUnsignedLongArray::SafeDownCast(&array))
449 if constexpr (
sizeof(
unsigned long) ==
sizeof(
unsigned))
455 if constexpr (
sizeof(
unsigned long long) ==
sizeof(
unsigned long))
458 array, properties, type);
463 "Array '{:s}' in VTU file uses unsupported data type '{:s}' ({:d}) "
464 "not convertible to unsigned ({:d}), or unsigned long ({:d}) "
466 array.GetName(), array.GetDataTypeAsString(),
467 array.GetDataTypeSize(),
sizeof(
unsigned),
sizeof(
unsigned long));
472 static_assert(
sizeof(std::uint64_t) ==
sizeof(
unsigned long long));
477 if (vtkUnsignedLongLongArray::SafeDownCast(&array))
479 if constexpr (
sizeof(
unsigned long long) ==
sizeof(
unsigned long))
482 array, properties, type);
489 array, properties, type);
495 "Array '{:s}' in VTU file uses unsupported data type '{:s}' of size "
496 "{:d}. The data array will not be available.",
497 array.GetName(), array.GetDataTypeAsString(), array.GetDataTypeSize());