amirameshwriter.hh

00001 #ifndef DUNE_AMIRAMESH_WRITER_HH
00002 #define DUNE_AMIRAMESH_WRITER_HH
00003 
00004 #include <string>
00005 
00006 #include <dune/common/fixedarray.hh>
00007 #include <amiramesh/AmiraMesh.h>
00008 
00009 
00010 namespace Dune {
00011    
00016     template<class GridView>
00017     class AmiraMeshWriter {
00018 
00019         enum {dim = GridView::dimension};
00020 
00021     public:
00022 
00029         void addGrid(const GridView& gridView, bool splitQuads=false);
00030 
00038         template <class GridType2>
00039         void addLevelGrid(const GridType2& grid, int level, bool splitQuads=false);
00040 
00047         template <class GridType2>
00048         void addLeafGrid(const GridType2& grid, bool splitQuads=false);
00049 
00054         template <class DataContainer>
00055         void addCellData(const DataContainer& data, const GridView& gridView);
00056 
00061         template <class DataContainer>
00062         void addVertexData(const DataContainer& data, const GridView& gridView);
00063 
00068         void write(const std::string& filename, bool ascii=false) const;
00069 
00072         template <class DataContainer>
00073         void addUniformData(const GridView& gridView,
00074                             const array<unsigned int, dim>& n,
00075                             const DataContainer& data);
00076 
00077     protected:
00078         
00079         AmiraMesh amiramesh_;
00080     };
00081 
00086     template<class GridType>
00087     class LevelAmiraMeshWriter 
00088         : public AmiraMeshWriter<typename GridType::LevelGridView>
00089     {
00090 
00091     public:
00092 
00094         LevelAmiraMeshWriter() {}
00095 
00097         LevelAmiraMeshWriter(const GridType& grid, int level) {
00098             this->addGrid(grid.levelView(level));
00099         }
00100 
00107         static void writeGrid(const GridType& grid, 
00108                               const std::string& filename,
00109                               int level) {
00110             LevelAmiraMeshWriter amiramesh(grid, level);
00111             amiramesh.write(filename);
00112         }
00113 
00120         template <class VectorType>
00121         static void writeBlockVector(const GridType& grid,
00122                                      const VectorType& f,
00123                                      const std::string& filename,
00124                                      int level) {
00125             
00126             LevelAmiraMeshWriter amiramesh;
00127             amiramesh.addVertexData(f, grid.levelView(level));
00128             amiramesh.write(filename);
00129         }
00130 
00131     };
00132 
00137     template<class GridType>
00138     class LeafAmiraMeshWriter 
00139         : public AmiraMeshWriter<typename GridType::LeafGridView>
00140     {
00141 
00142     public:
00143 
00145         LeafAmiraMeshWriter() {}
00146 
00148         LeafAmiraMeshWriter(const GridType& grid) {
00149             this->addLeafGrid(grid);
00150         }
00151 
00157         static void writeGrid(const GridType& grid, 
00158                               const std::string& filename) {
00159             LeafAmiraMeshWriter amiramesh(grid);
00160             amiramesh.write(filename);
00161         }
00162 
00168         template <class VectorType>
00169         static void writeBlockVector(const GridType& grid,
00170                                      const VectorType& f,
00171                                      const std::string& filename) {
00172             LeafAmiraMeshWriter amiramesh;
00173             amiramesh.addVertexData(f, grid.leafView());
00174             amiramesh.write(filename);
00175         }
00176 
00177     };
00178 
00179 }
00180 
00181 // implementation
00182 #include "amiramesh/amirameshwriter.cc"
00183 
00184 #endif

Generated on Tue Jul 28 22:28:14 2009 for dune-grid by  doxygen 1.5.6