MercuryDPM
Trunk
|
#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... | |
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.
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_.
File::File | ( | const File & | f | ) |
default copy constructor
Copy everything but the fstream object (which cannot be copied).
[in] | f | the file object that is to be copied. |
Definition at line 132 of file File.cc.
References counter_, fileType_, lastSavedTimeStep_, logarithmicSaveCountBase_, name_, openMode_, and saveCount_.
|
virtualdefault |
destructor
Destructor
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().
|
inline |
Definition at line 150 of file File.h.
References counter_.
Referenced by CGHandler::restart().
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.
Definition at line 223 of file File.cc.
References counter_.
Referenced by DPMBase::findNextExistingDataFile(), getFullName(), main(), openWrite(), DPMBase::readDataFile(), DPMBase::writeEneTimeStep(), and DPMBase::writeOutputFiles().
FileType File::getFileType | ( | ) | const |
Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. 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().
std::fstream & File::getFstream | ( | ) |
Allows to access the member variable File::fstream_.
Returns fstream (file stream) of any file for input and output tasks.
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().
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().
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
Definition at line 179 of file File.cc.
References getFileType(), MULTIPLE_FILES, MULTIPLE_FILES_PADDED, name_, and to_string_padded().
unsigned int File::getLastSavedTimeStep | ( | ) | const |
Gets File::nextSavedTimeStep_.
Returns the time step at which the next write or read operation has to happen
Definition at line 293 of file File.cc.
References lastSavedTimeStep_.
const std::string & File::getName | ( | ) | const |
Allows to access the file name, e.g., "problem.data".
Definition at line 165 of file File.cc.
References name_.
Referenced by DPMBase::findNextExistingDataFile(), DPMBase::read(), DPMBase::readDataFile(), Mercury3DRestart::readNextArgument(), CGHandler::restart(), and setName().
std::fstream::openmode File::getOpenMode | ( | ) | const |
Allows the user to know the file mode i.e. gets File::openMode_.
Definition at line 239 of file File.cc.
References openMode_.
unsigned int File::getSaveCount | ( | ) | const |
Gets File::saveCount_.
Definition at line 255 of file File.cc.
References saveCount_.
Referenced by DPMBase::readNextArgument().
|
inline |
Definition at line 148 of file File.h.
References counter_.
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
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().
bool File::open | ( | std::fstream::openmode | openMode | ) |
First calls setOpenMode(openMode), then calls open().
[in] | openMode |
Definition at line 372 of file File.cc.
References open(), and setOpenMode().
bool File::openWrite | ( | unsigned | nTimeSteps | ) |
First sets openmode to write (and append in some cases), then calls open().
[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().
bool File::openWriteNoAppend | ( | unsigned | nTimeSteps | ) |
[in] | openMode |
Definition at line 398 of file File.cc.
References open(), and setLastSavedTimeStep().
Referenced by DPMBase::writeRestartFile().
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_
[in,out] | is |
Definition at line 417 of file File.cc.
References counter_, fileType_, lastSavedTimeStep_, name_, NEVER, and saveCount_.
Referenced by operator>>().
bool File::saveCurrentTimeStep | ( | unsigned int | ntimeSteps | ) |
determined if this time step has to be written; if so, opens the output file
[in] | ntimeSteps |
Definition at line 312 of file File.cc.
References getFileType(), NO_FILE, and saveCurrentTimeStepNoFileTypeCheck().
Referenced by CGHandler::evaluate(), and DPMBase::writeOutputFiles().
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().
void File::setCounter | ( | unsigned int | counter | ) |
Allows the user to set the file counter according to his need. Sets File::counter_.
[in] | counter |
Definition at line 231 of file File.cc.
References counter_.
Referenced by CGHandler::evaluateDataFiles(), main(), DPMBase::readDataFile(), DPMBase::readRestartFile(), and DPMBase::resetFileCounter().
void File::setFileType | ( | FileType | fileType | ) |
Sets the type of file needed to write into or read from. File::fileType_.
[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().
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
[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().
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
[in] | logarithmicSaveCountBase |
Definition at line 283 of file File.cc.
References logarithmicSaveCountBase_, and logger.
Referenced by DPMBase::setLogarithmicSaveCount().
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)
[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().
void File::setOpenMode | ( | std::fstream::openmode | openMode | ) |
Allows the user to Sets File::openMode_.
[in] | openmode |
Definition at line 247 of file File.cc.
References openMode_.
Referenced by open(), openWrite(), DPMBase::setOpenMode(), and DPMBase::solve().
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.
[in] | saveCount |
Definition at line 273 of file File.cc.
References saveCount_.
Referenced by DPMBase::readNextArgument(), DPMBase::readOld(), DPMBase::readParAndIniFiles(), and DPMBase::setSaveCount().
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
[in,out] | os |
Definition at line 442 of file File.cc.
References helpers::compare(), counter_, fileType_, getFullName(), lastSavedTimeStep_, name_, and saveCount_.
Referenced by operator<<().
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.
[in] | saveCount |
Definition at line 264 of file File.cc.
References NEVER, and saveCount_.
|
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.
[in,out] | os | |
[in] | o |
Definition at line 462 of file File.cc.
|
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&.
[in,out] | is | |
[in] | o |
Definition at line 473 of file File.cc.
|
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().
|
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().
|
private |
Stream object used to read/write data files.
Definition at line 254 of file File.h.
Referenced by close(), getFstream(), and open().
|
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().
|
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().
|
private |
|
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().
|
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().