|
#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.
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. |
References counter_, fileType_, lastSavedTimeStep_, logarithmicSaveCountBase_, name_, openMode_, and saveCount_.
|
virtualdefault |
destructor
Destructor
void File::close | ( | ) |
Closes the file by calling fstream_.close()
References fstream_.
Referenced by DPMBase::closeFiles(), CGHandler::evaluateDataFiles(), CGHandler::evaluateRestartFiles(), DPMBase::readDataFile(), DPMBase::readRestartFile(), CSCInit::save(), ClosedCSCWalls::saveWalls(), CSCWalls::saveWalls(), DPMBase::writeDataFile(), DPMBase::writeEneFile(), DPMBase::writeFStatFile(), and DPMBase::writeRestartFile().
|
inline |
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.
References counter_.
Referenced by DPMBase::findNextExistingDataFile(), getFullName(), main(), openWrite(), DPMBase::readDataFile(), SaveCountUnitTest::SaveCountUnitTest(), DPMBase::writeEneTimeStep(), Drum::writeEneTimeStep(), Penetration::writeEneTimeStep(), Silo::writeEneTimeStep(), and DPMBase::writeOutputFiles().
FileType File::getFileType | ( | ) | const |
Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_.
References fileType_.
Referenced by commandLineCG(), 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.
References fstream_.
Referenced by BaseCG::BaseCG(), ClosedCSCRestart::ClosedCSCRestart(), ChuteWithPeriodicInflow::computeInternalForces(), DPMBase::constructor(), CSCRestart::CSCRestart(), DPMBase::findNextExistingDataFile(), DPMBase::readDataFile(), DPMBase::readNextDataFile(), DPMBase::readNextFStatFile(), DPMBase::readRestartFile(), CSCInit::save(), ClosedCSCWalls::saveWalls(), CSCWalls::saveWalls(), 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".
References getCounter().
Referenced by ClosedCSCStats::ClosedCSCStats(), CSCStats::CSCStats(), CGHandler::evaluateDataFiles(), CGHandler::evaluateRestartFiles(), main(), open(), DPMBase::readDataFile(), DPMBase::readRestartFile(), CGHandler::restart(), write(), and ChuteWithPeriodicInflow::writeXBallsScript().
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
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
References lastSavedTimeStep_.
Referenced by SaveCountUnitTest::SaveCountUnitTest().
const std::string & File::getName | ( | ) | const |
Allows to access the file name, e.g., "problem.data".
References name_.
Referenced by ParameterStudy1DDemo::actionsBeforeTimeLoop(), ParameterStudy2DDemo::actionsBeforeTimeLoop(), ParameterStudy3DDemo::actionsBeforeTimeLoop(), ClosedCSCRestart::ClosedCSCRestart(), commandLineCG(), CSCRestart::CSCRestart(), DPMBase::findNextExistingDataFile(), main(), DPMBase::read(), DPMBase::readDataFile(), Mercury3DRestart::readNextArgument(), CGHandler::restart(), FlowRule::run(), AngleOfRepose::run(), setName(), and CSCRun::setupInitialConditions().
std::fstream::openmode File::getOpenMode | ( | ) | const |
unsigned int File::getSaveCount | ( | ) | const |
Gets File::saveCount_.
References saveCount_.
Referenced by RotatingDrumWet::actionsAfterTimeStep(), NautaMixer::addSpeciesAndSetTimeStepAndSaveCount(), ClosedCSCRun::ClosedCSCRun(), InitialConditions< SpeciesType >::InitialConditions(), ChuteWithPeriodicInflow::integrateBeforeForceComputation(), main(), DPMBase::readNextArgument(), BaseWall::renderWall(), ClosedCSCStats::setupInitialConditions(), CSCStats::setupInitialConditions(), and SingleParticle< SpeciesType >::setupInitialConditions().
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
References counter_, fileType_, fstream_, getFullName(), MULTIPLE_FILES, MULTIPLE_FILES_PADDED, and openMode_.
Referenced by DPMBase::findNextExistingDataFile(), DPMBase::initialiseSolve(), open(), openWrite(), openWriteNoAppend(), DPMBase::readDataFile(), DPMBase::readNextDataFile(), DPMBase::readNextFStatFile(), DPMBase::readRestartFile(), CSCInit::save(), ClosedCSCWalls::saveWalls(), and CSCWalls::saveWalls().
bool File::open | ( | std::fstream::openmode | openMode | ) |
First calls setOpenMode(openMode), then calls open().
[in] | openMode |
References open(), and setOpenMode().
bool File::openWrite | ( | unsigned | nTimeSteps | ) |
First sets openmode to write (and append in some cases), then calls open().
[in] | openMode |
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 |
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 |
References counter_, fileType_, lastSavedTimeStep_, name_, NEVER, and saveCount_.
bool File::saveCurrentTimeStep | ( | unsigned int | ntimeSteps | ) |
determined if this time step has to be written; if so, opens the output file
[in] | ntimeSteps |
References getFileType(), NO_FILE, and saveCurrentTimeStepNoFileTypeCheck().
Referenced by CGHandler::evaluate(), and DPMBase::writeOutputFiles().
bool File::saveCurrentTimeStepNoFileTypeCheck | ( | unsigned int | ntimeSteps | ) |
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 |
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 |
References fileType_.
Referenced by ChuteRestartDemo::actionsOnRestart(), BaseCluster::actionsOnRestart(), AxisymmetricWallSelfTest::AxisymmetricWallSelfTest(), BoundariesSelfTest::BoundariesSelfTest(), ClosedCSCStats::ClosedCSCStats(), commandLineCG(), ChuteBottom::constructor(), DPMBase::constructor(), CSCStats::CSCStats(), FluxAndPeriodicBoundarySelfTest::FluxAndPeriodicBoundarySelfTest(), FluxBoundarySelfTest::FluxBoundarySelfTest(), ForceLawsMPI2Test::ForceLawsMPI2Test(), CLiveStatistics< T >::getLiveStatistics(), HorizontalMixer::HorizontalMixer(), InitialConditions< SpeciesType >::InitialConditions(), LeesEdwardsDemo::LeesEdwardsDemo(), LiquidMigrationMPI2Test::LiquidMigrationMPI2Test(), main(), ParticleParticleCollision::ParticleParticleCollision(), DPMBase::readDataFile(), DPMBase::readNextArgument(), DPMBase::readOld(), FlowRule::run(), statistics_while_running< T >::run(), AngleOfRepose::run(), DPMBase::setFileType(), Calibration::setOutput(), ChutePeriodic::setup(), RandomClusterInsertionBoundarySelfTest::setupInitialConditions(), MarbleRun::setupInitialConditions(), ShiftingConstantMassFlowMaserBoundarySelfTest::setupInitialConditions(), ShiftingMaserBoundarySelfTest::setupInitialConditions(), ChutePeriodic::setupInitialConditions(), Cstatic3D::setupInitialConditions(), GetDistanceAndNormalForIntersectionOfWalls::setupInitialConditions(), GetDistanceAndNormalForScrew::setupInitialConditions(), GetDistanceAndNormalForTriangleWall::setupInitialConditions(), Drum::setupInitialConditions(), Penetration::setupInitialConditions(), Silo::setupInitialConditions(), CubeDeletionBoundarySelfTest::setupInitialConditions(), DeletionBoundarySelfTest::setupInitialConditions(), LeesEdwardsSelfTest::setupInitialConditions(), ContactDetectionIntersectionOfWallsTest::setupInitialConditions(), GetDistanceAndNormalForTriangleWalls::setupInitialConditions(), RollingOverTriangleWalls::setupInitialConditions(), Packing::setupInitialConditions(), HertzianSinterForceUnitTest::setupInitialConditions(), MovingWalls::setupInitialConditions(), BaseCluster::setupInitialConditions(), SilbertHstop::SilbertHstop(), SilbertPeriodic::SilbertPeriodic(), statistics_while_running< T >::statistics_while_running(), TimeDependentPeriodicBoundary3DSelfTest::TimeDependentPeriodicBoundary3DSelfTest(), TimeDependentPeriodicBoundaryTest::TimeDependentPeriodicBoundaryTest(), TriangulatedScrewSelfTest::TriangulatedScrewSelfTest(), TriangulatedStepWallSelfTest::TriangulatedStepWallSelfTest(), TriangulatedWallSelfTest::TriangulatedWallSelfTest(), Tutorial11::Tutorial11(), and TwoByTwoMPIDomainMPI4Test::TwoByTwoMPIDomainMPI4Test().
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 |
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 |
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) |
References getName(), logger, units::name, and name_.
Referenced by commandLineCG(), Indenter::Indenter(), main(), DPMBase::read(), DPMBase::readDataFile(), DPMBase::readRestartFile(), CGHandler::restart(), AngleOfRepose::set_study(), SilbertPeriodic::set_study(), setCGHandler(), FlowRule::setName(), and DPMBase::setName().
void File::setOpenMode | ( | std::fstream::openmode | openMode | ) |
Allows the user to Sets File::openMode_.
[in] | openmode |
References openMode_.
Referenced by DPMBase::initialiseSolve(), open(), openWrite(), and DPMBase::setOpenMode().
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 |
References saveCount_.
Referenced by commandLineCG(), InitialConditions< SpeciesType >::InitialConditions(), main(), MultiParticlesInsertion::MultiParticlesInsertion(), DPMBase::readNextArgument(), DPMBase::readOld(), DPMBase::readParAndIniFiles(), setCGHandler(), DPMBase::setSaveCount(), DistributionToPSDSelfTest::setupInitialConditions(), InsertionBoundarySelfTest::setupInitialConditions(), MultiplePSDSelfTest::setupInitialConditions(), PolydisperseInsertionBoundarySelfTest::setupInitialConditions(), PSDManualInsertionSelfTest::setupInitialConditions(), PSDSelfTest::setupInitialConditions(), RandomClusterInsertionBoundarySelfTest::setupInitialConditions(), SingleParticle< SpeciesType >::SingleParticle(), TriangulatedScrewSelfTest::TriangulatedScrewSelfTest(), TriangulatedStepSelfTest::TriangulatedStepSelfTest(), and TriangulatedWallSelfTest::TriangulatedWallSelfTest().
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 |
References helpers::compare(), counter_, fileType_, getFullName(), lastSavedTimeStep_, name_, and saveCount_.
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 |
References NEVER, and saveCount_.
Referenced by ForceLawsMPI2Test::ForceLawsMPI2Test(), LiquidMigrationMPI2Test::LiquidMigrationMPI2Test(), MarbleRun::setupInitialConditions(), Drum::setupInitialConditions(), HertzSelfTest::setupInitialConditions(), MindlinSelfTest::setupInitialConditions(), Penetration::setupInitialConditions(), Silo::setupInitialConditions(), UnionOfWalls::setupInitialConditions(), and TwoByTwoMPIDomainMPI4Test::TwoByTwoMPIDomainMPI4Test().
|
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 |
|
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 |
|
private |
counts the number of already opened files, i.e. counter=1 means .0000 exists
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.
Referenced by File(), getFileType(), open(), read(), setFileType(), and write().
|
private |
Stream object used to read/write data files.
Referenced by close(), getFstream(), and open().
|
private |
the time step at which the next write or read operation has to happen.
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
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)
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}.
Referenced by File(), getSaveCount(), read(), saveCurrentTimeStepNoFileTypeCheck(), setSaveCount(), write(), and writeFirstAndLastTimeStep().