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