more changes ...
[physik/posic.git] / moldyn.c
index 8b80242..fe54330 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -227,20 +227,22 @@ int moldyn_shutdown(t_moldyn *moldyn) {
        return 0;
 }
 
-int create_lattice(u8 type,int element,double mass,double lc,
-                   int a,int b,int c,t_atom **atom) {
+int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
+                   u8 attr,u8 bnum,int a,int b,int c) {
 
        int count;
        int ret;
        t_3dvec origin;
+       t_atom *atom;
 
        count=a*b*c;
+       atom=moldyn->atom;
 
        if(type==FCC) count*=4;
        if(type==DIAMOND) count*=8;
 
-       *atom=malloc(count*sizeof(t_atom));
-       if(*atom==NULL) {
+       atom=malloc(count*sizeof(t_atom));
+       if(atom==NULL) {
                perror("malloc (atoms)");
                return -1;
        }
@@ -249,10 +251,10 @@ int create_lattice(u8 type,int element,double mass,double lc,
 
        switch(type) {
                case FCC:
-                       ret=fcc_init(a,b,c,lc,*atom,&origin);
+                       ret=fcc_init(a,b,c,lc,atom,&origin);
                        break;
                case DIAMOND:
-                       ret=diamond_init(a,b,c,lc,*atom,&origin);
+                       ret=diamond_init(a,b,c,lc,atom,&origin);
                        break;
                default:
                        printf("unknown lattice type (%02x)\n",type);
@@ -268,17 +270,45 @@ int create_lattice(u8 type,int element,double mass,double lc,
        }
 
        while(count) {
-               (*atom)[count-1].element=element;
-               (*atom)[count-1].mass=mass;
+               atom[count-1].element=element;
+               atom[count-1].mass=mass;
+               atom[count-1].attr=attr;
+               atom[count-1].bnum=bnum;
                count-=1;
        }
 
        return ret;
 }
 
-int destroy_lattice(t_atom *atom) {
+int add_atom(t_moldyn *moldyn,int element,double mass,u8 bnum,u8 attr,
+             t_3dvec r,t_3dvec v) {
+
+       t_atom *atom;
+       void *ptr;
+       int count;
+       
+       atom=moldyn->atom;
+       count=++(moldyn->count);
+
+       ptr=realloc(atom,count*sizeof(t_atom));
+       if(!ptr) {
+               perror("[moldyn] realloc (add atom)");
+               return -1;
+       }
+       
+       atom=ptr;
+       atom->r=r;
+       atom->v=v;
+       atom->element=element;
+       atom->bnum=bnum;
+       atom->attr=attr;
+
+       return 0;
+}
+
+int destroy_atoms(t_moldyn *moldyn) {
 
-       if(atom) free(atom);
+       if(moldyn->atom) free(moldyn->atom);
 
        return 0;
 }
@@ -547,6 +577,40 @@ int link_cell_shutdown(t_moldyn *moldyn) {
        return 0;
 }
 
+int moldyn_add_schedule(t_moldyn *moldyn,int runs,double tau ) {
+
+       int count;
+       void *ptr;
+       t_moldyn_schedule *schedule;
+
+       schedule=moldyn->schedule;
+       count=++(schedule->content_count);
+
+       ptr=realloc(moldyn->schedule.runs,count*sizeof(int));
+       if(!ptr) {
+               perror("[moldyn] realloc (runs)");
+               return -1;
+       }
+       moldyn->schedule.runs[count-1]=runs;
+
+       ptr=realloc(schedule->tau,count*sizeof(double));
+       if(!ptr) {
+               perror("[moldyn] realloc (tau)");
+               return -1;
+       }
+       moldyn->schedule.tau[count-1]=tau;
+
+       return 0;
+}
+
+int moldyn_set_schedule_hook(t_moldyn *moldyn,void *hook,void *hook_params) {
+
+       moldyn->schedule.hook=hook;
+       moldyn->schedule.hook_params=hook_params;
+       
+       return 0;
+}
+
 /*
  *
  * 'integration of newtons equation' - algorithms
@@ -587,10 +651,13 @@ int moldyn_integrate(t_moldyn *moldyn) {
        moldyn->potential_force_function(moldyn);
 
        for(sched=0;sched<moldyn->schedule.content_count;sched++) {
-               moldyn->tau=;
-               moldyn->tau_square=;
 
-       // hier weiter ...
+               /* setting amont of runs and finite time step size */
+               moldyn->tau=schedule->tau[sched];
+               moldyn->tau_square=moldyn->tau*moldyn->tau;
+               moldyn->timesteps=schedule->runs[sched];
+
+       /* integration according to schedule */
 
        for(i=0;i<moldyn->time_steps;i++) {
 
@@ -636,6 +703,10 @@ int moldyn_integrate(t_moldyn *moldyn) {
                }
        }
 
+               /* check for hooks */
+               if(schedule->hook)
+                       schedule->hook(moldyn,schedule->hook_params);
+
        return 0;
 }