Commit a6c704f8 authored by BRAMAS Berenger's avatar BRAMAS Berenger

Finished the group tree

parent 75044b07
......@@ -2,6 +2,7 @@
#define FGROUPATTACHEDLEAF_HPP
#include "../Utils/FGlobal.hpp"
#include "../Utils/FAssert.hpp"
/**
* This class is "attached" to a buffer.
......@@ -19,11 +20,13 @@ protected:
//< Pointers to the attributes of the particles
AttributeClass* attributes[NbAttributesPerParticle];
// Forbid copy even if there is no real reason to do that
FGroupAttachedLeaf(const FGroupAttachedLeaf&) = delete;
FGroupAttachedLeaf& operator=(const FGroupAttachedLeaf&) = delete;
public:
/** Empty constructor to point to nothing */
FGroupAttachedLeaf() : nbParticles(-1) {
memset(positionsPointers, 0, sizeof(FReal*) * 3);
memset(attributes, 0, sizeof(AttributeClass*) * NbAttributesPerParticle);
}
/**
* @brief FGroupAttachedLeaf
* @param inNbParticles the number of particles in the leaf
......@@ -41,9 +44,37 @@ public:
positionsPointers[2] = reinterpret_cast<FReal*>(reinterpret_cast<unsigned char*>(inPositionBuffer) + inLeadingPosition*2);
// Redirect pointers to data
for(int idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
particleAttributes[idxAttribute] = reinterpret_cast<AttributeClass*>(reinterpret_cast<unsigned char*>(inAttributesBuffer) + idxAttribute*inLeadingAttributes);
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
attributes[idxAttribute] = reinterpret_cast<AttributeClass*>(reinterpret_cast<unsigned char*>(inAttributesBuffer) + idxAttribute*inLeadingAttributes);
}
}
/** Copy the attached group to another one (copy the pointer not the content!) */
FGroupAttachedLeaf(const FGroupAttachedLeaf& other) : nbParticles(other.nbParticles) {
positionsPointers[0] = other.positionsPointers[0];
positionsPointers[1] = other.positionsPointers[1];
positionsPointers[2] = other.positionsPointers[2];
// Redirect pointers to data
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
attributes[idxAttribute] = other.attributes[idxAttribute];
}
}
/** Copy the attached group to another one (copy the pointer not the content!) */
FGroupAttachedLeaf& operator=(const FGroupAttachedLeaf& other){
nbParticles = (other.nbParticles);
positionsPointers[0] = other.positionsPointers[0];
positionsPointers[1] = other.positionsPointers[1];
positionsPointers[2] = other.positionsPointers[2];
// Redirect pointers to data
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
attributes[idxAttribute] = other.attributes[idxAttribute];
}
return (*this);
}
/**
......@@ -105,6 +136,42 @@ public:
static_assert(index < NbAttributesPerParticle, "Index to get attributes is out of scope.");
return attributes[index];
}
/** Return true if it has been attached to a memoy block */
bool isAttachedToSomething() const {
return nbParticles != -1;
}
/** Allocate a new leaf by calling its constructor */
template<class ParticleClassContainer>
void copyFromContainer(const ParticleClassContainer* particles, const int offsetInSrcContainer){
FAssertLF(isAttachedToSomething());
// Copy position
memcpy(positionsPointers[0], particles->getPositions()[0] + offsetInSrcContainer, nbParticles*sizeof(FReal));
memcpy(positionsPointers[1], particles->getPositions()[1] + offsetInSrcContainer, nbParticles*sizeof(FReal));
memcpy(positionsPointers[2], particles->getPositions()[2] + offsetInSrcContainer, nbParticles*sizeof(FReal));
// Copy data
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
memcpy(attributes[idxAttribute], particles->getAttribute(idxAttribute) + offsetInSrcContainer, nbParticles*sizeof(AttributeClass));
}
}
/** Copy data for one particle (from the ParticleClassContainer into the attached buffer) */
template<class ParticleClassContainer>
void setParticle(const int destPartIdx, const int srcPartIdx, const ParticleClassContainer* particles){
// Copy position
positionsPointers[0][destPartIdx] = particles->getPositions()[0][srcPartIdx];
positionsPointers[1][destPartIdx] = particles->getPositions()[1][srcPartIdx];
positionsPointers[2][destPartIdx] = particles->getPositions()[2][srcPartIdx];
// Copy data
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
attributes[idxAttribute][destPartIdx] = particles->getAttribute(idxAttribute)[srcPartIdx];
}
}
};
#endif // FGROUPATTACHEDLEAF_HPP
......@@ -152,25 +152,13 @@ public:
}
/** Allocate a new leaf by calling its constructor */
template<class ParticleClassContainer>
void newLeaf(const MortonIndex inIndex, const int id, const int nbParticles, const size_t offsetInGroup,
const ParticleClassContainer* particles, const int offsetInSrcContainer){
void newLeaf(const MortonIndex inIndex, const int id, const int nbParticles, const size_t offsetInGroup){
FAssertLF(isInside(inIndex));
FAssertLF(!exists(inIndex));
FAssertLF(id < blockHeader->blockIndexesTableSize);
blockIndexesTable[inIndex-blockHeader->startingIndex] = id;
leafHeader[id].nbParticles = nbParticles;
leafHeader[id].offSet = offsetInGroup;
// Copy position
memcpy(particlePosition[0] + offsetInGroup, particles->getPositions()[0] + offsetInSrcContainer, nbParticles*sizeof(FReal));
memcpy(particlePosition[1] + offsetInGroup, particles->getPositions()[1] + offsetInSrcContainer, nbParticles*sizeof(FReal));
memcpy(particlePosition[2] + offsetInGroup, particles->getPositions()[2] + offsetInSrcContainer, nbParticles*sizeof(FReal));
// Copy data
for(unsigned idxAttribute = 0 ; idxAttribute < NbAttributesPerParticle ; ++idxAttribute){
memcpy(particleAttributes[idxAttribute] + offsetInGroup, particles->getAttribute(idxAttribute) + offsetInSrcContainer, nbParticles*sizeof(AttributeClass));
}
}
/** Iterate on each allocated leaves */
......@@ -192,16 +180,16 @@ public:
/** Return the address of the leaf if it exists (or NULL) */
template<class ParticlesAttachedClass>
ParticlesAttachedClass* getLeaf(const MortonIndex leafIndex){
ParticlesAttachedClass getLeaf(const MortonIndex leafIndex){
if(blockIndexesTable[leafIndex - blockHeader->startingIndex] != LeafIsEmptyFlag){
const int id = blockIndexesTable[leafIndex - blockHeader->startingIndex];
return ParticlesAttachedClass(leafHeader[id].nbParticles,
particlePosition[0] + leafHeader[id].offSet,
positionOffset,
particleAttributes[0] + leafHeader[id].offSet,
attributeOffset);
positionOffset,
particleAttributes[0] + leafHeader[id].offSet,
attributeOffset);
}
return NULL;
return ParticlesAttachedClass();
}
};
......
This diff is collapsed.
......@@ -45,29 +45,30 @@ int main(int argc, char* argv[]){
OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
FP2PParticleContainer<> allParticles;
for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
FPoint particlePosition;
FReal physicalValue;
loader.fillParticle(&particlePosition,&physicalValue);
tree.insert(particlePosition, physicalValue );
allParticles.push(particlePosition, physicalValue);
}
std::cout << "Done " << "(@Creating and Inserting Particles = " << counter.tacAndElapsed() << "s)." << std::endl;
const int groupSize = FParameters::getValue(argc,argv,"-bs", 250);
counter.tic();
GroupOctreeClass groupedTree(NbLevels, groupSize, &tree, 0);
std::cout << "Done " << "(@Converting the tree with leafs only = " << counter.tacAndElapsed() << "s). Group size is " << groupSize << "." << std::endl;
counter.tic();
GroupOctreeClass groupedTree2(NbLevels, groupSize, &tree);
std::cout << "Done " << "(@Converting the tree with all Octree = " << counter.tacAndElapsed() << "s). Group size is " << groupSize << "." << std::endl;
counter.tic();
GroupOctreeClass groupedTree3(NbLevels, loader.getBoxWidth(), loader.getCenterOfBox(), groupSize, &allParticles);
std::cout << "Done " << "(@Converting the tree with all Octree = " << counter.tacAndElapsed() << "s). Group size is " << groupSize << "." << std::endl;
groupedTree.printInfoBlocks();
groupedTree2.printInfoBlocks();
groupedTree3.printInfoBlocks();
return 0;
}
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