MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
File Class Reference

#include <File.h>

Public Member Functions

 File ()
 constructor More...
 
 File (const File &)
 default copy constructor More...
 
virtual ~File ()
 destructor More...
 
std::fstream & getFstream ()
 Allows to access the member variable File::fstream_. More...
 
const std::string & getName () const
 Allows to access the file name, e.g., "problem.data". More...
 
const std::string getFullName () const
 Also allows to access the file name, however with additional information which is the file counter, e.g., "problem.data.0000". More...
 
const std::string getFullName (unsigned) const
 Allows to access the file name, however with additional information which is the file counter, e.g., "problem.data.0000". More...
 
void setName (const std::string &name)
 Sets the file name, e.g. "Name.data". More...
 
FileType getFileType () const
 Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_. More...
 
void setFileType (FileType fileType)
 Sets the type of file needed to write into or read from. File::fileType_. More...
 
unsigned int getCounter () const
 In case of multiple files, File::getCounter() returns the the number (FILE::Counter_) of the next file i.e. to be opened for reading or writing; NOTE: needed only if FILE::fileType_ is multiple files. More...
 
void setCounter (unsigned int counter)
 Allows the user to set the file counter according to his need. Sets File::counter_. More...
 
void increaseCounter ()
 
void decreaseCounter ()
 
std::fstream::openmode getOpenMode () const
 Allows the user to know the file mode i.e. gets File::openMode_. More...
 
void setOpenMode (std::fstream::openmode openMode)
 Allows the user to Sets File::openMode_. More...
 
unsigned int getSaveCount () const
 Gets File::saveCount_. More...
 
void writeFirstAndLastTimeStep ()
 Sets File::saveCount_ to the highest possible value such that only the first and last time step is written. More...
 
void setSaveCount (unsigned int saveCount)
 Sets File::saveCount_. More...
 
unsigned int getLastSavedTimeStep () const
 Gets File::nextSavedTimeStep_. More...
 
void setLastSavedTimeStep (unsigned int lastSavedTimeStep)
 Sets File::nextSavedTimeStep_. More...
 
bool saveCurrentTimeStep (unsigned int ntimeSteps)
 determined if this time step has to be written; if so, opens the output file More...
 
bool saveCurrentTimeStepNoFileTypeCheck (unsigned int ntimeSteps)
 
void read (std::istream &is)
 read function, which accepts an input stream std::istream. More...
 
void write (std::ostream &os) const
 print function, which accepts an std::stringstream as input. More...
 
bool open ()
 Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the nextSavedTimeStep and the counter. the counter is useful when the fileType_ is set to Multiple or Multiple with padded. More...
 
bool openWrite (unsigned)
 First sets openmode to write (and append in some cases), then calls open(). More...
 
bool openWriteNoAppend (unsigned)
 
bool open (std::fstream::openmode openMode)
 First calls setOpenMode(openMode), then calls open(). More...
 
void close ()
 Closes the file by calling fstream_.close() More...
 
void setlogarithmicSaveCount (const Mdouble logarithmicSaveCountBase)
 the function to set the user input base of logarithmic saving count More...
 

Private Attributes

std::string name_
 name of the file. More...
 
std::fstream fstream_
 Stream object used to read/write data files. More...
 
FileType fileType_
 fileType_ indicates the type of the files. Whether it is No file, one file or multiple file as described in the description of the class. More...
 
unsigned int counter_
 counts the number of already opened files, i.e. counter=1 means .0000 exists More...
 
std::fstream::openmode openMode_
 A variable to indicate how the file should be opened i.e. in, out, ... see http://en.cppreference.com (std::fstream::out by default) More...
 
unsigned int saveCount_
 Allows one to define the number of time steps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}. More...
 
Mdouble logarithmicSaveCountBase_
 the switch allow user to set saveCount in logarithmic timescale with equal distance , the number is the base of log scale from user input More...
 
unsigned int lastSavedTimeStep_
 the time step at which the next write or read operation has to happen. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const File &o)
 Operator overloading used to write data obtained from an object of class File into an output stream. It also returns a reference to the output stream. More...
 
