]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added write_lines options to write_msh and write_ucd to solve bug on 3d meshes with...
authorLuca Heltai <luca.heltai@sissa.it>
Mon, 10 Sep 2007 15:03:59 +0000 (15:03 +0000)
committerLuca Heltai <luca.heltai@sissa.it>
Mon, 10 Sep 2007 15:03:59 +0000 (15:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@15187 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/grid/grid_out.h
deal.II/deal.II/source/grid/grid_out.all_dimensions.cc
deal.II/deal.II/source/grid/grid_out.cc

index c4ffd123568fd121fc182259efc3a0c336112490..0135722293a7b11de316fe41d62c046ed0522109 100644 (file)
@@ -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
+                                       * <tt>dim==3</tt>, 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
+                                       * <tt>dim!=3</tt>.
+                                       *
+                                       *  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
+                                     * <tt>dim==1</tt> and
+                                     * <tt>dim==2</tt>, in which case
+                                     * the edge iterators are
+                                     * <tt>void*</tt>'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 <tt>dim==1/2</tt>. Bad luck.
+                                     */
+    template <int dim>
+    void write_msh_lines (const Triangulation<dim> &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 <tt>dim==1</tt>. Bad luck.
                                      */
+
+   
     template <int dim>
     void write_ucd_faces (const Triangulation<dim> &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 <tt>dim==1/2</tt>, in
+                                     * which case the edge iterators are
+                                     * <tt>void*</tt>'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 <tt>dim==1/2</tt>. Bad luck.
+                                     */
+
+   
+    template <int dim>
+    void write_ucd_lines (const Triangulation<dim> &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 <tt>write_*</tt> 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 <int dim>
+    unsigned int n_boundary_lines (const Triangulation<dim> &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;
 };
 
 
index b79d3b930bd1fea46d6ec8ae13a68e1e19570ccc..72a2fb3e8090030ff3e7c0b313b40706635dacb6 100644 (file)
@@ -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");
   }
 
   
index 1e7a8604926691f175e0f975bd098d5534c83155..a2f04de33354ad98b277330a448067377bc34fb1 100644 (file)
@@ -333,8 +333,10 @@ void GridOut::write_msh (const Triangulation<dim> &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<dim> &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<dim> &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<dim> &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<dim> &tria) const
 
 
 
+template <int dim>
+unsigned int GridOut::n_boundary_lines (const Triangulation<dim> &tria) const
+{
+  typename Triangulation<dim>::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<dim> &tria,
 }
 
 
+template <int dim>
+void GridOut::write_msh_lines (const Triangulation<dim> &tria,
+                              const unsigned int        starting_index,
+                              std::ostream             &out) const
+{
+  typename Triangulation<dim>::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<unsigned int>(line->boundary_indicator()) 
+           << ' ' 
+           << static_cast<unsigned int>(line->boundary_indicator()) 
+           << " 2 ";
+                                        // note: vertex numbers are 1-base
+       for (unsigned int vertex=0; vertex<2; ++vertex)
+         out << ' ' 
+             << line->vertex_index(GeometryInfo<dim-2>::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<dim> &tria,
 
 
 
+template <int dim>
+void GridOut::write_ucd_lines (const Triangulation<dim> &tria,
+                              const unsigned int        starting_index,
+                              std::ostream             &out) const
+{
+  typename Triangulation<dim>::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<unsigned int>(line->boundary_indicator())
+           << "  line    ";
+       // note: vertex numbers are 1-base
+       for (unsigned int vertex=0; vertex<2; ++vertex)
+         out << line->vertex_index(GeometryInfo<dim-2>::ucd_to_deal[vertex])+1 << ' ';
+       out << '\n';
+
+       ++index;
+      };         
+}
+
+
 #if deal_II_dimension==1
 
 template <int dim>

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.