From beabf24a609f5b71e483092842c7558f6e96d95f Mon Sep 17 00:00:00 2001 From: bangerth Date: Fri, 27 Apr 2012 09:18:38 +0000 Subject: [PATCH] Patch by Valentin Zingan: Read in UNV format produced by the Salome project. git-svn-id: https://svn.dealii.org/trunk@25459 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 5 + deal.II/include/deal.II/grid/grid_in.h | 54 +++++- deal.II/source/grid/grid_in.cc | 239 ++++++++++++++++++++++++- 3 files changed, 296 insertions(+), 2 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index eb9b381013..90f703f5a8 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -175,6 +175,11 @@ enabled due to a missing include file in file

Specific improvements

    +
  1. New: The GridIn::read_unv function can now read meshes generated +by the Salome framework, see http://www.salome-platform.org/ . +
    +(Valentin Zingan, 2012/04/27) +
  2. New: There is now a second DoFTools::map_dofs_to_support_points function that also works for parallel::distributed::Triangulation triangulations. diff --git a/deal.II/include/deal.II/grid/grid_in.h b/deal.II/include/deal.II/grid/grid_in.h index 9ecf9c6e44..a8df701221 100644 --- a/deal.II/include/deal.II/grid/grid_in.h +++ b/deal.II/include/deal.II/grid/grid_in.h @@ -31,7 +31,7 @@ struct SubCellData; /** * This class implements an input mechanism for grid data. It allows to read a * grid structure into a triangulation object. At present, UCD (unstructured - * cell data), DB Mesh, XDA, Gmsh, Tecplot, NetCDF and Cubit are supported as + * cell data), DB Mesh, XDA, Gmsh, Tecplot, NetCDF, UNV, and Cubit are supported as * input format for grid data. Any numerical data after the block of geometric * (vertex locations) and topological (how vertices form cells) information is * ignored. Notice also that at the moment in the codimension 1 case only UCD @@ -137,6 +137,27 @@ struct SubCellData; * that currently only the ASCII format is supported, binary data cannot be * read. * + *
  3. UNV format: this format is generated by the Salome mesh + * generator, see http://www.salome-platform.org/ . + * The sections of the format that the GridIn::read_unv function supports are + * documented here: + *
      + *
    • section 2411: http://www.sdrl.uc.edu/universal-file-formats-for-modal-analysis-testing-1/file-format-storehouse/unv_2411.htm + *
    • section 2412: http://www.sdrl.uc.edu/universal-file-formats-for-modal-analysis-testing-1/file-format-storehouse/unv_2412.htm + *
    • section 2467: http://www.sdrl.uc.edu/universal-file-formats-for-modal-analysis-testing-1/file-format-storehouse/unv_2467.htm + *
    • all sections of this format, even if they may not be supported in + * our reader, can be found here: + * http://www.sdrl.uc.edu/universal-file-formats-for-modal-analysis-testing-1/file-format-storehouse/file-formats + *
    + * Note that Salome, let's say in 2D, can only make a quad mesh on an object that + * has exactly 4 edges (or 4 pieces of the boundary). That means, that if you have + * a more complicated object and would like to mesh it with quads, you will need + * to decompose the object into >= 2 separate objects. Then 1) each of these + * separate objects is meshed, 2) the appropriate groups of cells and/or faces + * associated with each of these separate objects are created, 3) a compound + * mesh is built up, and 4) all numbers that might be associated with some of + * the internal faces of this compound mesh are removed. + * *
  4. Cubit format: deal.II doesn't directly support importing from * Cubit at this time. However, Cubit can export in UCD format using a simple * plug-in, and the resulting UCD file can then be read by this class. The @@ -253,6 +274,8 @@ class GridIn { /// Use GridIn::default_format stored in this object Default, + /// Use read_unv() + unv, /// Use read_ucd() ucd, /// Use read_dbmesh() @@ -296,6 +319,19 @@ class GridIn */ void read (const std::string &in, Format format=Default); + /** + * Read grid data from an unv + * file as generated by the + * Salome mesh generator. + * Numerical data is ignored. + * + * Note the comments on + * generating this file format in + * the general documentation of + * this class. + */ + void read_unv(std::istream &in); + /** * Read grid data from an ucd file. * Numerical data is ignored. @@ -375,6 +411,22 @@ class GridIn */ static std::string get_format_names (); + /** + * Exception + */ + DeclException1(ExcUnknownSectionType, + int, + << "The section type <" << arg1 << "> in an UNV " + << "input file is not implemented."); + + /** + * Exception + */ + DeclException1(ExcUnknownElementType, + int, + << "The element type <" << arg1 << "> in an UNV " + << "input file is not implemented."); + /** * Exception */ diff --git a/deal.II/source/grid/grid_in.cc b/deal.II/source/grid/grid_in.cc index 2a075f091d..c5a10923f5 100644 --- a/deal.II/source/grid/grid_in.cc +++ b/deal.II/source/grid/grid_in.cc @@ -46,6 +46,234 @@ void GridIn::attach_triangulation (Triangulation & } + +// --- --- +// --- read_unv --- +// --- --- + +template +void GridIn::read_unv(std::istream &in) +{ + Assert(tria != 0, ExcNoTriangulationSelected()); + Assert((dim == 2)||(dim == 3), ExcNotImplemented()); + + AssertThrow(in, ExcIO()); + skip_comment_lines(in, '#'); // skip comments (if any) at beginning of file + + int tmp; + + AssertThrow(in, ExcIO()); + in >> tmp; + AssertThrow(in, ExcIO()); + in >> tmp; + + AssertThrow(tmp == 2411, ExcUnknownSectionType(tmp)); // section 2411 describes vertices http://www.sdrl.uc.edu/universal-file-formats-for-modal-analysis-testing-1/file-format-storehouse/unv_2411.htm/ + + std::vector< Point > vertices; // vector of vertex coordinates + std::map vertex_indices; // # vert in unv (key) ---> # vert in deal.II (value) + + int no_vertex = 0; // deal.II + + while(tmp != -1) // we do until reach end of 2411 + { + int no; // unv + int dummy; + double x[3]; + + AssertThrow(in, ExcIO()); + in >> no; + + tmp = no; + if(tmp == -1) + break; + + in >> dummy >> dummy >> dummy; + + AssertThrow(in, ExcIO()); + in >> x[0] >> x[1] >> x[2]; + + vertices.push_back(Point()); + + for(unsigned int d = 0; d < spacedim; d++) + vertices.back()(d) = x[d]; + + vertex_indices[no] = no_vertex; + + no_vertex++; + } + + AssertThrow(in, ExcIO()); + in >> tmp; + AssertThrow(in, ExcIO()); + in >> tmp; + + AssertThrow(tmp == 2412, ExcUnknownSectionType(tmp)); // section 2412 describes elements http://www.sdrl.uc.edu/universal-file-formats-for-modal-analysis-testing-1/file-format-storehouse/unv_2412.htm/ + + std::vector< CellData > cells; // vector of cells + SubCellData subcelldata; + + std::map cell_indices; // # cell in unv (key) ---> # cell in deal.II (value) + std::map line_indices; // # line in unv (key) ---> # line in deal.II (value) + std::map quad_indices; // # quad in unv (key) ---> # quad in deal.II (value) + + int no_cell = 0; // deal.II + int no_line = 0; // deal.II + int no_quad = 0; // deal.II + + while(tmp != -1) // we do until reach end of 2412 + { + int no; // unv + int type; + int dummy; + + AssertThrow(in, ExcIO()); + in >> no; + + tmp = no; + if(tmp == -1) + break; + + in >> type >> dummy >> dummy >> dummy >> dummy; + + AssertThrow((type == 11)||(type == 44)||(type == 115), ExcUnknownElementType(type)); + + if( ((type == 44)&&(dim == 2)) || ((type == 115)&&(dim == 3)) ) // cell + { + cells.push_back(CellData()); + + AssertThrow(in, ExcIO()); + for(unsigned int v = 0; v < GeometryInfo::vertices_per_cell; v++) + in >> cells.back().vertices[v]; + + cells.back().material_id = 0; + + for(unsigned int v = 0; v < GeometryInfo::vertices_per_cell; v++) + cells.back().vertices[v] = vertex_indices[cells.back().vertices[v]]; + + cell_indices[no] = no_cell; + + no_cell++; + } + else if( ((type == 11)&&(dim == 2)) || ((type == 11)&&(dim == 3)) ) // boundary line + { + AssertThrow(in, ExcIO()); + in >> dummy >> dummy >> dummy; + + subcelldata.boundary_lines.push_back(CellData<1>()); + + AssertThrow(in, ExcIO()); + for(unsigned int v = 0; v < 2; v++) + in >> subcelldata.boundary_lines.back().vertices[v]; + + subcelldata.boundary_lines.back().material_id = 0; + + for(unsigned int v = 0; v < 2; v++) + subcelldata.boundary_lines.back().vertices[v] = vertex_indices[subcelldata.boundary_lines.back().vertices[v]]; + + line_indices[no] = no_line; + + no_line++; + } + else if( (type == 44) && (dim == 3) ) // boundary quad + { + subcelldata.boundary_quads.push_back(CellData<2>()); + + AssertThrow(in, ExcIO()); + for(unsigned int v = 0; v < 4; v++) + in >> subcelldata.boundary_quads.back().vertices[v]; + + subcelldata.boundary_quads.back().material_id = 0; + + for(unsigned int v = 0; v < 4; v++) + subcelldata.boundary_quads.back().vertices[v] = vertex_indices[subcelldata.boundary_quads.back().vertices[v]]; + + quad_indices[no] = no_quad; + + no_quad++; + } + } + +// note that so far all materials and bcs are explicitly set to 0 +// if we do not need more info on materials and bcs - this is end of file +// if we do - section 2467 comes + + in >> tmp; // tmp can be either -1 or end-of-file + + if( !in.eof() ) + { + AssertThrow(in, ExcIO()); + in >> tmp; + + AssertThrow(tmp == 2467, ExcUnknownSectionType(tmp)); // section 2467 describes (materials - first and bcs - second) or (bcs - first and materials - second) - sequence depends on which group is created first + // http://www.sdrl.uc.edu/universal-file-formats-for-modal-analysis-testing-1/file-format-storehouse/unv_2467.htm/ + + while(tmp != -1) // we do until reach end of 2467 + { + int n_entities; // number of entities in group + int id; // id is either material or bc + int no; // unv + int dummy; + + AssertThrow(in, ExcIO()); + in >> dummy; + + tmp = dummy; + if(tmp == -1) + break; + + in >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> n_entities; + + AssertThrow(in, ExcIO()); + in >> id; + + int n_lines = (n_entities%2 == 0)?(n_entities/2):((n_entities+1)/2); + + for(int no_line = 0; no_line < n_lines; no_line++) + { + int n_fragments; + + if(no_line == n_lines-1) + n_fragments = (n_entities%2 == 0)?(2):(1); + else + n_fragments = 2; + + for(int no_fragment = 0; no_fragment < n_fragments; no_fragment++) + { + AssertThrow(in, ExcIO()); + in >> dummy >> no >> dummy >> dummy; + + if( cell_indices.count(no) > 0 ) // cell - material + cells[cell_indices[no]].material_id = id; + + if( line_indices.count(no) > 0 ) // boundary line - bc + subcelldata.boundary_lines[line_indices[no]].material_id = id; + + if( quad_indices.count(no) > 0 ) // boundary quad - bc + subcelldata.boundary_quads[quad_indices[no]].material_id = id; + } + } + } + } + + Assert(subcelldata.check_consistency(dim), ExcInternalError()); + + GridTools::delete_unused_vertices(vertices, + cells, + subcelldata); + + if(dim == spacedim) + GridReordering::invert_all_cells_of_negative_grid(vertices, + cells); + + GridReordering::reorder_cells(cells); + + tria->create_triangulation_compatibility(vertices, + cells, + subcelldata); +} + + + template void GridIn::read_ucd (std::istream &in) { @@ -2111,6 +2339,10 @@ void GridIn::read (std::istream& in, read_msh (in); return; + case unv: + read_unv (in); + return; + case ucd: read_ucd (in); return; @@ -2147,6 +2379,8 @@ GridIn::default_suffix (const Format format) return ".dbmesh"; case msh: return ".msh"; + case unv: + return ".unv"; case ucd: return ".inp"; case xda: @@ -2173,6 +2407,9 @@ GridIn::parse_format (const std::string &format_name) if (format_name == "msh") return msh; + if (format_name == "unv") + return unv; + if (format_name == "inp") return ucd; @@ -2216,7 +2453,7 @@ GridIn::parse_format (const std::string &format_name) template std::string GridIn::get_format_names () { - return "dbmesh|msh|ucd|xda|netcdf|tecplot"; + return "dbmesh|msh|unv|ucd|xda|netcdf|tecplot"; } -- 2.39.5