56 vtkUnstructuredGrid* grid,
bool const compute_element_neighbors,
57 std::string
const& mesh_name)
65 const std::size_t nNodes = grid->GetPoints()->GetNumberOfPoints();
66 std::vector<MeshLib::Node*> nodes(nNodes);
67 double* coords =
nullptr;
68 for (std::size_t i = 0; i < nNodes; i++)
70 coords = grid->GetPoints()->GetPoint(i);
71 nodes[i] =
new MeshLib::Node(coords[0], coords[1], coords[2], i);
75 const std::size_t nElems = grid->GetNumberOfCells();
76 std::vector<MeshLib::Element*> elements;
77 elements.reserve(nElems);
78 auto node_ids = vtkSmartPointer<vtkIdList>::New();
79 for (std::size_t i = 0; i < nElems; i++)
82 grid->GetCellPoints(i, node_ids);
84 int cell_type = grid->GetCellType(i);
114 quad_nodes[0] = nodes[node_ids->GetId(0)];
115 quad_nodes[1] = nodes[node_ids->GetId(1)];
116 quad_nodes[2] = nodes[node_ids->GetId(3)];
117 quad_nodes[3] = nodes[node_ids->GetId(2)];
136 voxel_nodes[0] = nodes[node_ids->GetId(0)];
137 voxel_nodes[1] = nodes[node_ids->GetId(1)];
138 voxel_nodes[2] = nodes[node_ids->GetId(3)];
139 voxel_nodes[3] = nodes[node_ids->GetId(2)];
140 voxel_nodes[4] = nodes[node_ids->GetId(4)];
141 voxel_nodes[5] = nodes[node_ids->GetId(5)];
142 voxel_nodes[6] = nodes[node_ids->GetId(7)];
143 voxel_nodes[7] = nodes[node_ids->GetId(6)];
156 for (
unsigned j = 0; j < 3; ++j)
158 prism_nodes[j] = nodes[node_ids->GetId(j + 3)];
159 prism_nodes[j + 3] = nodes[node_ids->GetId(j)];
164 case VTK_QUADRATIC_EDGE:
170 case VTK_QUADRATIC_TRIANGLE:
176 case VTK_QUADRATIC_QUAD:
182 case VTK_BIQUADRATIC_QUAD:
188 case VTK_QUADRATIC_TETRA:
194 case VTK_QUADRATIC_HEXAHEDRON:
200 case VTK_QUADRATIC_PYRAMID:
207 case VTK_QUADRATIC_WEDGE:
215 ERR(
"VtkMeshConverter::convertUnstructuredGrid(): Unknown mesh "
216 "element type '{:d}'.",
221 elements.push_back(elem);
225 compute_element_neighbors);
234 vtkPointData* point_data = grid.GetPointData();
235 auto const n_point_arrays =
236 static_cast<unsigned>(point_data->GetNumberOfArrays());
237 for (
unsigned i = 0; i < n_point_arrays; ++i)
244 vtkCellData* cell_data = grid.GetCellData();
245 auto const n_cell_arrays =
246 static_cast<unsigned>(cell_data->GetNumberOfArrays());
247 for (
unsigned i = 0; i < n_cell_arrays; ++i)
254 vtkFieldData* field_data = grid.GetFieldData();
255 auto const n_field_arrays =
256 static_cast<unsigned>(field_data->GetNumberOfArrays());
257 for (
unsigned i = 0; i < n_field_arrays; ++i)
260 *vtkDataArray::SafeDownCast(field_data->GetAbstractArray(i)),
270 if (vtkDoubleArray::SafeDownCast(&array))
276 if (vtkFloatArray::SafeDownCast(&array))
282 if (vtkBitArray::SafeDownCast(&array))
290 if (vtkCharArray::SafeDownCast(&array) ||
291 vtkSignedCharArray::SafeDownCast(&array))
293 if constexpr (
sizeof(std::int8_t) !=
sizeof(char))
296 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
297 "not convertible to char.",
298 array.GetName(), array.GetDataTypeAsString());
306 if (vtkShortArray::SafeDownCast(&array))
308 if constexpr (
sizeof(std::int16_t) !=
sizeof(short))
311 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
312 "not convertible to short.",
313 array.GetName(), array.GetDataTypeAsString());
321 if (vtkIntArray::SafeDownCast(&array))
323 if constexpr (
sizeof(std::int32_t) !=
sizeof(int))
326 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
327 "not convertible to int.",
328 array.GetName(), array.GetDataTypeAsString());
336 if (vtkLongArray::SafeDownCast(&array))
338 if constexpr (
sizeof(long) ==
sizeof(int))
343 if constexpr (
sizeof(
long long) ==
sizeof(long))
350 "Array '{:s}' in VTU file uses unsupported data type '{:s}' ({:d}) "
351 "not convertible to int ({:d}), or long ({:d}) types.",
352 array.GetName(), array.GetDataTypeAsString(),
353 array.GetDataTypeSize(),
sizeof(
int),
sizeof(
long));
357 static_assert(
sizeof(std::int64_t) ==
sizeof(
long long));
362 if (vtkLongLongArray::SafeDownCast(&array))
364 if constexpr (
sizeof(
long long) ==
sizeof(long))
379 if (vtkUnsignedCharArray::SafeDownCast(&array))
381 if constexpr (
sizeof(std::uint8_t) !=
sizeof(
unsigned char))
384 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
385 "not convertible to unsigned char.",
386 array.GetName(), array.GetDataTypeAsString());
395 if (vtkUnsignedShortArray::SafeDownCast(&array))
397 if constexpr (
sizeof(std::uint16_t) !=
sizeof(
unsigned short))
400 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
401 "not convertible to unsigned short.",
402 array.GetName(), array.GetDataTypeAsString());
411 if (vtkUnsignedIntArray::SafeDownCast(&array))
413 if constexpr (
sizeof(std::uint32_t) !=
sizeof(unsigned))
416 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
417 "not convertible to unsigned.",
418 array.GetName(), array.GetDataTypeAsString());
422 if (std::strncmp(array.GetName(),
"MaterialIDs", 11) == 0)
438 if (vtkUnsignedLongArray::SafeDownCast(&array))
440 if constexpr (
sizeof(
unsigned long) ==
sizeof(unsigned))
446 if constexpr (
sizeof(
unsigned long long) ==
sizeof(
unsigned long))
449 array, properties, type);
454 "Array '{:s}' in VTU file uses unsupported data type '{:s}' ({:d}) "
455 "not convertible to unsigned ({:d}), or unsigned long ({:d}) "
457 array.GetName(), array.GetDataTypeAsString(),
458 array.GetDataTypeSize(),
sizeof(
unsigned),
sizeof(
unsigned long));
463 static_assert(
sizeof(std::uint64_t) ==
sizeof(
unsigned long long));
468 if (vtkUnsignedLongLongArray::SafeDownCast(&array))
470 if constexpr (
sizeof(
unsigned long long) ==
sizeof(
unsigned long))
473 array, properties, type);
480 array, properties, type);
485 if (vtkIdTypeArray::SafeDownCast(&array))
490 using namespace std::literals;
491 if (array.GetName() ==
"bulk_element_ids"sv ||
492 array.GetName() ==
"bulk_node_ids"sv)
506 "Array '{:s}' in VTU file uses unsupported data type '{:s}' of size "
507 "{:d}. The data array will not be available.",
508 array.GetName(), array.GetDataTypeAsString(), array.GetDataTypeSize());