testLoaderFMATsmCreate.cpp 3.07 KB
Newer Older
1
// ===================================================================================
2 3 4 5 6 7 8 9
// Logiciel initial: ScalFmm Version 0.5
// Co-auteurs : Olivier Coulaud, Bérenger Bramas.
// Propriétaires : INRIA.
// Copyright © 2011-2012, diffusé sous les termes et conditions d’une licence propriétaire.
// Initial software: ScalFmm Version 0.5
// Co-authors: Olivier Coulaud, Bérenger Bramas.
// Owners: INRIA.
// Copyright © 2011-2012, spread under the terms and conditions of a proprietary license.
10
// ===================================================================================
berenger-bramas's avatar
berenger-bramas committed
11 12 13 14

#include <iostream>
#include <fstream>

15 16
#include <cstdio>
#include <cstdlib>
berenger-bramas's avatar
berenger-bramas committed
17 18
#include <time.h>

19 20
#include "../../Src/Utils/FGlobal.hpp"
#include "../../Src/Utils/FParameters.hpp"
berenger-bramas's avatar
berenger-bramas committed
21

22
// This file can generate basic particles files in the FMA format
23 24 25

int main(int argc, char ** argv){
    ///////////////////////What we do/////////////////////////////
26
    std::cout << ">> This executable can create a FMA-like particles files (this is not a fma file!)";
27 28 29
    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";
30
    std::cout << ">> [number of particles] \n";
31 32 33
    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";
    //////////////////////////////////////////////////////////////
34
    // Nb of particles
35
    const long NbParticles = FParameters::getValue(argc,argv,"-nb", long(20000));
36 37
    const FReal physicalValue = FParameters::getValue(argc,argv,"-pv", FReal(0.1));

38
    const FReal FRandMax = FReal(RAND_MAX);
berenger-bramas's avatar
berenger-bramas committed
39 40 41 42 43 44 45 46 47

    // 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
48 49
    const char* const Output = FParameters::getStr(argc,argv,"-f", "../Data/test20k.tsm.fma");
    std::cout << "Creating : " << Output << "\n";
berenger-bramas's avatar
berenger-bramas committed
50 51 52 53 54 55 56 57 58 59

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

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

60
    std::cout << "Generating " << NbParticles << " in " << Output << "\n";
berenger-bramas's avatar
berenger-bramas committed
61 62 63
    std::cout << "Working...\n";

    // System properties
64
    myfile << NbParticles << "\n";
berenger-bramas's avatar
berenger-bramas committed
65 66
    myfile << BoxWidth << "\t" << XCenter << "\t" << YCenter << "\t" << ZCenter;

67 68
    // Generate particles
    for( long idx = 0 ; idx < NbParticles ; ++idx ){
69 70 71
        const FReal px = ((FReal(rand())/FRandMax) * BoxWidth * FReal(2)) + XCenter - BoxWidth;
        const FReal py = ((FReal(rand())/FRandMax) * BoxWidth * FReal(2)) + YCenter - BoxWidth;
        const FReal pz = ((FReal(rand())/FRandMax) * BoxWidth * FReal(2)) + ZCenter - BoxWidth;
berenger-bramas's avatar
berenger-bramas committed
72 73 74

        const int isTarget = rand() > RAND_MAX/2 ? 1 : 0;

75
        myfile << "\n" << px << "\t" << py << "\t" <<  pz << "\t" << physicalValue << "\t" << isTarget;
berenger-bramas's avatar
berenger-bramas committed
76 77 78 79 80 81 82 83 84 85
    }

    myfile.close();

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

    return 0;
}


86