Commit f3683c88 authored by COULAUD Olivier's avatar COULAUD Olivier

Change interface for getPeriodicLeafsNeighbors

parent 784714fe
......@@ -1291,7 +1291,7 @@ public:
}
/** This function return a cell (if it exists) from a morton index and a level
/** This function return a cell (if it exists) from a morton index
* @param inIndex the index of the desired cell
* @param inLevel the level of the desired cell (cannot be inferred from the index)
* @return the cell if it exist or null (0)
......@@ -1317,9 +1317,9 @@ public:
}
/** This function fill an array with the neighbors of a cell
* @param inNeighbors the array to store the elements
* @param inIndex the index of the element we want the neighbors
* @param inLevel the level of the element
* @param[out] inNeighbors the array to store the elements
* @param[in] center the 3d-array of 1d Morton index of the element we want the neighbors
* @param[in] inLevel the level of the element
* @return the number of neighbors
*/
int getLeafsNeighbors(ContainerClass* inNeighbors[27], const FTreeCoordinate& center, const int inLevel){
......@@ -1447,7 +1447,8 @@ public:
* @param inLevel the level of the element
* @return the number of neighbors
*/
int getLeafsNeighbors(const CellClass* inNeighbors[26], int inNeighborPositions[26], const FTreeCoordinate& center, const int inLevel){
int getLeafsNeighbors(const CellClass* inNeighbors[26], int inNeighborPositions[26],
const FTreeCoordinate& center, const int inLevel){
const int boxLimite = FMath::pow2(inLevel);
int idxNeighbors = 0;
......@@ -1483,37 +1484,43 @@ public:
return idxNeighbors;
}
/** This function fill an array with the neighbors of a cell
* @param inNeighbors the array to store the elements
* @param inIndex the index of the element we want the neighbors
* @param inLevel the level of the element
/** This function fill an array with the neighbors of a cell. The cell is set by its FTreeCordinate center
*
* @param[out] outNeighbors the array to store the elements
* @param[out] isPeriodic return true if there are periodic cells.
* @param[in] center the index of the element we want the neighbors
* @param[in] inLevel the level of the element
* @param[in] inDirection ...
* @return the number of neighbors
*/
int getPeriodicLeafsNeighbors(ContainerClass* inNeighbors[27], FTreeCoordinate outOffsets[27], bool*const isPeriodic,
int getPeriodicLeafsNeighbors(ContainerClass* outNeighbors[27], FTreeCoordinate outOffsets[27],
bool* const isPeriodic,
const FTreeCoordinate& center, const int inLevel, const int inDirection){
std::cout << " FOCTREE::getPeriodicLeafsNeighbors "<< std::endl;
const int boxLimite = FMath::pow2(inLevel);
if( center.getX() != 0 && center.getY() != 0 && center.getZ() != 0 &&
center.getX() != boxLimite - 1 && center.getY() != boxLimite - 1 && center.getZ() != boxLimite - 1 ){
// No periodic cells call classical method
(*isPeriodic) = false;
return getLeafsNeighbors(inNeighbors, center, inLevel);
return this->getLeafsNeighbors(outNeighbors, center, inLevel);
}
// Now we have periodic cells
//
(*isPeriodic) = true;
memset(inNeighbors , 0 , 27 * sizeof(ContainerClass*));
memset(outNeighbors , 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 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 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 endZ = (TestPeriodicCondition(inDirection, DirPlusZ) || center.getZ() != boxLimite - 1 ?1:0);
int otherX,otherY,otherZ;
FTreeCoordinate other;
std::cout << " startX" << startX << " startY" << startY<< " startZ" << startZ <<std::endl;
std::cout << " endX" << endX << " endY" << endY<< " endZ" << endZ <<std::endl;
int xoffset = 0, yoffset = 0, zoffset = 0;
// We test all cells around
for(int idxX = startX ; idxX <= endX ; ++idxX){
......@@ -1561,7 +1568,7 @@ public:
// add to list if not null
if(leaf){
const int index = (((idxX + 1) * 3) + (idxY +1)) * 3 + idxZ + 1;
inNeighbors[index] = leaf;
outNeighbors[index] = leaf;
outOffsets[index].setPosition(xoffset,yoffset,zoffset);
++idxNeighbors;
......@@ -1574,34 +1581,52 @@ public:
return idxNeighbors;
}
/** This function fill an array with the neighbors of a cell
* @param inNeighbors the array to store the elements
* @param inIndex the index of the element we want the neighbors
* @param inLevel the level of the element
* @return the number of neighbors
*/
int getPeriodicLeafsNeighbors(ContainerClass* inNeighbors[26], int inNeighborPositions[26], FTreeCoordinate outOffsets[26], bool*const isPeriodic,
const FTreeCoordinate& center, const int inLevel, const int inDirection){
/** This function fill an array with the neighbors of a cell in the tree.
* In the parallel case, we return only cells of the local octree.
*
* This method is used in the P2P operator in sequential or parallel periodic algorithm
* for idx between [0, number of neighbors[
* outNeighbors[idx] the particles structure of the ith neighbor
* outNeighborPositions[idx] the position of the ith neighbor in the 26 neighbors (Z,Y, X) ordering
* outOffsets[idx] (0,0,0) if the neighbor is inside the whole box otherwise the offset to the current cell
* to obtain the treeCordinate of the image of the cell. Usefull to deplace the coordinate
* of all particles inside the leaf newPos = pos + outOffsets[idx]*boxWidth
*Parameters
* @param[out] outNeighbors the array of pointers on the particle structure cells adjacent to the current cell
* @param[out] outNeighborPositions the array to store the elements
* @param[out] outOffsets the array to store the elements
* @param[out] isPeriodic return true if there are periodic cells.
* @param[in] center the index in tree cordinate of the cell we want the neighbors
* @param[in] inLevel the level of the element
* @return the number of neighbors */
//template< class ARRAY1, class ARRAY2, class ARRAY3 >
// int getPeriodicLeafsNeighbors(ARRAY1 outNeighbors, ARRAY2 outNeighborPositions,
// ARRAY3 outOffsets, bool*const isPeriodic,
int getPeriodicLeafsNeighbors(ContainerClass* outNeighbors[26], int outNeighborPositions[26],
FTreeCoordinate outOffsets[26], bool & isPeriodic,
const FTreeCoordinate& center, const int inLevel, const int inDirection){
std::cout << " FOCTREE::getPeriodicLeafsNeighbors "<< center.getMortonIndex() <<std::endl;
const int boxLimite = FMath::pow2(inLevel);
if( center.getX() != 0 && center.getY() != 0 && center.getZ() != 0 &&
center.getX() != boxLimite - 1 && center.getY() != boxLimite - 1 && center.getZ() != boxLimite - 1 ){
(*isPeriodic) = false;
return getLeafsNeighbors(inNeighbors, inNeighborPositions, center, inLevel);
isPeriodic = false;
return getLeafsNeighbors(outNeighbors, outNeighborPositions, center, inLevel);
}
(*isPeriodic) = true;
isPeriodic = true;
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);
int otherX,otherY,otherZ;
FTreeCoordinate other;
FTreeCoordinate other(0,0,0);
int xoffset = 0, yoffset = 0, zoffset = 0;
// We test all cells around
......@@ -1643,15 +1668,17 @@ public:
zoffset = 1;
}
other.setZ(otherZ);
// get the morton index of the cell
const MortonIndex mortonOther = other.getMortonIndex();
// get cell
// get the particle structure of the leaf
ContainerClass* const leaf = getLeafSrc(mortonOther);
// add to list if not null
// add to list if the cell exists i.e. the pointer is not null
if(leaf){
inNeighbors[idxNeighbors] = leaf;
std::cout << "mortonOther " <<mortonOther << " idx " <<idxX << " idyY " << idxY << " idxZ " <<idxZ
<< " " << (((idxX + 1) * 3) + (idxY +1)) * 3 + idxZ + 1 <<std::endl;
outNeighbors[idxNeighbors] = leaf;
outOffsets[idxNeighbors].setPosition(xoffset,yoffset,zoffset);
inNeighborPositions[idxNeighbors] = (((idxX + 1) * 3) + (idxY +1)) * 3 + idxZ + 1;
outNeighborPositions[idxNeighbors] = (((idxX + 1) * 3) + (idxY +1)) * 3 + idxZ + 1;
++idxNeighbors;
} // if(leaf)
......@@ -1659,7 +1686,7 @@ public:
}
}
}
// return the number of neighbors
return idxNeighbors;
}
......
......@@ -461,7 +461,9 @@ protected:
if(p2pEnabled){
// need the current particles and neighbors particles
const FTreeCoordinate centerOfLeaf = octreeIterator.getCurrentGlobalCoordinate();
const int counter = tree->getPeriodicLeafsNeighbors( neighbors, neighborPositions, offsets, &hasPeriodicLeaves, centerOfLeaf, heightMinusOne, AllDirs);
const int counter = tree->getPeriodicLeafsNeighbors( neighbors, neighborPositions, offsets,
hasPeriodicLeaves, centerOfLeaf,
heightMinusOne, AllDirs);
int periodicNeighborsCounter = 0;
if(hasPeriodicLeaves){
......
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