gnuplot.hh

Go to the documentation of this file.
00001 #ifndef DUNE_IO_GNUPLOT_HH
00002 #define DUNE_IO_GNUPLOT_HH
00003 
00009 #include <vector>
00010 #include <string>
00011 #include <iostream>
00012 #include <fstream>
00013 
00014 #include <dune/common/fvector.hh>
00015 #include <dune/common/helpertemplates.hh>
00016 
00017 #include <dune/grid/common/grid.hh>
00018 
00019 namespace Dune {
00020 
00026   template<class GridView>
00027   class GnuplotWriter {
00028     
00029       typedef typename GridView::Grid::ctype ctype;
00030 
00031       enum {dimworld = GridView::dimensionworld};
00032 
00033   public:
00034       GnuplotWriter (const GridView & gv) : _is(gv.indexSet()), _gv(gv)
00035       {
00036           dune_static_assert(dimworld==1 || dimworld==2, "GnuPlot export only works for worlddim==1 and worlddim==2");
00037         // allocate _data buffer
00038         _data.resize(_is.size(0)*2);
00039       }
00040     
00045     template <class DataContainer>
00046     void addCellData(const DataContainer& data, const std::string & name)
00047       {
00048           if (dimworld!=1)
00049               DUNE_THROW(IOError, "Gnuplot cell data writing is only supported for grids in a 1d world!");
00050         addData(cellData, data, name);
00051       }
00052     
00057     template <class DataContainer>
00058     void addVertexData(const DataContainer& data, const std::string & name)
00059       {
00060         addData(vertexData, data, name);
00061       }
00062     
00066     void write(const std::string& filename) const;
00067 
00068   private:
00069     enum DataType { vertexData, cellData };
00070       const typename GridView::IndexSet & _is;
00071       const GridView _gv;
00072     std::vector< std::vector< float > > _data;
00073     std::vector< std::string > _names;
00074 
00075     template <class DataContainer>
00076     void addData(DataType t, const DataContainer& data, const std::string & name);
00077 
00078     void writeRow(std::ostream & file, 
00079                   const FieldVector<ctype, dimworld>& position, 
00080                   const std::vector<float> & data) const;
00081   };
00082   
00086   template<class G>
00087   class LeafGnuplotWriter : public GnuplotWriter<typename G::LeafGridView>
00088   {
00089   public:
00091     LeafGnuplotWriter (const G& grid)
00092       : GnuplotWriter<typename G::LeafGridView>(grid.leafView())
00093       {}
00094   };
00095 
00099   template<class G>
00100   class LevelGnuplotWriter : public GnuplotWriter<typename G::LevelGridView>
00101   {
00102   public:
00104     LevelGnuplotWriter (const G& grid, int level)
00105       : GnuplotWriter<typename G::LevelGridView>(grid.levelView(level))
00106       {}
00107   };
00108 
00109 }
00110 
00111 #include "gnuplot/gnuplot.cc"
00112 
00113 #endif // DUNE_IO_GNUPLOT_HH

Generated on Sun Nov 15 22:28:40 2009 for dune-grid by  doxygen 1.5.6