1#ifndef DUNE_FEM_IOINTERFACE_HH
2#define DUNE_FEM_IOINTERFACE_HH
15#include <dune/common/exceptions.hh>
16#include <dune/grid/yaspgrid.hh>
17#include <dune/grid/io/file/dgfparser/dgfparser.hh>
30#include <dune/grid/io/visual/grapedatadisplay.hh>
33#include <dune/grid/yaspgrid.hh>
35#include <dune/grid/spgrid.hh>
51 std::ostringstream name;
52 name << fn << std::setw( precision ) << std::setfill(
'0' ) << ntime;
58 class TimeProviderBase;
174 virtual void writeData (
double sequenceStamp )
const = 0;
193 return defaultGridKey(
"fem.io.macroGridFile", dimension, parameter, check );
196 static std::string
defaultGridKey ( std::string base,
int dimension,
bool check =
true )
204 const std::string oldGridKey( base );
206 std::ostringstream gridKeyStream;
207 gridKeyStream << oldGridKey <<
"_" << dimension <<
"d";
208 const std::string newGridKey( gridKeyStream.str() );
211 if( parameter.
exists( oldGridKey ) )
213 if( parameter.
exists( newGridKey ) )
215 std::cerr <<
"WARNING: ignoring `" << oldGridKey <<
"' because `"
216 << newGridKey <<
"' was also found in parameter file." << std::endl;
221 std::cerr <<
"WARNING: change `" << oldGridKey <<
"' to `" << newGridKey
222 <<
"' in parameter file." << std::endl;
228 if( check && !parameter.
exists( newGridKey ) )
230 std::cerr <<
"ERROR: Parameter `" << newGridKey <<
"' not found." << std::endl;
240 std::cerr <<
"Failed to create path `" <<
path <<
"'." << std::endl;
246 std::string
path(pathPref);
251 std::stringstream rankDummy;
253 path += rankDummy.str();
266 template <
class CommunicatorType>
268 const std::string&
path)
271 if( comm.rank() <= 0 )
275 std::cerr <<
"Failed to create path `" <<
path <<
"'." << std::endl;
286 std::string filename(
path );
288 const char lastToken = filename.c_str()[ filename.size() - 1 ];
289 const char* slash =
"/";
291 if( lastToken != slash[0] )
298 template <
class CommunicatorType>
300 const std::string& pathPrefix,
301 const std::string& dataPrefix,
303 const bool alsoCreateRankPath =
true )
308 filename += dataPrefix;
315 if( alsoCreateRankPath )
325 std::cerr <<
"Failed to create path `" <<
path <<
"'." << std::endl;
332 const std::string& pathPrefix,
334 const std::string& dataPrefix,
336 const bool alsoUseRankPath =
true )
341 filename += dataPrefix;
344 if( alsoUseRankPath )
357 template <
class Gr
idImp>
360 const std::string& macroname,
361 const std::string&
path,
362 const std::string& prefix,
363 const bool writeSubFiles =
false )
369 std::ifstream gridin(macroname.c_str());
372 std::cerr <<
"Couldn't open file `" << macroname <<
"' ! \n";
377 dgf::IntervalBlock interval(gridin);
378 if(!interval.isactive())
380 std::cerr<<
"Did not find IntervalBlock in macro grid file `" << macroname <<
"' ! \n";
384 std::string filename(
path);
394 template <
class Gr
idImp>
396 const std::string& macroGrid,
397 const std::string& orgPath,
398 const std::string& destPath,
399 const std::string& prefix)
404 if( macroGrid !=
"" )
406 std::string destFilename(destPath);
408 destFilename += prefix;
409 destFilename +=
"_grid.macro";
411 std::ofstream file( destFilename.c_str() );
416 if( Parameter :: verbose () )
417 std::cerr <<
"Unable to open: '" << destFilename <<
"'." << std::endl;
426 std::stringstream tmp;
431 template <
class Gr
id>
435 typedef FieldVector<int, Grid::dimension>
iTupel;
439 DUNE_THROW(NotImplemented,
"SaveParallelCartesianGrid not implemented for choosen GridType");
443 template <
int dim,
class CoordCont >
457 enum { tag = Grid::tag };
458 YLoadBalance< dim > loadBalancer;
459 Torus< typename Grid::CollectiveCommunication, dim > torus( grid.comm(), tag, anz, &loadBalancer );
460 torus.partition( torus.rank(), origin, anz, originInterior, lengthInterior );
465 template<
class ct,
int dim,
template<
int >
class Strategy,
class Comm >
466 struct SaveParallelCartesianGrid< SPGrid< ct, dim, Strategy, Comm > >
470 typedef SPGrid< ct, dim, Strategy, Comm > Grid;
471 typedef FieldVector< int, dim >
iTupel;
478 typedef typename Grid::MultiIndex MultiIndex;
479 const MultiIndex begin = grid.gridLevel( 0 ).localCube().begin();
480 const MultiIndex end = grid.gridLevel( 0 ).localCube().end();
481 for(
int i = 0; i < dim; ++i )
483 originInterior[ i ] = begin[ i ];
484 lengthInterior[ i ] = end[ i ] - begin[ i ];
492 template <
class Gr
idImp>
495 dgf::IntervalBlock& intervalBlock,
496 std::string filename,
497 const bool writeSubFiles )
499 enum { dimension = GridImp :: dimension };
500 const int rank = grid.comm().rank();
502 FieldVector<double,dimension> lang;
503 FieldVector<int,dimension> anz;
504 FieldVector<double,dimension> h;
505 FieldVector<int,dimension> orig;
507 if( intervalBlock.numIntervals() != 1 )
509 std::cerr <<
"Warning: Only 1 interval block is handled by "
510 <<
"IOInterface::saveMacroGridImp" << std::endl;
513 typedef typename dgf::IntervalBlock::Interval Interval;
514 const Interval &interval = intervalBlock.get( 0 );
515 for(
int i = 0; i < dimension; ++i )
517 orig[ i ] = interval.p[ 0 ][ i ];
518 lang[ i ] = interval.p[ 1 ][ i ] - interval.p[ 0 ][ i ];
519 anz[ i ] = interval.n[ i ];
520 h[ i ] = lang[ i ] / anz[ i ];
525 std::string subfilename;
528 subfilename = filename;
535 typedef FieldVector<int,dimension> iTupel;
546 FieldVector<double,dimension> origin;
547 for(
int i=0; i<dimension; ++i)
548 origin[ i ] = o[ i ];
550 FieldVector<double,dimension> sublang(0.0);
551 for(
int i=0; i<dimension; ++i)
553 origin[i] = o_interior[i] * h[i];
554 sublang[i] = origin[i] + (s_interior[i] * h[i]);
563 FieldVector<double,dimension> zero(0.0);
573 filename +=
".global";
574 FieldVector<double,dimension> zero(0.0);
575 std::stringstream dummy;
580 template <
int dimension>
582 const FieldVector<double,dimension>& origin,
583 const FieldVector<double,dimension>& lang,
584 const FieldVector<int,dimension>& anz)
586 file <<
"DGF" << std::endl;
587 file <<
"Interval" << std::endl;
589 for(
int i=0;i<dimension; ++i)
591 file << origin[i] <<
" ";
595 for(
int i=0;i<dimension; ++i)
597 file << lang[i] <<
" ";
601 for(
int i=0;i<dimension; ++i)
603 file << anz[i] <<
" ";
606 file <<
"#" << std::endl;
608 file <<
"BoundaryDomain" << std::endl;
609 file <<
"default 1" << std::endl;
610 file <<
"#" << std::endl;
614 template <
int dimension>
617 const FieldVector<double,dimension>& origin,
618 const FieldVector<double,dimension>& lang,
619 const FieldVector<int,dimension>& anz)
625 std::ofstream file (filename.c_str());
632 std::cerr <<
"Couldn't open file `" << filename <<
"' !\n";
std::string path
Definition: readioparams.cc:156
Definition: bindguard.hh:11
bool createDirectory(const std::string &inName)
create a directory
Definition: io.cc:19
std::string generateFilename(const std::string &fn, int ntime, int precision=6)
Definition: iointerface.hh:47
IOInterface to write data to hard disk.
Definition: iointerface.hh:161
static void copyMacroGrid(const GridImp &g, const std::string ¯oGrid, const std::string &orgPath, const std::string &destPath, const std::string &prefix)
if grid is structured grid, write macro file
Definition: iointerface.hh:395
static std::string strRank(const int rank)
create string containing rank
Definition: iointerface.hh:424
static void createGlobalPath(const CommunicatorType &comm, const std::string &path)
create global path for data output
Definition: iointerface.hh:267
static std::string createRecoverPath(const std::string &pathPrefix, const int rank, const std::string &dataPrefix, const int step, const bool alsoUseRankPath=true)
Definition: iointerface.hh:331
static std::string createPath(const CommunicatorType &comm, const std::string &pathPrefix, const std::string &dataPrefix, const int step, const bool alsoCreateRankPath=true)
Definition: iointerface.hh:299
static std::string defaultGridKey(int dimension, const ParameterReader ¶meter, bool check=true)
Definition: iointerface.hh:191
static std::string defaultGridKey(int dimension, bool check=true)
return FEM key for macro grid reading
Definition: iointerface.hh:186
static void saveCartesianGrid(const GridImp &grid, std::ostream &out, dgf::IntervalBlock &intervalBlock, std::string filename, const bool writeSubFiles)
write my partition as macro grid
Definition: iointerface.hh:493
static void createPath(const std::string &path)
create given path in combination with rank
Definition: iointerface.hh:237
virtual void writeData(double sequenceStamp) const =0
write data with a given sequence stamp
virtual void write() const =0
write given data to disc, evaluates parameter savecount
static void writeToStream(std::ostream &file, const FieldVector< double, dimension > &origin, const FieldVector< double, dimension > &lang, const FieldVector< int, dimension > &anz)
Definition: iointerface.hh:581
virtual ~IOInterface()
destructor
Definition: iointerface.hh:169
static std::string readPath()
Definition: iointerface.hh:260
static std::string defaultGridKey(std::string base, int dimension, bool check=true)
Definition: iointerface.hh:196
virtual void write(const TimeProviderBase &tp) const =0
write given data to disc, evaluates parameter savecount and savestep
static std::string defaultGridKey(std::string base, int dimension, const ParameterReader ¶meter, bool check=true)
return FEM key for macro grid reading
Definition: iointerface.hh:202
static std::string copyPathToFilename(const std::string &path)
Definition: iointerface.hh:283
static void writeStructuredGrid(const std::string &filename, std::ostream &out, const FieldVector< double, dimension > &origin, const FieldVector< double, dimension > &lang, const FieldVector< int, dimension > &anz)
write structured grid as DGF file
Definition: iointerface.hh:615
static std::string createPathName(const std::string &pathPref, int rank)
create given path in combination with rank
Definition: iointerface.hh:244
static void writeMacroGrid(const GridImp &grid, std::ostream &out, const std::string ¯oname, const std::string &path, const std::string &prefix, const bool writeSubFiles=false)
if grid is structured grid, write macro file
Definition: iointerface.hh:358
IOInterface()
default constructor
Definition: iointerface.hh:165
Definition: iointerface.hh:433
FieldVector< int, Grid::dimension > iTupel
Definition: iointerface.hh:435
static void getCoordinates(const Grid &, const iTupel &, iTupel &, iTupel &, iTupel &)
Definition: iointerface.hh:437
static const bool saveMacroGrid
Definition: iointerface.hh:434
FieldVector< int, dim > iTupel
Definition: iointerface.hh:448
static void getCoordinates(const Grid &grid, const iTupel &anz, iTupel &origin, iTupel &originInterior, iTupel &lengthInterior)
Definition: iointerface.hh:450
YaspGrid< dim, CoordCont > Grid
Definition: iointerface.hh:447
static ParameterContainer & container()
Definition: io/parameter.hh:193
static std::string commonOutputPath()
obtain common output path
Definition: io/parameter.hh:411
Definition: io/parameter/exceptions.hh:17
bool exists(const std::string &key) const
check, whether a parameter is defined
Definition: reader.hh:44
Definition: griddeclaration.hh:36
general base for time providers
Definition: timeprovider.hh:36