dune-grid  2.2.0
amirameshwriter.hh
Go to the documentation of this file.
00001 #ifndef DUNE_AMIRAMESH_WRITER_HH
00002 #define DUNE_AMIRAMESH_WRITER_HH
00003 
00004 #include <string>
00005 
00006 #include <dune/common/array.hh>
00007 
00008 #if HAVE_AMIRAMESH
00009 #include <amiramesh/AmiraMesh.h>
00010 #endif
00011 
00012 namespace Dune {
00013    
00018     template<class GridView>
00019     class AmiraMeshWriter {
00020 
00021         enum {dim = GridView::dimension};
00022 
00023     public:
00024 
00033         void addGrid(const GridView& gridView, bool splitAll=false);
00034 
00044         template <class GridType2>
00045         void addLevelGrid(const GridType2& grid, int level, bool splitAll=false);
00046 
00055         template <class GridType2>
00056         void addLeafGrid(const GridType2& grid, bool splitAll=false);
00057 
00064         template <class DataContainer>
00065         void addCellData(const DataContainer& data, const GridView& gridView, bool GridSplitUp=false);
00066 
00073         template <class DataContainer>
00074         void addVertexData(const DataContainer& data, const GridView& gridView, bool GridSplitUp=false);
00075 
00080         void write(const std::string& filename, bool ascii=false) const;
00081 
00084         template <class DataContainer>
00085         void addUniformData(const GridView& gridView,
00086                             const array<unsigned int, dim>& n,
00087                             const DataContainer& data);
00088         
00100         static void writeSurfaceGrid(const GridView& gridView,
00101                                      const std::string& filename);
00102 
00103     protected:
00104         
00105 #if HAVE_AMIRAMESH  // better: use a pointer here and forward-declare AmiraMesh
00106         AmiraMesh amiramesh_;
00107 #endif
00108     };
00109 
00114     template<class GridType>
00115     class LevelAmiraMeshWriter 
00116         : public AmiraMeshWriter<typename GridType::LevelGridView>
00117     {
00118 
00119     public:
00120 
00122         LevelAmiraMeshWriter() {}
00123 
00125         LevelAmiraMeshWriter(const GridType& grid, int level) {
00126             this->addGrid(grid.levelView(level));
00127         }
00128 
00135         static void writeGrid(const GridType& grid, 
00136                               const std::string& filename,
00137                               int level) {
00138             LevelAmiraMeshWriter amiramesh(grid, level);
00139             amiramesh.write(filename);
00140         }
00141 
00150         template <class VectorType>
00151         static void writeBlockVector(const GridType& grid,
00152                                      const VectorType& f,
00153                                      const std::string& filename,
00154                                      int level,
00155                                      bool GridSplitUp=false) {
00156                 LevelAmiraMeshWriter amiramesh;
00157             if (f.size()==grid.size(level,GridType::dimension))
00158                 amiramesh.addVertexData(f, grid.levelView(level),GridSplitUp);
00159             else
00160                 amiramesh.addCellData(f, grid.levelView(level),GridSplitUp);
00161             amiramesh.write(filename);
00162         }
00163 
00164     };
00165 
00170     template<class GridType>
00171     class LeafAmiraMeshWriter 
00172         : public AmiraMeshWriter<typename GridType::LeafGridView>
00173     {
00174 
00175     public:
00176 
00178         LeafAmiraMeshWriter() {}
00179 
00181         LeafAmiraMeshWriter(const GridType& grid) {
00182             this->addLeafGrid(grid);
00183         }
00184 
00190         static void writeGrid(const GridType& grid, 
00191                               const std::string& filename) {
00192             LeafAmiraMeshWriter amiramesh(grid);
00193             amiramesh.write(filename);
00194         }
00195 
00202         template <class VectorType>
00203         static void writeBlockVector(const GridType& grid,
00204                                      const VectorType& f,
00205                                      const std::string& filename,
00206                                      bool GridSplitUp = false) {
00207                 LeafAmiraMeshWriter amiramesh;
00208             if (f.size()==grid.size(GridType::dimension))
00209                 amiramesh.addVertexData(f, grid.leafView(),GridSplitUp);
00210             else
00211                 amiramesh.addCellData(f, grid.leafView(),GridSplitUp);
00212             
00213             amiramesh.write(filename);
00214         }
00215 
00216     };
00217 
00218 }
00219 
00220 // implementation
00221 #if HAVE_AMIRAMESH
00222 #include "amiramesh/amirameshwriter.cc"
00223 #endif
00224 
00225 #endif