std::istream & operator>> (std::istream &is, File &o)
 Operator overloading used to read data from the input stream into member variables of an object of class File. It also returns a reference of type std::istream&. More...
 

Detailed Description

The instance of class File, for e.g. member variables of class Files (objects of type File) in Files.h, allows to manipulate the the input and output stream. In layman terms: In MercuryDPM, in order to read and write data into or from files we use the methods defined in Files.h. These methods implicitly calls the methods of class File and thereby allowing us to write or read data.

Definition at line 80 of file File.h.

Constructor & Destructor Documentation

File::File ( )

constructor

A File constructor which initialises FILE::saveCount_=0, sets the default filename as FILE::name_ = "", sets the default FileType to be as FileType::ONE_FILE and few other variables as listed below.

Definition at line 101 of file File.cc.

References counter_, fileType_, lastSavedTimeStep_, logarithmicSaveCountBase_, name_, NEVER, ONE_FILE, openMode_, and saveCount_.

102 {
103  //sets the default for the number of time steps to be skipped
104  //in between each saved "snapshot" of the system to zero
105  //(i.e. records every time step by default)
106  saveCount_ = 0;
107 
108  // file name has to be set by the user
109  name_ = "out";
110 
111  // output into a single file by default
113 
114  // counter of currently open file set to 0 by default
115  counter_ = 0;
116 
117  //stores the time step of the last write/read operation; NEVER by default
119 
120  //sets the default openMode to "out"
121  //i.e. files will by default be written to, not read from.
122  openMode_ = std::fstream::out;
123 
124  //sets the default logarithmicSaveCount to zero
126 }
FileType fileType_
fileType_ indicates the type of the files. Whether it is No file, one file or multiple file as descri...
Definition: File.h:260
unsigned int lastSavedTimeStep_
the time step at which the next write or read operation has to happen.
Definition: File.h:287
unsigned int counter_
counts the number of already opened files, i.e. counter=1 means .0000 exists
Definition: File.h:265
const unsigned NEVER
Definition: File.h:35
std::fstream::openmode openMode_
A variable to indicate how the file should be opened i.e. in, out, ... see http://en.cppreference.com (std::fstream::out by default)
Definition: File.h:270
all data will be written into/ read from a single file called name_
unsigned int saveCount_
Allows one to define the number of time steps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}.
Definition: File.h:276
Mdouble logarithmicSaveCountBase_
the switch allow user to set saveCount in logarithmic timescale with equal distance ...
Definition: File.h:282
std::string name_
name of the file.
Definition: File.h:249
File::File ( const File f)

default copy constructor

Copy everything but the fstream object (which cannot be copied).

Parameters
[in]fthe file object that is to be copied.

Definition at line 132 of file File.cc.

References counter_, fileType_, lastSavedTimeStep_, logarithmicSaveCountBase_, name_, openMode_, and saveCount_.

133 {
135  name_ = f.name_;
136  fileType_ = f.fileType_;
137  counter_ = f.counter_;
139  openMode_ = f.openMode_;
141 }
FileType fileType_
fileType_ indicates the type of the files. Whether it is No file, one file or multiple file as descri...
Definition: File.h:260
unsigned int lastSavedTimeStep_
the time step at which the next write or read operation has to happen.
Definition: File.h:287
unsigned int counter_
counts the number of already opened files, i.e. counter=1 means .0000 exists
Definition: File.h:265
std::fstream::openmode openMode_
A variable to indicate how the file should be opened i.e. in, out, ... see http://en.cppreference.com (std::fstream::out by default)
Definition: File.h:270
unsigned int saveCount_
Allows one to define the number of time steps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}.
Definition: File.h:276
Mdouble logarithmicSaveCountBase_
the switch allow user to set saveCount in logarithmic timescale with equal distance ...
Definition: File.h:282
std::string name_
name of the file.
Definition: File.h:249
File::~File ( )
virtualdefault

destructor

Destructor

Member Function Documentation

void File::close ( )

Closes the file by calling fstream_.close()

Definition at line 407 of file File.cc.

References fstream_.

