- Home
- About DUNE
- Download
- Documentation
- Community
- Development
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 00016 #include <dune/grid/common/grid.hh> 00017 00018 namespace Dune { 00019 00025 template<class GridView> 00026 class GnuplotWriter { 00027 00028 typedef typename GridView::Grid::ctype ctype; 00029 00030 enum {dimworld = GridView::dimensionworld}; 00031 00032 public: 00033 GnuplotWriter (const GridView & gv) : _is(gv.indexSet()), _gv(gv) 00034 { 00035 dune_static_assert(dimworld==1 || dimworld==2, "GnuPlot export only works for worlddim==1 and worlddim==2"); 00036 // allocate _data buffer 00037 _data.resize(_is.size(0)*2); 00038 } 00039 00044 template <class DataContainer> 00045 void addCellData(const DataContainer& data, const std::string & name) 00046 { 00047 if (dimworld!=1) 00048 DUNE_THROW(IOError, "Gnuplot cell data writing is only supported for grids in a 1d world!"); 00049 addData(cellData, data, name); 00050 } 00051 00056 template <class DataContainer> 00057 void addVertexData(const DataContainer& data, const std::string & name) 00058 { 00059 addData(vertexData, data, name); 00060 } 00061 00065 void write(const std::string& filename) const; 00066 00067 private: 00068 enum DataType { vertexData, cellData }; 00069 const typename GridView::IndexSet & _is; 00070 const GridView _gv; 00071 std::vector< std::vector< float > > _data; 00072 std::vector< std::string > _names; 00073 00074 template <class DataContainer> 00075 void addData(DataType t, const DataContainer& data, const std::string & name); 00076 00077 void writeRow(std::ostream & file, 00078 const FieldVector<ctype, dimworld>& position, 00079 const std::vector<float> & data) const; 00080 }; 00081 00085 template<class G> 00086 class LeafGnuplotWriter : public GnuplotWriter<typename G::LeafGridView> 00087 { 00088 public: 00090 LeafGnuplotWriter (const G& grid) 00091 : GnuplotWriter<typename G::LeafGridView>(grid.leafView()) 00092 {} 00093 }; 00094 00098 template<class G> 00099 class LevelGnuplotWriter : public GnuplotWriter<typename G::LevelGridView> 00100 { 00101 public: 00103 LevelGnuplotWriter (const G& grid, int level) 00104 : GnuplotWriter<typename G::LevelGridView>(grid.levelView(level)) 00105 {} 00106 }; 00107 00108 } 00109 00110 #include "gnuplot/gnuplot.cc" 00111 00112 #endif // DUNE_IO_GNUPLOT_HH
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].