Dune Core Modules (2.9.0)

backuprestore.hh
1#ifndef DUNE_GRID_ALUGRID_BACKUPRESTORE_HH
2#define DUNE_GRID_ALUGRID_BACKUPRESTORE_HH
3
4//- system headers
5#include <fstream>
6
7//- Dune headers
8#include <dune/alugrid/impl/macrofileheader.hh>
10#include <dune/grid/common/backuprestore.hh>
11#include <dune/alugrid/common/declaration.hh>
12
13namespace Dune
14{
15
17 template< int dim, int dimworld, ALUGridElementType elType, ALUGridRefinementType refineType, class Comm >
18 struct BackupRestoreFacility< ALUGrid< dim, dimworld, elType, refineType, Comm > >
19 {
20 // type of grid
22 typedef ::ALUGrid:: MacroFileHeader MacroFileHeaderType;
23
24 // if zlib was found we use the zlib compressed binary output
25 // otherwise binary output is used
26 typedef typename MacroFileHeaderType::Format MacroFileHeaderFormatType;
27
28 static std::string createFilename( const std::string &path, const std::string &fileprefix )
29 {
30 std::string filename( path );
31 if( fileprefix.size() > 0 )
32 {
33 filename += "/" + fileprefix ;
34 }
35 else if( filename[ filename.size() - 1 ] == char('/') )
36 {
37 filename += "/alugrid";
38 }
39 return filename;
40 }
41
43 static void backup ( const Grid &grid, const std::string &filename,
44 const MacroFileHeaderFormatType format = MacroFileHeaderType::defaultFormat )
45 {
46 std::ofstream file( filename.c_str() );
47 if( file )
48 {
49 // call backup on grid
50 backup( grid, file, format );
51 }
52 else
53 {
54 std::cerr << "ERROR: BackupRestoreFacility::backup: couldn't open file `" << filename << "'" << std::endl;
55 }
56 }
57
59 static void backup ( const Grid &grid, std::ostream &stream,
60 const MacroFileHeaderFormatType format = MacroFileHeaderType::defaultFormat )
61 {
62 // call backup on grid
63 grid.backup( stream, format );
64 }
65
67 static Grid *restore ( const std::string &filename )
68 {
69 // Problem here: how to pass boundary projections
70 std::ifstream file( filename.c_str() );
71 if( file )
72 {
73 return restore( file );
74 }
75 else
76 {
77 std::cerr << "ERROR: BackupRestoreFacility::restore: couldn't open file `" << filename << "'" << std::endl;
78 return 0;
79 }
80 }
81
83 static Grid *restore ( std::istream &stream )
84 {
85 // Problem here: how to pass boundary projections
86 Grid* grid = new Grid();
87 grid->restore( stream );
88 return grid;
89 }
90 };
91
92} // namespace Dune
93
94#endif // #ifndef DUNE_GRID_ALUGRID_BACKUPRESTORE_HH
unstructured parallel implementation of the DUNE grid interface
Definition: alugrid.hh:32
A few common exception classes.
Dune namespace.
Definition: alignedallocator.hh:13
static void backup(const Grid &grid, const std::string &filename, const MacroFileHeaderFormatType format=MacroFileHeaderType::defaultFormat)
Definition: backuprestore.hh:43
static Grid * restore(std::istream &stream)
Definition: backuprestore.hh:83
static void backup(const Grid &grid, std::ostream &stream, const MacroFileHeaderFormatType format=MacroFileHeaderType::defaultFormat)
Definition: backuprestore.hh:59
static Grid * restore(const std::string &filename)
Definition: backuprestore.hh:67
facility for writing and reading grids
Definition: backuprestore.hh:43
static Grid * restore(const std::string &filename)
read a hierarchic grid from disk
Definition: backuprestore.hh:78
static void backup(const Grid &grid, const std::string &filename)
write a hierarchic grid to disk
Definition: backuprestore.hh:51
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)