Referenced by DPMBase::closeFiles(), CGHandler::evaluateDataFiles(), CGHandler::evaluateRestartFiles(), DPMBase::readDataFile(), DPMBase::readRestartFile(), DPMBase::writeDataFile(), DPMBase::writeEneFile(), DPMBase::writeFStatFile(), and DPMBase::writeRestartFile().

408 {
409  fstream_.close();
410 }
std::fstream fstream_
Stream object used to read/write data files.
Definition: File.h:254
void File::decreaseCounter ( )
inline

Definition at line 150 of file File.h.

References counter_.

Referenced by CGHandler::restart().

150 {counter_--;}
unsigned int counter_
counts the number of already opened files, i.e. counter=1 means .0000 exists
Definition: File.h:265
unsigned int File::getCounter ( ) const

In case of multiple files, File::getCounter() returns the the number (FILE::Counter_) of the next file i.e. to be opened for reading or writing; NOTE: needed only if FILE::fileType_ is multiple files.

Returns
unsigned int counter_

Definition at line 223 of file File.cc.

References counter_.

Referenced by DPMBase::findNextExistingDataFile(), getFullName(), main(), openWrite(), DPMBase::readDataFile(), DPMBase::writeEneTimeStep(), and DPMBase::writeOutputFiles().

224 {
225  return counter_;
226 }
unsigned int counter_
counts the number of already opened files, i.e. counter=1 means .0000 exists
Definition: File.h:265
FileType File::getFileType ( ) const

Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_.

Returns
Returns the FileType (File::fileType_)

Definition at line 207 of file File.cc.

References fileType_.

Referenced by BaseInteraction::BaseInteraction(), DPMBase::findNextExistingDataFile(), getFullName(), openWrite(), DPMBase::readDataFile(), saveCurrentTimeStep(), DPMBase::writeEneTimeStep(), DPMBase::writeOutputFiles(), and BaseInteraction::~BaseInteraction().

208 {
209  return fileType_;
210 }
FileType fileType_
fileType_ indicates the type of the files. Whether it is No file, one file or multiple file as descri...
Definition: File.h:260
std::fstream & File::getFstream ( )

Allows to access the member variable File::fstream_.

Returns fstream (file stream) of any file for input and output tasks.

Returns
std::fstream&

Definition at line 153 of file File.cc.

References fstream_.

Referenced by BaseCG::BaseCG(), BaseInteraction::BaseInteraction(), DPMBase::constructor(), DPMBase::findNextExistingDataFile(), DPMBase::readDataFile(), DPMBase::readNextDataFile(), DPMBase::readNextFStatFile(), DPMBase::readRestartFile(), DPMBase::writeDataFile(), DPMBase::writeEneFile(), DPMBase::writeFStatFile(), DPMBase::writeRestartFile(), and BaseInteraction::~BaseInteraction().

154 {
155  return fstream_;
156 }
std::fstream fstream_
Stream object used to read/write data files.
Definition: File.h:254
const std::string File::getFullName ( ) const

Also allows to access the file name, however with additional information which is the file counter, e.g., "problem.data.0000".

Definition at line 170 of file File.cc.

References getCounter().

Referenced by CGHandler::evaluateDataFiles(), CGHandler::evaluateRestartFiles(), main(), open(), DPMBase::readDataFile(), DPMBase::readRestartFile(), CGHandler::restart(), and write().

171 {
172  return getFullName(getCounter() - 1);
173 }
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter...
Definition: File.cc:170
unsigned int getCounter() const
In case of multiple files, File::getCounter() returns the the number (FILE::Counter_) of the next fil...
Definition: File.cc:223
const std::string File::getFullName ( unsigned  counter) const

Allows to access the file name, however with additional information which is the file counter, e.g., "problem.data.0000".

In case of FileType:fileType_== multiple files or multiple files padded, multiple files are generated and are named as problem.data.0, problem.data.1 or problem.data.0000, problem.data.0001

Returns
Returns a constant of type std::string

Definition at line 179 of file File.cc.

