Commit f5fa3e03 authored by PIACIBELLO Cyrille's avatar PIACIBELLO Cyrille

Arranger can now handle sor/tgt particles. Test added.

parent f8a5c49a
......@@ -20,7 +20,7 @@ template<class OctreeClass,class ParticleClass>
class FAbstractMover{
public:
virtual void getParticlePosition(ParticleClass* lf, const int idxPart, FPoint* particlePos) = 0;
virtual void removeFromLeafAndKeep(ParticleClass* lf, const FPoint& particlePos, const int idxPart) = 0;
virtual void removeFromLeafAndKeep(ParticleClass* lf, const FPoint& particlePos, const int idxPart, FParticleType type) = 0;
virtual void insertAllParticles(OctreeClass* tree) = 0;
};
......
......@@ -74,6 +74,7 @@ public:
octreeIterator.gotoBottomLeft();
do{
const MortonIndex currentMortonIndex = octreeIterator.getCurrentGlobalIndex();
//First we test sources
ContainerClass * particles = octreeIterator.getCurrentLeaf()->getSrc();
for(int idxPart = 0 ; idxPart < particles->getNbParticles(); /*++idxPart*/){
FPoint currentPart;
......@@ -82,15 +83,33 @@ public:
const MortonIndex particuleIndex = tree->getMortonFromPosition(currentPart);
if(particuleIndex != currentMortonIndex){
//Need to move this one
interface->removeFromLeafAndKeep(particles,currentPart,idxPart);
interface->removeFromLeafAndKeep(particles,currentPart,idxPart,FParticleTypeSource);
}
else{
//Need to increment idx;
++idxPart;
}
}
//Then we test targets
if(octreeIterator.getCurrentLeaf()->getTargets() != particles){ //Leaf is TypedLeaf
ContainerClass * particleTargets = octreeIterator.getCurrentLeaf()->getTargets();
for(int idxPart = 0 ; idxPart < particleTargets->getNbParticles(); /*++idxPart*/){
FPoint currentPart;
interface->getParticlePosition(particleTargets,idxPart,&currentPart);
checkPosition(currentPart);
const MortonIndex particuleIndex = tree->getMortonFromPosition(currentPart);
if(particuleIndex != currentMortonIndex){
//Need to move this one
interface->removeFromLeafAndKeep(particleTargets,currentPart,idxPart, FParticleTypeTarget);
}
else{
//Need to increment idx;
++idxPart;
}
}
}
}while(octreeIterator.moveRight());
printf("Insert back particles\n");
//Insert back the parts that have been removed
interface->insertAllParticles(tree);
......@@ -101,7 +120,8 @@ public:
bool workOnNext = true;
do{
// Empty leaf
if( octreeIterator.getCurrentListTargets()->getNbParticles() == 0 ){
if( octreeIterator.getCurrentListTargets()->getNbParticles() == 0 &&
octreeIterator.getCurrentListSrc()->getNbParticles() == 0 ){
const MortonIndex currentIndex = octreeIterator.getCurrentGlobalIndex();
workOnNext = octreeIterator.moveRight();
tree->removeLeaf( currentIndex );
......
#ifndef FPARTICULETYPEDINDEXEDMOVER_HPP
#define FPARTICULETYPEDINDEXEDMOVER_HPP
#include "FAbstractMover.hpp"
#include "../Containers/FVector.hpp"
/**
* This class should be use with the octree arrange to move particles
* that are typed (src/tgt) and stored in a FBasicParticleContainer
*/
template<class OctreeClass, class ContainerClass >
class FParticleTypedIndexedMover : public FAbstractMover<OctreeClass, ContainerClass>{
private:
ContainerClass toStoreRemovedSourceParts;
ContainerClass toStoreRemovedTargetParts;
public:
FParticleTypedIndexedMover(){
}
virtual ~FParticleTypedIndexedMover(){
}
/** To get the position of the particle at idx idxPart in leaf lf */
void getParticlePosition(ContainerClass* lf, const int idxPart, FPoint* particlePos){
(*particlePos) = FPoint(lf->getPositions()[0][idxPart],lf->getPositions()[1][idxPart],lf->getPositions()[2][idxPart]);
}
/** Remove a particle but keep it to reinsert it later*/
void removeFromLeafAndKeep(ContainerClass* lf, const FPoint& particlePos, const int idxPart, FParticleType type){
std::array<typename ContainerClass::AttributesClass, ContainerClass::NbAttributes> particleValues;
for(int idxAttr = 0 ; idxAttr < ContainerClass::NbAttributes ; ++idxAttr){
particleValues[idxAttr] = lf->getAttribute(idxAttr)[idxPart];
}
if(type == FParticleTypeTarget){
toStoreRemovedTargetParts.push(particlePos,FParticleTypeTarget,lf->getIndexes()[idxPart],particleValues);
}
else{
toStoreRemovedSourceParts.push(particlePos,FParticleTypeSource,lf->getIndexes()[idxPart],particleValues);
}
lf->removeParticles(&idxPart,1);
}
/** Reinsert the previously saved particles */
void insertAllParticles(OctreeClass* tree){
std::array<typename ContainerClass::AttributesClass, ContainerClass::NbAttributes> particleValues;
for(int idxToInsert = 0; idxToInsert<toStoreRemovedSourceParts.getNbParticles() ; ++idxToInsert){
for(int idxAttr = 0 ; idxAttr < ContainerClass::NbAttributes ; ++idxAttr){
particleValues[idxAttr] = toStoreRemovedSourceParts.getAttribute(idxAttr)[idxToInsert];
}
const FPoint particlePos(toStoreRemovedSourceParts.getPositions()[0][idxToInsert],
toStoreRemovedSourceParts.getPositions()[1][idxToInsert],
toStoreRemovedSourceParts.getPositions()[2][idxToInsert]);
tree->insert(particlePos, FParticleTypeSource, toStoreRemovedSourceParts.getIndexes()[idxToInsert], particleValues);
}
for(int idxToInsert = 0; idxToInsert<toStoreRemovedTargetParts.getNbParticles() ; ++idxToInsert){
for(int idxAttr = 0 ; idxAttr < ContainerClass::NbAttributes ; ++idxAttr){
particleValues[idxAttr] = toStoreRemovedTargetParts.getAttribute(idxAttr)[idxToInsert];
}
const FPoint particlePos(toStoreRemovedTargetParts.getPositions()[0][idxToInsert],
toStoreRemovedTargetParts.getPositions()[1][idxToInsert],
toStoreRemovedTargetParts.getPositions()[2][idxToInsert]);
tree->insert(particlePos, FParticleTypeTarget, toStoreRemovedTargetParts.getIndexes()[idxToInsert], particleValues);
}
toStoreRemovedSourceParts.clear();
toStoreRemovedTargetParts.clear();
}
};
#endif //FPARTICULETYPEDINDEXEDMOVER_HPP
This diff is collapsed.
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