5#ifndef DUNE_GRID_YASPGRID_BACKUPRESTORE_HH
6#define DUNE_GRID_YASPGRID_BACKUPRESTORE_HH
13#include <dune/common/exceptions.hh>
14#include <dune/common/fvector.hh>
20#define YASPGRID_BACKUPRESTORE_FORMAT_VERSION 2
25 template<
class Coordinates>
34 static void readOrigin(S& , Dune::FieldVector<typename Coordinates::ctype,Coordinates::dimension>& )
37 template<
typename... A>
39 const Dune::FieldVector<typename Coordinates::ctype,Coordinates::dimension>& , A... args)
45 template<
class ctype,
int dim>
54 for (
int i=0; i<dim; i++)
55 s << coord.
origin(i) <<
" ";
60 static void readOrigin(S& s, Dune::FieldVector<ctype, dim>& coord)
64 for (
int i=0; i<dim; i++)
68 template<
typename... A>
70 const Dune::FieldVector<typename Coordinates::ctype,Coordinates::dimension>& lowerleft,
71 const Dune::FieldVector<typename Coordinates::ctype,Coordinates::dimension>& extension, A... args)
73 Dune::FieldVector<typename Coordinates::ctype,Coordinates::dimension> upperright(lowerleft);
74 upperright += extension;
80 template<
int dim,
class Coordinates>
89 static void backup (
const Grid &grid,
const std::string &filename )
91 if (grid.
comm().rank() == 0)
93 std::ofstream file(filename);
100 std::cerr <<
"ERROR: BackupRestoreFacility::backup: couldn't open file `" << filename <<
"'" << std::endl;
105 static void backup (
const Grid &grid, std::ostream &stream )
108 stream <<
"Torus structure: ";
109 for (
int i=0; i<dim; i++)
111 stream << std::endl <<
"Refinement level: " << grid.
maxLevel() << std::endl;
112 stream <<
"Periodicity: ";
113 for (
int i=0; i<dim; i++)
115 stream << std::endl <<
"Overlap: " << grid.
overlapSize(0,0) << std::endl;
116 stream <<
"KeepPhysicalOverlap: ";
118 stream << (i->keepOverlap ?
"1" :
"0") <<
" ";
120 stream <<
"Coarse Size: ";
121 for (
int i=0; i<dim; i++)
124 stream <<
"Meshsize: " ;
125 for (
int i=0; i<dim; i++)
126 stream << grid.
begin()->coords.meshsize(i,0) <<
" ";
134 std::ifstream file(filename);
139 std::cerr <<
"ERROR: BackupRestoreFacility::restore: couldn't open file `" << filename <<
"'" << std::endl;
150 stream >> input >> input >> input >> input;
153 DUNE_THROW(Dune::Exception,
"Your YaspGrid backup file is written in an outdated format!");
155 std::array<int,dim> torus_dims;
156 stream >> input >> input;
157 for (
int i=0; i<dim; i++)
158 stream >> torus_dims[i];
161 stream >> input >> input;
162 stream >> refinement;
164 std::bitset<dim> periodic;
167 for (
int i=0; i<dim; i++)
177 std::vector<bool> physicalOverlapSize;
178 physicalOverlapSize.resize(refinement);
180 for (
int i=0; i<refinement; ++i)
183 physicalOverlapSize[i] = b;
186 std::array<int,dim> coarseSize;
187 stream >> input >> input;
188 for (
int i=0; i<dim; i++)
189 stream >> coarseSize[i];
191 Dune::FieldVector<ctype,dim> h;
193 for (
int i=0; i<dim; i++)
196 Dune::FieldVector<ctype,dim> origin;
200 Dune::FieldVector<ctype,dim> length(h);
201 for (
int i=0; i<dim; i++)
202 length[i] *= coarseSize[i];
208 for (
int i=0; i<refinement; ++i)
219 template<
int dim,
class ctype>
227 static void backup (
const Grid &grid,
const std::string &filename )
229 std::ostringstream filename_str;
230 filename_str << filename << grid.
comm().rank();
231 std::ofstream file( filename_str.str() );
238 std::cerr <<
"ERROR: BackupRestoreFacility::backup: couldn't open file `" << filename_str.str() <<
"'" << std::endl;
242 static void backup (
const Grid &grid, std::ostream &stream )
245 stream <<
"Torus structure: ";
246 for (
int i=0; i<dim; i++)
248 stream << std::endl <<
"Refinement level: " << grid.
maxLevel() << std::endl;
249 stream <<
"Periodicity: ";
250 for (
int i=0; i<dim; i++)
252 stream << std::endl <<
"Overlap: " << grid.
overlapSize(0,0) << std::endl;
253 stream <<
"KeepPhysicalOverlap: ";
255 stream << (i->keepOverlap ?
"1" :
"0") <<
" ";
257 stream <<
"Coarse Size: ";
258 for (
int i=0; i<dim; i++)
262 grid.
begin()->coords.print(stream);
268 std::ostringstream filename_str;
269 filename_str << filename;
270 filename_str << comm.rank();
271 std::ifstream file(filename_str.str());
276 std::cerr <<
"ERROR: BackupRestoreFacility::restore: couldn't open file `" << filename_str.str() <<
"'" << std::endl;
287 stream >> input >> input >> input >> input;
290 DUNE_THROW(Dune::Exception,
"Your YaspGrid backup file is written in an outdated format!");
292 std::array<int,dim> torus_dims;
293 stream >> input >> input;
294 for (
int i=0; i<dim; i++)
295 stream >> torus_dims[i];
298 stream >> input >> input;
299 stream >> refinement;
301 std::bitset<dim> periodic;
304 for (
int i=0; i<dim; i++)
314 std::vector<bool> physicalOverlapSize;
315 physicalOverlapSize.resize(refinement);
317 for (
int i=0; i<refinement; ++i)
320 physicalOverlapSize[i] = b;
324 std::array<int,dim> coarseSize;
325 stream >> input >> input;
326 for (
int i=0; i<dim; i++)
327 stream >> coarseSize[i];
329 std::array<std::vector<ctype>,dim> coords;
330 stream >> input >> input >> input >> input;
331 for (
int d=0; d<dim; d++)
333 stream >> input >> input;
338 coords[d].resize(size);
339 for (
int i=0; i<size; i++)
347 Grid* grid =
new Grid(coords, periodic,
overlap, comm, coarseSize, &lb);
349 for (
int i=0; i<refinement; ++i)
Include standard header files.
Definition: agrid.hh:60
constexpr Overlap overlap
PartitionSet for the overlap partition.
Definition: partitionset.hh:278
facility for writing and reading grids
Definition: common/backuprestore.hh:43
static Grid * restore(const std::string &filename)
read a hierarchic grid from disk
Definition: common/backuprestore.hh:78
static void backup(const Grid &grid, const std::string &filename)
write a hierarchic grid to disk
Definition: common/backuprestore.hh:51
[ provides Dune::Grid ]
Definition: yaspgrid.hh:163
const Torus< Communication, dim > & torus() const
return reference to torus
Definition: yaspgrid.hh:244
typename Base::Communication Communication
Definition: yaspgrid.hh:178
void globalRefine(int refCount)
refine the grid refCount times.
Definition: yaspgrid.hh:1223
YGridLevelIterator end() const
return iterator pointing to one past the finest level
Definition: yaspgrid.hh:305
int maxLevel() const
Definition: yaspgrid.hh:1217
int overlapSize(int level, int codim) const
return size (= distance in graph) of overlap region
Definition: yaspgrid.hh:1406
bool isPeriodic(int i) const
return whether the grid is periodic in direction i
Definition: yaspgrid.hh:277
void refineOptions(bool keepPhysicalOverlap)
set options for refinement
Definition: yaspgrid.hh:1277
ReservedVector< YGridLevel, 32 >::const_iterator YGridLevelIterator
Iterator over the grid levels.
Definition: yaspgrid.hh:288
const Communication & comm() const
return a communication object
Definition: yaspgrid.hh:1764
Coordinates::ctype ctype
Type used for coordinates.
Definition: yaspgrid.hh:176
int levelSize(int l, int i) const
return size of the grid (in cells) on level l in direction i
Definition: yaspgrid.hh:262
YGridLevelIterator begin() const
return iterator pointing to coarsest level
Definition: yaspgrid.hh:291
Definition: yaspgrid/backuprestore.hh:27
static void writeOrigin(S &, const Coordinates &)
Definition: yaspgrid/backuprestore.hh:30
static void readOrigin(S &, Dune::FieldVector< typename Coordinates::ctype, Coordinates::dimension > &)
Definition: yaspgrid/backuprestore.hh:34
static Dune::YaspGrid< Coordinates::dimension, Coordinates > * createGrid(const Dune::FieldVector< typename Coordinates::ctype, Coordinates::dimension > &, A... args)
Definition: yaspgrid/backuprestore.hh:38
static void writeOrigin(S &s, const Coordinates &coord)
Definition: yaspgrid/backuprestore.hh:51
static Dune::YaspGrid< Coordinates::dimension, Coordinates > * createGrid(const Dune::FieldVector< typename Coordinates::ctype, Coordinates::dimension > &lowerleft, const Dune::FieldVector< typename Coordinates::ctype, Coordinates::dimension > &extension, A... args)
Definition: yaspgrid/backuprestore.hh:69
static void readOrigin(S &s, Dune::FieldVector< ctype, dim > &coord)
Definition: yaspgrid/backuprestore.hh:60
Dune::EquidistantOffsetCoordinates< ctype, dim > Coordinates
Definition: yaspgrid/backuprestore.hh:48
Dune::YaspGrid< dim, Coordinates > Grid
Definition: yaspgrid/backuprestore.hh:84
Grid::ctype ctype
Definition: yaspgrid/backuprestore.hh:85
static void backup(const Grid &grid, std::ostream &stream)
Definition: yaspgrid/backuprestore.hh:105
static Grid * restore(std::istream &stream, Comm comm=Comm())
Definition: yaspgrid/backuprestore.hh:145
static Grid * restore(const std::string &filename, Comm comm=Comm())
Definition: yaspgrid/backuprestore.hh:132
static void backup(const Grid &grid, const std::string &filename)
Definition: yaspgrid/backuprestore.hh:89
Grid::Traits::Communication Comm
Definition: yaspgrid/backuprestore.hh:86
static void backup(const Grid &grid, const std::string &filename)
Definition: yaspgrid/backuprestore.hh:227
YaspGrid< dim, TensorProductCoordinates< ctype, dim > > Grid
Definition: yaspgrid/backuprestore.hh:223
static Grid * restore(std::istream &stream, Comm comm=Comm())
Definition: yaspgrid/backuprestore.hh:282
static Grid * restore(const std::string &filename, Comm comm=Comm())
Definition: yaspgrid/backuprestore.hh:266
Grid::Traits::Communication Comm
Definition: yaspgrid/backuprestore.hh:224
static void backup(const Grid &grid, std::ostream &stream)
Definition: yaspgrid/backuprestore.hh:242
Container for equidistant coordinates in a YaspGrid with non-trivial origin.
Definition: coordinates.hh:131
ct origin(int d) const
Definition: coordinates.hh:185
Coordinate container for a tensor product YaspGrid.
Definition: coordinates.hh:245
Implement partitioner that gets a fixed partitioning from an array If the given partitioning doesn't ...
Definition: partitioning.hh:148
const iTupel & dims() const
return dimensions of torus
Definition: torus.hh:112
#define YASPGRID_BACKUPRESTORE_FORMAT_VERSION
Definition: yaspgrid/backuprestore.hh:20