00001 #ifndef DUNE_AMIRAMESH_WRITER_HH
00002 #define DUNE_AMIRAMESH_WRITER_HH
00003
00004 #include <string>
00005
00006 #include <amiramesh/AmiraMesh.h>
00007
00008
00009 namespace Dune {
00010
00015 template<class GridType, class IndexSetType>
00016 class AmiraMeshWriter {
00017
00018 enum {dim = GridType::dimension};
00019
00020 public:
00021
00029 template <class GridType2, class IndexSetType2>
00030 void addGrid(const GridType2& grid, const IndexSetType2& indexSet, bool splitQuads=false);
00031
00039 template <class GridType2>
00040 void addLevelGrid(const GridType2& grid, int level, bool splitQuads=false);
00041
00048 template <class GridType2>
00049 void addLeafGrid(const GridType2& grid, bool splitQuads=false);
00050
00052 template <class GridType2, class DataContainer>
00053 void addCellData(const DataContainer& data, const GridType2& grid);
00054
00059 template <class DataContainer>
00060 void addVertexData(const DataContainer& data, const IndexSetType& indexSet);
00061
00066 void write(const std::string& filename, bool ascii=false) const;
00067
00068 protected:
00069
00070 AmiraMesh amiramesh_;
00071 };
00072
00077 template<class GridType>
00078 class LevelAmiraMeshWriter
00079 : public AmiraMeshWriter<GridType,typename GridType::Traits::LevelIndexSet>
00080 {
00081
00082 enum {dim = GridType::dimension};
00083
00084 typedef AmiraMeshWriter<GridType,typename GridType::Traits::LevelIndexSet> WriterType;
00085
00086 public:
00087
00089 LevelAmiraMeshWriter() {}
00090
00092 LevelAmiraMeshWriter(const GridType& grid, int level) {
00093 this->addLevelGrid(grid, level);
00094 }
00095
00102 static void writeGrid(const GridType& grid,
00103 const std::string& filename,
00104 int level) {
00105 LevelAmiraMeshWriter amiramesh(grid, level);
00106 amiramesh.write(filename);
00107 }
00108
00115 template <class VectorType>
00116 static void writeBlockVector(const GridType& grid,
00117 const VectorType& f,
00118 const std::string& filename,
00119 int level) {
00120
00121 LevelAmiraMeshWriter amiramesh;
00122 amiramesh.addVertexData(f, grid.levelIndexSet(level));
00123 amiramesh.write(filename);
00124 }
00125
00126 };
00127
00132 template<class GridType>
00133 class LeafAmiraMeshWriter
00134 : public AmiraMeshWriter<GridType,typename GridType::Traits::LeafIndexSet>
00135 {
00136
00137 enum {dim = GridType::dimension};
00138
00139 typedef AmiraMeshWriter<GridType,typename GridType::Traits::LeafIndexSet> WriterType;
00140
00141 public:
00142
00144 LeafAmiraMeshWriter() {}
00145
00147 LeafAmiraMeshWriter(const GridType& grid) {
00148 this->addLeafGrid(grid);
00149 }
00150
00156 static void writeGrid(const GridType& grid,
00157 const std::string& filename) {
00158 LeafAmiraMeshWriter amiramesh(grid);
00159 amiramesh.write(filename);
00160 }
00161
00167 template <class VectorType>
00168 static void writeBlockVector(const GridType& grid,
00169 const VectorType& f,
00170 const std::string& filename) {
00171 LeafAmiraMeshWriter amiramesh;
00172 amiramesh.addVertexData(f, grid.leafIndexSet());
00173 amiramesh.write(filename);
00174 }
00175
00176 };
00177
00178 }
00179
00180
00181 #include "amiramesh/amirameshwriter.cc"
00182
00183
00184
00185
00186 #endif