dune-alugrid  3.0.0
backuprestore.hh
Go to the documentation of this file.
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>
12 
13 namespace Dune
14 {
15 
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
22 
23  // if zlib was found we use the zlib compressed binary output
24  // otherwise binary output is used
25  static const ::ALUGrid:: MacroFileHeader::Format defaultFormat = ::ALUGrid::
26  MacroFileHeader::defaultFormat ;
27 
28  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 
43  static void backup ( const Grid &grid, const std::string &filename,
44  const ::ALUGrid:: MacroFileHeader::Format format = defaultFormat )
45  {
46  std::ofstream file( filename.c_str() );
47  if( file )
48  {
49  // call backup on grid
50  backup( grid, file, defaultFormat );
51  }
52  else
53  {
54  std::cerr << "ERROR: BackupRestoreFacility::backup: couldn't open file `" << filename << "'" << std::endl;
55  }
56  }
57 
59  static void backup ( const Grid &grid, std::ostream &stream,
60  const ::ALUGrid:: MacroFileHeader::Format format = defaultFormat )
61  {
62  // call backup on grid
63  grid.backup( stream, format );
64  }
65 
67  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 
83  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
Dune::BackupRestoreFacility< ALUGrid< dim, dimworld, elType, refineType, Comm > >::restore
static Grid * restore(const std::string &filename)
Definition: backuprestore.hh:67
Dune::BackupRestoreFacility< ALUGrid< dim, dimworld, elType, refineType, Comm > >::createFilename
static std::string createFilename(const std::string &path, const std::string &fileprefix)
Definition: backuprestore.hh:28
Dune::BackupRestoreFacility< ALUGrid< dim, dimworld, elType, refineType, Comm > >::backup
static void backup(const Grid &grid, std::ostream &stream, const ::ALUGrid::MacroFileHeader::Format format=defaultFormat)
Definition: backuprestore.hh:59
Dune::BackupRestoreFacility< ALUGrid< dim, dimworld, elType, refineType, Comm > >::restore
static Grid * restore(std::istream &stream)
Definition: backuprestore.hh:83
Dune::BackupRestoreFacility< ALUGrid< dim, dimworld, elType, refineType, Comm > >::backup
static void backup(const Grid &grid, const std::string &filename, const ::ALUGrid::MacroFileHeader::Format format=defaultFormat)
Definition: backuprestore.hh:43
ALUGrid
Definition: alu3dinclude.hh:49
Dune::ALUGrid
unstructured parallel implementation of the DUNE grid interface
Definition: alugrid.hh:29
Dune::BackupRestoreFacility< ALUGrid< dim, dimworld, elType, refineType, Comm > >::Grid
ALUGrid< dim, dimworld, elType, refineType, Comm > Grid
Definition: backuprestore.hh:21
declaration.hh
Dune
Definition: alu3dinclude.hh:79