diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ce683a4..e411fe79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,7 @@ add_subdirectory(src) #add_subdirectory(solvers) -#add_subdirectory(utilities) +add_subdirectory(utilities) #add_subdirectory(DEMSystems) add_subdirectory(testIO) diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index eb52ef39..2129f985 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -37,20 +37,35 @@ containers/Vector/Vectors.cpp containers/Field/Fields.cpp containers/List/anyList/anyList.cpp +Timer/Timer.cpp +Timer/Timers.cpp + repository/IOobject/objectFile.cpp repository/IOobject/IOfileHeader.cpp repository/IOobject/IOobject.cpp repository/IOobject/IOPattern.cpp +repository/repository/repository.cpp +repository/Time/Time.cpp +repository/Time/timeControl.cpp +repository/systemControl/systemControl.cpp +repository/systemControl/dynamicLinkLibs.cpp eventManagement/subscriber.cpp eventManagement/observer.cpp +structuredData/box/box.cpp structuredData/line/line.cpp structuredData/infinitePlane/infinitePlane.cpp structuredData/plane/plane.cpp structuredData/domain/domain.cpp +structuredData/domain/simulationDomain.cpp +structuredData/domain/regularSimulationDomain.cpp +structuredData/pointStructure/boundaryList.cpp structuredData/pointStructure/internalPoints.cpp +structuredData/pointStructure/pointStructure.cpp structuredData/boundaries/boundaryBase/boundaryBase.cpp +structuredData/boundaries/boundaryExit/boundaryExit.cpp + ) diff --git a/src/phasicFlow/containers/Field/Field.hpp b/src/phasicFlow/containers/Field/Field.hpp index d183b5c8..aafbfbd2 100644 --- a/src/phasicFlow/containers/Field/Field.hpp +++ b/src/phasicFlow/containers/Field/Field.hpp @@ -48,17 +48,17 @@ public: using iterator = typename VectorType::iterator; - using constIterator = typename VectorType::constIterator; + using const_iterator = typename VectorType::const_iterator; using reference = typename VectorType::reference; - using constReference = typename VectorType::constReference; + using const_reference = typename VectorType::const_reference; - using valueType = typename VectorType::valueType; + using value_type = typename VectorType::value_type; - using pointer = typename VectorType::pointer; + using pointer = typename VectorType::pointer; - using constPointer = typename VectorType::constPointer; + using const_pointer = typename VectorType::const_pointer; protected: diff --git a/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp b/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp index ed150eed..fe1f1850 100644 --- a/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp +++ b/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp @@ -30,7 +30,6 @@ Licence: #include "error.hpp" #include "iOstream.hpp" - namespace pFlow { @@ -91,7 +90,7 @@ public: // - a list with initial length of len ListPtr(size_t len) : - list_(len) + list_(len, nullptr) {} // - copy construct, create new objects out of the pointers in the src @@ -141,10 +140,10 @@ public: //// - Methods // - set the ith element - T* set(size_t i, T* ptr); + uniquePtr set(size_t i, T* ptr); // - set the ith element and take the ownership from uniquePtr - uniquePtr set(size_t i, uniquePtr& ptr ); + uniquePtr set(size_t i, uniquePtr&& ptr ); // - create the object in-place and set the pointer in ith position // if oject creation fails, uniquePtr deletes the memeory @@ -155,7 +154,7 @@ public: void push_back(T* ptr); // - put the pointer at the end - void push_back(uniquePtr& ptr); + void push_back(uniquePtr&& ptr); // - safely create (in-place) and put the pointer at the end template diff --git a/src/phasicFlow/containers/List/ListPtr/ListPtrI.hpp b/src/phasicFlow/containers/List/ListPtr/ListPtrI.hpp index 57f42c2b..77ef5a99 100644 --- a/src/phasicFlow/containers/List/ListPtr/ListPtrI.hpp +++ b/src/phasicFlow/containers/List/ListPtr/ListPtrI.hpp @@ -144,7 +144,7 @@ pFlow::ListPtr& pFlow::ListPtr::operator= } template -T* pFlow::ListPtr::set +pFlow::uniquePtr pFlow::ListPtr::set ( size_t i, T* ptr ) @@ -158,7 +158,7 @@ template pFlow::uniquePtr pFlow::ListPtr::set ( size_t i, - uniquePtr& ptr + uniquePtr&& ptr ) { if( i > size() ) @@ -171,10 +171,9 @@ pFlow::uniquePtr pFlow::ListPtr::set auto iter = list_.begin(); std::advance(iter, i); - auto oldIter = iter; + T* oldPtr = *iter; *iter = ptr.release(); - return *oldIter; - + return uniquePtr(oldPtr); } @@ -200,7 +199,7 @@ void pFlow::ListPtr::push_back } template -void pFlow::ListPtr::push_back(uniquePtr& ptr) +void pFlow::ListPtr::push_back(uniquePtr&& ptr) { list_.push_back( ptr.release() ); } @@ -271,17 +270,23 @@ pFlow::uniquePtr pFlow::ListPtr::release return p; } + + template void pFlow::ListPtr::clear() { + + int i =0; for( auto iter = list_.begin(); iter != list_.end(); ++iter ) { if(*iter != nullptr) { + delete *iter; *iter = nullptr; - } + } } + list_.clear(); } diff --git a/src/phasicFlow/containers/Vector/Vector.hpp b/src/phasicFlow/containers/Vector/Vector.hpp index b025a148..05275ce5 100644 --- a/src/phasicFlow/containers/Vector/Vector.hpp +++ b/src/phasicFlow/containers/Vector/Vector.hpp @@ -65,19 +65,19 @@ public: typedef typename vectorType::iterator iterator; - typedef typename vectorType::const_iterator constIterator; + typedef typename vectorType::const_iterator const_iterator; typedef typename vectorType::reference reference; - typedef typename vectorType::const_reference constReference; + typedef typename vectorType::const_reference const_reference; - typedef T valueType; + typedef T value_type; typedef T* pointer; - typedef const T* constPointer; + typedef const T* const_pointer; - typedef typename std::initializer_list initList; + typedef typename std::initializer_list init_list; protected: @@ -139,7 +139,7 @@ public: /// Vector from name and initializer list - inline Vector(const word& name, const initList &l) + inline Vector(const word& name, const init_list &l) : vectorType(l), name_(name) @@ -325,11 +325,25 @@ public: // - fill the whole content of vector, [begin, end), with val inline void fill( const T& val); + inline + auto getSpan() + { + return span(this->data(), this->size()); + } + + inline + auto getSpan()const + { + return span(this->data(), this->size()); + } + static constexpr bool isHostAccessible() { return isHostAccessible_; } + + inline void operator +=( const T& val); inline void operator -=( const T& val); inline void operator *=( const T& val); diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp index 46b461b3..4e3b3d2d 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp @@ -62,27 +62,27 @@ public: using iterator = T*; - using constIterator = const T*; + using const_iterator = const T*; using reference = T&; - using constReference = const T&; + using const_reference = const T&; - using valueType = T; + using value_type = T; using pointer = T*; - using constPointer = const T*; + using const_pointer = const T*; //- typedefs related to memory management using viewType = ViewType1D; - using deviceType = typename viewType::device_type; + using device_type = typename viewType::device_type; - using memorySpace = typename viewType::memory_space; + using memory_space = typename viewType::memory_space; - using executionSpace = typename viewType::execution_space; + using execution_space = typename viewType::execution_space; protected: @@ -102,19 +102,19 @@ protected: /// Is the memory of this vector accessible from Host static constexpr - bool isHostAccessible_ = isHostAccessible(); - //Kokkos::SpaceAccessibility::accessible; + bool isHostAccessible_ = isHostAccessible(); + //Kokkos::SpaceAccessibility::accessible; /// Is the memory of this vector accessiple from Divce static constexpr - bool isDeviceAccessible_ = isDeviceAccessible(); + bool isDeviceAccessible_ = isDeviceAccessible(); /// Name of the memory space constexpr static inline const char* memoerySpaceName() { - return memorySpace::name(); + return memory_space::name(); } /// Evaluate capacity based on the input size @@ -461,6 +461,17 @@ public: assign(src, src.capacity()); } + INLINE_FUNCTION_H + auto getSpan() + { + return span(view_.data(), size()); + } + + INLINE_FUNCTION_H + auto getSpan()const + { + return span(view_.data(), this->size()); + } INLINE_FUNCTION_H bool insertSetElement(uint32IndexContainer indices, const T& val); @@ -520,7 +531,7 @@ public: } INLINE_FUNCTION_H - constPointer data()const{ + const_pointer data()const{ return view_.data(); } @@ -535,7 +546,7 @@ public: /// Return begin iterator. it works when host is accessible. template INLINE_FUNCTION_H - typename std::enable_if_t + typename std::enable_if_t begin()const { return data(); } @@ -553,7 +564,7 @@ public: /// Return end iterator. it works when host is accessible. template INLINE_FUNCTION_H - typename std::enable_if_t + typename std::enable_if_t end()const{ return size_ > 0 ? data() + size_: data(); } @@ -569,7 +580,7 @@ public: /// Return reference to element i. it works when host is accessible. template INLINE_FUNCTION_H - typename std::enable_if_t + typename std::enable_if_t operator[](size_t i)const{ return view_[i]; } diff --git a/src/phasicFlow/containers/VectorHD/VectorSingleI.hpp b/src/phasicFlow/containers/VectorHD/VectorSingleI.hpp index 61217a96..2dabf14a 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingleI.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingleI.hpp @@ -32,7 +32,7 @@ bool pFlow::VectorSingle::insertSetElement(uint32IndexContainer i resize(maxInd+1); } - using policy = Kokkos::RangePolicy>; + using policy = Kokkos::RangePolicy>; if constexpr( isDeviceAccessible_ ) { @@ -88,7 +88,7 @@ bool pFlow::VectorSingle::insertSetElement resize(maxInd+1); } - using policy = Kokkos::RangePolicy>; + using policy = Kokkos::RangePolicy>; hostViewType1D hVals( vals.data(), vals.size()); @@ -153,7 +153,7 @@ bool pFlow::VectorSingle::reorderItems(uint32IndexContainer indic viewType sortedView(this->name(), newSize); - using policy = Kokkos::RangePolicy< executionSpace,Kokkos::IndexType>; + using policy = Kokkos::RangePolicy< execution_space,Kokkos::IndexType>; if constexpr( isDeviceAccessible_) { diff --git a/src/phasicFlow/dictionary/dictionary.cpp b/src/phasicFlow/dictionary/dictionary.cpp index a52d1d76..156f99a2 100644 --- a/src/phasicFlow/dictionary/dictionary.cpp +++ b/src/phasicFlow/dictionary/dictionary.cpp @@ -378,7 +378,8 @@ bool pFlow::dictionary::isFileDict()const bool pFlow::dictionary::addPtr ( const word& keyword, - uniquePtr& entry + uniquePtr& entry, + bool warning ) { @@ -390,9 +391,13 @@ bool pFlow::dictionary::addPtr // search all entries for repeated keyword if(auto [ptr, exist] = entries_.find(keyword); exist ) { - warningInFunction << - "keyword " << keyword << " already exists in the dicrionary " << - this->globalName() << ". The old entry will be replaced by the new one. \n"; + if(warning) + { + warningInFunction << + "keyword " << keyword << " already exists in the dicrionary " << + this->globalName() << ". The old entry will be replaced by the new one. \n"; + } + // store the old pointer to entry oldEntryPtr = ptr; } @@ -400,6 +405,7 @@ bool pFlow::dictionary::addPtr if( entries_.insertReplace(keyword, entry) ) { + if(oldEntryPtr) { // this should be replaced diff --git a/src/phasicFlow/dictionary/dictionary.hpp b/src/phasicFlow/dictionary/dictionary.hpp index 661882d5..fcd55ba4 100644 --- a/src/phasicFlow/dictionary/dictionary.hpp +++ b/src/phasicFlow/dictionary/dictionary.hpp @@ -175,9 +175,10 @@ public: /// if dictionary is file dictionary, return false virtual bool isFileDict()const; - /// add a pointer entry (dictionary/dataEntry) - // replaces this entry with existing one - bool addPtr(const word& keyword, uniquePtr& etry ); + /// @brief add a pointer entry (dictionary/dataEntry) + /// replaces this entry with existing one and issue a warning + bool addPtr(const word& keyword, uniquePtr& etry, bool warning = true ); + /// add a float dataEntry bool add(const word& keyword, const float& v); @@ -206,13 +207,16 @@ public: /// add a uint8 dataEntry bool add(const word& keyword, const uint8& v); - // add a dictionary with the specifiedd keyword + /// @brief add a dictionary with the specifiedd keyword, if + /// it exists, replace it. bool addDict(const word& keyword, const dictionary& dict); /// add a dataEntry of type T template bool add(const word& keyword, const T& v ); + template + bool addOrKeep(const word& keyword, const T& v); void clear(); @@ -311,6 +315,19 @@ bool dictionary::add(const word& keyword, const T& v ) } +template +bool dictionary::addOrKeep(const word& keyword, const T& v ) +{ + if(!containsDataEntry(keyword)) + { + uniquePtr ptr = makeUnique(keyword, *this ,v); + return addPtr(keyword, ptr); + } + + return true; +} + + template bool dictionary::readDataEntry ( diff --git a/src/phasicFlow/eventManagement/eventManagement.hpp b/src/phasicFlow/eventManagement/eventManagement.hpp new file mode 100644 index 00000000..3b07b2be --- /dev/null +++ b/src/phasicFlow/eventManagement/eventManagement.hpp @@ -0,0 +1,16 @@ +#ifndef __eventManagement_hpp__ +#define __eventManagement_hpp__ + +#include "subscriber.hpp" +#include "observer.hpp" +#include "pointMessage.hpp" + +namespace pFlow +{ + +using pointSubcriber = subscriber + +} + + +#endif \ No newline at end of file diff --git a/src/phasicFlow/eventManagement/subscriber.hpp b/src/phasicFlow/eventManagement/subscriber.hpp index 3c424a3a..48090597 100644 --- a/src/phasicFlow/eventManagement/subscriber.hpp +++ b/src/phasicFlow/eventManagement/subscriber.hpp @@ -40,11 +40,23 @@ protected: // - list of subsribed objectd that recieve updage messages mutable std::array,16> observerList_; + word subName_; + public: - subscriber() + subscriber(const word& name) + : + subName_(name) {} + subscriber(const subscriber&) = delete; + + subscriber(subscriber&&) = default; + + subscriber& operator = (const subscriber&) = delete; + + subscriber& operator = (subscriber&&) = default; + virtual ~subscriber(); virtual bool subscribe(message msg, observer* obsevr)const; @@ -55,6 +67,7 @@ public: //bool notify(const eventMessage& msg, const List& exclutionList ); + bool notify(const message msg, const anyList& varList); diff --git a/src/phasicFlow/globals/vocabs.hpp b/src/phasicFlow/globals/vocabs.hpp index 8ac68538..5afac001 100755 --- a/src/phasicFlow/globals/vocabs.hpp +++ b/src/phasicFlow/globals/vocabs.hpp @@ -37,6 +37,7 @@ const inline char* integrationFolder__ = "integration"; // file names const inline char* settingsFile__ = "settingsDict"; +const inline char* domainFile__ = "domainDict"; const inline char* insertionFile__ = "particleInsertion"; const inline char* sphereShapeFile__ = "sphereShape"; const inline char* pointStructureFile__ = "pStructure"; diff --git a/src/phasicFlow/processors/processors.hpp b/src/phasicFlow/processors/processors.hpp index 494787a6..98d9314c 100644 --- a/src/phasicFlow/processors/processors.hpp +++ b/src/phasicFlow/processors/processors.hpp @@ -95,6 +95,18 @@ public: return processors::globalSize()>1; } + static inline + const char* runTypeName() + { + if(isParallel()) + { + return "MPI"; + } + else + { + return "regular"; + } + } /// Is MPI initialized? static bool isInitialized(); diff --git a/src/phasicFlow/ranges/stridedRange.hpp b/src/phasicFlow/ranges/stridedRange.hpp index 5ecf7367..ca1cf7ba 100644 --- a/src/phasicFlow/ranges/stridedRange.hpp +++ b/src/phasicFlow/ranges/stridedRange.hpp @@ -76,9 +76,9 @@ public: stridedRange(const dictionary& dict) : - begin_(dict.getVal