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 102 of file File.cc.

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

103 {
104  //sets the default for the number of time steps to be skipped
105  //in between each saved "snapshot" of the system to zero
106  //(i.e. records every time step by default)
107  saveCount_ = 0;
108 
109  // file name has to be set by the user
110  name_ = "out";
111 
112  // output into a single file by default
114 
115  // counter of currently open file set to 0 by default
116  counter_ = 0;
117 
118  //stores the time step of the last write/read operation; NEVER by default
120 
121  //sets the default openMode to "out"
122  //i.e. files will by default be written to, not read from.
123  openMode_ = std::fstream::out;
124 
125  //sets the default logarithmicSaveCount to zero
127 }
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 133 of file File.cc.

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

134 {
136  name_ = f.name_;
137  fileType_ = f.fileType_;
138  counter_ = f.counter_;
140  openMode_ = f.openMode_;
142 }
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 408 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().

409 {
410  fstream_.close();
411 }
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 224 of file File.cc.

References counter_.

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

225 {
226  return counter_;
227 }
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 208 of file File.cc.

References fileType_.

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

209 {
210  return fileType_;
211 }
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 154 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().

155 {
156  return fstream_;
157 }
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 171 of file File.cc.

References getCounter().

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

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

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

181 {
182  //get the full file name
183  std::stringstream lastName("");
184  lastName << name_;
186  {
187  lastName << "." << counter;
188  }
190  {
191  lastName << "." << to_string_padded(counter);
192  }
193  return lastName.str();
194 }
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:208
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 294 of file File.cc.

References lastSavedTimeStep_.

295 {
296  return lastSavedTimeStep_;
297 }
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 166 of file File.cc.

References name_.

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

167 {
168  return name_;
169 }
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 240 of file File.cc.

References openMode_.

241 {
242  return openMode_;
243 }
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 256 of file File.cc.

References saveCount_.

Referenced by DPMBase::readNextArgument().

257 {
258  return saveCount_;
259 }
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 348 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().

349 {
350  //close old file if multi-file output
352  {
353  fstream_.close();
354  }
355 
356  counter_++;
357 
358  if (!fstream_.is_open())
359  {
360  fstream_.open(getFullName().c_str(), openMode_);
361  if (!fstream_.is_open())
362  {
363  return false;
364  }
365  }
366 
367  return true;
368 }
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:171
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 373 of file File.cc.

References open(), and setOpenMode().

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

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

Parameters
[in]openMode

Definition at line 382 of file File.cc.

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

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

383 {
384  setLastSavedTimeStep(nTimeSteps);
385  if (getFileType() == FileType::ONE_FILE && getCounter() != 0)
386  {
387  setOpenMode(std::fstream::out | std::fstream::app);
388  }
389  else
390  {
391  setOpenMode(std::fstream::out);
392  }
393  return open();
394 }
FileType getFileType() const
Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_.
Definition: File.cc:208
void setLastSavedTimeStep(unsigned int lastSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:303
unsigned int getCounter() const
In case of multiple files, File::getCounter() returns the the number (FILE::Counter_) of the next fil...
Definition: File.cc:224
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:348
void setOpenMode(std::fstream::openmode openMode)
Allows the user to Sets File::openMode_.
Definition: File.cc:248
bool File::openWriteNoAppend ( unsigned  nTimeSteps)
Parameters
[in]openMode

Definition at line 399 of file File.cc.

References open(), and setLastSavedTimeStep().

Referenced by DPMBase::writeRestartFile().

400 {
401  setLastSavedTimeStep(nTimeSteps);
402  return open(std::fstream::out);
403 }
void setLastSavedTimeStep(unsigned int lastSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:303
bool open()
Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the ne...
Definition: File.cc:348
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 418 of file File.cc.

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

Referenced by operator>>().

419 {
420  std::string dummy;
421  is >> dummy;
422  if (!dummy.compare("name"))
423  is >> name_ >> dummy;
424  is >> fileType_;
425  is >> dummy >> saveCount_;
426  is >> dummy >> counter_;
427  if (counter_ != 0)
428  {
429  is >> dummy >> lastSavedTimeStep_;
430  }
431  else
432  {
434  }
435  //if (dummy != "lastSavedTimeStep") lastSavedTimeStep_=SAVE;
436 }
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 313 of file File.cc.

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

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

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

Definition at line 318 of file File.cc.

References lastSavedTimeStep_, logarithmicSaveCountBase_, NEVER, and saveCount_.

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

319 {
320  /* check:
321  * - if this time step should be written
322  * - if the file type is not NO_FILE
323  * - if file can be opened
324  * in that case, change lastSavedTimeStep and return true;
325  */
326  if ((lastSavedTimeStep_ == NEVER || ntimeSteps >= lastSavedTimeStep_ + saveCount_))
327  {
328  //note: do not do the following at t = 0 because this makes no sense for a logarithm
329  if (logarithmicSaveCountBase_ > 1 && ntimeSteps > 0 &&
331  {
332  /*calculate the new saveCount base on the user input logarithmicSaveCountBase,
333  *and multiply by the actual number of time steps
334  */
336  }
337  return true;
338  } else {
339  return false;
340  }
341 }
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 232 of file File.cc.

References counter_.

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

233 {
234  counter_ = counter;
235 }
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 216 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().

217 {
218  fileType_ = fileType;
219 }
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 303 of file File.cc.

References lastSavedTimeStep_.

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

304 {
305  lastSavedTimeStep_ = lastSavedTimeStep;
306 }
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 284 of file File.cc.

References logarithmicSaveCountBase_, and logger.

Referenced by DPMBase::setLogarithmicSaveCount().

285 {
286  logger.assert_always(logarithmicSaveCountBase > 1, "logarithmicSaveCountBase should always be larger than 1");
287  logarithmicSaveCountBase_ = logarithmicSaveCountBase;
288 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 199 of file File.cc.

References getName(), logger, and name_.

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

200 {
201  logger.assert_always(!getName().empty(), "Error: Name cannot be empty");
202  this->name_ = name;
203 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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:166
void File::setOpenMode ( std::fstream::openmode  openMode)

Allows the user to Sets File::openMode_.

Parameters
[in]openmode

Definition at line 248 of file File.cc.

References openMode_.

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

249 {
250  openMode_ = openMode;
251 }
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 274 of file File.cc.

References saveCount_.

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

275 {
276  saveCount_ = saveCount;
277 }
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 443 of file File.cc.

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

Referenced by operator<<().

444 {
445  //only write name if it differs from the default name
446  if (getFullName().compare(name_))
447  os << "name " << name_ << " ";
448  os << "fileType " << fileType_;
449  os << " saveCount " << saveCount_;
450  os << " counter " << counter_;
451  if (counter_ != 0)
452  {
453  os << " lastSavedTimeStep " << lastSavedTimeStep_;
454  }
456 }
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:171
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:860
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 265 of file File.cc.

References NEVER, and saveCount_.

266 {
267  saveCount_ = NEVER;
268 }
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 463 of file File.cc.

464 {
465  o.write(os);
466  return os;
467 }
void write(std::ostream &os) const
print function, which accepts an std::stringstream as input.
Definition: File.cc:443
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 474 of file File.cc.

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

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: