From 6b3a4f017b8279d57b3fad86cce7af04161462a1 Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Sun, 24 Mar 2024 02:02:48 -0700 Subject: [PATCH] structured data has been modified for new changes in version (1.0) --- .../boundaries/boundaryBase/boundaryBase.cpp | 87 ++++++++----------- .../boundaries/boundaryBase/boundaryBase.hpp | 16 ++-- .../boundaryBase/boundaryBaseKernels.cpp | 63 ++++++++------ .../boundaryBase/boundaryBaseKernels.hpp | 16 ++-- .../boundaries/boundaryExit/boundaryExit.cpp | 15 ++-- .../boundaries/boundaryExit/boundaryExit.hpp | 4 +- .../boundaries/boundaryList.cpp | 20 ++++- .../boundaries/boundaryNone/boundaryNone.cpp | 6 +- .../boundaries/boundaryNone/boundaryNone.hpp | 4 +- .../boundaryPeriodic/boundaryPeriodic.cpp | 13 +-- .../boundaryPeriodic/boundaryPeriodic.hpp | 6 +- .../domain/simulationDomain.cpp | 2 +- src/phasicFlow/structuredData/iBox/iBox.hpp | 2 +- .../pointStructure/internalPoints.cpp | 54 ++++++++++-- .../pointStructure/internalPoints.hpp | 9 +- .../pointStructure/pointFlag.hpp | 3 + .../pointStructure/pointFlagKernels.hpp | 31 ++++++- .../pointStructure/pointStructure.cpp | 17 +++- .../pointStructure/pointStructure.hpp | 16 ++-- 19 files changed, 251 insertions(+), 133 deletions(-) diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp index d6821ca9..503095a3 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp @@ -21,57 +21,25 @@ Licence: #include "boundaryBase.hpp" #include "dictionary.hpp" #include "internalPoints.hpp" - +#include "anyList.hpp" +#include "Time.hpp" #include "boundaryBaseKernels.hpp" -/*pFlow::boundaryBase::boundaryBase -( - const plane& bplane, - uint32 mirrorProc, - const word& name, - const word& type, - internalPoints& internal -) -: - subscriber(groupNames(name,type)), - boundaryPlane_(bplane), - name_(name), - type_(type), - mirrorProcessoNo_(mirrorProc), - internal_(internal) -{ - -}*/ void pFlow::boundaryBase::setNewIndices ( - deviceViewType1D newIndices + const uint32Vector_D& newIndices ) { - auto newSize = newIndices.size(); - setSize(static_cast(newSize)); - if(newSize>0u) - { - copy(indexList_.deviceView(), newIndices); - } + indexList_.assign(newIndices, false); } void pFlow::boundaryBase::appendNewIndices ( - deviceViewType1D newIndices + const uint32Vector_D& newIndices ) { - auto s = static_cast(newIndices.size()); - if(s == 0) return; - - uint32 oldS = size(); - uint32 newSize = oldS + s; - - setSize(newSize); - auto appendView = Kokkos::subview( - indexList_.deviceViewAll(), - Kokkos::make_pair(oldS, newSize)); - copy(appendView, newIndices); + indexList_.append(newIndices); // TODO: notify observers about this change @@ -79,12 +47,10 @@ void pFlow::boundaryBase::appendNewIndices //sort(indexList_.deviceViewAll(), 0, newSize); } - - bool pFlow::boundaryBase::removeIndices ( uint32 numRemove, - deviceViewType1D removeMask + const uint32Vector_D& removeMask ) { if(removeMask.size() != size()+1 ) @@ -93,12 +59,12 @@ bool pFlow::boundaryBase::removeIndices return false; } - deviceViewType1D removeIndices("removeIndices", 1); - deviceViewType1D keepIndices("keepIndices",1); + uint32Vector_D removeIndices("removeIndices"); + uint32Vector_D keepIndices("keepIndices"); pFlow::boundaryBaseKernels::createRemoveKeepIndices ( - indexList_.deviceView(), + indexList_, numRemove, removeMask, removeIndices, @@ -114,15 +80,32 @@ bool pFlow::boundaryBase::removeIndices setNewIndices(keepIndices); - //TODO: notify observers about changes + anyList aList; + + aList.emplaceBack( + message::eventName(message::BNDR_RESET), + std::move(keepIndices)); + + message msgBndry = message::BNDR_RESET; - return false; + uint32 iter = internal_.time().currentIter(); + real t = internal_.time().currentTime(); + real dt = internal_.time().dt(); + + if( !this->notify(iter, t, dt, msgBndry, aList) ) + { + fatalErrorInFunction<<"Error in notify operation in boundary "<< + name_ < transferMask, + const uint32Vector_D& transferMask, uint32 transferBoundaryIndex, realx3 transferVector ) @@ -133,12 +116,12 @@ bool pFlow::boundaryBase::transferPoints return false; } - deviceViewType1D transferIndices("transferIndices",1); - deviceViewType1D keepIndices("keepIndices",1); + uint32Vector_D transferIndices("transferIndices"); + uint32Vector_D keepIndices("keepIndices"); pFlow::boundaryBaseKernels::createRemoveKeepIndices ( - indexList_.deviceView(), + indexList_, numTransfer, transferMask, transferIndices, @@ -150,7 +133,7 @@ bool pFlow::boundaryBase::transferPoints // first, change the flags in the internalPoints if( !internal_.changePointsFlag( - transferIndices, + transferIndices.deviceView(), transferBoundaryIndex) ) { return false; @@ -158,7 +141,7 @@ bool pFlow::boundaryBase::transferPoints // second, change the position of points if(!internal_.changePointsPoisition( - transferIndices, + transferIndices.deviceView(), transferVector)) { return false; diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp index 038114e7..d55875c6 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp @@ -53,6 +53,10 @@ private: /// list of particles indices on device uint32Vector_D indexList_; + uint32Vector_H indexListH_; + + bool indexSync_ = false; + /// The length defined for creating neighbor list real neighborLength_; @@ -67,17 +71,17 @@ private: protected: - void setNewIndices(deviceViewType1D newIndices); + void setNewIndices(const uint32Vector_D& newIndices); - void appendNewIndices(deviceViewType1D newIndices); + void appendNewIndices(const uint32Vector_D& newIndices); bool removeIndices( uint32 numRemove, - deviceViewType1D removeMask); + const uint32Vector_D& removeMask); bool transferPoints( uint32 numTransfer, - deviceViewType1D transferMask, + const uint32Vector_D& transferMask, uint32 transferBoundaryIndex, realx3 transferVector); @@ -176,10 +180,10 @@ public: bool beforeIteration(uint32 iterNum, real t, real dt) = 0 ; virtual - bool iterate(uint32 iterNum, real t) = 0; + bool iterate(uint32 iterNum, real t, real dt) = 0; virtual - bool afterIteration(uint32 iterNum, real t) = 0; + bool afterIteration(uint32 iterNum, real t, real dt) = 0; const auto& indexList()const diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBaseKernels.cpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBaseKernels.cpp index ff31ba02..0b0fd10c 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBaseKernels.cpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBaseKernels.cpp @@ -24,16 +24,25 @@ void pFlow::boundaryBaseKernels::createRemoveKeepLists ( uint32 numTotal, uint32 numRemove, - deviceViewType1D removeMask, - deviceViewType1D& removeList, - deviceViewType1D& keepList + const uint32Vector_D& removeMask, + uint32Vector_D& removeList, + uint32Vector_D& keepList ) { uint32 numKeep = numTotal - numRemove; - deviceViewType1D rList("rList",numRemove); - deviceViewType1D kList("kList",numKeep); - - exclusiveScan(removeMask, 0u, numTotal+1, removeMask, 0u); + removeList.reallocate(numRemove,numRemove); + keepList.reallocate(numKeep,numKeep); + + auto maskD = removeMask.deviceViewAll(); + const auto& removeD = removeList.deviceViewAll(); + const auto& keepD = keepList.deviceViewAll(); + + exclusiveScan( + maskD, + 0u, + numTotal+1, + maskD, + 0u); Kokkos::parallel_for ( @@ -41,35 +50,38 @@ void pFlow::boundaryBaseKernels::createRemoveKeepLists deviceRPolicyStatic(0, numTotal), LAMBDA_HD(uint32 i) { - if(removeMask(i)!= removeMask(i+1)) - rList(removeMask(i)) = i; + if(maskD(i)!= maskD(i+1)) + removeD(maskD(i)) = i; else - kList(i-removeMask(i)) = i; + keepD(i-maskD(i)) = i; } ); Kokkos::fence(); - removeList = rList; - keepList = kList; - } void pFlow::boundaryBaseKernels::createRemoveKeepIndices ( - deviceViewType1D indices, + const uint32Vector_D& indices, uint32 numRemove, - deviceViewType1D removeMask, - deviceViewType1D& removeIndices, - deviceViewType1D& keepIndices + const uint32Vector_D& removeMask, + uint32Vector_D& removeIndices, + uint32Vector_D& keepIndices ) { uint32 numTotal = indices.size(); uint32 numKeep = numTotal - numRemove; - deviceViewType1D rIndices("rIndices",numRemove); - deviceViewType1D kIndices("kIndices",numKeep); + + removeIndices.reallocate(numRemove, numRemove); + keepIndices.reallocate(numKeep, numKeep); - exclusiveScan(removeMask, 0u, numTotal+1, removeMask, 0u); + auto maskD = removeMask.deviceViewAll(); + const auto& removeD = removeIndices.deviceViewAll(); + const auto& keepD = keepIndices.deviceViewAll(); + const auto& indicesD = indices.deviceViewAll(); + + exclusiveScan(maskD, 0u, numTotal+1, maskD, 0u); Kokkos::parallel_for ( @@ -77,14 +89,11 @@ void pFlow::boundaryBaseKernels::createRemoveKeepIndices deviceRPolicyStatic(0, numTotal), LAMBDA_HD(uint32 i) { - if(removeMask(i)!= removeMask(i+1)) - rIndices(removeMask(i)) = indices(i); + if(maskD(i)!= maskD(i+1)) + removeD(maskD(i)) = indicesD(i); else - kIndices(i-removeMask(i)) = indices(i); + keepD(i-maskD(i)) = indicesD(i); } ); - Kokkos::fence(); - - removeIndices = rIndices; - keepIndices = kIndices; + Kokkos::fence(); } \ No newline at end of file diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBaseKernels.hpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBaseKernels.hpp index e3166721..780360f7 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBaseKernels.hpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBaseKernels.hpp @@ -21,7 +21,7 @@ Licence: #ifndef __boundaryBaseKernels_hpp__ #define __boundaryBaseKernels_hpp__ -#include "phasicFlowKokkos.hpp" +#include "VectorSingles.hpp" namespace pFlow::boundaryBaseKernels { @@ -29,16 +29,16 @@ namespace pFlow::boundaryBaseKernels void createRemoveKeepLists( uint32 numTotal, uint32 numRemove, - deviceViewType1D removeMask, - deviceViewType1D& removeList, - deviceViewType1D& keepList); + const uint32Vector_D& removeMask, + uint32Vector_D& removeList, + uint32Vector_D& keepList); void createRemoveKeepIndices( - deviceViewType1D indices, + const uint32Vector_D& indices, uint32 numRemove, - deviceViewType1D removeMask, - deviceViewType1D& removeIndices, - deviceViewType1D& keepIndices); + const uint32Vector_D& removeMask, + uint32Vector_D& removeIndices, + uint32Vector_D& keepIndices); } diff --git a/src/phasicFlow/structuredData/boundaries/boundaryExit/boundaryExit.cpp b/src/phasicFlow/structuredData/boundaries/boundaryExit/boundaryExit.cpp index b48e80ca..7b91714c 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryExit/boundaryExit.cpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryExit/boundaryExit.cpp @@ -33,7 +33,7 @@ pFlow::boundaryExit::boundaryExit boundaryBase(dict, bplane, internal) { exitMarginLength_ = max( - dict.getValOrSet("exitMarginLength",0.0), 0.0); + dict.getValOrSet("exitMarginLength",(real)0.0), (real)0.0); checkForExitInterval_ = max( dict.getValOrSet("checkForExitInterval", 1), 1); } @@ -52,9 +52,10 @@ bool pFlow::boundaryExit::beforeIteration } uint32 s = size(); - deviceViewType1D deleteFlags("deleteFlags",s+1); - fill(deleteFlags, 0, s+1, 0u); + uint32Vector_D deleteFlags("deleteFlags",s+1, s+1, RESERVE()); + deleteFlags.fill(0u); + const auto& deleteD = deleteFlags.deviceViewAll(); auto points = thisPoints(); auto p = boundaryPlane().infPlane(); @@ -68,7 +69,7 @@ bool pFlow::boundaryExit::beforeIteration { if(p.pointInNegativeSide(points(i))) { - deleteFlags(i)=1; + deleteD(i)=1; delToUpdate++; } }, @@ -87,7 +88,8 @@ bool pFlow::boundaryExit::beforeIteration bool pFlow::boundaryExit::iterate ( uint32 iterNum, - real t + real t, + real dt ) { return true; @@ -96,7 +98,8 @@ bool pFlow::boundaryExit::iterate bool pFlow::boundaryExit::afterIteration ( uint32 iterNum, - real t + real t, + real dt ) { return true; diff --git a/src/phasicFlow/structuredData/boundaries/boundaryExit/boundaryExit.hpp b/src/phasicFlow/structuredData/boundaries/boundaryExit/boundaryExit.hpp index 2199fc60..77b6cfce 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryExit/boundaryExit.hpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryExit/boundaryExit.hpp @@ -63,9 +63,9 @@ public: bool beforeIteration(uint32 iterNum, real t, real dt) override; - bool iterate(uint32 iterNum, real t) override; + bool iterate(uint32 iterNum, real t, real dt) override; - bool afterIteration(uint32 iterNum, real t) override; + bool afterIteration(uint32 iterNum, real t, real dt) override; }; diff --git a/src/phasicFlow/structuredData/boundaries/boundaryList.cpp b/src/phasicFlow/structuredData/boundaries/boundaryList.cpp index 2e6d20dc..62a695cf 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryList.cpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryList.cpp @@ -155,6 +155,15 @@ bool pFlow::boundaryList::iterate real dt ) { + for(auto& bdry:*this) + { + if( !bdry->iterate(iter, t, dt)) + { + fatalErrorInFunction<< + "Error in iterate in boundary "<name()<afterIteration(iter, t, dt)) + { + fatalErrorInFunction<< + "Error in afterIteration in boundary "<name()< transferFlags("transferFlags",s+1); - fill(transferFlags, 0, s+1, 0u); + uint32Vector_D transferFlags("transferFlags",s+1, s+1, RESERVE()); + transferFlags.fill(0u); auto points = thisPoints(); auto p = boundaryPlane().infPlane(); + const auto & transferD = transferFlags.deviceViewAll(); uint32 numTransfered = 0; Kokkos::parallel_reduce @@ -78,7 +79,7 @@ bool pFlow::boundaryPeriodic::beforeIteration( { if(p.pointInNegativeSide(points(i))) { - transferFlags(i)=1; + transferD(i)=1; trnasToUpdate++; } }, @@ -109,7 +110,8 @@ bool pFlow::boundaryPeriodic::beforeIteration( bool pFlow::boundaryPeriodic::iterate ( uint32 iterNum, - real t + real t, + real dt ) { return true; @@ -118,7 +120,8 @@ bool pFlow::boundaryPeriodic::iterate bool pFlow::boundaryPeriodic::afterIteration ( uint32 iterNum, - real t + real t, + real dt ) { return true; diff --git a/src/phasicFlow/structuredData/boundaries/boundaryPeriodic/boundaryPeriodic.hpp b/src/phasicFlow/structuredData/boundaries/boundaryPeriodic/boundaryPeriodic.hpp index 01223885..bfb8be78 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryPeriodic/boundaryPeriodic.hpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryPeriodic/boundaryPeriodic.hpp @@ -46,7 +46,7 @@ public: const plane& bplane, internalPoints& internal); - virtual + ~boundaryPeriodic() override= default; add_vCtor @@ -64,9 +64,9 @@ public: bool beforeIteration(uint32 iterNum, real t, real dt) override; - bool iterate(uint32 iterNum, real t) override; + bool iterate(uint32 iterNum, real t, real dt) override; - bool afterIteration(uint32 iterNum, real t) override; + bool afterIteration(uint32 iterNum, real t, real dt) override; }; diff --git a/src/phasicFlow/structuredData/domain/simulationDomain.cpp b/src/phasicFlow/structuredData/domain/simulationDomain.cpp index cf4201a6..2930b1b4 100644 --- a/src/phasicFlow/structuredData/domain/simulationDomain.cpp +++ b/src/phasicFlow/structuredData/domain/simulationDomain.cpp @@ -53,7 +53,7 @@ pFlow::domain pFlow::simulationDomain::extendThisDomain } pFlow::uniquePtr -pFlow::simulationDomain::create(systemControl &control) + pFlow::simulationDomain::create(systemControl &control) { word sType = angleBracketsNames( "simulationDomain", diff --git a/src/phasicFlow/structuredData/iBox/iBox.hpp b/src/phasicFlow/structuredData/iBox/iBox.hpp index 89e7b225..b9105047 100644 --- a/src/phasicFlow/structuredData/iBox/iBox.hpp +++ b/src/phasicFlow/structuredData/iBox/iBox.hpp @@ -43,7 +43,7 @@ protected: public: // - type info - TypeInfoTemplateNV("iBox", intType); + TypeInfoTemplateNV11("iBox", intType); //// - Constructors INLINE_FUNCTION_HD diff --git a/src/phasicFlow/structuredData/pointStructure/internalPoints.cpp b/src/phasicFlow/structuredData/pointStructure/internalPoints.cpp index e9508076..7e213b54 100644 --- a/src/phasicFlow/structuredData/pointStructure/internalPoints.cpp +++ b/src/phasicFlow/structuredData/pointStructure/internalPoints.cpp @@ -18,10 +18,11 @@ Licence: -----------------------------------------------------------------------------*/ - +#include "Time.hpp" #include "internalPoints.hpp" #include "domain.hpp" #include "Vectors.hpp" +#include "anyList.hpp" #include "internalPointsKernels.hpp" void pFlow::internalPoints::syncPFlag()const @@ -33,16 +34,57 @@ void pFlow::internalPoints::syncPFlag()const } } -bool pFlow::internalPoints::deletePoints(deviceViewType1D delPoints) +bool pFlow::internalPoints::deletePoints(const uint32Vector_D& delPoints) { - if(!pFlagsD_.deletePoints(delPoints)) + + if(delPoints.empty())return true; + + auto oldRange = pFlagsD_.activeRange(); + auto oldSize = size(); + + if(!pFlagsD_.deletePoints(delPoints.deviceView())) { fatalErrorInFunction<< "Error in deleting points from internal points"< delPoints); + bool deletePoints(const uint32Vector_D& delPoints); bool changePointsFlag( deviceViewType1D changePoints, @@ -160,6 +161,12 @@ public: { return pointPosition_.capacity(); } + + INLINE_FUNCTION_H + bool empty()const + { + return size()==0u; + } // - number of active points INLINE_FUNCTION_H diff --git a/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp b/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp index ef91ccff..ebdeb1ae 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp +++ b/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp @@ -277,6 +277,9 @@ public: isAllActive_); } + ViewType1D getActivePoints(); + + /// @brief Loop over the active points and mark those out of the box /// and return number of deleted points /// @param validBox the box whose inside is valid diff --git a/src/phasicFlow/structuredData/pointStructure/pointFlagKernels.hpp b/src/phasicFlow/structuredData/pointStructure/pointFlagKernels.hpp index aad7ff6e..ff43112f 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointFlagKernels.hpp +++ b/src/phasicFlow/structuredData/pointStructure/pointFlagKernels.hpp @@ -20,7 +20,36 @@ Licence: #ifndef __pointFlagKernels_hpp__ #define __pointFlagKernels_hpp__ -#include "streams.hpp" +template +pFlow::ViewType1D::memory_space> + pFlow::pointFlag::getActivePoints() +{ + using rpAPoints = Kokkos::RangePolicy>; + + ViewType1D + aPoints("activePoints", activeRange_.end()+1); + + + Kokkos::parallel_for( + "pFlow::pointFlag::getActivePoints", + rpAPoints(0,activeRange_.end()), + CLASS_LAMBDA_HD(uint32 i) + { + if( isActive(i)) + { + aPoints[i] = 1; + } + else + { + aPoints[i] = 0; + } + } + ); + Kokkos::fence(); + return aPoints; +} + template pFlow::uint32 pFlow::pointFlag::markOutOfBoxDelete diff --git a/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp b/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp index 8fcbe2b8..40744c07 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp +++ b/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp @@ -80,7 +80,7 @@ bool pFlow::pointStructure::setupPointStructure(const PointsTypeHost &points) bool pFlow::pointStructure::initializePoints(const PointsTypeHost &points) { - pointPosition_.assign(points); + pointPosition_.assignFromHost(points); pFlagsD_ = pFlagTypeDevice(pointPosition_.capacity(), 0, pointPosition_.size()); pFlagSync_ = false; @@ -117,7 +117,7 @@ pFlow::pointStructure::pointStructure *this ) { - REPORT(0)<< "Reading "<< Green_Text("point structure")<< + REPORT(1)<< "Reading "<< Green_Text("pointStructure")<< " from "<