dune-grid  2.7.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 
6 #include <type_traits>
7 
8 #include <dune/common/exceptions.hh>
10 
13 
14 namespace Dune
15 {
16 
17  namespace GeoGrid
18  {
19 
20  // BackupRestoreFacilities
21  // -----------------------
22 
23  template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities< Grid > ::v >
25  {};
26 
27  template< class Grid >
29  {
31 
32  protected:
34  {}
35 
36  private:
37  BackupRestoreFacilities ( const This & );
38  This &operator= ( const This & );
39 
40  protected:
41  const Grid &asImp () const
42  {
43  return static_cast< const Grid & >( *this );
44  }
45 
46  Grid &asImp ()
47  {
48  return static_cast< Grid & >( *this );
49  }
50  };
51 
52  } // namespace GeoGrid
53 
54 
55 
56  // BackupRestoreFacility for GeometryGrid
57  // --------------------------------------
58 
59  template< class HostGrid, class CoordFunction, class Allocator >
60  struct BackupRestoreFacility< GeometryGrid< HostGrid, CoordFunction, Allocator > >
61  {
64 
66  template <class Output>
67  static void backup ( const Grid &grid, const Output &filename_or_stream )
68  {
69  // notice: We should also backup the coordinate function
70  HostBackupRestoreFacility::backup( grid.hostGrid(), filename_or_stream );
71  }
72 
74  template <class Input>
75  static Grid *restore ( const Input &filename_or_stream )
76  {
77  // notice: assumes the CoordFunction to be default-constructible
78  return restore_impl(filename_or_stream, std::is_default_constructible<CoordFunction>{});
79  }
80 
81  private:
82  template <class Input>
83  static Grid *restore_impl ( const Input &filename_or_stream, std::true_type )
84  {
85  // notice: We should also restore the coordinate function
86  HostGrid *hostGrid = HostBackupRestoreFacility::restore( filename_or_stream );
87  CoordFunction *coordFunction = new CoordFunction();
88  return new Grid( hostGrid, coordFunction );
89  }
90 
91  template <class Input>
92  static Grid *restore_impl ( const Input &filename_stream, std::false_type )
93  {
94  DUNE_THROW(NotImplemented,
95  "Restoring a GeometryGrid with a CoordFunction that is not default-constructible is not implemented.");
96  return nullptr;
97  }
98  };
99 
100 } // namespace Dune
101 
102 #endif // #ifndef DUNE_GEOGRID_BACKUPRESTORE_HH
Include standard header files.
Definition: agrid.hh:59
facility for writing and reading grids
Definition: common/backuprestore.hh:41
Grid abstract base class.
Definition: common/grid.hh:373
Definition: geometrygrid/backuprestore.hh:25
Definition: geometrygrid/backuprestore.hh:29
const Grid & asImp() const
Definition: geometrygrid/backuprestore.hh:41
Grid & asImp()
Definition: geometrygrid/backuprestore.hh:46
BackupRestoreFacilities()
Definition: geometrygrid/backuprestore.hh:33
BackupRestoreFacility< HostGrid > HostBackupRestoreFacility
Definition: geometrygrid/backuprestore.hh:63
static void backup(const Grid &grid, const Output &filename_or_stream)
Backup the grid to file or stream.
Definition: geometrygrid/backuprestore.hh:67
static Grid * restore(const Input &filename_or_stream)
Restore the grid from file or stream.
Definition: geometrygrid/backuprestore.hh:75
GeometryGrid< HostGrid, CoordFunction, Allocator > Grid
Definition: geometrygrid/backuprestore.hh:62
grid wrapper replacing the geometries
Definition: geometrygrid/grid.hh:85
const HostGrid & hostGrid() const
obtain constant reference to the host grid
Definition: geometrygrid/grid.hh:576