1 #ifndef DUNE_FEM_INPUTOUTPUTTUPLES_HH 2 #define DUNE_FEM_INPUTOUTPUTTUPLES_HH 9 #include <dune/common/forloop.hh> 10 #include <dune/common/typetraits.hh> 11 #include <dune/common/tuples.hh> 14 #include <dune/grid/common/backuprestore.hh> 21 #include <dune/grid/common/backuprestore.hh> 40 static std::string
pathAndName(
const std::string&
path,
const std::string& name,
const std::string& suffix)
42 std::string comboname;
55 static std::string
gridName(
const std::string&
path,
const std::string& name)
61 static std::string
dataName(
const std::string&
path,
const std::string& name)
67 static std::string
rankName(
const std::string&
path,
const std::string& name,
68 const int rank,
const int size )
70 std::stringstream rankStr;
73 rankStr <<
"." << number ;
77 template <
class Gr
idType >
80 InStreamType& inStream,
81 const std::string& filename )
86 std::istream& stream = inStream.
stream();
88 grid = BackupRestoreFacility< GridType > :: restore( stream );
90 catch ( NotImplemented )
93 grid = BackupRestoreFacility< GridType > :: restore( filename );
97 DUNE_THROW(IOError,
"Unable to restore grid" );
100 template <
class Gr
idType>
103 InStreamType& inStream )
109 DofManagerType& dm = DofManagerType :: instance ( grid );
115 dm.resizeForRestrict();
119 template <
class Gr
idType >
122 OutStreamType& outStream,
123 const std::string& filename )
128 std::ostream& stream = outStream.
stream();
130 BackupRestoreFacility< GridType > :: backup( grid, stream );
132 catch ( NotImplemented )
135 BackupRestoreFacility< GridType > :: backup( grid, filename );
142 DofManagerType& dm = DofManagerType :: instance ( grid );
145 dm.write( outStream );
154 template<
class Tuple >
158 template<
int N >
struct CreateData;
159 template<
int N >
struct RestoreStream;
160 template<
int N >
struct OutputStream;
161 template<
int N >
struct AddToDisplay;
162 template<
int N >
struct AddToDisplayOrRemove;
163 template<
int N >
struct RemoveData;
166 static const int length = tuple_size< Tuple >::value;
171 template <
class Gr
idType >
172 static Tuple *
input ( GridType *&grid,
176 const std::string &
path,
177 const std::string &name )
180 const bool newGrid = (grid == 0);
184 std::string filename =
rankName( path, name, rank, size );
187 std::cout <<
"IOTuple: Reading data from " << filename << std::endl;
199 Tuple *ret =
new Tuple;
200 ForLoop< CreateData, 0, length-1 >::apply( *grid, *ret );
212 ForLoop< RestoreStream, 0, length-1 >::apply( inStream, *ret );
215 std::cout <<
" FINISHED!" << std::endl;
224 template<
class Gr
idType >
226 const GridType &grid,
227 const std::string &
path,
228 const std::string &name )
231 std::string filename =
232 rankName( path, name, grid.comm().rank(), grid.comm().size() );
238 ForLoop< RestoreStream, 0, length-1 >::apply( inStream, data );
242 template<
class Gr
idType >
243 static void output (
const GridType &grid,
245 const std::string &
path,
246 const std::string &name,
250 std::string filename =
251 rankName( path, name, grid.comm().rank(), grid.comm().size() );
263 ForLoop< OutputStream, 0, length-1 >::apply( outStream, tuple );
269 template<
class Disp,
class DINFO >
270 static void addToDisplay ( Disp &disp,
const DINFO *dinf,
double time, Tuple &tuple )
272 ForLoop< AddToDisplay, 0, length-1 >::apply( disp, dinf, time, tuple );
275 template<
class Disp,
class DINFO >
278 ForLoop< AddToDisplayOrRemove, 0, length-1 >::apply( disp, dinf, time, tuple );
281 template<
class Disp >
284 ForLoop< AddToDisplay, 0, length-1 >::apply( disp, tuple );
289 ForLoop< RemoveData, 0, length-1 >::apply( tuple );
294 template<
class Tuple >
296 struct IOTuple< Tuple >::CreateData
298 typedef typename TypeTraits< typename tuple_element< N, Tuple >::type >::PointeeType DiscreteFunction;
300 typedef typename DiscreteFunctionSpace::GridPartType GridPart;
302 template<
class Gr
id >
303 static void apply ( Grid &grid, Tuple &tuple )
305 GridPart *gridPart =
new GridPart( grid );
306 DiscreteFunctionSpace *space =
new DiscreteFunctionSpace( *gridPart );
307 std::get< N >( tuple ) =
new DiscreteFunction(
"", *space );
311 template<
class Tuple >
313 struct IOTuple< Tuple >::RestoreStream
315 typedef typename TypeTraits< typename tuple_element< N, Tuple >::type >::PointeeType DiscreteFunction;
317 template<
class StreamTraits >
320 DiscreteFunction *df = std::get< N >( tuple );
321 bool readDF = false ;
327 df->read( inStream );
329 DUNE_THROW(InvalidStateException,
"no discrete function on input");
334 template<
class Tuple >
336 struct IOTuple< Tuple >::OutputStream
338 typedef typename TypeTraits< typename tuple_element< N, Tuple >::type >::PointeeType DiscreteFunction;
341 template<
class StreamTraits >
344 const DiscreteFunction *df = std::get< N >( tuple );
345 const bool writeDF = ( df != 0 );
348 outStream << writeDF ;
353 df->write( outStream );
358 template<
class Tuple >
360 struct IOTuple< Tuple >::AddToDisplay
363 static const int pos = tuple_size< Tuple >::value - 1 - N;
365 typedef typename TypeTraits< typename tuple_element< pos, Tuple >::type >::PointeeType DiscreteFunction;
367 template<
class Disp,
class DINFO >
368 static void apply ( Disp &disp,
const DINFO *&dinf,
const double &time, Tuple &tuple )
370 DiscreteFunction *df = std::get< pos >( tuple );
373 assert( dinf->comp );
374 std::cout <<
"adding to display " << dinf->name << std::endl;
375 disp.addData( *df, dinf, time );
379 template<
class Disp >
380 static void apply ( Disp &disp, Tuple &tuple )
382 DiscreteFunction *df = std::get< pos >( tuple );
391 template<
class Tuple >
393 struct IOTuple< Tuple >::AddToDisplayOrRemove
395 template<
class Disp,
class DINFO >
396 static void apply ( Disp &disp,
const DINFO *&dinf,
const double &time, Tuple &tuple )
399 AddToDisplay< N >::apply( disp, dinf, time, tuple );
402 RemoveData< N >::apply( tuple );
407 template<
class Tuple >
409 struct IOTuple< Tuple >::RemoveData
412 static const int pos = tuple_size< Tuple >::value - 1 - N;
413 typedef typename TypeTraits< typename tuple_element< pos, Tuple >::type >::PointeeType DiscreteFunction;
415 typedef typename DiscreteFunctionSpace::GridPartType GridPart;
417 static void apply ( Tuple &tuple )
419 DiscreteFunction *&df = std::get< pos >( tuple );
422 const DiscreteFunctionSpace *space = &(df->space());
423 const GridPart *gridPart = &(space->gridPart());
442 typedef tuple<> Tuple;
445 static const int length = 0;
447 template <
class DataIO,
class Gr
idType>
448 static Tuple *
input ( DataIO &dataio, GridType *&grid,
double &t,
int n,
449 const std::string &
path,
const std::string &name )
455 template<
class Gr
idType >
457 const GridType &grid,
458 const std::string &
path,
459 const std::string &name )
465 template<
class Gr
idType >
466 static void output (
const GridType &grid,
468 const std::string &
path,
469 const std::string &name,
473 std::string filename =
474 rankName( path, name, grid.comm().rank(), grid.comm().size() );
486 template<
class Disp,
class DINFO >
487 static void addToDisplay ( Disp &disp,
const DINFO *dinf,
double time, Tuple &tuple )
490 template<
class Disp,
class DINFO >
494 template<
class Disp >
506 #endif // #ifndef DUNE_FEM_INPUTOUTPUTTUPLES_HH static void addToDisplay(Disp &disp, Tuple &tuple)
Definition: iotuple.hh:495
static void removeData(Tuple &tuple)
Definition: iotuple.hh:498
static void restoreData(Tuple &data, const GridType &grid, const std::string &path, const std::string &name)
restore all data in tupel
Definition: iotuple.hh:456
static void addToDisplayOrRemove(Disp &disp, const DINFO *dinf, double time, Tuple &tuple)
Definition: iotuple.hh:491
static void writeGrid(const GridType &grid, OutStreamType &outStream, const std::string &filename)
write grid and data to given directory
Definition: iotuple.hh:121
static std::string rankName(const std::string &path, const std::string &name, const int rank, const int size)
Definition: iotuple.hh:67
static Tuple * input(GridType *&grid, double &time, const int rank, const int size, const std::string &path, const std::string &name)
Definition: iotuple.hh:172
static void addToDisplay(Disp &disp, Tuple &tuple)
Definition: iotuple.hh:282
std::ostream & stream()
Definition: standardstreams.hh:85
PersistenceManager::RestoreStreamType InStreamType
Definition: iotuple.hh:36
Definition: datacollector.hh:45
static void output(const GridType &grid, const double time, const std::string &path, const std::string &name, const Tuple &tuple)
write grid and data to given directory
Definition: iotuple.hh:466
static StreamImpl * create(const std::string &filename, const int rank=MPIManager::rank(), const MPICommunicatorType &mpiComm=MPIHelper::getCommunicator())
return pointer to stream object created by new.
Definition: streams.hh:369
constructor
Definition: binarystreams.hh:15
static std::string gridName(const std::string &path, const std::string &name)
Definition: iotuple.hh:55
static void addToDisplayOrRemove(Disp &disp, const DINFO *dinf, double time, Tuple &tuple)
Definition: iotuple.hh:276
Definition: coordinate.hh:4
Definition: iotuple.hh:155
abstract interface for an input stream
Definition: streams.hh:177
static Tuple * input(DataIO &dataio, GridType *&grid, double &t, int n, const std::string &path, const std::string &name)
Definition: iotuple.hh:448
std::istream & stream()
Definition: standardstreams.hh:220
static const bool singleBackupRestoreFile
Definition: iotuple.hh:37
PersistenceManager::BackupStreamType OutStreamType
Definition: iotuple.hh:35
std::string path
Definition: readioparams.cc:155
static void removeData(Tuple &tuple)
Definition: iotuple.hh:287
Tuple ReturnType
Definition: iotuple.hh:169
static bool verbose()
obtain the cached value for fem.verbose
Definition: io/parameter.hh:444
static void restoreData(Tuple &data, const GridType &grid, const std::string &path, const std::string &name)
restore all data in tupel
Definition: iotuple.hh:225
static void output(const GridType &grid, const double time, const std::string &path, const std::string &name, const Tuple &tuple)
write grid and data to given directory
Definition: iotuple.hh:243
static const bool singleBackupRestoreFile
Definition: persistencemanager.hh:152
static void restoreDofManager(const GridType &grid, InStreamType &inStream)
Definition: iotuple.hh:102
Definition: iotuple.hh:32
constructor
Definition: binarystreams.hh:56
static std::string pathAndName(const std::string &path, const std::string &name, const std::string &suffix)
Definition: iotuple.hh:40
static void addToDisplay(Disp &disp, const DINFO *dinf, double time, Tuple &tuple)
Definition: iotuple.hh:270
static void addToDisplay(Disp &disp, const DINFO *dinf, double time, Tuple &tuple)
Definition: iotuple.hh:487
static std::string dataName(const std::string &path, const std::string &name)
Definition: iotuple.hh:61
static void restoreGrid(GridType *&grid, InStreamType &inStream, const std::string &filename)
Definition: iotuple.hh:79
abstract interface for an output stream
Definition: streams.hh:44