dune-grid  2.5-git
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 
7 
10 
11 namespace Dune
12 {
13 
14  namespace GeoGrid
15  {
16 
17  // BackupRestoreFacilities
18  // -----------------------
19 
20  template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities< Grid > ::v >
22  {};
23 
24  template< class Grid >
26  {
28 
29  protected:
31  {}
32 
33  private:
34  BackupRestoreFacilities ( const This & );
35  This &operator= ( const This & );
36 
37  protected:
38  const Grid &asImp () const
39  {
40  return static_cast< const Grid & >( *this );
41  }
42 
43  Grid &asImp ()
44  {
45  return static_cast< Grid & >( *this );
46  }
47  };
48 
49  } // namespace GeoGrid
50 
51 
52 
53  // BackupRestoreFacility for GeometryGrid
54  // --------------------------------------
55 
56  template< class HostGrid, class CoordFunction, class Allocator >
57  struct BackupRestoreFacility< GeometryGrid< HostGrid, CoordFunction, Allocator > >
58  {
61 
62  static void backup ( const Grid &grid, const std::string &path, const std::string &fileprefix )
63  {
64  // notice: We should also backup the coordinate function
65  HostBackupRestoreFacility::backup( grid.hostGrid(), path, fileprefix );
66  }
67 
68  static void backup ( const Grid &grid, const std::ostream &stream )
69  {
70  // notice: We should also backup the coordinate function
71  HostBackupRestoreFacility::backup( grid.hostGrid(), stream );
72  }
73 
74  static Grid *restore ( const std::string &path, const std::string &fileprefix )
75  {
76  // notice: We should also restore the coordinate function
77  HostGrid *hostGrid = HostBackupRestoreFacility::restore( path, fileprefix );
78  CoordFunction *coordFunction = new CoordFunction();
79  return new Grid( hostGrid, coordFunction );
80  }
81 
82  static Grid *restore ( const std::istream &stream )
83  {
84  // notice: We should also restore the coordinate function
85  HostGrid *hostGrid = HostBackupRestoreFacility::restore( stream );
86  CoordFunction *coordFunction = new CoordFunction();
87  return new Grid( hostGrid, coordFunction );
88  }
89  };
90 
91 } // namespace Dune
92 
93 #endif // #ifndef DUNE_GEOGRID_BACKUPRESTORE_HH
const Grid & asImp() const
Definition: geometrygrid/backuprestore.hh:38
static void backup(const Grid &grid, const std::string &path, const std::string &fileprefix)
Definition: geometrygrid/backuprestore.hh:62
static Grid * restore(const std::string &path, const std::string &fileprefix)
Definition: geometrygrid/backuprestore.hh:74
BackupRestoreFacilities()
Definition: geometrygrid/backuprestore.hh:30
facility for writing and reading grids
Definition: common/backuprestore.hh:40
static void backup(const Grid &grid, const std::ostream &stream)
Definition: geometrygrid/backuprestore.hh:68
GeometryGrid< HostGrid, CoordFunction, Allocator > Grid
Definition: geometrygrid/backuprestore.hh:59
Include standard header files.
Definition: agrid.hh:59
Definition: geometrygrid/backuprestore.hh:25
BackupRestoreFacility< HostGrid > HostBackupRestoreFacility
Definition: geometrygrid/backuprestore.hh:60
static Grid * restore(const std::istream &stream)
Definition: geometrygrid/backuprestore.hh:82
Definition: geometrygrid/backuprestore.hh:21
const HostGrid & hostGrid() const
obtain constant reference to the host grid
Definition: geometrygrid/grid.hh:628
Grid & asImp()
Definition: geometrygrid/backuprestore.hh:43
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:373
grid wrapper replacing the geometriesGeometryGrid wraps another DUNE grid and replaces its geometry b...
Definition: declaration.hh:10