testTreeIO.cpp 3.76 KB
Newer Older
1
// See LICENCE file at project root
2 3 4

#include <iostream>

5 6
#include <cstdio>
#include <cstdlib>
COULAUD Olivier's avatar
COULAUD Olivier committed
7
#include <string>
8

9 10
#include "Utils/FTic.hpp"
#include "Utils/FParameters.hpp"
11

12 13
#include "Containers/FOctree.hpp"
#include "Containers/FVector.hpp"
14 15


16 17
#include "Files/FFmaGenericLoader.hpp"
#include "Files/FTreeIO.hpp"
18

19 20 21
#include "Kernels/Spherical/FSphericalCell.hpp"
#include "Components/FSimpleLeaf.hpp"
#include "Utils/FParameterNames.hpp"
22

23
#include "Kernels/P2P/FP2PParticleContainer.hpp"
24

COULAUD Olivier's avatar
COULAUD Olivier committed
25 26 27 28 29 30 31 32 33
void usage() {
	std::cout << "Exemple to store and load a tree" << std::endl;
	std::cout <<	 "Options  "<< std::endl
			<<     "      -help         to see the parameters    " << std::endl
			<<	  "      -depth       the depth of the octree   "<< std::endl
			<<	  "      -subdepth  specifies the size of the sub octree   " << std::endl
			<<     "      -fin    name    name specifies the file of the particle distribution" << std::endl
			<<     "      -fout   name    file name of the octree  " << std::endl;
}
34 35
// Simply create particles and try the kernels
int main(int argc, char ** argv){
36 37 38 39
    FHelpDescribeAndExit(argc, argv,
                         "Load and store a tree (only the code is interesting).",
                         FParameterDefinitions::InputFile, FParameterDefinitions::OctreeHeight,
                         FParameterDefinitions::OctreeSubHeight, FParameterDefinitions::OutputFile);
40

41 42
    typedef double FReal;

43
	typedef FSphericalCell<FReal>                 CellClass;
44
	typedef FP2PParticleContainer<FReal>         ContainerClass;
45

46 47
	typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
	typedef FOctree<FReal, CellClass, ContainerClass , LeafClass >  OctreeClass;
48

COULAUD Olivier's avatar
COULAUD Olivier committed
49 50 51
	///////////////////////What we do/////////////////////////////
	std::cout << ">> This executable has to be used to load or retrieve an entier tree.\n";
	//////////////////////////////////////////////////////////////
52 53
    const unsigned int TreeHeight       = FParameters::getValue(argc, argv, FParameterDefinitions::OctreeHeight.options, 5);
    const unsigned int SubTreeHeight  = FParameters::getValue(argc, argv, FParameterDefinitions::OctreeSubHeight.options, 2);
54

COULAUD Olivier's avatar
COULAUD Olivier committed
55
	FTic counter;
56 57
    const std::string filenameIN     = FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options, "../Data/test20k.fma");
    const std::string filenameOUT = FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "tmp_tree.data");
COULAUD Olivier's avatar
COULAUD Olivier committed
58
	std::cout << "Opening : " << filenameIN << "\n";
59

60
	FFmaGenericLoader<FReal> loader(filenameIN);
COULAUD Olivier's avatar
COULAUD Olivier committed
61 62 63 64
	//
	// -----------------------------------------------------
	CellClass::Init(5);
	OctreeClass tree(TreeHeight, SubTreeHeight, loader.getBoxWidth(), loader.getCenterOfBox());
65

COULAUD Olivier's avatar
COULAUD Olivier committed
66
	// -----------------------------------------------------
67

COULAUD Olivier's avatar
COULAUD Olivier committed
68 69 70
	std::cout << "Creating & Inserting " << loader.getNumberOfParticles() << " particles ..." << std::endl;
	std::cout << "\tHeight : " << TreeHeight << " \t sub-height : " << SubTreeHeight << std::endl;
	counter.tic();
71

72
	for(FSize idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
73
        FPoint<FReal> particlePosition;
COULAUD Olivier's avatar
COULAUD Olivier committed
74 75 76 77
		FReal physicalValue = 0.0;
		loader.fillParticle(&particlePosition,&physicalValue);
		tree.insert(particlePosition, physicalValue );
	}
78

COULAUD Olivier's avatar
COULAUD Olivier committed
79 80
	counter.tac();
	std::cout << "Done  " << "(@Creating and Inserting Particles = " << counter.elapsed() << "s)." << std::endl;
81

COULAUD Olivier's avatar
COULAUD Olivier committed
82
	// -----------------------------------------------------
83

COULAUD Olivier's avatar
COULAUD Olivier committed
84
	std::cout << "Save tree in binary format ..." << std::endl;
85

86
    FTreeIO<FReal>::Save<OctreeClass, CellClass, LeafClass, ContainerClass >(filenameOUT.c_str(), tree);
87

COULAUD Olivier's avatar
COULAUD Olivier committed
88
	// -----------------------------------------------------
89

COULAUD Olivier's avatar
COULAUD Olivier committed
90
	std::cout << "Load tree in binary format  ..." << std::endl;
91

92
    FTreeIO<FReal>::Load<OctreeClass, CellClass, LeafClass, ContainerClass >(filenameOUT.c_str(),tree);
93

COULAUD Olivier's avatar
COULAUD Olivier committed
94
	return 0;
95 96 97
}


98