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

Every simulation requires data files to store all the information necessary for visualisation and analysis. The class File provides an fstream variable for reading/writing i.e. input and output. More...

#include <Files.h>

+ Inheritance diagram for Files:

Public Member Functions

 Files ()
 A constructor. More...
 
virtual ~Files ()
 A destructor, watch out its a virtual destructor. More...
 
 Files (const Files &other)
 Copy constructor. More...
 
MERCURY_DEPRECATED FilegetDataFile ()
 The non const version. Allows one to edit the File::dataFile. More...
 
MERCURY_DEPRECATED FilegetEneFile ()
 The non const version. Allows to edit the File::eneFile. More...
 
MERCURY_DEPRECATED FilegetFStatFile ()
 The non const version. Allows to edit the File::fStatFile. More...
 
MERCURY_DEPRECATED FilegetRestartFile ()
 The non const version. Allows to edit the File::restartFile. More...
 
MERCURY_DEPRECATED FilegetStatFile ()
 The non const version. Allows to edit the File::statFile. More...
 
MERCURY_DEPRECATED const FilegetDataFile () const
 The const version. Does not allow for any editing of the File::dataFile. More...
 
MERCURY_DEPRECATED const FilegetEneFile () const
 The const version. Does not allow for any editing of the File::eneFile. More...
 
MERCURY_DEPRECATED const FilegetFStatFile () const
 The const version. Does not allow for any editing of the File::fStatFile. More...
 
MERCURY_DEPRECATED const FilegetRestartFile () const
 The const version. Does not allow for any editing of the File::restartFile. More...
 
MERCURY_DEPRECATED const FilegetStatFile () const
 The const version. Does not allow for any editing of the File::statFile. More...
 
const std::string & getName () const
 Returns the name of the file. Does not allow to change it though. More...
 
void setName (const std::string &name)
 Allows to set the name of all the files (ene, data, fstat, restart, stat) More...
 
void setName (const char *name)
 Calls setName(std::string) More...
 
void setSaveCount (unsigned int saveCount)
 Sets File::saveCount_ for all files (ene, data, fstat, restart, stat) More...
 
void setFileType (FileType fileType)
 Sets File::fileType_ for all files (ene, data, fstat, restart, stat) More...
 
void setOpenMode (std::fstream::openmode openMode)
 Sets File::openMode_ for all files (ene, data, fstat, restart, stat) More...
 
void resetFileCounter ()
 Resets the file counter for each file i.e. for ene, data, fstat, restart, stat) More...
 
void read (std::istream &is)
 Extracts data from the input stream (which is basically a file you want to read from) into name_, restartFile .... More...
 
void write (std::ostream &os) const
 Writes data into a file from the member variables name_, restartFile, dataFile etc. More...
 
void openFiles ()
 Opens all the files (ene, data, fstat, restart, stat) for reading and writing purposes. More...
 
void closeFiles ()
 Closes all files (ene, data, fstat, restart, stat) that were opened to read or write. More...
 
void setNextSavedTimeStep (unsigned int nextSavedTimeStep)
 Sets the next time step for all the files (ene, data, fstat, restart, stat) at which the data is to be written or saved. More...
 

Public Attributes

File dataFile
 An instance of class File to handle in- and output into a .data file. More...
 
File fStatFile
 An instance of class File to handle in- and output into a .fstat file. More...
 
File eneFile
 An instance of class File to handle in- and output into a .ene file. More...
 
File restartFile
 An instance of class File to handle in- and output into a .restart file. More...
 
File statFile
 An instance of class File to handle in- and output into a .stat file. More...
 

Private Attributes

std::string name_
 the name of the problem, used, e.g., for the files More...
 

Detailed Description

Every simulation requires data files to store all the information necessary for visualisation and analysis. The class File provides an fstream variable for reading/writing i.e. input and output.

Files is defined in the header Files.h, which includes definitions from another header called "File.h"

The class also allows one to store additional information like

  • the name of the file,
  • the type of the file (no file or one file or multiple files), File::fileType_, and
  • the opening mode which basically defines if one is using the file for reading or writing purposes (input/ output/ appended output).

Definition at line 42 of file Files.h.

Constructor & Destructor Documentation

Files::Files ( )

A constructor.

The constructor which sets the file precision for DataFile, FStatFile, EneFile, RestartFile, StatFile.

Definition at line 33 of file Files.cc.

References dataFile, eneFile, fStatFile, File::getFstream(), name_, restartFile, and statFile.

