backuprestore.hh 2.38 KB
Newer Older
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
1
2
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
Praetorius, Simon's avatar
Praetorius, Simon committed
3
4
#ifndef DUNE_CURVED_SURFACE_GRID_BACKUPRESTORE_HH
#define DUNE_CURVED_SURFACE_GRID_BACKUPRESTORE_HH
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
5
6
7
8
9
10
11

#include <dune/grid/common/backuprestore.hh>

#include <dune/curvedsurfacegrid/capabilities.hh>

namespace Dune
{
Praetorius, Simon's avatar
Praetorius, Simon committed
12
  namespace CGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
13
14
15
16
17
  {

    // BackupRestoreFacilities
    // -----------------------

Praetorius, Simon's avatar
Praetorius, Simon committed
18
    template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities<Grid> ::v >
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
19
20
21
22
    class BackupRestoreFacilities
    {};

    template< class Grid >
Praetorius, Simon's avatar
Praetorius, Simon committed
23
    class BackupRestoreFacilities<Grid, true>
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
24
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
25
      using Self = BackupRestoreFacilities<Grid, true>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
26
27
28
29
30
31

    protected:
      BackupRestoreFacilities ()
      {}

    private:
Praetorius, Simon's avatar
Praetorius, Simon committed
32
33
      BackupRestoreFacilities (const Self&);
      Self& operator= (const Self&);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
34
35

    protected:
Praetorius, Simon's avatar
Praetorius, Simon committed
36
      const Grid& asImp () const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
37
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
38
        return static_cast<const Grid&>(*this);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
39
40
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
41
      Grid& asImp ()
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
42
      {
Praetorius, Simon's avatar
Praetorius, Simon committed
43
        return static_cast<Grid&>(*this);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
44
45
46
      }
    };

Praetorius, Simon's avatar
Praetorius, Simon committed
47
  } // namespace CGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
48
49
50
51
52
53



  // BackupRestoreFacility for CurvedSurfaceGrid
  // -------------------------------------------

54
  template< class HostGrid, class CoordFunction, int order, class Allocator >
Praetorius, Simon's avatar
Praetorius, Simon committed
55
  struct BackupRestoreFacility<CurvedSurfaceGrid<HostGrid, CoordFunction, order, Allocator>>
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
56
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
57
58
    using Grid = CurvedSurfaceGrid<HostGrid, CoordFunction, order, Allocator>;
    using HostBackupRestoreFacility = BackupRestoreFacility<HostGrid>;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
59

Praetorius, Simon's avatar
Praetorius, Simon committed
60
    static void backup (const Grid& grid, const std::string& filename)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
61
62
    {
      // notice: We should also backup the coordinate function
63
      HostBackupRestoreFacility::backup(grid.hostGrid(), filename);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
64
65
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
66
    static void backup (const Grid& grid, const std::ostream& stream)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
67
68
    {
      // notice: We should also backup the coordinate function
Praetorius, Simon's avatar
Praetorius, Simon committed
69
      HostBackupRestoreFacility::backup(grid.hostGrid(), stream);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
70
71
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
72
    static Grid* restore (const std::string& filename)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
73
74
    {
      // notice: We should also restore the coordinate function
Praetorius, Simon's avatar
Praetorius, Simon committed
75
      HostGrid* hostGrid = HostBackupRestoreFacility::restore(filename);
76
      return new Grid(hostGrid, CoordFunction{});
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
77
78
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
79
    static Grid* restore (const std::istream& stream)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
80
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
81
      HostGrid* hostGrid = HostBackupRestoreFacility::restore(stream);
82
      return new Grid(hostGrid, CoordFunction{});
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
83
84
85
86
87
    }
  };

} // namespace Dune

Praetorius, Simon's avatar
Praetorius, Simon committed
88
#endif // DUNE_CURVED_SURFACE_GRID_BACKUPRESTORE_HH