dune-grid  2.4.1-rc2
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
88  HostBackupRestoreFacility::backup( grid.hostGrid(), stream );
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
BackupRestoreFacilities()
Definition: geometrygrid/backuprestore.hh:31
GeometryGrid< HostGrid, CoordFunction, Allocator > Grid
Definition: geometrygrid/backuprestore.hh:76
const HostGrid & hostGrid() const
Definition: geometrygrid/grid.hh:629
const Grid & asImp() const
Definition: geometrygrid/backuprestore.hh:55
Definition: geometrygrid/backuprestore.hh:26
bool writeGrid(const std::string &filename, double time) const
Definition: geometrygrid/backuprestore.hh:40
BackupRestoreFacility< HostGrid > HostBackupRestoreFacility
Definition: geometrygrid/backuprestore.hh:77
Definition: geometrygrid/backuprestore.hh:22
grid wrapper replacing the geometriesGeometryGrid wraps another DUNE grid and replaces its geometry b...
Definition: geometrygrid/declaration.hh:10
static Grid * restore(const std::string &path, const std::string &fileprefix)
Definition: geometrygrid/backuprestore.hh:91
static void backup(const Grid &grid, const std::string &path, const std::string &fileprefix)
Definition: geometrygrid/backuprestore.hh:79
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:388
Include standard header files.
Definition: agrid.hh:59
bool readGrid(const std::string &filename, double &time)
Definition: geometrygrid/backuprestore.hh:46
static Grid * restore(const std::istream &stream)
Definition: geometrygrid/backuprestore.hh:99
facility for writing and reading grids
Definition: common/backuprestore.hh:40
Grid & asImp()
Definition: geometrygrid/backuprestore.hh:60
static void backup(const Grid &grid, const std::ostream &stream)
Definition: geometrygrid/backuprestore.hh:85