17 #include <deal.II/base/exceptions.h> 18 #include <deal.II/base/path_search.h> 19 #include <deal.II/base/utilities.h> 21 #include <deal.II/grid/grid_in.h> 22 #include <deal.II/grid/grid_reordering.h> 23 #include <deal.II/grid/grid_tools.h> 24 #include <deal.II/grid/tria.h> 26 #include <boost/io/ios_state.hpp> 35 #ifdef DEAL_II_WITH_NETCDF 36 # include <netcdfcpp.h> 39 #ifdef DEAL_II_WITH_ASSIMP 40 # include <assimp/Importer.hpp> 41 # include <assimp/postprocess.h> 42 # include <assimp/scene.h> 46 DEAL_II_NAMESPACE_OPEN
59 template <
int spacedim>
61 assign_1d_boundary_ids(
62 const std::map<unsigned int, types::boundary_id> &boundary_ids,
65 if (boundary_ids.size() > 0)
67 triangulation.begin_active();
68 cell != triangulation.end();
70 for (
unsigned int f = 0; f < GeometryInfo<1>::faces_per_cell; ++f)
71 if (boundary_ids.find(cell->vertex_index(f)) != boundary_ids.end())
76 "You are trying to prescribe boundary ids on the face " 77 "of a 1d cell (i.e., on a vertex), but this face is not actually at " 78 "the boundary of the mesh. This is not allowed."));
79 cell->face(f)->set_boundary_id(
80 boundary_ids.find(cell->vertex_index(f))->second);
85 template <
int dim,
int spacedim>
87 assign_1d_boundary_ids(
const std::map<unsigned int, types::boundary_id> &,
96 template <
int dim,
int spacedim>
98 : tria(nullptr, typeid(*this).name())
103 template <
int dim,
int spacedim>
112 template <
int dim,
int spacedim>
124 text[0] =
"# vtk DataFile Version 3.0";
127 text[3] =
"DATASET UNSTRUCTURED_GRID";
129 for (
unsigned int i = 0; i < 4; ++i)
134 line.compare(text[i]) == 0,
137 "While reading VTK file, failed to find a header line with text <") +
144 std::vector<Point<spacedim>> vertices;
145 std::vector<CellData<dim>> cells;
154 if (keyword ==
"POINTS")
156 unsigned int n_vertices;
161 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
165 in >> x(0) >> x(1) >> x(2);
167 vertices.emplace_back();
168 for (
unsigned int d = 0; d < spacedim; ++d)
169 vertices.back()(d) = x(d);
176 "While reading VTK file, failed to find POINTS section"));
180 unsigned int n_geometric_objects = 0;
183 if (keyword ==
"CELLS")
185 in >> n_geometric_objects;
190 for (
unsigned int count = 0; count < n_geometric_objects; count++)
203 cells.emplace_back();
205 for (
unsigned int j = 0; j < type; j++)
206 in >> cells.back().vertices[j];
208 cells.back().material_id = 0;
220 for (
unsigned int j = 0; j < type;
230 for (
unsigned int j = 0; j < type;
241 "While reading VTK file, unknown file type encountered"));
247 for (
unsigned int count = 0; count < n_geometric_objects; count++)
259 cells.emplace_back();
261 for (
unsigned int j = 0; j < type; j++)
262 in >> cells.back().vertices[j];
264 cells.back().material_id = 0;
273 for (
unsigned int j = 0; j < type;
286 "While reading VTK file, unknown cell type encountered"));
291 for (
unsigned int count = 0; count < n_geometric_objects; count++)
299 "While reading VTK file, unknown cell type encountered"));
300 cells.emplace_back();
302 for (
unsigned int j = 0; j < type; j++)
303 in >> cells.back().vertices[j];
305 cells.back().material_id = 0;
311 "While reading VTK file, failed to find CELLS section"));
319 keyword ==
"CELL_TYPES",
321 "While reading VTK file, missing CELL_TYPES section. Found <" +
322 keyword +
"> instead.")));
326 n_ints == n_geometric_objects,
327 ExcMessage(
"The VTK reader found a CELL_DATA statement " 328 "that lists a total of " +
330 " cell data objects, but this needs to " 331 "equal the number of cells (which is " +
333 ") plus the number of quads (" +
335 " in 3d or the number of lines (" +
340 for (
unsigned int i = 0; i < n_ints; ++i)
344 while (in >> keyword)
345 if (keyword ==
"CELL_DATA")
351 ExcMessage(
"The VTK reader found a CELL_DATA statement " 352 "that lists a total of " +
354 " cell data objects, but this needs to " 355 "equal the number of cells (which is " +
357 ") plus the number of quads (" +
360 " in 3d or the number of lines (" +
365 const std::vector<std::string> data_sets{
"MaterialID",
368 for (
unsigned int i = 0; i < data_sets.size(); ++i)
371 while (in >> keyword)
372 if (keyword ==
"SCALARS")
377 std::string
set =
"";
379 for (
const auto &set_cmp : data_sets)
380 if (keyword == set_cmp)
394 in.ignore(256,
'\n');
398 keyword ==
"LOOKUP_TABLE",
400 "While reading VTK file, missing keyword LOOKUP_TABLE"));
404 keyword ==
"default",
406 "While reading VTK file, missing keyword default"));
413 for (
unsigned int i = 0; i < cells.size(); i++)
417 if (
set ==
"MaterialID")
418 cells[i].material_id =
420 else if (
set ==
"ManifoldID")
421 cells[i].manifold_id =
433 if (
set ==
"MaterialID")
434 boundary_quad.material_id =
436 else if (
set ==
"ManifoldID")
437 boundary_quad.manifold_id =
446 if (
set ==
"MaterialID")
447 boundary_line.material_id =
449 else if (
set ==
"ManifoldID")
450 boundary_line.manifold_id =
462 if (
set ==
"MaterialID")
463 boundary_line.material_id =
465 else if (
set ==
"ManifoldID")
466 boundary_line.manifold_id =
485 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
492 "While reading VTK file, failed to find CELLS section"));
496 template <
int dim,
int spacedim>
504 skip_comment_lines(in,
'#');
515 AssertThrow(tmp == 2411, ExcUnknownSectionType(tmp));
517 std::vector<Point<spacedim>> vertices;
536 in >> dummy >> dummy >> dummy;
539 in >> x[0] >> x[1] >> x[2];
541 vertices.emplace_back();
543 for (
unsigned int d = 0; d < spacedim; d++)
544 vertices.back()(d) = x[d];
546 vertex_indices[no] = no_vertex;
558 AssertThrow(tmp == 2412, ExcUnknownSectionType(tmp));
560 std::vector<CellData<dim>> cells;
587 in >> type >> dummy >> dummy >> dummy >> dummy;
589 AssertThrow((type == 11) || (type == 44) || (type == 94) || (type == 115),
590 ExcUnknownElementType(type));
592 if ((((type == 44) || (type == 94)) && (dim == 2)) ||
593 ((type == 115) && (dim == 3)))
595 cells.emplace_back();
598 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell;
600 in >> cells.back().vertices[v];
602 cells.back().material_id = 0;
604 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell;
606 cells.back().vertices[v] = vertex_indices[cells.back().vertices[v]];
608 cell_indices[no] = no_cell;
612 else if (((type == 11) && (dim == 2)) ||
613 ((type == 11) && (dim == 3)))
616 in >> dummy >> dummy >> dummy;
621 for (
unsigned int &vertex :
627 for (
unsigned int &vertex :
629 vertex = vertex_indices[vertex];
631 line_indices[no] = no_line;
635 else if (((type == 44) || (type == 94)) && (dim == 3))
640 for (
unsigned int &vertex :
646 for (
unsigned int &vertex :
648 vertex = vertex_indices[vertex];
650 quad_indices[no] = no_quad;
658 "> when running in dim=" +
677 AssertThrow((tmp == 2467) || (tmp == 2477), ExcUnknownSectionType(tmp));
693 in >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >>
699 const unsigned int n_lines =
700 (n_entities % 2 == 0) ? (n_entities / 2) : ((n_entities + 1) / 2);
702 for (
unsigned int line = 0; line < n_lines; line++)
704 unsigned int n_fragments;
706 if (line == n_lines - 1)
707 n_fragments = (n_entities % 2 == 0) ? (2) : (1);
711 for (
unsigned int no_fragment = 0; no_fragment < n_fragments;
715 in >> dummy >> no >> dummy >> dummy;
717 if (cell_indices.count(no) > 0)
718 cells[cell_indices[no]].material_id =
id;
720 if (line_indices.count(no) > 0)
724 if (quad_indices.count(no) > 0)
742 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
747 template <
int dim,
int spacedim>
750 const bool apply_all_indicators_to_manifolds)
756 skip_comment_lines(in,
'#');
759 unsigned int n_vertices;
760 unsigned int n_cells;
763 in >> n_vertices >> n_cells >> dummy
769 std::vector<Point<spacedim>> vertices(n_vertices);
773 std::map<int, int> vertex_indices;
775 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
782 in >> vertex_number >> x[0] >> x[1] >> x[2];
785 for (
unsigned int d = 0; d < spacedim; ++d)
786 vertices[vertex](d) = x[d];
790 vertex_indices[vertex_number] = vertex;
794 std::vector<CellData<dim>> cells;
797 for (
unsigned int cell = 0; cell < n_cells; ++cell)
806 std::string cell_type;
810 unsigned int material_id;
816 if (((cell_type ==
"line") && (dim == 1)) ||
817 ((cell_type ==
"quad") && (dim == 2)) ||
818 ((cell_type ==
"hex") && (dim == 3)))
822 cells.emplace_back();
823 for (
unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_cell;
825 in >> cells.back().vertices[i];
828 Assert(material_id <= std::numeric_limits<types::material_id>::max(),
831 std::numeric_limits<types::material_id>::max()));
837 if (apply_all_indicators_to_manifolds)
838 cells.back().manifold_id =
840 cells.back().material_id =
845 for (
unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_cell;
847 if (vertex_indices.find(cells.back().vertices[i]) !=
848 vertex_indices.end())
850 cells.back().vertices[i] =
851 vertex_indices[cells.back().vertices[i]];
857 cells.back().vertices[i]));
862 else if ((cell_type ==
"line") && ((dim == 2) || (dim == 3)))
870 Assert(material_id <= std::numeric_limits<types::boundary_id>::max(),
873 std::numeric_limits<types::boundary_id>::max()));
885 if (apply_all_indicators_to_manifolds)
902 for (
unsigned int &vertex :
904 if (vertex_indices.find(vertex) != vertex_indices.end())
906 vertex = vertex_indices[vertex];
914 else if ((cell_type ==
"quad") && (dim == 3))
924 Assert(material_id <= std::numeric_limits<types::boundary_id>::max(),
927 std::numeric_limits<types::boundary_id>::max()));
939 if (apply_all_indicators_to_manifolds)
956 for (
unsigned int &vertex :
958 if (vertex_indices.find(vertex) != vertex_indices.end())
960 vertex = vertex_indices[vertex];
970 AssertThrow(
false, ExcUnknownIdentifier(cell_type));
986 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
991 template <
int dim,
int spacedim>
998 read_in_abaqus(std::istream &in);
1000 write_out_avs_ucd(std::ostream &out)
const;
1003 const double tolerance;
1006 get_global_node_numbers(
const int face_cell_no,
1007 const int face_cell_face_no)
const;
1010 std::vector<std::vector<double>> node_list;
1013 std::vector<std::vector<double>> cell_list;
1015 std::vector<std::vector<double>> face_list;
1018 std::map<std::string, std::vector<int>> elsets_list;
1022 template <
int dim,
int spacedim>
1025 const bool apply_all_indicators_to_manifolds)
1032 Assert((spacedim == 2 && dim == spacedim) ||
1033 (spacedim == 3 && (dim == spacedim || dim == spacedim - 1)),
1039 Abaqus_to_UCD<dim, spacedim> abaqus_to_ucd;
1040 abaqus_to_ucd.read_in_abaqus(in);
1042 std::stringstream in_ucd;
1043 abaqus_to_ucd.write_out_avs_ucd(in_ucd);
1051 read_ucd(in_ucd, apply_all_indicators_to_manifolds);
1053 catch (std::exception &exc)
1055 std::cerr <<
"Exception on processing internal UCD data: " << std::endl
1056 << exc.what() << std::endl;
1061 "Internal conversion from ABAQUS file to UCD format was unsuccessful. " 1062 "More information is provided in an error message printed above. " 1063 "Are you sure that your ABAQUS mesh file conforms with the requirements " 1064 "listed in the documentation?"));
1071 "Internal conversion from ABAQUS file to UCD format was unsuccessful. " 1072 "Are you sure that your ABAQUS mesh file conforms with the requirements " 1073 "listed in the documentation?"));
1078 template <
int dim,
int spacedim>
1088 skip_comment_lines(in,
'#');
1094 AssertThrow(line ==
"MeshVersionFormatted 0", ExcInvalidDBMESHInput(line));
1096 skip_empty_lines(in);
1100 AssertThrow(line ==
"Dimension", ExcInvalidDBMESHInput(line));
1101 unsigned int dimension;
1103 AssertThrow(dimension == dim, ExcDBMESHWrongDimension(dimension));
1104 skip_empty_lines(in);
1117 while (getline(in, line), line.find(
"# END") == std::string::npos)
1119 skip_empty_lines(in);
1124 AssertThrow(line ==
"Vertices", ExcInvalidDBMESHInput(line));
1126 unsigned int n_vertices;
1130 std::vector<Point<spacedim>> vertices(n_vertices);
1131 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
1134 for (
unsigned int d = 0; d < dim; ++d)
1135 in >> vertices[vertex][d];
1141 skip_empty_lines(in);
1147 AssertThrow(line ==
"Edges", ExcInvalidDBMESHInput(line));
1149 unsigned int n_edges;
1151 for (
unsigned int edge = 0; edge < n_edges; ++edge)
1154 in >> dummy >> dummy;
1160 skip_empty_lines(in);
1169 AssertThrow(line ==
"CrackedEdges", ExcInvalidDBMESHInput(line));
1172 for (
unsigned int edge = 0; edge < n_edges; ++edge)
1175 in >> dummy >> dummy;
1181 skip_empty_lines(in);
1187 AssertThrow(line ==
"Quadrilaterals", ExcInvalidDBMESHInput(line));
1189 std::vector<CellData<dim>> cells;
1191 unsigned int n_cells;
1193 for (
unsigned int cell = 0; cell < n_cells; ++cell)
1197 cells.emplace_back();
1198 for (
unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_cell; ++i)
1200 in >> cells.back().vertices[i];
1203 (static_cast<unsigned int>(cells.back().vertices[i]) <=
1207 --cells.back().vertices[i];
1215 skip_empty_lines(in);
1223 while (getline(in, line), ((line.find(
"End") == std::string::npos) && (in)))
1240 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
1245 template <
int dim,
int spacedim>
1266 unsigned int n_vertices;
1267 unsigned int n_cells;
1277 for (
unsigned int i = 0; i < 8; ++i)
1281 std::vector<CellData<2>> cells(n_cells);
1284 for (
unsigned int cell = 0; cell < n_cells; ++cell)
1294 for (
unsigned int &vertex : cells[cell].vertices)
1301 std::vector<Point<2>> vertices(n_vertices);
1302 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
1307 in >> x[0] >> x[1] >> x[2];
1310 for (
unsigned int d = 0;
d < 2; ++
d)
1311 vertices[vertex](d) = x[
d];
1320 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
1332 static const unsigned int xda_to_dealII_map[] = {0, 1, 5, 4, 3, 2, 6, 7};
1339 unsigned int n_vertices;
1340 unsigned int n_cells;
1350 for (
unsigned int i = 0; i < 8; ++i)
1354 std::vector<CellData<3>> cells(n_cells);
1357 for (
unsigned int cell = 0; cell < n_cells; ++cell)
1367 unsigned int xda_ordered_nodes[8];
1369 for (
unsigned int &xda_ordered_node : xda_ordered_nodes)
1370 in >> xda_ordered_node;
1372 for (
unsigned int i = 0; i < 8; i++)
1373 cells[cell].vertices[i] = xda_ordered_nodes[xda_to_dealII_map[i]];
1379 std::vector<Point<3>> vertices(n_vertices);
1380 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
1385 in >> x[0] >> x[1] >> x[2];
1388 for (
unsigned int d = 0;
d < 3; ++
d)
1389 vertices[vertex](d) = x[
d];
1398 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
1403 template <
int dim,
int spacedim>
1410 unsigned int n_vertices;
1411 unsigned int n_cells;
1417 std::array<std::map<int, int>, 4> tag_maps;
1422 unsigned int gmsh_file_format = 0;
1423 if (line ==
"@f$NOD")
1424 gmsh_file_format = 10;
1425 else if (line ==
"@f$MeshFormat")
1426 gmsh_file_format = 20;
1432 if (gmsh_file_format == 20)
1435 unsigned int file_type, data_size;
1437 in >> version >> file_type >> data_size;
1440 gmsh_file_format =
static_cast<unsigned int>(version * 10);
1448 AssertThrow(line ==
"@f$EndMeshFormat", ExcInvalidGMSHInput(line));
1452 if (line ==
"@f$PhysicalNames")
1458 while (line !=
"@f$EndPhysicalNames");
1463 if (line ==
"@f$Entities")
1465 unsigned long n_points, n_curves, n_surfaces, n_volumes;
1467 in >> n_points >> n_curves >> n_surfaces >> n_volumes;
1468 for (
unsigned int i = 0; i < n_points; ++i)
1472 unsigned int n_physicals;
1473 double box_min_x, box_min_y, box_min_z, box_max_x, box_max_y,
1477 if (gmsh_file_format > 40)
1479 in >> tag >> box_min_x >> box_min_y >> box_min_z >>
1481 box_max_x = box_min_x;
1482 box_max_y = box_min_y;
1483 box_max_z = box_min_z;
1487 in >> tag >> box_min_x >> box_min_y >> box_min_z >>
1488 box_max_x >> box_max_y >> box_max_z >> n_physicals;
1492 ExcMessage(
"More than one tag is not supported!"));
1494 int physical_tag = 0;
1495 for (
unsigned int j = 0; j < n_physicals; ++j)
1497 tag_maps[0][tag] = physical_tag;
1499 for (
unsigned int i = 0; i < n_curves; ++i)
1503 unsigned int n_physicals;
1504 double box_min_x, box_min_y, box_min_z, box_max_x, box_max_y,
1508 in >> tag >> box_min_x >> box_min_y >> box_min_z >> box_max_x >>
1509 box_max_y >> box_max_z >> n_physicals;
1512 ExcMessage(
"More than one tag is not supported!"));
1514 int physical_tag = 0;
1515 for (
unsigned int j = 0; j < n_physicals; ++j)
1517 tag_maps[1][tag] = physical_tag;
1521 for (
unsigned int j = 0; j < n_points; ++j)
1525 for (
unsigned int i = 0; i < n_surfaces; ++i)
1529 unsigned int n_physicals;
1530 double box_min_x, box_min_y, box_min_z, box_max_x, box_max_y,
1534 in >> tag >> box_min_x >> box_min_y >> box_min_z >> box_max_x >>
1535 box_max_y >> box_max_z >> n_physicals;
1538 ExcMessage(
"More than one tag is not supported!"));
1540 int physical_tag = 0;
1541 for (
unsigned int j = 0; j < n_physicals; ++j)
1543 tag_maps[2][tag] = physical_tag;
1547 for (
unsigned int j = 0; j < n_curves; ++j)
1550 for (
unsigned int i = 0; i < n_volumes; ++i)
1554 unsigned int n_physicals;
1555 double box_min_x, box_min_y, box_min_z, box_max_x, box_max_y,
1559 in >> tag >> box_min_x >> box_min_y >> box_min_z >> box_max_x >>
1560 box_max_y >> box_max_z >> n_physicals;
1563 ExcMessage(
"More than one tag is not supported!"));
1565 int physical_tag = 0;
1566 for (
unsigned int j = 0; j < n_physicals; ++j)
1568 tag_maps[3][tag] = physical_tag;
1572 for (
unsigned int j = 0; j < n_surfaces; ++j)
1576 AssertThrow(line ==
"@f$EndEntities", ExcInvalidGMSHInput(line));
1581 if (line ==
"@f$PartitionedEntities")
1587 while (line !=
"@f$EndPartitionedEntities");
1594 AssertThrow(line ==
"@f$Nodes", ExcInvalidGMSHInput(line));
1598 int n_entity_blocks = 1;
1599 if (gmsh_file_format > 40)
1603 in >> n_entity_blocks >> n_vertices >> min_node_tag >> max_node_tag;
1605 else if (gmsh_file_format == 40)
1607 in >> n_entity_blocks >> n_vertices;
1611 std::vector<Point<spacedim>> vertices(n_vertices);
1615 std::map<int, int> vertex_indices;
1618 unsigned int global_vertex = 0;
1619 for (
int entity_block = 0; entity_block < n_entity_blocks; ++entity_block)
1622 unsigned long numNodes;
1624 if (gmsh_file_format < 40)
1626 numNodes = n_vertices;
1633 int tagEntity, dimEntity;
1634 in >> tagEntity >> dimEntity >> parametric >> numNodes;
1637 std::vector<int> vertex_numbers;
1639 if (gmsh_file_format > 40)
1640 for (
unsigned long vertex_per_entity = 0;
1641 vertex_per_entity < numNodes;
1642 ++vertex_per_entity)
1644 in >> vertex_number;
1645 vertex_numbers.push_back(vertex_number);
1648 for (
unsigned long vertex_per_entity = 0; vertex_per_entity < numNodes;
1649 ++vertex_per_entity, ++global_vertex)
1655 if (gmsh_file_format > 40)
1657 vertex_number = vertex_numbers[vertex_per_entity];
1658 in >> x[0] >> x[1] >> x[2];
1661 in >> vertex_number >> x[0] >> x[1] >> x[2];
1663 for (
unsigned int d = 0; d < spacedim; ++d)
1664 vertices[global_vertex](d) = x[d];
1666 vertex_indices[vertex_number] = global_vertex;
1669 if (parametric != 0)
1684 static const std::string end_nodes_marker[] = {
"@f$ENDNOD",
"@f$EndNodes"};
1685 AssertThrow(line == end_nodes_marker[gmsh_file_format == 10 ? 0 : 1],
1686 ExcInvalidGMSHInput(line));
1690 static const std::string begin_elements_marker[] = {
"@f$ELM",
"@f$Elements"};
1691 AssertThrow(line == begin_elements_marker[gmsh_file_format == 10 ? 0 : 1],
1692 ExcInvalidGMSHInput(line));
1695 if (gmsh_file_format > 40)
1699 in >> n_entity_blocks >> n_cells >> min_node_tag >> max_node_tag;
1701 else if (gmsh_file_format == 40)
1703 in >> n_entity_blocks >> n_cells;
1707 n_entity_blocks = 1;
1714 std::vector<CellData<dim>> cells;
1716 std::map<unsigned int, types::boundary_id> boundary_ids_1d;
1719 unsigned int global_cell = 0;
1720 for (
int entity_block = 0; entity_block < n_entity_blocks; ++entity_block)
1722 unsigned int material_id;
1723 unsigned long numElements;
1726 if (gmsh_file_format < 40)
1730 numElements = n_cells;
1732 else if (gmsh_file_format == 40)
1734 int tagEntity, dimEntity;
1735 in >> tagEntity >> dimEntity >> cell_type >> numElements;
1736 material_id = tag_maps[dimEntity][tagEntity];
1741 int tagEntity, dimEntity;
1742 in >> dimEntity >> tagEntity >> cell_type >> numElements;
1743 material_id = tag_maps[dimEntity][tagEntity];
1746 for (
unsigned int cell_per_entity = 0; cell_per_entity < numElements;
1747 ++cell_per_entity, ++global_cell)
1756 unsigned int nod_num;
1776 unsigned int elm_number = 0;
1777 if (gmsh_file_format < 40)
1783 if (gmsh_file_format < 20)
1789 else if (gmsh_file_format < 40)
1794 unsigned int n_tags;
1801 for (
unsigned int i = 1; i < n_tags; ++i)
1830 if (((cell_type == 1) && (dim == 1)) ||
1831 ((cell_type == 3) && (dim == 2)) ||
1832 ((cell_type == 5) && (dim == 3)))
1837 "Number of nodes does not coincide with the " 1838 "number required for this object"));
1841 cells.emplace_back();
1842 for (
unsigned int i = 0;
1843 i < GeometryInfo<dim>::vertices_per_cell;
1845 in >> cells.back().vertices[i];
1849 std::numeric_limits<types::material_id>::max(),
1853 std::numeric_limits<types::material_id>::max()));
1861 cells.back().material_id =
1866 for (
unsigned int i = 0;
1867 i < GeometryInfo<dim>::vertices_per_cell;
1871 vertex_indices.find(cells.back().vertices[i]) !=
1872 vertex_indices.end(),
1873 ExcInvalidVertexIndexGmsh(cell_per_entity,
1875 cells.back().vertices[i]));
1878 cells.back().vertices[i] =
1879 vertex_indices[cells.back().vertices[i]];
1882 else if ((cell_type == 1) && ((dim == 2) || (dim == 3)))
1891 std::numeric_limits<types::boundary_id>::max(),
1895 std::numeric_limits<types::boundary_id>::max()));
1908 for (
unsigned int &vertex :
1910 if (vertex_indices.find(vertex) != vertex_indices.end())
1912 vertex = vertex_indices[vertex];
1922 else if ((cell_type == 3) && (dim == 3))
1933 std::numeric_limits<types::boundary_id>::max(),
1937 std::numeric_limits<types::boundary_id>::max()));
1950 for (
unsigned int &vertex :
1952 if (vertex_indices.find(vertex) != vertex_indices.end())
1954 vertex = vertex_indices[vertex];
1963 else if (cell_type == 15)
1966 unsigned int node_index = 0;
1967 if (gmsh_file_format < 20)
1969 for (
unsigned int i = 0; i < nod_num; ++i)
1980 boundary_ids_1d[vertex_indices[node_index]] = material_id;
1991 ExcMessage(
"Found triangles while reading a file " 1992 "in gmsh format. deal.II does not " 1993 "support triangles"));
1995 ExcMessage(
"Found tetrahedra while reading a file " 1996 "in gmsh format. deal.II does not " 1997 "support tetrahedra"));
1999 AssertThrow(
false, ExcGmshUnsupportedGeometry(cell_type));
2007 static const std::string end_elements_marker[] = {
"@f$ENDELM",
"@f$EndElements"};
2008 AssertThrow(line == end_elements_marker[gmsh_file_format == 10 ? 0 : 1],
2009 ExcInvalidGMSHInput(line));
2018 AssertThrow(cells.size() > 0, ExcGmshNoCellInformation());
2024 if (dim == spacedim)
2028 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
2033 assign_1d_boundary_ids(boundary_ids_1d, *tria);
2071 #ifndef DEAL_II_WITH_NETCDF 2075 const unsigned int dim = 2;
2076 const unsigned int spacedim = 2;
2100 const unsigned int coord = 1;
2106 const unsigned int x2d = 0;
2107 const unsigned int y2d = 2;
2116 NcFile nc(filename.c_str());
2120 NcDim *elements_dim = nc.get_dim(
"no_of_elements");
2122 const unsigned int n_cells = elements_dim->size();
2126 NcDim *marker_dim = nc.get_dim(
"no_of_markers");
2128 const unsigned int n_markers = marker_dim->size();
2130 NcVar *marker_var = nc.get_var(
"marker");
2133 AssertThrow(static_cast<unsigned int>(marker_var->get_dim(0)->size()) ==
2137 std::vector<int> marker(n_markers);
2140 marker_var->get(&*marker.begin(), n_markers);
2145 NcDim *bquads_dim = nc.get_dim(
"no_of_surfacequadrilaterals");
2147 const unsigned int n_bquads = bquads_dim->size();
2149 NcVar *bmarker_var = nc.get_var(
"boundarymarker_of_surfaces");
2152 AssertThrow(static_cast<unsigned int>(bmarker_var->get_dim(0)->size()) ==
2156 std::vector<int> bmarker(n_bquads);
2157 bmarker_var->get(&*bmarker.begin(), n_bquads);
2162 std::map<int, unsigned int> n_bquads_per_bmarker;
2163 for (
unsigned int i = 0; i < n_markers; ++i)
2167 AssertThrow(n_bquads_per_bmarker.find(marker[i]) ==
2168 n_bquads_per_bmarker.end(),
2171 n_bquads_per_bmarker[marker[i]] =
2172 count(bmarker.begin(), bmarker.end(), marker[i]);
2191 NcDim *quad_vertices_dim = nc.get_dim(
"points_per_surfacequadrilateral");
2193 const unsigned int vertices_per_quad = quad_vertices_dim->size();
2197 NcVar *vertex_indices_var = nc.get_var(
"points_of_surfacequadrilaterals");
2201 vertex_indices_var->get_dim(0)->size()) == n_bquads,
2204 vertex_indices_var->get_dim(1)->size()) == vertices_per_quad,
2207 std::vector<int> vertex_indices(n_bquads * vertices_per_quad);
2208 vertex_indices_var->get(&*vertex_indices.begin(),
2212 for (
const int idx : vertex_indices)
2219 NcDim *vertices_dim = nc.get_dim(
"no_of_points");
2221 const unsigned int n_vertices = vertices_dim->size();
2223 NcVar *points_xc = nc.get_var(
"points_xc");
2224 NcVar *points_yc = nc.get_var(
"points_yc");
2225 NcVar *points_zc = nc.get_var(
"points_zc");
2232 AssertThrow(points_yc->get_dim(0)->size() ==
static_cast<int>(n_vertices),
2234 AssertThrow(points_zc->get_dim(0)->size() ==
static_cast<int>(n_vertices),
2236 AssertThrow(points_xc->get_dim(0)->size() ==
static_cast<int>(n_vertices),
2238 std::vector<std::vector<double>> point_values(
2239 3, std::vector<double>(n_vertices));
2240 points_xc->get(point_values[0].data(), n_vertices);
2241 points_yc->get(point_values[1].data(), n_vertices);
2242 points_zc->get(point_values[2].data(), n_vertices);
2245 std::vector<Point<spacedim>> vertices(n_vertices);
2246 for (
unsigned int i = 0; i < n_vertices; ++i)
2248 vertices[i](0) = point_values[x2d][i];
2249 vertices[i](1) = point_values[y2d][i];
2255 std::map<int, bool> zero_plane_markers;
2256 for (
unsigned int quad = 0; quad < n_bquads; ++quad)
2258 bool zero_plane =
true;
2259 for (
unsigned int i = 0; i < vertices_per_quad; ++i)
2260 if (point_values[coord][vertex_indices[quad * vertices_per_quad + i]] !=
2268 zero_plane_markers[bmarker[quad]] =
true;
2270 unsigned int sum_of_zero_plane_cells = 0;
2271 for (std::map<int, bool>::const_iterator iter = zero_plane_markers.begin();
2272 iter != zero_plane_markers.end();
2274 sum_of_zero_plane_cells += n_bquads_per_bmarker[iter->first];
2280 std::vector<CellData<dim>> cells(n_cells);
2281 for (
unsigned int quad = 0, cell = 0; quad < n_bquads; ++quad)
2283 bool zero_plane =
false;
2284 for (std::map<int, bool>::const_iterator iter =
2285 zero_plane_markers.begin();
2286 iter != zero_plane_markers.end();
2288 if (bmarker[quad] == iter->first)
2296 for (
unsigned int i = 0; i < vertices_per_quad; ++i)
2300 [vertex_indices[quad * vertices_per_quad + i]] == 0,
2302 cells[cell].vertices[i] =
2303 vertex_indices[quad * vertices_per_quad + i];
2312 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
2321 #ifndef DEAL_II_WITH_NETCDF 2328 const unsigned int dim = 3;
2329 const unsigned int spacedim = 3;
2335 NcFile nc(filename.c_str());
2339 NcDim *elements_dim = nc.get_dim(
"no_of_elements");
2341 const unsigned int n_cells = elements_dim->size();
2343 NcDim *hexes_dim = nc.get_dim(
"no_of_hexaeders");
2345 const unsigned int n_hexes = hexes_dim->size();
2347 ExcMessage(
"deal.II can handle purely hexaedral grids, only."));
2353 NcDim *hex_vertices_dim = nc.get_dim(
"points_per_hexaeder");
2355 const unsigned int vertices_per_hex = hex_vertices_dim->size();
2359 NcVar *vertex_indices_var = nc.get_var(
"points_of_hexaeders");
2363 vertex_indices_var->get_dim(0)->size()) == n_cells,
2366 vertex_indices_var->get_dim(1)->size()) == vertices_per_hex,
2369 std::vector<int> vertex_indices(n_cells * vertices_per_hex);
2372 vertex_indices_var->get(&*vertex_indices.begin(), n_cells, vertices_per_hex);
2374 for (
const int idx : vertex_indices)
2381 NcDim *vertices_dim = nc.get_dim(
"no_of_points");
2383 const unsigned int n_vertices = vertices_dim->size();
2385 NcVar *points_xc = nc.get_var(
"points_xc");
2386 NcVar *points_yc = nc.get_var(
"points_yc");
2387 NcVar *points_zc = nc.get_var(
"points_zc");
2394 AssertThrow(points_yc->get_dim(0)->size() ==
static_cast<int>(n_vertices),
2396 AssertThrow(points_zc->get_dim(0)->size() ==
static_cast<int>(n_vertices),
2398 AssertThrow(points_xc->get_dim(0)->size() ==
static_cast<int>(n_vertices),
2400 std::vector<std::vector<double>> point_values(
2401 3, std::vector<double>(n_vertices));
2402 points_xc->get(point_values[0].data(), n_vertices);
2403 points_yc->get(point_values[1].data(), n_vertices);
2404 points_zc->get(point_values[2].data(), n_vertices);
2407 std::vector<Point<spacedim>> vertices(n_vertices);
2408 for (
unsigned int i = 0; i < n_vertices; ++i)
2410 vertices[i](0) = point_values[0][i];
2411 vertices[i](1) = point_values[1][i];
2412 vertices[i](2) = point_values[2][i];
2416 std::vector<CellData<dim>> cells(n_cells);
2417 for (
unsigned int cell = 0; cell < n_cells; ++cell)
2418 for (
unsigned int i = 0; i < vertices_per_hex; ++i)
2419 cells[cell].vertices[i] = vertex_indices[cell * vertices_per_hex + i];
2430 NcDim *quad_vertices_dim = nc.get_dim(
"points_per_surfacequadrilateral");
2432 const unsigned int vertices_per_quad = quad_vertices_dim->size();
2436 NcVar *bvertex_indices_var = nc.get_var(
"points_of_surfacequadrilaterals");
2439 const unsigned int n_bquads = bvertex_indices_var->get_dim(0)->size();
2441 bvertex_indices_var->get_dim(1)->size()) ==
2445 std::vector<int> bvertex_indices(n_bquads * vertices_per_quad);
2446 bvertex_indices_var->get(&*bvertex_indices.begin(),
2453 NcDim *bquads_dim = nc.get_dim(
"no_of_surfacequadrilaterals");
2455 AssertThrow(static_cast<unsigned int>(bquads_dim->size()) == n_bquads,
2458 NcVar *bmarker_var = nc.get_var(
"boundarymarker_of_surfaces");
2461 AssertThrow(static_cast<unsigned int>(bmarker_var->get_dim(0)->size()) ==
2465 std::vector<int> bmarker(n_bquads);
2466 bmarker_var->get(&*bmarker.begin(), n_bquads);
2472 for (
const int id : bmarker)
2474 Assert(0 <=
id && static_cast<types::boundary_id>(
id) !=
2484 for (
unsigned int i = 0; i < n_bquads; ++i)
2486 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_face; ++v)
2490 static_cast<types::boundary_id>(bmarker[i]);
2497 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
2502 template <
int dim,
int spacedim>
2505 std::string & header,
2506 std::vector<unsigned int> &tecplot2deal,
2507 unsigned int & n_vars,
2508 unsigned int & n_vertices,
2509 unsigned int & n_cells,
2510 std::vector<unsigned int> &IJK,
2524 DEAL_II_FALLTHROUGH;
2527 DEAL_II_FALLTHROUGH;
2535 std::transform(header.begin(), header.end(), header.begin(), ::toupper);
2539 std::replace(header.begin(), header.end(),
'\t',
' ');
2540 std::replace(header.begin(), header.end(),
',',
' ');
2541 std::replace(header.begin(), header.end(),
'\n',
' ');
2545 std::string::size_type pos = header.find(
'=');
2547 while (pos != static_cast<std::string::size_type>(std::string::npos))
2548 if (header[pos + 1] ==
' ')
2549 header.erase(pos + 1, 1);
2550 else if (header[pos - 1] ==
' ')
2552 header.erase(pos - 1, 1);
2556 pos = header.find(
'=', ++pos);
2559 std::vector<std::string> entries =
2563 for (
unsigned int i = 0; i < entries.size(); ++i)
2572 tecplot2deal[0] = 0;
2575 while (entries[i][0] ==
'"')
2577 if (entries[i] ==
"\"X\"")
2578 tecplot2deal[0] = n_vars;
2579 else if (entries[i] ==
"\"Y\"")
2585 tecplot2deal[1] = n_vars;
2587 else if (entries[i] ==
"\"Z\"")
2593 tecplot2deal[2] = n_vars;
2605 "Tecplot file must contain at least one variable for each dimension"));
2606 for (
unsigned int d = 1; d < dim; ++d)
2608 tecplot2deal[d] > 0,
2610 "Tecplot file must contain at least one variable for each dimension."));
2615 "ZONETYPE=FELINESEG") &&
2619 "ZONETYPE=FEQUADRILATERAL") &&
2623 "ZONETYPE=FEBRICK") &&
2631 "The tecplot file contains an unsupported ZONETYPE."));
2634 "DATAPACKING=POINT"))
2637 "DATAPACKING=BLOCK"))
2660 "ET=QUADRILATERAL") &&
2672 "The tecplot file contains an unsupported ElementType."));
2680 dim > 1 || IJK[1] == 1,
2682 "Parameter 'J=' found in tecplot, although this is only possible for dimensions greater than 1."));
2688 dim > 2 || IJK[2] == 1,
2690 "Parameter 'K=' found in tecplot, although this is only possible for dimensions greater than 2."));
2705 for (
unsigned int d = 0; d < dim; ++d)
2710 "Tecplot file does not contain a complete and consistent set of parameters"));
2711 n_vertices *= IJK[d];
2712 n_cells *= (IJK[d] - 1);
2720 "Tecplot file does not contain a complete and consistent set of parameters"));
2726 n_cells = *std::max_element(IJK.begin(), IJK.end());
2730 "Tecplot file does not contain a complete and consistent set of parameters"));
2740 const unsigned int dim = 2;
2741 const unsigned int spacedim = 2;
2746 skip_comment_lines(in,
'#');
2749 std::string line, header;
2756 std::string letters =
"abcdfghijklmnopqrstuvwxyzABCDFGHIJKLMNOPQRSTUVWXYZ";
2759 while (line.find_first_of(letters) != std::string::npos)
2761 header +=
" " + line;
2768 std::vector<unsigned int> tecplot2deal(dim);
2769 std::vector<unsigned int> IJK(dim);
2770 unsigned int n_vars, n_vertices, n_cells;
2771 bool structured, blocked;
2773 parse_tecplot_header(header,
2788 std::vector<Point<spacedim>> vertices(n_vertices + 1);
2791 std::vector<CellData<dim>> cells(n_cells);
2807 unsigned int next_index = 0;
2811 if (tecplot2deal[0] == 0)
2815 std::vector<std::string> first_var =
2818 for (
unsigned int i = 1; i < first_var.size() + 1; ++i)
2819 vertices[i](0) = std::strtod(first_var[i - 1].c_str(), &endptr);
2824 for (
unsigned int j = first_var.size() + 1; j < n_vertices + 1; ++j)
2825 in >> vertices[j](next_index);
2832 for (
unsigned int i = 1; i < n_vars; ++i)
2841 if (next_index == dim && structured)
2844 if ((next_index < dim) && (i == tecplot2deal[next_index]))
2847 for (
unsigned int j = 1; j < n_vertices + 1; ++j)
2848 in >> vertices[j](next_index);
2855 for (
unsigned int j = 1; j < n_vertices + 1; ++j)
2867 std::vector<double> vars(n_vars);
2872 std::vector<std::string> first_vertex =
2875 for (
unsigned int d = 0;
d < dim; ++
d)
2877 std::strtod(first_vertex[tecplot2deal[d]].c_str(), &endptr);
2881 for (
unsigned int v = 2; v < n_vertices + 1; ++v)
2883 for (
unsigned int i = 0; i < n_vars; ++i)
2889 for (
unsigned int i = 0; i < dim; ++i)
2890 vertices[v](i) = vars[tecplot2deal[i]];
2898 unsigned int I = IJK[0], J = IJK[1];
2900 unsigned int cell = 0;
2902 for (
unsigned int j = 0; j < J - 1; ++j)
2903 for (
unsigned int i = 1; i < I; ++i)
2905 cells[cell].vertices[0] = i + j * I;
2906 cells[cell].vertices[1] = i + 1 + j * I;
2907 cells[cell].vertices[2] = i + 1 + (j + 1) * I;
2908 cells[cell].vertices[3] = i + (j + 1) * I;
2912 std::vector<unsigned int> boundary_vertices(2 * I + 2 * J - 4);
2914 for (
unsigned int i = 1; i < I + 1; ++i)
2916 boundary_vertices[k] = i;
2918 boundary_vertices[k] = i + (J - 1) * I;
2921 for (
unsigned int j = 1; j < J - 1; ++j)
2923 boundary_vertices[k] = 1 + j * I;
2925 boundary_vertices[k] = I + j * I;
2944 for (
unsigned int i = 0; i < n_cells; ++i)
2955 for (
unsigned int &vertex : cells[i].vertices)
2972 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
2977 template <
int dim,
int spacedim>
2986 template <
int dim,
int spacedim>
2989 const unsigned int mesh_index,
2990 const bool remove_duplicates,
2992 const bool ignore_unsupported_types)
2994 #ifdef DEAL_II_WITH_ASSIMP 2999 Assimp::Importer importer;
3002 const aiScene *scene =
3003 importer.ReadFile(filename.c_str(),
3004 aiProcess_RemoveComponent |
3005 aiProcess_JoinIdenticalVertices |
3006 aiProcess_ImproveCacheLocality | aiProcess_SortByPType |
3007 aiProcess_OptimizeGraph | aiProcess_OptimizeMeshes);
3013 ExcMessage(
"Input file contains no meshes."));
3016 (mesh_index < scene->mNumMeshes),
3019 unsigned int start_mesh =
3021 unsigned int end_mesh =
3026 std::vector<Point<spacedim>> vertices;
3027 std::vector<CellData<dim>> cells;
3031 unsigned int v_offset = 0;
3032 unsigned int c_offset = 0;
3035 for (
unsigned int m = start_mesh; m < end_mesh; ++m)
3037 const aiMesh *mesh = scene->mMeshes[m];
3041 if ((dim == 2) && mesh->mPrimitiveTypes != aiPrimitiveType_POLYGON)
3044 ExcMessage(
"Incompatible mesh " + std::to_string(m) +
3045 "/" + std::to_string(scene->mNumMeshes)));
3048 else if ((dim == 1) && mesh->mPrimitiveTypes != aiPrimitiveType_LINE)
3051 ExcMessage(
"Incompatible mesh " + std::to_string(m) +
3052 "/" + std::to_string(scene->mNumMeshes)));
3056 const unsigned int n_vertices = mesh->mNumVertices;
3057 const aiVector3D * mVertices = mesh->mVertices;
3060 const unsigned int n_faces = mesh->mNumFaces;
3061 const aiFace * mFaces = mesh->mFaces;
3063 vertices.resize(v_offset + n_vertices);
3064 cells.resize(c_offset + n_faces);
3066 for (
unsigned int i = 0; i < n_vertices; ++i)
3067 for (
unsigned int d = 0; d < spacedim; ++d)
3068 vertices[i + v_offset][d] = mVertices[i][d];
3070 unsigned int valid_cell = c_offset;
3071 for (
unsigned int i = 0; i < n_faces; ++i)
3075 for (
unsigned int f = 0; f < GeometryInfo<dim>::vertices_per_cell;
3078 cells[valid_cell].vertices[f] =
3079 mFaces[i].mIndices[f] + v_offset;
3081 cells[valid_cell].material_id = m;
3087 ExcMessage(
"Face " + std::to_string(i) +
" of mesh " +
3088 std::to_string(m) +
" has " +
3089 std::to_string(mFaces[i].mNumIndices) +
3090 " vertices. We expected only " +
3095 cells.resize(valid_cell);
3100 v_offset += n_vertices;
3101 c_offset = valid_cell;
3105 if (cells.size() == 0)
3108 if (remove_duplicates)
3113 unsigned int n_verts = 0;
3114 while (n_verts != vertices.size())
3116 n_verts = vertices.size();
3117 std::vector<unsigned int> considered_vertices;
3119 vertices, cells, subcelldata, considered_vertices, tol);
3124 if (dim == spacedim)
3130 tria->create_triangulation_compatibility(vertices, cells, subcelldata);
3132 tria->create_triangulation(vertices, cells, subcelldata);
3136 (void)remove_duplicates;
3138 (void)ignore_unsupported_types;
3144 template <
int dim,
int spacedim>
3158 if (std::find_if(line.begin(),
3160 std::bind(std::not_equal_to<char>(),
3161 std::placeholders::_1,
3162 ' ')) != line.end())
3165 for (
int i = line.length() - 1; i >= 0; --i)
3166 in.putback(line[i]);
3176 template <
int dim,
int spacedim>
3179 const char comment_start)
3184 while (in.get(c) && c == comment_start)
3187 while (in.get() !=
'\n')
3197 skip_empty_lines(in);
3202 template <
int dim,
int spacedim>
3217 const std::vector<
Point<2>> & vertices,
3220 double min_x = vertices[cells[0].vertices[0]](0),
3221 max_x = vertices[cells[0].vertices[0]](0),
3222 min_y = vertices[cells[0].vertices[0]](1),
3223 max_y = vertices[cells[0].vertices[0]](1);
3225 for (
unsigned int i = 0; i < cells.size(); ++i)
3227 for (
const auto vertex : cells[i].vertices)
3229 const Point<2> &p = vertices[vertex];
3241 out <<
"# cell " << i << std::endl;
3243 for (
const auto vertex : cells[i].vertices)
3244 center += vertices[vertex];
3247 out <<
"set label \"" << i <<
"\" at " << center(0) <<
',' << center(1)
3248 <<
" center" << std::endl;
3251 for (
unsigned int f = 0; f < 2; ++f)
3252 out <<
"set arrow from " << vertices[cells[i].vertices[f]](0) <<
',' 3253 << vertices[cells[i].vertices[f]](1) <<
" to " 3254 << vertices[cells[i].vertices[(f + 1) % 4]](0) <<
',' 3255 << vertices[cells[i].vertices[(f + 1) % 4]](1) << std::endl;
3257 for (
unsigned int f = 2; f < 4; ++f)
3258 out <<
"set arrow from " << vertices[cells[i].vertices[(f + 1) % 4]](0)
3259 <<
',' << vertices[cells[i].vertices[(f + 1) % 4]](1) <<
" to " 3260 << vertices[cells[i].vertices[f]](0) <<
',' 3261 << vertices[cells[i].vertices[f]](1) << std::endl;
3267 <<
"set nokey" << std::endl
3268 <<
"pl [" << min_x <<
':' << max_x <<
"][" << min_y <<
':' << max_y
3269 <<
"] " << min_y << std::endl
3270 <<
"pause -1" << std::endl;
3278 const std::vector<
Point<3>> & vertices,
3281 for (
const auto &cell : cells)
3284 out << vertices[cell.vertices[0]] << std::endl
3285 << vertices[cell.vertices[1]] << std::endl
3289 out << vertices[cell.vertices[1]] << std::endl
3290 << vertices[cell.vertices[2]] << std::endl
3294 out << vertices[cell.vertices[3]] << std::endl
3295 << vertices[cell.vertices[2]] << std::endl
3299 out << vertices[cell.vertices[0]] << std::endl
3300 << vertices[cell.vertices[3]] << std::endl
3304 out << vertices[cell.vertices[4]] << std::endl
3305 << vertices[cell.vertices[5]] << std::endl
3309 out << vertices[cell.vertices[5]] << std::endl
3310 << vertices[cell.vertices[6]] << std::endl
3314 out << vertices[cell.vertices[7]] << std::endl
3315 << vertices[cell.vertices[6]] << std::endl
3319 out << vertices[cell.vertices[4]] << std::endl
3320 << vertices[cell.vertices[7]] << std::endl
3324 out << vertices[cell.vertices[0]] << std::endl
3325 << vertices[cell.vertices[4]] << std::endl
3329 out << vertices[cell.vertices[1]] << std::endl
3330 << vertices[cell.vertices[5]] << std::endl
3334 out << vertices[cell.vertices[2]] << std::endl
3335 << vertices[cell.vertices[6]] << std::endl
3339 out << vertices[cell.vertices[3]] << std::endl
3340 << vertices[cell.vertices[7]] << std::endl
3348 template <
int dim,
int spacedim>
3356 if (format == Default)
3357 name = search.
find(filename);
3359 name = search.
find(filename, default_suffix(format));
3361 std::ifstream in(name.c_str());
3363 if (format == Default)
3365 const std::string::size_type slashpos = name.find_last_of(
'/');
3366 const std::string::size_type dotpos = name.find_last_of(
'.');
3367 if (dotpos < name.length() &&
3368 (dotpos > slashpos || slashpos == std::string::npos))
3370 std::string ext = name.substr(dotpos + 1);
3371 format = parse_format(ext);
3374 if (format == netcdf)
3375 read_netcdf(filename);
3381 template <
int dim,
int spacedim>
3385 if (format == Default)
3386 format = default_format;
3420 ExcMessage(
"There is no read_netcdf(istream &) function. " 3421 "Use the read_netcdf(string &filename) " 3422 "functions, instead."));
3431 ExcMessage(
"There is no read_assimp(istream &) function. " 3432 "Use the read_assimp(string &filename, ...) " 3433 "functions, instead."));
3444 template <
int dim,
int spacedim>
3471 return ".unknown_format";
3477 template <
int dim,
int spacedim>
3481 if (format_name ==
"dbmesh")
3484 if (format_name ==
"msh")
3487 if (format_name ==
"unv")
3490 if (format_name ==
"vtk")
3494 if (format_name ==
"inp")
3497 if (format_name ==
"ucd")
3500 if (format_name ==
"xda")
3503 if (format_name ==
"netcdf")
3506 if (format_name ==
"nc")
3509 if (format_name ==
"tecplot")
3512 if (format_name ==
"dat")
3515 if (format_name ==
"plt")
3534 template <
int dim,
int spacedim>
3538 return "dbmesh|msh|unv|vtk|ucd|abaqus|xda|netcdf|tecplot|assimp";
3545 template <
int dim,
int spacedim>
3546 Abaqus_to_UCD<dim, spacedim>::Abaqus_to_UCD()
3559 from_string(T &t,
const std::string &s, std::ios_base &(*f)(std::ios_base &))
3561 std::istringstream iss(s);
3562 return !(iss >> f >> t).fail();
3569 extract_int(
const std::string &s)
3572 for (
const char c : s)
3581 from_string(number, tmp, std::dec);
3587 template <
int dim,
int spacedim>
3589 Abaqus_to_UCD<dim, spacedim>::read_in_abaqus(std::istream &input_stream)
3598 while (std::getline(input_stream, line))
3601 std::transform(line.begin(), line.end(), line.begin(), ::toupper);
3603 if (line.compare(
"*HEADING") == 0 || line.compare(0, 2,
"**") == 0 ||
3604 line.compare(0, 5,
"*PART") == 0)
3607 while (std::getline(input_stream, line))
3613 else if (line.compare(0, 5,
"*NODE") == 0)
3622 while (std::getline(input_stream, line))
3627 std::vector<double> node(spacedim + 1);
3629 std::istringstream iss(line);
3631 for (
unsigned int i = 0; i < spacedim + 1; ++i)
3632 iss >> node[i] >> comma;
3634 node_list.push_back(node);
3637 else if (line.compare(0, 8,
"*ELEMENT") == 0)
3652 const std::string before_material =
"ELSET=EB";
3653 const std::size_t idx = line.find(before_material);
3654 if (idx != std::string::npos)
3656 from_string(material,
3657 line.substr(idx + before_material.size()),
3663 while (std::getline(input_stream, line))
3668 std::istringstream iss(line);
3674 const unsigned int n_data_per_cell =
3676 std::vector<double> cell(n_data_per_cell);
3677 for (
unsigned int i = 0; i < n_data_per_cell; ++i)
3678 iss >> cell[i] >> comma;
3681 cell[0] =
static_cast<double>(material);
3682 cell_list.push_back(cell);
3685 else if (line.compare(0, 8,
"*SURFACE") == 0)
3696 const std::string name_key =
"NAME=";
3697 const std::size_t name_idx_start =
3698 line.find(name_key) + name_key.size();
3699 std::size_t name_idx_end = line.find(
',', name_idx_start);
3700 if (name_idx_end == std::string::npos)
3702 name_idx_end = line.size();
3704 const int b_indicator = extract_int(
3705 line.substr(name_idx_start, name_idx_end - name_idx_start));
3712 while (std::getline(input_stream, line))
3718 std::transform(line.begin(),
3726 std::istringstream iss(line);
3733 std::vector<double> quad_node_list;
3734 const std::string elset_name = line.substr(0, line.find(
','));
3735 if (elsets_list.count(elset_name) != 0)
3739 iss >> stmp >> temp >> face_number;
3741 const std::vector<int> cells = elsets_list[elset_name];
3742 for (
const int cell : cells)
3746 get_global_node_numbers(el_idx, face_number);
3747 quad_node_list.insert(quad_node_list.begin(),
3750 face_list.push_back(quad_node_list);
3757 iss >> el_idx >> comma >> temp >> face_number;
3759 get_global_node_numbers(el_idx, face_number);
3760 quad_node_list.insert(quad_node_list.begin(), b_indicator);
3762 face_list.push_back(quad_node_list);
3766 else if (line.compare(0, 6,
"*ELSET") == 0)
3770 std::string elset_name;
3772 const std::string elset_key =
"*ELSET, ELSET=";
3773 const std::size_t idx = line.find(elset_key);
3774 if (idx != std::string::npos)
3776 const std::string comma =
",";
3777 const std::size_t first_comma = line.find(comma);
3778 const std::size_t second_comma =
3779 line.find(comma, first_comma + 1);
3780 const std::size_t elset_name_start =
3781 line.find(elset_key) + elset_key.size();
3782 elset_name = line.substr(elset_name_start,
3783 second_comma - elset_name_start);
3793 std::vector<int> elements;
3794 const std::size_t generate_idx = line.find(
"GENERATE");
3795 if (generate_idx != std::string::npos)
3798 std::getline(input_stream, line);
3799 std::istringstream iss(line);
3808 iss >> elid_start >> comma >> elid_end;
3812 "While reading an ABAQUS file, the reader " 3813 "expected a comma but found a <") +
3814 comma +
"> in the line <" + line +
">."));
3816 elid_start <= elid_end,
3819 "While reading an ABAQUS file, the reader encountered " 3820 "a GENERATE statement in which the upper bound <") +
3822 "> for the element numbers is not larger or equal " 3823 "than the lower bound <" +
3827 if (iss.rdbuf()->in_avail() != 0)
3828 iss >> comma >> elis_step;
3832 "While reading an ABAQUS file, the reader " 3833 "expected a comma but found a <") +
3834 comma +
"> in the line <" + line +
">."));
3836 for (
int i = elid_start; i <= elid_end; i += elis_step)
3837 elements.push_back(i);
3838 elsets_list[elset_name] = elements;
3840 std::getline(input_stream, line);
3845 while (std::getline(input_stream, line))
3850 std::istringstream iss(line);
3855 iss >> elid >> comma;
3860 "While reading an ABAQUS file, the reader " 3861 "expected a comma but found a <") +
3862 comma +
"> in the line <" + line +
">."));
3864 elements.push_back(elid);
3868 elsets_list[elset_name] = elements;
3873 else if (line.compare(0, 5,
"*NSET") == 0)
3876 while (std::getline(input_stream, line))
3882 else if (line.compare(0, 14,
"*SOLID SECTION") == 0)
3885 const std::string elset_key =
"ELSET=";
3886 const std::size_t elset_start =
3887 line.find(
"ELSET=") + elset_key.size();
3888 const std::size_t elset_end = line.find(
',', elset_start + 1);
3889 const std::string elset_name =
3890 line.substr(elset_start, elset_end - elset_start);
3895 const std::string material_key =
"MATERIAL=";
3896 const std::size_t last_equal =
3897 line.find(
"MATERIAL=") + material_key.size();
3898 const std::size_t material_id_start = line.find(
'-', last_equal);
3900 from_string(material_id,
3901 line.substr(material_id_start + 1),
3905 const std::vector<int> &elset_cells = elsets_list[elset_name];
3906 for (
const int elset_cell : elset_cells)
3908 const int cell_id = elset_cell - 1;
3916 template <
int dim,
int spacedim>
3918 Abaqus_to_UCD<dim, spacedim>::get_global_node_numbers(
3919 const int face_cell_no,
3920 const int face_cell_face_no)
const 3930 if (face_cell_face_no == 1)
3932 quad_node_list[0] = cell_list[face_cell_no - 1][1];
3933 quad_node_list[1] = cell_list[face_cell_no - 1][2];
3935 else if (face_cell_face_no == 2)
3937 quad_node_list[0] = cell_list[face_cell_no - 1][2];
3938 quad_node_list[1] = cell_list[face_cell_no - 1][3];
3940 else if (face_cell_face_no == 3)
3942 quad_node_list[0] = cell_list[face_cell_no - 1][3];
3943 quad_node_list[1] = cell_list[face_cell_no - 1][4];
3945 else if (face_cell_face_no == 4)
3947 quad_node_list[0] = cell_list[face_cell_no - 1][4];
3948 quad_node_list[1] = cell_list[face_cell_no - 1][1];
3958 if (face_cell_face_no == 1)
3960 quad_node_list[0] = cell_list[face_cell_no - 1][1];
3961 quad_node_list[1] = cell_list[face_cell_no - 1][4];
3962 quad_node_list[2] = cell_list[face_cell_no - 1][3];
3963 quad_node_list[3] = cell_list[face_cell_no - 1][2];
3965 else if (face_cell_face_no == 2)
3967 quad_node_list[0] = cell_list[face_cell_no - 1][5];
3968 quad_node_list[1] = cell_list[face_cell_no - 1][8];
3969 quad_node_list[2] = cell_list[face_cell_no - 1][7];
3970 quad_node_list[3] = cell_list[face_cell_no - 1][6];
3972 else if (face_cell_face_no == 3)
3974 quad_node_list[0] = cell_list[face_cell_no - 1][1];
3975 quad_node_list[1] = cell_list[face_cell_no - 1][2];
3976 quad_node_list[2] = cell_list[face_cell_no - 1][6];
3977 quad_node_list[3] = cell_list[face_cell_no - 1][5];
3979 else if (face_cell_face_no == 4)
3981 quad_node_list[0] = cell_list[face_cell_no - 1][2];
3982 quad_node_list[1] = cell_list[face_cell_no - 1][3];
3983 quad_node_list[2] = cell_list[face_cell_no - 1][7];
3984 quad_node_list[3] = cell_list[face_cell_no - 1][6];
3986 else if (face_cell_face_no == 5)
3988 quad_node_list[0] = cell_list[face_cell_no - 1][3];
3989 quad_node_list[1] = cell_list[face_cell_no - 1][4];
3990 quad_node_list[2] = cell_list[face_cell_no - 1][8];
3991 quad_node_list[3] = cell_list[face_cell_no - 1][7];
3993 else if (face_cell_face_no == 6)
3995 quad_node_list[0] = cell_list[face_cell_no - 1][1];
3996 quad_node_list[1] = cell_list[face_cell_no - 1][5];
3997 quad_node_list[2] = cell_list[face_cell_no - 1][8];
3998 quad_node_list[3] = cell_list[face_cell_no - 1][4];
4011 return quad_node_list;
4014 template <
int dim,
int spacedim>
4016 Abaqus_to_UCD<dim, spacedim>::write_out_avs_ucd(std::ostream &output)
const 4025 const boost::io::ios_base_all_saver formatting_saver(output);
4029 output <<
"# Abaqus to UCD mesh conversion" << std::endl;
4030 output <<
"# Mesh type: AVS UCD" << std::endl;
4055 output << node_list.size() <<
"\t" << (cell_list.size() + face_list.size())
4056 <<
"\t0\t0\t0" << std::endl;
4059 output.precision(8);
4063 for (
unsigned int ii = 0; ii < node_list.size(); ++ii)
4066 output << node_list[ii][0] <<
"\t";
4069 output.setf(std::ios::scientific, std::ios::floatfield);
4070 for (
unsigned int jj = 1; jj < spacedim + 1; ++jj)
4073 if (std::abs(node_list[ii][jj]) > tolerance)
4074 output << static_cast<double>(node_list[ii][jj]) <<
"\t";
4076 output << 0.0 <<
"\t";
4079 output << 0.0 <<
"\t";
4081 output << std::endl;
4082 output.unsetf(std::ios::floatfield);
4086 for (
unsigned int ii = 0; ii < cell_list.size(); ++ii)
4088 output << ii + 1 <<
"\t" << cell_list[ii][0] <<
"\t" 4089 << (dim == 2 ?
"quad" :
"hex") <<
"\t";
4090 for (
unsigned int jj = 1; jj < GeometryInfo<dim>::vertices_per_cell + 1;
4092 output << cell_list[ii][jj] <<
"\t";
4094 output << std::endl;
4098 for (
unsigned int ii = 0; ii < face_list.size(); ++ii)
4100 output << ii + 1 <<
"\t" << face_list[ii][0] <<
"\t" 4101 << (dim == 2 ?
"line" :
"quad") <<
"\t";
4102 for (
unsigned int jj = 1; jj < GeometryInfo<dim>::vertices_per_face + 1;
4104 output << face_list[ii][jj] <<
"\t";
4106 output << std::endl;
4113 #include "grid_in.inst" 4115 DEAL_II_NAMESPACE_CLOSE
std::vector< CellData< 1 > > boundary_lines
static std::string get_format_names()
static void reorder_cells(std::vector< CellData< dim >> &original_cells, const bool use_new_style_ordering=false)
const types::manifold_id flat_manifold_id
static const unsigned int invalid_unsigned_int
static ::ExceptionBase & ExcNoTriangulationSelected()
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcIO()
std::pair< int, unsigned int > get_integer_at_position(const std::string &name, const unsigned int position)
std::vector< std::string > break_text_into_lines(const std::string &original_text, const unsigned int width, const char delimiter=' ')
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcInvalidVertexIndex(int arg1, int arg2, int arg3)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
static Format parse_format(const std::string &format_name)
static void skip_empty_lines(std::istream &in)
void read_vtk(std::istream &in)
void read_dbmesh(std::istream &in)
void read_tecplot(std::istream &in)
static ::ExceptionBase & ExcInvalidState()
static ::ExceptionBase & ExcMessage(std::string arg1)
bool check_consistency(const unsigned int dim) const
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static void parse_tecplot_header(std::string &header, std::vector< unsigned int > &tecplot2deal, unsigned int &n_vars, unsigned int &n_vertices, unsigned int &n_cells, std::vector< unsigned int > &IJK, bool &structured, bool &blocked)
static ::ExceptionBase & ExcNeedsNetCDF()
#define Assert(cond, exc)
static void skip_comment_lines(std::istream &in, const char comment_start)
bool match_at_string_start(const std::string &name, const std::string &pattern)
void read_ucd(std::istream &in, const bool apply_all_indicators_to_manifolds=false)
static ::ExceptionBase & ExcNeedsAssimp()
static void debug_output_grid(const std::vector< CellData< dim >> &cells, const std::vector< Point< spacedim >> &vertices, std::ostream &out)
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
std::string find(const std::string &filename, const char *open_mode="r")
void read_xda(std::istream &in)
void read_msh(std::istream &in)
std::vector< CellData< 2 > > boundary_quads
void read_netcdf(const std::string &filename)
static std::string default_suffix(const Format format)
void read_unv(std::istream &in)
void read(std::istream &in, Format format=Default)
static ::ExceptionBase & ExcNotImplemented()
static void invert_all_cells_of_negative_grid(const std::vector< Point< spacedim >> &all_vertices, std::vector< CellData< dim >> &original_cells)
const types::boundary_id internal_face_boundary_id
void read_assimp(const std::string &filename, const unsigned int mesh_index=numbers::invalid_unsigned_int, const bool remove_duplicates=true, const double tol=1e-12, const bool ignore_unsupported_element_types=true)
void read_abaqus(std::istream &in, const bool apply_all_indicators_to_manifolds=false)
const types::material_id invalid_material_id
void attach_triangulation(Triangulation< dim, spacedim > &tria)
static ::ExceptionBase & ExcInternalError()