References getFileType(), MULTIPLE_FILES, MULTIPLE_FILES_PADDED, name_, and to_string_padded().

180 {
181  //get the full file name
182  std::stringstream lastName("");
183  lastName << name_;
185  {
186  lastName << "." << counter;
187  }
189  {
190  lastName << "." << to_string_padded(counter);
191  }
192  return lastName.str();
193 }
each time-step will be written into/read from separate files numbered consecutively, with numbers padded by zeros to a minimum of four digits: name_.0000, name_.0001, ..
FileType getFileType() const
Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_.
Definition: File.cc:207
std::string to_string_padded(unsigned int value)
Pads the number This function tries to pad the number to 4 digits, which is used when you create mult...
Definition: File.cc:44
std::string name_
name of the file.
Definition: File.h:249
each time-step will be written into/read from separate files numbered consecutively: name_...
unsigned int File::getLastSavedTimeStep ( ) const

Gets File::nextSavedTimeStep_.

Returns the time step at which the next write or read operation has to happen

Returns
unsigned int nextSaveTimeStep_

Definition at line 293 of file File.cc.

References lastSavedTimeStep_.

294 {
295  return lastSavedTimeStep_;
296 }
unsigned int lastSavedTimeStep_
the time step at which the next write or read operation has to happen.
Definition: File.h:287
const std::string & File::getName ( ) const

Allows to access the file name, e.g., "problem.data".

Returns
Returns a constant reference of type const std::string&

Definition at line 165 of file File.cc.

References name_.

Referenced by DPMBase::findNextExistingDataFile(), DPMBase::read(), DPMBase::readDataFile(), Mercury3DRestart::readNextArgument(), CGHandler::restart(), and setName().

166 {
167  return name_;
168 }
std::string name_
name of the file.
Definition: File.h:249
std::fstream::openmode File::getOpenMode ( ) const

Allows the user to know the file mode i.e. gets File::openMode_.

Returns
std::fstream::openmode

Definition at line 239 of file File.cc.

References openMode_.

240 {
241  return openMode_;
242 }
std::fstream::openmode openMode_
A variable to indicate how the file should be opened i.e. in, out, ... see http://en.cppreference.com (std::fstream::out by default)
Definition: File.h:270
unsigned int File::getSaveCount ( ) const

Gets File::saveCount_.

Returns
unsigned int saveCount_

Definition at line 255 of file File.cc.

References saveCount_.

Referenced by DPMBase::readNextArgument().

256 {
257  return saveCount_;
258 }
unsigned int saveCount_
Allows one to define the number of time steps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}.
Definition: File.h:276
void File::increaseCounter ( )
inline

Definition at line 148 of file File.h.

References counter_.

148 {counter_++;}
unsigned int counter_
counts the number of already opened files, i.e. counter=1 means .0000 exists
Definition: File.h:265
bool File::open ( )

Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the nextSavedTimeStep and the counter. the counter is useful when the fileType_ is set to Multiple or Multiple with padded.

Returns a bool to check if the file is open or closed. It also increments the nextSavedTimeStep with the saveCount

Returns
bool (True or False)
Bug:
Deepak checked by using fstream_.fail() instead of !fstrea_.is_open(), however this breaks selftests, Thomas will look at this

Definition at line 347 of file File.cc.

References counter_, fileType_, fstream_, getFullName(), MULTIPLE_FILES, MULTIPLE_FILES_PADDED, and openMode_.

Referenced by DPMBase::findNextExistingDataFile(), open(), openWrite(), openWriteNoAppend(), DPMBase::readDataFile(), DPMBase::readNextDataFile(), DPMBase::readNextFStatFile(), DPMBase::readRestartFile(), and DPMBase::solve().

