From ad420cc789533e53e66fa509746024d80765c618 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Mon, 10 Sep 2007 15:03:59 +0000 Subject: [PATCH] Added write_lines options to write_msh and write_ucd to solve bug on 3d meshes with boundary id!=0. git-svn-id: https://svn.dealii.org/trunk@15187 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/grid_out.h | 191 +++++++++++++++++- .../source/grid/grid_out.all_dimensions.cc | 16 +- deal.II/deal.II/source/grid/grid_out.cc | 157 +++++++++++++- 3 files changed, 347 insertions(+), 17 deletions(-) diff --git a/deal.II/deal.II/include/grid/grid_out.h b/deal.II/deal.II/include/grid/grid_out.h index c4ffd12356..0135722293 100644 --- a/deal.II/deal.II/include/grid/grid_out.h +++ b/deal.II/deal.II/include/grid/grid_out.h @@ -121,11 +121,34 @@ namespace GridOutFlags * Default: @p false. */ bool write_faces; + /** + * When writing a mesh, write boundary + * lines explicitly if their boundary + * indicator is not the default + * boundary indicator, which is zero. + * This is necessary if you later + * want to re-read the grid and want + * to get the same boundary indicators + * for the different parts of the + * boundary of the triangulation. + * + * It is not necessary if you only want + * to write the triangulation to + * view or print it. + * + * This is used only if + * dim==3, and ignored + * in all other cases. + * + * Default: @p false. + */ + bool write_lines; /** * Constructor. */ - Msh (const bool write_faces = false); + Msh (const bool write_faces = false, + const bool write_lines = false); /** * Declare parameters in * ParameterHandler. @@ -181,11 +204,35 @@ namespace GridOutFlags */ bool write_faces; + /** + * When writing a mesh, write boundary + * lines explicitly if their boundary + * indicator is not the default + * boundary indicator, which is zero. + * This is necessary if you later + * want to re-read the grid and want + * to get the same boundary indicators + * for the different parts of the + * boundary of the triangulation. + * + * It is not necessary if you only want + * to write the triangulation to + * view or print it. + * + * This directive is ignored if + * dim!=3. + * + * Default: @p false. + */ + bool write_lines; + /** * Constructor. */ Ucd (const bool write_preamble = true, - const bool write_faces = false); + const bool write_faces = false, + const bool write_lines = false); + /** * Declare parameters in * ParameterHandler. @@ -1243,6 +1290,58 @@ class GridOut const unsigned int starting_index, std::ostream &out) const; + /** + * Write the grid information about + * lines to @p out. Only those lines + * are printed which are on the boundary + * and which have a boundary indicator + * not equal to zero, since the latter + * is the default for boundary faces. + * + * Since cells and faces are continuously + * numbered, the @p starting_index for + * the numbering of the lines is passed + * also. + * + * This function unfortunately + * can not be included in the + * regular @p write_msh function, + * since it needs special + * treatment for the case + * dim==1 and + * dim==2, in which case + * the edge iterators are + * void*'s and lack the + * member functions which are + * called. We would not actually + * call these functions, but the + * compiler would complain anyway + * when compiling the function + * for dim==1/2. Bad luck. + */ + template + void write_msh_lines (const Triangulation &tria, + const unsigned int starting_index, + std::ostream &out) const; + + /** + * Declaration of the specialization + * of above function for 1d. Does + * nothing. + */ + void write_msh_lines (const Triangulation<1> &tria, + const unsigned int starting_index, + std::ostream &out) const; + + /** + * Declaration of the specialization + * of above function for 2d. Does + * nothing. + */ + void write_msh_lines (const Triangulation<2> &tria, + const unsigned int starting_index, + std::ostream &out) const; + /** * Write the grid information about * faces to @p out. Only those faces @@ -1267,6 +1366,8 @@ class GridOut * would complain anyway when compiling * the function for dim==1. Bad luck. */ + + template void write_ucd_faces (const Triangulation &tria, const unsigned int starting_index, @@ -1278,6 +1379,57 @@ class GridOut * nothing. */ void write_ucd_faces (const Triangulation<1> &tria, + const unsigned int starting_index, + std::ostream &out) const; + + + /** + * Write the grid information about + * lines to @p out. Only those lines + * are printed which are on the boundary + * and which have a boundary indicator + * not equal to zero, since the latter + * is the default for boundary lines. + * + * Since cells, faces and lines + * are continuously numbered, the + * @p starting_index for the + * numbering of the faces is + * passed also. + * + * This function unfortunately can not + * be included in the regular @p write_ucd + * function, since it needs special + * treatment for the case dim==1/2, in + * which case the edge iterators are + * void*'s and lack the member functions + * which are called. We would not actually + * call these functions, but the compiler + * would complain anyway when compiling + * the function for dim==1/2. Bad luck. + */ + + + template + void write_ucd_lines (const Triangulation &tria, + const unsigned int starting_index, + std::ostream &out) const; + + /** + * Declaration of the specialization + * of above function for 1d. Does + * nothing. + */ + void write_ucd_lines (const Triangulation<1> &tria, + const unsigned int starting_index, + std::ostream &out) const; + + /** + * Declaration of the specialization + * of above function for 2d. Does + * nothing. + */ + void write_ucd_lines (const Triangulation<2> &tria, const unsigned int starting_index, std::ostream &out) const; @@ -1308,6 +1460,41 @@ class GridOut * 1d. Simply returns zero. */ unsigned int n_boundary_faces (const Triangulation<1> &tria) const; + + /** + * Return the number of lines in the + * triangulation which have a boundary + * indicator not equal to zero. Only + * these lines are explicitly printed + * in the write_* functions; + * all lines with indicator 255 are + * interior ones and an indicator with + * value zero for faces at the boundary + * are considered default. + * + * This function always returns an empty + * list in one and two dimensions. + * + * The reason for this function is the + * same as for @p write_ucd_faces. See + * there for more information. + */ + template + unsigned int n_boundary_lines (const Triangulation &tria) const; + + /** + * Declaration of the specialization + * of above function for + * 1d. Simply returns zero. + */ + unsigned int n_boundary_lines (const Triangulation<1> &tria) const; + + /** + * Declaration of the specialization + * of above function for + * 2d. Simply returns zero. + */ + unsigned int n_boundary_lines (const Triangulation<2> &tria) const; }; diff --git a/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc b/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc index b79d3b930b..72a2fb3e80 100644 --- a/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc +++ b/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc @@ -59,26 +59,32 @@ namespace GridOutFlags } - Msh::Msh (const bool write_faces) : - write_faces (write_faces) + Msh::Msh (const bool write_faces, + const bool write_lines) : + write_faces (write_faces), + write_lines (write_lines) {} void Msh::declare_parameters (ParameterHandler& param) { param.declare_entry("Write faces", "false", Patterns::Bool()); + param.declare_entry("Write lines", "false", Patterns::Bool()); } void Msh::parse_parameters (ParameterHandler& param) { write_faces = param.get_bool("Write faces"); + write_lines = param.get_bool("Write lines"); } Ucd::Ucd (const bool write_preamble, - const bool write_faces) : + const bool write_faces, + const bool write_lines) : write_preamble (write_preamble), - write_faces (write_faces) + write_faces (write_faces), + write_lines (write_lines) {} @@ -87,6 +93,7 @@ namespace GridOutFlags { param.declare_entry("Write preamble", "true", Patterns::Bool()); param.declare_entry("Write faces", "false", Patterns::Bool()); + param.declare_entry("Write lines", "false", Patterns::Bool()); } @@ -94,6 +101,7 @@ namespace GridOutFlags { write_preamble = param.get_bool("Write preamble"); write_faces = param.get_bool("Write faces"); + write_lines = param.get_bool("Write lines"); } diff --git a/deal.II/deal.II/source/grid/grid_out.cc b/deal.II/deal.II/source/grid/grid_out.cc index 1e7a860492..a2f04de333 100644 --- a/deal.II/deal.II/source/grid/grid_out.cc +++ b/deal.II/deal.II/source/grid/grid_out.cc @@ -333,8 +333,10 @@ void GridOut::write_msh (const Triangulation &tria, // Write cells preamble out << "$ENDNOD" << std::endl << "$ELM" << std::endl - << tria.n_active_cells() + (msh_flags.write_faces ? - n_boundary_faces(tria) : 0) << std::endl; + << tria.n_active_cells() + ( (msh_flags.write_faces ? + n_boundary_faces(tria) :0 ) + + ( msh_flags.write_lines ? + n_boundary_lines(tria) : 0 ) ) << std::endl; /* elm-type @@ -404,10 +406,12 @@ void GridOut::write_msh (const Triangulation &tria, out << std::endl; }; - // write faces with non-zero boundary - // indicator - if (msh_flags.write_faces) + // write faces and lines with + // non-zero boundary indicator + if (msh_flags.write_faces) write_msh_faces (tria, cell_index, out); + if (msh_flags.write_lines) + write_msh_lines (tria, cell_index, out); out << "$ENDELM" << std::endl; @@ -461,9 +465,10 @@ void GridOut::write_ucd (const Triangulation &tria, // start with ucd data out << n_vertices << ' ' - << tria.n_active_cells() + (ucd_flags.write_faces ? - n_boundary_faces(tria) : - 0) + << tria.n_active_cells() + ( (ucd_flags.write_faces ? + n_boundary_faces(tria) : 0) + + (ucd_flags.write_lines ? + n_boundary_lines(tria) : 0) ) << " 0 0 0" // no data << '\n'; @@ -520,10 +525,12 @@ void GridOut::write_ucd (const Triangulation &tria, out << '\n'; }; - // write faces with non-zero boundary - // indicator - if (ucd_flags.write_faces) + // write faces and lines with + // non-zero boundary indicator + if (ucd_flags.write_faces) write_ucd_faces (tria, cell_index, out); + if (ucd_flags.write_lines) + write_ucd_lines (tria, cell_index, out); // make sure everything now gets to // disk @@ -687,6 +694,21 @@ unsigned int GridOut::n_boundary_faces (const Triangulation<1> &) const return 0; } +unsigned int GridOut::n_boundary_lines (const Triangulation<1> &) const +{ + return 0; +} + +#endif + + +#if deal_II_dimension == 2 + +unsigned int GridOut::n_boundary_lines (const Triangulation<2> &) const +{ + return 0; +} + #endif @@ -708,6 +730,23 @@ unsigned int GridOut::n_boundary_faces (const Triangulation &tria) const +template +unsigned int GridOut::n_boundary_lines (const Triangulation &tria) const +{ + typename Triangulation::active_line_iterator edge, endedge; + unsigned int n_lines = 0; + + for (edge=tria.begin_active_line(), endedge=tria.end_line(); + edge != endedge; ++edge) + if ((edge->at_boundary()) && + (edge->boundary_indicator() != 0)) + n_lines++; + + return n_lines; +} + + + #if deal_II_dimension == 1 void GridOut::write_msh_faces (const Triangulation<1> &, @@ -717,6 +756,26 @@ void GridOut::write_msh_faces (const Triangulation<1> &, return; } + +void GridOut::write_msh_lines (const Triangulation<1> &, + const unsigned int, + std::ostream &) const +{ + return; +} + +#endif + + +#if deal_II_dimension == 2 + +void GridOut::write_msh_lines (const Triangulation<2> &, + const unsigned int, + std::ostream &) const +{ + return; +} + #endif @@ -757,6 +816,35 @@ void GridOut::write_msh_faces (const Triangulation &tria, } +template +void GridOut::write_msh_lines (const Triangulation &tria, + const unsigned int starting_index, + std::ostream &out) const +{ + typename Triangulation::active_line_iterator line, endl; + unsigned int index=starting_index; + + for (line=tria.begin_active_line(), endl=tria.end_line(); + line != endl; ++line) + if (line->at_boundary() && + (line->boundary_indicator() != 0)) + { + out << index << " 1 "; + out << static_cast(line->boundary_indicator()) + << ' ' + << static_cast(line->boundary_indicator()) + << " 2 "; + // note: vertex numbers are 1-base + for (unsigned int vertex=0; vertex<2; ++vertex) + out << ' ' + << line->vertex_index(GeometryInfo::ucd_to_deal[vertex])+1; + out << '\n'; + + ++index; + }; +} + + #if deal_II_dimension == 1 @@ -767,6 +855,27 @@ void GridOut::write_ucd_faces (const Triangulation<1> &, return; } + +void GridOut::write_ucd_lines (const Triangulation<1> &, + const unsigned int, + std::ostream &) const +{ + return; +} + +#endif + + + +#if deal_II_dimension == 2 + +void GridOut::write_ucd_lines (const Triangulation<2> &, + const unsigned int, + std::ostream &) const +{ + return; +} + #endif @@ -805,6 +914,32 @@ void GridOut::write_ucd_faces (const Triangulation &tria, +template +void GridOut::write_ucd_lines (const Triangulation &tria, + const unsigned int starting_index, + std::ostream &out) const +{ + typename Triangulation::active_line_iterator line, endl; + unsigned int index=starting_index; + + for (line=tria.begin_active_line(), endl=tria.end_line(); + line != endl; ++line) + if (line->at_boundary() && + (line->boundary_indicator() != 0)) + { + out << index << " " + << static_cast(line->boundary_indicator()) + << " line "; + // note: vertex numbers are 1-base + for (unsigned int vertex=0; vertex<2; ++vertex) + out << line->vertex_index(GeometryInfo::ucd_to_deal[vertex])+1 << ' '; + out << '\n'; + + ++index; + }; +} + + #if deal_II_dimension==1 template -- 2.39.5