testLoaderFMABinCreate.cpp 3.19 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
// ===================================================================================
11 12 13 14 15

#include <iostream>
#include <fstream>

#include <cstdio>
16
#include <cstdlib>
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <time.h>

#include "../Src/Utils/FGlobal.hpp"
#include "../Src/Utils/FParameters.hpp"

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

int main(int argc, char ** argv){
    ///////////////////////What we do/////////////////////////////
    std::cout << ">> This executable can create a FMA particles files\n";
    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";
    std::cout << ">> [number of particles] \n";
    std::cout << ">> [boxe width] [boxe x center] [boxe y center] [boxe z center]\n";
    std::cout << ">> [x] [y] [z] [physical value]...\n";
    //////////////////////////////////////////////////////////////

    // Nb of particles
36
    const FSize NbParticles = FParameters::getValue(argc,argv,"-nb", FSize(20000));
37 38 39 40 41 42 43 44 45

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

    // Create file
    FILE* const myfile = fopen(Output, "wb");
    if(!myfile){
        std::cout << "Cannot create " << Output << "\n";
        return 1;
    }

    std::cout << "Generating " << NbParticles << " in " << Output << "\n";
    std::cout << "Working...\n";

    // System properties
    const int sizeOfFreal = int(sizeof(FReal));
61
    const FReal FRandMax = FReal(RAND_MAX);
62

63 64
    fwrite(&sizeOfFreal, sizeof(int),   1, myfile);
    fwrite(&NbParticles, sizeof(FSize), 1, myfile);
65

66 67 68 69
    fwrite(&BoxWidth,   sizeof(FReal), 1, myfile);
    fwrite(&XCenter,    sizeof(FReal), 1, myfile);
    fwrite(&YCenter,    sizeof(FReal), 1, myfile);
    fwrite(&ZCenter,    sizeof(FReal), 1, myfile);
70

71 72 73
    const FReal Limite = FReal(0.00001);
    const FReal LimitedBoxWidth = BoxWidth - Limite * 2;

74
    FReal data[4];
75
    data[3] = FReal(0.1);
76
    // Generate particles
77
    for( FSize idx = 0 ; idx < NbParticles ; ++idx ){
78 79 80
        data[0] = ((FReal(rand())/FRandMax) * LimitedBoxWidth * 2) + XCenter - BoxWidth + Limite;
        data[1] = ((FReal(rand())/FRandMax) * LimitedBoxWidth * 2) + YCenter - BoxWidth + Limite;
        data[2] = ((FReal(rand())/FRandMax) * LimitedBoxWidth * 2) + ZCenter - BoxWidth + Limite;
81 82 83 84 85 86 87 88 89 90 91 92

        fwrite(&data, sizeof(FReal), 4, myfile);
    }

    fclose(myfile);

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

    return 0;
}


93