Dune Core Modules (2.4.1)

backuprestore.hh
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 <dune/grid/common/backuprestore.hh>
7#include <dune/grid/utility/grapedataioformattypes.hh>
8
9#include <dune/grid/geometrygrid/declaration.hh>
10#include <dune/grid/geometrygrid/capabilities.hh>
11
12namespace Dune
13{
14
15 namespace GeoGrid
16 {
17
18 // BackupRestoreFacilities
19 // -----------------------
20
21 template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities< Grid > ::v >
22 class BackupRestoreFacilities
23 {};
24
25 template< class Grid >
26 class BackupRestoreFacilities< Grid, true >
27 {
28 typedef BackupRestoreFacilities< Grid, true > This;
29
30 protected:
31 BackupRestoreFacilities ()
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 {
77 typedef BackupRestoreFacility< HostGrid > HostBackupRestoreFacility;
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
grid wrapper replacing the geometries
Definition: grid.hh:83
Grid abstract base class.
Definition: grid.hh:388
Dune namespace.
Definition: alignment.hh:10
facility for writing and reading grids
Definition: backuprestore.hh:41
static Grid * restore(const std::string &filename)
read a hierarchic grid from disk
Definition: backuprestore.hh:76
static void backup(const Grid &grid, const std::string &filename)
write a hierarchic grid to disk
Definition: backuprestore.hh:49
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)