testLoaderFMATsmCreate.cpp 2.91 KB
Newer Older
1
// See LICENCE file at project root
2 3 4 5

#include <iostream>
#include <fstream>

6 7
#include <cstdio>
#include <cstdlib>
8 9
#include <time.h>

10 11
#include "Utils/FGlobal.hpp"
#include "Utils/FParameters.hpp"
12

13
#include "Utils/FParameterNames.hpp"
14

15
// This file can generate basic particles files in the FMA format
16 17

int main(int argc, char ** argv){
18 19 20 21
    FHelpDescribeAndExit(argc, argv, "Create a file for the TSM (target source model)",
                         FParameterDefinitions::NbParticles, FParameterDefinitions::OutputFile,
                         FParameterDefinitions::PhysicalValue);

22
    ///////////////////////What we do/////////////////////////////
23
    std::cout << ">> This executable can create a FMA-like particles files (this is not a fma file!)";
24 25 26
    std::cout << ">> You can pass a filename in parameter else the program will use\n";
    std::cout << ">> a default filename.\n";
    std::cout << ">> The format of the file is : \n";
27
    std::cout << ">> [number of particles] \n";
28 29 30
    std::cout << ">> [boxe width] [boxe x center] [boxe y center] [boxe z center]\n";
    std::cout << ">> [x] [y] [z] [physical value] [1 if target 0 if source]...\n";
    //////////////////////////////////////////////////////////////
31
    // Nb of particles
32
    typedef double FReal;
33 34
    const long NbParticles = FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, long(20000));
    const FReal physicalValue = FParameters::getValue(argc,argv,FParameterDefinitions::PhysicalValue.options, FReal(0.1));
35

36 37 38 39 40 41 42 43
    // Center of the box
    const FReal XCenter = 0.5;
    const FReal YCenter = 0.5;
    const FReal ZCenter = 0.5;

    // Box width
    const FReal BoxWidth = 1.0/2;
    // Output file please let .temp extension
44
    const char* const Output = FParameters::getStr(argc,argv,FParameterDefinitions::OutputFile.options, "../Data/test20k.tsm.fma");
45
    std::cout << "Creating : " << Output << "\n";
46 47 48 49 50 51 52 53 54 55

    // Create file
    std::ofstream myfile;
    myfile.open (Output);

    if(!myfile.is_open()){
        std::cout << "Cannot create " << Output << "\n";
        return 1;
    }

56
    std::cout << "Generating " << NbParticles << " in " << Output << "\n";
57 58 59
    std::cout << "Working...\n";

    // System properties
60
    myfile << NbParticles << "\n";
61
    myfile << BoxWidth << "\t" << XCenter << "\t" << YCenter << "\t" << ZCenter;
62
	srand48( static_cast<long>(time(nullptr))) ;
63

64 65
    // Generate particles
    for( long idx = 0 ; idx < NbParticles ; ++idx ){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
66 67 68
        const FReal px = ((FReal(drand48())) * BoxWidth * FReal(2)) + XCenter - BoxWidth;
        const FReal py = ((FReal(drand48())) * BoxWidth * FReal(2)) + YCenter - BoxWidth;
        const FReal pz = ((FReal(drand48())) * BoxWidth * FReal(2)) + ZCenter - BoxWidth;
69

70
        const int isTarget = drand48() > 0.5 ? 1 : 0;
71

72
        myfile << "\n" << px << "\t" << py << "\t" <<  pz << "\t" << physicalValue << "\t" << isTarget;
73 74 75 76 77 78 79 80 81 82
    }

    myfile.close();

    std::cout << "Done\n";

    return 0;
}


83