Exemplo n.º 1
0
unsigned Convolution(CONFIG &config)
{
    time_t  time1, time2;
    time(&time1);
    int dim;

    cout << "Add " << config.atoms_box << " atoms to the box" << endl;

    for(int i = 0; i < config.atoms_box; i++) // check all atoms of this grain
    {
        for(dim=0; dim < 3; dim++)
        {
            if (config.atom_box[i].r(dim) >  config.shift(dim)) config.atom_box[i].r(dim) -= config.l(dim);
            else
            if (config.atom_box[i].r(dim) < -config.shift(dim)) config.atom_box[i].r(dim) += config.l(dim);
        }
    }

    time(&time2);
    if (config.time) cout << "Done in " << time2-time1 << " s." << endl;

    return 0;
}
Exemplo n.º 2
0
unsigned IniGrainCenters(CONFIG& config)
{
    Vector3d a;
    Vector3d rotv;
    Vector3d rtmp;
    double angle;
    time_t  time1, time2;
    time(&time1);


    cout << "Initialize grain centers ";
    for (int ig=0; ig<config.grains; ig++)
    {
        for (int dim=0; dim<3; dim++)
        {
            config.grain[ig].r(dim) = config.shift(dim) * (rand()%2000000/1000000. - 1);
        }

        for (unsigned j=0; j<3; j++)
        {
            config.grain[ig].angle(j) = 2.0 * M_PI * (rand()%1000000/1000000.);
        }

        a = config.grain[ig].angle;
        rotv << 1/cos(a(0))*sin(a(1)), 1/sin(a(0))*sin(a(1)), 1/cos(a(1));
        angle = -a(2);
        rtmp = -config.grain[ig].r;
        config.grain[ig].rotvT = rtmp * cos(angle) + rotv.cross(rtmp) * sin(angle) + (1 - cos(angle)) * rotv *(rotv.dot(rtmp)) + config.grain[ig].r; //  Rodrigue's rotation formula
        cout << ".";
    }

    time(&time2);
    if (config.time) cout << endl << "Done in " << time2-time1 << " s.";
    cout << endl;
    return 0;
}