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
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
const HostGrid & hostGrid() const
Definition: geometrygrid/grid.hh:696
facility for writing and reading grids
Definition: common/backuprestore.hh:40
const Grid & asImp() const
Definition: geometrygrid/backuprestore.hh:55
static Grid * restore(const std::string &path, const std::string &fileprefix)
Definition: geometrygrid/backuprestore.hh:91
Grid & asImp()
Definition: geometrygrid/backuprestore.hh:60
Definition: geometrygrid/backuprestore.hh:26
bool writeGrid(const std::string &filename, double time) const
Definition: geometrygrid/backuprestore.hh:40
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:386
static void backup(const Grid &grid, const std::ostream &stream)
Definition: geometrygrid/backuprestore.hh:85
BackupRestoreFacility< HostGrid > HostBackupRestoreFacility
Definition: geometrygrid/backuprestore.hh:77
GeometryGrid< HostGrid, CoordFunction, Allocator > Grid
Definition: geometrygrid/backuprestore.hh:76
bool readGrid(const std::string &filename, double &time)
Definition: geometrygrid/backuprestore.hh:46
Definition: geometrygrid/backuprestore.hh:22
static Grid * restore(const std::istream &stream)
Definition: geometrygrid/backuprestore.hh:99
static void backup(const Grid &grid, const std::string &path, const std::string &fileprefix)
Definition: geometrygrid/backuprestore.hh:79
grid wrapper replacing the geometriesGeometryGrid wraps another DUNE grid and replaces its geometry b...
Definition: geometrygrid/declaration.hh:10