diff --git a/Src/Arranger/FOctreeArranger.hpp b/Src/Arranger/FOctreeArranger.hpp index ff968ab2b9d5561594a55458f7a171a9cadcdb7c..7c2ffea1fe22e2dc8ab4e1117c9e517e2187437a 100644 --- a/Src/Arranger/FOctreeArranger.hpp +++ b/Src/Arranger/FOctreeArranger.hpp @@ -2,6 +2,7 @@ #define FOCTREEARRANGER_HPP #include "../Utils/FGlobal.hpp" +#include "../Utils/F3DPosition.hpp" #include "../Containers/FVector.hpp" #include "../Utils/FAssertable.hpp" @@ -20,10 +21,16 @@ public: } /** Arrange */ - void rearrange(){ + void rearrange(const bool isPeriodic = false){ // This vector is to keep the moving particles FVector<ParticleClass> tomove; + // For periodic + const FReal boxWidth = tree->getBoxWidth(); + const F3DPosition min(tree->getBoxCenter(),-boxWidth/2); + const F3DPosition max(tree->getBoxCenter(),boxWidth/2); + + { // iterate on the leafs and found particle to remove typename OctreeClass::Iterator octreeIterator(tree); octreeIterator.gotoBottomLeft(); @@ -32,6 +39,28 @@ public: typename ContainerClass::BasicIterator iter(*octreeIterator.getCurrentListTargets()); while( iter.hasNotFinished() ){ + if(isPeriodic){ + F3DPosition partPos = iter.data().getPosition(); + while(partPos.getX() < min.getX()){ + partPos.incX(boxWidth); + } + while(partPos.getX() > max.getX()){ + partPos.incX(-boxWidth); + } + while(partPos.getY() < min.getY()){ + partPos.incY(boxWidth); + } + while(partPos.getY() > max.getY()){ + partPos.incY(-boxWidth); + } + while(partPos.getZ() < min.getZ()){ + partPos.incZ(boxWidth); + } + while(partPos.getZ() > max.getZ()){ + partPos.incZ(-boxWidth); + } + iter.data().setPosition(partPos); + } const MortonIndex particuleIndex = tree->getMortonFromPosition(iter.data().getPosition()); if(particuleIndex != currentIndex){ tomove.push(iter.data()); diff --git a/Src/Arranger/FOctreeArrangerProc.hpp b/Src/Arranger/FOctreeArrangerProc.hpp index c1cfe4f1044afa1ab2cafdaf6620142abaf508dc..5d0feccc0a0c299cd1c5a6501a264da15547938f 100644 --- a/Src/Arranger/FOctreeArrangerProc.hpp +++ b/Src/Arranger/FOctreeArrangerProc.hpp @@ -43,7 +43,7 @@ public: } /** return false if the tree is empty after processing */ - bool rearrange(const FMpi::FComm& comm){ + bool rearrange(const FMpi::FComm& comm, const bool isPeriodic = false){ // interval of each procs Interval*const intervals = new Interval[comm.processCount()]; memset(intervals, 0, sizeof(Interval) * comm.processCount()); @@ -77,6 +77,11 @@ public: FVector<ParticleClass>*const toMove = new FVector<ParticleClass>[comm.processCount()]; { // iterate on the leafs and found particle to remove or to send + // For periodic + const FReal boxWidth = tree->getBoxWidth(); + const F3DPosition min(tree->getBoxCenter(),-boxWidth/2); + const F3DPosition max(tree->getBoxCenter(),boxWidth/2); + typename OctreeClass::Iterator octreeIterator(tree); octreeIterator.gotoBottomLeft(); do{ @@ -84,6 +89,28 @@ public: typename ContainerClass::BasicIterator iter(*octreeIterator.getCurrentListTargets()); while( iter.hasNotFinished() ){ + if(isPeriodic){ + F3DPosition partPos = iter.data().getPosition(); + while(partPos.getX() < min.getX()){ + partPos.incX(boxWidth); + } + while(partPos.getX() > max.getX()){ + partPos.incX(-boxWidth); + } + while(partPos.getY() < min.getY()){ + partPos.incY(boxWidth); + } + while(partPos.getY() > max.getY()){ + partPos.incY(-boxWidth); + } + while(partPos.getZ() < min.getZ()){ + partPos.incZ(boxWidth); + } + while(partPos.getZ() > max.getZ()){ + partPos.incZ(-boxWidth); + } + iter.data().setPosition(partPos); + } const MortonIndex particuleIndex = tree->getMortonFromPosition(iter.data().getPosition()); // is this particle need to be changed from its leaf if(particuleIndex != currentIndex){