Dune Core Modules (2.7.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 <type_traits>
7
9#include <dune/grid/common/backuprestore.hh>
10
11#include <dune/grid/geometrygrid/declaration.hh>
12#include <dune/grid/geometrygrid/capabilities.hh>
13
14namespace Dune
15{
16
17 namespace GeoGrid
18 {
19
20 // BackupRestoreFacilities
21 // -----------------------
22
23 template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities< Grid > ::v >
24 class BackupRestoreFacilities
25 {};
26
27 template< class Grid >
28 class BackupRestoreFacilities< Grid, true >
29 {
30 typedef BackupRestoreFacilities< Grid, true > This;
31
32 protected:
33 BackupRestoreFacilities ()
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 {
63 typedef BackupRestoreFacility< HostGrid > HostBackupRestoreFacility;
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
grid wrapper replacing the geometries
Definition: grid.hh:85
Grid abstract base class.
Definition: grid.hh:373
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:14
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 (Nov 12, 23:30, 2024)