dune-grid  2.2.1
geometrygrid/backuprestore.hh
Go to the documentation of this file.
1 #ifndef DUNE_GEOGRID_BACKUPRESTORE_HH
2 #define DUNE_GEOGRID_BACKUPRESTORE_HH
3 
6 
9 
10 namespace Dune
11 {
12 
13  namespace GeoGrid
14  {
15 
16  // BackupRestoreFacilities
17  // -----------------------
18 
19  template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities< Grid > ::v >
21  {};
22 
23  template< class Grid >
25  {
27 
28  protected:
30  {}
31 
32  private:
33  BackupRestoreFacilities ( const This & );
34  This &operator= ( const This & );
35 
36  public:
37  template< GrapeIOFileFormatType type >
38  bool writeGrid ( const std::string &filename, double time ) const
39  {
40  return asImp().hostGrid().template writeGrid< type >( filename, time );
41  }
42 
43  template< GrapeIOFileFormatType type >
44  bool readGrid ( const std::string &filename, double &time )
45  {
46  const bool success
47  = asImp().hostGrid().template readGrid< type >( filename, time );
48  asImp().update();
49  return success;
50  }
51 
52  protected:
53  const Grid &asImp () const
54  {
55  return static_cast< const Grid & >( *this );
56  }
57 
58  Grid &asImp ()
59  {
60  return static_cast< Grid & >( *this );
61  }
62  };
63 
64  } // namespace GeoGrid
65 
66 
67 
68  // BackupRestoreFacility for GeometryGrid
69  // --------------------------------------
70 
71  template< class HostGrid, class CoordFunction, class Allocator >
72  struct BackupRestoreFacility< GeometryGrid< HostGrid, CoordFunction, Allocator > >
73  {
76 
77  static void backup ( const Grid &grid, const std::string &path, const std::string &fileprefix )
78  {
79  // notice: We should also backup the coordinate function
80  HostBackupRestoreFacility::backup( grid.hostGrid(), path, fileprefix );
81  }
82 
83  static void backup ( const Grid &grid, const std::ostream &stream )
84  {
85  // notice: We should also backup the coordinate function
86  HostBackupRestoreFacility::backup( grid.hostGrid(), stream );
87  }
88 
89  static Grid *restore ( const std::string &path, const std::string &fileprefix )
90  {
91  // notice: We should also restore the coordinate function
92  HostGrid *hostGrid = HostBackupRestoreFacility::restore( path, fileprefix );
93  CoordFunction *coordFunction = new CoordFunction();
94  return new Grid( hostGrid, coordFunction );
95  }
96 
97  static Grid *restore ( const std::istream &stream )
98  {
99  // notice: We should also restore the coordinate function
100  HostGrid *hostGrid = HostBackupRestoreFacility::restore( stream );
101  CoordFunction *coordFunction = new CoordFunction();
102  return new Grid( hostGrid, coordFunction );
103  }
104  };
105 
106 } // namespace Dune
107 
108 #endif // #ifndef DUNE_GEOGRID_BACKUPRESTORE_HH