348 {
349  //close old file if multi-file output
351  {
352  fstream_.close();
353  }
354 
355  counter_++;
356 
357  if (!fstream_.is_open())
358  {
359  fstream_.open(getFullName().c_str(), openMode_);
360  if (!fstream_.is_open())
361  {
362  return false;
363  }
364  }
365 
366  return true;
367 }
FileType fileType_
fileType_ indicates the type of the files. Whether it is No file, one file or multiple file as descri...
Definition: File.h:260
each time-step will be written into/read from separate files numbered consecutively, with numbers padded by zeros to a minimum of four digits: name_.0000, name_.0001, ..
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter...
Definition: File.cc:170
unsigned int counter_
counts the number of already opened files, i.e. counter=1 means .0000 exists
Definition: File.h:265
std::fstream::openmode openMode_
A variable to indicate how the file should be opened i.e. in, out, ... see http://en.cppreference.com (std::fstream::out by default)
Definition: File.h:270
each time-step will be written into/read from separate files numbered consecutively: name_...
std::fstream fstream_
Stream object used to read/write data files.
Definition: File.h:254
bool File::open ( std::fstream::openmode  openMode)

First calls setOpenMode(openMode), then calls open().

Parameters
[in]openMode

Definition at line 372 of file File.cc.

References open(), and setOpenMode().

373 {
374  setOpenMode(openMode);
375  return open();
376 }
bool open()
Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the ne...
Definition: File.cc:347
void setOpenMode(std::fstream::openmode openMode)
Allows the user to Sets File::openMode_.
Definition: File.cc:247
bool File::openWrite ( unsigned  nTimeSteps)

First sets openmode to write (and append in some cases), then calls open().

Parameters
[in]openMode

Definition at line 381 of file File.cc.

References getCounter(), getFileType(), ONE_FILE, open(), setLastSavedTimeStep(), and setOpenMode().

Referenced by DPMBase::writeDataFile(), DPMBase::writeEneFile(), and DPMBase::writeFStatFile().

