Dune Core Modules (2.8.0)

gnuplot.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_IO_GNUPLOT_HH
4#define DUNE_IO_GNUPLOT_HH
5
11#include <vector>
12#include <string>
13#include <iostream>
14#include <fstream>
15
17
19
20namespace Dune {
21
27 template<class GridView>
29
30 typedef typename GridView::Grid::ctype ctype;
31
32 enum {dimworld = GridView::dimensionworld};
33
34 public:
35 GnuplotWriter (const GridView & gv) : _is(gv.indexSet()), _gv(gv)
36 {
37 static_assert(dimworld==1 || dimworld==2, "GnuPlot export only works for worlddim==1 and worlddim==2");
38 // allocate _data buffer
39 _data.resize(_is.size(0)*2);
40 }
41
46 template <class DataContainer>
47 void addCellData(const DataContainer& data, const std::string & name)
48 {
49 if (dimworld!=1)
50 DUNE_THROW(IOError, "Gnuplot cell data writing is only supported for grids in a 1d world!");
51 addData(cellData, data, name);
52 }
53
58 template <class DataContainer>
59 void addVertexData(const DataContainer& data, const std::string & name)
60 {
61 addData(vertexData, data, name);
62 }
63
67 void write(const std::string& filename) const;
68
69 private:
70 enum DataType { vertexData, cellData };
71 const typename GridView::IndexSet & _is;
72 const GridView _gv;
73 std::vector< std::vector< float > > _data;
74 std::vector< std::string > _names;
75
76 template <class DataContainer>
77 void addData(DataType t, const DataContainer& data, const std::string & name);
78
79 void writeRow(std::ostream & file,
80 const FieldVector<ctype, dimworld>& position,
81 const std::vector<float> & data) const;
82 };
83
87 template<class G>
88 class LeafGnuplotWriter : public GnuplotWriter<typename G::LeafGridView>
89 {
90 public:
92 LeafGnuplotWriter (const G& grid)
93 : GnuplotWriter<typename G::LeafGridView>(grid.leafGridView())
94 {}
95 };
96
100 template<class G>
101 class LevelGnuplotWriter : public GnuplotWriter<typename G::LevelGridView>
102 {
103 public:
105 LevelGnuplotWriter (const G& grid, int level)
106 : GnuplotWriter<typename G::LevelGridView>(grid.levelGridView(level))
107 {}
108 };
109
110}
111
112#include "gnuplot/gnuplot.cc"
113
114#endif // DUNE_IO_GNUPLOT_HH
Writer for 1D grids in gnuplot format.
Definition: gnuplot.hh:28
void addVertexData(const DataContainer &data, const std::string &name)
Add vertex data.
Definition: gnuplot.hh:59
void addCellData(const DataContainer &data, const std::string &name)
Add cell data.
Definition: gnuplot.hh:47
void write(const std::string &filename) const
Write Gnuplot file to disk.
Definition: gnuplot.cc:17
Grid view abstract base class.
Definition: gridview.hh:63
Default exception class for I/O errors.
Definition: exceptions.hh:229
GnuplotWriter on the leaf grid.
Definition: gnuplot.hh:89
LeafGnuplotWriter(const G &grid)
Construct a Gnuplot writer for the leaf level of a given grid.
Definition: gnuplot.hh:92
GnuplotWriter on a given level grid.
Definition: gnuplot.hh:102
LevelGnuplotWriter(const G &grid, int level)
Construct a Gnuplot writer for a certain level of a given grid.
Definition: gnuplot.hh:105
Different resources needed by all grid implementations.
Implements a vector constructed from a given type representing a field and a compile-time given size.
Implementation of gnuplot output for 1D and 2D grids.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
const IndexSet & indexSet() const
obtain the index set
Definition: gridview.hh:175
Traits::IndexSet IndexSet
type of the index set
Definition: gridview.hh:83
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
leaf grid view for the given grid
Definition: grid.hh:808
Grid< dim, dimworld, ct, GridFamily >::LevelGridView levelGridView(const Grid< dim, dimworld, ct, GridFamily > &grid, int level)
level grid view for the given grid and level.
Definition: grid.hh:791
@ dimensionworld
The dimension of the world the grid lives in.
Definition: gridview.hh:134
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)