MercuryDPM
Beta
|
#include <File.h>
Public Member Functions | |
File () | |
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... | |
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... | |
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 | setSaveCount (unsigned int saveCount) |
Sets File::saveCount_. More... | |
unsigned int | getNextSavedTimeStep () const |
Gets File::nextSavedTimeStep_. More... | |
void | setNextSavedTimeStep (unsigned int nextSavedTimeStep) |
Sets File::nextSavedTimeStep_. More... | |
bool | saveCurrentTimestep (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 | open (std::fstream::openmode openMode) |
First calls setOpenMode(openMode), then open(). More... | |
bool | openNextFile () |
This function should be called before a data corresponding to the new time step is written or read. It is essential in case of multiple files, as it opens a new file for every increment in the File::counter_. More... | |
bool | openNextFile (std::fstream::openmode openMode) |
Similar to File::openNextFile(), but also lets the user set the mode of opening, see std::fstream::openmode More... | |
void | close () |
Closes the file by calling fstream_.close() 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 the next file to be opened; needed if multiple files are written/read 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 timesteps 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... | |
unsigned int | nextSavedTimeStep_ |
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 119 of file File.cc.
References counter_, fileType_, name_, nextSavedTimeStep_, ONE_FILE, openMode_, and saveCount_.
void File::close | ( | ) |
Closes the file by calling fstream_.close()
Definition at line 360 of file File.cc.
References fstream_.
Referenced by Files::closeFiles(), openNextFile(), DPMBase::readDataFile(), DPMBase::readRestartFile(), and DPMBase::writeOutputFiles().
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 216 of file File.cc.
References counter_.
Referenced by DPMBase::findNextExistingDataFile(), getFullName(), and DPMBase::writeOutputFiles().
FileType File::getFileType | ( | ) | const |
Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_.
Definition at line 202 of file File.cc.
References fileType_.
Referenced by DPMBase::findNextExistingDataFile(), getFullName(), openNextFile(), DPMBase::readDataFile(), saveCurrentTimestep(), and DPMBase::writeOutputFiles().
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 150 of file File.cc.
References fstream_.
Referenced by Files::Files(), DPMBase::findNextExistingDataFile(), DPMBase::readDataFile(), Mercury3DRestart::readNextArgument(), DPMBase::readNextDataFile(), DPMBase::readRestartFile(), DPMBase::writeOutputFiles(), and DPMBase::writeRestartFile().
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".
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 170 of file File.cc.
References getCounter(), getFileType(), MULTIPLE_FILES, MULTIPLE_FILES_PADDED, and name_.
Referenced by open(), and write().
const std::string & File::getName | ( | ) | const |
Allows to access the file name, e.g., "problem.data".
Definition at line 162 of file File.cc.
References name_.
Referenced by DPMBase::findNextExistingDataFile(), open(), DPMBase::readDataFile(), Mercury3DRestart::readNextArgument(), and DPMBase::readRestartFile().
unsigned int File::getNextSavedTimeStep | ( | ) | const |
Gets File::nextSavedTimeStep_.
Returns the time step at which the next write or read operation has to happen
Definition at line 290 of file File.cc.
References nextSavedTimeStep_.
std::fstream::openmode File::getOpenMode | ( | ) | const |
Allows the user to know the file mode i.e. gets File::openMode_.
Definition at line 260 of file File.cc.
References openMode_.
unsigned int File::getSaveCount | ( | ) | const |
Gets File::saveCount_.
Definition at line 274 of file File.cc.
References saveCount_.
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 318 of file File.cc.
References counter_, fileType_, fstream_, getFullName(), getName(), MULTIPLE_FILES, MULTIPLE_FILES_PADDED, nextSavedTimeStep_, openMode_, and saveCount_.
Referenced by open(), Files::openFiles(), openNextFile(), DPMBase::readDataFile(), DPMBase::readRestartFile(), and saveCurrentTimestep().
bool File::open | ( | std::fstream::openmode | openMode | ) |
First calls setOpenMode(openMode), then open().
[in] | openMode |
Definition at line 352 of file File.cc.
References open(), and setOpenMode().
bool File::openNextFile | ( | ) |
This function should be called before a data corresponding to the new time step is written or read. It is essential in case of multiple files, as it opens a new file for every increment in the File::counter_.
Definition at line 230 of file File.cc.
References close(), getFileType(), MULTIPLE_FILES, MULTIPLE_FILES_PADDED, and open().
Referenced by DPMBase::findNextExistingDataFile(), openNextFile(), and DPMBase::readNextDataFile().
bool File::openNextFile | ( | std::fstream::openmode | openMode | ) |
Similar to File::openNextFile(), but also lets the user set the mode of opening, see std::fstream::openmode
[in] | openmode |
Definition at line 252 of file File.cc.
References openNextFile(), and setOpenMode().
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 nextSavedTimeStep_
[in,out] | is |
Definition at line 370 of file File.cc.
References counter_, fileType_, name_, nextSavedTimeStep_, and saveCount_.
Referenced by operator>>().
bool File::saveCurrentTimestep | ( | unsigned int | ntimeSteps | ) |
[in] | ntimeSteps |
Definition at line 307 of file File.cc.
References getFileType(), nextSavedTimeStep_, NO_FILE, and open().
Referenced by 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 223 of file File.cc.
References counter_.
Referenced by Files::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 209 of file File.cc.
References fileType_.
Referenced by ChuteBottom::constructor(), DPMBase::readDataFile(), DPMBase::readNextArgument(), DPMBase::readOld(), and Files::setFileType().
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 195 of file File.cc.
References name_.
Referenced by DPMBase::readDataFile(), DPMBase::readRestartFile(), and Files::setName().
void File::setNextSavedTimeStep | ( | unsigned int | nextSavedTimeStep | ) |
Sets File::nextSavedTimeStep_.
Allows one to set the time step at which the next write or read operation has to happen
[in] | nextSavedTimeStep |
Definition at line 298 of file File.cc.
References nextSavedTimeStep_.
Referenced by Files::setNextSavedTimeStep().
void File::setOpenMode | ( | std::fstream::openmode | openMode | ) |
Allows the user to Sets File::openMode_.
[in] | openmode |
Definition at line 267 of file File.cc.
References openMode_.
Referenced by open(), openNextFile(), Files::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 282 of file File.cc.
References saveCount_.
Referenced by DPMBase::readNextArgument(), DPMBase::readOld(), DPMBase::readParAndIniFiles(), and Files::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 386 of file File.cc.
References counter_, fileType_, getFullName(), name_, nextSavedTimeStep_, and saveCount_.
Referenced by operator<<().
|
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 402 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 412 of file File.cc.
|
private |
counts the number of the next file to be opened; needed if multiple files are written/read
Definition at line 241 of file File.h.
Referenced by File(), getCounter(), 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 236 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 230 of file File.h.
Referenced by close(), getFstream(), and open().
|
private |
|
private |
the time step at which the next write or read operation has to happen.
Definition at line 257 of file File.h.
Referenced by File(), getNextSavedTimeStep(), open(), read(), saveCurrentTimestep(), setNextSavedTimeStep(), and write().
|
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 246 of file File.h.
Referenced by File(), getOpenMode(), open(), and setOpenMode().
|
private |
Allows one to define the number of timesteps 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 252 of file File.h.
Referenced by File(), getSaveCount(), open(), read(), setSaveCount(), and write().