382 {
383  setLastSavedTimeStep(nTimeSteps);
384  if (getFileType() == FileType::ONE_FILE && getCounter() != 0)
385  {
386  setOpenMode(std::fstream::out | std::fstream::app);
387  }
388  else
389  {
390  setOpenMode(std::fstream::out);
391  }
392  return open();
393 }
FileType getFileType() const
Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_.
Definition: File.cc:207
void setLastSavedTimeStep(unsigned int lastSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:302
unsigned int getCounter() const
In case of multiple files, File::getCounter() returns the the number (FILE::Counter_) of the next fil...
Definition: File.cc:223
all data will be written into/ read from a single file called name_
bool open()
Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the ne...
Definition: File.cc:347
void setOpenMode(std::fstream::openmode openMode)
Allows the user to Sets File::openMode_.
Definition: File.cc:247
bool File::openWriteNoAppend ( unsigned  nTimeSteps)
Parameters
[in]openMode

Definition at line 398 of file File.cc.

References open(), and setLastSavedTimeStep().

Referenced by DPMBase::writeRestartFile().

399 {
400  setLastSavedTimeStep(nTimeSteps);
401  return open(std::fstream::out);
402 }
void setLastSavedTimeStep(unsigned int lastSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:302
bool open()
Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the ne...
Definition: File.cc:347
void File::read ( std::istream &  is)

read function, which accepts an input stream std::istream.

Read function, which accepts an input stream object as input and assigns the member variables i.e. name_, fileType_, saveCount_, counter_ and lastSavedTimeStep_

Parameters
[in,out]is

Definition at line 417 of file File.cc.

References counter_, fileType_, lastSavedTimeStep_, name_, NEVER, and saveCount_.

Referenced by operator>>().

418 {
419  std::string dummy;
420  is >> dummy;
421  if (!dummy.compare("name"))
422  is >> name_ >> dummy;
423  is >> fileType_;
424  is >> dummy >> saveCount_;
425  is >> dummy >> counter_;
426  if (counter_ != 0)
427  {
428  is >> dummy >> lastSavedTimeStep_;
429  }
430  else
431  {
433  }
434  //if (dummy != "lastSavedTimeStep") lastSavedTimeStep_=SAVE;
435 }
FileType fileType_
fileType_ indicates the type of the files. Whether it is No file, one file or multiple file as descri...
Definition: File.h:260
unsigned int lastSavedTimeStep_
the time step at which the next write or read operation has to happen.
Definition: File.h:287
unsigned int counter_
counts the number of already opened files, i.e. counter=1 means .0000 exists
Definition: File.h:265
const unsigned NEVER
Definition: File.h:35
unsigned int saveCount_
Allows one to define the number of time steps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}.
Definition: File.h:276
std::string name_
name of the file.
Definition: File.h:249
bool File::saveCurrentTimeStep ( unsigned int  ntimeSteps)

determined if this time step has to be written; if so, opens the output file

Parameters
[in]ntimeSteps
Returns
True or False (a bool)

Definition at line 312 of file File.cc.

References getFileType(), NO_FILE, and saveCurrentTimeStepNoFileTypeCheck().

Referenced by CGHandler::evaluate(), and DPMBase::writeOutputFiles().

312  {
314 }
FileType getFileType() const
Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_.
Definition: File.cc:207
file will not be created/read
bool saveCurrentTimeStepNoFileTypeCheck(unsigned int ntimeSteps)
Definition: File.cc:317
bool File::saveCurrentTimeStepNoFileTypeCheck ( unsigned int  ntimeSteps)

Definition at line 317 of file File.cc.

References lastSavedTimeStep_, logarithmicSaveCountBase_, NEVER, and saveCount_.

Referenced by saveCurrentTimeStep(), and DPMBase::writeOutputFiles().

318 {
319  /* check:
320  * - if this time step should be written
321  * - if the file type is not NO_FILE
322  * - if file can be opened
323  * in that case, change lastSavedTimeStep and return true;
324  */
325  if ((lastSavedTimeStep_ == NEVER || ntimeSteps >= lastSavedTimeStep_ + saveCount_))
326  {
327  //note: do not do the following at t = 0 because this makes no sense for a logarithm
328  if (logarithmicSaveCountBase_ > 1 && ntimeSteps > 0 &&
330  {
331  /*calculate the new saveCount base on the user input logarithmicSaveCountBase,
332  *and multiply by the actual number of time steps
333  */
335  }
336  return true;
337  } else {
338  return false;
339  }
340 }
unsigned int lastSavedTimeStep_
the time step at which the next write or read operation has to happen.
Definition: File.h:287
const unsigned NEVER
Definition: File.h:35
unsigned int saveCount_
Allows one to define the number of time steps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}.
Definition: File.h:276
Mdouble logarithmicSaveCountBase_
the switch allow user to set saveCount in logarithmic timescale with equal distance ...
Definition: File.h:282
void File::setCounter ( unsigned int  counter)

Allows the user to set the file counter according to his need. Sets File::counter_.

Parameters
[in]counter

Definition at line 231 of file File.cc.

References counter_.

Referenced by CGHandler::evaluateDataFiles(), main(), DPMBase::readDataFile(), DPMBase::readRestartFile(), and DPMBase::resetFileCounter().

232 {
233  counter_ = counter;
234 }
unsigned int counter_
counts the number of already opened files, i.e. counter=1 means .0000 exists
Definition: File.h:265
void File::setFileType ( FileType  fileType)

Sets the type of file needed to write into or read from. File::fileType_.

Parameters
[in]fileType

Definition at line 215 of file File.cc.

References fileType_.

Referenced by BaseCluster::actionsOnRestart(), DPMBase::constructor(), ChuteBottom::constructor(), DPMBase::readDataFile(), DPMBase::readNextArgument(), DPMBase::readOld(), DPMBase::setFileType(), and BaseCluster::setupInitialConditions().

216 {
217  fileType_ = fileType;
218 }
FileType fileType_
fileType_ indicates the type of the files. Whether it is No file, one file or multiple file as descri...
Definition: File.h:260
void File::setLastSavedTimeStep ( unsigned int  lastSavedTimeStep)

Sets File::nextSavedTimeStep_.

Allows one to set the time step at which the next write or read operation has to happen

Parameters
[in]lastSavedTimeStep

Definition at line 302 of file File.cc.

References lastSavedTimeStep_.

Referenced by BaseCG::BaseCG(), CGHandler::evaluate(), CGHandler::finish(), openWrite(), openWriteNoAppend(), DPMBase::setLastSavedTimeStep(), and DPMBase::writeOutputFiles().

303 {
304  lastSavedTimeStep_ = lastSavedTimeStep;
305 }
unsigned int lastSavedTimeStep_
the time step at which the next write or read operation has to happen.
Definition: File.h:287
void File::setlogarithmicSaveCount ( const Mdouble  logarithmicSaveCountBase)

the function to set the user input base of logarithmic saving count

File::setlogarithmicSaveCount assigns the base of the saveCount on a logarithmic time scale

Parameters
[in]logarithmicSaveCountBase

Definition at line 283 of file File.cc.

References logarithmicSaveCountBase_, and logger.

Referenced by DPMBase::setLogarithmicSaveCount().

284 {
285  logger.assert_always(logarithmicSaveCountBase > 1, "logarithmicSaveCountBase should always be larger than 1");
286  logarithmicSaveCountBase_ = logarithmicSaveCountBase;
287 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
Mdouble logarithmicSaveCountBase_
the switch allow user to set saveCount in logarithmic timescale with equal distance ...
Definition: File.h:282
void File::setName ( const std::string &  name)

Sets the file name, e.g. "Name.data".

Note the file name is usually set by MD::setName(), which sets names for all file types (data, restart, fstat, stat, ene)

Parameters
[in]name(Takes in the to be name of the File)

Definition at line 198 of file File.cc.

References getName(), logger, and name_.

Referenced by DPMBase::read(), DPMBase::readDataFile(), DPMBase::readRestartFile(), CGHandler::restart(), and DPMBase::setName().

199 {
200  logger.assert_always(!getName().empty(), "Error: Name cannot be empty");
201  this->name_ = name;
202 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
std::string name_
name of the file.
Definition: File.h:249
const std::string & getName() const
Allows to access the file name, e.g., "problem.data".
Definition: File.cc:165
void File::setOpenMode ( std::fstream::openmode  openMode)

Allows the user to Sets File::openMode_.

Parameters
[in]openmode

Definition at line 247 of file File.cc.

References openMode_.

Referenced by open(), openWrite(), DPMBase::setOpenMode(), and DPMBase::solve().

248 {
249  openMode_ = openMode;
250 }
std::fstream::openmode openMode_
A variable to indicate how the file should be opened i.e. in, out, ... see http://en.cppreference.com (std::fstream::out by default)
Definition: File.h:270
void File::setSaveCount ( unsigned int  saveCount)

Sets File::saveCount_.

File::setSaveCount assigns the number of time steps to be skipped before the data is written to an existing file or a new file.

Parameters
[in]saveCount

Definition at line 273 of file File.cc.

References saveCount_.

Referenced by DPMBase::readNextArgument(), DPMBase::readOld(), DPMBase::readParAndIniFiles(), and DPMBase::setSaveCount().

274 {
275  saveCount_ = saveCount;
276 }
unsigned int saveCount_
Allows one to define the number of time steps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}.
Definition: File.h:276
void File::write ( std::ostream &  os) const

print function, which accepts an std::stringstream as input.

BaseParticle print function, which accepts an output stream object as input and writes the info to the std::ostream

Parameters
[in,out]os
Todo:
TW: openMode_ is not saved, maybe it should not even be stored but set every time you open a file

Definition at line 442 of file File.cc.

References helpers::compare(), counter_, fileType_, getFullName(), lastSavedTimeStep_, name_, and saveCount_.

Referenced by operator<<().

443 {
444  //only write name if it differs from the default name
445  if (getFullName().compare(name_))
446  os << "name " << name_ << " ";
447  os << "fileType " << fileType_;
448  os << " saveCount " << saveCount_;
449  os << " counter " << counter_;
450  if (counter_ != 0)
451  {
452  os << " lastSavedTimeStep " << lastSavedTimeStep_;
453  }
455 }
FileType fileType_
fileType_ indicates the type of the files. Whether it is No file, one file or multiple file as descri...
Definition: File.h:260
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter...
Definition: File.cc:170
unsigned int lastSavedTimeStep_
the time step at which the next write or read operation has to happen.
Definition: File.h:287
unsigned int counter_
counts the number of already opened files, i.e. counter=1 means .0000 exists
Definition: File.h:265
unsigned int saveCount_
Allows one to define the number of time steps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}.
Definition: File.h:276
bool compare(std::istream &is, std::string s)
Checks if the next argument in the input stream is a certain string.
Definition: Helpers.cc:858
std::string name_
name of the file.
Definition: File.h:249
void File::writeFirstAndLastTimeStep ( )

Sets File::saveCount_ to the highest possible value such that only the first and last time step is written.

File::setSaveCount assigns the number of time steps to be skipped before the data is written to an existing file or a new file.

Parameters
[in]saveCount

Definition at line 264 of file File.cc.

References NEVER, and saveCount_.

265 {
266  saveCount_ = NEVER;
267 }
const unsigned NEVER
Definition: File.h:35
unsigned int saveCount_
Allows one to define the number of time steps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}.
Definition: File.h:276

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const File o 
)
friend

