From af2572331d769f6ed8c20bce556ccd1726f8e5c4 Mon Sep 17 00:00:00 2001 From: HRN Date: Fri, 31 Jan 2025 01:06:16 +0330 Subject: [PATCH] some cleanup --- src/phasicFlow/CMakeLists-old.txt | 87 ----------- src/phasicFlow/containers/span/span.hpp | 138 +++++++----------- src/phasicFlow/globals/error.cpp | 32 ++-- src/phasicFlow/globals/error.hpp | 16 +- .../repository/IOobject/objectFile.hpp | 2 +- .../types/basicTypes/bTypesFunctions.hpp | 2 +- .../types/basicTypes/builtinTypes.hpp | 38 +++-- src/phasicFlow/types/triple/triple.hpp | 4 +- src/phasicFlow/types/triple/tripleFwd.hpp | 6 +- src/phasicFlow/types/triple/tripleI.hpp | 10 +- 10 files changed, 112 insertions(+), 223 deletions(-) delete mode 100644 src/phasicFlow/CMakeLists-old.txt diff --git a/src/phasicFlow/CMakeLists-old.txt b/src/phasicFlow/CMakeLists-old.txt deleted file mode 100644 index b6b68815..00000000 --- a/src/phasicFlow/CMakeLists-old.txt +++ /dev/null @@ -1,87 +0,0 @@ - -list(APPEND SourceFiles -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/iIstream.cpp -streams/iStream/iOstream.cpp -streams/Stream/Istream.cpp -streams/Stream/Ostream.cpp -streams/Fstream/iFstream.cpp -streams/Fstream/oFstream.cpp -streams/Fstream/fileStream.cpp -streams/TStream/iTstream.cpp -streams/TStream/oTstream.cpp -streams/streams.cpp - -dictionary/dictionary.cpp -dictionary/entry/iEntry.cpp -dictionary/entry/dataEntry.cpp -dictionary/twoPartEntry/twoPartEntry.cpp - -fileSystem/fileSystem.cpp - -commandLine/commandLine.cpp - -random/randomReal/randomReal.cpp -random/randomReal/randomReals.cpp - -Timer/Timer.cpp -Timer/Timers.cpp - -repository/Time/Time.cpp -repository/Time/timeControl.cpp -repository/systemControl/systemControl.cpp -repository/systemControl/dynamicLinkLibs.cpp -repository/repository/repository.cpp -repository/IOobject/objectFile.cpp -repository/IOobject/IOobject.cpp -repository/IOobject/IOfileHeader.cpp - -structuredData/box/box.cpp -structuredData/cells/cells.cpp -structuredData/cylinder/cylinder.cpp -structuredData/sphere/sphere.cpp -structuredData/iBox/iBoxs.cpp -structuredData/line/line.cpp -structuredData/zAxis/zAxis.cpp -structuredData/pointStructure/pointStructure.cpp -structuredData/pointStructure/mortonIndexing.cpp -structuredData/pointStructure/selectors/pStructSelector/pStructSelector.cpp -structuredData/pointStructure/selectors/selectBox/selectBox.cpp -structuredData/pointStructure/selectors/selectRange/selectRange.cpp -structuredData/pointStructure/selectors/selectRandom/selectRandom.cpp -structuredData/trisurfaceStructure/triSurface.cpp -structuredData/trisurfaceStructure/multiTriSurface.cpp -structuredData/trisurfaceStructure/stlFile.cpp -structuredData/peakableRegion/sphereRegion/sphereRegion.cpp -structuredData/peakableRegion/cylinderRegion/cylinderRegion.cpp -structuredData/peakableRegion/boxRegion/boxRegion.cpp -structuredData/peakableRegion/peakableRegion/peakableRegion.cpp -structuredData/peakableRegion/peakableRegions.cpp - -containers/Vector/Vectors.cpp -containers/Field/Fields.cpp -containers/symArrayHD/symArrays.cpp -containers/triSurfaceField/triSurfaceFields.cpp -containers/bitsetHD/bitsetHDs.cpp -containers/indexContainer/indexContainer.cpp - -setFieldList/setFieldList.cpp -setFieldList/setFieldEntry.cpp - -eventSubscriber/eventSubscriber.cpp -eventSubscriber/eventObserver.cpp) - -set(link_libs Kokkos::kokkos tbb) - -pFlow_add_library_install(phasicFlow SourceFiles link_libs) - -target_include_directories(phasicFlow PUBLIC ./Kokkos ./algorithms ./globals) - diff --git a/src/phasicFlow/containers/span/span.hpp b/src/phasicFlow/containers/span/span.hpp index 91deb71f..879bcb84 100644 --- a/src/phasicFlow/containers/span/span.hpp +++ b/src/phasicFlow/containers/span/span.hpp @@ -26,60 +26,65 @@ Licence: namespace pFlow { - +/// +/// @class span +/// @brief Represents a view into a contiguous sequence of elements. +/// +/// `span` provides a lightweight way to work with arrays and other contiguous +/// sequences without the overhead of copying. This will word on both GPU and CPU template class span { - public: - - using iterator = T*; + + using iterator = T*; - using constIterator = const T*; - - using reference = T&; - - using constReference = const T&; + using constIterator = const T*; + + using reference = T&; + + using constReference = const T&; - using valueType = T; - - using pointer = T*; - - using constPointer = const T*; + using valueType = T; + + using pointer = T*; + + using constPointer = const T*; -protected: +private: - T* data_ = nullptr; - - uint32 size_ = 0; + mutable T* data_ = nullptr; + + index size_ = 0; public: TypeInfoTemplateNV11("span", T); - /// Constructor + /// Constructor with no arguments INLINE_FUNCTION_HD span() = default; + /// Constructor that takes a pointer to the beginning of the data and the size of the span INLINE_FUNCTION_HD span(T* data, uint32 size) : data_(data), size_(size) {} - /// copy + /// copy constructor INLINE_FUNCTION_HD span(const span&) = default; - /// assignment + /// copy assignment operator INLINE_FUNCTION_HD span& operator=(const span&) = default; - /// move + /// move constructor INLINE_FUNCTION_HD span(span&&) = default; - /// assignment + /// move assignment operator INLINE_FUNCTION_HD span& operator=(span&) = default; @@ -90,6 +95,7 @@ public: return size_ == 0; } + /// Returns a pointer to the beginning of the data INLINE_FUNCTION_HD T* data() const { @@ -98,7 +104,7 @@ public: /// Returns the number of elements in the span INLINE_FUNCTION_HD - uint32 size() const + index size() const { return size_; } @@ -110,7 +116,7 @@ public: return data_; } - /// Returns an iterator to the beginning of the span + /// Returns an iterator to the beginning of the span (const version) INLINE_FUNCTION_HD constIterator cbegin() const { @@ -124,93 +130,59 @@ public: return data_ + size_; } - /// Returns an iterator to one past the end of the span + /// Returns an iterator to one past the end of the span (const version) INLINE_FUNCTION_HD constIterator cend() const { return data_ + size_; } + /// Returns a reference to the element at the specified index INLINE_FUNCTION_HD - T& operator[](uint32 i) + T& operator[](index i) { - return data_[i]; + return data_[i]; } + /// Returns a const reference to the element at the specified index INLINE_FUNCTION_HD - const T& operator[](uint32 i)const + T& operator[](index i)const { - return data_[i]; - } - - INLINE_FUNCTION_HD - T& operator[](int32 i) - { - return data_[i]; - } - - INLINE_FUNCTION_HD - const T& operator[](int32 i)const - { - return data_[i]; + return data_[i]; } }; -/*template class Container> -size_t makeSpan(Container& container) -{ - return span(container.data(), container.size()); -} - -template class Container> -size_t makeSpan(const Container& container) -{ - return span( - const_cast(container.data()), - container.size()); -}*/ - +/// Creates a span of char from a span of any type. +/// +/// This helper function reinterprets the underlying memory of the given span +/// as a span of char. template inline span charSpan(span s) { - auto el = sizeof(T); - return span( - reinterpret_cast(s.data()), - s.size()*el); + auto el = sizeof(T); + return span( + reinterpret_cast(s.data()), + s.size()*el); } +/// Creates a span of const char from a span of const any type. +/// +/// This helper function reinterprets the underlying memory of the given span +/// as a span of const char. template inline span charSpan(span s) { - auto el = sizeof(T); - return span( - reinterpret_cast(s.data()), - s.size()*el); + auto el = sizeof(T); + return span( + reinterpret_cast(s.data()), + s.size()*el); } -/*template class Container> -span makeSpan(Container& container) -{ - return span(container.data(), container.size()); -} - -template class Container> -span makeSpan(const Container& container) -{ - return span( - const_cast(container.data()), - container.size()); -}*/ - - - - - } // pFlow -#endif //__span_hpp__ +#endif //__span_hpp__ \ No newline at end of file diff --git a/src/phasicFlow/globals/error.cpp b/src/phasicFlow/globals/error.cpp index 9135c69b..d9d7efc3 100644 --- a/src/phasicFlow/globals/error.cpp +++ b/src/phasicFlow/globals/error.cpp @@ -32,41 +32,35 @@ Licence: static pFlow::Ostream& errorStream = pFlow::pOutput; pFlow::iOstream& -fatalErrorMessage(const char* fileName, int linNumber) +pFlow::fatalErrorMessage(const char* fileName, int lineNumber) { - errorStream << "\n>>> Fatal error in phasicFlow\n" - << "Error occured in source file " << Red_Text(fileName) - << " at line " << Red_Text(linNumber) << '\n'; + errorStream << "\nError occured in file ("<>> Fatal error in phasicFlow\n" - << " Error is issued in function " << Red_Text(fnName) - << ", located in file " << Red_Text(fileName) << " at line " - << Red_Text(linNumber) << '\n'; + errorStream << "\nError occured in file ("<>> Fatal error in phasicFlow\n"; - errorStream << " Function " << Red_Text(fnName) + errorStream << "\n Function " << Yellow_Text(fnName) << " has not been implemented yet!\n" - << " File " << Yellow_Text(fileName) << " at line " - << Yellow_Text(lineNumber) << '\n'; + << " Look into file ("<>> Warning in phasicFlow\n" << " Warning is issued in function " << Yellow_Text(fnName) @@ -108,7 +102,7 @@ warningMessage(const char* fnName, const char* fileName, int linNumber) } pFlow::iOstream& -reportAndExit(int errorCode) +pFlow::reportAndExit(int errorCode) { errorStream << "\n>>> phasicFlow is exiting . . ." << pFlow::endl; fatalExitPhasicFlow(errorCode); @@ -116,7 +110,7 @@ reportAndExit(int errorCode) } int -fatalExitPhasicFlow(int errorCode) +pFlow::fatalExitPhasicFlow(int errorCode) { // Kokkos should be finalized first Kokkos::finalize(); diff --git a/src/phasicFlow/globals/error.hpp b/src/phasicFlow/globals/error.hpp index 7e16d379..f658e465 100644 --- a/src/phasicFlow/globals/error.hpp +++ b/src/phasicFlow/globals/error.hpp @@ -27,7 +27,7 @@ Licence: namespace pFlow { class iOstream; -} + //- Decleartions @@ -66,35 +66,37 @@ warningMessage(const char* fnName, const char* fileName, int linNumber); pFlow::iOstream& reportAndExit(int errorCode = EXIT_FAILURE); +} + /// Report a fatal error and exit the applicaiton -#define fatalError fatalErrorMessage(__FILE__, __LINE__) +#define fatalError pFlow::fatalErrorMessage(__FILE__, __LINE__) /// Report a fatal error and supplied function name and exit the application #define fatalErrorIn(functionName) \ - fatalErrorInMessage((functionName), __FILE__, __LINE__) + pFlow::fatalErrorInMessage((functionName), __FILE__, __LINE__) /// Report a fatal error and function name and exit the application #define fatalErrorInFunction fatalErrorIn(FUNCTION_NAME) /// Report that a function is yet not implemented with supplied function name. #define Not_Implemented(functionName) \ - notImplementedErrorMessage((functionName), __FILE__, __LINE__) + pFlow::notImplementedErrorMessage((functionName), __FILE__, __LINE__) /// Report that a function is yet not implemented. #define notImplementedFunction Not_Implemented(FUNCTION_NAME) /// Report an error in file operation with supplied fileName and lineNumber. #define ioErrorInFile(fileName, lineNumber) \ - ioErrorMessage(fileName, lineNumber, FUNCTION_NAME, __FILE__, __LINE__) + pFlow::ioErrorMessage(fileName, lineNumber, FUNCTION_NAME, __FILE__, __LINE__) /// Report a warning with supplied function name #define warningIn(functionName) \ - warningMessage((functionName), __FILE__, __LINE__) + pFlow::warningMessage((functionName), __FILE__, __LINE__) /// Report a warning #define warningInFunction warningIn(FUNCTION_NAME) /// Fatal exit -#define fatalExit reportAndExit() +#define fatalExit pFlow::reportAndExit() #endif diff --git a/src/phasicFlow/repository/IOobject/objectFile.hpp b/src/phasicFlow/repository/IOobject/objectFile.hpp index ee0cf85a..c0bb281b 100644 --- a/src/phasicFlow/repository/IOobject/objectFile.hpp +++ b/src/phasicFlow/repository/IOobject/objectFile.hpp @@ -60,7 +60,7 @@ private: fileSystem localPath_ = ""; /// Number of bytes used for writing/reading real variable (used for binray) - int numBytesForReal_ = numBytesForReal__; + int numBytesForReal_ = sizeof(real); /// Does the objectFile read & write the header? bool readWriteHeader_ = true; diff --git a/src/phasicFlow/types/basicTypes/bTypesFunctions.hpp b/src/phasicFlow/types/basicTypes/bTypesFunctions.hpp index 764866d2..87f0408a 100755 --- a/src/phasicFlow/types/basicTypes/bTypesFunctions.hpp +++ b/src/phasicFlow/types/basicTypes/bTypesFunctions.hpp @@ -277,7 +277,7 @@ equal(const uint32& s1, const uint32& s2) } /// Are two words equal (host only)? -INLINE_FUNCTION +inline bool equal(const word& s1, const word& s2) { diff --git a/src/phasicFlow/types/basicTypes/builtinTypes.hpp b/src/phasicFlow/types/basicTypes/builtinTypes.hpp index ab8673ed..be3d5647 100755 --- a/src/phasicFlow/types/basicTypes/builtinTypes.hpp +++ b/src/phasicFlow/types/basicTypes/builtinTypes.hpp @@ -29,20 +29,22 @@ namespace pFlow { #ifdef pFlow_Build_Double -#define useDouble 1 -inline const char* floatingPointType__ = "double"; -inline const bool usingDouble__ = true; + #define UseDouble 1 + inline const char* floatingPointType__ = "double"; + inline const bool usingDouble__ = true; #else -#define useDouble 0 -inline const char* floatingPointType__ = "float"; -inline const bool usingDouble__ = false; + #define UseDouble 0 + inline const char* floatingPointType__ = "float"; + inline const bool usingDouble__ = false; #endif + + // scalars -#if useDouble -using real = double; +#if UseDouble + using real = double; #else -using real = float; + using real = float; #endif using int8 = signed char; @@ -57,21 +59,27 @@ using uint32 = unsigned int; using uint64 = unsigned long long int; -using id_t = uint32; - -using size_t = std::size_t; - using word = std::string; using timeValue = double; -inline const int numBytesForReal__ = sizeof(real); +#ifdef pFlow_Build_Index64 + #define Index64 1 + using index = std::size_t; + inline const char* IndexType__ = "std::size_t"; +#else + #define Index64 0 + using index = uint32; + inline const char* IndexType__ = "uint32"; +#endif + inline word floatingPointDescription() { return word("In this build, ") + word(floatingPointType__) + - word(" is used for floating point operations."); + word(" is used for floating point operations and ") + + IndexType__ + "for indexing."; } } // end of pFlow diff --git a/src/phasicFlow/types/triple/triple.hpp b/src/phasicFlow/types/triple/triple.hpp index 8b6735af..64662aa6 100644 --- a/src/phasicFlow/types/triple/triple.hpp +++ b/src/phasicFlow/types/triple/triple.hpp @@ -114,13 +114,13 @@ struct triple triple& operator=(triple&& src) = default; /// clone - INLINE_FUNCTION + inline uniquePtr> clone() const { return makeUnique>(*this); } - INLINE_FUNCTION + inline triple* clonePtr() const { return new triple(*this); diff --git a/src/phasicFlow/types/triple/tripleFwd.hpp b/src/phasicFlow/types/triple/tripleFwd.hpp index e9d36b0e..90e638c2 100644 --- a/src/phasicFlow/types/triple/tripleFwd.hpp +++ b/src/phasicFlow/types/triple/tripleFwd.hpp @@ -103,13 +103,13 @@ INLINE_FUNCTION_HD bool operator>=(const triple& opr1, const triple& opr2); template -INLINE_FUNCTION iOstream& +inline iOstream& operator<<(iOstream& str, const triple& ov); template -INLINE_FUNCTION iIstream& +inline iIstream& operator>>(iIstream& str, triple& iv); template -INLINE_FUNCTION void +inline void readIstream(iIstream& str, triple& iv); \ No newline at end of file diff --git a/src/phasicFlow/types/triple/tripleI.hpp b/src/phasicFlow/types/triple/tripleI.hpp index b829d56e..6b630cc2 100644 --- a/src/phasicFlow/types/triple/tripleI.hpp +++ b/src/phasicFlow/types/triple/tripleI.hpp @@ -287,8 +287,8 @@ pFlow::operator>=(const triple& opr1, const triple& opr2) } template -INLINE_FUNCTION pFlow::iOstream& - pFlow::operator<<(iOstream& str, const triple& ov) +inline pFlow::iOstream& + pFlow::operator<<(iOstream& str, const triple& ov) { str << token::BEGIN_LIST << ov.x_ << token::SPACE << ov.y_ << token::SPACE << ov.z_ << token::END_LIST; @@ -299,8 +299,8 @@ INLINE_FUNCTION pFlow::iOstream& } template -INLINE_FUNCTION pFlow::iIstream& - pFlow::operator>>(iIstream& str, triple& iv) +inline pFlow::iIstream& + pFlow::operator>>(iIstream& str, triple& iv) { str.readBegin("triple"); @@ -316,7 +316,7 @@ INLINE_FUNCTION pFlow::iIstream& } template -INLINE_FUNCTION void +inline void pFlow::readIstream(iIstream& str, triple& iv) { str.readBegin("triple");