From 2220767bb94be3a75adda89b7d73e5442b52bd6d Mon Sep 17 00:00:00 2001 From: David Wells Date: Thu, 15 Apr 2021 09:18:39 -0400 Subject: [PATCH] Merge the two read_xda functions. --- source/grid/grid_in.cc | 138 ++++++++--------------------------------- 1 file changed, 27 insertions(+), 111 deletions(-) diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index 56f2ef865f..fde2b74b14 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -1367,153 +1367,69 @@ GridIn::read_dbmesh(std::istream &in) template void -GridIn::read_xda(std::istream &) -{ - Assert(false, ExcNotImplemented()); -} - - - -template <> -void -GridIn<2>::read_xda(std::istream &in) -{ - Assert(tria != nullptr, ExcNoTriangulationSelected()); - AssertThrow(in, ExcIO()); - - const auto reference_cell = ReferenceCells::get_hypercube<2>(); - - std::string line; - // skip comments at start of file - getline(in, line); - - - unsigned int n_vertices; - unsigned int n_cells; - - // read cells, throw away rest of line - in >> n_cells; - getline(in, line); - - in >> n_vertices; - getline(in, line); - - // ignore following 8 lines - for (unsigned int i = 0; i < 8; ++i) - getline(in, line); - - // set up array of cells - std::vector> cells(n_cells); - SubCellData subcelldata; - - for (unsigned int cell = 0; cell < n_cells; ++cell) - { - // note that since in the input - // file we found the number of - // cells at the top, there - // should still be input here, - // so check this: - AssertThrow(in, ExcIO()); - - // XDA happens to use ExodusII's numbering because XDA/XDR is libMesh's - // native format, and libMesh's node numberings come from ExodusII: - for (unsigned int i = 0; i < GeometryInfo<2>::vertices_per_cell; i++) - in >> cells[cell].vertices[reference_cell.exodusii_vertex_to_deal_vertex(i)]; - } - - - - // set up array of vertices - std::vector> vertices(n_vertices); - for (unsigned int vertex = 0; vertex < n_vertices; ++vertex) - { - double x[3]; - - // read vertex - in >> x[0] >> x[1] >> x[2]; - - // store vertex - for (unsigned int d = 0; d < 2; ++d) - vertices[vertex](d) = x[d]; - } - AssertThrow(in, ExcIO()); - - // do some clean-up on vertices... - GridTools::delete_unused_vertices(vertices, cells, subcelldata); - // ... and cells - GridReordering<2>::invert_all_cells_of_negative_grid(vertices, cells, true); - GridReordering<2>::reorder_cells(cells, true); - tria->create_triangulation(vertices, cells, subcelldata); -} - - - -template <> -void -GridIn<3>::read_xda(std::istream &in) +GridIn::read_xda(std::istream &in) { Assert(tria != nullptr, ExcNoTriangulationSelected()); AssertThrow(in, ExcIO()); - const auto reference_cell = ReferenceCells::get_hypercube<3>(); + const auto reference_cell = ReferenceCells::get_hypercube(); std::string line; // skip comments at start of file - getline(in, line); + std::getline(in, line); unsigned int n_vertices; unsigned int n_cells; // read cells, throw away rest of line in >> n_cells; - getline(in, line); + std::getline(in, line); in >> n_vertices; - getline(in, line); + std::getline(in, line); // ignore following 8 lines for (unsigned int i = 0; i < 8; ++i) - getline(in, line); + std::getline(in, line); // set up array of cells - std::vector> cells(n_cells); - SubCellData subcelldata; + std::vector> cells(n_cells); + SubCellData subcelldata; - for (unsigned int cell = 0; cell < n_cells; ++cell) + for (CellData &cell : cells) { - // note that since in the input - // file we found the number of - // cells at the top, there - // should still be input here, - // so check this: + // note that since in the input file we found the number of cells at the + // top, there should still be input here, so check this: AssertThrow(in, ExcIO()); // XDA happens to use ExodusII's numbering because XDA/XDR is libMesh's // native format, and libMesh's node numberings come from ExodusII: - for (unsigned int i = 0; i < GeometryInfo<3>::vertices_per_cell; i++) - in >> cells[cell].vertices[reference_cell.exodusii_vertex_to_deal_vertex(i)]; + for (unsigned int i = 0; i < GeometryInfo::vertices_per_cell; i++) + in >> cell.vertices[reference_cell.exodusii_vertex_to_deal_vertex(i)]; } // set up array of vertices - std::vector> vertices(n_vertices); - for (unsigned int vertex = 0; vertex < n_vertices; ++vertex) + std::vector> vertices(n_vertices); + for (Point &vertex : vertices) { - double x[3]; - - // read vertex - in >> x[0] >> x[1] >> x[2]; - - // store vertex - for (unsigned int d = 0; d < 3; ++d) - vertices[vertex](d) = x[d]; + for (unsigned int d = 0; d < spacedim; ++d) + in >> vertex[d]; + for (unsigned int d = spacedim; d < 3; ++d) + { + // file is always in 3D + double dummy; + in >> dummy; + } } AssertThrow(in, ExcIO()); // do some clean-up on vertices... GridTools::delete_unused_vertices(vertices, cells, subcelldata); // ... and cells - GridReordering<3>::invert_all_cells_of_negative_grid(vertices, cells, true); - GridReordering<3>::reorder_cells(cells, true); + GridReordering::invert_all_cells_of_negative_grid(vertices, + cells, + true); + GridReordering::reorder_cells(cells, true); tria->create_triangulation(vertices, cells, subcelldata); } -- 2.39.5