Operator overloading used to write data obtained from an object of class File into an output stream. It also returns a reference to the output stream.

Parameters
[in,out]os
[in]o
Returns
std::ostream& os

Definition at line 462 of file File.cc.

463 {
464  o.write(os);
465  return os;
466 }
void write(std::ostream &os) const
print function, which accepts an std::stringstream as input.
Definition: File.cc:442
std::istream& operator>> ( std::istream &  is,
File o 
)
friend

Operator overloading used to read data from the input stream into member variables of an object of class File. It also returns a reference of type std::istream&.

Parameters
[in,out]is
[in]o
Returns
std::istream&

Definition at line 473 of file File.cc.

474 {
475  o.read(is);
476  return (is);
477 }
void read(std::istream &is)
read function, which accepts an input stream std::istream.
Definition: File.cc:417

Member Data Documentation

unsigned int File::counter_
private

counts the number of already opened files, i.e. counter=1 means .0000 exists

Definition at line 265 of file File.h.

Referenced by decreaseCounter(), File(), getCounter(), increaseCounter(), open(), read(), setCounter(), and write().

FileType File::fileType_
private

fileType_ indicates the type of the files. Whether it is No file, one file or multiple file as described in the description of the class.

Definition at line 260 of file File.h.

Referenced by File(), getFileType(), open(), read(), setFileType(), and write().

