27#include <boost/archive/binary_iarchive.hpp>
28#include <boost/io/ios_state.hpp>
29#include <boost/property_tree/ptree.hpp>
30#include <boost/property_tree/xml_parser.hpp>
31#include <boost/serialization/serialization.hpp>
33#ifdef DEAL_II_GMSH_WITH_API
43#ifdef DEAL_II_WITH_ASSIMP
44# include <assimp/Importer.hpp>
45# include <assimp/postprocess.h>
46# include <assimp/scene.h>
49#ifdef DEAL_II_TRILINOS_WITH_SEACAS
67 template <
int spacedim>
69 assign_1d_boundary_ids(
70 const std::map<unsigned int, types::boundary_id> &boundary_ids,
73 if (boundary_ids.size() > 0)
74 for (
const auto &cell :
triangulation.active_cell_iterators())
76 if (boundary_ids.find(cell->vertex_index(f)) != boundary_ids.end())
81 "You are trying to prescribe boundary ids on the face "
82 "of a 1d cell (i.e., on a vertex), but this face is not actually at "
83 "the boundary of the mesh. This is not allowed."));
84 cell->face(f)->set_boundary_id(
85 boundary_ids.find(cell->vertex_index(f))->second);
90 template <
int dim,
int spacedim>
92 assign_1d_boundary_ids(
const std::map<unsigned int, types::boundary_id> &,
101template <
int dim,
int spacedim>
103 : tria(nullptr, typeid(*this).name())
109template <
int dim,
int spacedim>
111 : tria(&t, typeid(*this).name())
117template <
int dim,
int spacedim>
126template <
int dim,
int spacedim>
138 text[0] =
"# vtk DataFile Version 3.0";
141 text[3] =
"DATASET UNSTRUCTURED_GRID";
143 for (
unsigned int i = 0; i < 4; ++i)
148 line.compare(text[i]) == 0,
151 "While reading VTK file, failed to find a header line with text <") +
158 std::vector<Point<spacedim>>
vertices;
159 std::vector<CellData<dim>> cells;
168 if (keyword ==
"POINTS")
170 unsigned int n_vertices;
175 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
179 in >> x(0) >> x(1) >> x(2);
182 for (
unsigned int d = 0;
d < spacedim; ++
d)
190 "While reading VTK file, failed to find POINTS section"));
194 unsigned int n_geometric_objects = 0;
197 bool is_quad_or_hex_mesh =
false;
198 bool is_tria_or_tet_mesh =
false;
200 if (keyword ==
"CELLS")
203 std::vector<unsigned int> cell_types;
205 std::streampos oldpos = in.tellg();
208 while (in >> keyword)
209 if (keyword ==
"CELL_TYPES")
213 cell_types.resize(n_ints);
215 for (
unsigned int i = 0; i < n_ints; ++i)
224 in >> n_geometric_objects;
229 for (
unsigned int count = 0; count < n_geometric_objects; count++)
231 unsigned int n_vertices;
235 if (cell_types[count] == 10 || cell_types[count] == 12)
237 if (cell_types[count] == 10)
238 is_tria_or_tet_mesh =
true;
239 if (cell_types[count] == 12)
240 is_quad_or_hex_mesh =
true;
248 cells.emplace_back(n_vertices);
250 for (
unsigned int j = 0; j < n_vertices;
252 in >> cells.back().vertices[j];
256 if (cell_types[count] == 12)
259 cells.back().vertices[3]);
261 cells.back().vertices[7]);
264 cells.back().material_id = 0;
267 else if (cell_types[count] == 5 || cell_types[count] == 9)
269 if (cell_types[count] == 5)
270 is_tria_or_tet_mesh =
true;
271 if (cell_types[count] == 9)
272 is_quad_or_hex_mesh =
true;
281 for (
unsigned int j = 0; j < n_vertices;
288 else if (cell_types[count] == 3)
292 for (
unsigned int j = 0; j < n_vertices;
303 "While reading VTK file, unknown cell type encountered"));
308 for (
unsigned int count = 0; count < n_geometric_objects; count++)
310 unsigned int n_vertices;
314 if (cell_types[count] == 5 || cell_types[count] == 9)
321 if (cell_types[count] == 5)
322 is_tria_or_tet_mesh =
true;
323 if (cell_types[count] == 9)
324 is_quad_or_hex_mesh =
true;
326 cells.emplace_back(n_vertices);
328 for (
unsigned int j = 0; j < n_vertices;
330 in >> cells.back().vertices[j];
334 if (cell_types[count] == 9)
339 cells.back().vertices[3]);
342 cells.back().material_id = 0;
345 else if (cell_types[count] == 3)
351 for (
unsigned int j = 0; j < n_vertices;
364 "While reading VTK file, unknown cell type encountered"));
369 for (
unsigned int count = 0; count < n_geometric_objects; count++)
375 cell_types[count] == 3 && type == 2,
377 "While reading VTK file, unknown cell type encountered"));
378 cells.emplace_back(type);
380 for (
unsigned int j = 0; j < type; j++)
381 in >> cells.back().vertices[j];
383 cells.back().material_id = 0;
389 "While reading VTK file, failed to find CELLS section"));
397 keyword ==
"CELL_TYPES",
399 "While reading VTK file, missing CELL_TYPES section. Found <" +
400 keyword +
"> instead.")));
404 n_ints == n_geometric_objects,
405 ExcMessage(
"The VTK reader found a CELL_DATA statement "
406 "that lists a total of " +
408 " cell data objects, but this needs to "
409 "equal the number of cells (which is " +
411 ") plus the number of quads (" +
413 " in 3d or the number of lines (" +
418 for (
unsigned int i = 0; i < n_ints; ++i)
422 while (in >> keyword)
423 if (keyword ==
"CELL_DATA")
429 ExcMessage(
"The VTK reader found a CELL_DATA statement "
430 "that lists a total of " +
432 " cell data objects, but this needs to "
433 "equal the number of cells (which is " +
435 ") plus the number of quads (" +
438 " in 3d or the number of lines (" +
443 const std::vector<std::string> data_sets{
"MaterialID",
446 for (
unsigned int i = 0; i < data_sets.size(); ++i)
449 while (in >> keyword)
450 if (keyword ==
"SCALARS")
455 std::string field_name;
457 if (std::find(data_sets.begin(),
459 field_name) == data_sets.end())
471 std::getline(in, line);
474 std::min(
static_cast<std::size_t
>(3),
475 line.size() - 1)) ==
"int",
477 "While reading VTK file, material- and manifold IDs can only have type 'int'."));
481 keyword ==
"LOOKUP_TABLE",
483 "While reading VTK file, missing keyword 'LOOKUP_TABLE'."));
487 keyword ==
"default",
489 "While reading VTK file, missing keyword 'default'."));
496 for (
unsigned int i = 0; i < cells.size(); i++)
500 if (field_name ==
"MaterialID")
501 cells[i].material_id =
503 else if (field_name ==
"ManifoldID")
504 cells[i].manifold_id =
516 if (field_name ==
"MaterialID")
517 boundary_quad.material_id =
519 else if (field_name ==
"ManifoldID")
520 boundary_quad.manifold_id =
529 if (field_name ==
"MaterialID")
530 boundary_line.material_id =
532 else if (field_name ==
"ManifoldID")
533 boundary_line.manifold_id =
545 if (field_name ==
"MaterialID")
546 boundary_line.material_id =
548 else if (field_name ==
"ManifoldID")
549 boundary_line.manifold_id =
567 if (dim == 1 || (is_quad_or_hex_mesh && !is_tria_or_tet_mesh))
575 tria->create_triangulation(
vertices, cells, subcelldata);
580 tria->create_triangulation(
vertices, cells, subcelldata);
586 "While reading VTK file, failed to find CELLS section"));
591template <
int dim,
int spacedim>
595 namespace pt = boost::property_tree;
597 pt::read_xml(in, tree);
598 auto section = tree.get_optional<std::string>(
"VTKFile.dealiiData");
602 "While reading a VTU file, failed to find dealiiData section. "
603 "Notice that we can only read grid files in .vtu format that "
604 "were created by the deal.II library, using a call to "
605 "GridOut::write_vtu(), where the flag "
606 "GridOutFlags::Vtu::serialize_triangulation is set to true."));
610 const auto string_archive =
612 std::istringstream in_stream(string_archive);
613 boost::archive::binary_iarchive ia(in_stream);
618template <
int dim,
int spacedim>
626 skip_comment_lines(in,
'#');
637 AssertThrow(tmp == 2411, ExcUnknownSectionType(tmp));
639 std::vector<Point<spacedim>>
vertices;
658 in >> dummy >> dummy >> dummy;
661 in >> x[0] >> x[1] >> x[2];
665 for (
unsigned int d = 0;
d < spacedim;
d++)
680 AssertThrow(tmp == 2412, ExcUnknownSectionType(tmp));
682 std::vector<CellData<dim>> cells;
709 in >> type >> dummy >> dummy >> dummy >> dummy;
711 AssertThrow((type == 11) || (type == 44) || (type == 94) || (type == 115),
712 ExcUnknownElementType(type));
714 if ((((type == 44) || (type == 94)) && (dim == 2)) ||
715 ((type == 115) && (dim == 3)))
718 cells.emplace_back();
725 cells.back().material_id = 0;
728 cells.back().vertices[v] =
vertex_indices[cells.back().vertices[v]];
730 cell_indices[no] = no_cell;
734 else if (((type == 11) && (dim == 2)) ||
735 ((type == 11) && (dim == 3)))
738 in >> dummy >> dummy >> dummy;
743 for (
unsigned int &vertex :
749 for (
unsigned int &vertex :
753 line_indices[no] = no_line;
757 else if (((type == 44) || (type == 94)) && (dim == 3))
772 for (
unsigned int &vertex :
776 quad_indices[no] = no_quad;
784 "> when running in dim=" +
803 AssertThrow((tmp == 2467) || (tmp == 2477), ExcUnknownSectionType(tmp));
819 in >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >>
825 const unsigned int n_lines =
826 (n_entities % 2 == 0) ? (n_entities / 2) : ((n_entities + 1) / 2);
828 for (
unsigned int line = 0; line < n_lines; line++)
830 unsigned int n_fragments;
832 if (line == n_lines - 1)
833 n_fragments = (n_entities % 2 == 0) ? (2) : (1);
837 for (
unsigned int no_fragment = 0; no_fragment < n_fragments;
841 in >> dummy >> no >> dummy >> dummy;
843 if (cell_indices.count(no) > 0)
844 cells[cell_indices[no]].material_id = id;
846 if (line_indices.count(no) > 0)
850 if (quad_indices.count(no) > 0)
867 tria->create_triangulation(
vertices, cells, subcelldata);
872template <
int dim,
int spacedim>
875 const bool apply_all_indicators_to_manifolds)
881 skip_comment_lines(in,
'#');
884 unsigned int n_vertices;
888 in >> n_vertices >>
n_cells >> dummy
894 std::vector<Point<spacedim>>
vertices(n_vertices);
900 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
907 in >> vertex_number >> x[0] >> x[1] >> x[2];
910 for (
unsigned int d = 0;
d < spacedim; ++
d)
919 std::vector<CellData<dim>> cells;
922 for (
unsigned int cell = 0; cell <
n_cells; ++cell)
931 std::string cell_type;
941 if (((cell_type ==
"line") && (dim == 1)) ||
942 ((cell_type ==
"quad") && (dim == 2)) ||
943 ((cell_type ==
"hex") && (dim == 3)))
947 cells.emplace_back();
960 if (apply_all_indicators_to_manifolds)
961 cells.back().manifold_id =
971 cells.back().vertices[i] =
978 cells.back().vertices[i]));
983 else if ((cell_type ==
"line") && ((dim == 2) || (dim == 3)))
1003 if (apply_all_indicators_to_manifolds)
1020 for (
unsigned int &vertex :
1032 else if ((cell_type ==
"quad") && (dim == 3))
1053 if (apply_all_indicators_to_manifolds)
1070 for (
unsigned int &vertex :
1084 AssertThrow(
false, ExcUnknownIdentifier(cell_type));
1096 if (dim == spacedim)
1099 tria->create_triangulation(
vertices, cells, subcelldata);
1104 template <
int dim,
int spacedim>
1111 read_in_abaqus(std::istream &in);
1113 write_out_avs_ucd(std::ostream &out)
const;
1116 const double tolerance;
1119 get_global_node_numbers(
const int face_cell_no,
1120 const int face_cell_face_no)
const;
1123 std::vector<std::vector<double>> node_list;
1126 std::vector<std::vector<double>> cell_list;
1128 std::vector<std::vector<double>> face_list;
1131 std::map<std::string, std::vector<int>> elsets_list;
1135template <
int dim,
int spacedim>
1138 const bool apply_all_indicators_to_manifolds)
1145 Assert((spacedim == 2 && dim == spacedim) ||
1146 (spacedim == 3 && (dim == spacedim || dim == spacedim - 1)),
1152 Abaqus_to_UCD<dim, spacedim> abaqus_to_ucd;
1153 abaqus_to_ucd.read_in_abaqus(in);
1155 std::stringstream in_ucd;
1156 abaqus_to_ucd.write_out_avs_ucd(in_ucd);
1164 read_ucd(in_ucd, apply_all_indicators_to_manifolds);
1166 catch (std::exception &exc)
1168 std::cerr <<
"Exception on processing internal UCD data: " << std::endl
1169 << exc.what() << std::endl;
1174 "Internal conversion from ABAQUS file to UCD format was unsuccessful. "
1175 "More information is provided in an error message printed above. "
1176 "Are you sure that your ABAQUS mesh file conforms with the requirements "
1177 "listed in the documentation?"));
1184 "Internal conversion from ABAQUS file to UCD format was unsuccessful. "
1185 "Are you sure that your ABAQUS mesh file conforms with the requirements "
1186 "listed in the documentation?"));
1191template <
int dim,
int spacedim>
1201 skip_comment_lines(in,
'#');
1207 AssertThrow(line ==
"MeshVersionFormatted 0", ExcInvalidDBMESHInput(line));
1209 skip_empty_lines(in);
1213 AssertThrow(line ==
"Dimension", ExcInvalidDBMESHInput(line));
1214 unsigned int dimension;
1216 AssertThrow(dimension == dim, ExcDBMESHWrongDimension(dimension));
1217 skip_empty_lines(in);
1230 while (getline(in, line), line.find(
"# END") == std::string::npos)
1232 skip_empty_lines(in);
1237 AssertThrow(line ==
"Vertices", ExcInvalidDBMESHInput(line));
1239 unsigned int n_vertices;
1243 std::vector<Point<spacedim>>
vertices(n_vertices);
1244 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
1247 for (
unsigned int d = 0;
d < dim; ++
d)
1254 skip_empty_lines(in);
1260 AssertThrow(line ==
"Edges", ExcInvalidDBMESHInput(line));
1262 unsigned int n_edges;
1264 for (
unsigned int edge = 0; edge < n_edges; ++edge)
1267 in >> dummy >> dummy;
1273 skip_empty_lines(in);
1282 AssertThrow(line ==
"CrackedEdges", ExcInvalidDBMESHInput(line));
1285 for (
unsigned int edge = 0; edge < n_edges; ++edge)
1288 in >> dummy >> dummy;
1294 skip_empty_lines(in);
1300 AssertThrow(line ==
"Quadrilaterals", ExcInvalidDBMESHInput(line));
1302 std::vector<CellData<dim>> cells;
1306 for (
unsigned int cell = 0; cell <
n_cells; ++cell)
1310 cells.emplace_back();
1316 (
static_cast<unsigned int>(cells.back().vertices[i]) <=
1320 --cells.back().vertices[i];
1328 skip_empty_lines(in);
1336 while (getline(in, line), ((line.find(
"End") == std::string::npos) && (in)))
1352 tria->create_triangulation(
vertices, cells, subcelldata);
1357template <
int dim,
int spacedim>
1364 const auto reference_cell = ReferenceCells::get_hypercube<dim>();
1368 std::getline(in, line);
1370 unsigned int n_vertices;
1375 std::getline(in, line);
1378 std::getline(in, line);
1381 for (
unsigned int i = 0; i < 8; ++i)
1382 std::getline(in, line);
1385 std::vector<CellData<dim>> cells(
n_cells);
1396 for (
unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_cell; i++)
1397 in >> cell.vertices[
reference_cell.exodusii_vertex_to_deal_vertex(i)];
1401 std::vector<Point<spacedim>>
vertices(n_vertices);
1404 for (
unsigned int d = 0;
d < spacedim; ++
d)
1406 for (
unsigned int d = spacedim;
d < 3; ++
d)
1420 tria->create_triangulation(
vertices, cells, subcelldata);
1425template <
int dim,
int spacedim>
1432 unsigned int n_vertices;
1439 std::array<std::map<int, int>, 4> tag_maps;
1444 unsigned int gmsh_file_format = 0;
1445 if (line ==
"@f$NOD")
1446 gmsh_file_format = 10;
1447 else if (line ==
"@f$MeshFormat")
1448 gmsh_file_format = 20;
1454 if (gmsh_file_format == 20)
1457 unsigned int file_type, data_size;
1459 in >> version >> file_type >> data_size;
1462 gmsh_file_format =
static_cast<unsigned int>(version * 10);
1470 AssertThrow(line ==
"@f$EndMeshFormat", ExcInvalidGMSHInput(line));
1474 if (line ==
"@f$PhysicalNames")
1480 while (line !=
"@f$EndPhysicalNames");
1485 if (line ==
"@f$Entities")
1487 unsigned long n_points, n_curves, n_surfaces, n_volumes;
1489 in >> n_points >> n_curves >> n_surfaces >> n_volumes;
1490 for (
unsigned int i = 0; i < n_points; ++i)
1494 unsigned int n_physicals;
1495 double box_min_x, box_min_y, box_min_z, box_max_x, box_max_y,
1499 if (gmsh_file_format > 40)
1501 in >> tag >> box_min_x >> box_min_y >> box_min_z >>
1503 box_max_x = box_min_x;
1504 box_max_y = box_min_y;
1505 box_max_z = box_min_z;
1509 in >> tag >> box_min_x >> box_min_y >> box_min_z >>
1510 box_max_x >> box_max_y >> box_max_z >> n_physicals;
1514 ExcMessage(
"More than one tag is not supported!"));
1516 int physical_tag = 0;
1517 for (
unsigned int j = 0; j < n_physicals; ++j)
1519 tag_maps[0][tag] = physical_tag;
1521 for (
unsigned int i = 0; i < n_curves; ++i)
1525 unsigned int n_physicals;
1526 double box_min_x, box_min_y, box_min_z, box_max_x, box_max_y,
1530 in >> tag >> box_min_x >> box_min_y >> box_min_z >> box_max_x >>
1531 box_max_y >> box_max_z >> n_physicals;
1534 ExcMessage(
"More than one tag is not supported!"));
1536 int physical_tag = 0;
1537 for (
unsigned int j = 0; j < n_physicals; ++j)
1539 tag_maps[1][tag] = physical_tag;
1543 for (
unsigned int j = 0; j < n_points; ++j)
1547 for (
unsigned int i = 0; i < n_surfaces; ++i)
1551 unsigned int n_physicals;
1552 double box_min_x, box_min_y, box_min_z, box_max_x, box_max_y,
1556 in >> tag >> box_min_x >> box_min_y >> box_min_z >> box_max_x >>
1557 box_max_y >> box_max_z >> n_physicals;
1560 ExcMessage(
"More than one tag is not supported!"));
1562 int physical_tag = 0;
1563 for (
unsigned int j = 0; j < n_physicals; ++j)
1565 tag_maps[2][tag] = physical_tag;
1569 for (
unsigned int j = 0; j < n_curves; ++j)
1572 for (
unsigned int i = 0; i < n_volumes; ++i)
1576 unsigned int n_physicals;
1577 double box_min_x, box_min_y, box_min_z, box_max_x, box_max_y,
1581 in >> tag >> box_min_x >> box_min_y >> box_min_z >> box_max_x >>
1582 box_max_y >> box_max_z >> n_physicals;
1585 ExcMessage(
"More than one tag is not supported!"));
1587 int physical_tag = 0;
1588 for (
unsigned int j = 0; j < n_physicals; ++j)
1590 tag_maps[3][tag] = physical_tag;
1594 for (
unsigned int j = 0; j < n_surfaces; ++j)
1598 AssertThrow(line ==
"@f$EndEntities", ExcInvalidGMSHInput(line));
1603 if (line ==
"@f$PartitionedEntities")
1609 while (line !=
"@f$EndPartitionedEntities");
1616 AssertThrow(line ==
"@f$Nodes", ExcInvalidGMSHInput(line));
1620 int n_entity_blocks = 1;
1621 if (gmsh_file_format > 40)
1625 in >> n_entity_blocks >> n_vertices >> min_node_tag >> max_node_tag;
1627 else if (gmsh_file_format == 40)
1629 in >> n_entity_blocks >> n_vertices;
1633 std::vector<Point<spacedim>>
vertices(n_vertices);
1640 unsigned int global_vertex = 0;
1641 for (
int entity_block = 0; entity_block < n_entity_blocks; ++entity_block)
1644 unsigned long numNodes;
1646 if (gmsh_file_format < 40)
1648 numNodes = n_vertices;
1655 int tagEntity, dimEntity;
1656 in >> tagEntity >> dimEntity >> parametric >> numNodes;
1659 std::vector<int> vertex_numbers;
1661 if (gmsh_file_format > 40)
1662 for (
unsigned long vertex_per_entity = 0;
1663 vertex_per_entity < numNodes;
1664 ++vertex_per_entity)
1666 in >> vertex_number;
1667 vertex_numbers.push_back(vertex_number);
1670 for (
unsigned long vertex_per_entity = 0; vertex_per_entity < numNodes;
1671 ++vertex_per_entity, ++global_vertex)
1677 if (gmsh_file_format > 40)
1679 vertex_number = vertex_numbers[vertex_per_entity];
1680 in >> x[0] >> x[1] >> x[2];
1683 in >> vertex_number >> x[0] >> x[1] >> x[2];
1685 for (
unsigned int d = 0;
d < spacedim; ++
d)
1691 if (parametric != 0)
1706 static const std::string end_nodes_marker[] = {
"@f$ENDNOD",
"@f$EndNodes"};
1707 AssertThrow(line == end_nodes_marker[gmsh_file_format == 10 ? 0 : 1],
1708 ExcInvalidGMSHInput(line));
1712 static const std::string begin_elements_marker[] = {
"@f$ELM",
"@f$Elements"};
1713 AssertThrow(line == begin_elements_marker[gmsh_file_format == 10 ? 0 : 1],
1714 ExcInvalidGMSHInput(line));
1717 if (gmsh_file_format > 40)
1721 in >> n_entity_blocks >>
n_cells >> min_node_tag >> max_node_tag;
1723 else if (gmsh_file_format == 40)
1725 in >> n_entity_blocks >>
n_cells;
1729 n_entity_blocks = 1;
1736 std::vector<CellData<dim>> cells;
1738 std::map<unsigned int, types::boundary_id> boundary_ids_1d;
1739 bool is_quad_or_hex_mesh =
false;
1740 bool is_tria_or_tet_mesh =
false;
1743 unsigned int global_cell = 0;
1744 for (
int entity_block = 0; entity_block < n_entity_blocks; ++entity_block)
1747 unsigned long numElements;
1750 if (gmsh_file_format < 40)
1756 else if (gmsh_file_format == 40)
1758 int tagEntity, dimEntity;
1759 in >> tagEntity >> dimEntity >> cell_type >> numElements;
1765 int tagEntity, dimEntity;
1766 in >> dimEntity >> tagEntity >> cell_type >> numElements;
1770 for (
unsigned int cell_per_entity = 0; cell_per_entity < numElements;
1771 ++cell_per_entity, ++global_cell)
1780 unsigned int nod_num;
1800 unsigned int elm_number = 0;
1801 if (gmsh_file_format < 40)
1807 if (gmsh_file_format < 20)
1813 else if (gmsh_file_format < 40)
1818 unsigned int n_tags;
1825 for (
unsigned int i = 1; i < n_tags; ++i)
1830 else if (cell_type == 2)
1832 else if (cell_type == 3)
1834 else if (cell_type == 4)
1836 else if (cell_type == 5)
1847 else if (cell_type == 2)
1849 else if (cell_type == 3)
1851 else if (cell_type == 4)
1853 else if (cell_type == 5)
1879 if (((cell_type == 1) && (dim == 1)) ||
1880 ((cell_type == 2) && (dim == 2)) ||
1881 ((cell_type == 3) && (dim == 2)) ||
1882 ((cell_type == 4) && (dim == 3)) ||
1883 ((cell_type == 5) && (dim == 3)))
1886 unsigned int vertices_per_cell = 0;
1888 vertices_per_cell = 2;
1889 else if (cell_type == 2)
1891 vertices_per_cell = 3;
1892 is_tria_or_tet_mesh =
true;
1894 else if (cell_type == 3)
1896 vertices_per_cell = 4;
1897 is_quad_or_hex_mesh =
true;
1899 else if (cell_type == 4)
1901 vertices_per_cell = 4;
1902 is_tria_or_tet_mesh =
true;
1904 else if (cell_type == 5)
1906 vertices_per_cell = 8;
1907 is_quad_or_hex_mesh =
true;
1912 "Number of nodes does not coincide with the "
1913 "number required for this object"));
1916 cells.emplace_back();
1917 cells.back().vertices.resize(vertices_per_cell);
1918 for (
unsigned int i = 0; i < vertices_per_cell; ++i)
1921 if (vertices_per_cell ==
1929 in >> cells.back().vertices[i];
1947 for (
unsigned int i = 0; i < vertices_per_cell; ++i)
1952 ExcInvalidVertexIndexGmsh(cell_per_entity,
1954 cells.back().vertices[i]));
1957 cells.back().vertices[i] =
1961 else if ((cell_type == 1) && ((dim == 2) || (dim == 3)))
1985 for (
unsigned int &vertex :
1999 else if ((cell_type == 2 || cell_type == 3) && (dim == 3))
2002 unsigned int vertices_per_cell = 0;
2006 vertices_per_cell = 3;
2007 is_tria_or_tet_mesh =
true;
2009 else if (cell_type == 3)
2011 vertices_per_cell = 4;
2012 is_quad_or_hex_mesh =
true;
2021 for (
unsigned int i = 0; i < vertices_per_cell; ++i)
2041 for (
unsigned int &vertex :
2054 else if (cell_type == 15)
2057 unsigned int node_index = 0;
2058 if (gmsh_file_format < 20)
2077 AssertThrow(
false, ExcGmshUnsupportedGeometry(cell_type));
2085 static const std::string end_elements_marker[] = {
"@f$ENDELM",
"@f$EndElements"};
2086 AssertThrow(line == end_elements_marker[gmsh_file_format == 10 ? 0 : 1],
2087 ExcInvalidGMSHInput(line));
2095 AssertThrow(cells.size() > 0, ExcGmshNoCellInformation());
2102 if (dim == 1 || (is_quad_or_hex_mesh && !is_tria_or_tet_mesh))
2107 if (dim == spacedim)
2111 tria->create_triangulation(
vertices, cells, subcelldata);
2116 assign_1d_boundary_ids(boundary_ids_1d, *tria);
2121#ifdef DEAL_II_GMSH_WITH_API
2122template <
int dim,
int spacedim>
2128 const std::map<int, std::uint8_t> gmsh_to_dealii_type = {
2129 {{15, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {7, 5}, {6, 6}, {5, 7}}};
2132 const std::array<std::vector<unsigned int>, 8> gmsh_to_dealii = {
2139 {{0, 1, 2, 3, 4, 5}},
2140 {{0, 1, 3, 2, 4, 5, 7, 6}}}};
2142 std::vector<Point<spacedim>>
vertices;
2143 std::vector<CellData<dim>> cells;
2145 std::map<unsigned int, types::boundary_id> boundary_ids_1d;
2148 gmsh::option::setNumber(
"General.Verbosity", 0);
2152 ExcMessage(
"You are trying to read a gmsh file with dimension " +
2159 gmsh::model::mesh::removeDuplicateNodes();
2160 gmsh::model::mesh::renumberNodes();
2161 std::vector<std::size_t> node_tags;
2162 std::vector<double> coord;
2163 std::vector<double> parametricCoord;
2164 gmsh::model::mesh::getNodes(
2165 node_tags, coord, parametricCoord, -1, -1,
false,
false);
2167 for (
unsigned int i = 0; i < node_tags.size(); ++i)
2171 for (
unsigned int d = 0;
d < spacedim; ++
d)
2175 for (
unsigned int d = spacedim;
d < 3; ++
d)
2177 ExcMessage(
"The grid you are reading contains nodes that are "
2178 "nonzero in the coordinate with index " +
2180 ", but you are trying to save "
2181 "it on a grid embedded in a " +
2189 std::vector<std::pair<int, int>> entities;
2190 gmsh::model::getEntities(entities);
2192 for (
const auto &
e : entities)
2195 const int &entity_dim =
e.first;
2196 const int &entity_tag =
e.second;
2202 std::vector<int> physical_tags;
2203 gmsh::model::getPhysicalGroupsForEntity(entity_dim,
2208 if (physical_tags.size())
2209 for (
auto physical_tag : physical_tags)
2212 gmsh::model::getPhysicalName(entity_dim, physical_tag, name);
2216 std::map<std::string, int> id_names;
2218 bool throw_anyway =
false;
2219 bool found_boundary_id =
false;
2222 for (
const auto &it : id_names)
2224 const auto &name = it.first;
2225 const auto &
id = it.second;
2226 if (entity_dim == dim && name ==
"MaterialID")
2229 found_boundary_id =
true;
2231 else if (entity_dim < dim && name ==
"BoundaryID")
2234 found_boundary_id =
true;
2236 else if (name ==
"ManifoldID")
2242 throw_anyway =
true;
2248 if (throw_anyway && !found_boundary_id)
2262 std::vector<int> element_types;
2263 std::vector<std::vector<std::size_t>> element_ids, element_nodes;
2264 gmsh::model::mesh::getElements(
2265 element_types, element_ids, element_nodes, entity_dim, entity_tag);
2267 for (
unsigned int i = 0; i < element_types.size(); ++i)
2269 const auto &type = gmsh_to_dealii_type.at(element_types[i]);
2270 const auto n_vertices = gmsh_to_dealii[type].size();
2271 const auto &elements = element_ids[i];
2272 const auto &nodes = element_nodes[i];
2273 for (
unsigned int j = 0; j < elements.size(); ++j)
2275 if (entity_dim == dim)
2277 cells.emplace_back(n_vertices);
2278 auto &cell = cells.back();
2279 for (
unsigned int v = 0; v < n_vertices; ++v)
2281 nodes[n_vertices * j + gmsh_to_dealii[type][v]] - 1;
2285 else if (entity_dim == 2)
2289 for (
unsigned int v = 0; v < n_vertices; ++v)
2291 nodes[n_vertices * j + gmsh_to_dealii[type][v]] - 1;
2296 else if (entity_dim == 1)
2300 for (
unsigned int v = 0; v < n_vertices; ++v)
2302 nodes[n_vertices * j + gmsh_to_dealii[type][v]] - 1;
2307 else if (entity_dim == 0)
2311 for (
unsigned int j = 0; j < elements.size(); ++j)
2320 tria->create_triangulation(
vertices, cells, subcelldata);
2325 assign_1d_boundary_ids(boundary_ids_1d, *tria);
2334template <
int dim,
int spacedim>
2337 std::string & header,
2338 std::vector<unsigned int> &tecplot2deal,
2339 unsigned int & n_vars,
2340 unsigned int & n_vertices,
2342 std::vector<unsigned int> &IJK,
2367 std::transform(header.begin(), header.end(), header.begin(), ::toupper);
2371 std::replace(header.begin(), header.end(),
'\t',
' ');
2372 std::replace(header.begin(), header.end(),
',',
' ');
2373 std::replace(header.begin(), header.end(),
'\n',
' ');
2380 if (header[pos + 1] ==
' ')
2381 header.erase(pos + 1, 1);
2382 else if (header[pos - 1] ==
' ')
2384 header.erase(pos - 1, 1);
2388 pos = header.find(
'=', ++pos);
2391 std::vector<std::string> entries =
2395 for (
unsigned int i = 0; i < entries.size(); ++i)
2404 tecplot2deal[0] = 0;
2407 while (entries[i][0] ==
'"')
2409 if (entries[i] ==
"\"X\"")
2410 tecplot2deal[0] = n_vars;
2411 else if (entries[i] ==
"\"Y\"")
2417 tecplot2deal[1] = n_vars;
2419 else if (entries[i] ==
"\"Z\"")
2425 tecplot2deal[2] = n_vars;
2437 "Tecplot file must contain at least one variable for each dimension"));
2438 for (
unsigned int d = 1;
d < dim; ++
d)
2440 tecplot2deal[
d] > 0,
2442 "Tecplot file must contain at least one variable for each dimension."));
2447 "ZONETYPE=FELINESEG") &&
2451 "ZONETYPE=FEQUADRILATERAL") &&
2455 "ZONETYPE=FEBRICK") &&
2463 "The tecplot file contains an unsupported ZONETYPE."));
2466 "DATAPACKING=POINT"))
2469 "DATAPACKING=BLOCK"))
2492 "ET=QUADRILATERAL") &&
2504 "The tecplot file contains an unsupported ElementType."));
2512 dim > 1 || IJK[1] == 1,
2514 "Parameter 'J=' found in tecplot, although this is only possible for dimensions greater than 1."));
2520 dim > 2 || IJK[2] == 1,
2522 "Parameter 'K=' found in tecplot, although this is only possible for dimensions greater than 2."));
2537 for (
unsigned int d = 0;
d < dim; ++
d)
2542 "Tecplot file does not contain a complete and consistent set of parameters"));
2543 n_vertices *= IJK[
d];
2552 "Tecplot file does not contain a complete and consistent set of parameters"));
2558 n_cells = *std::max_element(IJK.begin(), IJK.end());
2562 "Tecplot file does not contain a complete and consistent set of parameters"));
2572 const unsigned int dim = 2;
2573 const unsigned int spacedim = 2;
2578 skip_comment_lines(in,
'#');
2581 std::string line, header;
2588 std::string letters =
"abcdfghijklmnopqrstuvwxyzABCDFGHIJKLMNOPQRSTUVWXYZ";
2591 while (line.find_first_of(letters) != std::string::npos)
2593 header +=
" " + line;
2600 std::vector<unsigned int> tecplot2deal(dim);
2601 std::vector<unsigned int> IJK(dim);
2602 unsigned int n_vars, n_vertices,
n_cells;
2603 bool structured, blocked;
2605 parse_tecplot_header(header,
2620 std::vector<Point<spacedim>>
vertices(n_vertices + 1);
2623 std::vector<CellData<dim>> cells(
n_cells);
2639 unsigned int next_index = 0;
2643 if (tecplot2deal[0] == 0)
2647 std::vector<std::string> first_var =
2650 for (
unsigned int i = 1; i < first_var.size() + 1; ++i)
2651 vertices[i](0) = std::strtod(first_var[i - 1].c_str(), &endptr);
2656 for (
unsigned int j = first_var.size() + 1; j < n_vertices + 1; ++j)
2664 for (
unsigned int i = 1; i < n_vars; ++i)
2673 if (next_index == dim && structured)
2676 if ((next_index < dim) && (i == tecplot2deal[next_index]))
2679 for (
unsigned int j = 1; j < n_vertices + 1; ++j)
2687 for (
unsigned int j = 1; j < n_vertices + 1; ++j)
2699 std::vector<double> vars(n_vars);
2704 std::vector<std::string> first_vertex =
2707 for (
unsigned int d = 0;
d < dim; ++
d)
2709 std::strtod(first_vertex[tecplot2deal[
d]].c_str(), &endptr);
2713 for (
unsigned int v = 2; v < n_vertices + 1; ++v)
2715 for (
unsigned int i = 0; i < n_vars; ++i)
2721 for (
unsigned int i = 0; i < dim; ++i)
2722 vertices[v](i) = vars[tecplot2deal[i]];
2730 unsigned int I = IJK[0], J = IJK[1];
2732 unsigned int cell = 0;
2734 for (
unsigned int j = 0; j < J - 1; ++j)
2735 for (
unsigned int i = 1; i < I; ++i)
2737 cells[cell].vertices[0] = i + j * I;
2738 cells[cell].vertices[1] = i + 1 + j * I;
2739 cells[cell].vertices[2] = i + (j + 1) * I;
2740 cells[cell].vertices[3] = i + 1 + (j + 1) * I;
2744 std::vector<unsigned int> boundary_vertices(2 * I + 2 * J - 4);
2746 for (
unsigned int i = 1; i < I + 1; ++i)
2748 boundary_vertices[k] = i;
2750 boundary_vertices[k] = i + (J - 1) * I;
2753 for (
unsigned int j = 1; j < J - 1; ++j)
2755 boundary_vertices[k] = 1 + j * I;
2757 boundary_vertices[k] = I + j * I;
2776 for (
unsigned int i = 0; i <
n_cells; ++i)
2803 tria->create_triangulation(
vertices, cells, subcelldata);
2808template <
int dim,
int spacedim>
2817template <
int dim,
int spacedim>
2820 const unsigned int mesh_index,
2821 const bool remove_duplicates,
2823 const bool ignore_unsupported_types)
2825#ifdef DEAL_II_WITH_ASSIMP
2830 Assimp::Importer importer;
2833 const aiScene *scene =
2834 importer.ReadFile(filename.c_str(),
2835 aiProcess_RemoveComponent |
2836 aiProcess_JoinIdenticalVertices |
2837 aiProcess_ImproveCacheLocality | aiProcess_SortByPType |
2838 aiProcess_OptimizeGraph | aiProcess_OptimizeMeshes);
2844 ExcMessage(
"Input file contains no meshes."));
2847 (mesh_index < scene->mNumMeshes),
2850 unsigned int start_mesh =
2852 unsigned int end_mesh =
2857 std::vector<Point<spacedim>>
vertices;
2858 std::vector<CellData<dim>> cells;
2862 unsigned int v_offset = 0;
2863 unsigned int c_offset = 0;
2866 for (
unsigned int m = start_mesh; m < end_mesh; ++m)
2868 const aiMesh *mesh = scene->mMeshes[m];
2872 if ((dim == 2) && mesh->mPrimitiveTypes != aiPrimitiveType_POLYGON)
2879 else if ((dim == 1) && mesh->mPrimitiveTypes != aiPrimitiveType_LINE)
2887 const unsigned int n_vertices = mesh->mNumVertices;
2888 const aiVector3D * mVertices = mesh->mVertices;
2891 const unsigned int n_faces = mesh->mNumFaces;
2892 const aiFace * mFaces = mesh->mFaces;
2894 vertices.resize(v_offset + n_vertices);
2895 cells.resize(c_offset + n_faces);
2897 for (
unsigned int i = 0; i < n_vertices; ++i)
2898 for (
unsigned int d = 0;
d < spacedim; ++
d)
2901 unsigned int valid_cell = c_offset;
2902 for (
unsigned int i = 0; i < n_faces; ++i)
2910 mFaces[i].mIndices[f] + v_offset;
2912 cells[valid_cell].material_id = m;
2921 " vertices. We expected only " +
2926 cells.resize(valid_cell);
2931 v_offset += n_vertices;
2932 c_offset = valid_cell;
2936 if (cells.size() == 0)
2939 if (remove_duplicates)
2944 unsigned int n_verts = 0;
2948 std::vector<unsigned int> considered_vertices;
2950 vertices, cells, subcelldata, considered_vertices, tol);
2955 if (dim == spacedim)
2958 tria->create_triangulation(
vertices, cells, subcelldata);
2963 (void)remove_duplicates;
2965 (void)ignore_unsupported_types;
2970#ifdef DEAL_II_TRILINOS_WITH_SEACAS
2977 exodusii_name_to_type(
const std::string &type_name,
2978 const int n_nodes_per_element)
2984 std::string type_name_2 = type_name;
2987 type_name_2.begin(),
2988 [](
unsigned char c) { return std::toupper(c); });
2989 const std::string
numbers =
"0123456789";
2990 type_name_2.erase(std::find_first_of(type_name_2.begin(),
2996 if (type_name_2 ==
"TRI" || type_name_2 ==
"TRIANGLE")
2998 else if (type_name_2 ==
"QUAD" || type_name_2 ==
"QUADRILATERAL")
3000 else if (type_name_2 ==
"SHELL")
3002 if (n_nodes_per_element == 3)
3007 else if (type_name_2 ==
"TET" || type_name_2 ==
"TETRA" ||
3008 type_name_2 ==
"TETRAHEDRON")
3010 else if (type_name_2 ==
"PYRA" || type_name_2 ==
"PYRAMID")
3012 else if (type_name_2 ==
"WEDGE")
3014 else if (type_name_2 ==
"HEX" || type_name_2 ==
"HEXAHEDRON")
3024 template <
int dim,
int spacedim = dim>
3025 std::pair<SubCellData, std::vector<std::vector<int>>>
3026 read_exodusii_sidesets(
const int ex_id,
3027 const int n_side_sets,
3029 const bool apply_all_indicators_to_manifolds)
3032 std::vector<std::vector<int>> b_or_m_id_to_sideset_ids;
3034 b_or_m_id_to_sideset_ids.emplace_back();
3039 if (dim == spacedim && n_side_sets > 0)
3041 std::vector<int> side_set_ids(n_side_sets);
3042 int ierr = ex_get_ids(ex_id, EX_SIDE_SET, side_set_ids.data());
3043 AssertThrowExodusII(ierr);
3050 std::map<std::size_t, std::vector<int>> face_side_sets;
3051 for (
const int side_set_id : side_set_ids)
3054 int n_distribution_factors = -1;
3056 ierr = ex_get_set_param(ex_id,
3060 &n_distribution_factors);
3061 AssertThrowExodusII(ierr);
3064 std::vector<int> elements(n_sides);
3065 std::vector<int> faces(n_sides);
3066 ierr = ex_get_set(ex_id,
3071 AssertThrowExodusII(ierr);
3079 for (
int side_n = 0; side_n < n_sides; ++side_n)
3081 const long element_n = elements[side_n] - 1;
3082 const long face_n = faces[side_n] - 1;
3083 const std::size_t face_id =
3084 element_n * max_faces_per_cell + face_n;
3085 face_side_sets[face_id].push_back(side_set_id);
3091 std::vector<std::pair<std::size_t, std::vector<int>>>
3092 face_id_to_side_sets;
3093 for (
auto &pair : face_side_sets)
3096 face_id_to_side_sets.push_back(std::move(pair));
3100 std::sort(face_id_to_side_sets.begin(),
3101 face_id_to_side_sets.end(),
3102 [](
const auto &a,
const auto &
b) {
3103 return std::lexicographical_compare(a.second.begin(),
3110 for (
const auto &pair : face_id_to_side_sets)
3112 const std::size_t face_id = pair.first;
3113 const std::vector<int> &face_sideset_ids = pair.second;
3114 if (face_sideset_ids != b_or_m_id_to_sideset_ids.back())
3118 ++current_b_or_m_id;
3119 b_or_m_id_to_sideset_ids.push_back(face_sideset_ids);
3120 Assert(current_b_or_m_id == b_or_m_id_to_sideset_ids.size() - 1,
3124 const unsigned int local_face_n = face_id % max_faces_per_cell;
3125 const CellData<dim> &cell = cells[face_id / max_faces_per_cell];
3128 const unsigned int deal_face_n =
3139 if (apply_all_indicators_to_manifolds)
3140 boundary_line.manifold_id = current_b_or_m_id;
3142 boundary_line.boundary_id = current_b_or_m_id;
3143 for (
unsigned int j = 0; j < face_reference_cell.
n_vertices();
3145 boundary_line.vertices[j] =
3147 deal_face_n, j, 0)];
3154 if (apply_all_indicators_to_manifolds)
3155 boundary_quad.manifold_id = current_b_or_m_id;
3157 boundary_quad.boundary_id = current_b_or_m_id;
3158 for (
unsigned int j = 0; j < face_reference_cell.
n_vertices();
3160 boundary_quad.vertices[j] =
3162 deal_face_n, j, 0)];
3169 return std::make_pair(std::move(subcelldata),
3170 std::move(b_or_m_id_to_sideset_ids));
3175template <
int dim,
int spacedim>
3178 const std::string &filename,
3179 const bool apply_all_indicators_to_manifolds)
3181#ifdef DEAL_II_TRILINOS_WITH_SEACAS
3183 int component_word_size =
sizeof(double);
3185 int floating_point_word_size = 0;
3186 float ex_version = 0.0;
3188 const int ex_id = ex_open(filename.c_str(),
3190 &component_word_size,
3191 &floating_point_word_size,
3194 ExcMessage(
"ExodusII failed to open the specified input file."));
3197 std::vector<char> string_temp(MAX_LINE_LENGTH + 1,
'\0');
3198 int mesh_dimension = 0;
3201 int n_element_blocks = 0;
3202 int n_node_sets = 0;
3203 int n_side_sets = 0;
3205 int ierr = ex_get_init(ex_id,
3213 AssertThrowExodusII(ierr);
3217 std::vector<double> xs(n_nodes);
3218 std::vector<double> ys(n_nodes);
3219 std::vector<double> zs(n_nodes);
3221 ierr = ex_get_coord(ex_id, xs.data(), ys.data(), zs.data());
3222 AssertThrowExodusII(ierr);
3230 std::vector<Point<spacedim>>
vertices;
3232 for (
int vertex_n = 0; vertex_n < n_nodes; ++vertex_n)
3237 vertices.emplace_back(xs[vertex_n]);
3240 vertices.emplace_back(xs[vertex_n], ys[vertex_n]);
3243 vertices.emplace_back(xs[vertex_n], ys[vertex_n], zs[vertex_n]);
3250 std::vector<int> element_block_ids(n_element_blocks);
3251 ierr = ex_get_ids(ex_id, EX_ELEM_BLOCK, element_block_ids.data());
3252 AssertThrowExodusII(ierr);
3254 bool is_only_quad_or_hex =
true;
3256 std::vector<CellData<dim>> cells;
3260 for (
const int element_block_id : element_block_ids)
3262 std::fill(string_temp.begin(), string_temp.end(),
'\0');
3263 int n_block_elements = 0;
3264 int n_nodes_per_element = 0;
3265 int n_edges_per_element = 0;
3266 int n_faces_per_element = 0;
3267 int n_attributes_per_element = 0;
3270 ierr = ex_get_block(ex_id,
3275 &n_nodes_per_element,
3276 &n_edges_per_element,
3277 &n_faces_per_element,
3278 &n_attributes_per_element);
3279 AssertThrowExodusII(ierr);
3281 exodusii_name_to_type(string_temp.data(), n_nodes_per_element);
3284 is_only_quad_or_hex =
false;
3291 std::vector<int> connection(n_nodes_per_element * n_block_elements);
3292 ierr = ex_get_conn(ex_id,
3298 AssertThrowExodusII(ierr);
3300 for (
unsigned int elem_n = 0; elem_n < connection.size();
3301 elem_n += n_nodes_per_element)
3307 connection[elem_n + i] - 1;
3310 cells.push_back(cell);
3315 auto pair = read_exodusii_sidesets<dim, spacedim>(
3316 ex_id, n_side_sets, cells, apply_all_indicators_to_manifolds);
3317 ierr = ex_close(ex_id);
3318 AssertThrowExodusII(ierr);
3320 if (is_only_quad_or_hex)
3325 if (dim == spacedim)
3330 tria->create_triangulation(
vertices, cells, pair.first);
3336 (void)apply_all_indicators_to_manifolds;
3343template <
int dim,
int spacedim>
3357 if (std::find_if(line.begin(), line.end(), [](
const char c) {
3362 for (
int i = line.length() - 1; i >= 0; --i)
3363 in.putback(line[i]);
3373template <
int dim,
int spacedim>
3376 const char comment_start)
3381 while (in.get(c) && c == comment_start)
3384 while (in.get() !=
'\n')
3394 skip_empty_lines(in);
3399template <
int dim,
int spacedim>
3417 double min_x =
vertices[cells[0].vertices[0]](0),
3419 min_y =
vertices[cells[0].vertices[0]](1),
3422 for (
unsigned int i = 0; i < cells.size(); ++i)
3424 for (
const auto vertex : cells[i].
vertices)
3438 out <<
"# cell " << i << std::endl;
3440 for (
const auto vertex : cells[i].
vertices)
3444 out <<
"set label \"" << i <<
"\" at " <<
center(0) <<
',' <<
center(1)
3445 <<
" center" << std::endl;
3448 for (
unsigned int f = 0; f < 2; ++f)
3450 <<
vertices[cells[i].vertices[f]](1) <<
" to "
3454 for (
unsigned int f = 2; f < 4; ++f)
3458 <<
vertices[cells[i].vertices[f]](1) << std::endl;
3464 <<
"set nokey" << std::endl
3465 <<
"pl [" << min_x <<
':' << max_x <<
"][" << min_y <<
':' << max_y
3466 <<
"] " << min_y << std::endl
3467 <<
"pause -1" << std::endl;
3478 for (
const auto &cell : cells)
3545template <
int dim,
int spacedim>
3553 if (format == Default)
3554 name = search.
find(filename);
3559 if (format == Default)
3563 if (dotpos < name.length() &&
3564 (dotpos > slashpos || slashpos == std::string::npos))
3566 std::string ext = name.substr(dotpos + 1);
3567 format = parse_format(ext);
3571 if (format == assimp)
3575 else if (format == exodusii)
3577 read_exodusii(name);
3581 std::ifstream in(name.c_str());
3587template <
int dim,
int spacedim>
3591 if (format == Default)
3634 ExcMessage(
"There is no read_assimp(istream &) function. "
3635 "Use the read_assimp(string &filename, ...) "
3636 "functions, instead."));
3641 ExcMessage(
"There is no read_exodusii(istream &) function. "
3642 "Use the read_exodusii(string &filename, ...) "
3643 "function, instead."));
3654template <
int dim,
int spacedim>
3683 return ".unknown_format";
3689template <
int dim,
int spacedim>
3693 if (format_name ==
"dbmesh")
3696 if (format_name ==
"exodusii")
3699 if (format_name ==
"msh")
3702 if (format_name ==
"unv")
3705 if (format_name ==
"vtk")
3708 if (format_name ==
"vtu")
3712 if (format_name ==
"inp")
3715 if (format_name ==
"ucd")
3718 if (format_name ==
"xda")
3721 if (format_name ==
"tecplot")
3724 if (format_name ==
"dat")
3727 if (format_name ==
"plt")
3746template <
int dim,
int spacedim>
3750 return "dbmesh|exodusii|msh|unv|vtk|vtu|ucd|abaqus|xda|tecplot|assimp";
3757 template <
int dim,
int spacedim>
3758 Abaqus_to_UCD<dim, spacedim>::Abaqus_to_UCD()
3771 from_string(
T &t,
const std::string &s, std::ios_base &(*f)(std::ios_base &))
3773 std::istringstream iss(s);
3774 return !(iss >> f >> t).fail();
3781 extract_int(
const std::string &s)
3784 for (
const char c : s)
3793 from_string(number, tmp, std::dec);
3799 template <
int dim,
int spacedim>
3801 Abaqus_to_UCD<dim, spacedim>::read_in_abaqus(std::istream &input_stream)
3810 while (std::getline(input_stream, line))
3813 std::transform(line.begin(), line.end(), line.begin(), ::toupper);
3815 if (line.compare(
"*HEADING") == 0 || line.compare(0, 2,
"**") == 0 ||
3816 line.compare(0, 5,
"*PART") == 0)
3819 while (std::getline(input_stream, line))
3825 else if (line.compare(0, 5,
"*NODE") == 0)
3834 while (std::getline(input_stream, line))
3839 std::vector<double> node(spacedim + 1);
3841 std::istringstream iss(line);
3843 for (
unsigned int i = 0; i < spacedim + 1; ++i)
3844 iss >> node[i] >> comma;
3846 node_list.push_back(node);
3849 else if (line.compare(0, 8,
"*ELEMENT") == 0)
3864 const std::string before_material =
"ELSET=EB";
3865 const std::size_t idx = line.find(before_material);
3866 if (idx != std::string::npos)
3868 from_string(material,
3869 line.substr(idx + before_material.size()),
3875 while (std::getline(input_stream, line))
3880 std::istringstream iss(line);
3886 const unsigned int n_data_per_cell =
3888 std::vector<double> cell(n_data_per_cell);
3889 for (
unsigned int i = 0; i < n_data_per_cell; ++i)
3890 iss >> cell[i] >> comma;
3893 cell[0] =
static_cast<double>(material);
3894 cell_list.push_back(cell);
3897 else if (line.compare(0, 8,
"*SURFACE") == 0)
3908 const std::string name_key =
"NAME=";
3909 const std::size_t name_idx_start =
3910 line.find(name_key) + name_key.size();
3911 std::size_t name_idx_end = line.find(
',', name_idx_start);
3912 if (name_idx_end == std::string::npos)
3914 name_idx_end = line.size();
3916 const int b_indicator = extract_int(
3917 line.substr(name_idx_start, name_idx_end - name_idx_start));
3924 while (std::getline(input_stream, line))
3938 std::istringstream iss(line);
3945 std::vector<double> quad_node_list;
3946 const std::string elset_name = line.substr(0, line.find(
','));
3947 if (elsets_list.count(elset_name) != 0)
3951 iss >> stmp >> temp >> face_number;
3953 const std::vector<int> cells = elsets_list[elset_name];
3954 for (
const int cell : cells)
3958 get_global_node_numbers(el_idx, face_number);
3959 quad_node_list.insert(quad_node_list.begin(),
3962 face_list.push_back(quad_node_list);
3969 iss >> el_idx >> comma >> temp >> face_number;
3971 get_global_node_numbers(el_idx, face_number);
3972 quad_node_list.insert(quad_node_list.begin(), b_indicator);
3974 face_list.push_back(quad_node_list);
3978 else if (line.compare(0, 6,
"*ELSET") == 0)
3982 std::string elset_name;
3984 const std::string elset_key =
"*ELSET, ELSET=";
3985 const std::size_t idx = line.find(elset_key);
3986 if (idx != std::string::npos)
3988 const std::string comma =
",";
3989 const std::size_t first_comma = line.find(comma);
3990 const std::size_t second_comma =
3991 line.find(comma, first_comma + 1);
3992 const std::size_t elset_name_start =
3993 line.find(elset_key) + elset_key.size();
3994 elset_name = line.substr(elset_name_start,
3995 second_comma - elset_name_start);
4005 std::vector<int> elements;
4006 const std::size_t generate_idx = line.find(
"GENERATE");
4007 if (generate_idx != std::string::npos)
4010 std::getline(input_stream, line);
4011 std::istringstream iss(line);
4020 iss >> elid_start >> comma >> elid_end;
4024 "While reading an ABAQUS file, the reader "
4025 "expected a comma but found a <") +
4026 comma +
"> in the line <" + line +
">."));
4028 elid_start <= elid_end,
4031 "While reading an ABAQUS file, the reader encountered "
4032 "a GENERATE statement in which the upper bound <") +
4034 "> for the element numbers is not larger or equal "
4035 "than the lower bound <" +
4039 if (iss.rdbuf()->in_avail() != 0)
4040 iss >> comma >> elis_step;
4044 "While reading an ABAQUS file, the reader "
4045 "expected a comma but found a <") +
4046 comma +
"> in the line <" + line +
">."));
4048 for (
int i = elid_start; i <= elid_end; i += elis_step)
4049 elements.push_back(i);
4050 elsets_list[elset_name] = elements;
4052 std::getline(input_stream, line);
4057 while (std::getline(input_stream, line))
4062 std::istringstream iss(line);
4067 iss >> elid >> comma;
4072 "While reading an ABAQUS file, the reader "
4073 "expected a comma but found a <") +
4074 comma +
"> in the line <" + line +
">."));
4076 elements.push_back(elid);
4080 elsets_list[elset_name] = elements;
4085 else if (line.compare(0, 5,
"*NSET") == 0)
4088 while (std::getline(input_stream, line))
4094 else if (line.compare(0, 14,
"*SOLID SECTION") == 0)
4097 const std::string elset_key =
"ELSET=";
4098 const std::size_t elset_start =
4099 line.find(
"ELSET=") + elset_key.size();
4100 const std::size_t elset_end = line.find(
',', elset_start + 1);
4101 const std::string elset_name =
4102 line.substr(elset_start, elset_end - elset_start);
4107 const std::string material_key =
"MATERIAL=";
4108 const std::size_t last_equal =
4109 line.find(
"MATERIAL=") + material_key.size();
4110 const std::size_t material_id_start = line.find(
'-', last_equal);
4113 line.substr(material_id_start + 1),
4117 const std::vector<int> &elset_cells = elsets_list[elset_name];
4118 for (
const int elset_cell : elset_cells)
4120 const int cell_id = elset_cell - 1;
4128 template <
int dim,
int spacedim>
4130 Abaqus_to_UCD<dim, spacedim>::get_global_node_numbers(
4131 const int face_cell_no,
4132 const int face_cell_face_no)
const
4142 if (face_cell_face_no == 1)
4144 quad_node_list[0] = cell_list[face_cell_no - 1][1];
4145 quad_node_list[1] = cell_list[face_cell_no - 1][2];
4147 else if (face_cell_face_no == 2)
4149 quad_node_list[0] = cell_list[face_cell_no - 1][2];
4150 quad_node_list[1] = cell_list[face_cell_no - 1][3];
4152 else if (face_cell_face_no == 3)
4154 quad_node_list[0] = cell_list[face_cell_no - 1][3];
4155 quad_node_list[1] = cell_list[face_cell_no - 1][4];
4157 else if (face_cell_face_no == 4)
4159 quad_node_list[0] = cell_list[face_cell_no - 1][4];
4160 quad_node_list[1] = cell_list[face_cell_no - 1][1];
4170 if (face_cell_face_no == 1)
4172 quad_node_list[0] = cell_list[face_cell_no - 1][1];
4173 quad_node_list[1] = cell_list[face_cell_no - 1][4];
4174 quad_node_list[2] = cell_list[face_cell_no - 1][3];
4175 quad_node_list[3] = cell_list[face_cell_no - 1][2];
4177 else if (face_cell_face_no == 2)
4179 quad_node_list[0] = cell_list[face_cell_no - 1][5];
4180 quad_node_list[1] = cell_list[face_cell_no - 1][8];
4181 quad_node_list[2] = cell_list[face_cell_no - 1][7];
4182 quad_node_list[3] = cell_list[face_cell_no - 1][6];
4184 else if (face_cell_face_no == 3)
4186 quad_node_list[0] = cell_list[face_cell_no - 1][1];
4187 quad_node_list[1] = cell_list[face_cell_no - 1][2];
4188 quad_node_list[2] = cell_list[face_cell_no - 1][6];
4189 quad_node_list[3] = cell_list[face_cell_no - 1][5];
4191 else if (face_cell_face_no == 4)
4193 quad_node_list[0] = cell_list[face_cell_no - 1][2];
4194 quad_node_list[1] = cell_list[face_cell_no - 1][3];
4195 quad_node_list[2] = cell_list[face_cell_no - 1][7];
4196 quad_node_list[3] = cell_list[face_cell_no - 1][6];
4198 else if (face_cell_face_no == 5)
4200 quad_node_list[0] = cell_list[face_cell_no - 1][3];
4201 quad_node_list[1] = cell_list[face_cell_no - 1][4];
4202 quad_node_list[2] = cell_list[face_cell_no - 1][8];
4203 quad_node_list[3] = cell_list[face_cell_no - 1][7];
4205 else if (face_cell_face_no == 6)
4207 quad_node_list[0] = cell_list[face_cell_no - 1][1];
4208 quad_node_list[1] = cell_list[face_cell_no - 1][5];
4209 quad_node_list[2] = cell_list[face_cell_no - 1][8];
4210 quad_node_list[3] = cell_list[face_cell_no - 1][4];
4223 return quad_node_list;
4226 template <
int dim,
int spacedim>
4228 Abaqus_to_UCD<dim, spacedim>::write_out_avs_ucd(std::ostream &output)
const
4237 const boost::io::ios_base_all_saver formatting_saver(output);
4241 output <<
"# Abaqus to UCD mesh conversion" << std::endl;
4242 output <<
"# Mesh type: AVS UCD" << std::endl;
4267 output << node_list.size() <<
"\t" << (cell_list.size() + face_list.size())
4268 <<
"\t0\t0\t0" << std::endl;
4271 output.precision(8);
4275 for (
const auto &node : node_list)
4278 output << node[0] <<
"\t";
4281 output.setf(std::ios::scientific, std::ios::floatfield);
4282 for (
unsigned int jj = 1; jj < spacedim + 1; ++jj)
4285 if (
std::abs(node[jj]) > tolerance)
4286 output <<
static_cast<double>(node[jj]) <<
"\t";
4288 output << 0.0 <<
"\t";
4291 output << 0.0 <<
"\t";
4293 output << std::endl;
4294 output.unsetf(std::ios::floatfield);
4298 for (
unsigned int ii = 0; ii < cell_list.size(); ++ii)
4300 output << ii + 1 <<
"\t" << cell_list[ii][0] <<
"\t"
4301 << (dim == 2 ?
"quad" :
"hex") <<
"\t";
4302 for (
unsigned int jj = 1; jj < GeometryInfo<dim>::vertices_per_cell + 1;
4304 output << cell_list[ii][jj] <<
"\t";
4306 output << std::endl;
4310 for (
unsigned int ii = 0; ii < face_list.size(); ++ii)
4312 output << ii + 1 <<
"\t" << face_list[ii][0] <<
"\t"
4313 << (dim == 2 ?
"line" :
"quad") <<
"\t";
4314 for (
unsigned int jj = 1; jj < GeometryInfo<dim>::vertices_per_face + 1;
4316 output << face_list[ii][jj] <<
"\t";
4318 output << std::endl;
4325#include "grid_in.inst"
static void skip_empty_lines(std::istream &in)
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)
static std::string default_suffix(const Format format)
void read_xda(std::istream &in)
static void skip_comment_lines(std::istream &in, const char comment_start)
void attach_triangulation(Triangulation< dim, spacedim > &tria)
static Format parse_format(const std::string &format_name)
void read_vtu(std::istream &in)
void read_tecplot(std::istream &in)
ExodusIIData read_exodusii(const std::string &filename, const bool apply_all_indicators_to_manifolds=false)
void read_dbmesh(std::istream &in)
void read_ucd(std::istream &in, const bool apply_all_indicators_to_manifolds=false)
void read(std::istream &in, Format format=Default)
static void debug_output_grid(const std::vector< CellData< dim > > &cells, const std::vector< Point< spacedim > > &vertices, std::ostream &out)
static std::string get_format_names()
void read_unv(std::istream &in)
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)
std::string find(const std::string &filename, const char *open_mode="r")
std_cxx20::ranges::iota_view< unsigned int, unsigned int > vertex_indices() const
unsigned int n_vertices() const
unsigned int face_to_cell_vertices(const unsigned int face, const unsigned int vertex, const unsigned char face_orientation) const
unsigned int exodusii_vertex_to_deal_vertex(const unsigned int vertex_n) const
ReferenceCell face_reference_cell(const unsigned int face_no) const
unsigned int exodusii_face_to_deal_face(const unsigned int face_n) const
static ReferenceCell n_vertices_to_type(const int dim, const unsigned int n_vertices)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_FALLTHROUGH
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcNeedsAssimp()
static ::ExceptionBase & ExcNotImplemented()
void to_value(const std::string &s, T &t)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
#define Assert(cond, exc)
std::string to_string(const T &t)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static ::ExceptionBase & ExcNeedsExodusII()
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNoTriangulationSelected()
static ::ExceptionBase & ExcInvalidState()
static ::ExceptionBase & ExcInvalidVertexIndex(int arg1, int arg2, int arg3)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
void read_vtk(std::istream &in)
void read_msh(std::istream &in)
std::string default_suffix(const OutputFormat output_format)
void reference_cell(Triangulation< dim, spacedim > &tria, const ReferenceCell &reference_cell)
types::global_dof_index size_type
void swap(MemorySpaceData< Number, MemorySpace > &, MemorySpaceData< Number, MemorySpace > &)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
constexpr const ReferenceCell Tetrahedron
constexpr const ReferenceCell Quadrilateral
constexpr const ReferenceCell Wedge
constexpr const ReferenceCell Pyramid
constexpr const ReferenceCell Invalid
constexpr const ReferenceCell Triangle
constexpr const ReferenceCell Hexahedron
std::pair< int, unsigned int > get_integer_at_position(const std::string &name, const unsigned int position)
std::vector< unsigned char > decode_base64(const std::string &base64_input)
std::vector< std::string > break_text_into_lines(const std::string &original_text, const unsigned int width, const char delimiter=' ')
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
bool match_at_string_start(const std::string &name, const std::string &pattern)
std::string decompress(const std::string &compressed_input)
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
const types::material_id invalid_material_id
const types::boundary_id internal_face_boundary_id
static const unsigned int invalid_unsigned_int
const types::manifold_id flat_manifold_id
void transform(const InputIterator &begin_in, const InputIterator &end_in, OutputIterator out, const Predicate &predicate, const unsigned int grainsize)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
std::vector< unsigned int > vertices
types::material_id material_id
std::vector< std::vector< int > > id_to_sideset_ids
std::vector< CellData< 2 > > boundary_quads
bool check_consistency(const unsigned int dim) const
std::vector< CellData< 1 > > boundary_lines