dune-grid  2.3.1-rc1
alugrid/common/backuprestore.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GRID_ALUGRID_BACKUPRESTORE_HH
4 #define DUNE_GRID_ALUGRID_BACKUPRESTORE_HH
5 
6 //- system headers
7 #include <fstream>
8 
9 //- Dune headers
10 #include <dune/common/exceptions.hh>
13 
14 namespace Dune
15 {
16 
18  template< int dim, int dimworld, ALUGridElementType elType, ALUGridRefinementType refineType, class Comm >
19  struct BackupRestoreFacility< ALUGrid< dim, dimworld, elType, refineType, Comm > >
20  {
21  // type of grid
23 
24  static std::string createFilename( const std::string &path, const std::string &fileprefix )
25  {
26  std::string filename( path );
27  if( fileprefix.size() > 0 )
28  {
29  filename += "/" + fileprefix ;
30  }
31  else if( filename[ filename.size() - 1 ] == char('/') )
32  {
33  filename += "/alugrid";
34  }
35  return filename;
36  }
37 
39  static void backup ( const Grid &grid, const std::string &filename )
40  {
41  std::ofstream file( filename.c_str() );
42  if( file )
43  {
44  // call backup on grid
45  backup( grid, file );
46  }
47  else
48  {
49  std::cerr << "ERROR: BackupRestoreFacility::backup: couldn't open file `" << filename << "'" << std::endl;
50  }
51  }
52 
54  static void backup ( const Grid &grid, std::ostream &stream )
55  {
56  // call backup on grid
57  grid.backup( stream );
58  }
59 
61  static Grid *restore ( const std::string &filename )
62  {
63  // Problem here: how to pass boundary projections
64  std::ifstream file( filename.c_str() );
65  if( file )
66  {
67  return restore( file );
68  }
69  else
70  {
71  std::cerr << "ERROR: BackupRestoreFacility::restore: couldn't open file `" << filename << "'" << std::endl;
72  return 0;
73  }
74  }
75 
77  static Grid *restore ( std::istream &stream )
78  {
79  // Problem here: how to pass boundary projections
80  Grid* grid = new Grid();
81  grid->restore( stream );
82  return grid;
83  }
84  };
85 
86 } // namespace Dune
87 
88 #endif // #ifndef DUNE_GRID_ALUGRID_BACKUPRESTORE_HH
static Grid * restore(std::istream &stream)
Definition: alugrid/common/backuprestore.hh:77
static Grid * restore(const std::string &filename)
read a hierarchic grid from disk
Definition: common/backuprestore.hh:76
facility for writing and reading grids
Definition: common/backuprestore.hh:40
static void backup(const Grid &grid, std::ostream &stream)
Definition: alugrid/common/backuprestore.hh:54
static void backup(const Grid &grid, const std::string &filename)
Definition: alugrid/common/backuprestore.hh:39
[ provides Dune::Grid ]
Definition: alugrid/common/declaration.hh:63
ALUGrid< dim, dimworld, elType, refineType, Comm > Grid
Definition: alugrid/common/backuprestore.hh:22
static std::string createFilename(const std::string &path, const std::string &fileprefix)
Definition: alugrid/common/backuprestore.hh:24
static void backup(const Grid &grid, const std::string &filename)
write a hierarchic grid to disk
Definition: common/backuprestore.hh:49
static Grid * restore(const std::string &filename)
Definition: alugrid/common/backuprestore.hh:61