initial checkin of the new concept approach
[physik/posic.git] / init / init.c
1 /*
2  * init.c - create initial conditions
3  *
4  * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
5  *
6  */
7
8 #include "../math/math.h"
9 #include "../moldyn.h"
10
11 /* fcc lattice init */
12 int fcc_init(t_3dvec *dim,double lc,t_atom *atom,t_3dvec *origin) {
13
14         int count;
15         int i,j;
16         t_3dvec o,r,n;
17         t_3dvec basis[3];
18         double help[3];
19
20         if(origin) v3_copy(&o,origin);
21         else v3_zero(&o);
22
23         /* construct the basis */
24         for(i=0;i<3;i++) {
25                 for(j=0;j<3;j++) {
26                         if(i!=j) help[j]=0.5*lc;
27                         else help[j]=.0;
28                 }
29                 v3_set(&basis[i],help);
30         }
31
32         v3_zero(&r);
33         v3_add(&r,&r,&o);
34         count=0;
35         
36         /* fill up the room */
37         while(r.x<dim->x) {
38                 while(r.y<dim->y) {
39                         while(r.z<dim->z) {
40                                 v3_copy(&(atom[count].r),&r);
41                                 count+=1;
42                                 for(i=0;i<3;i++) {
43                                         v3_add(&n,&r,&basis[i]);
44                                         if((n.x<dim->x+o.x)&&(n.y<dim->y+o.y)&&(n.z<dim->z+o.z)) {
45                                                 v3_copy(&(atom[count].r),&n);
46                                                 count+=1;
47                                         }
48                                 }
49                                 r.z+=lc;        
50                         }
51                         r.y+=lc;
52                 }
53                 r.x+=lc;
54         }
55
56         /* coordinate transformation */
57         help[0]=dim->x/2.0;
58         help[1]=dim->y/2.0;
59         help[2]=dim->z/2.0;
60         v3_set(&n,help);
61         for(i=0;i<count;i++)
62                 v3_sub(&(atom[i].r),&(atom[i].r),&n);
63                 
64         return count;
65 }
66
67 int diamond_init(t_3dvec *dim,double lc,t_atom *atom,t_3dvec *origin) {
68
69         int count;
70         t_3dvec o;
71
72         count=fcc_init(dim,lc,atom,origin);
73
74         o.x=0.25*lc;
75         o.y=0.25*lc;
76         o.z=0.25*lc;
77
78         if(origin) v3_add(&o,&o,origin);
79
80         count+=fcc_init(dim,lc,&atom[count],&o);
81
82
83         return count;
84 }