From ba358cc755183893a44c7f1e7ffce3d69590400e Mon Sep 17 00:00:00 2001 From: bramas <berenger.bramas@inria.fr> Date: Tue, 16 Sep 2014 14:04:08 +0200 Subject: [PATCH] Add a test for the group tree (which count the number of interaction particles) --- Src/GroupTree/FGroupSeqAlgorithm.hpp | 1 + Src/GroupTree/FGroupTestParticleContainer.hpp | 34 ++++++++ Tests/noDist/testBlockedAlgorithm.cpp | 79 +++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 Src/GroupTree/FGroupTestParticleContainer.hpp create mode 100644 Tests/noDist/testBlockedAlgorithm.cpp diff --git a/Src/GroupTree/FGroupSeqAlgorithm.hpp b/Src/GroupTree/FGroupSeqAlgorithm.hpp index e8b807d39..4d89a147c 100644 --- a/Src/GroupTree/FGroupSeqAlgorithm.hpp +++ b/Src/GroupTree/FGroupSeqAlgorithm.hpp @@ -162,6 +162,7 @@ protected: CellClass* interCell = (*iterCells)->getCell(interactionsIndexes[idxInter]); if(interCell){ FAssertLF(interCell->getMortonIndex() == interactionsIndexes[idxInter]); + FAssertLF(interactions[interactionsPosition[idxInter]] == nullptr); interactions[interactionsPosition[idxInter]] = interCell; counterExistingCell += 1; } diff --git a/Src/GroupTree/FGroupTestParticleContainer.hpp b/Src/GroupTree/FGroupTestParticleContainer.hpp new file mode 100644 index 000000000..3ae407d11 --- /dev/null +++ b/Src/GroupTree/FGroupTestParticleContainer.hpp @@ -0,0 +1,34 @@ +#ifndef FGROUPTESTPARTICLECONTAINER_HPP +#define FGROUPTESTPARTICLECONTAINER_HPP + +#include "FGroupAttachedLeaf.hpp" + +class FGroupTestParticleContainer : public FGroupAttachedLeaf<2, long long int> { + typedef FGroupAttachedLeaf<2, long long int> Parent; + +public: + FGroupTestParticleContainer(){} + FGroupTestParticleContainer(const int inNbParticles, FReal* inPositionBuffer, const size_t inLeadingPosition, + long long int* inAttributesBuffer, const size_t inLeadingAttributes) + : Parent(inNbParticles, inPositionBuffer, inLeadingPosition, inAttributesBuffer, inLeadingAttributes) { + + } + + /** + * @brief getDataDown + * @return + */ + long long int* getDataDown(){ + return Parent::getAttribute<0>(); + } + + /** + * @brief getDataDown + * @return + */ + const long long int* getDataDown() const { + return Parent::getAttribute<0>(); + } +}; + +#endif // FGROUPTESTPARTICLECONTAINER_HPP diff --git a/Tests/noDist/testBlockedAlgorithm.cpp b/Tests/noDist/testBlockedAlgorithm.cpp new file mode 100644 index 000000000..6eb7340c9 --- /dev/null +++ b/Tests/noDist/testBlockedAlgorithm.cpp @@ -0,0 +1,79 @@ +#include "../../Src/GroupTree/FGroupTree.hpp" + +#include "../../Src/Components/FSimpleLeaf.hpp" +#include "../../Src/Containers/FVector.hpp" + +#include "../../Src/Kernels/P2P/FP2PParticleContainer.hpp" + +#include "../../Src/Utils/FMath.hpp" +#include "../../Src/Utils/FMemUtils.hpp" +#include "../../Src/Utils/FParameters.hpp" + +#include "../../Src/Files/FRandomLoader.hpp" + +#include "../../Src/GroupTree/FGroupSeqAlgorithm.hpp" + +#include "../../Src/Utils/FParameterNames.hpp" + +#include "../../Src/Components/FTestCell.hpp" +#include "../../Src/Components/FTestKernels.hpp" +#include "../Src/GroupTree/FGroupTestParticleContainer.hpp" + +int main(int argc, char* argv[]){ + const FParameterNames LocalOptionBlocSize { + {"-bs"}, + "The size of the block of the blocked tree" + }; + FHelpDescribeAndExit(argc, argv, "Test the blocked tree by counting the particles.", + FParameterDefinitions::OctreeHeight, + FParameterDefinitions::NbParticles, LocalOptionBlocSize); + // Initialize the types + typedef FTestCell GroupCellClass; + typedef FGroupTestParticleContainer GroupContainerClass; + typedef FSimpleLeaf< GroupContainerClass > LeafClass; + typedef FGroupTree< GroupCellClass, GroupContainerClass, 2, long long int> GroupOctreeClass; + typedef FTestKernels< GroupCellClass, GroupContainerClass > GroupKernelClass; + typedef FGroupSeqAlgorithm<GroupOctreeClass, typename GroupOctreeClass::CellGroupClass, GroupCellClass, GroupKernelClass, typename GroupOctreeClass::ParticleGroupClass, GroupContainerClass > GroupAlgorithm; + // Get params + const int NbLevels = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeHeight.options, 5); + const int NbParticles = FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, 20); + const int groupSize = FParameters::getValue(argc,argv,LocalOptionBlocSize.options, 250); + + // Load the particles + FRandomLoader loader(NbParticles, 1.0, FPoint(0,0,0), 0); + FAssertLF(loader.isOpen()); + FP2PParticleContainer<> allParticles; + for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){ + FPoint particlePosition; + loader.fillParticle(&particlePosition); + allParticles.push(particlePosition); + } + + // Put the data into the tree + GroupOctreeClass groupedTree(NbLevels, loader.getBoxWidth(), loader.getCenterOfBox(), groupSize, &allParticles); + groupedTree.printInfoBlocks(); + + // Run the algorithm + GroupKernelClass kernel; + GroupAlgorithm algo(&groupedTree,&kernel); + algo.execute(); + + // Validate the result + groupedTree.forEachCellLeaf<FGroupTestParticleContainer>([&](GroupCellClass* cell, FGroupTestParticleContainer* leaf){ + const int nbPartsInLeaf = leaf->getNbParticles(); + if(cell->getDataUp() != nbPartsInLeaf){ + std::cout << "[P2M] Error a Cell has " << cell->getDataUp() << " (it should be " << nbPartsInLeaf << ")\n"; + } + }); + groupedTree.forEachCellLeaf<FGroupTestParticleContainer>([&](GroupCellClass* cell, FGroupTestParticleContainer* leaf){ + const int nbPartsInLeaf = leaf->getNbParticles(); + const long long int* dataDown = leaf->getDataDown(); + for(int idxPart = 0 ; idxPart < nbPartsInLeaf ; ++idxPart){ + if(dataDown[idxPart] != NbParticles-1){ + std::cout << "[Full] Error a particle has " << dataDown[idxPart] << " (it should be " << (NbParticles-1) << ") at index " << cell->getMortonIndex() << "\n"; + } + } + }); + + return 0; +} -- GitLab