27#include <boost/algorithm/string.hpp>
28#include <boost/archive/binary_iarchive.hpp>
29#include <boost/io/ios_state.hpp>
30#include <boost/property_tree/ptree.hpp>
31#include <boost/property_tree/xml_parser.hpp>
32#include <boost/serialization/serialization.hpp>
34#ifdef DEAL_II_GMSH_WITH_API
45#ifdef DEAL_II_WITH_ASSIMP
46# include <assimp/Importer.hpp>
47# include <assimp/postprocess.h>
48# include <assimp/scene.h>
51#ifdef DEAL_II_TRILINOS_WITH_SEACAS
78 template <
int spacedim>
97 template <
int dim,
int spacedim>
111 template <
int dim,
int spacedim>
120 ReferenceCells::get_hypercube<dim>().n_vertices();
138template <
int dim,
int spacedim>
141 , default_format(ucd)
146template <
int dim,
int spacedim>
149 , default_format(ucd)
154template <
int dim,
int spacedim>
163template <
int dim,
int spacedim>
175 text[0] =
"# vtk DataFile Version 3.0";
178 text[3] =
"DATASET UNSTRUCTURED_GRID";
180 for (
unsigned int i = 0; i < 4; ++i)
185 line.compare(
text[i]) == 0,
188 "While reading VTK file, failed to find a header line with text <") +
195 std::vector<Point<spacedim>>
vertices;
196 std::vector<CellData<dim>> cells;
207 unsigned int n_vertices;
212 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
216 in >>
x(0) >>
x(1) >>
x(2);
219 for (
unsigned int d = 0; d < spacedim; ++d)
227 "While reading VTK file, failed to find POINTS section"));
237 std::vector<unsigned int> cell_types;
239 std::streampos
oldpos = in.tellg();
247 cell_types.resize(
n_ints);
249 for (
unsigned int i = 0; i <
n_ints; ++i)
265 unsigned int n_vertices;
269 if (cell_types[
count] == 10 || cell_types[
count] == 12)
277 cells.emplace_back(n_vertices);
279 for (
unsigned int j = 0;
j < n_vertices;
281 in >> cells.back().vertices[
j];
285 if (cell_types[
count] == 12)
287 std::swap(cells.back().vertices[2],
288 cells.back().vertices[3]);
289 std::swap(cells.back().vertices[6],
290 cells.back().vertices[7]);
293 cells.back().material_id = 0;
296 else if (cell_types[
count] == 5 || cell_types[
count] == 9)
303 subcelldata.boundary_quads.emplace_back(n_vertices);
305 for (
unsigned int j = 0;
j < n_vertices;
312 else if (cell_types[
count] == 3)
314 subcelldata.boundary_lines.emplace_back(n_vertices);
316 for (
unsigned int j = 0;
j < n_vertices;
327 "While reading VTK file, unknown cell type encountered"));
334 unsigned int n_vertices;
338 if (cell_types[
count] == 5 || cell_types[
count] == 9)
345 cells.emplace_back(n_vertices);
347 for (
unsigned int j = 0;
j < n_vertices;
349 in >> cells.back().vertices[
j];
353 if (cell_types[
count] == 9)
357 std::swap(cells.back().vertices[2],
358 cells.back().vertices[3]);
361 cells.back().material_id = 0;
364 else if (cell_types[
count] == 3)
368 subcelldata.boundary_lines.emplace_back(n_vertices);
370 for (
unsigned int j = 0;
j < n_vertices;
383 "While reading VTK file, unknown cell type encountered"));
394 cell_types[
count] == 3 && type == 2,
396 "While reading VTK file, unknown cell type encountered"));
397 cells.emplace_back(type);
399 for (
unsigned int j = 0;
j < type; ++
j)
400 in >> cells.back().vertices[
j];
402 cells.back().material_id = 0;
408 "While reading VTK file, failed to find CELLS section"));
417 "While reading VTK file, missing CELL_TYPES section. Found <" +
423 ExcMessage(
"The VTK reader found a CELL_DATA statement "
424 "that lists a total of " +
426 " cell data objects, but this needs to "
427 "equal the number of cells (which is " +
429 ") plus the number of quads (" +
431 " in 3d or the number of lines (" +
436 for (
unsigned int i = 0; i <
n_ints; ++i)
447 ExcMessage(
"The VTK reader found a CELL_DATA statement "
448 "that lists a total of " +
450 " cell data objects, but this needs to "
451 "equal the number of cells (which is " +
453 ") plus the number of quads (" +
456 " in 3d or the number of lines (" +
461 const std::vector<std::string> data_sets{
"MaterialID",
464 for (
unsigned int i = 0; i < data_sets.size(); ++i)
475 if (std::find(data_sets.begin(),
489 std::getline(in, line);
492 std::min(
static_cast<std::size_t
>(3),
493 line.size() - 1)) ==
"int",
495 "While reading VTK file, material- and manifold IDs can only have type 'int'."));
501 "While reading VTK file, missing keyword 'LOOKUP_TABLE'."));
507 "While reading VTK file, missing keyword 'default'."));
514 for (
unsigned int i = 0; i < cells.size(); ++i)
519 cells[i].material_id =
522 cells[i].manifold_id =
583 "While reading VTK file, failed to find CELLS section"));
588template <
int dim,
int spacedim>
592 namespace pt = boost::property_tree;
595 auto section = tree.get_optional<std::string>(
"VTKFile.dealiiData");
599 "While reading a VTU file, failed to find dealiiData section. "
600 "Notice that we can only read grid files in .vtu format that "
601 "were created by the deal.II library, using a call to "
602 "GridOut::write_vtu(), where the flag "
603 "GridOutFlags::Vtu::serialize_triangulation is set to true."));
615template <
int dim,
int spacedim>
619 Assert(
tria !=
nullptr, ExcNoTriangulationSelected());
623 skip_comment_lines(in,
'#');
634 "Expected '-1' before and after a section."));
646 std::getline(in, line);
648 boost::algorithm::trim(line);
649 if (line.compare(
"-1") == 0)
660 std::vector<Point<spacedim>>
vertices;
682 in >>
x[0] >>
x[1] >>
x[2];
686 for (
unsigned int d = 0; d < spacedim; ++d)
701 AssertThrow(tmp == 2412, ExcUnknownSectionType(tmp));
703 std::vector<CellData<dim>> cells;
732 AssertThrow((type == 11) || (type == 44) || (type == 94) || (type == 115),
733 ExcUnknownElementType(type));
735 if ((((type == 44) || (type == 94)) && (dim == 2)) ||
736 ((type == 115) && (dim == 3)))
738 const auto reference_cell = ReferenceCells::get_hypercube<dim>();
739 cells.emplace_back();
744 .vertices[reference_cell.unv_vertex_to_deal_vertex(v)];
746 cells.back().material_id = 0;
749 cells.back().vertices[v] =
vertex_indices[cells.back().vertices[v]];
755 else if (((type == 11) && (dim == 2)) ||
756 ((type == 11) && (dim == 3)))
764 for (
unsigned int &vertex :
770 for (
unsigned int &vertex :
778 else if (((type == 44) || (type == 94)) && (dim == 3))
789 .vertices[reference_cell.unv_vertex_to_deal_vertex(v)];
793 for (
unsigned int &vertex :
805 "> when running in dim=" +
824 AssertThrow((tmp == 2467) || (tmp == 2477), ExcUnknownSectionType(tmp));
851 std::getline(in, line);
854 "The line before the line containing an ID has too "
855 "many entries. This is not a valid UNV file."));
857 std::getline(in, line);
864 "The given UNV file contains a boundary or material id set to '" +
866 "', which cannot be parsed as a fixed-width integer, whereas "
867 "deal.II only supports integer boundary and material ids. To fix "
868 "this, ensure that all such ids are given integer values."));
871 id <=
long(std::numeric_limits<types::material_id>::max()),
872 ExcMessage(
"The provided integer id '" + std::to_string(
id) +
873 "' is not convertible to either types::material_id nor "
874 "types::boundary_id."));
876 const unsigned int n_lines =
877 (n_entities % 2 == 0) ? (n_entities / 2) : ((n_entities + 1) / 2);
879 for (
unsigned int line = 0; line < n_lines; ++line)
883 if (line == n_lines - 1)
897 if (line_indices.count(
no) > 0)
915template <
int dim,
int spacedim>
920 Assert(
tria !=
nullptr, ExcNoTriangulationSelected());
924 skip_comment_lines(in,
'#');
927 unsigned int n_vertices;
928 unsigned int n_cells;
931 in >> n_vertices >> n_cells >>
dummy
937 std::vector<Point<spacedim>>
vertices(n_vertices);
943 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
953 for (
unsigned int d = 0; d < spacedim; ++d)
962 std::vector<CellData<dim>> cells;
965 for (
unsigned int cell = 0; cell < n_cells; ++cell)
974 std::string cell_type;
978 unsigned int material_id;
984 if (((cell_type ==
"line") && (dim == 1)) ||
985 ((cell_type ==
"quad") && (dim == 2)) ||
986 ((cell_type ==
"hex") && (dim == 3)))
990 cells.emplace_back();
995 Assert(material_id <= std::numeric_limits<types::material_id>::max(),
998 std::numeric_limits<types::material_id>::max()));
1004 cells.back().manifold_id =
1006 cells.back().material_id = material_id;
1014 cells.back().vertices[i] =
1020 ExcInvalidVertexIndex(cell,
1021 cells.back().vertices[i]));
1026 else if ((cell_type ==
"line") && ((dim == 2) || (dim == 3)))
1030 in >>
subcelldata.boundary_lines.back().vertices[0] >>
1034 Assert(material_id <= std::numeric_limits<types::boundary_id>::max(),
1037 std::numeric_limits<types::boundary_id>::max()));
1063 for (
unsigned int &vertex :
1071 AssertThrow(
false, ExcInvalidVertexIndex(cell, vertex));
1075 else if ((cell_type ==
"quad") && (dim == 3))
1084 Assert(material_id <= std::numeric_limits<types::boundary_id>::max(),
1087 std::numeric_limits<types::boundary_id>::max()));
1113 for (
unsigned int &vertex :
1121 Assert(
false, ExcInvalidVertexIndex(cell, vertex));
1127 AssertThrow(
false, ExcUnknownIdentifier(cell_type));
1138 template <
int dim,
int spacedim>
1150 const double tolerance;
1157 std::vector<std::vector<double>> node_list;
1160 std::vector<std::vector<double>> cell_list;
1162 std::vector<std::vector<double>> face_list;
1165 std::map<std::string, std::vector<int>> elsets_list;
1169template <
int dim,
int spacedim>
1174 Assert(
tria !=
nullptr, ExcNoTriangulationSelected());
1179 Assert((spacedim == 2 && dim == spacedim) ||
1180 (spacedim == 3 && (dim == spacedim || dim == spacedim - 1)),
1189 std::stringstream
in_ucd;
1200 catch (std::exception &exc)
1202 std::cerr <<
"Exception on processing internal UCD data: " << std::endl
1203 << exc.what() << std::endl;
1208 "Internal conversion from ABAQUS file to UCD format was unsuccessful. "
1209 "More information is provided in an error message printed above. "
1210 "Are you sure that your ABAQUS mesh file conforms with the requirements "
1211 "listed in the documentation?"));
1218 "Internal conversion from ABAQUS file to UCD format was unsuccessful. "
1219 "Are you sure that your ABAQUS mesh file conforms with the requirements "
1220 "listed in the documentation?"));
1225template <
int dim,
int spacedim>
1229 Assert(
tria !=
nullptr, ExcNoTriangulationSelected());
1235 skip_comment_lines(in,
'#');
1241 AssertThrow(line ==
"MeshVersionFormatted 0", ExcInvalidDBMESHInput(line));
1243 skip_empty_lines(in);
1247 AssertThrow(line ==
"Dimension", ExcInvalidDBMESHInput(line));
1248 unsigned int dimension;
1250 AssertThrow(dimension == dim, ExcDBMESHWrongDimension(dimension));
1251 skip_empty_lines(in);
1264 while (
getline(in, line), line.find(
"# END") == std::string::npos)
1266 skip_empty_lines(in);
1271 AssertThrow(line ==
"Vertices", ExcInvalidDBMESHInput(line));
1273 unsigned int n_vertices;
1277 std::vector<Point<spacedim>>
vertices(n_vertices);
1278 for (
unsigned int vertex = 0; vertex < n_vertices; ++vertex)
1281 for (
unsigned int d = 0; d < dim; ++d)
1288 skip_empty_lines(in);
1294 AssertThrow(line ==
"Edges", ExcInvalidDBMESHInput(line));
1307 skip_empty_lines(in);
1316 AssertThrow(line ==
"CrackedEdges", ExcInvalidDBMESHInput(line));
1328 skip_empty_lines(in);
1334 AssertThrow(line ==
"Quadrilaterals", ExcInvalidDBMESHInput(line));
1337 {0, 1, 5, 4, 2, 3, 7, 6}};
1338 std::vector<CellData<dim>> cells;
1340 unsigned int n_cells;
1342 for (
unsigned int cell = 0; cell < n_cells; ++cell)
1346 cells.emplace_back();
1354 (
static_cast<unsigned int>(cells.back().vertices[i]) <=
1356 ExcInvalidVertexIndex(cell, cells.back().vertices[i]));
1358 --cells.back().vertices[i];
1366 skip_empty_lines(in);
1374 while (
getline(in, line), ((line.find(
"End") == std::string::npos) && (in)))
1386template <
int dim,
int spacedim>
1390 Assert(
tria !=
nullptr, ExcNoTriangulationSelected());
1393 const auto reference_cell = ReferenceCells::get_hypercube<dim>();
1397 std::getline(in, line);
1399 unsigned int n_vertices;
1400 unsigned int n_cells;
1404 std::getline(in, line);
1407 std::getline(in, line);
1410 for (
unsigned int i = 0; i < 8; ++i)
1411 std::getline(in, line);
1414 std::vector<CellData<dim>> cells(n_cells);
1426 in >> cell.vertices[reference_cell.exodusii_vertex_to_deal_vertex(i)];
1430 std::vector<Point<spacedim>>
vertices(n_vertices);
1433 for (
unsigned int d = 0; d < spacedim; ++d)
1435 for (
unsigned int d = spacedim; d < 3; ++d)
1450template <
int dim,
int spacedim>
1454 Assert(
tria !=
nullptr, ExcNoTriangulationSelected());
1472 std::getline(in, line);
1480 if ((line.size() > 0) && (line.back() ==
'\r'))
1481 line.erase(line.size() - 1);
1486 if (line.find(
'#') != std::string::npos)
1487 line.erase(line.find(
'#'), std::string::npos);
1488 while ((line.size() > 0) && (line.back() ==
' '))
1489 line.erase(line.size() - 1);
1491 if (line.size() > 0)
1514 ExcMessage(
"deal.II can currently only read version 0.1 "
1515 "of the mphtxt file format."));
1522 for (
unsigned int i = 0; i <
n_tags; ++i)
1535 for (
unsigned int i = 0; i <
n_types; ++i)
1568 ExcMessage(
"Expected '4 Mesh', but got '" + s +
"'."));
1571 unsigned int version;
1581 "The mesh file uses a different number of space dimensions "
1582 "than the triangulation you want to read it into."));
1584 unsigned int n_vertices;
1590 std::vector<Point<spacedim>>
vertices(n_vertices);
1591 for (
unsigned int v = 0; v < n_vertices; ++v)
1622 std::vector<CellData<dim>> cells;
1627 for (
unsigned int type = 0; type <
n_types; ++type)
1641 static const std::map<std::string, ReferenceCell>
name_to_type = {
1652 ExcMessage(
"The input file contains a cell type <" +
1654 "> that the reader does not "
1655 "current support"));
1676 ExcMessage(
"Triangles should not appear in input files "
1684 "Quadrilaterals should not appear in input files "
1691 ExcMessage(
"Tetrahedra should not appear in input files "
1692 "for 1d or 2d meshes."));
1699 "Prisms (wedges) should not appear in input files "
1700 "for 1d or 2d meshes."));
1721 for (
unsigned int e = 0; e <
n_elements; ++e)
1736 cells.emplace_back();
1751 cells.emplace_back();
1766 cells.emplace_back();
1802 cells[cells.size() -
n_elements + e].material_id =
1814 cells[cells.size() -
n_elements + e].material_id =
1826 cells[cells.size() -
n_elements + e].material_id =
1853 if (line.vertices[1] < line.vertices[0])
1854 std::swap(line.vertices[0], line.vertices[1]);
1859 return std::lexicographical_compare(a.vertices.begin(),
1881 Assert((face.vertices.size() == 3) || (face.vertices.size() == 4),
1883 std::sort(face.vertices.begin(), face.vertices.end());
1888 return std::lexicographical_compare(a.vertices.begin(),
1898 for (
const auto &cell :
tria->active_cell_iterators())
1899 for (
const auto &face : cell->face_iterators())
1900 if (face->at_boundary())
1907 {face->vertex_index(0), face->vertex_index(1)}};
1917 const std::array<unsigned int, 2>
1919 return std::lexicographical_compare(
1922 face_vertex_indices.begin(),
1923 face_vertex_indices.end());
1930 face->set_boundary_id(p->boundary_id);
1939 face->n_vertices());
1940 for (
unsigned int v = 0; v < face->n_vertices(); ++v)
1951 const std::vector<unsigned int>
1953 return std::lexicographical_compare(
1956 face_vertex_indices.begin(),
1957 face_vertex_indices.end());
1963 face->set_boundary_id(p->boundary_id);
1968 for (
unsigned int e = 0; e < face->n_lines(); ++e)
1970 const auto edge = face->line(e);
1973 {
edge->vertex_index(0),
edge->vertex_index(1)}};
1984 const std::array<unsigned int, 2>
1986 return std::lexicographical_compare(
1989 edge_vertex_indices.begin(),
1990 edge_vertex_indices.end());
1997 edge->set_boundary_id(p->boundary_id);
2006template <
int dim,
int spacedim>
2010 Assert(
tria !=
nullptr, ExcNoTriangulationSelected());
2013 unsigned int n_vertices;
2014 unsigned int n_cells;
2020 std::array<std::map<int, int>, 4>
tag_maps;
2026 if (line ==
"@f$NOD")
2028 else if (line ==
"@f$MeshFormat")
2040 in >> version >> file_type >>
data_size;
2051 AssertThrow(line ==
"@f$EndMeshFormat", ExcInvalidGMSHInput(line));
2055 if (line ==
"@f$PhysicalNames")
2061 while (line !=
"@f$EndPhysicalNames");
2066 if (line ==
"@f$Entities")
2071 for (
unsigned int i = 0; i < n_points; ++i)
2096 ExcMessage(
"More than one tag is not supported!"));
2103 for (
unsigned int i = 0; i <
n_curves; ++i)
2117 ExcMessage(
"More than one tag is not supported!"));
2127 for (
unsigned int j = 0;
j < n_points; ++
j)
2131 for (
unsigned int i = 0; i <
n_surfaces; ++i)
2145 ExcMessage(
"More than one tag is not supported!"));
2158 for (
unsigned int i = 0; i <
n_volumes; ++i)
2172 ExcMessage(
"More than one tag is not supported!"));
2186 AssertThrow(line ==
"@f$EndEntities", ExcInvalidGMSHInput(line));
2191 if (line ==
"@f$PartitionedEntities")
2197 while (line !=
"@f$EndPartitionedEntities");
2204 AssertThrow(line ==
"@f$Nodes", ExcInvalidGMSHInput(line));
2221 std::vector<Point<spacedim>>
vertices(n_vertices);
2268 in >>
x[0] >>
x[1] >>
x[2];
2273 for (
unsigned int d = 0; d < spacedim; ++d)
2294 static const std::string
end_nodes_marker[] = {
"@f$ENDNOD",
"@f$EndNodes"};
2296 ExcInvalidGMSHInput(line));
2302 ExcInvalidGMSHInput(line));
2324 std::vector<CellData<dim>> cells;
2336 {0, 1, 5, 4, 2, 3, 7, 6}};
2340 unsigned int material_id;
2420 for (
unsigned int i = 1; i <
n_tags; ++i)
2425 else if (cell_type == 2)
2427 else if (cell_type == 3)
2429 else if (cell_type == 4)
2431 else if (cell_type == 5)
2442 else if (cell_type == 2)
2444 else if (cell_type == 3)
2446 else if (cell_type == 4)
2448 else if (cell_type == 5)
2474 if (((cell_type == 1) && (dim == 1)) ||
2475 ((cell_type == 2) && (dim == 2)) ||
2476 ((cell_type == 3) && (dim == 2)) ||
2477 ((cell_type == 4) && (dim == 3)) ||
2478 ((cell_type == 5) && (dim == 3)))
2481 unsigned int vertices_per_cell = 0;
2483 vertices_per_cell = 2;
2484 else if (cell_type == 2)
2485 vertices_per_cell = 3;
2486 else if (cell_type == 3)
2487 vertices_per_cell = 4;
2488 else if (cell_type == 4)
2489 vertices_per_cell = 4;
2490 else if (cell_type == 5)
2491 vertices_per_cell = 8;
2495 "Number of nodes does not coincide with the "
2496 "number required for this object"));
2499 cells.emplace_back();
2501 cell.vertices.resize(vertices_per_cell);
2502 for (
unsigned int i = 0; i < vertices_per_cell; ++i)
2505 if (vertices_per_cell ==
2507 in >> cell.vertices[dim == 3 ?
2511 in >> cell.vertices[i];
2516 std::numeric_limits<types::material_id>::max(),
2520 std::numeric_limits<types::material_id>::max()));
2525 cell.material_id = material_id;
2528 for (
unsigned int i = 0; i < vertices_per_cell; ++i)
2539 cell.vertices[i] = vertex;
2542 else if ((cell_type == 1) &&
2543 ((dim == 2) || (dim == 3)))
2547 in >>
subcelldata.boundary_lines.back().vertices[0] >>
2552 std::numeric_limits<types::boundary_id>::max(),
2556 std::numeric_limits<types::boundary_id>::max()));
2567 for (
unsigned int &vertex :
2581 else if ((cell_type == 2 || cell_type == 3) &&
2585 unsigned int vertices_per_cell = 0;
2588 vertices_per_cell = 3;
2589 else if (cell_type == 3)
2590 vertices_per_cell = 4;
2595 subcelldata.boundary_quads.back().vertices.resize(
2598 for (
unsigned int i = 0; i < vertices_per_cell; ++i)
2599 in >>
subcelldata.boundary_quads.back().vertices[i];
2603 std::numeric_limits<types::boundary_id>::max(),
2607 std::numeric_limits<types::boundary_id>::max()));
2618 for (
unsigned int &vertex :
2631 else if (cell_type == 15)
2655 AssertThrow(
false, ExcGmshUnsupportedGeometry(cell_type));
2665 ExcInvalidGMSHInput(line));
2679 if (
pair.second == 1u)
2694#ifdef DEAL_II_GMSH_WITH_API
2695template <
int dim,
int spacedim>
2699 Assert(
tria !=
nullptr, ExcNoTriangulationSelected());
2702 {{15, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {7, 5}, {6, 6}, {5, 7}}};
2705 const std::array<std::vector<unsigned int>, 8>
gmsh_to_dealii = {
2712 {{0, 1, 2, 3, 4, 5}},
2713 {{0, 1, 3, 2, 4, 5, 7, 6}}}};
2715 std::vector<Point<spacedim>>
vertices;
2716 std::vector<CellData<dim>> cells;
2727 gmsh::option::setNumber(
"General.Verbosity", 0);
2731 ExcMessage(
"You are trying to read a gmsh file with dimension " +
2732 std::to_string(gmsh::model::getDimension()) +
2733 " into a grid of dimension " + std::to_string(dim)));
2738 gmsh::model::mesh::removeDuplicateNodes();
2739 gmsh::model::mesh::renumberNodes();
2741 std::vector<double>
coord;
2743 gmsh::model::mesh::getNodes(
2750 for (
unsigned int d = 0; d < spacedim; ++d)
2754 for (
unsigned int d = spacedim; d < 3; ++d)
2756 ExcMessage(
"The grid you are reading contains nodes that are "
2757 "nonzero in the coordinate with index " +
2759 ", but you are trying to save "
2760 "it on a grid embedded in a " +
2761 std::to_string(spacedim) +
" dimensional space."));
2768 std::vector<std::pair<int, int>>
entities;
2769 gmsh::model::getEntities(
entities);
2782 gmsh::model::getPhysicalGroupsForEntity(
entity_dim,
2795 std::map<std::string, int>
id_names;
2803 const auto &name =
it.first;
2804 const auto &
id =
it.second;
2805 if (
entity_dim == dim && name ==
"MaterialID")
2810 else if (
entity_dim < dim && name ==
"BoundaryID")
2815 else if (name ==
"ManifoldID")
2843 gmsh::model::mesh::getElements(
2852 for (
unsigned int j = 0;
j < elements.
size(); ++
j)
2856 cells.emplace_back(n_vertices);
2857 auto &cell = cells.back();
2858 for (
unsigned int v = 0; v < n_vertices; ++v)
2865 cell.manifold_id = manifold_id;
2866 cell.material_id = boundary_id;
2870 subcelldata.boundary_quads.emplace_back(n_vertices);
2872 for (
unsigned int v = 0; v < n_vertices; ++v)
2876 face.manifold_id = manifold_id;
2877 face.boundary_id = boundary_id;
2881 subcelldata.boundary_lines.emplace_back(n_vertices);
2883 for (
unsigned int v = 0; v < n_vertices; ++v)
2887 line.manifold_id = manifold_id;
2888 line.boundary_id = boundary_id;
2894 for (
unsigned int j = 0;
j < elements.
size(); ++
j)
2907 if (
pair.second == 1u)
2926template <
int dim,
int spacedim>
2931 unsigned int & n_vars,
2932 unsigned int & n_vertices,
2933 unsigned int & n_cells,
2934 std::vector<unsigned int> &
IJK,
2969 std::string::size_type
pos =
header.find(
'=');
2971 while (
pos !=
static_cast<std::string::size_type
>(std::string::npos))
2983 std::vector<std::string> entries =
2987 for (
unsigned int i = 0; i < entries.size(); ++i)
2999 while (entries[i][0] ==
'"')
3001 if (entries[i] ==
"\"X\"")
3003 else if (entries[i] ==
"\"Y\"")
3011 else if (entries[i] ==
"\"Z\"")
3029 "Tecplot file must contain at least one variable for each dimension"));
3030 for (
unsigned int d = 1; d < dim; ++d)
3034 "Tecplot file must contain at least one variable for each dimension."));
3039 "ZONETYPE=FELINESEG") &&
3043 "ZONETYPE=FEQUADRILATERAL") &&
3047 "ZONETYPE=FEBRICK") &&
3055 "The tecplot file contains an unsupported ZONETYPE."));
3058 "DATAPACKING=POINT"))
3061 "DATAPACKING=BLOCK"))
3084 "ET=QUADRILATERAL") &&
3096 "The tecplot file contains an unsupported ElementType."));
3104 dim > 1 ||
IJK[1] == 1,
3106 "Parameter 'J=' found in tecplot, although this is only possible for dimensions greater than 1."));
3112 dim > 2 ||
IJK[2] == 1,
3114 "Parameter 'K=' found in tecplot, although this is only possible for dimensions greater than 2."));
3129 for (
unsigned int d = 0; d < dim; ++d)
3134 "Tecplot file does not contain a complete and consistent set of parameters"));
3135 n_vertices *=
IJK[d];
3136 n_cells *= (
IJK[d] - 1);
3144 "Tecplot file does not contain a complete and consistent set of parameters"));
3154 "Tecplot file does not contain a complete and consistent set of parameters"));
3164 const unsigned int dim = 2;
3165 const unsigned int spacedim = 2;
3166 Assert(
tria !=
nullptr, ExcNoTriangulationSelected());
3170 skip_comment_lines(in,
'#');
3173 std::string line,
header;
3180 std::string
letters =
"abcdfghijklmnopqrstuvwxyzABCDFGHIJKLMNOPQRSTUVWXYZ";
3183 while (line.find_first_of(
letters) != std::string::npos)
3193 std::vector<unsigned int>
IJK(dim);
3194 unsigned int n_vars, n_vertices, n_cells;
3197 parse_tecplot_header(
header,
3212 std::vector<Point<spacedim>>
vertices(n_vertices + 1);
3215 std::vector<CellData<dim>> cells(n_cells);
3231 unsigned int next_index = 0;
3256 for (
unsigned int i = 1; i < n_vars; ++i)
3268 if ((next_index < dim) && (i ==
tecplot2deal[next_index]))
3271 for (
unsigned int j = 1;
j < n_vertices + 1; ++
j)
3279 for (
unsigned int j = 1;
j < n_vertices + 1; ++
j)
3291 std::vector<double> vars(n_vars);
3299 for (
unsigned int d = 0; d < dim; ++d)
3305 for (
unsigned int v = 2; v < n_vertices + 1; ++v)
3307 for (
unsigned int i = 0; i < n_vars; ++i)
3313 for (
unsigned int i = 0; i < dim; ++i)
3322 unsigned int I =
IJK[0], J =
IJK[1];
3324 unsigned int cell = 0;
3326 for (
unsigned int j = 0;
j < J - 1; ++
j)
3327 for (
unsigned int i = 1; i < I; ++i)
3329 cells[cell].vertices[0] = i +
j * I;
3330 cells[cell].vertices[1] = i + 1 +
j * I;
3331 cells[cell].vertices[2] = i + (
j + 1) * I;
3332 cells[cell].vertices[3] = i + 1 + (
j + 1) * I;
3338 for (
unsigned int i = 1; i < I + 1; ++i)
3345 for (
unsigned int j = 1;
j < J - 1; ++
j)
3368 for (
unsigned int i = 0; i < n_cells; ++i)
3391template <
int dim,
int spacedim>
3400template <
int dim,
int spacedim>
3408#ifdef DEAL_II_WITH_ASSIMP
3417 importer.ReadFile(
filename.c_str(),
3427 ExcMessage(
"Input file contains no meshes."));
3440 std::vector<Point<spacedim>>
vertices;
3441 std::vector<CellData<dim>> cells;
3449 {0, 1, 5, 4, 2, 3, 7, 6}};
3460 ExcMessage(
"Incompatible mesh " + std::to_string(m) +
3461 "/" + std::to_string(
scene->mNumMeshes)));
3467 ExcMessage(
"Incompatible mesh " + std::to_string(m) +
3468 "/" + std::to_string(
scene->mNumMeshes)));
3472 const unsigned int n_vertices =
mesh->mNumVertices;
3476 const unsigned int n_faces =
mesh->mNumFaces;
3482 for (
unsigned int i = 0; i < n_vertices; ++i)
3483 for (
unsigned int d = 0; d < spacedim; ++d)
3487 for (
unsigned int i = 0; i < n_faces; ++i)
3504 ExcMessage(
"Face " + std::to_string(i) +
" of mesh " +
3505 std::to_string(m) +
" has " +
3507 " vertices. We expected only " +
3522 if (cells.size() == 0)
3553#ifdef DEAL_II_TRILINOS_WITH_SEACAS
3571 [](
unsigned char c) { return std::toupper(c); });
3572 const std::string
numbers =
"0123456789";
3611 template <
int dim,
int spacedim = dim>
3612 std::pair<SubCellData, std::vector<std::vector<int>>>
3653 std::vector<int> elements(
n_sides);
3654 std::vector<int> faces(
n_sides);
3680 std::vector<std::pair<std::size_t, std::vector<int>>>
3692 [](
const auto &a,
const auto &b) {
3693 return std::lexicographical_compare(a.second.begin(),
3738 for (
unsigned int j = 0;
j < face_reference_cell.
n_vertices();
3753 for (
unsigned int j = 0;
j < face_reference_cell.
n_vertices();
3770template <
int dim,
int spacedim>
3776#ifdef DEAL_II_TRILINOS_WITH_SEACAS
3789 ExcMessage(
"ExodusII failed to open the specified input file."));
3819 std::vector<Point<spacedim>>
vertices;
3822 std::vector<double>
xs(n_nodes);
3823 std::vector<double>
ys(n_nodes);
3824 std::vector<double>
zs(n_nodes);
3852 std::vector<CellData<dim>> cells;
3884 ", which does not match the topological mesh dimension " +
3885 std::to_string(dim) +
"."));
3908 connection[
elem_n + i] - 1;
3911 cells.push_back(std::move(cell));
3935template <
int dim,
int spacedim>
3949 if (std::find_if(line.begin(), line.end(), [](
const char c) {
3954 for (
int i = line.size() - 1; i >= 0; --i)
3955 in.putback(line[i]);
3965template <
int dim,
int spacedim>
3976 while (in.get() !=
'\n')
3986 skip_empty_lines(in);
3991template <
int dim,
int spacedim>
4014 for (
unsigned int i = 0; i < cells.size(); ++i)
4016 for (
const auto vertex : cells[i].vertices)
4030 out <<
"# cell " << i << std::endl;
4032 for (
const auto vertex : cells[i].vertices)
4036 out <<
"set label \"" << i <<
"\" at " <<
center(0) <<
',' <<
center(1)
4037 <<
" center" << std::endl;
4040 for (
unsigned int f = 0; f < 2; ++f)
4042 <<
vertices[cells[i].vertices[f]](1) <<
" to "
4046 for (
unsigned int f = 2; f < 4; ++f)
4050 <<
vertices[cells[i].vertices[f]](1) << std::endl;
4056 <<
"set nokey" << std::endl
4058 <<
"] " <<
min_y << std::endl
4059 <<
"pause -1" << std::endl;
4070 for (
const auto &cell : cells)
4073 out <<
vertices[cell.vertices[0]] << std::endl
4074 <<
vertices[cell.vertices[1]] << std::endl
4078 out <<
vertices[cell.vertices[1]] << std::endl
4079 <<
vertices[cell.vertices[2]] << std::endl
4083 out <<
vertices[cell.vertices[3]] << std::endl
4084 <<
vertices[cell.vertices[2]] << std::endl
4088 out <<
vertices[cell.vertices[0]] << std::endl
4089 <<
vertices[cell.vertices[3]] << std::endl
4093 out <<
vertices[cell.vertices[4]] << std::endl
4094 <<
vertices[cell.vertices[5]] << std::endl
4098 out <<
vertices[cell.vertices[5]] << std::endl
4099 <<
vertices[cell.vertices[6]] << std::endl
4103 out <<
vertices[cell.vertices[7]] << std::endl
4104 <<
vertices[cell.vertices[6]] << std::endl
4108 out <<
vertices[cell.vertices[4]] << std::endl
4109 <<
vertices[cell.vertices[7]] << std::endl
4113 out <<
vertices[cell.vertices[0]] << std::endl
4114 <<
vertices[cell.vertices[4]] << std::endl
4118 out <<
vertices[cell.vertices[1]] << std::endl
4119 <<
vertices[cell.vertices[5]] << std::endl
4123 out <<
vertices[cell.vertices[2]] << std::endl
4124 <<
vertices[cell.vertices[6]] << std::endl
4128 out <<
vertices[cell.vertices[3]] << std::endl
4129 <<
vertices[cell.vertices[7]] << std::endl
4137template <
int dim,
int spacedim>
4153 const std::string::size_type
slashpos = name.find_last_of(
'/');
4154 const std::string::size_type
dotpos = name.find_last_of(
'.');
4158 std::string
ext = name.substr(
dotpos + 1);
4167 else if (
format == exodusii)
4169 read_exodusii(name);
4173 std::ifstream in(name.c_str());
4179template <
int dim,
int spacedim>
4226 ExcMessage(
"There is no read_assimp(istream &) function. "
4227 "Use the read_assimp(string &filename, ...) "
4228 "functions, instead."));
4233 ExcMessage(
"There is no read_exodusii(istream &) function. "
4234 "Use the read_exodusii(string &filename, ...) "
4235 "function, instead."));
4246template <
int dim,
int spacedim>
4275 return ".unknown_format";
4281template <
int dim,
int spacedim>
4338template <
int dim,
int spacedim>
4342 return "dbmesh|exodusii|msh|unv|vtk|vtu|ucd|abaqus|xda|tecplot|assimp";
4349 template <
int dim,
int spacedim>
4350 Abaqus_to_UCD<dim, spacedim>::Abaqus_to_UCD()
4363 from_string(T &t,
const std::string &s, std::ios_base &(*f)(std::ios_base &))
4365 std::istringstream
iss(s);
4366 return !(
iss >> f >> t).
fail();
4376 for (
const char c : s)
4391 template <
int dim,
int spacedim>
4393 Abaqus_to_UCD<dim, spacedim>::read_in_abaqus(std::istream &
input_stream)
4405 std::transform(line.begin(), line.end(), line.begin(),
::toupper);
4407 if (line.compare(
"*HEADING") == 0 || line.compare(0, 2,
"**") == 0 ||
4408 line.compare(0, 5,
"*PART") == 0)
4417 else if (line.compare(0, 5,
"*NODE") == 0)
4431 std::vector<double>
node(spacedim + 1);
4433 std::istringstream
iss(line);
4435 for (
unsigned int i = 0; i < spacedim + 1; ++i)
4438 node_list.push_back(
node);
4441 else if (line.compare(0, 8,
"*ELEMENT") == 0)
4458 if (idx != std::string::npos)
4472 std::istringstream
iss(line);
4485 cell[0] =
static_cast<double>(
material);
4486 cell_list.push_back(cell);
4489 else if (line.compare(0, 8,
"*SURFACE") == 0)
4500 const std::string
name_key =
"NAME=";
4522 std::transform(line.begin(),
4530 std::istringstream
iss(line);
4538 const std::string
elset_name = line.substr(0, line.find(
','));
4545 const std::vector<int> cells = elsets_list[
elset_name];
4546 for (
const int cell : cells)
4570 else if (line.compare(0, 6,
"*ELSET") == 0)
4576 const std::string
elset_key =
"*ELSET, ELSET=";
4577 const std::size_t idx = line.find(
elset_key);
4578 if (idx != std::string::npos)
4580 const std::string
comma =
",";
4597 std::vector<int> elements;
4598 const std::size_t
generate_idx = line.find(
"GENERATE");
4603 std::istringstream
iss(line);
4617 "While reading an ABAQUS file, the reader "
4618 "expected a comma but found a <") +
4619 comma +
"> in the line <" + line +
">."));
4624 "While reading an ABAQUS file, the reader encountered "
4625 "a GENERATE statement in which the upper bound <") +
4627 "> for the element numbers is not larger or equal "
4628 "than the lower bound <" +
4632 if (
iss.rdbuf()->in_avail() != 0)
4637 "While reading an ABAQUS file, the reader "
4638 "expected a comma but found a <") +
4639 comma +
"> in the line <" + line +
">."));
4642 elements.push_back(i);
4655 std::istringstream
iss(line);
4665 "While reading an ABAQUS file, the reader "
4666 "expected a comma but found a <") +
4667 comma +
"> in the line <" + line +
">."));
4669 elements.push_back(
elid);
4678 else if (line.compare(0, 5,
"*NSET") == 0)
4687 else if (line.compare(0, 14,
"*SOLID SECTION") == 0)
4722 template <
int dim,
int spacedim>
4724 Abaqus_to_UCD<dim, spacedim>::get_global_node_numbers(
4820 template <
int dim,
int spacedim>
4822 Abaqus_to_UCD<dim, spacedim>::write_out_avs_ucd(std::ostream &output)
const
4835 output <<
"# Abaqus to UCD mesh conversion" << std::endl;
4836 output <<
"# Mesh type: AVS UCD" << std::endl;
4865 output << node_list.size() <<
"\t" << (cell_list.size() + face_list.size())
4866 <<
"\t0\t0\t0" << std::endl;
4869 output.precision(8);
4873 for (
const auto &
node : node_list)
4876 output <<
node[0] <<
"\t";
4879 output.setf(std::ios::scientific, std::ios::floatfield);
4880 for (
unsigned int jj = 1;
jj < spacedim + 1; ++
jj)
4886 output << 0.0 <<
"\t";
4889 output << 0.0 <<
"\t";
4891 output << std::endl;
4892 output.unsetf(std::ios::floatfield);
4896 for (
unsigned int ii = 0;
ii < cell_list.
size(); ++
ii)
4898 output <<
ii + 1 <<
"\t" << cell_list[
ii][0] <<
"\t"
4899 << (dim == 2 ?
"quad" :
"hex") <<
"\t";
4902 output << cell_list[
ii][
jj] <<
"\t";
4904 output << std::endl;
4908 for (
unsigned int ii = 0;
ii < face_list.
size(); ++
ii)
4910 output <<
ii + 1 <<
"\t" << face_list[
ii][0] <<
"\t"
4911 << (dim == 2 ?
"line" :
"quad") <<
"\t";
4914 output << face_list[
ii][
jj] <<
"\t";
4916 output << std::endl;
4923#include "grid_in.inst"
value_type * data() const noexcept
void read_vtk(std::istream &in)
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)
void read_comsol_mphtxt(std::istream &in)
static void skip_comment_lines(std::istream &in, const char comment_start)
void attach_triangulation(Triangulation< dim, spacedim > &tria)
void read_msh(std::istream &in)
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_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
unsigned int get_dimension() 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()
#define Assert(cond, exc)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static ::ExceptionBase & ExcNeedsExodusII()
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
static ::ExceptionBase & ExcInvalidState()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
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
constexpr const ReferenceCell Vertex
constexpr const ReferenceCell Line
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)
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
::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
static std_cxx20::ranges::iota_view< unsigned int, unsigned int > vertex_indices()
std::vector< std::vector< int > > id_to_sideset_ids
const ::Triangulation< dim, spacedim > & tria