]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Implement DBMesh input.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 25 Sep 2000 13:44:11 +0000 (13:44 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 25 Sep 2000 13:44:11 +0000 (13:44 +0000)
git-svn-id: https://svn.dealii.org/trunk@3347 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/grid/grid_in.h
deal.II/deal.II/source/grid/grid_in.cc

index 0ef14dcaeec2b5b3b8c5a835f5dde313c8ee9a79..e8c4913fcd3ecb3edfd4401c600f374be691eb0e 100644 (file)
@@ -35,16 +35,38 @@ template <int dim> class Triangulation;
  * will be undefined afterwards. Upon input, only lines in one dimension
  * and line and quads in two dimensions are accepted. All other cell types
  * (e.g. triangles in two dimensions, quads and hexes in 3d) are rejected.
- * The vertex and cell numbering in the UCD file, which
+ * The vertex and cell numbering in the input file, which
  * need not be consecutively, is lost upon transfer to the triangulation
  * object, since this one needs consecutively numbered elements.
  *
- * Material indicators are accepted to denote the material id of cells and
+ * Material indicators are accepted to denote the material ID of cells and
  * to denote boundary part indication for lines in 2D. Read the according
  * sections in the documentation of the @ref{Triangulation} class for
  * further details.
  *
  *
+ * @sect3{Supported input formats}
+ *
+ * At present, the following input formats are supported:
+ * @begin{itemize}
+ * @item @p{UCD} (unstructured cell data) format: this format is used
+ * for grid input as well as data output. If there are data vectors in
+ * the input file, they are ignored, as we are only interested in the
+ * grid in this class. The exact description of the format can be
+ * found in the AVS Explorer manual (see @url{http://www.avs.com}).
+ * The @p{UCD} format can be read by the @p{read_ucd} function.
+ *
+ * @item @p{DB mesh} format: this format is used by the @p{BAMG} mesh
+ * generator (see
+ * @url{http://www-rocq.inria.fr/gamma/cdrom/www/bamg/eng.htm}. The
+ * documentation of the format in the @p{BAMG} manual is very
+ * incomplete, so we don't actually parse many of the fields of the
+ * output since we don't know their meaning, but the data that is read
+ * is enough to build up the mesh as intended by the mesh generator.
+ * This format can be read by the @p{read_dbmesh} function.
+ * @end{itemize}
+ *
+ *
  * @sect3{Structure of input grid data}
  * 
  * It is your duty to use a correct numbering of vertices in the cell list,
@@ -146,6 +168,13 @@ class GridIn
                                      */
     void read_ucd (istream &);
 
+                                    /**
+                                     * Read grid data from a file
+                                     * containing data in the DB mesh
+                                     * format.
+                                     */
+    void read_dbmesh (istream &);
+    
                                     /**
                                      * Exception
                                      */
@@ -168,11 +197,22 @@ class GridIn
                                     /**
                                      * Exception
                                      */
-    DeclException0 (ExcInternalError);
+    DeclException1 (ExcInvalidDBMESHInput,
+                   string,
+                   << "The string <" << arg1 << "> is not recognized at the present"
+                   << " position of a DB Mesh file.");
+    
                                     /**
                                      * Exception
                                      */
     DeclException0 (ExcIO);
+                                    /**
+                                     * Exception
+                                     */
+    DeclException1 (ExcDBMESHWrongDimension,
+                   int,
+                   << "The specified dimension " << arg1
+                   << " is not the same as that of the triangulation to be created.");
     
   private:
                                     /**
@@ -180,6 +220,31 @@ class GridIn
                                      * be fed with the data read in.
                                      */
     SmartPointer<Triangulation<dim> > tria;
+
+                                    /**
+                                     * Skip empty lines in the input
+                                     * stream, i.e. lines that
+                                     * contain either nothing or only
+                                     * whitespace.
+                                     */
+    static void skip_empty_lines (istream &in);
+    
+                                    /**
+                                     * Skip lines of comment that
+                                     * start with the indicated
+                                     * character (e.g. @p{#})
+                                     * following the point where the
+                                     * given input stream presently
+                                     * is. After the call to this
+                                     * function, the stream is at the
+                                     * start of the first line after
+                                     * the comment lines, or at the
+                                     * same position as before if
+                                     * there were no lines of
+                                     * comments.
+                                     */
+    static void skip_comment_lines (istream    &in,
+                                   const char  comment_start);
 };
 
 
index dec6a0e55c528b2104e6b250c04a925ae63d60c7..7b351e38c3e41430008f3b12f69f9e94f55ebe7a 100644 (file)
@@ -39,17 +39,7 @@ void GridIn<dim>::read_ucd (istream &in)
   AssertThrow (in, ExcIO());
   
                                   // skip comments at start of file
-  char c;
-  while (in.get(c), c=='#') 
-    {
-      char line[256];
-      in.get (line, 255, '\n'); // ignore rest of line, at most 256 chars
-      in.get (c);         // ignore '\n' at end of line.
-    };
-  
-                                  // put back first character of
-                                  // first non-comment line
-  in.putback (c);
+  skip_comment_lines (in, '#');
 
 
   unsigned int n_vertices;
@@ -163,5 +153,204 @@ void GridIn<dim>::read_ucd (istream &in)
 };
 
 
+
+template <int dim>
+void GridIn<dim>::read_dbmesh (istream &in)
+{
+  Assert (tria != 0, ExcNoTriangulationSelected());
+  Assert (dim==2, ExcNotImplemented());
+
+  AssertThrow (in, ExcIO());
+  
+                                  // skip comments at start of file
+  skip_comment_lines (in, '#');
+
+
+                                  // first read in identifier string
+  string line;
+  getline (in, line);
+
+  AssertThrow (line=="MeshVersionFormatted 0",
+              ExcInvalidDBMESHInput(line));
+
+  skip_empty_lines (in);
+
+                                  // next read dimension
+  getline (in, line);
+  AssertThrow (line=="Dimension", ExcInvalidDBMESHInput(line));
+  unsigned int dimension;
+  in >> dimension;
+  AssertThrow (dimension == dim, ExcDBMESHWrongDimension(dimension));
+  skip_empty_lines (in);
+
+                                  // now there are a lot of fields of
+                                  // which we don't know the exact
+                                  // meaning and which are far from
+                                  // being properly documented in the
+                                  // manual. we skip everything until
+                                  // we find a comment line with the
+                                  // string "# END". at some point in
+                                  // the future, someone may have the
+                                  // knowledge to parse and interpret
+                                  // the other fields in between as
+                                  // well...
+  while (getline(in,line), line.find("# END")==string::npos);
+  skip_empty_lines (in);
+
+
+                                  // now read vertices
+  getline (in, line);
+  AssertThrow (line=="Vertices", ExcInvalidDBMESHInput(line));
+  
+  unsigned int n_vertices;
+  int dummy;
+  
+  in >> n_vertices;
+  vector<Point<dim> >     vertices (n_vertices);
+  for (unsigned int vertex=0; vertex<n_vertices; ++vertex)
+    {
+                                      // read vertex coordinates
+      for (unsigned int d=0; d<dim; ++d)
+       in >> vertices[vertex][d];
+                                      // read Ref phi_i, whatever that may be
+      in >> dummy;
+    };
+
+  skip_empty_lines(in);
+
+                                  // read edges. we ignore them at
+                                  // present, so just read them and
+                                  // discard the input
+  getline (in, line);
+  AssertThrow (line=="Edges", ExcInvalidDBMESHInput(line));
+  
+  unsigned int n_edges;
+  in >> n_edges;
+  for (unsigned int edge=0; edge<n_edges; ++edge)
+    {
+                                      // read vertex indices
+      in >> dummy >> dummy;
+                                      // read Ref phi_i, whatever that may be
+      in >> dummy;
+    };
+
+  skip_empty_lines(in);
+
+
+
+                                  // read cracked edges (whatever
+                                  // that may be). we ignore them at
+                                  // present, so just read them and
+                                  // discard the input
+  getline (in, line);
+  AssertThrow (line=="CrackedEdges", ExcInvalidDBMESHInput(line));
+  
+  in >> n_edges;
+  for (unsigned int edge=0; edge<n_edges; ++edge)
+    {
+                                      // read vertex indices
+      in >> dummy >> dummy;
+                                      // read Ref phi_i, whatever that may be
+      in >> dummy;
+    };
+
+  skip_empty_lines(in);
+
+
+                                  // now read cells.
+                                  // set up array of cells
+  getline (in, line);
+  AssertThrow (line=="Quadrilaterals", ExcInvalidDBMESHInput(line));
+
+  vector<CellData<dim> > cells;
+  SubCellData            subcelldata;
+  unsigned int n_cells;
+  in >> n_cells;
+  for (unsigned int cell=0; cell<n_cells; ++cell) 
+    {
+                                      // read in vertex numbers. they
+                                      // are 1-based, so subtract one
+      cells.push_back (CellData<dim>());
+      for (unsigned int i=0; i<GeometryInfo<dim>::vertices_per_cell; ++i)
+       {
+         in >> cells.back().vertices[i];
+         --cells.back().vertices[i];
+       };
+
+                                      // read and discard Ref phi_i
+      in >> dummy;
+    };
+
+  skip_empty_lines(in);
+  
+
+                                  // then there are again a whole lot
+                                  // of fields of which I have no
+                                  // clue what they mean. skip them
+                                  // all and leave the interpretation
+                                  // to other implementors...
+  while (getline(in,line), line.find("End")==string::npos);
+                                  // ok, so we are not at the end of
+                                  // the file, that's it, mostly
+
+  
+                                  // check that no forbidden arrays are used
+  Assert (subcelldata.check_consistency(dim), ExcInternalError());
+
+  AssertThrow (in, ExcIO());
+
+  tria->create_triangulation (vertices, cells, subcelldata);
+};
+
+
+
+template <int dim>
+void GridIn<dim>::skip_empty_lines (istream &in)
+{    
+  string line;
+  while (in) 
+    {
+                                      // get line
+      getline (in, line);
+                                      // eat all spaces from the back
+      while ((line.length()>0) && (line[line.length()-1]==' '))
+       line.erase (line.length()-1, 1);
+                                      // if still non-null, then this
+                                      // is a non-empty line. put
+                                      // back all info and leave
+      if (line.length() > 0)
+       {
+         in.putback ('\n');
+         for (int i=line.length()-1; i>=0; --i)
+           in.putback (line[i]);
+         return;
+       };
+
+                                      // else: go on with next line
+    };
+};
+
+
+
+template <int dim>
+void GridIn<dim>::skip_comment_lines (istream    &in,
+                                     const char  comment_start)
+{    
+  char c;
+  while (in.get(c), c==comment_start) 
+    {
+      char line[256];
+      in.get (line, 255, '\n'); // ignore rest of line, at most 256 chars
+      in.get (c);         // ignore '\n' at end of line.
+    };
+  
+                                  // put back first character of
+                                  // first non-comment line
+  in.putback (c);
+};
+
+
+
+
 //explicit instantiations
 template class GridIn<deal_II_dimension>;

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.