MercuryDPM  Beta
 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(), 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 }
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
std::fstream & getFstream()
Allows to access the member variable File::fstream_.
Definition: File.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
Files::~Files ( )
virtual

A destructor, watch out its a virtual destructor.

Definition at line 44 of file Files.cc.

45 {
46 
47 }
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 52 of file Files.cc.

References getName(), and setName().

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

Member Function Documentation

void Files::closeFiles ( )

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

Definition at line 250 of file Files.cc.

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

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

251 {
252  dataFile.close();
253  fStatFile.close();
254  restartFile.close();
255  statFile.close();
256  eneFile.close();
257 }
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:360
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 60 of file Files.cc.

References dataFile.

61 {
62  return dataFile;
63 }
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 95 of file Files.cc.

References dataFile.

96 {
97  return dataFile;
98 }
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 67 of file Files.cc.

References eneFile.

68 {
69  return eneFile;
70 }
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 103 of file Files.cc.

References eneFile.

104 {
105  return eneFile;
106 }
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 74 of file Files.cc.

References fStatFile.

75 {
76  return fStatFile;
77 }
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 110 of file Files.cc.

References fStatFile.

111 {
112  return fStatFile;
113 }
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 131 of file Files.cc.

References name_.

Referenced by Files(), DPMBase::readNextArgument(), Chute::setupInitialConditions(), DPMBase::solve(), and Mercury3DRestart::writeOutputFiles().

132 {
133  return name_;
134 }
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 81 of file Files.cc.

References restartFile.

82 {
83  return restartFile;
84 }
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 117 of file Files.cc.

References restartFile.

118 {
119  return restartFile;
120 }
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 88 of file Files.cc.

References statFile.

89 {
90  return statFile;
91 }
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 124 of file Files.cc.

References statFile.

125 {
126  return statFile;
127 }
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 239 of file Files.cc.

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

240 {
241  dataFile.open();
242  fStatFile.open();
243  restartFile.open();
244  //statFile.open();
245  eneFile.open();
246 }
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:318
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 211 of file Files.cc.

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

Referenced by FilesAndRunNumber::read().

212 {
213  std::string dummy;
214  is >> dummy >> name_;
215  is >> dummy >> dataFile;
216  is >> dummy >> fStatFile;
217  is >> dummy >> eneFile;
218  is >> dummy >> restartFile;
219  is >> dummy >> statFile;
220 }
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
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 189 of file Files.cc.

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

Referenced by DPMBase::solve().

190 {
191  dataFile.setCounter(0);
194  statFile.setCounter(0);
195  eneFile.setCounter(0);
196 }
void setCounter(unsigned int counter)
Allows the user to set the file counter according to his need. Sets File::counter_.
Definition: File.cc:223
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 169 of file Files.cc.

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

Referenced by DPMBase::readNextArgument().

170 {
171  dataFile.setFileType(fileType);
172  fStatFile.setFileType(fileType);
173  restartFile.setFileType(fileType);
174  statFile.setFileType(fileType);
175  eneFile.setFileType(fileType);
176 }
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:209
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 149 of file Files.cc.

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

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

150 {
151  name_ = name; // was before this->name_ = name
152  dataFile.setName(name_ + ".data");
153  fStatFile.setName(name_ + ".fstat");
154  restartFile.setName(name_ + ".restart");
155  statFile.setName(name_ + ".stat");
156  eneFile.setName(name_ + ".ene");
157 }
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:195
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 161 of file Files.cc.

References setName().

162 {
163  setName(std::string(name));
164 }
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: Files.cc:149
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 261 of file Files.cc.

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

Referenced by DPMBase::solve().

262 {
263  dataFile.setNextSavedTimeStep(nextSavedTimeStep);
264  fStatFile.setNextSavedTimeStep(nextSavedTimeStep);
265  restartFile.setNextSavedTimeStep(nextSavedTimeStep);
266  statFile.setNextSavedTimeStep(nextSavedTimeStep);
267  eneFile.setNextSavedTimeStep(nextSavedTimeStep);
268 }
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:298
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 200 of file Files.cc.

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

Referenced by DPMBase::solve().

201 {
202  dataFile.setOpenMode(openMode);
203  fStatFile.setOpenMode(openMode);
204  restartFile.setOpenMode(openMode);
205  statFile.setOpenMode(openMode);
206  eneFile.setOpenMode(openMode);
207 }
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:267
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 138 of file Files.cc.

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

Referenced by DPMBase::constructor(), ChuteBottom::makeRoughBottom(), DPMBase::readNextArgument(), and DPMBase::readParAndIniFiles().

139 {
140  dataFile.setSaveCount(saveCount);
141  fStatFile.setSaveCount(saveCount);
142  restartFile.setSaveCount(saveCount);
143  statFile.setSaveCount(saveCount);
144  eneFile.setSaveCount(saveCount);
145 }
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:282
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 227 of file Files.cc.

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

Referenced by FilesAndRunNumber::write().

228 {
229  os << " name " << name_<< std::endl;
230  os << "dataFile " << dataFile << std::endl;
231  os << "fStatFile " << fStatFile << std::endl;
232  os << "eneFile " << eneFile << std::endl;
233  os << "restartFile " << restartFile << std::endl;
234  os << "statFile " << statFile << std::endl;
235 }
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 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: