dune-grid  2.2.0
amirameshwriter.hh
Go to the documentation of this file.
1 #ifndef DUNE_AMIRAMESH_WRITER_HH
2 #define DUNE_AMIRAMESH_WRITER_HH
3 
4 #include <string>
5 
6 #include <dune/common/array.hh>
7 
8 #if HAVE_AMIRAMESH
9 #include <amiramesh/AmiraMesh.h>
10 #endif
11 
12 namespace Dune {
13 
18  template<class GridView>
20 
21  enum {dim = GridView::dimension};
22 
23  public:
24 
33  void addGrid(const GridView& gridView, bool splitAll=false);
34 
44  template <class GridType2>
45  void addLevelGrid(const GridType2& grid, int level, bool splitAll=false);
46 
55  template <class GridType2>
56  void addLeafGrid(const GridType2& grid, bool splitAll=false);
57 
64  template <class DataContainer>
65  void addCellData(const DataContainer& data, const GridView& gridView, bool GridSplitUp=false);
66 
73  template <class DataContainer>
74  void addVertexData(const DataContainer& data, const GridView& gridView, bool GridSplitUp=false);
75 
80  void write(const std::string& filename, bool ascii=false) const;
81 
84  template <class DataContainer>
85  void addUniformData(const GridView& gridView,
86  const array<unsigned int, dim>& n,
87  const DataContainer& data);
88 
100  static void writeSurfaceGrid(const GridView& gridView,
101  const std::string& filename);
102 
103  protected:
104 
105 #if HAVE_AMIRAMESH // better: use a pointer here and forward-declare AmiraMesh
106  AmiraMesh amiramesh_;
107 #endif
108  };
109 
114  template<class GridType>
116  : public AmiraMeshWriter<typename GridType::LevelGridView>
117  {
118 
119  public:
120 
123 
125  LevelAmiraMeshWriter(const GridType& grid, int level) {
126  this->addGrid(grid.levelView(level));
127  }
128 
135  static void writeGrid(const GridType& grid,
136  const std::string& filename,
137  int level) {
138  LevelAmiraMeshWriter amiramesh(grid, level);
139  amiramesh.write(filename);
140  }
141 
150  template <class VectorType>
151  static void writeBlockVector(const GridType& grid,
152  const VectorType& f,
153  const std::string& filename,
154  int level,
155  bool GridSplitUp=false) {
156  LevelAmiraMeshWriter amiramesh;
157  if (f.size()==grid.size(level,GridType::dimension))
158  amiramesh.addVertexData(f, grid.levelView(level),GridSplitUp);
159  else
160  amiramesh.addCellData(f, grid.levelView(level),GridSplitUp);
161  amiramesh.write(filename);
162  }
163 
164  };
165 
170  template<class GridType>
172  : public AmiraMeshWriter<typename GridType::LeafGridView>
173  {
174 
175  public:
176 
179 
181  LeafAmiraMeshWriter(const GridType& grid) {
182  this->addLeafGrid(grid);
183  }
184 
190  static void writeGrid(const GridType& grid,
191  const std::string& filename) {
192  LeafAmiraMeshWriter amiramesh(grid);
193  amiramesh.write(filename);
194  }
195 
202  template <class VectorType>
203  static void writeBlockVector(const GridType& grid,
204  const VectorType& f,
205  const std::string& filename,
206  bool GridSplitUp = false) {
207  LeafAmiraMeshWriter amiramesh;
208  if (f.size()==grid.size(GridType::dimension))
209  amiramesh.addVertexData(f, grid.leafView(),GridSplitUp);
210  else
211  amiramesh.addCellData(f, grid.leafView(),GridSplitUp);
212 
213  amiramesh.write(filename);
214  }
215 
216  };
217 
218 }
219 
220 // implementation
221 #if HAVE_AMIRAMESH
223 #endif
224 
225 #endif