1 #ifndef DUNE_GRID_ALUGRID_BACKUPRESTORE_HH 2 #define DUNE_GRID_ALUGRID_BACKUPRESTORE_HH 3 4 //- system headers 5 #include <fstream> 6 7 //- Dune headers 8 #include <dune/alugrid/impl/macrofileheader.hh> 9 #include <dune/common/exceptions.hh> 10 #include <dune/grid/common/backuprestore.hh> 11 #include <dune/alugrid/common/declaration.hh> 12 13 namespace Dune 14 { 15 16 /** \copydoc Dune::BackupRestoreFacility */ 17 template< int dim, int dimworld, ALUGridElementType elType, ALUGridRefinementType refineType, class Comm > 18 struct BackupRestoreFacility< ALUGrid< dim, dimworld, elType, refineType, Comm > > 19 { 20 // type of grid 21 typedef ALUGrid< dim, dimworld, elType, refineType, Comm > Grid; 22 typedef ::ALUGrid:: MacroFileHeader MacroFileHeaderType; 23 24 // if zlib was found we use the zlib compressed binary output 25 // otherwise binary output is used 26 typedef typename MacroFileHeaderType::Format MacroFileHeaderFormatType; 27 createFilenameDune::BackupRestoreFacility28 static std::string createFilename( const std::string &path, const std::string &fileprefix ) 29 { 30 std::string filename( path ); 31 if( fileprefix.size() > 0 ) 32 { 33 filename += "/" + fileprefix ; 34 } 35 else if( filename[ filename.size() - 1 ] == char('/') ) 36 { 37 filename += "/alugrid"; 38 } 39 return filename; 40 } 41 42 /** \copydoc Dune::BackupRestoreFacility::backup(grid,filename) */ backupDune::BackupRestoreFacility43 static void backup ( const Grid &grid, const std::string &filename, 44 const MacroFileHeaderFormatType format = MacroFileHeaderType::defaultFormat ) 45 { 46 std::ofstream file( filename.c_str() ); 47 if( file ) 48 { 49 // call backup on grid 50 backup( grid, file, format ); 51 } 52 else 53 { 54 std::cerr << "ERROR: BackupRestoreFacility::backup: couldn't open file `" << filename << "'" << std::endl; 55 } 56 } 57 58 /** \copydoc Dune::BackupRestoreFacility::backup(grid,stream) */ backupDune::BackupRestoreFacility59 static void backup ( const Grid &grid, std::ostream &stream, 60 const MacroFileHeaderFormatType format = MacroFileHeaderType::defaultFormat ) 61 { 62 // call backup on grid 63 grid.backup( stream, format ); 64 } 65 66 /** \copydoc Dune::BackupRestoreFacility::restore(filename) */ restoreDune::BackupRestoreFacility67 static Grid *restore ( const std::string &filename ) 68 { 69 // Problem here: how to pass boundary projections 70 std::ifstream file( filename.c_str() ); 71 if( file ) 72 { 73 return restore( file ); 74 } 75 else 76 { 77 std::cerr << "ERROR: BackupRestoreFacility::restore: couldn't open file `" << filename << "'" << std::endl; 78 return 0; 79 } 80 } 81 82 /** \copydoc Dune::BackupRestoreFacility::restore(stream) */ restoreDune::BackupRestoreFacility83 static Grid *restore ( std::istream &stream ) 84 { 85 // Problem here: how to pass boundary projections 86 Grid* grid = new Grid(); 87 grid->restore( stream ); 88 return grid; 89 } 90 }; 91 92 } // namespace Dune 93 94 #endif // #ifndef DUNE_GRID_ALUGRID_BACKUPRESTORE_HH 95