include/deal.II/base/data_out_base.h

00001 //---------------------------------------------------------------------------
00002 //    @f$Id: data_out_base.h 25345 2012-03-31 08:37:04Z bangerth @f$
00003 //
00004 //    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by the deal.II authors
00005 //
00006 //    This file is subject to QPL and may not be  distributed
00007 //    without copyright and license information. Please refer
00008 //    to the file deal.II/doc/license.html for the  text  and
00009 //    further information on this license.
00010 //
00011 //---------------------------------------------------------------------------
00012 #ifndef __deal2__data_out_base_h
00013 #define __deal2__data_out_base_h
00014 
00015 
00016 #include <deal.II/base/config.h>
00017 #include <deal.II/base/point.h>
00018 #include <deal.II/base/table.h>
00019 #include <deal.II/base/geometry_info.h>
00020 #include <deal.II/base/std_cxx1x/tuple.h>
00021 
00022 #include <vector>
00023 #include <string>
00024 
00025 #include <deal.II/base/mpi.h>
00026 
00027 // Only include the Tecplot API header if the appropriate files
00028 // were detected by configure
00029 #ifdef DEAL_II_HAVE_TECPLOT
00030 #  include "TECIO.h"
00031 #  include <string.h>
00032 #endif
00033 
00034 // we only need output streams, but older compilers did not provide
00035 // them in a separate include file
00036 #ifdef HAVE_STD_OSTREAM_HEADER
00037 #  include <ostream>
00038 #else
00039 #  include <iostream>
00040 #endif
00041 
00042 DEAL_II_NAMESPACE_OPEN
00043 
00044 
00045 class ParameterHandler;
00046 
00047 
00218 class DataOutBase
00219 {
00220   public:
00254     template <int dim, int spacedim=dim>
00255     struct Patch
00256     {
00261         static const unsigned int space_dim=spacedim;
00262 
00273         Point<spacedim> vertices[GeometryInfo<dim>::vertices_per_cell];
00274 
00287         unsigned int neighbors[GeometryInfo<dim>::faces_per_cell];
00288 
00296         unsigned int patch_index;
00297 
00306         unsigned int n_subdivisions;
00307 
00348         Table<2,float> data;
00349 
00369         bool points_are_available;
00370 
00375         Patch ();
00376 
00384         bool operator == (const Patch &patch) const;
00385 
00402         std::size_t memory_consumption () const;
00403 
00409         static const unsigned int no_neighbor = numbers::invalid_unsigned_int;
00416         DeclException2 (ExcInvalidCombinationOfDimensions,
00417                         int, int,
00418                         << "It is not possible to have a structural dimension of " << arg1
00419                         << " to be larger than the space dimension of the surrounding"
00420                         << " space " << arg2);
00422     };
00423 
00430     struct DXFlags
00431     {
00443         bool write_neighbors;
00449         bool int_binary;
00454         bool coordinates_binary;
00455 
00460         bool data_binary;
00461 
00467         bool data_double;
00468 
00472         DXFlags (const bool write_neighbors = false,
00473                  const bool int_binary = false,
00474                  const bool coordinates_binary = false,
00475                  const bool data_binary = false);
00476 
00482         static void declare_parameters (ParameterHandler &prm);
00483 
00493         void parse_parameters (const ParameterHandler &prm);
00494 
00501         std::size_t memory_consumption () const;
00502     };
00503 
00511     struct UcdFlags
00512     {
00531         bool write_preamble;
00532 
00536         UcdFlags (const bool write_preamble = false);
00537 
00543         static void declare_parameters (ParameterHandler &prm);
00544 
00554         void parse_parameters (const ParameterHandler &prm);
00555 
00572         std::size_t memory_consumption () const;
00573     };
00574 
00582     struct GnuplotFlags
00583     {
00584       private:
00593         int dummy;
00594 
00595       public:
00599         GnuplotFlags ();
00600 
00606         static void declare_parameters (ParameterHandler &prm);
00607 
00617         void parse_parameters (const ParameterHandler &prm) const;
00618 
00635         std::size_t memory_consumption () const;
00636     };
00637 
00647     struct PovrayFlags
00648     {
00655         bool smooth;
00656 
00663         bool bicubic_patch;
00664 
00673         bool external_data;
00674 
00678         PovrayFlags (const bool smooth = false,
00679                      const bool bicubic_patch = false,
00680                      const bool external_data = false);
00681 
00687         static void declare_parameters (ParameterHandler &prm);
00688 
00698         void parse_parameters (const ParameterHandler &prm);
00699 
00716         std::size_t memory_consumption () const;
00717     };
00718 
00719 
00727     struct EpsFlags
00728     {
00740         unsigned int height_vector;
00741 
00748         unsigned int color_vector;
00749 
00757         enum SizeType {
00759               width,
00761               height
00762         };
00763 
00767         SizeType size_type;
00768 
00781         unsigned int size;
00782 
00787         double line_width;
00788 
00796         double azimut_angle;
00797 
00828         double turn_angle;
00829 
00846         double z_scaling;
00847 
00856         bool   draw_mesh;
00857 
00882         bool   draw_cells;
00883 
00895         bool   shade_cells;
00896 
00901         struct RgbValues
00902         {
00903             float red;
00904             float green;
00905             float blue;
00906 
00915             bool is_grey () const;
00916         };
00917 
00929         typedef RgbValues (*ColorFunction) (const double value,
00930                                             const double min_value,
00931                                             const double max_value);
00932 
00940         ColorFunction color_function;
00941 
00942 
00955         static RgbValues
00956         default_color_function (const double value,
00957                                 const double min_value,
00958                                 const double max_value);
00959 
00969         static RgbValues
00970         grey_scale_color_function (const double value,
00971                                    const double min_value,
00972                                    const double max_value);
00973 
00988         static RgbValues
00989         reverse_grey_scale_color_function (const double value,
00990                                            const double min_value,
00991                                            const double max_value);
00992 
00996         EpsFlags (const unsigned int  height_vector = 0,
00997                   const unsigned int  color_vector  = 0,
00998                   const SizeType      size_type     = width,
00999                   const unsigned int  size          = 300,
01000                   const double        line_width    = 0.5,
01001                   const double        azimut_angle  = 60,
01002                   const double        turn_angle    = 30,
01003                   const double        z_scaling     = 1.0,
01004                   const bool          draw_mesh     = true,
01005                   const bool          draw_cells    = true,
01006                   const bool          shade_cells   = true,
01007                   const ColorFunction color_function= &default_color_function);
01008 
01018         static void declare_parameters (ParameterHandler &prm);
01019 
01029         void parse_parameters (const ParameterHandler &prm);
01030 
01047         std::size_t memory_consumption () const;
01048     };
01049 
01058     struct GmvFlags
01059     {
01060       private:
01069         int dummy;
01070 
01071       public:
01075         GmvFlags ();
01076 
01082         static void declare_parameters (ParameterHandler &prm);
01083 
01093         void parse_parameters (const ParameterHandler &prm) const;
01094 
01111         std::size_t memory_consumption () const;
01112     };
01113 
01121     struct TecplotFlags
01122     {
01123 
01124       public:
01125 
01135         const char* tecplot_binary_file_name;
01136 
01142         const char* zone_name;
01143 
01147         TecplotFlags (const char* tecplot_binary_file_name = NULL,
01148                       const char* zone_name = NULL);
01149 
01155         static void declare_parameters (ParameterHandler &prm);
01156 
01166         void parse_parameters (const ParameterHandler &prm) const;
01167 
01184         std::size_t memory_consumption () const;
01185     };
01186 
01195     struct VtkFlags
01196     {
01197       private:
01206         int dummy;
01207 
01208       public:
01212         VtkFlags ();
01213 
01219         static void declare_parameters (ParameterHandler &prm);
01220 
01230         void parse_parameters (const ParameterHandler &prm) const;
01231 
01248         std::size_t memory_consumption () const;
01249     };
01259     struct Deal_II_IntermediateFlags
01260     {
01274         static const unsigned int format_version = 3;
01275       private:
01284         int dummy;
01285 
01286       public:
01290         Deal_II_IntermediateFlags ();
01291 
01297         static void declare_parameters (ParameterHandler &prm);
01298 
01308         void parse_parameters (const ParameterHandler &prm) const;
01309 
01326         std::size_t memory_consumption () const;
01327     };
01328 
01334     enum OutputFormat
01335     {
01340           default_format,
01344           none,
01348           dx,
01353           ucd,
01358           gnuplot,
01364           povray,
01369           eps,
01373           gmv,
01380           tecplot,
01388           tecplot_binary,
01389 
01394           vtk,
01395 
01400           vtu,
01401 
01406           deal_II_intermediate
01407     };
01408 
01409 
01418     template <int dim, int spacedim>
01419     static void write_dx (const std::vector<Patch<dim,spacedim> > &patches,
01420                           const std::vector<std::string>          &data_names,
01421                           const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01422                           const DXFlags                           &flags,
01423                           std::ostream                            &out);
01424 
01470     template <int dim, int spacedim>
01471     static void write_eps (const std::vector<Patch<dim,spacedim> > &patches,
01472                            const std::vector<std::string>          &data_names,
01473                            const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01474                            const EpsFlags                          &flags,
01475                            std::ostream                            &out);
01476 
01487     template <int dim, int spacedim>
01488     static void write_gmv (const std::vector<Patch<dim,spacedim> > &patches,
01489                            const std::vector<std::string>          &data_names,
01490                            const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01491                            const GmvFlags                          &flags,
01492                            std::ostream                            &out);
01493 
01554     template <int dim, int spacedim>
01555     static void write_gnuplot (const std::vector<Patch<dim,spacedim> > &patches,
01556                                const std::vector<std::string>          &data_names,
01557                                const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01558                                const GnuplotFlags                      &flags,
01559                                std::ostream                            &out);
01560 
01608     template <int dim, int spacedim>
01609     static void write_povray (const std::vector<Patch<dim,spacedim> > &patches,
01610                               const std::vector<std::string>          &data_names,
01611                               const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01612                               const PovrayFlags                       &flags,
01613                               std::ostream                            &out);
01614 
01622     template <int dim, int spacedim>
01623     static void write_tecplot (const std::vector<Patch<dim,spacedim> > &patches,
01624                                const std::vector<std::string>          &data_names,
01625                                const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01626                                const TecplotFlags                      &flags,
01627                                std::ostream                            &out);
01628 
01650     template <int dim, int spacedim>
01651     static void write_tecplot_binary (
01652       const std::vector<Patch<dim,spacedim> > &patches,
01653       const std::vector<std::string>          &data_names,
01654       const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01655       const TecplotFlags                      &flags,
01656       std::ostream                            &out);
01657 
01673     template <int dim, int spacedim>
01674     static void write_ucd (const std::vector<Patch<dim,spacedim> > &patches,
01675                            const std::vector<std::string>          &data_names,
01676                            const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01677                            const UcdFlags                          &flags,
01678                            std::ostream                            &out);
01679 
01692     template <int dim, int spacedim>
01693     static void write_vtk (const std::vector<Patch<dim,spacedim> > &patches,
01694                            const std::vector<std::string>          &data_names,
01695                            const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01696                            const VtkFlags                          &flags,
01697                            std::ostream                            &out);
01698 
01699 
01721     template <int dim, int spacedim>
01722     static void write_vtu (const std::vector<Patch<dim,spacedim> > &patches,
01723                            const std::vector<std::string>          &data_names,
01724                            const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01725                            const VtkFlags                          &flags,
01726                            std::ostream                            &out);
01727 
01734     static void write_vtu_header (std::ostream &out);
01735 
01742     static void write_vtu_footer (std::ostream &out);
01743 
01750     template <int dim, int spacedim>
01751     static void write_vtu_main (const std::vector<Patch<dim,spacedim> > &patches,
01752                          const std::vector<std::string>          &data_names,
01753                          const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01754                          const VtkFlags                          &flags,
01755                          std::ostream                            &out);
01756 
01797     template <int dim, int spacedim>
01798     static void write_deal_II_intermediate (
01799       const std::vector<Patch<dim,spacedim> > &patches,
01800       const std::vector<std::string>          &data_names,
01801       const std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > &vector_data_ranges,
01802       const Deal_II_IntermediateFlags         &flags,
01803       std::ostream                            &out);
01804 
01805 
01824     static
01825     std::pair<unsigned int, unsigned int>
01826     determine_intermediate_format_dimensions (std::istream &input);
01827 
01855     static OutputFormat parse_output_format (const std::string &format_name);
01856 
01865     static std::string get_output_format_names ();
01866 
01886     static std::string default_suffix (const OutputFormat output_format);
01887 
01904     static std::size_t memory_consumption ();
01905 
01912     DeclException2 (ExcInvalidDatasetSize,
01913                     int, int,
01914                     << "The number of points in this data set is " << arg1
01915                     << ", but we expected " << arg2 << " in each space direction.");
01921     DeclException0 (ExcNoPatches);
01925     DeclException0 (ExcTecplotAPIError);
01929     DeclException1 (ExcErrorOpeningTecplotFile,
01930                     char*,
01931                     << "There was an error opening Tecplot file " << arg1
01932                     << " for output");
01933 
01935   private:
01940     template <int dim, int spacedim, typename STREAM>
01941     static void write_nodes (const std::vector<Patch<dim,spacedim> >& patches,
01942                              STREAM& out);
01943 
01948     template <int dim, int spacedim, typename STREAM>
01949     static void write_cells (const std::vector<Patch<dim,spacedim> >& patches,
01950                              STREAM& out);
01951 
01956     template <int dim, int spacedim, class STREAM>
01957     static void write_data (const std::vector<Patch<dim,spacedim> >& patches,
01958                             const unsigned int n_data_sets,
01959                             const bool double_precision,
01960                             STREAM& out);
01961 
01971     class EpsCell2d
01972     {
01973       public:
01974 
01978         Point<2> vertices[4];
01979 
01986         float color_value;
01987 
01994         float depth;
01995 
02000         bool operator < (const EpsCell2d &) const;
02001     };
02002 
02003 
02024     template <int dim, int spacedim>
02025     static void
02026     write_gmv_reorder_data_vectors (const std::vector<Patch<dim,spacedim> > &patches,
02027                                     Table<2,double>                         &data_vectors);
02028 
02029 
02030 
02031 };
02032 
02033 
02034 
02035 
02150 template <int dim, int spacedim=dim>
02151 class DataOutInterface : private DataOutBase
02152 {
02153   public:
02154                                      /*
02155                                       * Import a few names that were
02156                                       * previously in this class and have then
02157                                       * moved to the base class. Since the
02158                                       * base class is inherited from
02159                                       * privately, we need to re-import these
02160                                       * symbols to make sure that references
02161                                       * to DataOutInterface<dim,spacedim>::XXX
02162                                       * remain valid.
02163                                       */
02164     using DataOutBase::OutputFormat;
02165     using DataOutBase::default_format;
02166     using DataOutBase::dx;
02167     using DataOutBase::gnuplot;
02168     using DataOutBase::povray;
02169     using DataOutBase::eps;
02170     using DataOutBase::tecplot;
02171     using DataOutBase::tecplot_binary;
02172     using DataOutBase::vtk;
02173     using DataOutBase::vtu;
02174     using DataOutBase::deal_II_intermediate;
02175     using DataOutBase::parse_output_format;
02176     using DataOutBase::get_output_format_names;
02177     using DataOutBase::determine_intermediate_format_dimensions;
02178 
02182     DataOutInterface ();
02183 
02189     virtual ~DataOutInterface ();
02190 
02197     void write_dx (std::ostream &out) const;
02198 
02205     void write_eps (std::ostream &out) const;
02206 
02213     void write_gmv (std::ostream &out) const;
02214 
02221     void write_gnuplot (std::ostream &out) const;
02222 
02229     void write_povray (std::ostream &out) const;
02230 
02237     void write_tecplot (std::ostream &out) const;
02238 
02248     void write_tecplot_binary (std::ostream &out) const;
02249 
02257     void write_ucd (std::ostream &out) const;
02258 
02265     void write_vtk (std::ostream &out) const;
02266 
02287     void write_vtu (std::ostream &out) const;
02288 
02302     void write_vtu_in_parallel (const char* filename, MPI_Comm comm) const;
02303 
02348     void write_pvtu_record (std::ostream &out,
02349                             const std::vector<std::string> &piece_names) const;
02350 
02367     void write_visit_record (std::ostream &out,
02368                              const std::vector<std::string> &piece_names) const;
02369 
02390     void write_deal_II_intermediate (std::ostream &out) const;
02391 
02406     void write (std::ostream       &out,
02407                 const OutputFormat  output_format = default_format) const;
02408 
02416     void set_default_format (const OutputFormat default_format);
02417 
02422     void set_flags (const DXFlags &dx_flags);
02423 
02428     void set_flags (const UcdFlags &ucd_flags);
02429 
02434     void set_flags (const GnuplotFlags &gnuplot_flags);
02435 
02440     void set_flags (const PovrayFlags &povray_flags);
02441 
02446     void set_flags (const EpsFlags &eps_flags);
02447 
02452     void set_flags (const GmvFlags &gmv_flags);
02453 
02458     void set_flags (const TecplotFlags &tecplot_flags);
02459 
02464     void set_flags (const VtkFlags &vtk_flags);
02465 
02470     void set_flags (const Deal_II_IntermediateFlags &deal_II_intermediate_flags);
02471 
02485     std::string
02486     default_suffix (const OutputFormat output_format = default_format) const;
02487 
02514     static void declare_parameters (ParameterHandler &prm);
02515 
02528     void parse_parameters (ParameterHandler &prm);
02529 
02546     std::size_t memory_consumption () const;
02547 
02548   protected:
02562     virtual
02563     const std::vector<typename DataOutBase::Patch<dim,spacedim> > &
02564     get_patches () const = 0;
02565 
02573     virtual
02574     std::vector<std::string>
02575     get_dataset_names () const = 0;
02576 
02611     virtual
02612     std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> >
02613     get_vector_data_ranges () const;
02614 
02623     unsigned int default_subdivisions;
02624 
02625   private:
02634     OutputFormat default_fmt;
02635 
02642     DXFlags     dx_flags;
02643 
02650     UcdFlags     ucd_flags;
02651 
02658     GnuplotFlags gnuplot_flags;
02659 
02666     PovrayFlags povray_flags;
02667 
02675     EpsFlags     eps_flags;
02676 
02684     GmvFlags     gmv_flags;
02685 
02693     TecplotFlags tecplot_flags;
02694 
02702     VtkFlags     vtk_flags;
02703 
02710     Deal_II_IntermediateFlags     deal_II_intermediate_flags;
02711 };
02712 
02713 
02714 
02765 template <int dim, int spacedim=dim>
02766 class DataOutReader : public DataOutInterface<dim,spacedim>
02767 {
02768   public:
02777     void read (std::istream &in);
02778 
02825     void merge (const DataOutReader<dim,spacedim> &other);
02826 
02830     DeclException0 (ExcNoPatches);
02834     DeclException0 (ExcIncompatibleDatasetNames);
02838     DeclException0 (ExcIncompatiblePatchLists);
02842     DeclException4 (ExcIncompatibleDimensions,
02843                     int, int, int, int,
02844                     << "Either the dimensions <" << arg1 << "> and <"
02845                     << arg2 << "> or the space dimensions <"
02846                     << arg3 << "> and <" << arg4
02847                     << "> do not match!");
02848 
02849   protected:
02864     virtual const std::vector<typename ::DataOutBase::Patch<dim,spacedim> > &
02865     get_patches () const;
02866 
02878     virtual std::vector<std::string> get_dataset_names () const;
02879 
02914     virtual
02915     std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> >
02916     get_vector_data_ranges () const;
02917 
02918   private:
02926     std::vector<typename ::DataOutBase::Patch<dim,spacedim> > patches;
02927     std::vector<std::string> dataset_names;
02928 
02935     std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> >
02936     vector_data_ranges;
02937 };
02938 
02939 
02940 
02941 
02942 /* -------------------- inline functions ------------------- */
02943 
02944 inline
02945 bool
02946 DataOutBase::EpsFlags::RgbValues::is_grey () const
02947 {
02948   return (red == green) && (red == blue);
02949 }
02950 
02951 
02952 /* -------------------- template functions ------------------- */
02953 
02963 template <int dim, int spacedim>
02964 std::ostream &
02965 operator << (std::ostream                           &out,
02966              const DataOutBase::Patch<dim,spacedim> &patch);
02967 
02968 
02969 
02978 template <int dim, int spacedim>
02979 std::istream &
02980 operator >> (std::istream                     &in,
02981              DataOutBase::Patch<dim,spacedim> &patch);
02982 
02983 
02984 
02985 DEAL_II_NAMESPACE_CLOSE
02986 
02987 #endif
02988 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Tue May 22 2012 12:06:04 by doxygen 1.7.3