1#ifndef DUNE_FEM_IOINTERFACE_HH 
    2#define DUNE_FEM_IOINTERFACE_HH 
   17#include <dune/grid/io/file/dgfparser/dgfparser.hh> 
   21#include <dune/fem/io/parameter.hh> 
   24#include <dune/fem/io/io.hh> 
   26#include <dune/fem/misc/capabilities.hh> 
   30#include <dune/grid/io/visual/grapedatadisplay.hh> 
   42    inline std::string generateFilename ( 
const std::string &fn,
 
   46      std::ostringstream name;
 
   47      name << fn << std::setw( precision ) << std::setfill( 
'0' ) << ntime;
 
   53    class TimeProviderBase;
 
  169      virtual void writeData ( 
double sequenceStamp ) 
const = 0;
 
  183        return defaultGridKey( dimension, Parameter::container(), check );
 
  186      static std::string 
defaultGridKey ( 
int dimension, 
const ParameterReader ¶meter, 
bool check = 
true )
 
  188        return defaultGridKey( 
"fem.io.macroGridFile", dimension, parameter, check );
 
  191      static std::string 
defaultGridKey ( std::string base, 
int dimension, 
bool check = 
true )
 
  193        return defaultGridKey( std::move( base ), dimension, Parameter::container(), check );
 
  197      static std::string 
defaultGridKey ( std::string base, 
int dimension, 
const ParameterReader ¶meter, 
bool check = 
true )
 
  199        const std::string oldGridKey( base );
 
  201        std::ostringstream gridKeyStream;
 
  202        gridKeyStream << oldGridKey << 
"_" << dimension << 
"d";
 
  203        const std::string newGridKey( gridKeyStream.str() );
 
  206        if( parameter.exists( oldGridKey ) )
 
  208          if( parameter.exists( newGridKey ) )
 
  210            std::cerr << 
"WARNING: ignoring `" << oldGridKey << 
"' because `" 
  211                      << newGridKey << 
"' was also found in parameter file." << std::endl;
 
  216            std::cerr << 
"WARNING: change `" << oldGridKey << 
"' to `"  << newGridKey
 
  217                      << 
"' in parameter file." << std::endl;
 
  223        if( check && !parameter.exists( newGridKey ) )
 
  225          std::cerr << 
"ERROR: Parameter `" << newGridKey << 
"' not found." << std::endl;
 
  226          DUNE_THROW( ParameterNotFound, 
"Parameter `" << newGridKey << 
"' not found." );
 
  234        if( !createDirectory( path ) )
 
  235          std::cerr << 
"Failed to create path `" << path << 
"'." << std::endl;
 
  241        std::string path(pathPref);
 
  246          std::stringstream rankDummy;
 
  248          path += rankDummy.str();
 
  261      template <
class CommunicatorType>
 
  263              const std::string& path)
 
  266        if( comm.rank() <= 0 )
 
  269          if( !createDirectory( path ) )
 
  270            std::cerr << 
"Failed to create path `" << path << 
"'." << std::endl;
 
  278      static std::string copyPathToFilename( 
const std::string& path )
 
  281        std::string filename( path );
 
  283        const char lastToken = filename.c_str()[ filename.size() - 1 ];
 
  284        const char* slash = 
"/";
 
  286        if( lastToken != slash[0] )
 
  293      template <
class CommunicatorType>
 
  294      static std::string 
createPath(
const CommunicatorType& comm,
 
  295              const std::string& pathPrefix,
 
  296              const std::string& dataPrefix,
 
  298              const bool alsoCreateRankPath = 
true )
 
  301        std::string filename( copyPathToFilename( pathPrefix ));
 
  303        filename += dataPrefix;
 
  304        std::string path = generateFilename( filename, step );
 
  310        if( alsoCreateRankPath )
 
  319          if( !createDirectory( path ) )
 
  320            std::cerr << 
"Failed to create path `" << path << 
"'." << std::endl;
 
  326      static std::string createRecoverPath(
 
  327              const std::string& pathPrefix,
 
  329              const std::string& dataPrefix,
 
  331              const bool alsoUseRankPath = 
true )
 
  334        std::string filename( copyPathToFilename( pathPrefix ));
 
  336        filename += dataPrefix;
 
  337        std::string path = generateFilename( filename, step );
 
  339        if( alsoUseRankPath )
 
IOInterface to write data to hard disk.
Definition: iointerface.hh:156
 
static void createGlobalPath(const CommunicatorType &comm, const std::string &path)
create global path for data output
Definition: iointerface.hh:262
 
static std::string defaultGridKey(int dimension, bool check=true)
return FEM key for macro grid reading
Definition: iointerface.hh:181
 
static void createPath(const std::string &path)
create given path in combination with rank
Definition: iointerface.hh:232
 
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
 
virtual ~IOInterface()
destructor
Definition: iointerface.hh:164
 
static std::string readPath()
Definition: iointerface.hh:255
 
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:197
 
static std::string createPathName(const std::string &pathPref, int rank)
create given path in combination with rank
Definition: iointerface.hh:239
 
IOInterface()
default constructor
Definition: iointerface.hh:160
 
static std::string commonOutputPath()
obtain common output path
Definition: parameter.hh:432
 
general base for time providers
Definition: timeprovider.hh:36
 
A few common exception classes.
 
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
 
Dune namespace.
Definition: alignedallocator.hh:13