67 vtkUnstructuredGrid* grid,
bool const compute_element_neighbors,
68 std::string
const& mesh_name)
76 const std::size_t nNodes = grid->GetPoints()->GetNumberOfPoints();
77 std::vector<MeshLib::Node*> nodes(nNodes);
78 double* coords =
nullptr;
79 for (std::size_t i = 0; i < nNodes; i++)
81 coords = grid->GetPoints()->GetPoint(i);
82 nodes[i] =
new MeshLib::Node(coords[0], coords[1], coords[2], i);
86 const std::size_t nElems = grid->GetNumberOfCells();
87 std::vector<MeshLib::Element*> elements;
88 elements.reserve(nElems);
89 auto node_ids = vtkSmartPointer<vtkIdList>::New();
90 for (std::size_t i = 0; i < nElems; i++)
93 grid->GetCellPoints(i, node_ids);
95 int cell_type = grid->GetCellType(i);
125 quad_nodes[0] = nodes[node_ids->GetId(0)];
126 quad_nodes[1] = nodes[node_ids->GetId(1)];
127 quad_nodes[2] = nodes[node_ids->GetId(3)];
128 quad_nodes[3] = nodes[node_ids->GetId(2)];
147 voxel_nodes[0] = nodes[node_ids->GetId(0)];
148 voxel_nodes[1] = nodes[node_ids->GetId(1)];
149 voxel_nodes[2] = nodes[node_ids->GetId(3)];
150 voxel_nodes[3] = nodes[node_ids->GetId(2)];
151 voxel_nodes[4] = nodes[node_ids->GetId(4)];
152 voxel_nodes[5] = nodes[node_ids->GetId(5)];
153 voxel_nodes[6] = nodes[node_ids->GetId(7)];
154 voxel_nodes[7] = nodes[node_ids->GetId(6)];
167 for (
unsigned j = 0; j < 3; ++j)
169 prism_nodes[j] = nodes[node_ids->GetId(j + 3)];
170 prism_nodes[j + 3] = nodes[node_ids->GetId(j)];
175 case VTK_QUADRATIC_EDGE:
181 case VTK_QUADRATIC_TRIANGLE:
187 case VTK_QUADRATIC_QUAD:
193 case VTK_BIQUADRATIC_QUAD:
199 case VTK_QUADRATIC_TETRA:
205 case VTK_QUADRATIC_HEXAHEDRON:
211 case VTK_QUADRATIC_PYRAMID:
218 case VTK_QUADRATIC_WEDGE:
226 ERR(
"VtkMeshConverter::convertUnstructuredGrid(): Unknown mesh "
227 "element type '{:d}'.",
232 elements.push_back(elem);
236 compute_element_neighbors);
245 vtkPointData* point_data = grid.GetPointData();
246 auto const n_point_arrays =
247 static_cast<unsigned>(point_data->GetNumberOfArrays());
248 for (
unsigned i = 0; i < n_point_arrays; ++i)
255 vtkCellData* cell_data = grid.GetCellData();
256 auto const n_cell_arrays =
257 static_cast<unsigned>(cell_data->GetNumberOfArrays());
258 for (
unsigned i = 0; i < n_cell_arrays; ++i)
265 vtkFieldData* field_data = grid.GetFieldData();
266 auto const n_field_arrays =
267 static_cast<unsigned>(field_data->GetNumberOfArrays());
268 for (
unsigned i = 0; i < n_field_arrays; ++i)
271 *vtkDataArray::SafeDownCast(field_data->GetAbstractArray(i)),
281 if (vtkDoubleArray::SafeDownCast(&array))
287 if (vtkFloatArray::SafeDownCast(&array))
293 if (vtkBitArray::SafeDownCast(&array))
301 if (vtkCharArray::SafeDownCast(&array) ||
302 vtkSignedCharArray::SafeDownCast(&array))
304 if constexpr (
sizeof(std::int8_t) !=
sizeof(char))
307 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
308 "not convertible to char.",
309 array.GetName(), array.GetDataTypeAsString());
317 if (vtkShortArray::SafeDownCast(&array))
319 if constexpr (
sizeof(std::int16_t) !=
sizeof(short))
322 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
323 "not convertible to short.",
324 array.GetName(), array.GetDataTypeAsString());
332 if (vtkIntArray::SafeDownCast(&array))
334 if constexpr (
sizeof(std::int32_t) !=
sizeof(int))
337 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
338 "not convertible to int.",
339 array.GetName(), array.GetDataTypeAsString());
347 if (vtkLongArray::SafeDownCast(&array))
349 if constexpr (
sizeof(long) ==
sizeof(int))
354 if constexpr (
sizeof(
long long) ==
sizeof(long))
361 "Array '{:s}' in VTU file uses unsupported data type '{:s}' ({:d}) "
362 "not convertible to int ({:d}), or long ({:d}) types.",
363 array.GetName(), array.GetDataTypeAsString(),
364 array.GetDataTypeSize(),
sizeof(
int),
sizeof(
long));
368 static_assert(
sizeof(std::int64_t) ==
sizeof(
long long));
373 if (vtkLongLongArray::SafeDownCast(&array))
375 if constexpr (
sizeof(
long long) ==
sizeof(long))
390 if (vtkUnsignedCharArray::SafeDownCast(&array))
392 if constexpr (
sizeof(std::uint8_t) !=
sizeof(
unsigned char))
395 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
396 "not convertible to unsigned char.",
397 array.GetName(), array.GetDataTypeAsString());
406 if (vtkUnsignedShortArray::SafeDownCast(&array))
408 if constexpr (
sizeof(std::uint16_t) !=
sizeof(
unsigned short))
411 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
412 "not convertible to unsigned short.",
413 array.GetName(), array.GetDataTypeAsString());
422 if (vtkUnsignedIntArray::SafeDownCast(&array))
424 if constexpr (
sizeof(std::uint32_t) !=
sizeof(unsigned))
427 "Array '{:s}' in VTU file uses unsupported data type '{:s}' "
428 "not convertible to unsigned.",
429 array.GetName(), array.GetDataTypeAsString());
433 if (std::strncmp(array.GetName(),
"MaterialIDs", 11) == 0)
449 if (vtkUnsignedLongArray::SafeDownCast(&array))
451 if constexpr (
sizeof(
unsigned long) ==
sizeof(unsigned))
457 if constexpr (
sizeof(
unsigned long long) ==
sizeof(
unsigned long))
460 array, properties, type);
465 "Array '{:s}' in VTU file uses unsupported data type '{:s}' ({:d}) "
466 "not convertible to unsigned ({:d}), or unsigned long ({:d}) "
468 array.GetName(), array.GetDataTypeAsString(),
469 array.GetDataTypeSize(),
sizeof(
unsigned),
sizeof(
unsigned long));
474 static_assert(
sizeof(std::uint64_t) ==
sizeof(
unsigned long long));
479 if (vtkUnsignedLongLongArray::SafeDownCast(&array))
481 if constexpr (
sizeof(
unsigned long long) ==
sizeof(
unsigned long))
484 array, properties, type);
491 array, properties, type);
496 if (vtkIdTypeArray::SafeDownCast(&array))
501 using namespace std::literals;
502 if (array.GetName() ==
"bulk_element_ids"sv ||
503 array.GetName() ==
"bulk_node_ids"sv)
517 "Array '{:s}' in VTU file uses unsupported data type '{:s}' of size "
518 "{:d}. The data array will not be available.",
519 array.GetName(), array.GetDataTypeAsString(), array.GetDataTypeSize());