From: wolf Date: Tue, 29 Jun 1999 12:38:41 +0000 (+0000) Subject: Implement ucd for grid output. Make the write_* functions non-static. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba968e68dbe81fd9f5e150101867312d99f59920;p=dealii-svn.git Implement ucd for grid output. Make the write_* functions non-static. git-svn-id: https://svn.dealii.org/trunk@1498 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/grid/grid_out.h b/deal.II/deal.II/include/grid/grid_out.h index 2083f309e8..8e66cf8a05 100644 --- a/deal.II/deal.II/include/grid/grid_out.h +++ b/deal.II/deal.II/include/grid/grid_out.h @@ -81,7 +81,7 @@ class GridOut * Declaration of a name for each of the * different output formats. */ - enum OutputFormat { gnuplot, eps }; + enum OutputFormat { gnuplot, eps, ucd }; /** * Write the triangulation in the @@ -90,8 +90,18 @@ class GridOut * of what happens here. */ template - static void write_gnuplot (const Triangulation &tria, - ostream &out); + void write_gnuplot (const Triangulation &tria, + ostream &out); + + /** + * Write the triangulation in the + * ucd format. See the general + * documentation for a description + * of what happens here. + */ + template + void write_ucd (const Triangulation &tria, + ostream &out); /** * Write the triangulation in the @@ -100,9 +110,9 @@ class GridOut * of what happens here. */ template - static void write_eps (const Triangulation &tria, - ostream &out); - + void write_eps (const Triangulation &tria, + ostream &out); + /** * Write data and grid to #out# according * to the given data format. This function @@ -110,9 +120,9 @@ class GridOut * #write_*# function. */ template - static void write (const Triangulation &tria, - ostream &out, - const OutputFormat output_format); + void write (const Triangulation &tria, + ostream &out, + const OutputFormat output_format); /** * Provide a function which tells us which @@ -121,6 +131,7 @@ class GridOut * formats are defined: * \begin{itemize} * \item #gnuplot#: #.gnuplot# + * \item #ucd#: #.inp# * \item #eps#: #.eps#. * \end{itemize} * @@ -171,6 +182,58 @@ class GridOut * Exception */ DeclException0 (ExcIO); + + private: + + /** + * Write the grid information about + * faces to #out#. Only those faces + * 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 #starting_index# for + * the numbering of the faces is passed + * also. + * + * This function unfortunately can not + * be included in the regular #write_ucd# + * function, since it needs special + * treatment for the case #dim==1#, in + * which case the face 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#. Bad luck. + */ + template + void write_ucd_faces (const Triangulation &tria, + const unsigned int starting_index, + ostream &out) const; + + /** + * Return the number of faces in the + * triangulation which have a boundary + * indicator not equal to zero. Only + * these faces are explicitely printed + * in the #write_*# functions; + * all faces 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 dimension. + * + * The reason for this function is the + * same as for #write_ucd_faces#. See + * there for more information. + */ + template + unsigned int n_boundary_faces (const Triangulation &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 31d39e45a1..99610be383 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 @@ -3,34 +3,16 @@ #include -template -void GridOut::write (const Triangulation &tria, - ostream &out, - OutputFormat output_format) -{ - switch (output_format) - { - case gnuplot: - write_gnuplot (tria, out); - return; - - case eps: - write_eps (tria, out); - return; - }; - - Assert (false, ExcInternalError()); -}; - - - string GridOut::default_suffix (const OutputFormat output_format) { switch (output_format) { case gnuplot: return ".gnuplot"; - + + case ucd: + return ".inp"; + case eps: return ".eps"; @@ -44,7 +26,11 @@ string GridOut::default_suffix (const OutputFormat output_format) GridOut::OutputFormat -GridOut::parse_output_format (const string &format_name) { +GridOut::parse_output_format (const string &format_name) +{ + if (format_name == "ucd") + return ucd; + if (format_name == "gnuplot") return gnuplot; diff --git a/deal.II/deal.II/source/grid/grid_out.cc b/deal.II/deal.II/source/grid/grid_out.cc index f52c3d2e5a..9d3ce9bb21 100644 --- a/deal.II/deal.II/source/grid/grid_out.cc +++ b/deal.II/deal.II/source/grid/grid_out.cc @@ -15,6 +15,204 @@ +template +void GridOut::write_ucd (const Triangulation &tria, + ostream &out) +{ + AssertThrow (out, ExcIO()); + + typename Triangulation::active_cell_iterator cell=tria.begin_active(); + const typename Triangulation::active_cell_iterator endc=tria.end(); + + // first loop over all cells to + // find out the vertices which + // are in use. copy them for fast + // output + vector > vertices (tria.n_vertices()); + vector vertex_used (tria.n_vertices(), false); + unsigned int n_vertices = 0; + + for (cell=tria.begin_active(); cell!=endc; ++cell) + for (unsigned int vertex=0; vertex::vertices_per_cell; + ++vertex) + // if not yet copied + if (vertex_used[cell->vertex_index(vertex)] == false) + { + vertex_used[cell->vertex_index(vertex)] = true; + vertices[cell->vertex_index(vertex)] = cell->vertex(vertex); + ++n_vertices; + }; + + + // write preamble + if (true) + { +/* + // block this to have local + // variables destroyed after + // use + time_t time1= time (0); + tm *time = localtime(&time1); + out << "# This file was generated by the deal.II library." << endl + << "# Date = " + << time->tm_year+1900 << "/" + << time->tm_mon+1 << "/" + << time->tm_mday << endl + << "# Time = " + << time->tm_hour << ":" + << setw(2) << time->tm_min << ":" + << setw(2) << time->tm_sec << endl + << "#" << endl + << "# For a description of the UCD format see the AVS Developer's guide." + << endl + << "#" << endl; +*/ + }; + + // start with ucd data + out << n_vertices << ' ' + << tria.n_active_cells() + n_boundary_faces(tria) + << " 0 0 0" // no data + << endl; + + // actually write the vertices. + // note that we shall number them + // with first index 1 instead of 0 + for (unsigned int i=0; i(cell->material_id()) + << " "; + switch (dim) + { + case 1: out << "line "; break; + case 2: out << "quad "; break; + case 3: out << "hex "; break; + default: + Assert (false, ExcNotImplemented()); + }; + + // it follows a list of the + // vertices of each cell. in 1d + // this is simply a list of the + // two vertices, in 2d its counter + // clockwise, as usual in this + // library. in 3d, the same applies + // (special thanks to AVS for + // numbering their vertices in a + // way compatible to deal.II!) + // + // technical reference: + // AVS Developer's Guide, Release 4, + // May, 1992, p. E6 + // + // note: vertex numbers are 1-base + for (unsigned int vertex=0; vertex::vertices_per_cell; + ++vertex) + out << cell->vertex_index(vertex)+1 << ' '; + out << endl; + }; + + // write faces with non-zero boundary + // indicator + write_ucd_faces (tria, cell_index, out); + + AssertThrow (out, ExcIO()); +}; + + + +#if deal_II_dimension == 1 + +template <> +unsigned int GridOut::n_boundary_faces (const Triangulation<1> &) const +{ + return 0; +}; + +#endif + + + +template +unsigned int GridOut::n_boundary_faces (const Triangulation &tria) const +{ + typename Triangulation::active_face_iterator face, endf; + unsigned long int n_faces = 0; + + for (face=tria.begin_active_face(), endf=tria.end_face(); + face != endf; ++face) + if ((face->at_boundary()) && + (face->boundary_indicator() != 0)) + n_faces++; + + return n_faces; +}; + + + +#if deal_II_dimension == 1 + +template <> +void GridOut::write_ucd_faces (const Triangulation<1> &, + const unsigned int, + ostream &) const +{ + return; +}; + +#endif + + + +template +void GridOut::write_ucd_faces (const Triangulation &tria, + const unsigned int starting_index, + ostream &out) const +{ + typename Triangulation::active_face_iterator face, endf; + unsigned int index=starting_index; + + for (face=tria.begin_active_face(), endf=tria.end_face(); + face != endf; ++face) + if (face->at_boundary() && + (face->boundary_indicator() != 0)) + { + out << index << " " + << static_cast(face->boundary_indicator()) + << " "; + switch (dim) + { + case 2: out << "line "; break; + case 3: out << "quad "; break; + default: + Assert (false, ExcNotImplemented()); + }; + for (unsigned int vertex=0; vertex::vertices_per_face; ++vertex) + out << face->vertex_index(vertex) << ' '; + out << endl; + + ++index; + }; +}; + + + template void GridOut::write_gnuplot (const Triangulation &tria, ostream &out) @@ -275,7 +473,32 @@ void GridOut::write_eps (const Triangulation &tria, -// explicit instantiations -template void GridOut::write_gnuplot (const Triangulation &, ostream &); -template void GridOut::write_eps (const Triangulation &, ostream &); +template +void GridOut::write (const Triangulation &tria, + ostream &out, + OutputFormat output_format) +{ + switch (output_format) + { + case ucd: + write_ucd (tria, out); + return; + + case gnuplot: + write_gnuplot (tria, out); + return; + + case eps: + write_eps (tria, out); + return; + }; + + Assert (false, ExcInternalError()); +}; + + + + +// explicit instantiations. note that write instantiates all the other +// functions as needed template void GridOut::write (const Triangulation &, ostream &, OutputFormat);