diff --git a/src/phasicFlow/containers/Field/Field.hpp b/src/phasicFlow/containers/Field/Field.hpp index 405cf68e..887b994d 100644 --- a/src/phasicFlow/containers/Field/Field.hpp +++ b/src/phasicFlow/containers/Field/Field.hpp @@ -188,6 +188,11 @@ public: { this->fill(span, val); } + + void fillField(const T& val) + { + this->fill(val); + } //// - IO operations diff --git a/src/phasicFlow/containers/List/anyList/anyList.hpp b/src/phasicFlow/containers/List/anyList/anyList.hpp index 9ed114b1..b0d39405 100644 --- a/src/phasicFlow/containers/List/anyList/anyList.hpp +++ b/src/phasicFlow/containers/List/anyList/anyList.hpp @@ -51,7 +51,9 @@ protected: anyListType anyList_; /// List of variable names in anyList_ - wordList names_; + wordList names_; + + wordList types_; public: @@ -89,6 +91,7 @@ public: fatalExit; } names_.push_back(name); + types_.push_back(getTypeName()); return anyList_.emplace_back( std::in_place_type, std::forward(args)...); @@ -106,6 +109,7 @@ public: fatalExit; } names_.push_back(name); + types_.push_back(getTypeName()); return anyList_.emplace_back(std::in_place_type, other); } @@ -121,6 +125,7 @@ public: fatalExit; } names_.push_back(name); + types_.push_back(getTypeName()); return anyList_.emplace_back(std::in_place_type, std::move(other)); } diff --git a/src/phasicFlow/containers/Map/hashMap/hashMap.hpp b/src/phasicFlow/containers/Map/hashMap/hashMap.hpp index 1761b552..042800f5 100644 --- a/src/phasicFlow/containers/Map/hashMap/hashMap.hpp +++ b/src/phasicFlow/containers/Map/hashMap/hashMap.hpp @@ -43,6 +43,8 @@ public: using hashmapType = std::unordered_map; + using hasher = typename hashmapType::hasher; + using iterator = typename hashmapType::iterator; using constIterator = typename hashmapType::const_iterator; @@ -75,46 +77,24 @@ public: {} // - Copy construct - hashMap(const hashMapType & src) - : - hashmapType(src) - {} + hashMap(const hashMapType & src) = default; // - Move construct - hashMap( hashMapType&& src) - : - hashmapType(std::move(src)) - {} + hashMap( hashMapType&& src) = default; // - Copy assignment - hashMapType& operator=(const hashMapType& rhs) - { - hashmapType::operator=(rhs); - return *this; - } - + hashMapType& operator=(const hashMapType& rhs) = default; + // - Move assignment - hashMapType& operator=(hashMapType&& rhs) - { - hashmapType::operator=( std::move(rhs)); - return *this; - } - + hashMapType& operator=(hashMapType&& rhs) = default; + uniquePtr clone()const { return makeUnique(*this); } - hashMapType* clonePtr()const - { - return new hashMapType(*this); - } - - ~hashMap() - { - this->clear(); - } - + ~hashMap() = default; + //// - Methods diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.cpp b/src/phasicFlow/containers/VectorHD/VectorSingle.cpp index 0f9e4638..1ea576d2 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.cpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.cpp @@ -509,7 +509,7 @@ void pFlow::VectorSingle::assign template INLINE_FUNCTION_H -void pFlow::VectorSingle::assign(const VectorTypeHost& src) +void pFlow::VectorSingle::assignFromHost(const VectorTypeHost& src) { uint32 srcSize = src.size(); uint32 srcCap = src.capacity(); @@ -540,7 +540,45 @@ void pFlow::VectorSingle::assign(const VectorTypeHost& src) } } +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::assign +( + const VectorType& src, + bool srcCapacity +) +{ + uint32 srcSize = src.size(); + uint32 srcCap = src.capacity(); + + if(srcCapacity && srcCap != capacity()) + { + reallocateCapacitySize(srcCap, srcSize); + } + else + { + setSize(srcSize); + } + + if constexpr(isTriviallyCopyable_) + { + copy(deviceView(), src.deviceView()); + } + else if constexpr( isHostAccessible_) + { + for(auto i=0u; i +INLINE_FUNCTION_H void pFlow::VectorSingle::append ( const std::vector &appVec @@ -575,6 +613,41 @@ void pFlow::VectorSingle::append } +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::append +( + const VectorType& appVec +) +{ + uint32 appSize = appVec.size(); + if(appSize == 0) return; + + uint32 oldS = size(); + uint32 newSize = oldS + appSize; + + setSize(newSize); + auto appendView = Kokkos::subview( + view_, + Kokkos::make_pair(oldS, newSize)); + + if constexpr( isTriviallyCopyable_) + { + copy(appendView, appVec.deviceView()); + } + else if constexpr( isHostAccessible_) + { + for(auto i=0u; i INLINE_FUNCTION_H auto pFlow::VectorSingle::getSpan() { diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp index 1461503f..1243d501 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp @@ -284,10 +284,16 @@ public: /// The size of *this becomes the size of src. /// The capacity of *this becomes the capacity of src. INLINE_FUNCTION_H - void assign(const VectorTypeHost& src); + void assignFromHost(const VectorTypeHost& src); + + INLINE_FUNCTION_H + void assign(const VectorType& src, bool srcCapacity = true); INLINE_FUNCTION_H void append(const std::vector& appVec); + + INLINE_FUNCTION_H + void append(const VectorType& appVec); INLINE_FUNCTION_H auto getSpan(); diff --git a/src/phasicFlow/containers/pointField/boundaryField.cpp b/src/phasicFlow/containers/pointField/boundaryField/boundaryField.cpp similarity index 100% rename from src/phasicFlow/containers/pointField/boundaryField.cpp rename to src/phasicFlow/containers/pointField/boundaryField/boundaryField.cpp diff --git a/src/phasicFlow/containers/pointField/boundaryField.hpp b/src/phasicFlow/containers/pointField/boundaryField/boundaryField.hpp similarity index 92% rename from src/phasicFlow/containers/pointField/boundaryField.hpp rename to src/phasicFlow/containers/pointField/boundaryField/boundaryField.hpp index 9836599c..a0ad8a0e 100644 --- a/src/phasicFlow/containers/pointField/boundaryField.hpp +++ b/src/phasicFlow/containers/pointField/boundaryField/boundaryField.hpp @@ -52,10 +52,8 @@ protected: static inline const message defaultMessage_ = ( - message::CAP_CHANGED+ - message::SIZE_CHANGED+ - message::ITEM_INSERT+ - message::ITEM_DELETE + message::BNDR_RESET+ + message::BNDR_REARRANGE ); public: @@ -95,8 +93,16 @@ public: const anyList& varList ) override { - notImplementedFunction; - return false; + + if(msg.equivalentTo(message::BNDR_REARRANGE)) + { + // do nothing + } + if(msg.equivalentTo(message::BNDR_RESET)) + { + //do nothing + } + return true; } auto size()const diff --git a/src/phasicFlow/containers/pointField/createBoundaryFields.hpp b/src/phasicFlow/containers/pointField/boundaryField/createBoundaryFields.hpp similarity index 100% rename from src/phasicFlow/containers/pointField/createBoundaryFields.hpp rename to src/phasicFlow/containers/pointField/boundaryField/createBoundaryFields.hpp diff --git a/src/phasicFlow/containers/pointField/exitBoundaryField.cpp b/src/phasicFlow/containers/pointField/boundaryField/exitBoundaryField.cpp similarity index 100% rename from src/phasicFlow/containers/pointField/exitBoundaryField.cpp rename to src/phasicFlow/containers/pointField/boundaryField/exitBoundaryField.cpp diff --git a/src/phasicFlow/containers/pointField/exitBoundaryField.hpp b/src/phasicFlow/containers/pointField/boundaryField/exitBoundaryField.hpp similarity index 92% rename from src/phasicFlow/containers/pointField/exitBoundaryField.hpp rename to src/phasicFlow/containers/pointField/boundaryField/exitBoundaryField.hpp index dbc942d7..8c5fcb57 100644 --- a/src/phasicFlow/containers/pointField/exitBoundaryField.hpp +++ b/src/phasicFlow/containers/pointField/boundaryField/exitBoundaryField.hpp @@ -70,8 +70,14 @@ public: const anyList& varList ) override { - notImplementedFunction; - return false; + BoundaryFieldType::hearChanges(t,dt,iter, msg,varList); + + if(msg.equivalentTo(message::BNDR_DELETE)) + { + // do nothing; + } + + return true; } }; diff --git a/src/phasicFlow/containers/pointField/periodicBoundaryField.cpp b/src/phasicFlow/containers/pointField/boundaryField/periodicBoundaryField.cpp similarity index 100% rename from src/phasicFlow/containers/pointField/periodicBoundaryField.cpp rename to src/phasicFlow/containers/pointField/boundaryField/periodicBoundaryField.cpp diff --git a/src/phasicFlow/containers/pointField/periodicBoundaryField.hpp b/src/phasicFlow/containers/pointField/boundaryField/periodicBoundaryField.hpp similarity index 100% rename from src/phasicFlow/containers/pointField/periodicBoundaryField.hpp rename to src/phasicFlow/containers/pointField/boundaryField/periodicBoundaryField.hpp diff --git a/src/phasicFlow/containers/pointField/internalField.cpp b/src/phasicFlow/containers/pointField/internalField.cpp index d75c6d5f..99bd7860 100644 --- a/src/phasicFlow/containers/pointField/internalField.cpp +++ b/src/phasicFlow/containers/pointField/internalField.cpp @@ -98,6 +98,46 @@ typename pFlow::internalField::FieldTypeHost return aField; } +template +bool pFlow::internalField:: hearChanges +( + real t, + real dt, + uint32 iter, + const message& msg, + const anyList& varList +) +{ + if(msg.equivalentTo(message::CAP_CHANGED)) + { + auto newCap = varList.getObject( + message::eventName(message::CAP_CHANGED)); + + field_.reserve(newCap); + } + if(msg.equivalentTo(message::SIZE_CHANGED)) + { + auto newSize = varList.getObject( + message::eventName(message::SIZE_CHANGED)); + field_.resize(newSize); + } + if(msg.equivalentTo(message::ITEM_DELETE)) + { + // do nothing + } + if(msg.equivalentTo(message::ITEM_REARRANGE)) + { + notImplementedFunction; + return false; + } + if(msg.equivalentTo(message::ITEM_INSERT)) + { + notImplementedFunction; + return false; + } + return true; +} + template bool pFlow::internalField::write ( diff --git a/src/phasicFlow/containers/pointField/internalField.hpp b/src/phasicFlow/containers/pointField/internalField.hpp index d92fff0f..92ba1bf6 100644 --- a/src/phasicFlow/containers/pointField/internalField.hpp +++ b/src/phasicFlow/containers/pointField/internalField.hpp @@ -24,6 +24,7 @@ Licence: #include "Field.hpp" #include "observer.hpp" #include "dataIO.hpp" +#include "anyList.hpp" namespace pFlow @@ -59,6 +60,7 @@ protected: const message defaultMessage_ = ( message::CAP_CHANGED+ + message::SIZE_CHANGED+ message::ITEM_INSERT+ message::ITEM_REARRANGE+ message::ITEM_DELETE @@ -75,6 +77,11 @@ public: const internalPoints& internal, const T& val); + inline + const auto& deviceViewAll()const + { + return field_.deviceViewAll(); + } inline auto deviceView()const { @@ -166,11 +173,8 @@ public: uint32 iter, const message& msg, const anyList& varList - ) override - { - notImplementedFunction; - return false; - } + ) override; + //// - IO diff --git a/src/phasicFlow/containers/pointField/internalFieldAlgorithms.hpp b/src/phasicFlow/containers/pointField/internalFieldAlgorithms.hpp index 8f94bfb6..118fb21c 100644 --- a/src/phasicFlow/containers/pointField/internalFieldAlgorithms.hpp +++ b/src/phasicFlow/containers/pointField/internalFieldAlgorithms.hpp @@ -194,7 +194,58 @@ Pair minMax(const internalField& iField) } } +template +inline +void fillSequence(internalField& iField, const T& startVal) +{ + using exeSpace = typename internalField::execution_space; + using policy = Kokkos::RangePolicy< + exeSpace, + Kokkos::IndexType >; + + if constexpr(isDeviceAccessible()) + { + auto maskD = iField.activePointsMaskDevice(); + auto aRange = maskD.activeRange(); + auto field = iField.field().deviceViewAll(); + auto aPoints = maskD.getActivePoints(); + exclusiveScan(aPoints,0, aRange.end(), aPoints,0); + + Kokkos::parallel_for( + "internalField::fillSequence", + policy(aRange.start(), aRange.end() ), + LAMBDA_HD(uint32 i) + { + if(maskD(i)) + { + field[i] = aPoints[i]+startVal; + } + }); + Kokkos::fence(); + } + else + { + // this is a host view + auto maskH = iField.activePointsMaskHost(); + auto aRange = maskH.activeRange(); + auto field = iField.field().deviceViewAll(); + auto aPoints = maskH.getActivePoints(); + exclusiveScan(aPoints,0, aRange.end(), aPoints,0); + + Kokkos::parallel_for( + "internalField::fillSequence", + policy(aRange.start(), aRange.end() ), + LAMBDA_HD(uint32 i) + { + if(maskH(i)) + { + field[i] = aPoints[i]+startVal; + } + }); + Kokkos::fence(); + } +} } diff --git a/src/phasicFlow/containers/pointField/pointField.cpp b/src/phasicFlow/containers/pointField/pointField.cpp index 5b444402..0a6315ab 100644 --- a/src/phasicFlow/containers/pointField/pointField.cpp +++ b/src/phasicFlow/containers/pointField/pointField.cpp @@ -274,7 +274,7 @@ bool pFlow::pointField::readPointField return false; } - this->field_.assign(internal); + this->field_.assignFromHost(internal); return true; } diff --git a/src/phasicFlow/containers/pointField/pointFields.cpp b/src/phasicFlow/containers/pointField/pointFields.cpp index 09a979b1..f116e5ee 100644 --- a/src/phasicFlow/containers/pointField/pointFields.cpp +++ b/src/phasicFlow/containers/pointField/pointFields.cpp @@ -60,6 +60,14 @@ template class pFlow::pointField; createBaseBoundary(pFlow::uint32, void); createAllBoundary(pFlow::uint32, void); +template class pFlow::pointField; +createBaseBoundary(pFlow::uint64, pFlow::HostSpace); +createAllBoundary(pFlow::uint64, pFlow::HostSpace); + +template class pFlow::pointField; +createBaseBoundary(pFlow::uint64, void); +createAllBoundary(pFlow::uint64, void); + template class pFlow::pointField; createBaseBoundary(pFlow::real, pFlow::HostSpace); createAllBoundary(pFlow::real, pFlow::HostSpace); diff --git a/src/phasicFlow/containers/symArrayHD/symArrayHD.hpp b/src/phasicFlow/containers/symArrayHD/symArrayHD.hpp index d1d0ddd7..9c7d1a67 100644 --- a/src/phasicFlow/containers/symArrayHD/symArrayHD.hpp +++ b/src/phasicFlow/containers/symArrayHD/symArrayHD.hpp @@ -23,22 +23,11 @@ Licence: #include "KokkosTypes.hpp" - #include "types.hpp" #include "typeInfo.hpp" #include "Vector.hpp" -/* -stores the elemnt of a symetric array in the following order in a 1D vector - - 0 1 2 3 - 4 5 6 - 7 8 - 9 - -*/ - namespace pFlow { @@ -52,6 +41,15 @@ void SWAP(Type &x, Type& y) x = temp; } +/* +stores the elemnt of a symetric array in the following order in a 1D vector + + 0 1 2 3 + 4 5 6 + 7 8 + 9 + +*/ template class symArray { @@ -82,14 +80,14 @@ class symArray using execution_space = typename ViewType::execution_space; -protected: +private: - uint32 n_=0; + uint32 n_= 0; ViewType view_; - constexpr static inline const char* memoerySpaceName() + constexpr static const char* memoerySpaceName() { return memory_space::name(); } @@ -97,14 +95,14 @@ protected: public: // - type info - TypeInfoTemplateNV2("symArray", T, memoerySpaceName()); + TypeInfoTemplateNV111("symArray", T, memoerySpaceName()); //// constructors INLINE_FUNCTION_H symArray(); INLINE_FUNCTION_H - symArray(uint32 n) + explicit symArray(uint32 n) : symArray("symArray",n) {} @@ -125,7 +123,7 @@ public: } INLINE_FUNCTION_H - symArray(word name, Vector src) + symArray(word name, const Vector& src) : view_(name) { @@ -137,19 +135,19 @@ public: } } - INLINE_FUNCTION_H + INLINE_FUNCTION_HD symArray(const symArray&) = default; - INLINE_FUNCTION_H + INLINE_FUNCTION_HD symArray& operator=(const symArray&) = default; - INLINE_FUNCTION_H - symArray(symArray&&) = delete; + INLINE_FUNCTION_HD + symArray(symArray&&) = default; - INLINE_FUNCTION_H - symArray& operator=(symArray&&) = delete; + INLINE_FUNCTION_HD + symArray& operator=(symArray&&) = default; - INLINE_FUNCTION_H + INLINE_FUNCTION_HD ~symArray()=default; @@ -219,10 +217,10 @@ public: bool write(iOstream& os)const { - int32 s = numElem(n_); - Vector> vecToFile(s); + uint32 s = numElem(n_); + Vector vecToFile(view_.label(),s); - const auto dVec = Kokkos::subview(view_, kPair(0, s)); + const auto dVec = Kokkos::subview(view_, Pair(0, s)); hostViewType1D mirror(vecToFile.data(), vecToFile.size()); Kokkos::deep_copy(mirror,dVec); diff --git a/src/phasicFlow/containers/triSurfaceField/triSurfaceField.hpp b/src/phasicFlow/containers/triSurfaceField/triSurfaceField.hpp index 9659ab66..54c4c0db 100644 --- a/src/phasicFlow/containers/triSurfaceField/triSurfaceField.hpp +++ b/src/phasicFlow/containers/triSurfaceField/triSurfaceField.hpp @@ -130,6 +130,41 @@ public: field_.assign(vals, surface_.capacity()); } + inline + const auto& deviceViewAll()const + { + return field_.deviceViewAll(); + } + inline + auto deviceView()const + { + return field_.deviceView(); + } + + inline + auto hostView()const + { + return field_.hostView(); + } + + inline + const FieldType& field()const + { + return field_; + } + + inline + FieldType& field() + { + return field_; + } + + inline + void fill(const T& val) + { + field_.fillField(val); + } + bool hearChanges( real t, real dt,