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_GRID_ALUGRID_BACKUPRESTORE_HH
4#define DUNE_GRID_ALUGRID_BACKUPRESTORE_HH
5
6//- system headers
7#include <fstream>
8
9//- Dune headers
11#include <dune/grid/common/backuprestore.hh>
12#include <dune/grid/alugrid/common/declaration.hh>
13
14namespace Dune
15{
16
18 template< int dim, int dimworld, ALUGridElementType elType, ALUGridRefinementType refineType, class Comm >
19 struct BackupRestoreFacility< ALUGrid< dim, dimworld, elType, refineType, Comm > >
20 {
21 // type of grid
23
24 static std::string createFilename( const std::string &path, const std::string &fileprefix )
25 {
26 std::string filename( path );
27 if( fileprefix.size() > 0 )
28 {
29 filename += "/" + fileprefix ;
30 }
31 else if( filename[ filename.size() - 1 ] == char('/') )
32 {
33 filename += "/alugrid";
34 }
35 return filename;
36 }
37
39 static void backup ( const Grid &grid, const std::string &filename )
40 {
41 std::ofstream file( filename.c_str() );
42 if( file )
43 {
44 // call backup on grid
45 backup( grid, file );
46 }
47 else
48 {
49 std::cerr << "ERROR: BackupRestoreFacility::backup: couldn't open file `" << filename << "'" << std::endl;
50 }
51 }
52
54 static void backup ( const Grid &grid, std::ostream &stream )
55 {
56 // call backup on grid
57 grid.backup( stream );
58 }
59
61 static Grid *restore ( const std::string &filename )
62 {
63 // Problem here: how to pass boundary projections
64 std::ifstream file( filename.c_str() );
65 if( file )
66 {
67 return restore( file );
68 }
69 else
70 {
71 std::cerr << "ERROR: BackupRestoreFacility::restore: couldn't open file `" << filename << "'" << std::endl;
72 return 0;
73 }
74 }
75
77 static Grid *restore ( std::istream &stream )
78 {
79 // Problem here: how to pass boundary projections
80 Grid* grid = new Grid();
81 grid->restore( stream );
82 return grid;
83 }
84 };
85
86} // namespace Dune
87
88#endif // #ifndef DUNE_GRID_ALUGRID_BACKUPRESTORE_HH
[ provides Dune::Grid ]
Definition: declaration.hh:63
A few common exception classes.
Dune namespace.
Definition: alignment.hh:10
static Grid * restore(std::istream &stream)
Definition: backuprestore.hh:77
static void backup(const Grid &grid, const std::string &filename)
Definition: backuprestore.hh:39
static void backup(const Grid &grid, std::ostream &stream)
Definition: backuprestore.hh:54
static Grid * restore(const std::string &filename)
Definition: backuprestore.hh:61
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)