Implementation of output

In a grid-model the atoms move from site to site. If we loop over the sites in the output function, the atoms would be printed in a more or less random sequence. However, most file-formats require that the atoms in a fixed sequence.

The variable seq is used to print the data for the atoms in a fixed sequence.

When the sites are allocated, we initialize seq where size is the size of the grid.

    for (iy = 0; iy < size; iy++)
        for (ix = 0; ix < size; ix++)
        {
            site[ix+size*iy].seq = ix+size*iy;
            ...
        }

When an atom moves from one site, c, to another n, we swap both id and seq:

void  swapAtm(struct SITE * c, struct SITE * n)
{
        int             t;
        ...
        t = c->id;
        c->id = n->id;
        n->id = t;
        t = c->seq;
        c->seq = n->seq;
        n->seq = t;
}

In the output routine, the sites are first loaded into an array based seq for each site and then printed in the original sequence of the atoms

       struct LIST
       {
               float x,y;
               int id;
       } *list;
       int is;

       list=malloc(size*size*sizeof(struct LIST *));

       for(ix=0; ix < size; ix++)
               for(iy=0; iy < size; iy++)
               {
                   is=site[ix+size*iy].seq;
                   list[is].id = site[ix+size*iy].id;
                   list[is].x = ix/(double)size;
                   list[is].y = iy/(double)size;
               }

       for(is=0; is < size*size; is++)
           printf("%d %.3f %.3f\n", list[is].id, list[is].x, list[is].y);

       free(list);

This algorithm has several features. The geometry of the grid is completely encoded in the links between the sites and the storage of the position of each site would be redundant. Further, the mapping of the sites into a fixed sequence will work for any geometry and dimension of the grid.


Source
Start
Back
Author Per Stoltze stoltze@fysik.dtu.dk