KASKADE 7 development version
amirameshwriter.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2023 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12// Code from Dune contributed by Oliver Sander.
13
14
15#ifndef DUNE_AMIRAMESH_WRITER_HH
16#define DUNE_AMIRAMESH_WRITER_HH
17
18#include <string>
19#include <array>
20
21#if HAVE_AMIRAMESH
22#include <amiramesh/AmiraMesh.h>
23#endif
24
25namespace Dune {
26
31 template<class GridView>
33
34 enum {dim = GridView::dimension};
35
36 public:
37
46 void addGrid(const GridView& gridView, bool splitAll=false);
47
57 template <class GridType2>
58 void addLevelGrid(const GridType2& grid, int level, bool splitAll=false);
59
68 template <class GridType2>
69 void addLeafGrid(const GridType2& grid, bool splitAll=false);
70
77 template <class DataContainer>
78 void addCellData(const DataContainer& data, const GridView& gridView, bool GridSplitUp=false);
79
86 template <class DataContainer>
87 void addVertexData(const DataContainer& data, const GridView& gridView, bool GridSplitUp=false);
88
93 void write(const std::string& filename, bool ascii=false) const;
94
97 template <class DataContainer>
98 void addUniformData(const GridView& gridView,
99 const std::array<unsigned int, dim>& n,
100 const DataContainer& data);
101
113 static void writeSurfaceGrid(const GridView& gridView,
114 const std::string& filename);
115
116 protected:
117
118#if HAVE_AMIRAMESH // better: use a pointer here and forward-declare AmiraMesh
119 AmiraMesh amiramesh_;
120#endif
121 };
122
127 template<class GridType>
129 : public AmiraMeshWriter<typename GridType::LevelGridView>
130 {
131
132 public:
133
136
138 LevelAmiraMeshWriter(const GridType& grid, int level) {
139 this->addGrid(grid.levelGridView(level));
140 }
141
148 static void writeGrid(const GridType& grid,
149 const std::string& filename,
150 int level) {
151 LevelAmiraMeshWriter amiramesh(grid, level);
152 amiramesh.write(filename);
153 }
154
163 template <class VectorType>
164 static void writeBlockVector(const GridType& grid,
165 const VectorType& f,
166 const std::string& filename,
167 int level,
168 bool GridSplitUp=false) {
169 LevelAmiraMeshWriter amiramesh;
170 if (f.size()==grid.size(level,GridType::dimension))
171 amiramesh.addVertexData(f, grid.levelGridView(level),GridSplitUp);
172 else
173 amiramesh.addCellData(f, grid.levelGridView(level),GridSplitUp);
174 amiramesh.write(filename);
175 }
176
177 };
178
183 template<class GridType>
185 : public AmiraMeshWriter<typename GridType::LeafGridView>
186 {
187
188 public:
189
192
194 LeafAmiraMeshWriter(const GridType& grid) {
195 this->addLeafGrid(grid);
196 }
197
203 static void writeGrid(const GridType& grid,
204 const std::string& filename) {
205 LeafAmiraMeshWriter amiramesh(grid);
206 amiramesh.write(filename);
207 }
208
215 template <class VectorType>
216 static void writeBlockVector(const GridType& grid,
217 const VectorType& f,
218 const std::string& filename,
219 bool GridSplitUp = false) {
220 LeafAmiraMeshWriter amiramesh;
221 if ((int) f.size() == grid.size(GridType::dimension))
222 amiramesh.addVertexData(f, grid.leafGridView(),GridSplitUp);
223 else
224 amiramesh.addCellData(f, grid.leafGridView(),GridSplitUp);
225
226 amiramesh.write(filename);
227 }
228
229 };
230
231}
232
233// implementation
234#if HAVE_AMIRAMESH
235#include "io/dune/amirameshwriter.cc"
236#endif
237
238#endif
Provides file writing facilities in the AmiraMesh format.
void addLeafGrid(const GridType2 &grid, bool splitAll=false)
Add leaf grid.
void write(const std::string &filename, bool ascii=false) const
Write AmiraMesh object to disk.
static void writeSurfaceGrid(const GridView &gridView, const std::string &filename)
Write a 2d grid in a 3d world.
void addVertexData(const DataContainer &data, const GridView &gridView, bool GridSplitUp=false)
Add vertex data.
void addGrid(const GridView &gridView, bool splitAll=false)
Add a grid view to the file.
void addLevelGrid(const GridType2 &grid, int level, bool splitAll=false)
Add level grid.
void addUniformData(const GridView &gridView, const std::array< unsigned int, dim > &n, const DataContainer &data)
Write data on a uniform grid into an AmiraMesh file.
void addCellData(const DataContainer &data, const GridView &gridView, bool GridSplitUp=false)
Add cell data.
Provides file writing facilities in the AmiraMesh format for leaf grids.
static void writeBlockVector(const GridType &grid, const VectorType &f, const std::string &filename, bool GridSplitUp=false)
Writes an ISTL block vector in AmiraMesh format.
LeafAmiraMeshWriter()
Default constructor.
static void writeGrid(const GridType &grid, const std::string &filename)
Write a grid in AmiraMesh format.
LeafAmiraMeshWriter(const GridType &grid)
Constructor which initializes the AmiraMesh object with a given leaf grid.
Provides file writing facilities in the AmiraMesh format for level grids.
static void writeBlockVector(const GridType &grid, const VectorType &f, const std::string &filename, int level, bool GridSplitUp=false)
Writes an ISTL block vector in AmiraMesh format.
LevelAmiraMeshWriter(const GridType &grid, int level)
Constructor which initializes the AmiraMesh object with a given level grid.
static void writeGrid(const GridType &grid, const std::string &filename, int level)
Write a grid in AmiraMesh format.
LevelAmiraMeshWriter()
Default constructor.