diff --git a/CMakeLists.txt b/CMakeLists.txt index 64532366..3ce683a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,6 @@ endif() if(pFlow_Build_MPI) find_package(MPI REQUIRED) - link_libraries(MPI::MPI_CXX) endif() @@ -78,7 +77,7 @@ add_subdirectory(src) #add_subdirectory(utilities) #add_subdirectory(DEMSystems) -#add_subdirectory(testIO) +add_subdirectory(testIO) install(FILES "${PROJECT_BINARY_DIR}/phasicFlowConfig.H" DESTINATION include) diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index 155dc7db..6ebacce2 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -4,13 +4,37 @@ types/basicTypes/bTypesFunctions.cpp types/basicTypes/Logical.cpp types/types.cpp + + +globals/error.cpp + +streams/token/tokenIO.cpp +streams/token/token.cpp +streams/iStream/IOstream.cpp +streams/iStream/iOstream.cpp +streams/iStream/iIstream.cpp +streams/Stream/Ostream.cpp +streams/Stream/Istream.cpp +streams/processorOstream/processorOstream.cpp +streams/masterOstream/masterOstream.cpp +streams/TStream/iTstream.cpp +streams/TStream/oTstream.cpp +streams/Fstream/iFstream.cpp +streams/Fstream/oFstream.cpp +streams/Fstream/fileStream.cpp +streams/streams.cpp + +fileSystem/fileSystem.cpp + processors/processors.cpp +) -globals/error.cpp) - -set(link_libs Kokkos::kokkos tbb) +set(link_libs) +if(MPI_FOUND) + set(link_libs Kokkos::kokkos tbb PRIVATE MPI::MPI_CXX) +else() + set(link_libs Kokkos::kokkos tbb) +endif() pFlow_add_library_install(phasicFlow SourceFiles link_libs) - target_include_directories(phasicFlow PUBLIC ./globals) - diff --git a/src/phasicFlow/fileSystem/fileSystem.cpp b/src/phasicFlow/fileSystem/fileSystem.cpp index 0e82fe80..79065498 100644 --- a/src/phasicFlow/fileSystem/fileSystem.cpp +++ b/src/phasicFlow/fileSystem/fileSystem.cpp @@ -284,13 +284,13 @@ pFlow::fileSystem pFlow::operator + return path; } -pFlow::iOstream& pFlow::operator << (iOstream& os, fileSystem fs) +pFlow::iOstream& pFlow::operator << (iOstream& os, const fileSystem& fs) { os << fs.path_.c_str(); return os; } -std::ostream& pFlow::operator << (std::ostream& os, fileSystem fs) +std::ostream& pFlow::operator << (std::ostream& os, const fileSystem& fs) { os << fs.path_.c_str(); return os; diff --git a/src/phasicFlow/fileSystem/fileSystem.hpp b/src/phasicFlow/fileSystem/fileSystem.hpp index 655bc0e8..2904407e 100644 --- a/src/phasicFlow/fileSystem/fileSystem.hpp +++ b/src/phasicFlow/fileSystem/fileSystem.hpp @@ -29,21 +29,20 @@ Licence: namespace pFlow { - +// - Forward class iOstream; -class ostream; class fileSystem; iOstream& operator << ( iOstream& os, - fileSystem fs + const fileSystem& fs ); std::ostream& operator << ( std::ostream& os, - fileSystem fs + const fileSystem& fs ); @@ -59,29 +58,40 @@ fileSystem operator + const word fName ); -// a class to manage file/directory names +/** + * Manages file pathes, manupulate and combines them. + * + */ class fileSystem { +public: + + using pathType = std::filesystem::path; + protected: + /// File path std::filesystem::path path_; + + /// Is this a directory path? bool isDir_; - // protected static variables + /// Not premitted chars in file name inline static word notPermittedCharsFile = word(" ") + word("\t\n\0;:?*/<>\"?\'"); - // protected methods - + /// Is name is valid for a file? bool static validFileName(const word& name) { return name.find_first_of(notPermittedCharsFile); } + /// Is a valid file name? bool static checkFileName(const word& name); public: + /// return current working directory inline static fileSystem CWD() { return fileSystem(std::filesystem::current_path().c_str()); @@ -89,92 +99,103 @@ public: public: + //// - Constructors - typedef std::filesystem::path pathType; + /// Default + fileSystem(): + path_(), + isDir_(true) + {} + /// From dir and file name + fileSystem( const word& dir, const word& file = ""); + + /// From dir and file name + fileSystem( const char* dir, const char* file = ""); - fileSystem(): - path_(), - isDir_(true) - {} - // Constructors - fileSystem( const word& dir, const word& file = ""); - fileSystem( const char* dir, const char* file = ""); - fileSystem( const pathType& path ); + /// Copy + fileSystem( const pathType& path ); - fileSystem(const fileSystem&) = default; + /// Copy + fileSystem(const fileSystem&) = default; + + /// Move + fileSystem(fileSystem&&) = default; + + /// Copy assignment + fileSystem& operator = (const fileSystem&) = default; + + /// Move assignment + fileSystem& operator = (fileSystem&&) = default; + + /// Destructor + ~fileSystem() = default; - fileSystem(fileSystem&&) = default; + //// - Methods + + /// Is directory? + bool isDir() const + { + return isDir_; + } + + /// Const access to path + const pathType& path()const + { + return path_; + } - fileSystem& operator = (const fileSystem&) = default; + /// Path in word type + word wordPath()const + { + return word(path_.c_str()); + } - fileSystem& operator = (fileSystem&&) = default; + /// Dir part of the path + fileSystem dirPath() const; - ~fileSystem() = default; + /// File name part of the path (if any) + word fileName() const; + + /// Absolute path of this + fileSystem absolute()const; + + + /// Canonical path of this (it should exist) + fileSystem canonical()const; + + /// Only operate on dir path + /// Check if the dir path exists + bool dirExist()const; + + /// Check if the path exists + bool exist()const; + + /// Operate on dir path only + /// Create dir based on the path and returns the canonical path + fileSystem createDirs()const; + + + /// If this is dir path, add the filename to dir path + /// if it is file path, replace the file name + void operator += (const word& fileName); + + /// It operates on dir path only + /// Add the dir path of fs to this + void operator /=(const fileSystem& fs ); + + /// Create a dir path from dir path of fs1 and fas2 in the + /// form of fs1/fs2 + friend fileSystem operator /(const fileSystem& fs1, const fileSystem& fs2 ); + + + /// Return the dir path of this + fileSystem operator()(bool retDir = true) const; - // Methods - bool isDir() const - { - return isDir_; - } - - const pathType& path()const - { - return path_; - } + //// - IO + friend iOstream& operator << (iOstream& os, const fileSystem& fs); - word wordPath()const - { - return word(path_.c_str()); - } - - // dir path of this - fileSystem dirPath() const; - - // file name of this (if any) - word fileName() const; - - // absolute path of this - fileSystem absolute()const; - - - //fileSystem relative()const; - - // canonical path of this (it should exist) - fileSystem canonical()const; - - // only operate on dir path - // check if the dir path exists - bool dirExist()const; - - // check if the path exists - bool exist()const; - - // operate on dir path only - // create dir based on the path and returns the canonical path - fileSystem createDirs()const; - - - // if this is dir path, add the filename to dir path - // if it is file path, replace the file name - void operator += (const word& fileName); - - // it operates on dir path only - // it adds the dir path of fs to this - void operator /=(const fileSystem& fs ); - - // Create a dir path from dir path of fs1 and fas2 in the - // form of fs1/fs2 - friend fileSystem operator /(const fileSystem& fs1, const fileSystem& fs2 ); - - - // return the dir path of this - fileSystem operator()(bool retDir = true) const; - - - friend iOstream& operator << (iOstream& os, fileSystem fs); - - friend std::ostream& operator << (std::ostream& os, fileSystem fs); + friend std::ostream& operator << (std::ostream& os, const fileSystem& fs); }; @@ -182,18 +203,22 @@ public: using fileSystemList = List; - +/// Free function to reture current working directory inline fileSystem CWD() { return fileSystem::CWD(); } +/// Free function to check if the path is dir path bool isDirectory(const fileSystem& path); +/// free function to check if the path is regular file bool isRegularFile(const fileSystem& path); +/// A list of sub-directories that exist in path. fileSystemList subDirectories(const fileSystem& path); +/// A list of file paths that exist in the path. fileSystemList containingFiles(const fileSystem& path); } // pFlow diff --git a/src/phasicFlow/globals/error.cpp b/src/phasicFlow/globals/error.cpp index d32d771e..c3b20b5a 100644 --- a/src/phasicFlow/globals/error.cpp +++ b/src/phasicFlow/globals/error.cpp @@ -37,8 +37,8 @@ pFlow::iOstream& fatalErrorMessage(const char* fileName, int linNumber ) { errorStream<<"\n>>> Fatal error in phasicFlow\n" << - "Error occured in source file "<< redText(fileName) << - " at line "<>> Fatal error in phasicFlow\n" << - " Error is issued in function " << redText(fnName)<< - ", located in file "<< redText(fileName) << - " at line "<< redText(linNumber) << '\n'; + " Error is issued in function " << Red_Text(fnName)<< + ", located in file "<< Red_Text(fileName) << + " at line "<< Red_Text(linNumber) << '\n'; return errorStream; } @@ -57,9 +57,9 @@ pFlow::iOstream& notImplementedErrorMessage(const char*fnName, const char* fileN { errorStream<<"\n>>> Fatal error in phasicFlow\n"; - errorStream<<" Function "<< redText(fnName) << " has not implmented yet!\n" << - " Function definition is in source file "<< redText(fileName) << - " at line "<< redText(lineNumber) <<'\n'; + errorStream<<" Function "<< Red_Text(fnName) << " has not implmented yet!\n" << + " Function definition is in source file "<< Red_Text(fileName) << + " at line "<< Red_Text(lineNumber) <<'\n'; return errorStream; } @@ -68,10 +68,10 @@ pFlow::iOstream& ioErrorMessage(const char* fileName, int fileLineNumber, const { errorStream<<"\n>>> Fatal IO file error\n"<< - " IO error at number "<>> Warning in phasicFlow\n"<< - " Warning is issued in function " << yellowText(fnName)<< - " in source file "<< yellowText(fileName) << - " at line "<< yellowText(linNumber) <<'\n'; + " Warning is issued in function " << Yellow_Text(fnName)<< + " in source file "<< Yellow_Text(fileName) << + " at line "<< Yellow_Text(linNumber) <<'\n'; return errorStream; } diff --git a/src/phasicFlow/processors/processors.cpp b/src/phasicFlow/processors/processors.cpp index 544b01ed..735e75db 100644 --- a/src/phasicFlow/processors/processors.cpp +++ b/src/phasicFlow/processors/processors.cpp @@ -42,8 +42,12 @@ void pFlow::processors::initProcessors(int argc, char *argv[]) processors::globalSize_ = MPI::COMM_WORLD.Get_size(); processors::globalRank_ = MPI::COMM_WORLD.Get_rank(); - //CheckMPI(MPI_comm_size( MPI_COMM_WORLD, &processors::globalSize_), true ); - //CheckMPI(MPI_comm_rank( MPI_COMM_WORLD, &processors::globalRank_), true ); + + pFlow::pOutput.activatePrefix(); + pFlow::pOutput.setPrefixNum(processors::globalRank_); + + pFlow::mOutput.setMasterSlave(processors::isMaster()); + pFlow::errReport.setMasterSlave(processors::isMaster()); } #else diff --git a/src/phasicFlow/streams/Fstream/fileStream.cpp b/src/phasicFlow/streams/Fstream/fileStream.cpp index 8edf2d3a..a577d83c 100755 --- a/src/phasicFlow/streams/Fstream/fileStream.cpp +++ b/src/phasicFlow/streams/Fstream/fileStream.cpp @@ -17,9 +17,6 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ -// based on OpenFOAM stream, with some modifications/simplifications -// to be tailored to our needs - #include "fileStream.hpp" #include "error.hpp" @@ -133,6 +130,3 @@ std::ofstream& pFlow::fileStream::outStream() { return outStream_(); } - - - diff --git a/src/phasicFlow/streams/Fstream/fileStream.hpp b/src/phasicFlow/streams/Fstream/fileStream.hpp index 8804200c..0cf6f34b 100755 --- a/src/phasicFlow/streams/Fstream/fileStream.hpp +++ b/src/phasicFlow/streams/Fstream/fileStream.hpp @@ -33,49 +33,61 @@ Licence: namespace pFlow { +/** + * Creates and manages an input/output file stream + * with specified format. + * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs. + */ class fileStream { protected: - // - in file stream + /// in file stream uniquePtr inStream_; - // - out file stream + /// out file stream uniquePtr outStream_; bool binary_ = false; - // - open input file + /// open input file void openInFile(const fileSystem& path); - // - open output file + /// open output file void openOutFile(const fileSystem& path); - // - close streams + /// close streams void close(); public: - // - Constructors + //// - Constructors - fileStream( const fileSystem& path, bool outStream = false, bool binary = false); - - fileStream(const fileStream&)= delete; + /// From file path and input type and format. + fileStream( const fileSystem& path, bool outStream = false, bool binary = false); + + /// No copy + fileStream(const fileStream&)= delete; - fileStream& operator=(const fileStream&)=delete; + /// No assignment + fileStream& operator=(const fileStream&)=delete; - virtual ~fileStream() - { - close(); - } + /// Destructor + virtual ~fileStream() + { + close(); + } - // - access - - std::ifstream& inStream(); + //// - Access - std::ofstream& outStream(); - + /// Access input file stream + std::ifstream& inStream(); + + /// Access output file stream + std::ofstream& outStream(); }; } diff --git a/src/phasicFlow/streams/Fstream/iFstream.cpp b/src/phasicFlow/streams/Fstream/iFstream.cpp index 2eb0a4fe..01043a95 100755 --- a/src/phasicFlow/streams/Fstream/iFstream.cpp +++ b/src/phasicFlow/streams/Fstream/iFstream.cpp @@ -17,9 +17,6 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ -// based on OpenFOAM stream, with some modifications/simplifications -// to be tailored to our needs - #include "iFstream.hpp" diff --git a/src/phasicFlow/streams/Fstream/iFstream.hpp b/src/phasicFlow/streams/Fstream/iFstream.hpp index a37baf81..dc90a8c2 100755 --- a/src/phasicFlow/streams/Fstream/iFstream.hpp +++ b/src/phasicFlow/streams/Fstream/iFstream.hpp @@ -17,9 +17,6 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ -// based on OpenFOAM stream, with some modifications/simplifications -// to be tailored to our needs - #ifndef __iFstream_hpp__ #define __iFstream_hpp__ @@ -31,7 +28,12 @@ Licence: namespace pFlow { - +/** + * Input file stream for reading binary or ascii data from a file. + * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs. + */ class iFstream : public fileStream, @@ -39,17 +41,19 @@ class iFstream { public: - // - Constructor - iFstream (const fileSystem& path, bool binary = false); + //// - Constructors - // no copy constructor - iFstream( const iFstream& src) = delete; + /// From file path and format + iFstream (const fileSystem& path, bool binary = false); - // no assignment - iFstream& operator = (const iFstream& rhs) = delete; + /// No copy constructor + iFstream( const iFstream& src) = delete; - // - Destructor - virtual ~iFstream() = default; + /// No assignment + iFstream& operator = (const iFstream& rhs) = delete; + + /// Destructor + virtual ~iFstream() = default; }; diff --git a/src/phasicFlow/streams/Fstream/oFstream.cpp b/src/phasicFlow/streams/Fstream/oFstream.cpp index 5e975843..54e1606a 100755 --- a/src/phasicFlow/streams/Fstream/oFstream.cpp +++ b/src/phasicFlow/streams/Fstream/oFstream.cpp @@ -17,8 +17,6 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ -// based on OpenFOAM stream, with some modifications/simplifications -// to be tailored to our needs #include "oFstream.hpp" diff --git a/src/phasicFlow/streams/Fstream/oFstream.hpp b/src/phasicFlow/streams/Fstream/oFstream.hpp index 0fa6d86d..3092b2ca 100755 --- a/src/phasicFlow/streams/Fstream/oFstream.hpp +++ b/src/phasicFlow/streams/Fstream/oFstream.hpp @@ -17,10 +17,6 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ -// based on OpenFOAM stream, with some modifications/simplifications -// to be tailored to our needs - - #ifndef __oFstream_hpp__ #define __oFstream_hpp__ @@ -32,7 +28,13 @@ Licence: namespace pFlow { - +/** + * Output file stream to send binary or ascii data to a file. + * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs + * + */ class oFstream : public fileStream, @@ -40,16 +42,18 @@ class oFstream { public: - // Constructor + //// - Constructors + + /// From file path and format oFstream (const fileSystem& path, bool binary = false); - // no copy constructor + /// No copy constructor oFstream( const oFstream& src) = delete; - // no assignment + /// No assignment oFstream& operator = (const oFstream& rhs) = delete; - // Destructor + /// Destructor virtual ~oFstream() = default; }; diff --git a/src/phasicFlow/streams/Stream/Istream.cpp b/src/phasicFlow/streams/Stream/Istream.cpp index 06e3a4ed..cda6117e 100755 --- a/src/phasicFlow/streams/Stream/Istream.cpp +++ b/src/phasicFlow/streams/Stream/Istream.cpp @@ -17,10 +17,6 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ -// based on OpenFOAM stream, with some modifications/simplifications -// to be tailored to our needs - - #include "Istream.hpp" #include "token.hpp" #include "error.hpp" @@ -797,12 +793,6 @@ pFlow::iIstream& pFlow::Istream::read(int32& val) return *this; } -pFlow::iIstream& pFlow::Istream::read(int16& val) -{ - is_ >> val; - setState(is_.rdstate()); - return *this; -} pFlow::iIstream& pFlow::Istream::read(int8& val) { @@ -811,7 +801,7 @@ pFlow::iIstream& pFlow::Istream::read(int8& val) return *this; } -pFlow::iIstream& pFlow::Istream::read(label& val) +pFlow::iIstream& pFlow::Istream::read(uint64& val) { is_ >> val; setState(is_.rdstate()); @@ -825,7 +815,7 @@ pFlow::iIstream& pFlow::Istream::read(uint32& val) return *this; } -pFlow::iIstream& pFlow::Istream::read(uint16& val) +pFlow::iIstream& pFlow::Istream::read(uint8& val) { is_ >> val; setState(is_.rdstate()); diff --git a/src/phasicFlow/streams/Stream/Istream.hpp b/src/phasicFlow/streams/Stream/Istream.hpp index b74d7dbc..2b3b4879 100755 --- a/src/phasicFlow/streams/Stream/Istream.hpp +++ b/src/phasicFlow/streams/Stream/Istream.hpp @@ -17,10 +17,6 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ -// based on OpenFOAM stream, with some modifications/simplifications -// to be tailored to our needs - - #ifndef __Istream_hpp__ #define __Istream_hpp__ @@ -34,16 +30,23 @@ Licence: namespace pFlow { - +/** + * Standard input stream for binary and ascii data + * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs. + */ class Istream : public iIstream { - // Private Data + //- Private Data - word name_; + /// Stream name + word name_; - std::istream& is_; + /// Input stream + std::istream& is_; /// Get the next valid character @@ -63,90 +66,91 @@ class Istream public: + //// - Constructors - /// Construct wrapper around std::istream, set stream status - Istream( std::istream& is, const word& streamName, writeFormat wf = ASCII); + /// Construct wrapper around std::istream, set stream status + Istream( std::istream& is, const word& streamName, writeFormat wf = ASCII); - /// Destructor - virtual ~Istream() = default; + /// Destructor + virtual ~Istream() = default; //// - Methods - /// Return the name of the stream - virtual const word& name() const - { - return name_; - } + /// Return the name of the stream + virtual const word& name() const + { + return name_; + } - /// Return non-const access to the name of the stream - virtual word& name() - { - return name_; - } + /// Return non-const access to the name of the stream + virtual word& name() + { + return name_; + } - /// Return flags of output stream - virtual ios_base::fmtflags flags() const; + /// Return flags of output stream + virtual ios_base::fmtflags flags() const; - //// Read Functions + //// - Read Functions - /// Raw, low-level get character function. - Istream& get(char& c); + /// Raw, low-level get character function. + Istream& get(char& c); - /// Raw, low-level peek function. - // Does not remove the character from the stream. - // Returns the next character in the stream or EOF if the - // end of file is read. - int peek(); + /// Raw, low-level peek function. + /// Does not remove the character from the stream. + /// Returns the next character in the stream or EOF if the + /// end of file is read. + int peek(); - /// Raw, low-level getline (until delimiter) into a string. - Istream& getLine(word& str, char delim = '\n'); + /// Raw, low-level getline (until delimiter) into a string. + Istream& getLine(word& str, char delim = '\n'); - /// Low-level discard until delimiter - // return the number of characters extracted - std::streamsize getLine(std::nullptr_t, char delim = '\n'); + /// Low-level discard until delimiter + /// return the number of characters extracted + std::streamsize getLine(std::nullptr_t, char delim = '\n'); - /// Raw, low-level putback character function. - Istream& putback(const char c); + /// Raw, low-level putback character function. + Istream& putback(const char c); - /// Return next token from stream - virtual iIstream& read(token& t) override; + /// Return next token from stream + virtual iIstream& read(token& t) override; - /// Read a character - virtual iIstream& read(char& c) override; + /// Read a character + virtual iIstream& read(char& c) override; - /// Read a word - virtual iIstream& read(word& str) override; + /// Read a word + virtual iIstream& read(word& str) override; - /// Read a string - virtual iIstream& readString(word& str) override; + /// Read a string + virtual iIstream& readString(word& str) override; - /// Read a int64 - virtual iIstream& read(int64&) override; + /// Read a int64 + virtual iIstream& read(int64&) override; - /// Read a int32 - virtual iIstream& read(int32&) override; + /// Read a int32 + virtual iIstream& read(int32&) override; - /// Read a int8 - virtual iIstream& read(int8&) override; + /// Read a int8 + virtual iIstream& read(int8&) override; - /// Read a uint64 - virtual iIstream& read(uint64&) override; + /// Read a uint64 + virtual iIstream& read(uint64&) override; - /// Read a uint32 - virtual iIstream& read(uint32&) override; + /// Read a uint32 + virtual iIstream& read(uint32&) override; - /// Read a uint8 - virtual iIstream& read(uint8&) override; + /// Read a uint8 + virtual iIstream& read(uint8&) override; - /// Read a float - virtual iIstream& read(float& val) override; + /// Read a float + virtual iIstream& read(float& val) override; - /// Read a double - virtual iIstream& read(double& val) override; + /// Read a double + virtual iIstream& read(double& val) override; - iIstream& read(char* buffer, std::streamsize count) override; + iIstream& read(char* buffer, std::streamsize count) override; /// Rewind the stream so that it may be read again diff --git a/src/phasicFlow/streams/Stream/Ostream.cpp b/src/phasicFlow/streams/Stream/Ostream.cpp index 51f2f28d..aa89bd54 100755 --- a/src/phasicFlow/streams/Stream/Ostream.cpp +++ b/src/phasicFlow/streams/Stream/Ostream.cpp @@ -17,8 +17,6 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ -// based on OpenFOAM stream, with some modifications/simplifications -// to be tailored to our needs #include "error.hpp" #include "token.hpp" @@ -181,21 +179,14 @@ pFlow::iOstream& pFlow::Ostream::write(const int32 val) return *this; } -/*pFlow::iOstream& pFlow::Ostream::write(const int16 val) +pFlow::iOstream& pFlow::Ostream::write(const int8 val) { os_ << val; setState(os_.rdstate()); return *this; } -pFlow::iOstream& pFlow::Ostream::write(const int8 val) -{ - os_ << val; - setState(os_.rdstate()); - return *this; -}*/ - -pFlow::iOstream& pFlow::Ostream::write(const label val) +pFlow::iOstream& pFlow::Ostream::write(const uint64 val) { os_ << val; setState(os_.rdstate()); @@ -209,7 +200,7 @@ pFlow::iOstream& pFlow::Ostream::write(const uint32 val) return *this; } -pFlow::iOstream& pFlow::Ostream::write(const uint16 val) +pFlow::iOstream& pFlow::Ostream::write(const uint8 val) { os_ << val; setState(os_.rdstate()); @@ -253,9 +244,6 @@ pFlow::iOstream& pFlow::Ostream::write return *this; } - - - void pFlow::Ostream::indent() { for (unsigned short i = 0; i < indentLevel_*indentSize_; ++i) @@ -270,14 +258,12 @@ void pFlow::Ostream::flush() os_.flush(); } - void pFlow::Ostream::endl() { write('\n'); os_.flush(); } - std::ios_base::fmtflags pFlow::Ostream::flags() const { return os_.flags(); diff --git a/src/phasicFlow/streams/Stream/Ostream.hpp b/src/phasicFlow/streams/Stream/Ostream.hpp index da3e0bd9..25b2b09c 100755 --- a/src/phasicFlow/streams/Stream/Ostream.hpp +++ b/src/phasicFlow/streams/Stream/Ostream.hpp @@ -30,34 +30,44 @@ Licence: namespace pFlow { - - +/** + * Standard output stream for BINARY and ASCII formats + * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs + */ class Ostream : public iOstream { +private: + // - private data members + + /// Stream name word name_; + /// Output stream std::ostream& os_; public: - // Constructors + ///- Constructors - Ostream ( std::ostream& os, const word& streamName, writeFormat wf = ASCII); + /// Construct from components + Ostream ( std::ostream& os, const word& streamName, writeFormat wf = ASCII); - /// no copy construct - Ostream(const Ostream&) = delete; + /// No copy construct + Ostream(const Ostream&) = delete; - /// No copy assignment - void operator=(const Ostream&) = delete; + /// No copy assignment + void operator=(const Ostream&) = delete; //// - Methods - /// Return the name of the stream + /// Return the name of the stream virtual const word& name() const { return name_; @@ -74,7 +84,7 @@ public: /// Write token to stream or otherwise handle it. - // return false if the token type was not handled by this method + /// return false if the token type was not handled by this method bool write(const token& tok)override; /// Write character @@ -87,7 +97,7 @@ public: iOstream& write(const word& str)override; /// Write std::string surrounded by quotes. - // Optional write without quotes. + /// Optional write without quotes. iOstream& writeQuoted ( const word& str, const bool quoted=true ) override; /// Write int64 @@ -133,21 +143,21 @@ public: char fill() const override; /// Set padding character for formatted field up to field width - // \return previous padding character + /// \return previous padding character char fill(const char fillch) override; /// Get width of output field int width() const override; /// Set width of output field - // \return previous width + /// \return previous width int width(const int w) override; /// Get precision of output field int precision() const override; /// Set precision of output field - // return old precision + /// return old precision int precision(const int p) override; /// Access to underlying std::ostream @@ -165,10 +175,9 @@ public: }; - } // pFlow -#endif +#endif //__Ostream_hpp__ diff --git a/src/phasicFlow/streams/TStream/helperTstream.hpp b/src/phasicFlow/streams/TStream/helperTstream.hpp index 6a43874c..9fae802c 100755 --- a/src/phasicFlow/streams/TStream/helperTstream.hpp +++ b/src/phasicFlow/streams/TStream/helperTstream.hpp @@ -1,8 +1,26 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ #ifndef __helperTstream_hpp__ #define __helperTstream_hpp__ - inline bool validTokenForStream(const token tok) { if( tok.good() && !tok.isPunctuation() )return true; diff --git a/src/phasicFlow/streams/TStream/iTstream.cpp b/src/phasicFlow/streams/TStream/iTstream.cpp index d5f6ab2a..a786561a 100755 --- a/src/phasicFlow/streams/TStream/iTstream.cpp +++ b/src/phasicFlow/streams/TStream/iTstream.cpp @@ -222,16 +222,6 @@ pFlow::iIstream& pFlow::iTstream::read return *this; } -pFlow::iIstream& pFlow::iTstream::read -( - int16& val -) -{ - notImplementedFunction; - fatalExit; - CONSUME_PARAM(val); - return *this; -} pFlow::iIstream& pFlow::iTstream::read ( @@ -246,7 +236,7 @@ pFlow::iIstream& pFlow::iTstream::read pFlow::iIstream& pFlow::iTstream::read ( - label& val + uint64& val ) { notImplementedFunction; @@ -268,7 +258,7 @@ pFlow::iIstream& pFlow::iTstream::read pFlow::iIstream& pFlow::iTstream::read ( - uint16& val + uint8& val ) { notImplementedFunction; diff --git a/src/phasicFlow/streams/TStream/iTstream.hpp b/src/phasicFlow/streams/TStream/iTstream.hpp index 930b2f65..8bb2e824 100755 --- a/src/phasicFlow/streams/TStream/iTstream.hpp +++ b/src/phasicFlow/streams/TStream/iTstream.hpp @@ -10,7 +10,7 @@ namespace pFlow { -// helper functions declearation +//- helper functions declearation inline bool validTokenForStream(const token tok); inline bool isBeginToken(const token& tok); @@ -18,28 +18,34 @@ inline bool isBeginToken(const token& tok); inline bool isEndToken(const token& tok); +/** + * Input token stream. + * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs. + */ class iTstream : public iIstream { protected: - // - name of the stream + /// name of the stream word name_; - // - list of tokens in this stream + /// list of tokens in this stream tokenList tokenList_; - // - current token + /// current token tokenList::iterator currentToken_; - // - check if end of list is reached + /// check if end of list is reached bool isLastToken(); - // - rewind the stream + /// rewind the stream void setFirstToken(); - // - check for valid tokens in the tokenList + /// check for valid tokens in the tokenList void validate(); public: @@ -49,34 +55,35 @@ public: /// construct with a name iTstream(const word& streamName); - // - construct with name and copy + /// construct with name and copy iTstream(const word& streamName, const tokenList& tList); - // - construct with name and move + /// construct with name and move iTstream(const word& streamName, tokenList && tList); - // - copy construct + /// copy construct iTstream(const iTstream&) = default; - // - move construct + + /// move construct iTstream(iTstream&&) = default; - // - copy assignment + /// copy assignment iTstream& operator=(const iTstream&) = default; - // - move assignment + /// move assignment iTstream& operator=(iTstream&&) = default; - // copy assignment from tokenList + /// copy assignment from tokenList void operator=(const tokenList& tList); - // move assignment from tokenList + /// move assignment from tokenList void operator=(tokenList&& tList); /// Destructor virtual ~iTstream() = default; - //// Member Functions + //// - Member Functions /// Return the name of the stream virtual const word& name() const; @@ -122,26 +129,26 @@ public: iIstream& read(char* buffer, std::streamsize count) override; - // - Rewind the stream so that it may be read again + /// Rewind the stream so that it may be read again virtual void rewind(); - // - reset the iTstream and make the stream empty + /// reset the iTstream and make the stream empty virtual void reset(); - // - const access to token list + /// const access to token list const tokenList& tokens()const; - // - size + /// size size_t size()const; - // - size + /// size size_t numTokens()const; - // - append a list of tokens to the end of tokens + /// append a list of tokens to the end of tokens // and rewind the stream void appendTokens(const tokenList & tList); - // - append token to the end of token and rewind the stream + /// append token to the end of token and rewind the stream void appendToken(const token& t); /// Return flags of output stream diff --git a/src/phasicFlow/streams/TStream/oTstream.cpp b/src/phasicFlow/streams/TStream/oTstream.cpp index 5f158545..2ef897ca 100755 --- a/src/phasicFlow/streams/TStream/oTstream.cpp +++ b/src/phasicFlow/streams/TStream/oTstream.cpp @@ -108,10 +108,17 @@ pFlow::iOstream& pFlow::oTstream::write(const int32 val) return *this; } +pFlow::iOstream& pFlow::oTstream::write(const int8 val) +{ + append(token(val)); // tokenType::INT64 + + return *this; +} -pFlow::iOstream& pFlow::oTstream::write(const label val) + +pFlow::iOstream& pFlow::oTstream::write(const uint64 val) { append(token(static_cast(val))); // tokenType::INT64 @@ -125,7 +132,7 @@ pFlow::iOstream& pFlow::oTstream::write(const uint32 val) return *this; } -pFlow::iOstream& pFlow::oTstream::write(const uint16 val) +pFlow::iOstream& pFlow::oTstream::write(const uint8 val) { append(token(static_cast(val))); // tokenType::INT64 diff --git a/src/phasicFlow/streams/TStream/oTstream.hpp b/src/phasicFlow/streams/TStream/oTstream.hpp index 5458cbbd..c86b0090 100755 --- a/src/phasicFlow/streams/TStream/oTstream.hpp +++ b/src/phasicFlow/streams/TStream/oTstream.hpp @@ -1,4 +1,22 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +-----------------------------------------------------------------------------*/ #ifndef __oTstream_hpp__ #define __oTstream_hpp__ @@ -6,20 +24,27 @@ #include "iOstream.hpp" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - namespace pFlow { -// helper functions declearation +//- Helper functions declearation + +/// Is tok a valid token for this stream? inline bool validTokenForStream(const token tok); +/// Is tok a begin token? inline bool isBeginToken(const token& tok); +/// Is tok an end token? inline bool isEndToken(const token& tok); - +/** + * Output token stream + * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs. + */ class oTstream : public iOstream @@ -27,49 +52,49 @@ class oTstream protected: - // - name of stream + /// name of stream word name_; - // - tokenList + /// tokenList tokenList tokenList_; public: //// - Constructors - // - emtpy stream with a name + /// emtpy stream with a name oTstream(const word& nm); - // - copy construcotr + /// copy construcotr oTstream(const oTstream& src); - // - move construct + /// move construct oTstream(oTstream&&) = default; - // - destructor + /// destructor virtual ~oTstream() = default; //// - Methods - // give const access + // Give const access const tokenList& tokens()const; - // give access + // Give access tokenList& tokens(); //// - Write /// Write token to stream or otherwise handle it. - // return false if the token type was not handled by this method + /// return false if the token type was not handled by this method virtual bool write(const token& tok); /// Write single character. Whitespace is suppressed. virtual iOstream& write(const char c); /// Write the word-characters of a character string. - // Sends as a single char, or as word. + /// Sends as a single char, or as word. virtual iOstream& write(const char* str); /// Write word @@ -77,7 +102,7 @@ public: /// Write std::string surrounded by quotes. - // Optional write without quotes. + /// Optional write without quotes. virtual iOstream& writeQuoted(const std::string& str, const bool quoted=true ); /// Write int64 @@ -138,7 +163,7 @@ public: {} /// Get the current padding character - // \return previous padding character + /// \return previous padding character virtual char fill() const { return 0; @@ -157,7 +182,7 @@ public: } /// Set width of output field - // \return previous width + /// \return previous width virtual int width(const int) { return 0; @@ -170,7 +195,7 @@ public: } /// Set precision of output field - // \return old precision + /// \return old precision virtual int precision(const int) { return 0; @@ -192,12 +217,9 @@ public: #include "helperTstream.hpp" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace pFlow -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif -// ************************************************************************* // diff --git a/src/phasicFlow/streams/iStream/IOstream.hpp b/src/phasicFlow/streams/iStream/IOstream.hpp index 046aa1f0..a0f037de 100644 --- a/src/phasicFlow/streams/iStream/IOstream.hpp +++ b/src/phasicFlow/streams/iStream/IOstream.hpp @@ -17,13 +17,9 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ - - #ifndef __IOstream_hpp__ #define __IOstream_hpp__ -// based on OpenFOAM stream, with some modifications/simplifications -// to be tailored to our needs #include @@ -42,6 +38,12 @@ using std::cerr; namespace pFlow { +/** + * A base calss for input/output streams + * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs + */ class IOstream { @@ -115,7 +117,7 @@ protected: public: - //- Constructors + ////- Constructors /// Default explicit IOstream(): @@ -144,7 +146,7 @@ public: virtual ~IOstream() = default; - //- Member Functions + ////- Member Functions /// Return the name of the stream virtual const word& name() const; @@ -299,13 +301,13 @@ public: flags(flags() & ~f); } - }; // end of IOstream /// An IOstream manipulator typedef IOstream& (*IOstreamManip)(IOstream&); + inline IOstream& dec(IOstream& io) { io.setf(ios_base::dec, ios_base::dec|ios_base::hex|ios_base::oct); @@ -337,7 +339,6 @@ inline IOstream& scientific(IOstream& io) } - } // pFlow #endif // __IOstream__hpp__ diff --git a/src/phasicFlow/streams/iStream/iIstream.cpp b/src/phasicFlow/streams/iStream/iIstream.cpp index 96849244..f91798b2 100755 --- a/src/phasicFlow/streams/iStream/iIstream.cpp +++ b/src/phasicFlow/streams/iStream/iIstream.cpp @@ -1,4 +1,22 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +-----------------------------------------------------------------------------*/ #include "iIstream.hpp" diff --git a/src/phasicFlow/streams/iStream/iIstream.hpp b/src/phasicFlow/streams/iStream/iIstream.hpp index f63c170f..90a2f81d 100755 --- a/src/phasicFlow/streams/iStream/iIstream.hpp +++ b/src/phasicFlow/streams/iStream/iIstream.hpp @@ -17,7 +17,6 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ - #ifndef __iIstream_hpp__ #define __iIstream_hpp__ @@ -30,25 +29,27 @@ namespace pFlow { /** - * Interface input stream class + * Interface class for any input stream * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs */ -class iIstream // interface class for input streams +class iIstream : public IOstream { - // Private Data + //- Private Data - /// Has a token been put back on the stream? - bool putBack_; + /// Has a token been put back on the stream? + bool putBack_; - /// The last token put back on the stream - token putBackToken_; + /// The last token put back on the stream + token putBackToken_; public: - ///// Constructors + ////- Constructors /// default iIstream(): @@ -69,7 +70,7 @@ public: - //// member methods + ////- member methods /// Put back token /// Only a single put back is permitted @@ -134,7 +135,7 @@ public: virtual void rewind() = 0; - ///// find and lookups + ////- find and lookups /// search for all tokesn and find the first word token tbat matchs w virtual bool findToken( const word & w ); @@ -231,8 +232,7 @@ inline iIstream& operator>>(iIstream& is, IOstreamManip f) } -// read operation for basic types it gets from the -// token stream +// read operation for basic types it gets from the token stream inline iIstream& operator>>( iIstream& is, word & w); inline iIstream& operator>>( iIstream& is, int64& val); @@ -259,4 +259,4 @@ inline iIstream& operator>>( iIstream& is, double& val); #include "iIstreamI.hpp" -#endif +#endif //__iIstream_hpp__ diff --git a/src/phasicFlow/streams/iStream/iOstream.hpp b/src/phasicFlow/streams/iStream/iOstream.hpp index 37540301..76141a01 100644 --- a/src/phasicFlow/streams/iStream/iOstream.hpp +++ b/src/phasicFlow/streams/iStream/iOstream.hpp @@ -17,17 +17,13 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ - - #ifndef __iOstream_hpp__ #define __iOstream_hpp__ -// based on OpenFOAM stream, with some modifications/simplifications -// to be tailored to our needs - #include "IOstream.hpp" +/// char constants to alter output format and color const inline char* defaultColor = "\033[0m"; const inline char* blackColor = "\033[30m"; const inline char* redColor = "\033[31m"; @@ -41,22 +37,25 @@ const inline char* whiteColor = "\033[37m"; const inline char* boldChar = "\033[1m"; - namespace pFlow { // Forward Declarations class token; - - +/** + * Interface class for any output stream. + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs + * + */ class iOstream : public IOstream { protected: - // Protected Data + //- Protected Data /// Indentation of the entry from the start of the keyword static constexpr const unsigned short entryIndentation_ = 16; @@ -71,7 +70,7 @@ protected: public: - // Constructors + ////- Constructors /// Default explicit iOstream() @@ -89,7 +88,7 @@ public: virtual ~iOstream() = default; - /// Write Functions + ////- Write Functions /// Write token to stream or otherwise handle it. /// return false if the token type was not handled by this method @@ -140,7 +139,7 @@ public: virtual iOstream& write(const char* binaryData, std::streamsize count) = 0; - // - Indent + //// - Indent /// Add indentation characters virtual void indent() = 0; @@ -178,7 +177,7 @@ public: /// Decrement the indent level void decrIndent(); - //- Punctuations + ////- Punctuations /// Write begin block group with a name /// Increments indentation, adds newline. @@ -231,7 +230,7 @@ public: } - //- Stream state functions + ////- Stream state functions /// Flush stream virtual void flush() = 0; @@ -258,7 +257,7 @@ public: virtual int precision(const int p) = 0; - //- Member Operators + ////- Member Operators /// Return a non-const reference to const iOstream /// Needed for write functions where the stream argument is temporary: @@ -411,16 +410,14 @@ inline iOstream& operator<<( iOstream& os, const double& val) { return os.write(val); } + // Useful aliases for tab and newline characters constexpr char tab = '\t'; constexpr char nl = '\n'; - - } // pFlow #endif -// ************************************************************************* // diff --git a/src/phasicFlow/streams/masterOstream/masterOstream.cpp b/src/phasicFlow/streams/masterOstream/masterOstream.cpp new file mode 100755 index 00000000..6c02c7a2 --- /dev/null +++ b/src/phasicFlow/streams/masterOstream/masterOstream.cpp @@ -0,0 +1,178 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ + + +#include "masterOstream.hpp" +#include "token.hpp" + + +pFlow::masterOstream::masterOstream +( + std::ostream& os, + const word& streamName +) +: + Ostream(os, streamName, writeFormat::ASCII) +{} + + +pFlow::iOstream& pFlow::masterOstream::write(const char c) +{ + if(showOutput()) + { + Ostream::write(c); + } + return *this; +} + + +pFlow::iOstream& pFlow::masterOstream::write(const char* str) +{ + if(showOutput()) + { + Ostream::write(str); + } + return *this; +} + + +pFlow::iOstream& pFlow::masterOstream::write(const word& str) +{ + if(showOutput()) + { + Ostream::write(str); + } + return *this; +} + + +pFlow::iOstream& pFlow::masterOstream::writeQuoted +( + const word& str, + const bool quoted +) +{ + if(showOutput()) + { + Ostream::writeQuoted(str, quoted); + } + return *this; +} + + + +pFlow::iOstream& pFlow::masterOstream::write(const int64 val) +{ + if(showOutput()) + { + Ostream::write(val); + } + return *this; +} + + +pFlow::iOstream& pFlow::masterOstream::write(const int32 val) +{ + if(showOutput()) + { + Ostream::write(val); + } + return *this; +} + + +pFlow::iOstream& pFlow::masterOstream::write(const int8 val) +{ + if(showOutput()) + { + Ostream::write(val); + } + return *this; +} + +pFlow::iOstream& pFlow::masterOstream::write(const uint64 val) +{ + if(showOutput()) + { + Ostream::write(val); + } + return *this; +} + +pFlow::iOstream& pFlow::masterOstream::write(const uint32 val) +{ + if(showOutput()) + { + Ostream::write(val); + } + return *this; +} + +pFlow::iOstream& pFlow::masterOstream::write(const uint8 val) +{ + if(showOutput()) + { + Ostream::write(val); + } + return *this; +} + +pFlow::iOstream& pFlow::masterOstream::write(const float val) +{ + if(showOutput()) + { + Ostream::write(val); + } + return *this; +} + + +pFlow::iOstream& pFlow::masterOstream::write(const double val) +{ + if(showOutput()) + { + Ostream::write(val); + } + return *this; +} + + +pFlow::iOstream& pFlow::masterOstream::write +( + const char* binaryData, + std::streamsize count +) +{ + if(showOutput()) + { + Ostream::write(binaryData, count); + } + return *this; +} + + +void pFlow::masterOstream::indent() +{ + + if(showOutput()) + { + Ostream::indent(); + } +} \ No newline at end of file diff --git a/src/phasicFlow/streams/masterOstream/masterOstream.hpp b/src/phasicFlow/streams/masterOstream/masterOstream.hpp new file mode 100755 index 00000000..6568bb0d --- /dev/null +++ b/src/phasicFlow/streams/masterOstream/masterOstream.hpp @@ -0,0 +1,123 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ +#ifndef __masterOstream_hpp__ +#define __masterOstream_hpp__ + +#include "Ostream.hpp" + +namespace pFlow +{ + +/** + * Output stream for MPI parallel run, when we need to + * know which the processor number in the output line. + * The processor number is shown as a prefix for the output line. + * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs. + */ +class masterOstream +: + public Ostream +{ +protected: + + /// Print prefix? + bool isThisMaster_ = true; + + + inline bool showOutput() const + { + return isThisMaster_; + } + +public: + + //// - Constructors + + /// From components + masterOstream(std::ostream& os, const word& streamName); + + /// No copy construct + masterOstream(const masterOstream&) = delete; + + /// No copy assignment + void operator=(const masterOstream&) = delete; + + + + //// - Methods + void setMasterSlave(bool master) + { + isThisMaster_ = master; + } + + /// Write character + iOstream& write(const char c)override; + + /// Write character string + iOstream& write(const char* str)override; + + /// Write word + iOstream& write(const word& str)override; + + /// Write std::string surrounded by quotes. + // Optional write without quotes. + iOstream& writeQuoted ( const word& str, const bool quoted=true ) override; + + /// Write int64 + iOstream& write(const int64 val) override; + + /// Write int32 + iOstream& write(const int32 val) override; + + /// Write int32 + iOstream& write(const int8 val) override; + + /// Write uint64 + iOstream& write(const uint64 val) override; + + /// Write uint32 + iOstream& write(const uint32 val) override; + + /// Write uint8 + iOstream& write(const uint8 val) override; + + /// Write float + iOstream& write(const float val) override; + + /// Write double + iOstream& write(const double val) override; + + /// Write a block of binray data + iOstream& write(const char* binaryData, std::streamsize count) override; + + /// Add indentation characters + void indent() override; + + +}; // masterOstream + + + +} // pFlow + + +#endif // __masterOstream_hpp__ diff --git a/src/phasicFlow/streams/processorOstream/processorOstream.cpp b/src/phasicFlow/streams/processorOstream/processorOstream.cpp new file mode 100755 index 00000000..5f39d158 --- /dev/null +++ b/src/phasicFlow/streams/processorOstream/processorOstream.cpp @@ -0,0 +1,153 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ + +#include + +#include "processorOstream.hpp" +#include "token.hpp" + + +pFlow::processorOstream::processorOstream +( + std::ostream& os, + const word& streamName +) +: + Ostream(os, streamName, writeFormat::ASCII) +{} + + +pFlow::iOstream& pFlow::processorOstream::write(const char c) +{ + checkForPrefix(); + Ostream::write(c); + + if (c == token::NL) + { + printPrefix_ = true; + } + + return *this; + +} + + +pFlow::iOstream& pFlow::processorOstream::write(const char* str) +{ + checkForPrefix(); + Ostream::write(str); + + size_t len = std::strlen(str); + if (len && str[len-1] == token::NL) + { + printPrefix_ = true; + } + + return *this; +} + + +pFlow::iOstream& pFlow::processorOstream::write(const word& str) +{ + checkForPrefix(); + return Ostream::write(str); +} + + +pFlow::iOstream& pFlow::processorOstream::writeQuoted +( + const word& str, + const bool quoted +) +{ + checkForPrefix(); + return Ostream::writeQuoted(str, quoted); +} + + + +pFlow::iOstream& pFlow::processorOstream::write(const int64 val) +{ + checkForPrefix(); + return Ostream::write(val); +} + + +pFlow::iOstream& pFlow::processorOstream::write(const int32 val) +{ + checkForPrefix(); + return Ostream::write(val); +} + + +pFlow::iOstream& pFlow::processorOstream::write(const int8 val) +{ + checkForPrefix(); + return Ostream::write(val); +} + +pFlow::iOstream& pFlow::processorOstream::write(const uint64 val) +{ + checkForPrefix(); + return Ostream::write(val); +} + +pFlow::iOstream& pFlow::processorOstream::write(const uint32 val) +{ + checkForPrefix(); + return Ostream::write(val); +} + +pFlow::iOstream& pFlow::processorOstream::write(const uint8 val) +{ + checkForPrefix(); + return Ostream::write(val); +} + +pFlow::iOstream& pFlow::processorOstream::write(const float val) +{ + checkForPrefix(); + return Ostream::write(val); +} + + +pFlow::iOstream& pFlow::processorOstream::write(const double val) +{ + checkForPrefix(); + return Ostream::write(val); +} + + +pFlow::iOstream& pFlow::processorOstream::write +( + const char* binaryData, + std::streamsize count +) +{ + checkForPrefix(); + return Ostream::write(binaryData, count); +} + + +void pFlow::processorOstream::indent() +{ + checkForPrefix(); + Ostream::indent(); +} diff --git a/src/phasicFlow/streams/processorOstream/processorOstream.hpp b/src/phasicFlow/streams/processorOstream/processorOstream.hpp new file mode 100755 index 00000000..6f6dd7e6 --- /dev/null +++ b/src/phasicFlow/streams/processorOstream/processorOstream.hpp @@ -0,0 +1,139 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ +#ifndef __processorOstream_hpp__ +#define __processorOstream_hpp__ + +#include "Ostream.hpp" + +namespace pFlow +{ + +/** + * Output stream for MPI parallel run, when we need to + * know which the processor number in the output line. + * The processor number is shown as a prefix for the output line. + * + * It is based on OpenFOAM stream, with some modifications/simplifications + * to be tailored to our needs. + */ +class processorOstream +: + public Ostream +{ +protected: + + /// Print prefix? + bool printPrefix_ = false; + + /// Prefix word + word prefix_ = ""; + + /// Output the prefix if required. + inline + void checkForPrefix() + { + if(printPrefix_ && prefix_.size()) + { + Ostream::write(prefix_.c_str()); + printPrefix_ = false; + } + } + +public: + + //// - Constructors + + /// From components + processorOstream(std::ostream& os, const word& streamName); + + /// No copy construct + processorOstream(const processorOstream&) = delete; + + /// No copy assignment + void operator=(const processorOstream&) = delete; + + + //// - Methods + + /// Set processor number to be used in the prefix. + word setPrefixNum(int procNum) + { + prefix_ = word("[")+int322Word(procNum)+word("] "); + return prefix_; + } + + /// Activate prefix for this stream. + void activatePrefix() + { + printPrefix_ = true; + } + + /// Write character + iOstream& write(const char c)override; + + /// Write character string + iOstream& write(const char* str)override; + + /// Write word + iOstream& write(const word& str)override; + + /// Write std::string surrounded by quotes. + // Optional write without quotes. + iOstream& writeQuoted ( const word& str, const bool quoted=true ) override; + + /// Write int64 + iOstream& write(const int64 val) override; + + /// Write int32 + iOstream& write(const int32 val) override; + + /// Write int32 + iOstream& write(const int8 val) override; + + /// Write uint64 + iOstream& write(const uint64 val) override; + + /// Write uint32 + iOstream& write(const uint32 val) override; + + /// Write uint8 + iOstream& write(const uint8 val) override; + + /// Write float + iOstream& write(const float val) override; + + /// Write double + iOstream& write(const double val) override; + + /// Write a block of binray data + iOstream& write(const char* binaryData, std::streamsize count) override; + + /// Add indentation characters + void indent() override; + + +}; // processorOstream + + + +} // pFlow + + +#endif // __processorOstream_hpp__ diff --git a/src/phasicFlow/streams/streams.cpp b/src/phasicFlow/streams/streams.cpp index 337b7e81..12ad3690 100755 --- a/src/phasicFlow/streams/streams.cpp +++ b/src/phasicFlow/streams/streams.cpp @@ -3,6 +3,11 @@ pFlow::Ostream pFlow::output(std::cout, "pFlow Ostream"); +pFlow::masterOstream pFlow::mOutput(cout, "pFlow masterOstream"); + +pFlow::processorOstream pFlow::pOutput(cout, "pFlow processorOstream"); + pFlow::Istream pFlow::input( std::cin, "sFlow Istream"); -pFlow::Ostream pFlow::errReport( std::cerr, "pFlow error report stream"); +pFlow::masterOstream pFlow::errReport( std::cerr, "pFlow error report stream"); + diff --git a/src/phasicFlow/streams/streams.hpp b/src/phasicFlow/streams/streams.hpp index de60dc6f..c4808d1b 100755 --- a/src/phasicFlow/streams/streams.hpp +++ b/src/phasicFlow/streams/streams.hpp @@ -13,38 +13,44 @@ #include "iTstream.hpp" +#include "processorOstream.hpp" + +#include "masterOstream.hpp" + namespace pFlow { - extern Ostream output; + extern masterOstream mOutput; + + extern processorOstream pOutput; + extern Istream input; - extern Ostream errReport; - + extern masterOstream errReport; } -#define redText(text) redColor< INFO: "< INFO: "< WARNING\n"< WARNING\n"< ERROR\n"< ERROR\n"<(val); } +inline pFlow::token::token(const uint8 val, int32 lineNumber) +: + data_(), + type_(tokenType::INT64), + lineNumber_(lineNumber) +{ + data_.int64Val = static_cast(val); +} + inline pFlow::token::token(const int64 val, int32 lineNumber) : data_(), @@ -180,6 +189,15 @@ inline pFlow::token::token(const int32 val, int32 lineNumber) data_.int64Val = static_cast(val); } +inline pFlow::token::token(const int8 val, int32 lineNumber) +: + data_(), + type_(tokenType::INT64), + lineNumber_(lineNumber) +{ + data_.int64Val = static_cast(val); +} + inline pFlow::token::token(const float val, int32 lineNumber) : data_(), diff --git a/src/phasicFlow/types/basicTypes/bTypesFunctions.cpp b/src/phasicFlow/types/basicTypes/bTypesFunctions.cpp index 29c3f99a..0e29b280 100755 --- a/src/phasicFlow/types/basicTypes/bTypesFunctions.cpp +++ b/src/phasicFlow/types/basicTypes/bTypesFunctions.cpp @@ -276,6 +276,17 @@ bool pFlow::readInt32( const char* buf, int32 & val) return readInt32(w, val); } +bool pFlow::readInt8( const word& w, int8 & val) +{ + try{ + val = std::stoi(w); + } + catch (...) + { + return false; + } + return true; +} bool pFlow::readInt8( const char* buf, int8 & val) {