34 {
35  //constructor();
36  dataFile.getFstream().precision(13);
37  fStatFile.getFstream().precision(13);
38  eneFile.getFstream().precision(13);
39  restartFile.getFstream().precision(15);
40  statFile.getFstream().precision(5);
41  statFile.getFstream().setf(std::ios::left);
42  name_ = "out";
43 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
std::string name_
the name of the problem, used, e.g., for the files
Definition: Files.h:230
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
std::fstream & getFstream()
Allows to access the member variable File::fstream_.
Definition: File.cc:151
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
Files::~Files ( )
virtual

A destructor, watch out its a virtual destructor.

Definition at line 45 of file Files.cc.

46 {
47 
48 }
Files::Files ( const Files other)

Copy constructor.

Also sets the name of Files to be the same as the one from which one makes a copy.

Parameters
[in]other(A const reference of the object to be copied)

Definition at line 53 of file Files.cc.

References getName(), and setName().

54 {
55  //constructor();
56  setName(other.getName());
57 }
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: Files.cc:150
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: Files.cc:132

Member Function Documentation

void Files::closeFiles ( )

Closes all files (ene, data, fstat, restart, stat) that were opened to read or write.

Definition at line 252 of file Files.cc.

References File::close(), dataFile, eneFile, fStatFile, restartFile, and statFile.

Referenced by DPMBase::solve(), and Mercury3DRestart::writeOutputFiles().

253 {
254  dataFile.close();
255  fStatFile.close();
256  restartFile.close();
257  statFile.close();
258  eneFile.close();
259 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
void close()
Closes the file by calling fstream_.close()
Definition: File.cc:362
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
File & Files::getDataFile ( )

The non const version. Allows one to edit the File::dataFile.

Deprecated:
dataFile is now protected, so it can be used by all applications. Please don't use getDataFile() anymore.
Returns
File& (A reference of object type File i.e. File& dataFile)

Definition at line 61 of file Files.cc.

References dataFile.

62 {
63  return dataFile;
64 }
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
const File & Files::getDataFile ( ) const

The const version. Does not allow for any editing of the File::dataFile.

Deprecated:
dataFile is now protected, so it can be used by all applications. Please don't use getDataFile() anymore.
Returns
const File& (A const reference of object type File i.e. const File& dataFile)

Definition at line 96 of file Files.cc.

References dataFile.

97 {
98  return dataFile;
99 }
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
File & Files::getEneFile ( )

The non const version. Allows to edit the File::eneFile.

Deprecated:
eneFile is now protected, so it can be used by all applications. Please don't use getEneFile() anymore.
Returns
File& (A reference of object type File i.e. File& eneFile)

Definition at line 68 of file Files.cc.

References eneFile.

69 {
70  return eneFile;
71 }
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
const File & Files::getEneFile ( ) const

The const version. Does not allow for any editing of the File::eneFile.

Deprecated:
eneFile is now protected, so it can be used by all applications. Please don't use getEneFile() anymore.
Returns
const File& (A const reference of object type File i.e. const File& eneFile)

Definition at line 104 of file Files.cc.

References eneFile.

105 {
106  return eneFile;
107 }
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
File & Files::getFStatFile ( )

The non const version. Allows to edit the File::fStatFile.

Deprecated:
fStatFile is now protected, so it can be used by all applications. Please don't use getFStatFile() anymore.
Returns
File& (A reference of object type File i.e. File& fStatFile)

Definition at line 75 of file Files.cc.

References fStatFile.

76 {
77  return fStatFile;
78 }
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
const File & Files::getFStatFile ( ) const

The const version. Does not allow for any editing of the File::fStatFile.

Deprecated:
fStatFile is now protected, so it can be used by all applications. Please don't use getFStatFile() anymore.
Returns
const File& (A const reference of object type File i.e. const File& fStatFile)

Definition at line 111 of file Files.cc.

References fStatFile.

112 {
113  return fStatFile;
114 }
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
const std::string & Files::getName ( ) const

Returns the name of the file. Does not allow to change it though.

Returns
const File& (A const reference of object type std::string i.e. const std::string& name_)

Definition at line 132 of file Files.cc.

References name_.

Referenced by Files(), main(), Mercury3DRestart::readNextArgument(), DPMBase::readNextArgument(), Chute::setupInitialConditions(), DPMBase::solve(), Mercury3DRestart::writeOutputFiles(), InteractionHandler::writeVTK(), ParticleHandler::writeVTK(), DPMBase::writeVTK(), WallHandler::writeVTKBoundingBox(), and WallHandler::writeVTKFile().

133 {
134  return name_;
135 }
std::string name_
the name of the problem, used, e.g., for the files
Definition: Files.h:230
File & Files::getRestartFile ( )

The non const version. Allows to edit the File::restartFile.

Deprecated:
restartFile is now protected, so it can be used by all applications. Please don't use getRestartFile() anymore.
Returns
File& (A reference of object type File i.e. File& restartFile)

Definition at line 82 of file Files.cc.

References restartFile.

83 {
84  return restartFile;
85 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
const File & Files::getRestartFile ( ) const

The const version. Does not allow for any editing of the File::restartFile.

Deprecated:
restartFile is now protected, so it can be used by all applications. Please don't use getRestartFile() anymore.
Returns
const File& (A const reference of object type File i.e. const File& restartFile)

Definition at line 118 of file Files.cc.

References restartFile.

119 {
120  return restartFile;
121 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
File & Files::getStatFile ( )

The non const version. Allows to edit the File::statFile.

Deprecated:
statFile is now protected, so it can be used by all applications. Please don't use getStatFile() anymore.
Returns
File& (A reference of object type File i.e. File& statFile)

Definition at line 89 of file Files.cc.

References statFile.

90 {
91  return statFile;
92 }
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
const File & Files::getStatFile ( ) const

The const version. Does not allow for any editing of the File::statFile.

Deprecated:
statFile is now protected, so it can be used by all applications. Please don't use getStatFile() anymore.
Returns
const File& (A const reference of object type File i.e. const File& statFile)

Definition at line 125 of file Files.cc.

References statFile.

126 {
127  return statFile;
128 }
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
void Files::openFiles ( )

Opens all the files (ene, data, fstat, restart, stat) for reading and writing purposes.

Definition at line 241 of file Files.cc.

References dataFile, eneFile, fStatFile, File::open(), and restartFile.

242 {
243  dataFile.open();
244  fStatFile.open();
245  restartFile.open();
246  //statFile.open();
247  eneFile.open();
248 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
bool open()
Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the ne...
Definition: File.cc:320
void Files::read ( std::istream &  is)

Extracts data from the input stream (which is basically a file you want to read from) into name_, restartFile ....

Parameters
[in,out]is(a reference of the input stream)

Definition at line 212 of file Files.cc.

References dataFile, eneFile, fStatFile, name_, restartFile, setName(), and statFile.

Referenced by FilesAndRunNumber::read().

213 {
214  std::string dummy;
215  is >> dummy >> name_;
216  setName(name_);
217  is >> dummy >> dataFile;
218  is >> dummy >> fStatFile;
219  is >> dummy >> eneFile;
220  is >> dummy >> restartFile;
221  is >> dummy >> statFile;
222 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
std::string name_
the name of the problem, used, e.g., for the files
Definition: Files.h:230
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: Files.cc:150
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
void Files::resetFileCounter ( )

Resets the file counter for each file i.e. for ene, data, fstat, restart, stat)

This implicitly calls the setCounter() function defined in File.h

Definition at line 190 of file Files.cc.

References dataFile, eneFile, fStatFile, restartFile, File::setCounter(), and statFile.

Referenced by DPMBase::solve().

191 {
192  dataFile.setCounter(0);
195  statFile.setCounter(0);
196  eneFile.setCounter(0);
197 }
void setCounter(unsigned int counter)
Allows the user to set the file counter according to his need. Sets File::counter_.
Definition: File.cc:224
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
void Files::setFileType ( FileType  fileType)

Sets File::fileType_ for all files (ene, data, fstat, restart, stat)

Calls the setFileType() function from the File.h, which basically sets the File::fileType_

Parameters
[in]fileType(an object of enum class FileType)

Definition at line 170 of file Files.cc.

References dataFile, eneFile, fStatFile, restartFile, File::setFileType(), and statFile.

Referenced by helpers::loadingTest(), helpers::normalAndTangentialLoadingTest(), helpers::objectivenessTest(), and DPMBase::readNextArgument().

171 {
172  dataFile.setFileType(fileType);
173  fStatFile.setFileType(fileType);
174  restartFile.setFileType(fileType);
175  statFile.setFileType(fileType);
176  eneFile.setFileType(fileType);
177 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
void setFileType(FileType fileType)
Sets the type of file needed to write into or read from. File::fileType_.
Definition: File.cc:210
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
void Files::setName ( const std::string &  name)

Allows to set the name of all the files (ene, data, fstat, restart, stat)

Parameters
[in]name

Definition at line 150 of file Files.cc.

References dataFile, eneFile, fStatFile, name_, restartFile, File::setName(), and statFile.

Referenced by DPMBase::constructor(), ChuteBottom::constructor(), FileReader::FileReader(), Files(), main(), read(), Mercury3DRestart::readNextArgument(), DPMBase::readNextArgument(), DPMBase::readOld(), setName(), and DPMBase::solve().

151 {
152  name_ = name; // was before this->name_ = name
153  dataFile.setName(name_ + ".data");
154  fStatFile.setName(name_ + ".fstat");
155  restartFile.setName(name_ + ".restart");
156  statFile.setName(name_ + ".stat");
157  eneFile.setName(name_ + ".ene");
158 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
std::string name_
the name of the problem, used, e.g., for the files
Definition: Files.h:230
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
Definition: File.cc:196
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
void Files::setName ( const char *  name)

Calls setName(std::string)

Parameters
[in]name

Definition at line 162 of file Files.cc.

References setName().

163 {
164  setName(std::string(name));
165 }
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: Files.cc:150
void Files::setNextSavedTimeStep ( unsigned int  nextSavedTimeStep)

Sets the next time step for all the files (ene, data, fstat, restart, stat) at which the data is to be written or saved.

Parameters
[in]nextSavedTimeStep

Definition at line 263 of file Files.cc.

References dataFile, eneFile, fStatFile, restartFile, File::setNextSavedTimeStep(), and statFile.

Referenced by FileReader::read(), DPMBase::readNextArgument(), and DPMBase::solve().

264 {
265  dataFile.setNextSavedTimeStep(nextSavedTimeStep);
266  fStatFile.setNextSavedTimeStep(nextSavedTimeStep);
267  restartFile.setNextSavedTimeStep(nextSavedTimeStep);
268  statFile.setNextSavedTimeStep(nextSavedTimeStep);
269  eneFile.setNextSavedTimeStep(nextSavedTimeStep);
270 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
void setNextSavedTimeStep(unsigned int nextSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:300
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
void Files::setOpenMode ( std::fstream::openmode  openMode)

Sets File::openMode_ for all files (ene, data, fstat, restart, stat)

Parameters
[in]openmode

Definition at line 201 of file Files.cc.

References dataFile, eneFile, fStatFile, restartFile, File::setOpenMode(), and statFile.

Referenced by DPMBase::solve().

202 {
203  dataFile.setOpenMode(openMode);
204  fStatFile.setOpenMode(openMode);
205  restartFile.setOpenMode(openMode);
206  statFile.setOpenMode(openMode);
207  eneFile.setOpenMode(openMode);
208 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
void setOpenMode(std::fstream::openmode openMode)
Allows the user to Sets File::openMode_.
Definition: File.cc:268
void Files::setSaveCount ( unsigned int  saveCount)

Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)

sets the number of time steps skipped between each save for ALL data files.

Definition at line 139 of file Files.cc.

References dataFile, eneFile, fStatFile, restartFile, File::setSaveCount(), and statFile.

Referenced by DPMBase::constructor(), helpers::loadingTest(), ChuteBottom::makeRoughBottom(), helpers::normalAndTangentialLoadingTest(), helpers::objectivenessTest(), DPMBase::readNextArgument(), and DPMBase::readParAndIniFiles().

140 {
141  dataFile.setSaveCount(saveCount);
142  fStatFile.setSaveCount(saveCount);
143  restartFile.setSaveCount(saveCount);
144  statFile.setSaveCount(saveCount);
145  eneFile.setSaveCount(saveCount);
146 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_.
Definition: File.cc:283
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
void Files::write ( std::ostream &  os) const

Writes data into a file from the member variables name_, restartFile, dataFile etc.

Parameters
[in,out]osWe pass the std::ostream& os (which is basically the file into which you want the data to be written into) as an input argument, As the output stream is modified in the write function below, it is also the output variable (do not confuse
[out]withthe return variable)

Definition at line 229 of file Files.cc.

References dataFile, eneFile, fStatFile, name_, restartFile, and statFile.

Referenced by FilesAndRunNumber::write().

230 {
231  os << " name " << name_<< std::endl;
232  os << "dataFile " << dataFile << std::endl;
233  os << "fStatFile " << fStatFile << std::endl;
234  os << "eneFile " << eneFile << std::endl;
235  os << "restartFile " << restartFile << std::endl;
236  os << "statFile " << statFile << std::endl;
237 }
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
std::string name_
the name of the problem, used, e.g., for the files
Definition: Files.h:230
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: Files.h:214
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224

Member Data Documentation

File Files::eneFile
std::string Files::name_
private

the name of the problem, used, e.g., for the files

Definition at line 230 of file Files.h.

Referenced by Files(), getName(), read(), setName(), and write().

File Files::statFile

An instance of class File to handle in- and output into a .stat file.

Definition at line 224 of file Files.h.

Referenced by closeFiles(), Files(), getStatFile(), read(), DPMBase::readNextArgument(), DPMBase::readOld(), resetFileCounter(), setFileType(), setName(), setNextSavedTimeStep(), setOpenMode(), setSaveCount(), and write().


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