Commit 62c68aea authored by BRAMAS Berenger's avatar BRAMAS Berenger

Add direction in octree rearrange

parent 2123b967
......@@ -21,6 +21,8 @@
#include "../Containers/FVector.hpp"
#include "../Utils/FAssertable.hpp"
#include "../Utils/FGlobalPeriodic.hpp"
/** This class is an arranger, it move the particles that need
* to be hosted in a different leaf
......@@ -41,7 +43,7 @@ public:
}
/** Arrange */
void rearrange(const bool isPeriodic = false){
void rearrange(const int isPeriodic = DirNone){
// This vector is to keep the moving particles
FVector<ParticleClass> tomove;
......@@ -58,28 +60,67 @@ public:
typename ContainerClass::BasicIterator iter(*octreeIterator.getCurrentListTargets());
while( iter.hasNotFinished() ){
if(isPeriodic){
FPoint partPos = iter.data().getPosition();
while(partPos.getX() < min.getX()){
partPos.incX(boxWidth);
}
FPoint partPos = iter.data().getPosition();
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if( TestPeriodicCondition(isPeriodic, DirPlusX) ){
while(partPos.getX() >= max.getX()){
partPos.incX(-boxWidth);
}
while(partPos.getY() < min.getY()){
partPos.incY(boxWidth);
}
else if(partPos.getX() >= max.getX()){
printf("Error, particle out of Box in +X, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
if( TestPeriodicCondition(isPeriodic, DirMinusX) ){
while(partPos.getX() < min.getX()){
partPos.incX(boxWidth);
}
}
else if(partPos.getX() < min.getX()){
printf("Error, particle out of Box in -X, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
// YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
if( TestPeriodicCondition(isPeriodic, DirPlusY) ){
while(partPos.getY() >= max.getY()){
partPos.incY(-boxWidth);
}
while(partPos.getZ() < min.getZ()){
partPos.incZ(boxWidth);
}
else if(partPos.getY() >= max.getY()){
printf("Error, particle out of Box in +Y, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
if( TestPeriodicCondition(isPeriodic, DirMinusY) ){
while(partPos.getY() < min.getY()){
partPos.incY(boxWidth);
}
}
else if(partPos.getY() < min.getY()){
printf("Error, particle out of Box in -Y, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
// ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
if( TestPeriodicCondition(isPeriodic, DirPlusX) ){
while(partPos.getZ() >= max.getZ()){
partPos.incZ(-boxWidth);
}
iter.data().setPosition(partPos);
}
else if(partPos.getZ() >= max.getZ()){
printf("Error, particle out of Box in +Z, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
if( TestPeriodicCondition(isPeriodic, DirMinusX) ){
while(partPos.getZ() < min.getZ()){
partPos.incZ(boxWidth);
}
}
else if(partPos.getZ() < min.getZ()){
printf("Error, particle out of Box in -Z, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
// set pos
iter.data().setPosition(partPos);
const MortonIndex particuleIndex = tree->getMortonFromPosition(iter.data().getPosition());
if(particuleIndex != currentIndex){
tomove.push(iter.data());
......
......@@ -21,6 +21,9 @@
#include "../Utils/FAssertable.hpp"
#include "../Utils/FMpi.hpp"
#include "../Utils/FGlobalPeriodic.hpp"
/** This class is an arranger, it move the particles that need
* to be hosted in a different leaf
* This is the parallel version that use MPI.
......@@ -63,7 +66,7 @@ public:
}
/** return false if the tree is empty after processing */
bool rearrange(const FMpi::FComm& comm, const bool isPeriodic = false){
bool rearrange(const FMpi::FComm& comm, const int isPeriodic = DirNone){
// interval of each procs
Interval*const intervals = new Interval[comm.processCount()];
memset(intervals, 0, sizeof(Interval) * comm.processCount());
......@@ -109,28 +112,67 @@ public:
typename ContainerClass::BasicIterator iter(*octreeIterator.getCurrentListTargets());
while( iter.hasNotFinished() ){
if(isPeriodic){
FPoint partPos = iter.data().getPosition();
while(partPos.getX() < min.getX()){
partPos.incX(boxWidth);
}
FPoint partPos = iter.data().getPosition();
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if( TestPeriodicCondition(isPeriodic, DirPlusX) ){
while(partPos.getX() >= max.getX()){
partPos.incX(-boxWidth);
}
while(partPos.getY() < min.getY()){
partPos.incY(boxWidth);
}
else if(partPos.getX() >= max.getX()){
printf("Error, particle out of Box in +X, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
if( TestPeriodicCondition(isPeriodic, DirMinusX) ){
while(partPos.getX() < min.getX()){
partPos.incX(boxWidth);
}
}
else if(partPos.getX() < min.getX()){
printf("Error, particle out of Box in -X, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
// YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
if( TestPeriodicCondition(isPeriodic, DirPlusY) ){
while(partPos.getY() >= max.getY()){
partPos.incY(-boxWidth);
}
while(partPos.getZ() < min.getZ()){
partPos.incZ(boxWidth);
}
else if(partPos.getY() >= max.getY()){
printf("Error, particle out of Box in +Y, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
if( TestPeriodicCondition(isPeriodic, DirMinusY) ){
while(partPos.getY() < min.getY()){
partPos.incY(boxWidth);
}
}
else if(partPos.getY() < min.getY()){
printf("Error, particle out of Box in -Y, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
// ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
if( TestPeriodicCondition(isPeriodic, DirPlusX) ){
while(partPos.getZ() >= max.getZ()){
partPos.incZ(-boxWidth);
}
iter.data().setPosition(partPos);
}
else if(partPos.getZ() >= max.getZ()){
printf("Error, particle out of Box in +Z, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
if( TestPeriodicCondition(isPeriodic, DirMinusX) ){
while(partPos.getZ() < min.getZ()){
partPos.incZ(boxWidth);
}
}
else if(partPos.getZ() < min.getZ()){
printf("Error, particle out of Box in -Z, index %lld\n", currentIndex);
printf("Application is exiting...\n");
}
// set pos
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){
......
......@@ -863,12 +863,12 @@ public:
// reset
memset(inNeighbors, 0, sizeof(CellClass*) * 343);
const int startX = (testPeriodicCondition(inDirection, DirMinusX) || parentCell.getX() != 0 ?-1:0);
const int endX = (testPeriodicCondition(inDirection, DirPlusX) || parentCell.getX() != boxLimite - 1 ?1:0);
const int startY = (testPeriodicCondition(inDirection, DirMinusY) || parentCell.getY() != 0 ?-1:0);
const int endY = (testPeriodicCondition(inDirection, DirPlusY) || parentCell.getY() != boxLimite - 1 ?1:0);
const int startZ = (testPeriodicCondition(inDirection, DirMinusZ) || parentCell.getZ() != 0 ?-1:0);
const int endZ = (testPeriodicCondition(inDirection, DirPlusZ) || parentCell.getZ() != boxLimite - 1 ?1:0);
const int startX = (TestPeriodicCondition(inDirection, DirMinusX) || parentCell.getX() != 0 ?-1:0);
const int endX = (TestPeriodicCondition(inDirection, DirPlusX) || parentCell.getX() != boxLimite - 1 ?1:0);
const int startY = (TestPeriodicCondition(inDirection, DirMinusY) || parentCell.getY() != 0 ?-1:0);
const int endY = (TestPeriodicCondition(inDirection, DirPlusY) || parentCell.getY() != boxLimite - 1 ?1:0);
const int startZ = (TestPeriodicCondition(inDirection, DirMinusZ) || parentCell.getZ() != 0 ?-1:0);
const int endZ = (TestPeriodicCondition(inDirection, DirPlusZ) || parentCell.getZ() != boxLimite - 1 ?1:0);
int idxNeighbors = 0;
// We test all cells around
......@@ -1023,12 +1023,12 @@ public:
memset(inNeighbors , 0 , 27 * sizeof(ContainerClass*));
int idxNeighbors = 0;
const int startX = (testPeriodicCondition(inDirection, DirMinusX) || center.getX() != 0 ?-1:0);
const int endX = (testPeriodicCondition(inDirection, DirPlusX) || center.getX() != boxLimite - 1 ?1:0);
const int startY = (testPeriodicCondition(inDirection, DirMinusY) || center.getY() != 0 ?-1:0);
const int endY = (testPeriodicCondition(inDirection, DirPlusY) || center.getY() != boxLimite - 1 ?1:0);
const int startZ = (testPeriodicCondition(inDirection, DirMinusZ) || center.getZ() != 0 ?-1:0);
const int endZ = (testPeriodicCondition(inDirection, DirPlusZ) || center.getZ() != boxLimite - 1 ?1:0);
const int startX = (TestPeriodicCondition(inDirection, DirMinusX) || center.getX() != 0 ?-1:0);
const int endX = (TestPeriodicCondition(inDirection, DirPlusX) || center.getX() != boxLimite - 1 ?1:0);
const int startY = (TestPeriodicCondition(inDirection, DirMinusY) || center.getY() != 0 ?-1:0);
const int endY = (TestPeriodicCondition(inDirection, DirPlusY) || center.getY() != boxLimite - 1 ?1:0);
const int startZ = (TestPeriodicCondition(inDirection, DirMinusZ) || center.getZ() != 0 ?-1:0);
const int endZ = (TestPeriodicCondition(inDirection, DirPlusZ) || center.getZ() != boxLimite - 1 ?1:0);
// We test all cells around
for(int idxX = startX ; idxX <= endX ; ++idxX){
......
......@@ -529,7 +529,7 @@ public:
* @return true if the direction is used else false
*/
bool usePerDir(const int testDir) const{
return testPeriodicCondition(periodicDirections , PeriodicCondition(testDir));
return TestPeriodicCondition(periodicDirections , PeriodicCondition(testDir));
}
/** To enable quick test of the direction
......
......@@ -1420,12 +1420,12 @@ private:
int idxNeig = 0;
const int startX = (testPeriodicCondition(inDirection, DirMinusX) || center.getX() != 0 ?-1:0);
const int endX = (testPeriodicCondition(inDirection, DirPlusX) || center.getX() != boxLimite - 1 ?1:0);
const int startY = (testPeriodicCondition(inDirection, DirMinusY) || center.getY() != 0 ?-1:0);
const int endY = (testPeriodicCondition(inDirection, DirPlusY) || center.getY() != boxLimite - 1 ?1:0);
const int startZ = (testPeriodicCondition(inDirection, DirMinusZ) || center.getZ() != 0 ?-1:0);
const int endZ = (testPeriodicCondition(inDirection, DirPlusZ) || center.getZ() != boxLimite - 1 ?1:0);
const int startX = (TestPeriodicCondition(inDirection, DirMinusX) || center.getX() != 0 ?-1:0);
const int endX = (TestPeriodicCondition(inDirection, DirPlusX) || center.getX() != boxLimite - 1 ?1:0);
const int startY = (TestPeriodicCondition(inDirection, DirMinusY) || center.getY() != 0 ?-1:0);
const int endY = (TestPeriodicCondition(inDirection, DirPlusY) || center.getY() != boxLimite - 1 ?1:0);
const int startZ = (TestPeriodicCondition(inDirection, DirMinusZ) || center.getZ() != 0 ?-1:0);
const int endZ = (TestPeriodicCondition(inDirection, DirPlusZ) || center.getZ() != boxLimite - 1 ?1:0);
// We test all cells around
for(int idxX = startX ; idxX <= endX ; ++idxX){
......@@ -1488,12 +1488,12 @@ private:
return getInteractionNeighbors( workingCell, inLevel, inNeighbors, inNeighborsPosition);
}
const int startX = (testPeriodicCondition(inDirection, DirMinusX) || parentCell.getX() != 0 ?-1:0);
const int endX = (testPeriodicCondition(inDirection, DirPlusX) || parentCell.getX() != boxLimite - 1 ?1:0);
const int startY = (testPeriodicCondition(inDirection, DirMinusY) || parentCell.getY() != 0 ?-1:0);
const int endY = (testPeriodicCondition(inDirection, DirPlusY) || parentCell.getY() != boxLimite - 1 ?1:0);
const int startZ = (testPeriodicCondition(inDirection, DirMinusZ) || parentCell.getZ() != 0 ?-1:0);
const int endZ = (testPeriodicCondition(inDirection, DirPlusZ) || parentCell.getZ() != boxLimite - 1 ?1:0);
const int startX = (TestPeriodicCondition(inDirection, DirMinusX) || parentCell.getX() != 0 ?-1:0);
const int endX = (TestPeriodicCondition(inDirection, DirPlusX) || parentCell.getX() != boxLimite - 1 ?1:0);
const int startY = (TestPeriodicCondition(inDirection, DirMinusY) || parentCell.getY() != 0 ?-1:0);
const int endY = (TestPeriodicCondition(inDirection, DirPlusY) || parentCell.getY() != boxLimite - 1 ?1:0);
const int startZ = (TestPeriodicCondition(inDirection, DirMinusZ) || parentCell.getZ() != 0 ?-1:0);
const int endZ = (TestPeriodicCondition(inDirection, DirPlusZ) || parentCell.getZ() != boxLimite - 1 ?1:0);
int idxNeighbors = 0;
// We test all cells around
......@@ -1781,7 +1781,7 @@ public:
* @return true if the direction is used else false
*/
bool usePerDir(const int testDir) const{
return testPeriodicCondition(periodicDirections , PeriodicCondition(testDir));
return TestPeriodicCondition(periodicDirections , PeriodicCondition(testDir));
}
/** To enable quick test of the direction
......
......@@ -21,6 +21,8 @@
///////////////////////////////////////////////////////
enum PeriodicCondition {
DirNone = 0,
DirPlusX = 1 << 0,
DirMinusX = 1 << 1,
DirPlusY = 1 << 2,
......@@ -35,7 +37,7 @@ enum PeriodicCondition {
AllDirs = (DirX | DirY | DirZ)
};
bool testPeriodicCondition(const int conditions, const PeriodicCondition testConditions) {
bool TestPeriodicCondition(const int conditions, const PeriodicCondition testConditions) {
return (conditions & testConditions) == testConditions;
}
......
......@@ -136,7 +136,7 @@ int main(int argc, char ** argv){
} while(octreeIterator.moveRight());
}
// update tree and vtk
arranger.rearrange(true);
arranger.rearrange(AllDirs);
saver.exportTree(&tree);
}
......
......@@ -34,7 +34,6 @@
#include "../../Src/Files/FTreeMpiCsvSaver.hpp"
#include "../../Src/Files/FFmaLoader.hpp"
#include "../../Src/Arranger/FOctreeArranger.hpp"
#include "../../Src/Components/FSimpleLeaf.hpp"
#include "../../Src/Components/FBasicCell.hpp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment