init testing
[physik/posic.git] / moldyn.c
1 /*
2  * moldyn.c - molecular dynamics library main file
3  *
4  * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
5  *
6  */
7
8 #include "moldyn.h"
9
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 #include "math/math.h"
14 #include "init/init.h"
15
16
17 int create_lattice(unsigned char type,int element,double mass,double lc,
18                    int a,int b,int c,t_atom **atom) {
19
20         int count;
21         int ret;
22         t_3dvec origin;
23
24         count=a*b*c;
25
26         if(type==FCC) count*=4;
27         if(type==DIAMOND) count*=8;
28
29         *atom=malloc(count*sizeof(t_atom));
30         if(*atom==NULL) {
31                 perror("malloc (atoms)");
32                 return -1;
33         }
34
35         v3_zero(&origin);
36
37         switch(type) {
38                 case FCC:
39                         ret=fcc_init(a,b,c,lc,*atom,&origin);
40                         break;
41                 case DIAMOND:
42                         ret=diamond_init(a,b,c,lc,*atom,&origin);
43                         break;
44                 default:
45                         ret=-1;
46                         printf("unknown lattice type (%02x)\n",type);
47         }
48
49         /* debug */
50         if(ret!=count) {
51                 printf("ok, there is something wrong ...\n");
52                 printf("calculated -> %d atoms\n",count);
53                 printf("created -> %d atoms\n",ret);
54         }
55
56         while(count) {
57                 (*atom)[count-1].element=element;
58                 (*atom)[count-1].mass=mass;
59                 count-=1;
60         }
61
62         return ret;
63 }
64