From b315786dd546019619668912a92a663f7b75bd5a Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Fri, 30 Nov 2001 07:33:59 +0000 Subject: [PATCH] dx output declared git-svn-id: https://svn.dealii.org/trunk@5316 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/grid_out.h | 86 ++++++++++++----- .../source/grid/grid_out.all_dimensions.cc | 22 ++++- deal.II/deal.II/source/grid/grid_out.cc | 92 +++++++++++++++++++ 3 files changed, 178 insertions(+), 22 deletions(-) diff --git a/deal.II/deal.II/include/grid/grid_out.h b/deal.II/deal.II/include/grid/grid_out.h index e98fab327e..a000405a5c 100644 --- a/deal.II/deal.II/include/grid/grid_out.h +++ b/deal.II/deal.II/include/grid/grid_out.h @@ -34,6 +34,30 @@ template class Mapping; */ namespace GridOutFlags { + /** + * Flags for grid output in OpenDX format. + */ + struct DX + { + /** + * Write faces instead of + * cells. Defaults to false. + */ + bool write_faces; + /** + * Write all faces, including + * interior faces. Default is to + * write boundary faces only. + */ + bool write_all_faces; + + /** + * Constructor. + */ + DX (bool write_faces = false, + bool write_all_faces = false); + }; + /** * Flags describing the details of * output in UCD format. @@ -386,7 +410,19 @@ class GridOut * Declaration of a name for each of the * different output formats. */ - enum OutputFormat { gnuplot, eps, ucd }; + enum OutputFormat { dx, gnuplot, eps, ucd }; + + /** + * Write triangulation in OpenDX format. + * + * Cells or faces are written + * together with their level and + * their material id or boundary + * indicator, resp. + */ + template + void write_dx (const Triangulation &tria, + std::ostream &out); /** * Write the triangulation in the @@ -583,34 +619,37 @@ class GridOut const Mapping *mapping=0); /** - * Set the flags to be used for output - * in UCD format. + * Set flags for DX output */ - void set_flags (const GridOutFlags::Ucd &ucd_flags); + void set_flags (const GridOutFlags::DX &flags); + + /** + * Set flags for UCD output + */ + void set_flags (const GridOutFlags::Ucd &flags); /** - * Set the flags to be used for output - * in GNUPLOT format. + * Set flags for GNUPLOT output */ - void set_flags (const GridOutFlags::Gnuplot &gnuplot_flags); + void set_flags (const GridOutFlags::Gnuplot &flags); /** - * Set the flags to be used for output - * in 1d EPS output. + * Set flags for EPS output of a + * one-dimensional triangulation */ - void set_flags (const GridOutFlags::Eps<1> &eps_flags); + void set_flags (const GridOutFlags::Eps<1> &flags); - /** - * Set the flags to be used for output - * in 2d EPS output. + /** + * Set flags for EPS output of a + * two-dimensional triangulation */ - void set_flags (const GridOutFlags::Eps<2> &eps_flags); + void set_flags (const GridOutFlags::Eps<2> &flags); - /** - * Set the flags to be used for output - * in 3d EPS output. + /** + * Set flags for EPS output of a + * three-dimensional triangulation */ - void set_flags (const GridOutFlags::Eps<3> &eps_flags); + void set_flags (const GridOutFlags::Eps<3> &flags); /** * Provide a function which tells us which @@ -618,6 +657,7 @@ class GridOut * usually has. At present the following * formats are defined: * @begin{itemize} + * @item @p{OpenDX}: @p{.dx} * @item @p{gnuplot}: @p{.gnuplot} * @item @p{ucd}: @p{.inp} * @item @p{eps}: @p{.eps}. @@ -674,10 +714,14 @@ class GridOut DeclException0 (ExcInvalidState); private: - + /** + * Flags for OpenDX output. + */ + GridOutFlags::DX dx_flags; + /** - * Flags to be used upon output of UCD - * data. Can be changed by using the + * Flags for UCD output. Can be + * changed by using the * @p{set_flags} function. */ GridOutFlags::Ucd ucd_flags; 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 3ac37f64c9..cc01ce2146 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 @@ -17,6 +17,14 @@ namespace GridOutFlags { + DX::DX (const bool write_faces, + const bool write_all_faces) : + write_faces (write_faces), + write_all_faces (write_all_faces) + {}; + + + Ucd::Ucd (const bool write_preamble, const bool write_faces) : write_preamble (write_preamble), @@ -91,6 +99,13 @@ namespace GridOutFlags +void GridOut::set_flags (const GridOutFlags::DX &flags) +{ + dx_flags = flags; +}; + + + void GridOut::set_flags (const GridOutFlags::Ucd &flags) { ucd_flags = flags; @@ -131,6 +146,8 @@ GridOut::default_suffix (const OutputFormat output_format) { switch (output_format) { + case dx: + return ".dx"; case gnuplot: return ".gnuplot"; @@ -151,6 +168,9 @@ GridOut::default_suffix (const OutputFormat output_format) GridOut::OutputFormat GridOut::parse_output_format (const std::string &format_name) { + if (format_name == "dx") + return dx; + if (format_name == "ucd") return ucd; @@ -169,7 +189,7 @@ GridOut::parse_output_format (const std::string &format_name) std::string GridOut::get_output_format_names () { - return "gnuplot|eps|ucd"; + return "dx|gnuplot|eps|ucd"; }; diff --git a/deal.II/deal.II/source/grid/grid_out.cc b/deal.II/deal.II/source/grid/grid_out.cc index 4329eb492c..968a2ffdd4 100644 --- a/deal.II/deal.II/source/grid/grid_out.cc +++ b/deal.II/deal.II/source/grid/grid_out.cc @@ -27,6 +27,94 @@ #include +template +void GridOut::write_dx (const Triangulation &tria, + std::ostream &out) +{ + AssertThrow (out, ExcIO()); + + // get the positions of the + // vertices and whether they are + // used. + const std::vector > &vertices = tria.get_vertices(); + const std::vector &vertex_used = tria.get_used_vertices(); + + const unsigned int n_vertices = tria.n_used_vertices(); + + typename Triangulation::active_cell_iterator cell=tria.begin_active(); + const typename Triangulation::active_cell_iterator endc=tria.end(); + + // start with ucd data + out << n_vertices << ' ' + << tria.n_active_cells() + (ucd_flags.write_faces ? + n_boundary_faces(tria) : + 0) + << " 0 0 0" // no data + << std::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 << std::endl; + }; + + // write faces with non-zero boundary + // indicator + if (ucd_flags.write_faces) + write_ucd_faces (tria, cell_index, out); + + AssertThrow (out, ExcIO()); +}; + + + template void GridOut::write_ucd (const Triangulation &tria, std::ostream &out) @@ -806,6 +894,10 @@ void GridOut::write (const Triangulation &tria, { switch (output_format) { + case dx: + write_dx (tria, out); + return; + case ucd: write_ucd (tria, out); return; -- 2.39.5