dune-grid  2.3.1
amirameshwriter.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_AMIRAMESH_WRITER_HH
4 #define DUNE_AMIRAMESH_WRITER_HH
5 
6 #include <string>
7 
8 #include <dune/common/array.hh>
9 
10 #if HAVE_AMIRAMESH
11 #include <amiramesh/AmiraMesh.h>
12 #endif
13 
14 namespace Dune {
15 
20  template<class GridView>
22 
23  enum {dim = GridView::dimension};
24 
25  public:
26 
35  void addGrid(const GridView& gridView, bool splitAll=false);
36 
46  template <class GridType2>
47  void addLevelGrid(const GridType2& grid, int level, bool splitAll=false);
48 
57  template <class GridType2>
58  void addLeafGrid(const GridType2& grid, bool splitAll=false);
59 
66  template <class DataContainer>
67  void addCellData(const DataContainer& data, const GridView& gridView, bool GridSplitUp=false);
68 
75  template <class DataContainer>
76  void addVertexData(const DataContainer& data, const GridView& gridView, bool GridSplitUp=false);
77 
82  void write(const std::string& filename, bool ascii=false) const;
83 
86  template <class DataContainer>
87  void addUniformData(const GridView& gridView,
88  const array<unsigned int, dim>& n,
89  const DataContainer& data);
90 
102  static void writeSurfaceGrid(const GridView& gridView,
103  const std::string& filename);
104 
105  protected:
106 
107 #if HAVE_AMIRAMESH // better: use a pointer here and forward-declare AmiraMesh
108  AmiraMesh amiramesh_;
109 #endif
110  };
111 
116  template<class GridType>
118  : public AmiraMeshWriter<typename GridType::LevelGridView>
119  {
120 
121  public:
122 
125 
127  LevelAmiraMeshWriter(const GridType& grid, int level) {
128  this->addGrid(grid.levelGridView(level));
129  }
130 
137  static void writeGrid(const GridType& grid,
138  const std::string& filename,
139  int level) {
140  LevelAmiraMeshWriter amiramesh(grid, level);
141  amiramesh.write(filename);
142  }
143 
152  template <class VectorType>
153  static void writeBlockVector(const GridType& grid,
154  const VectorType& f,
155  const std::string& filename,
156  int level,
157  bool GridSplitUp=false) {
158  LevelAmiraMeshWriter amiramesh;
159  if (f.size()==grid.size(level,GridType::dimension))
160  amiramesh.addVertexData(f, grid.levelGridView(level),GridSplitUp);
161  else
162  amiramesh.addCellData(f, grid.levelGridView(level),GridSplitUp);
163  amiramesh.write(filename);
164  }
165 
166  };
167 
172  template<class GridType>
174  : public AmiraMeshWriter<typename GridType::LeafGridView>
175  {
176 
177  public:
178 
181 
183  LeafAmiraMeshWriter(const GridType& grid) {
184  this->addLeafGrid(grid);
185  }
186 
192  static void writeGrid(const GridType& grid,
193  const std::string& filename) {
194  LeafAmiraMeshWriter amiramesh(grid);
195  amiramesh.write(filename);
196  }
197 
204  template <class VectorType>
205  static void writeBlockVector(const GridType& grid,
206  const VectorType& f,
207  const std::string& filename,
208  bool GridSplitUp = false) {
209  LeafAmiraMeshWriter amiramesh;
210  if (f.size()==grid.size(GridType::dimension))
211  amiramesh.addVertexData(f, grid.leafView(),GridSplitUp);
212  else
213  amiramesh.addCellData(f, grid.leafView(),GridSplitUp);
214 
215  amiramesh.write(filename);
216  }
217 
218  };
219 
220 }
221 
222 // implementation
223 #if HAVE_AMIRAMESH
225 #endif
226 
227 #endif