std::fstream File::fstream_
private

Stream object used to read/write data files.

Definition at line 254 of file File.h.

Referenced by close(), getFstream(), and open().

unsigned int File::lastSavedTimeStep_
private

the time step at which the next write or read operation has to happen.

Definition at line 287 of file File.h.

Referenced by File(), getLastSavedTimeStep(), read(), saveCurrentTimeStepNoFileTypeCheck(), setLastSavedTimeStep(), and write().

Mdouble File::logarithmicSaveCountBase_
private

the switch allow user to set saveCount in logarithmic timescale with equal distance , the number is the base of log scale from user input

Definition at line 282 of file File.h.

Referenced by File(), saveCurrentTimeStepNoFileTypeCheck(), and setlogarithmicSaveCount().

std::string File::name_
private

name of the file.

Definition at line 249 of file File.h.

Referenced by File(), getFullName(), getName(), read(), setName(), and write().

std::fstream::openmode File::openMode_
private

A variable to indicate how the file should be opened i.e. in, out, ... see http://en.cppreference.com (std::fstream::out by default)

Definition at line 270 of file File.h.

Referenced by File(), getOpenMode(), open(), and setOpenMode().

unsigned int File::saveCount_
private

Allows one to define the number of time steps to be skipped to make a snap shot. E.g. TMax = 100, saveCount_ = 10, timeStep = 1; It stores data at t={0,10,20,30,40...100}. And if TMax =101, it stores data at t={0,10,20,30,...100,101}.

Definition at line 276 of file File.h.

Referenced by File(), getSaveCount(), read(), saveCurrentTimeStepNoFileTypeCheck(), setSaveCount(), write(), and writeFirstAndLastTimeStep().


The documentation for this class was generated from the following files: