*/
MathGL ();
+ /**
+ * Draw a bounding box around the graph.
+ */
+ bool draw_bounding_box;
+
/**
* Declare parameters in ParameterHandler.
*/
*/
template <int dim, int spacedim>
void write_svg (const Triangulation<dim,spacedim> &tria,
- std::ostream &out) const;
+ std::ostream &out) const;
void write_svg (const Triangulation<2,2> &tria,
- std::ostream &out) const;
+ std::ostream &out) const;
/**
- * Write triangulation in MathGL format.
+ * Write triangulation in MathGL script format. To interpret this
+ * file a version of MathGL>=2.0.0 is required.
*
- * Not implemented for the codimension one case.
+ * To get a handle on the resultant MathGL script within a graphical
+ * environment an interpreter is needed. A suggestion to start with
+ * is <code>mglview</code>, which is bundled with MathGL. With
+ * <code>mglview</code> can interpret and display small-to-medium
+ * MathGL scripts in a graphical window and enables conversion to
+ * other formats such as EPS, PNG, JPG, SVG, as well as view/display
+ * animations. Some minor editing, such as modifying the lighting or
+ * alpha channels, can also be done.
+ *
+ * @note Not implemented for the codimensional one case.
*/
template <int dim>
void write_mathgl (const Triangulation<dim> &tria,
*/
template <int dim, int spacedim>
void write (const Triangulation<dim,spacedim> &tria,
- std::ostream &out,
- const OutputFormat output_format,
+ std::ostream &out,
+ const OutputFormat output_format,
const Mapping<dim,spacedim> *mapping=0) const;
/**
*/
template <int dim, int spacedim>
void write (const Triangulation<dim,spacedim> &tria,
- std::ostream &out,
+ std::ostream &out,
const Mapping<dim,spacedim> *mapping=0) const;
/**
{}
MathGL::MathGL ()
+ :
+ draw_bounding_box (false) // box
{}
void MathGL::declare_parameters (ParameterHandler ¶m)
- {}
+ {
+ param.declare_entry ("Draw bounding box", "false", Patterns::Bool ());
+ }
void MathGL::parse_parameters (ParameterHandler ¶m)
- {}
+ {
+ draw_bounding_box = param.get_bool ("Draw bounding box");
+ }
} // end namespace GridOutFlags
}
+
template <>
void GridOut::write_mathgl (const Triangulation<1> &,
std::ostream &) const
void GridOut::write_mathgl (const Triangulation<dim> &tria,
std::ostream &out) const
{
- Assert (false, ExcNotImplemented());
+ AssertThrow (out, ExcIO ());
+ Assert (dim!=3, ExcNotImplemented ());
+
+ // (i) write header
+ if (true)
+ {
+ // block this to have local variables destroyed after use
+ const std::time_t time1 = std::time (0);
+ const std::tm *time = std::localtime (&time1);
+
+ out << "\n#"
+ << "\n# This file was generated by the deal.II library."
+ << "\n# Date = "
+ << time->tm_year+1900 << "/"
+ << std::setfill('0') << std::setw (2) << time->tm_mon+1 << "/"
+ << std::setfill('0') << std::setw (2) << time->tm_mday
+ << "\n# Time = "
+ << std::setfill('0') << std::setw (2) << time->tm_hour << ":"
+ << std::setfill('0') << std::setw (2) << time->tm_min << ":"
+ << std::setfill('0') << std::setw (2) << time->tm_sec
+ << "\n#"
+ << "\n# For a description of the MathGL script format see the MathGL manual. "
+ << "\n#"
+ << "\n# Note: This file is understood by MathGL v2.1 and higher only, and can "
+ << "\n# be quickly viewed in a graphical environment using "mglview". "
+ << "\n#" << "\n"
+ ;
+ }
+
+ // define a helper to keep loops approximately dim-independent
+ // since MathGL labels axes as x, y, z
+ Assert (dim<=3, ExcInternalError ());
+ const std::string axes = "xyz";
+
+ // (ii) write preamble and graphing tweaks
+ out << "\n#"
+ << "\n# Preamble."
+ << "\n#" << "\n";
+
+ if (mathgl_flags.draw_bounding_box)
+ out << "\nbox";
+
+ // Default, cf. MathGL / gnuplot.
+ out << "\nsetsize 800 800";
+
+ out << "\n";
+
+ // (iii) write vertex ordering
+ out << "\n#"
+ << "\n# Vertex ordering."
+ << "\n# list <vertex order> <vertex indices>"
+ << "\n#" << "\n";
+
+ // todo: This denotes the natural ordering of vertices, but it needs
+ // to check this is really always true for a given grid (it's not
+ // true in step-1 grid-2 for instance).
+ out << "\nlist f 0 1 2 3"
+ << "\n";
+
+ // (iv) write a list of vertices of cells
+ out << "\n#"
+ << "\n# List of vertices."
+ << "\n# list <id> <vertices>"
+ << "\n#" << "\n";
+
+ // run over all active cells and write out a list of
+ // xyz-coordinates that correspond to vertices
+ typename dealii::Triangulation<dim>::active_cell_iterator
+ cell=tria.begin_active (),
+ endc=tria.end ();
+
+ // No global indices in deal.II, so we make one up here.
+ unsigned int cell_global_index = 0;
+
+ for (; cell!=endc; ++cell, ++cell_global_index)
+ {
+ for (unsigned int i=0; i<dim; ++i)
+ {
+ // if (cell->direction_flag ()==true)
+ // out << "\ntrue";
+ // else
+ // out << "\nfalse";
+
+ out << "\nlist " << axes[i] << cell_global_index << " ";
+ for (unsigned int j=0; j<GeometryInfo<dim>::vertices_per_cell; ++j)
+ out << cell->vertex(j)[i] << " ";
+ }
+ out << '\n';
+ }
+
+ // (v) write out cells to plot as quadplot objects
+ out << "\n#"
+ << "\n# List of cells to quadplot."
+ << "\n# quadplot <vertex order> <id> <style>"
+ << "\n#" << "\n";
+ for (unsigned int i=0; i<tria.n_active_cells (); ++i)
+ {
+ out << "\nquadplot f ";
+ for (unsigned int j=0; j<dim; ++j)
+ out << axes[j] << i << " ";
+ out << "\'k#\'";
+ }
+ out << "\n";
+
+ // (vi) write footer
+ out << "\n#"
+ << "\n#"
+ << "\n#" << "\n";
+
+ // make sure everything now gets to the output stream
+ out.flush ();
+ AssertThrow (out, ExcIO ());
}