From: bangerth Date: Mon, 14 Jul 2014 22:55:47 +0000 (+0000) Subject: Also provide GridOut::write_vtu(). X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aee97c61446e8194cc1967fead94caf77f03b2a3;p=dealii-svn.git Also provide GridOut::write_vtu(). git-svn-id: https://svn.dealii.org/trunk@33174 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index ab287d9439..41acf13069 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -172,8 +172,9 @@ inconvenience this causes.

Specific improvements

    -
  1. New: There is now a function GridOut::write_vtk() that can - write a mesh in VTK format. +
  2. New: There are now functions GridOut::write_vtk() and + GridOut::write_vtu() that can + write a mesh in VTK/VTU format.
    (Wolfgang Bangerth, 2014/07/14)
  3. diff --git a/deal.II/include/deal.II/grid/grid_out.h b/deal.II/include/deal.II/grid/grid_out.h index 29e7742eeb..308df13c5e 100644 --- a/deal.II/include/deal.II/grid/grid_out.h +++ b/deal.II/include/deal.II/grid/grid_out.h @@ -753,6 +753,16 @@ namespace GridOutFlags */ struct Vtk : public DataOutBase::VtkFlags {}; + + + /** + * Flags for grid output in Vtu format. These flags are the same as + * those declared in DataOutBase::VtuFlags. + * + * @ingroup output + */ + struct Vtu : public DataOutBase::VtkFlags + {}; } @@ -863,7 +873,9 @@ public: /// write() calls write_mathgl() mathgl, /// write() calls write_vtk() - vtk + vtk, + /// write() calls write_vtu() + vtu }; /** @@ -1121,6 +1133,13 @@ public: void write_vtk (const Triangulation &tria, std::ostream &out) const; + /** + * Write triangulation in VTU format. + */ + template + void write_vtu (const Triangulation &tria, + std::ostream &out) const; + /** * Write grid to @p out according to the given data format. This * function simply calls the appropriate write_* function. @@ -1196,6 +1215,11 @@ public: */ void set_flags (const GridOutFlags::Vtk &flags); + /** + * Set flags for VTU output + */ + void set_flags (const GridOutFlags::Vtu &flags); + /** * Provide a function that can tell us which * suffix a given output format @@ -1338,6 +1362,11 @@ private: */ GridOutFlags::Vtk vtk_flags; + /** + * Flags for VTU output. + */ + GridOutFlags::Vtu vtu_flags; + /** * Write the grid information about faces to @p out. Only those * faces are printed which are on the boundary and which have a diff --git a/deal.II/source/grid/grid_out.cc b/deal.II/source/grid/grid_out.cc index abbf96cebe..afd5647f65 100644 --- a/deal.II/source/grid/grid_out.cc +++ b/deal.II/source/grid/grid_out.cc @@ -472,6 +472,11 @@ void GridOut::set_flags (const GridOutFlags::Vtk &flags) vtk_flags = flags; } +void GridOut::set_flags (const GridOutFlags::Vtu &flags) +{ + vtu_flags = flags; +} + std::string GridOut::default_suffix (const OutputFormat output_format) { @@ -497,6 +502,8 @@ GridOut::default_suffix (const OutputFormat output_format) return ".mathgl"; case vtk: return ".vtk"; + case vtu: + return ".vtu"; default: Assert (false, ExcNotImplemented()); return ""; @@ -546,6 +553,9 @@ GridOut::parse_output_format (const std::string &format_name) if (format_name == "vtk") return vtk; + if (format_name == "vtu") + return vtu; + AssertThrow (false, ExcInvalidState ()); // return something weird return OutputFormat(-1); @@ -555,7 +565,7 @@ GridOut::parse_output_format (const std::string &format_name) std::string GridOut::get_output_format_names () { - return "none|dx|gnuplot|eps|ucd|xfig|msh|svg|mathgl|vtk"; + return "none|dx|gnuplot|eps|ucd|xfig|msh|svg|mathgl|vtk|vtu"; } @@ -599,6 +609,10 @@ GridOut::declare_parameters(ParameterHandler ¶m) param.enter_subsection("Vtk"); GridOutFlags::Vtk::declare_parameters(param); param.leave_subsection(); + + param.enter_subsection("Vtu"); + GridOutFlags::Vtu::declare_parameters(param); + param.leave_subsection(); } @@ -641,6 +655,10 @@ GridOut::parse_parameters(ParameterHandler ¶m) param.enter_subsection("Vtk"); vtk_flags.parse_parameters(param); param.leave_subsection(); + + param.enter_subsection("Vtu"); + vtu_flags.parse_parameters(param); + param.leave_subsection(); } @@ -658,7 +676,8 @@ GridOut::memory_consumption () const sizeof(xfig_flags) + sizeof(svg_flags) + sizeof(mathgl_flags) + - sizeof(vtk_flags)); + sizeof(vtk_flags) + + sizeof(vtu_flags)); } @@ -2444,6 +2463,27 @@ void GridOut::write_vtk (const Triangulation &tria, +template +void GridOut::write_vtu (const Triangulation &tria, + std::ostream &out) const +{ + AssertThrow (out, ExcIO ()); + + // convert the cells of the triangulation into a set of patches + // and then have them output. since there is no data attached to + // the geometry, we also do not have to provide any names, identifying + // information, etc. + DataOutBase::write_vtu (triangulation_to_patches(tria), + std::vector(), + std::vector >(), + vtu_flags, + out); + + AssertThrow (out, ExcIO ()); +} + + + unsigned int GridOut::n_boundary_faces (const Triangulation<1> &) const { return 0; @@ -3817,6 +3857,10 @@ void GridOut::write (const Triangulation &tria, case vtk: write_vtk (tria, out); return; + + case vtu: + write_vtu (tria, out); + return; } Assert (false, ExcInternalError()); diff --git a/deal.II/source/grid/grid_out.inst.in b/deal.II/source/grid/grid_out.inst.in index 0b84908ff4..160a8fd98f 100644 --- a/deal.II/source/grid/grid_out.inst.in +++ b/deal.II/source/grid/grid_out.inst.in @@ -52,6 +52,9 @@ for (deal_II_dimension : DIMENSIONS) template void GridOut::write_vtk (const Triangulation&, std::ostream&) const; + template void GridOut::write_vtu + (const Triangulation&, + std::ostream&) const; template void GridOut::write (const Triangulation &, @@ -76,6 +79,9 @@ for (deal_II_dimension : DIMENSIONS) template void GridOut::write_vtk (const Triangulation&, std::ostream&) const; + template void GridOut::write_vtu + (const Triangulation&, + std::ostream&) const; #endif #if deal_II_dimension == 3 template void GridOut::write_ucd