2 * moldyn.c - molecular dynamics library main file
4 * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
12 #include <sys/types.h>
20 #include <fpu_control.h>
26 #if defined PTHREADS || defined VISUAL_THREAD
31 #include "report/report.h"
33 /* potential includes */
34 #include "potentials/harmonic_oscillator.h"
35 #include "potentials/lennard_jones.h"
36 #include "potentials/albe.h"
38 #include "potentials/tersoff_orig.h"
40 #include "potentials/tersoff.h"
54 pthread_mutex_t *amutex;
55 pthread_mutex_t emutex;
59 * the moldyn functions
62 int moldyn_init(t_moldyn *moldyn,int argc,char **argv) {
64 printf("[moldyn] init\n");
66 /* only needed if compiled without -msse2 (float-store prob!) */
69 memset(moldyn,0,sizeof(t_moldyn));
74 rand_init(&(moldyn->random),NULL,1);
75 moldyn->random.status|=RAND_STAT_VERBOSE;
78 pthread_mutex_init(&emutex,NULL);
84 int moldyn_shutdown(t_moldyn *moldyn) {
90 printf("[moldyn] shutdown\n");
93 for(i=0;i<moldyn->count;i++)
94 pthread_mutex_destroy(&(amutex[i]));
96 pthread_mutex_destroy(&emutex);
99 moldyn_log_shutdown(moldyn);
100 link_cell_shutdown(moldyn);
101 rand_close(&(moldyn->random));
107 int set_int_alg(t_moldyn *moldyn,u8 algo) {
109 printf("[moldyn] integration algorithm: ");
112 case MOLDYN_INTEGRATE_VERLET:
113 moldyn->integrate=velocity_verlet;
114 printf("velocity verlet\n");
117 printf("unknown integration algorithm: %02x\n",algo);
125 int set_cutoff(t_moldyn *moldyn,double cutoff) {
127 moldyn->cutoff=cutoff;
128 moldyn->cutoff_square=cutoff*cutoff;
130 printf("[moldyn] cutoff [A]: %f\n",moldyn->cutoff);
135 int set_temperature(t_moldyn *moldyn,double t_ref) {
139 printf("[moldyn] temperature [K]: %f\n",moldyn->t_ref);
144 int set_pressure(t_moldyn *moldyn,double p_ref) {
148 printf("[moldyn] pressure [bar]: %f\n",moldyn->p_ref/BAR);
153 int set_p_scale(t_moldyn *moldyn,u8 ptype,double ptc) {
155 moldyn->pt_scale&=(~(P_SCALE_MASK));
156 moldyn->pt_scale|=ptype;
159 printf("[moldyn] p scaling:\n");
161 printf(" p: %s",ptype?"yes":"no ");
163 printf(" | type: %02x | factor: %f",ptype,ptc);
169 int set_t_scale(t_moldyn *moldyn,u8 ttype,double ttc) {
171 moldyn->pt_scale&=(~(T_SCALE_MASK));
172 moldyn->pt_scale|=ttype;
175 printf("[moldyn] t scaling:\n");
177 printf(" t: %s",ttype?"yes":"no ");
179 printf(" | type: %02x | factor: %f",ttype,ttc);
185 int set_pt_scale(t_moldyn *moldyn,u8 ptype,double ptc,u8 ttype,double ttc) {
187 moldyn->pt_scale=(ptype|ttype);
191 printf("[moldyn] p/t scaling:\n");
193 printf(" p: %s",ptype?"yes":"no ");
195 printf(" | type: %02x | factor: %f",ptype,ptc);
198 printf(" t: %s",ttype?"yes":"no ");
200 printf(" | type: %02x | factor: %f",ttype,ttc);
206 int set_dim(t_moldyn *moldyn,double x,double y,double z,u8 visualize) {
212 moldyn->volume=x*y*z;
220 printf("[moldyn] dimensions in A and A^3 respectively:\n");
221 printf(" x: %f\n",moldyn->dim.x);
222 printf(" y: %f\n",moldyn->dim.y);
223 printf(" z: %f\n",moldyn->dim.z);
224 printf(" volume: %f\n",moldyn->volume);
225 printf(" visualize simulation box: %s\n",visualize?"yes":"no");
230 int set_nn_dist(t_moldyn *moldyn,double dist) {
237 int set_pbc(t_moldyn *moldyn,u8 x,u8 y,u8 z) {
239 printf("[moldyn] periodic boundary conditions:\n");
242 moldyn->status|=MOLDYN_STAT_PBX;
245 moldyn->status|=MOLDYN_STAT_PBY;
248 moldyn->status|=MOLDYN_STAT_PBZ;
250 printf(" x: %s\n",x?"yes":"no");
251 printf(" y: %s\n",y?"yes":"no");
252 printf(" z: %s\n",z?"yes":"no");
257 int set_potential(t_moldyn *moldyn,u8 type) {
260 case MOLDYN_POTENTIAL_TM:
261 moldyn->func1b=tersoff_mult_1bp;
262 moldyn->func3b_j1=tersoff_mult_3bp_j1;
263 moldyn->func3b_k1=tersoff_mult_3bp_k1;
264 moldyn->func3b_j2=tersoff_mult_3bp_j2;
265 moldyn->func3b_k2=tersoff_mult_3bp_k2;
266 moldyn->check_2b_bond=tersoff_mult_check_2b_bond;
268 case MOLDYN_POTENTIAL_AM:
269 moldyn->func3b_j1=albe_mult_3bp_j1;
270 moldyn->func3b_k1=albe_mult_3bp_k1;
271 moldyn->func3b_j2=albe_mult_3bp_j2;
272 moldyn->func3b_k2=albe_mult_3bp_k2;
273 moldyn->check_2b_bond=albe_mult_check_2b_bond;
275 case MOLDYN_POTENTIAL_HO:
276 moldyn->func2b=harmonic_oscillator;
277 moldyn->check_2b_bond=harmonic_oscillator_check_2b_bond;
279 case MOLDYN_POTENTIAL_LJ:
280 moldyn->func2b=lennard_jones;
281 moldyn->check_2b_bond=lennard_jones_check_2b_bond;
284 printf("[moldyn] set potential: unknown type %02x\n",
292 int set_avg_skip(t_moldyn *moldyn,int skip) {
294 printf("[moldyn] skip %d steps before starting average calc\n",skip);
295 moldyn->avg_skip=skip;
300 int moldyn_set_log_dir(t_moldyn *moldyn,char *dir) {
302 strncpy(moldyn->vlsdir,dir,127);
307 int moldyn_set_report(t_moldyn *moldyn,char *author,char *title) {
309 strncpy(moldyn->rauthor,author,63);
310 strncpy(moldyn->rtitle,title,63);
315 int moldyn_set_log(t_moldyn *moldyn,u8 type,int timer) {
320 printf("[moldyn] set log: ");
323 case LOG_TOTAL_ENERGY:
324 moldyn->ewrite=timer;
325 snprintf(filename,127,"%s/energy",moldyn->vlsdir);
326 moldyn->efd=open(filename,
327 O_WRONLY|O_CREAT|O_EXCL,
330 perror("[moldyn] energy log fd open");
333 dprintf(moldyn->efd,"# total energy log file\n");
334 printf("total energy (%d)\n",timer);
336 case LOG_TOTAL_MOMENTUM:
337 moldyn->mwrite=timer;
338 snprintf(filename,127,"%s/momentum",moldyn->vlsdir);
339 moldyn->mfd=open(filename,
340 O_WRONLY|O_CREAT|O_EXCL,
343 perror("[moldyn] momentum log fd open");
346 dprintf(moldyn->efd,"# total momentum log file\n");
347 printf("total momentum (%d)\n",timer);
350 moldyn->pwrite=timer;
351 snprintf(filename,127,"%s/pressure",moldyn->vlsdir);
352 moldyn->pfd=open(filename,
353 O_WRONLY|O_CREAT|O_EXCL,
356 perror("[moldyn] pressure log file\n");
359 dprintf(moldyn->pfd,"# pressure log file\n");
360 printf("pressure (%d)\n",timer);
362 case LOG_TEMPERATURE:
363 moldyn->twrite=timer;
364 snprintf(filename,127,"%s/temperature",moldyn->vlsdir);
365 moldyn->tfd=open(filename,
366 O_WRONLY|O_CREAT|O_EXCL,
369 perror("[moldyn] temperature log file\n");
372 dprintf(moldyn->tfd,"# temperature log file\n");
373 printf("temperature (%d)\n",timer);
376 moldyn->vwrite=timer;
377 snprintf(filename,127,"%s/volume",moldyn->vlsdir);
378 moldyn->vfd=open(filename,
379 O_WRONLY|O_CREAT|O_EXCL,
382 perror("[moldyn] volume log file\n");
385 dprintf(moldyn->vfd,"# volume log file\n");
386 printf("volume (%d)\n",timer);
389 moldyn->swrite=timer;
390 printf("save file (%d)\n",timer);
393 moldyn->awrite=timer;
394 ret=visual_init(moldyn,moldyn->vlsdir);
396 printf("[moldyn] visual init failure\n");
399 printf("visual file (%d)\n",timer);
402 snprintf(filename,127,"%s/report.tex",moldyn->vlsdir);
403 moldyn->rfd=open(filename,
404 O_WRONLY|O_CREAT|O_EXCL,
407 perror("[moldyn] report fd open");
410 printf("report -> ");
412 snprintf(filename,127,"%s/e_plot.scr",
414 moldyn->epfd=open(filename,
415 O_WRONLY|O_CREAT|O_EXCL,
418 perror("[moldyn] energy plot fd open");
421 dprintf(moldyn->epfd,e_plot_script);
426 snprintf(filename,127,"%s/pressure_plot.scr",
428 moldyn->ppfd=open(filename,
429 O_WRONLY|O_CREAT|O_EXCL,
432 perror("[moldyn] p plot fd open");
435 dprintf(moldyn->ppfd,pressure_plot_script);
440 snprintf(filename,127,"%s/temperature_plot.scr",
442 moldyn->tpfd=open(filename,
443 O_WRONLY|O_CREAT|O_EXCL,
446 perror("[moldyn] t plot fd open");
449 dprintf(moldyn->tpfd,temperature_plot_script);
451 printf("temperature ");
453 dprintf(moldyn->rfd,report_start,
454 moldyn->rauthor,moldyn->rtitle);
458 printf("unknown log type: %02x\n",type);
465 int moldyn_log_shutdown(t_moldyn *moldyn) {
469 printf("[moldyn] log shutdown\n");
473 dprintf(moldyn->rfd,report_energy);
474 snprintf(sc,255,"cd %s && gnuplot e_plot.scr",
479 if(moldyn->mfd) close(moldyn->mfd);
483 dprintf(moldyn->rfd,report_pressure);
484 snprintf(sc,255,"cd %s && gnuplot pressure_plot.scr",
491 dprintf(moldyn->rfd,report_temperature);
492 snprintf(sc,255,"cd %s && gnuplot temperature_plot.scr",
497 dprintf(moldyn->rfd,report_end);
499 snprintf(sc,255,"cd %s && pdflatex report >/dev/null 2>&1",
502 snprintf(sc,255,"cd %s && pdflatex report >/dev/null 2>&1",
505 snprintf(sc,255,"cd %s && dvipdf report >/dev/null 2>&1",
514 * creating lattice functions
517 int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,
518 u8 attr,u8 brand,int a,int b,int c,t_3dvec *origin,
519 t_part_params *p_params,t_defect_params *d_params) {
528 pthread_mutex_t *mutex;
534 /* how many atoms do we expect */
537 printf("[moldyn] WARNING: create 'none' lattice called");
539 if(type==CUBIC) new*=1;
540 if(type==FCC) new*=4;
541 if(type==DIAMOND) new*=8;
545 switch(d_params->stype) {
546 case DEFECT_STYPE_DB_X:
547 case DEFECT_STYPE_DB_Y:
548 case DEFECT_STYPE_DB_Z:
549 case DEFECT_STYPE_DB_R:
553 printf("[moldyn] WARNING: cl unknown defect\n");
558 /* allocate space for atoms */
559 ptr=realloc(moldyn->atom,(count+new)*sizeof(t_atom));
561 perror("[moldyn] realloc (create lattice)");
565 atom=&(moldyn->atom[count]);
568 ptr=realloc(amutex,(count+new)*sizeof(pthread_mutex_t));
570 perror("[moldyn] mutex realloc (add atom)");
574 mutex=&(amutex[count]);
577 /* no atoms on the boundaries (only reason: it looks better!) */
591 set_nn_dist(moldyn,lc);
592 ret=cubic_init(a,b,c,lc,atom,&orig,p_params,d_params);
593 strcpy(name,"cubic");
597 v3_scale(&orig,&orig,0.5);
598 set_nn_dist(moldyn,0.5*sqrt(2.0)*lc);
599 ret=fcc_init(a,b,c,lc,atom,&orig,p_params,d_params);
604 v3_scale(&orig,&orig,0.25);
605 set_nn_dist(moldyn,0.25*sqrt(3.0)*lc);
606 ret=diamond_init(a,b,c,lc,atom,&orig,p_params,d_params);
607 strcpy(name,"diamond");
610 printf("unknown lattice type (%02x)\n",type);
616 printf("[moldyn] creating %s lattice (lc=%f) incomplete\n",
618 printf(" (ignore for partial lattice creation)\n");
619 printf(" amount of atoms\n");
620 printf(" - expected: %d\n",new);
621 printf(" - created: %d\n",ret);
626 printf("[moldyn] created %s lattice with %d atoms\n",name,ret);
628 for(new=0;new<ret;new++) {
629 atom[new].element=element;
630 atom[new].mass=pse_mass[element];
632 atom[new].brand=brand;
633 atom[new].tag=count+new;
634 check_per_bound(moldyn,&(atom[new].r));
635 atom[new].r_0=atom[new].r;
637 pthread_mutex_init(&(mutex[new]),NULL);
641 atom[new].element=d_params->element;
642 atom[new].mass=pse_mass[d_params->element];
643 atom[new].attr=d_params->attr;
644 atom[new].brand=d_params->brand;
645 atom[new].tag=count+new;
646 check_per_bound(moldyn,&(atom[new].r));
647 atom[new].r_0=atom[new].r;
649 pthread_mutex_init(&(mutex[new]),NULL);
655 ptr=realloc(moldyn->atom,moldyn->count*sizeof(t_atom));
657 perror("[moldyn] realloc (create lattice - alloc fix)");
662 // WHAT ABOUT AMUTEX !!!!
665 ptr=realloc(moldyn->lc.subcell->list,moldyn->count*sizeof(int));
667 perror("[moldyn] list realloc (create lattice)");
670 moldyn->lc.subcell->list=ptr;
673 /* update total system mass */
674 total_mass_calc(moldyn);
679 int add_atom(t_moldyn *moldyn,int element,u8 brand,u8 attr,
680 t_3dvec *r,t_3dvec *v) {
687 count=(moldyn->count)++; // asshole style!
689 ptr=realloc(atom,(count+1)*sizeof(t_atom));
691 perror("[moldyn] realloc (add atom)");
697 ptr=realloc(moldyn->lc.subcell->list,(count+1)*sizeof(int));
699 perror("[moldyn] list realloc (add atom)");
702 moldyn->lc.subcell->list=ptr;
706 ptr=realloc(amutex,(count+1)*sizeof(pthread_mutex_t));
708 perror("[moldyn] mutex realloc (add atom)");
712 pthread_mutex_init(&(amutex[count]),NULL);
717 /* initialize new atom */
718 memset(&(atom[count]),0,sizeof(t_atom));
721 atom[count].element=element;
722 atom[count].mass=pse_mass[element];
723 atom[count].brand=brand;
724 atom[count].tag=count;
725 atom[count].attr=attr;
726 check_per_bound(moldyn,&(atom[count].r));
727 atom[count].r_0=atom[count].r;
729 /* update total system mass */
730 total_mass_calc(moldyn);
735 int del_atom(t_moldyn *moldyn,int tag) {
739 #if defined LOWMEM_LISTS || defined PTHREADS
745 new=(t_atom *)malloc((moldyn->count-1)*sizeof(t_atom));
747 perror("[moldyn]malloc (del atom)");
751 for(cnt=0;cnt<tag;cnt++)
754 for(cnt=tag+1;cnt<moldyn->count;cnt++) {
756 new[cnt-1].tag=cnt-1;
765 ptr=realloc(moldyn->lc.subcell->list,moldyn->count*sizeof(int));
767 perror("[moldyn] list realloc (del atom)");
770 moldyn->lc.subcell->list=ptr;
772 link_cell_update(moldyn);
776 ptr=realloc(amutex,moldyn->count*sizeof(pthread_mutex_t));
778 perror("[moldyn] mutex realloc (add atom)");
782 pthread_mutex_destroy(&(amutex[moldyn->count+1]));
789 #define set_atom_positions(pos) \
790 if(d_params->type) {\
791 d_o.x=0; d_o.y=0; d_o.z=0;\
792 d_d.x=0; d_d.y=0; d_d.z=0;\
793 switch(d_params->stype) {\
794 case DEFECT_STYPE_DB_X:\
798 case DEFECT_STYPE_DB_Y:\
802 case DEFECT_STYPE_DB_Z:\
806 case DEFECT_STYPE_DB_R:\
809 printf("[moldyn] WARNING: unknown defect\n");\
812 v3_add(&dr,&pos,&d_o);\
813 v3_copy(&(atom[count].r),&dr);\
815 v3_add(&dr,&pos,&d_d);\
816 v3_copy(&(atom[count].r),&dr);\
820 v3_copy(&(atom[count].r),&pos);\
825 int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin,
826 t_part_params *p_params,t_defect_params *d_params) {
846 /* shift partition values */
848 p.x=p_params->p.x+(a*lc)/2.0;
849 p.y=p_params->p.y+(b*lc)/2.0;
850 p.z=p_params->p.z+(c*lc)/2.0;
859 switch(p_params->type) {
862 if(v3_absolute_square(&dist)<
863 (p_params->r*p_params->r)) {
864 set_atom_positions(r);
869 if(v3_absolute_square(&dist)>=
870 (p_params->r*p_params->r)) {
871 set_atom_positions(r);
876 if((fabs(dist.x)<p_params->d.x)&&
877 (fabs(dist.y)<p_params->d.y)&&
878 (fabs(dist.z)<p_params->d.z)) {
879 set_atom_positions(r);
884 if((fabs(dist.x)>=p_params->d.x)||
885 (fabs(dist.y)>=p_params->d.y)||
886 (fabs(dist.z)>=p_params->d.z)) {
887 set_atom_positions(r);
891 set_atom_positions(r);
901 for(i=0;i<count;i++) {
902 atom[i].r.x-=(a*lc)/2.0;
903 atom[i].r.y-=(b*lc)/2.0;
904 atom[i].r.z-=(c*lc)/2.0;
910 /* fcc lattice init */
911 int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin,
912 t_part_params *p_params,t_defect_params *d_params) {
930 /* construct the basis */
931 memset(basis,0,3*sizeof(t_3dvec));
939 /* shift partition values */
941 p.x=p_params->p.x+(a*lc)/2.0;
942 p.y=p_params->p.y+(b*lc)/2.0;
943 p.z=p_params->p.z+(c*lc)/2.0;
946 /* fill up the room */
954 switch(p_params->type) {
957 if(v3_absolute_square(&dist)<
958 (p_params->r*p_params->r)) {
959 set_atom_positions(r);
964 if(v3_absolute_square(&dist)>=
965 (p_params->r*p_params->r)) {
966 set_atom_positions(r);
971 if((fabs(dist.x)<p_params->d.x)&&
972 (fabs(dist.y)<p_params->d.y)&&
973 (fabs(dist.z)<p_params->d.z)) {
974 set_atom_positions(r);
979 if((fabs(dist.x)>=p_params->d.x)||
980 (fabs(dist.y)>=p_params->d.y)||
981 (fabs(dist.z)>=p_params->d.z)) {
982 set_atom_positions(r);
986 set_atom_positions(r);
989 /* the three face centered atoms */
991 v3_add(&n,&r,&basis[l]);
992 switch(p_params->type) {
995 if(v3_absolute_square(&dist)<
996 (p_params->r*p_params->r)) {
997 set_atom_positions(n);
1000 case PART_OUTSIDE_R:
1001 v3_sub(&dist,&n,&p);
1002 if(v3_absolute_square(&dist)>=
1003 (p_params->r*p_params->r)) {
1004 set_atom_positions(n);
1008 v3_sub(&dist,&n,&p);
1009 if((fabs(dist.x)<p_params->d.x)&&
1010 (fabs(dist.y)<p_params->d.y)&&
1011 (fabs(dist.z)<p_params->d.z)) {
1012 set_atom_positions(n);
1015 case PART_OUTSIDE_D:
1016 v3_sub(&dist,&n,&p);
1017 if((fabs(dist.x)>=p_params->d.x)||
1018 (fabs(dist.y)>=p_params->d.y)||
1019 (fabs(dist.z)>=p_params->d.z)) {
1020 set_atom_positions(n);
1024 set_atom_positions(n);
1035 /* coordinate transformation */
1036 for(i=0;i<count;i++) {
1037 atom[i].r.x-=(a*lc)/2.0;
1038 atom[i].r.y-=(b*lc)/2.0;
1039 atom[i].r.z-=(c*lc)/2.0;
1045 int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin,
1046 t_part_params *p_params,t_defect_params *d_params) {
1051 count=fcc_init(a,b,c,lc,atom,origin,p_params,d_params);
1057 if(origin) v3_add(&o,&o,origin);
1059 count+=fcc_init(a,b,c,lc,&atom[count],&o,p_params,d_params);
1064 int destroy_atoms(t_moldyn *moldyn) {
1066 if(moldyn->atom) free(moldyn->atom);
1071 int thermal_init(t_moldyn *moldyn,u8 equi_init) {
1074 * - gaussian distribution of velocities
1075 * - zero total momentum
1076 * - velocity scaling (E = 3/2 N k T), E: kinetic energy
1081 t_3dvec p_total,delta;
1086 random=&(moldyn->random);
1088 printf("[moldyn] thermal init (equi init: %s)\n",equi_init?"yes":"no");
1090 /* gaussian distribution of velocities */
1092 for(i=0;i<moldyn->count;i++) {
1093 sigma=sqrt(2.0*K_BOLTZMANN*moldyn->t_ref/atom[i].mass);
1095 v=sigma*rand_get_gauss(random);
1097 p_total.x+=atom[i].mass*v;
1099 v=sigma*rand_get_gauss(random);
1101 p_total.y+=atom[i].mass*v;
1103 v=sigma*rand_get_gauss(random);
1105 p_total.z+=atom[i].mass*v;
1108 /* zero total momentum */
1109 v3_scale(&p_total,&p_total,1.0/moldyn->count);
1110 for(i=0;i<moldyn->count;i++) {
1111 v3_scale(&delta,&p_total,1.0/atom[i].mass);
1112 v3_sub(&(atom[i].v),&(atom[i].v),&delta);
1115 /* velocity scaling */
1116 scale_velocity(moldyn,equi_init);
1121 double total_mass_calc(t_moldyn *moldyn) {
1127 for(i=0;i<moldyn->count;i++)
1128 moldyn->mass+=moldyn->atom[i].mass;
1130 return moldyn->mass;
1133 double temperature_calc(t_moldyn *moldyn) {
1135 /* assume up to date kinetic energy, which is 3/2 N k_B T */
1138 moldyn->t=(2.0*moldyn->ekin)/(3.0*K_BOLTZMANN*moldyn->count);
1144 double get_temperature(t_moldyn *moldyn) {
1149 int scale_velocity(t_moldyn *moldyn,u8 equi_init) {
1159 * - velocity scaling (E = 3/2 N k T), E: kinetic energy
1162 /* get kinetic energy / temperature & count involved atoms */
1165 for(i=0;i<moldyn->count;i++) {
1166 if((equi_init&TRUE)||(atom[i].attr&ATOM_ATTR_HB)) {
1167 e+=atom[i].mass*v3_absolute_square(&(atom[i].v));
1172 if(count!=0) moldyn->t=e/(1.5*count*K_BOLTZMANN);
1173 else return 0; /* no atoms involved in scaling! */
1175 /* (temporary) hack for e,t = 0 */
1178 if(moldyn->t_ref!=0.0) {
1179 thermal_init(moldyn,equi_init);
1183 return 0; /* no scaling needed */
1187 /* get scaling factor */
1188 scale=moldyn->t_ref/moldyn->t;
1192 if(moldyn->pt_scale&T_SCALE_BERENDSEN)
1193 scale=1.0+(scale-1.0)*moldyn->tau/moldyn->t_tc;
1196 /* velocity scaling */
1197 for(i=0;i<moldyn->count;i++) {
1198 if((equi_init&TRUE)||(atom[i].attr&ATOM_ATTR_HB))
1199 v3_scale(&(atom[i].v),&(atom[i].v),scale);
1205 double ideal_gas_law_pressure(t_moldyn *moldyn) {
1209 p=moldyn->count*moldyn->t*K_BOLTZMANN/moldyn->volume;
1214 double virial_sum(t_moldyn *moldyn) {
1219 /* virial (sum over atom virials) */
1227 for(i=0;i<moldyn->count;i++) {
1228 virial=&(moldyn->atom[i].virial);
1229 moldyn->virial+=(virial->xx+virial->yy+virial->zz);
1230 moldyn->vir.xx+=virial->xx;
1231 moldyn->vir.yy+=virial->yy;
1232 moldyn->vir.zz+=virial->zz;
1233 moldyn->vir.xy+=virial->xy;
1234 moldyn->vir.xz+=virial->xz;
1235 moldyn->vir.yz+=virial->yz;
1238 /* global virial (absolute coordinates) */
1239 //virial=&(moldyn->gvir);
1240 //moldyn->gv=virial->xx+virial->yy+virial->zz;
1242 return moldyn->virial;
1245 double pressure_calc(t_moldyn *moldyn) {
1249 * with W = 1/3 sum_i f_i r_i (- skipped!)
1250 * virial = sum_i f_i r_i
1252 * => P = (2 Ekin + virial) / (3V)
1255 /* assume up to date virial & up to date kinetic energy */
1257 /* pressure (atom virials) */
1258 moldyn->p=2.0*moldyn->ekin+moldyn->virial;
1259 moldyn->p/=(3.0*moldyn->volume);
1261 //moldyn->px=2.0*moldyn->ekinx+moldyn->vir.xx;
1262 //moldyn->px/=moldyn->volume;
1263 //moldyn->py=2.0*moldyn->ekiny+moldyn->vir.yy;
1264 //moldyn->py/=moldyn->volume;
1265 //moldyn->pz=2.0*moldyn->ekinz+moldyn->vir.zz;
1266 //moldyn->pz/=moldyn->volume;
1268 /* pressure (absolute coordinates) */
1269 //moldyn->gp=2.0*moldyn->ekin+moldyn->gv;
1270 //moldyn->gp/=(3.0*moldyn->volume);
1275 int average_reset(t_moldyn *moldyn) {
1277 printf("[moldyn] average reset\n");
1279 /* update skip value */
1280 moldyn->avg_skip=moldyn->total_steps;
1282 /* kinetic energy */
1286 /* potential energy */
1294 moldyn->virial_sum=0.0;
1295 //moldyn->gv_sum=0.0;
1299 //moldyn->gp_sum=0.0;
1305 int average_and_fluctuation_calc(t_moldyn *moldyn) {
1309 if(moldyn->total_steps<moldyn->avg_skip)
1312 denom=moldyn->total_steps+1-moldyn->avg_skip;
1314 /* assume up to date energies, temperature, pressure etc */
1316 /* kinetic energy */
1317 moldyn->k_sum+=moldyn->ekin;
1318 moldyn->k2_sum+=(moldyn->ekin*moldyn->ekin);
1319 moldyn->k_avg=moldyn->k_sum/denom;
1320 moldyn->k2_avg=moldyn->k2_sum/denom;
1321 moldyn->dk2_avg=moldyn->k2_avg-(moldyn->k_avg*moldyn->k_avg);
1323 /* potential energy */
1324 moldyn->v_sum+=moldyn->energy;
1325 moldyn->v2_sum+=(moldyn->energy*moldyn->energy);
1326 moldyn->v_avg=moldyn->v_sum/denom;
1327 moldyn->v2_avg=moldyn->v2_sum/denom;
1328 moldyn->dv2_avg=moldyn->v2_avg-(moldyn->v_avg*moldyn->v_avg);
1331 moldyn->t_sum+=moldyn->t;
1332 moldyn->t_avg=moldyn->t_sum/denom;
1335 moldyn->virial_sum+=moldyn->virial;
1336 moldyn->virial_avg=moldyn->virial_sum/denom;
1337 //moldyn->gv_sum+=moldyn->gv;
1338 //moldyn->gv_avg=moldyn->gv_sum/denom;
1341 moldyn->p_sum+=moldyn->p;
1342 moldyn->p_avg=moldyn->p_sum/denom;
1343 //moldyn->gp_sum+=moldyn->gp;
1344 //moldyn->gp_avg=moldyn->gp_sum/denom;
1345 moldyn->tp_sum+=moldyn->tp;
1346 moldyn->tp_avg=moldyn->tp_sum/denom;
1351 int get_heat_capacity(t_moldyn *moldyn) {
1355 /* averages needed for heat capacity calc */
1356 if(moldyn->total_steps<moldyn->avg_skip)
1359 /* (temperature average)^2 */
1360 temp2=moldyn->t_avg*moldyn->t_avg;
1361 printf("[moldyn] specific heat capacity for T=%f K [J/(kg K)]\n",
1364 /* ideal gas contribution */
1365 ighc=3.0*moldyn->count*K_BOLTZMANN/2.0;
1366 printf(" ideal gas contribution: %f\n",
1367 ighc/moldyn->mass*KILOGRAM/JOULE);
1369 /* specific heat for nvt ensemble */
1370 moldyn->c_v_nvt=moldyn->dv2_avg/(K_BOLTZMANN*temp2)+ighc;
1371 moldyn->c_v_nvt/=moldyn->mass;
1373 /* specific heat for nve ensemble */
1374 moldyn->c_v_nve=ighc/(1.0-(moldyn->dv2_avg/(ighc*K_BOLTZMANN*temp2)));
1375 moldyn->c_v_nve/=moldyn->mass;
1377 printf(" NVE: %f\n",moldyn->c_v_nve*KILOGRAM/JOULE);
1378 printf(" NVT: %f\n",moldyn->c_v_nvt*KILOGRAM/JOULE);
1379 printf(" --> <dV2> sim: %f experimental: %f\n",moldyn->dv2_avg,1.5*moldyn->count*K_B2*moldyn->t_avg*moldyn->t_avg*(1.0-1.5*moldyn->count*K_BOLTZMANN/(700*moldyn->mass*JOULE/KILOGRAM)));
1384 double thermodynamic_pressure_calc(t_moldyn *moldyn) {
1400 /* store atomic configuration + dimension */
1401 store=malloc(moldyn->count*sizeof(t_atom));
1403 printf("[moldyn] allocating store mem failed\n");
1406 memcpy(store,moldyn->atom,moldyn->count*sizeof(t_atom));
1411 h=(1.0-sd)*(1.0-sd)*(1.0-sd);
1412 su=pow(2.0-h,ONE_THIRD)-1.0;
1413 dv=(1.0-h)*moldyn->volume;
1415 /* scale up dimension and atom positions */
1416 scale_dim(moldyn,SCALE_UP,su,TRUE,TRUE,TRUE);
1417 scale_atoms(moldyn,SCALE_UP,su,TRUE,TRUE,TRUE);
1418 link_cell_shutdown(moldyn);
1419 link_cell_init(moldyn,QUIET);
1420 potential_force_calc(moldyn);
1423 /* restore atomic configuration + dim */
1424 memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
1427 /* scale down dimension and atom positions */
1428 scale_dim(moldyn,SCALE_DOWN,sd,TRUE,TRUE,TRUE);
1429 scale_atoms(moldyn,SCALE_DOWN,sd,TRUE,TRUE,TRUE);
1430 link_cell_shutdown(moldyn);
1431 link_cell_init(moldyn,QUIET);
1432 potential_force_calc(moldyn);
1435 /* calculate pressure */
1436 moldyn->tp=-(y1-y0)/(2.0*dv);
1438 /* restore atomic configuration */
1439 memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
1441 link_cell_shutdown(moldyn);
1442 link_cell_init(moldyn,QUIET);
1443 //potential_force_calc(moldyn);
1445 /* free store buffer */
1452 double get_pressure(t_moldyn *moldyn) {
1458 int scale_dim(t_moldyn *moldyn,u8 dir,double scale,u8 x,u8 y,u8 z) {
1470 if(x) dim->x*=scale;
1471 if(y) dim->y*=scale;
1472 if(z) dim->z*=scale;
1477 int scale_atoms(t_moldyn *moldyn,u8 dir,double scale,u8 x,u8 y,u8 z) {
1488 for(i=0;i<moldyn->count;i++) {
1489 r=&(moldyn->atom[i].r);
1498 int scale_atoms_ind(t_moldyn *moldyn,double x,double y,double z) {
1503 for(i=0;i<moldyn->count;i++) {
1504 r=&(moldyn->atom[i].r);
1513 int scale_dim_ind(t_moldyn *moldyn,double x,double y,double z) {
1526 int scale_volume(t_moldyn *moldyn) {
1533 vdim=&(moldyn->vis.dim);
1537 /* scaling factor */
1538 if(moldyn->pt_scale&P_SCALE_BERENDSEN) {
1539 scale=1.0-(moldyn->p_ref-moldyn->p)*moldyn->p_tc*moldyn->tau;
1540 scale=pow(scale,ONE_THIRD);
1543 scale=pow(moldyn->p/moldyn->p_ref,ONE_THIRD);
1548 sx=1.0-(moldyn->p_ref-moldyn->px)*moldyn->p_tc*moldyn->tau;
1549 sy=1.0-(moldyn->p_ref-moldyn->py)*moldyn->p_tc*moldyn->tau;
1550 sz=1.0-(moldyn->p_ref-moldyn->pz)*moldyn->p_tc*moldyn->tau;
1551 sx=pow(sx,ONE_THIRD);
1552 sy=pow(sy,ONE_THIRD);
1553 sz=pow(sz,ONE_THIRD);
1556 /* scale the atoms and dimensions */
1557 scale_atoms(moldyn,SCALE_DIRECT,scale,TRUE,TRUE,TRUE);
1558 scale_dim(moldyn,SCALE_DIRECT,scale,TRUE,TRUE,TRUE);
1559 //scale_atoms_ind(moldyn,sx,sy,sz);
1560 //scale_dim_ind(moldyn,sx,sy,sz);
1562 /* visualize dimensions */
1569 /* recalculate scaled volume */
1570 moldyn->volume=dim->x*dim->y*dim->z;
1572 /* adjust/reinit linkcell */
1573 if(((int)(dim->x/moldyn->cutoff)!=lc->nx)||
1574 ((int)(dim->y/moldyn->cutoff)!=lc->ny)||
1575 ((int)(dim->z/moldyn->cutoff)!=lc->nx)) {
1576 link_cell_shutdown(moldyn);
1577 link_cell_init(moldyn,QUIET);
1591 double e_kin_calc(t_moldyn *moldyn) {
1598 //moldyn->ekinx=0.0;
1599 //moldyn->ekiny=0.0;
1600 //moldyn->ekinz=0.0;
1602 for(i=0;i<moldyn->count;i++) {
1603 atom[i].ekin=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v));
1604 moldyn->ekin+=atom[i].ekin;
1605 //moldyn->ekinx+=0.5*atom[i].mass*atom[i].v.x*atom[i].v.x;
1606 //moldyn->ekiny+=0.5*atom[i].mass*atom[i].v.y*atom[i].v.y;
1607 //moldyn->ekinz+=0.5*atom[i].mass*atom[i].v.z*atom[i].v.z;
1610 return moldyn->ekin;
1613 double get_total_energy(t_moldyn *moldyn) {
1615 return(moldyn->ekin+moldyn->energy);
1618 t_3dvec get_total_p(t_moldyn *moldyn) {
1627 for(i=0;i<moldyn->count;i++) {
1628 v3_scale(&p,&(atom[i].v),atom[i].mass);
1629 v3_add(&p_total,&p_total,&p);
1635 double estimate_time_step(t_moldyn *moldyn,double nn_dist) {
1639 /* nn_dist is the nearest neighbour distance */
1641 tau=(0.05*nn_dist*moldyn->atom[0].mass)/sqrt(3.0*K_BOLTZMANN*moldyn->t);
1650 /* linked list / cell method */
1652 int link_cell_init(t_moldyn *moldyn,u8 vol) {
1655 #ifndef LOWMEM_LISTS
1661 /* partitioning the md cell */
1662 lc->nx=moldyn->dim.x/moldyn->cutoff;
1663 lc->x=moldyn->dim.x/lc->nx;
1664 lc->ny=moldyn->dim.y/moldyn->cutoff;
1665 lc->y=moldyn->dim.y/lc->ny;
1666 lc->nz=moldyn->dim.z/moldyn->cutoff;
1667 lc->z=moldyn->dim.z/lc->nz;
1668 lc->cells=lc->nx*lc->ny*lc->nz;
1671 lc->subcell=malloc(lc->cells*sizeof(int*));
1673 lc->subcell=malloc(sizeof(t_lowmem_list));
1675 lc->subcell=malloc(lc->cells*sizeof(t_list));
1678 if(lc->subcell==NULL) {
1679 perror("[moldyn] cell init (malloc)");
1684 printf("[moldyn] FATAL: less then 27 subcells! (%d)\n",
1689 printf("[moldyn] initializing 'static' linked cells (%d)\n",
1692 printf("[moldyn] initializing 'lowmem' linked cells (%d)\n",
1695 printf("[moldyn] initializing 'dynamic' linked cells (%d)\n",
1698 printf(" x: %d x %f A\n",lc->nx,lc->x);
1699 printf(" y: %d x %f A\n",lc->ny,lc->y);
1700 printf(" z: %d x %f A\n",lc->nz,lc->z);
1705 for(i=0;i<lc->cells;i++) {
1706 lc->subcell[i]=malloc((MAX_ATOMS_PER_LIST+1)*sizeof(int));
1707 if(lc->subcell[i]==NULL) {
1708 perror("[moldyn] list init (malloc)");
1713 printf(" ---> %d malloc %p (%p)\n",
1714 i,lc->subcell[0],lc->subcell);
1718 lc->subcell->head=malloc(lc->cells*sizeof(int));
1719 if(lc->subcell->head==NULL) {
1720 perror("[moldyn] head init (malloc)");
1723 lc->subcell->list=malloc(moldyn->count*sizeof(int));
1724 if(lc->subcell->list==NULL) {
1725 perror("[moldyn] list init (malloc)");
1729 for(i=0;i<lc->cells;i++)
1730 list_init_f(&(lc->subcell[i]));
1733 /* update the list */
1734 link_cell_update(moldyn);
1739 int link_cell_update(t_moldyn *moldyn) {
1757 for(i=0;i<lc->cells;i++)
1759 memset(lc->subcell[i],-1,(MAX_ATOMS_PER_LIST+1)*sizeof(int));
1761 lc->subcell->head[i]=-1;
1763 list_destroy_f(&(lc->subcell[i]));
1766 for(count=0;count<moldyn->count;count++) {
1767 i=((atom[count].r.x+(moldyn->dim.x/2))/lc->x);
1768 j=((atom[count].r.y+(moldyn->dim.y/2))/lc->y);
1769 k=((atom[count].r.z+(moldyn->dim.z/2))/lc->z);
1773 while(lc->subcell[i+j*nx+k*nxy][p]!=-1)
1776 if(p>=MAX_ATOMS_PER_LIST) {
1777 printf("[moldyn] FATAL: amount of atoms too high!\n");
1781 lc->subcell[i+j*nx+k*nxy][p]=count;
1784 lc->subcell->list[count]=lc->subcell->head[p];
1785 lc->subcell->head[p]=count;
1787 list_add_immediate_f(&(lc->subcell[i+j*nx+k*nxy]),
1791 printf(" ---> %d %d malloc %p (%p)\n",
1792 i,count,lc->subcell[i].current,lc->subcell);
1800 int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,
1826 if(i>=nx||j>=ny||k>=nz)
1827 printf("[moldyn] WARNING: lcni %d/%d %d/%d %d/%d\n",
1830 #ifndef LOWMEM_LISTS
1831 cell[0]=lc->subcell[i+j*nx+k*a];
1833 cell[0]=lc->subcell->head[i+j*nx+k*a];
1835 for(ci=-1;ci<=1;ci++) {
1838 if((x<0)||(x>=nx)) {
1842 for(cj=-1;cj<=1;cj++) {
1845 if((y<0)||(y>=ny)) {
1849 for(ck=-1;ck<=1;ck++) {
1852 if((z<0)||(z>=nz)) {
1856 if(!(ci|cj|ck)) continue;
1858 #ifndef LOWMEM_LISTS
1859 cell[--count2]=lc->subcell[x+y*nx+z*a];
1861 cell[--count2]=lc->subcell->head[x+y*nx+z*a];
1866 #ifndef LOWMEM_LISTS
1867 cell[count1++]=lc->subcell[x+y*nx+z*a];
1869 cell[count1++]=lc->subcell->head[x+y*nx+z*a];
1881 int link_cell_shutdown(t_moldyn *moldyn) {
1883 #ifndef LOWMEM_LISTS
1891 free(lc->subcell->head);
1892 free(lc->subcell->list);
1896 for(i=0;i<lc->cells;i++) {
1898 free(lc->subcell[i]);
1900 //printf(" ---> %d free %p\n",i,lc->subcell[i].start);
1901 list_destroy_f(&(lc->subcell[i]));
1911 int moldyn_add_schedule(t_moldyn *moldyn,int runs,double tau) {
1915 t_moldyn_schedule *schedule;
1917 schedule=&(moldyn->schedule);
1918 count=++(schedule->total_sched);
1920 ptr=realloc(schedule->runs,count*sizeof(int));
1922 perror("[moldyn] realloc (runs)");
1926 schedule->runs[count-1]=runs;
1928 ptr=realloc(schedule->tau,count*sizeof(double));
1930 perror("[moldyn] realloc (tau)");
1934 schedule->tau[count-1]=tau;
1936 printf("[moldyn] schedule added:\n");
1937 printf(" number: %d | runs: %d | tau: %f\n",count-1,runs,tau);
1943 int moldyn_set_schedule_hook(t_moldyn *moldyn,set_hook hook,void *hook_params) {
1945 moldyn->schedule.hook=hook;
1946 moldyn->schedule.hook_params=hook_params;
1953 * 'integration of newtons equation' - algorithms
1957 /* start the integration */
1959 int moldyn_integrate(t_moldyn *moldyn) {
1962 unsigned int e,m,s,v,p,t,a;
1964 t_moldyn_schedule *sched;
1969 double energy_scale;
1970 struct timeval t1,t2;
1973 #ifdef VISUAL_THREAD
1975 pthread_t io_thread;
1984 sched=&(moldyn->schedule);
1987 /* initialize linked cell method */
1988 link_cell_init(moldyn,VERBOSE);
1990 /* logging & visualization */
1999 /* sqaure of some variables */
2000 moldyn->tau_square=moldyn->tau*moldyn->tau;
2002 /* get current time */
2003 gettimeofday(&t1,NULL);
2005 /* calculate initial forces */
2006 potential_force_calc(moldyn);
2011 /* some stupid checks before we actually start calculating bullshit */
2012 if(moldyn->cutoff>0.5*moldyn->dim.x)
2013 printf("[moldyn] WARNING: cutoff > 0.5 x dim.x\n");
2014 if(moldyn->cutoff>0.5*moldyn->dim.y)
2015 printf("[moldyn] WARNING: cutoff > 0.5 x dim.y\n");
2016 if(moldyn->cutoff>0.5*moldyn->dim.z)
2017 printf("[moldyn] WARNING: cutoff > 0.5 x dim.z\n");
2019 ds=0.5*atom[0].f.x*moldyn->tau_square/atom[0].mass;
2020 if(ds>0.05*moldyn->nnd)
2021 printf("[moldyn] WARNING: forces too high / tau too small!\n");
2024 /* zero absolute time */
2025 // should have right values!
2027 //moldyn->total_steps=0;
2029 /* debugging, ignore */
2032 /* zero & init moldyn copy */
2033 #ifdef VISUAL_THREAD
2034 memset(&md_copy,0,sizeof(t_moldyn));
2035 atom_copy=malloc(moldyn->count*sizeof(t_atom));
2036 if(atom_copy==NULL) {
2037 perror("[moldyn] malloc atom copy (init)");
2043 printf("##################\n");
2044 printf("# USING PTHREADS #\n");
2045 printf("##################\n");
2047 /* tell the world */
2048 printf("[moldyn] integration start, go get a coffee ...\n");
2050 /* executing the schedule */
2052 while(sched->count<sched->total_sched) {
2054 /* setting amount of runs and finite time step size */
2055 moldyn->tau=sched->tau[sched->count];
2056 moldyn->tau_square=moldyn->tau*moldyn->tau;
2057 moldyn->time_steps=sched->runs[sched->count];
2059 /* energy scaling factor (might change!) */
2060 energy_scale=moldyn->count*EV;
2062 /* integration according to schedule */
2064 for(i=0;i<moldyn->time_steps;i++) {
2066 /* integration step */
2067 moldyn->integrate(moldyn);
2069 /* calculate kinetic energy, temperature and pressure */
2071 temperature_calc(moldyn);
2073 pressure_calc(moldyn);
2075 thermodynamic_pressure_calc(moldyn);
2076 printf("\n\nDEBUG: numeric pressure calc: %f\n\n",
2080 /* calculate fluctuations + averages */
2081 average_and_fluctuation_calc(moldyn);
2084 if(moldyn->pt_scale&(T_SCALE_BERENDSEN|T_SCALE_DIRECT))
2085 scale_velocity(moldyn,FALSE);
2086 if(moldyn->pt_scale&(P_SCALE_BERENDSEN|P_SCALE_DIRECT))
2087 scale_volume(moldyn);
2089 /* check for log & visualization */
2091 if(!(moldyn->total_steps%e))
2092 dprintf(moldyn->efd,
2093 "%f %f %f %f %f %f\n",
2094 moldyn->time,moldyn->ekin/energy_scale,
2095 moldyn->energy/energy_scale,
2096 get_total_energy(moldyn)/energy_scale,
2097 moldyn->ekin/EV,moldyn->energy/EV);
2100 if(!(moldyn->total_steps%m)) {
2101 momentum=get_total_p(moldyn);
2102 dprintf(moldyn->mfd,
2103 "%f %f %f %f %f\n",moldyn->time,
2104 momentum.x,momentum.y,momentum.z,
2105 v3_norm(&momentum));
2109 if(!(moldyn->total_steps%p)) {
2110 dprintf(moldyn->pfd,
2111 "%f %f %f %f %f %f %f\n",moldyn->time,
2112 moldyn->p/BAR,moldyn->p_avg/BAR,
2113 moldyn->p/BAR,moldyn->p_avg/BAR,
2114 moldyn->tp/BAR,moldyn->tp_avg/BAR);
2118 if(!(moldyn->total_steps%t)) {
2119 dprintf(moldyn->tfd,
2121 moldyn->time,moldyn->t,moldyn->t_avg);
2125 if(!(moldyn->total_steps%v)) {
2126 dprintf(moldyn->vfd,
2127 "%f %f %f %f %f\n",moldyn->time,
2135 if(!(moldyn->total_steps%s)) {
2136 snprintf(dir,128,"%s/s-%08.f.save",
2137 moldyn->vlsdir,moldyn->time);
2138 fd=open(dir,O_WRONLY|O_TRUNC|O_CREAT,
2140 if(fd<0) perror("[moldyn] save fd open");
2142 write(fd,moldyn,sizeof(t_moldyn));
2143 write(fd,moldyn->atom,
2144 moldyn->count*sizeof(t_atom));
2150 if(!(moldyn->total_steps%a)) {
2151 #ifdef VISUAL_THREAD
2152 /* check whether thread has not terminated yet */
2154 ret=pthread_join(io_thread,NULL);
2157 /* prepare and start thread */
2158 if(moldyn->count!=md_copy.count) {
2162 memcpy(&md_copy,moldyn,sizeof(t_moldyn));
2164 atom_copy=malloc(moldyn->count*sizeof(t_atom));
2165 if(atom_copy==NULL) {
2166 perror("[moldyn] malloc atom copy (change)");
2170 md_copy.atom=atom_copy;
2171 memcpy(atom_copy,moldyn->atom,moldyn->count*sizeof(t_atom));
2173 ret=pthread_create(&io_thread,NULL,visual_atoms,&md_copy);
2175 perror("[moldyn] create visual atoms thread\n");
2179 visual_atoms(moldyn);
2184 /* display progress */
2186 /* get current time */
2187 gettimeofday(&t2,NULL);
2189 printf("sched:%d, steps:%d/%d, T:%4.1f/%4.1f P:%4.1f/%4.1f V:%6.1f (%d)\n",
2190 sched->count,i,moldyn->total_steps,
2191 moldyn->t,moldyn->t_avg,
2192 moldyn->p/BAR,moldyn->p_avg/BAR,
2193 //moldyn->p/BAR,(moldyn->p-2.0*moldyn->ekin/(3.0*moldyn->volume))/BAR,
2195 (int)(t2.tv_sec-t1.tv_sec));
2199 /* copy over time */
2203 /* increase absolute time */
2204 moldyn->time+=moldyn->tau;
2205 moldyn->total_steps+=1;
2209 /* check for hooks */
2211 printf("\n ## schedule hook %d start ##\n",
2213 sched->hook(moldyn,sched->hook_params);
2214 printf(" ## schedule hook end ##\n");
2217 /* increase the schedule counter */
2225 /* velocity verlet */
2227 int velocity_verlet(t_moldyn *moldyn) {
2230 double tau,tau_square,h;
2235 count=moldyn->count;
2237 tau_square=moldyn->tau_square;
2239 for(i=0;i<count;i++) {
2240 /* check whether fixed atom */
2241 if(atom[i].attr&ATOM_ATTR_FP)
2245 v3_scale(&delta,&(atom[i].v),tau);
2246 v3_add(&(atom[i].r),&(atom[i].r),&delta);
2247 v3_scale(&delta,&(atom[i].f),h*tau_square);
2248 v3_add(&(atom[i].r),&(atom[i].r),&delta);
2249 check_per_bound(moldyn,&(atom[i].r));
2251 /* velocities [actually v(t+tau/2)] */
2252 v3_scale(&delta,&(atom[i].f),h*tau);
2253 v3_add(&(atom[i].v),&(atom[i].v),&delta);
2256 /* criticial check */
2257 moldyn_bc_check(moldyn);
2259 /* neighbour list update */
2260 link_cell_update(moldyn);
2262 /* forces depending on chosen potential */
2264 potential_force_calc(moldyn);
2266 albe_potential_force_calc(moldyn);
2269 for(i=0;i<count;i++) {
2270 /* check whether fixed atom */
2271 if(atom[i].attr&ATOM_ATTR_FP)
2273 /* again velocities [actually v(t+tau)] */
2274 v3_scale(&delta,&(atom[i].f),0.5*tau/atom[i].mass);
2275 v3_add(&(atom[i].v),&(atom[i].v),&delta);
2284 * potentials & corresponding forces & virial routine
2288 /* generic potential and force calculation */
2290 int potential_force_calc(t_moldyn *moldyn) {
2293 t_atom *itom,*jtom,*ktom;
2297 int *neighbour_i[27];
2301 int neighbour_i[27];
2304 t_list neighbour_i[27];
2305 t_list neighbour_i2[27];
2311 count=moldyn->count;
2321 /* reset global virial */
2322 memset(&(moldyn->gvir),0,sizeof(t_virial));
2324 /* reset force, site energy and virial of every atom */
2326 i=omp_get_thread_num();
2327 #pragma omp parallel for private(virial)
2329 for(i=0;i<count;i++) {
2332 v3_zero(&(itom[i].f));
2335 virial=(&(itom[i].virial));
2343 /* reset site energy */
2348 /* get energy, force and virial of every atom */
2350 /* first (and only) loop over atoms i */
2351 for(i=0;i<count;i++) {
2353 /* single particle potential/force */
2354 if(itom[i].attr&ATOM_ATTR_1BP)
2356 moldyn->func1b(moldyn,&(itom[i]));
2358 if(!(itom[i].attr&(ATOM_ATTR_2BP|ATOM_ATTR_3BP)))
2361 /* 2 body pair potential/force */
2363 link_cell_neighbour_index(moldyn,
2364 (itom[i].r.x+moldyn->dim.x/2)/lc->x,
2365 (itom[i].r.y+moldyn->dim.y/2)/lc->y,
2366 (itom[i].r.z+moldyn->dim.z/2)/lc->z,
2371 /* first loop over atoms j */
2372 if(moldyn->func2b) {
2379 while(neighbour_i[j][p]!=-1) {
2381 jtom=&(atom[neighbour_i[j][p]]);
2389 p=lc->subcell->list[p];
2391 this=&(neighbour_i[j]);
2394 if(this->start==NULL)
2398 jtom=this->current->data;
2401 if(jtom==&(itom[i]))
2404 if((jtom->attr&ATOM_ATTR_2BP)&
2405 (itom[i].attr&ATOM_ATTR_2BP)) {
2406 moldyn->func2b(moldyn,
2416 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
2422 /* 3 body potential/force */
2424 if(!(itom[i].attr&ATOM_ATTR_3BP))
2427 /* copy the neighbour lists */
2429 /* no copy needed for static lists */
2431 /* no copy needed for lowmem lists */
2433 memcpy(neighbour_i2,neighbour_i,27*sizeof(t_list));
2436 /* second loop over atoms j */
2443 while(neighbour_i[j][p]!=-1) {
2445 jtom=&(atom[neighbour_i[j][p]]);
2453 p=lc->subcell->list[p];
2455 this=&(neighbour_i[j]);
2458 if(this->start==NULL)
2463 jtom=this->current->data;
2466 if(jtom==&(itom[i]))
2469 if(!(jtom->attr&ATOM_ATTR_3BP))
2475 if(moldyn->func3b_j1)
2476 moldyn->func3b_j1(moldyn,
2481 /* in first j loop, 3bp run can be skipped */
2482 if(!(moldyn->run3bp))
2485 /* first loop over atoms k */
2486 if(moldyn->func3b_k1) {
2494 while(neighbour_i[k][q]!=-1) {
2496 ktom=&(atom[neighbour_i[k][q]]);
2504 q=lc->subcell->list[q];
2506 that=&(neighbour_i2[k]);
2509 if(that->start==NULL)
2513 ktom=that->current->data;
2516 if(!(ktom->attr&ATOM_ATTR_3BP))
2522 if(ktom==&(itom[i]))
2525 moldyn->func3b_k1(moldyn,
2536 } while(list_next_f(that)!=\
2544 if(moldyn->func3b_j2)
2545 moldyn->func3b_j2(moldyn,
2550 /* second loop over atoms k */
2551 if(moldyn->func3b_k2) {
2559 while(neighbour_i[k][q]!=-1) {
2561 ktom=&(atom[neighbour_i[k][q]]);
2569 q=lc->subcell->list[q];
2571 that=&(neighbour_i2[k]);
2574 if(that->start==NULL)
2578 ktom=that->current->data;
2581 if(!(ktom->attr&ATOM_ATTR_3BP))
2587 if(ktom==&(itom[i]))
2590 moldyn->func3b_k2(moldyn,
2601 } while(list_next_f(that)!=\
2609 /* 2bp post function */
2610 if(moldyn->func3b_j3) {
2611 moldyn->func3b_j3(moldyn,
2620 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
2635 //printf("\nATOM 0: %f %f %f\n\n",itom->f.x,itom->f.y,itom->f.z);
2636 if(moldyn->time>DSTART&&moldyn->time<DEND) {
2638 printf(" x: %0.40f\n",moldyn->atom[DATOM].f.x);
2639 printf(" y: %0.40f\n",moldyn->atom[DATOM].f.y);
2640 printf(" z: %0.40f\n",moldyn->atom[DATOM].f.z);
2644 /* some postprocessing */
2646 #pragma omp parallel for
2648 for(i=0;i<count;i++) {
2649 /* calculate global virial */
2650 moldyn->gvir.xx+=itom[i].r.x*itom[i].f.x;
2651 moldyn->gvir.yy+=itom[i].r.y*itom[i].f.y;
2652 moldyn->gvir.zz+=itom[i].r.z*itom[i].f.z;
2653 moldyn->gvir.xy+=itom[i].r.y*itom[i].f.x;
2654 moldyn->gvir.xz+=itom[i].r.z*itom[i].f.x;
2655 moldyn->gvir.yz+=itom[i].r.z*itom[i].f.y;
2657 /* check forces regarding the given timestep */
2658 if(v3_norm(&(itom[i].f))>\
2659 0.1*moldyn->nnd*itom[i].mass/moldyn->tau_square)
2660 printf("[moldyn] WARNING: pfc (high force: atom %d)\n",
2668 * virial calculation
2671 //inline int virial_calc(t_atom *a,t_3dvec *f,t_3dvec *d) {
2672 int virial_calc(t_atom *a,t_3dvec *f,t_3dvec *d) {
2674 a->virial.xx+=f->x*d->x;
2675 a->virial.yy+=f->y*d->y;
2676 a->virial.zz+=f->z*d->z;
2677 a->virial.xy+=f->x*d->y;
2678 a->virial.xz+=f->x*d->z;
2679 a->virial.yz+=f->y*d->z;
2685 * periodic boundary checking
2688 //inline int check_per_bound(t_moldyn *moldyn,t_3dvec *a) {
2689 int check_per_bound(t_moldyn *moldyn,t_3dvec *a) {
2700 if(moldyn->status&MOLDYN_STAT_PBX) {
2701 if(a->x>=x) a->x-=dim->x;
2702 else if(-a->x>x) a->x+=dim->x;
2704 if(moldyn->status&MOLDYN_STAT_PBY) {
2705 if(a->y>=y) a->y-=dim->y;
2706 else if(-a->y>y) a->y+=dim->y;
2708 if(moldyn->status&MOLDYN_STAT_PBZ) {
2709 if(a->z>=z) a->z-=dim->z;
2710 else if(-a->z>z) a->z+=dim->z;
2717 * debugging / critical check functions
2720 int moldyn_bc_check(t_moldyn *moldyn) {
2733 for(i=0;i<moldyn->count;i++) {
2734 if(atom[i].r.x>=dim->x/2||-atom[i].r.x>dim->x/2) {
2735 printf("FATAL: atom %d: x: %.20f (%.20f)\n",
2736 i,atom[i].r.x,dim->x/2);
2737 printf("diagnostic:\n");
2738 printf("-----------\natom.r.x:\n");
2740 memcpy(&byte,(u8 *)(&(atom[i].r.x))+j,1);
2743 ((byte)&(1<<k))?1:0,
2746 printf("---------------\nx=dim.x/2:\n");
2748 memcpy(&byte,(u8 *)(&x)+j,1);
2751 ((byte)&(1<<k))?1:0,
2754 if(atom[i].r.x==x) printf("the same!\n");
2755 else printf("different!\n");
2757 if(atom[i].r.y>=dim->y/2||-atom[i].r.y>dim->y/2)
2758 printf("FATAL: atom %d: y: %.20f (%.20f)\n",
2759 i,atom[i].r.y,dim->y/2);
2760 if(atom[i].r.z>=dim->z/2||-atom[i].r.z>dim->z/2)
2761 printf("FATAL: atom %d: z: %.20f (%.20f)\n",
2762 i,atom[i].r.z,dim->z/2);
2772 int moldyn_read_save_file(t_moldyn *moldyn,char *file) {
2779 fd=open(file,O_RDONLY);
2781 perror("[moldyn] load save file open");
2785 fsize=lseek(fd,0,SEEK_END);
2786 lseek(fd,0,SEEK_SET);
2788 size=sizeof(t_moldyn);
2791 cnt=read(fd,moldyn,size);
2793 perror("[moldyn] load save file read (moldyn)");
2799 size=moldyn->count*sizeof(t_atom);
2801 /* correcting possible atom data offset */
2803 if(fsize!=sizeof(t_moldyn)+size) {
2804 corr=fsize-sizeof(t_moldyn)-size;
2805 printf("[moldyn] WARNING: lsf (illegal file size)\n");
2806 printf(" moifying offset:\n");
2807 printf(" - current pos: %d\n",sizeof(t_moldyn));
2808 printf(" - atom size: %d\n",size);
2809 printf(" - file size: %d\n",fsize);
2810 printf(" => correction: %d\n",corr);
2811 lseek(fd,corr,SEEK_CUR);
2814 moldyn->atom=(t_atom *)malloc(size);
2815 if(moldyn->atom==NULL) {
2816 perror("[moldyn] load save file malloc (atoms)");
2821 cnt=read(fd,moldyn->atom,size);
2823 perror("[moldyn] load save file read (atoms)");
2830 amutex=malloc(moldyn->count*sizeof(pthread_mutex_t));
2832 perror("[moldyn] load save file (mutexes)");
2835 for(cnt=0;cnt<moldyn->count;cnt++)
2836 pthread_mutex_init(&(amutex[cnt]),NULL);
2844 int moldyn_free_save_file(t_moldyn *moldyn) {
2851 int moldyn_load(t_moldyn *moldyn) {
2859 * function to find/callback all combinations of 2 body bonds
2862 int process_2b_bonds(t_moldyn *moldyn,void *data,
2863 int (*process)(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,
2864 void *data,u8 bc)) {
2874 t_list neighbour[27];
2884 for(i=0;i<moldyn->count;i++) {
2885 /* neighbour indexing */
2886 link_cell_neighbour_index(moldyn,
2887 (itom[i].r.x+moldyn->dim.x/2)/lc->x,
2888 (itom[i].r.y+moldyn->dim.y/2)/lc->x,
2889 (itom[i].r.z+moldyn->dim.z/2)/lc->x,
2894 bc=(j<lc->dnlc)?0:1;
2899 while(neighbour[j][p]!=-1) {
2901 jtom=&(moldyn->atom[neighbour[j][p]]);
2909 p=lc->subcell->list[p];
2911 this=&(neighbour[j]);
2914 if(this->start==NULL)
2919 jtom=this->current->data;
2923 process(moldyn,&(itom[i]),jtom,data,bc);
2930 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
2940 * function to find neighboured atoms
2943 int process_neighbours(t_moldyn *moldyn,void *data,t_atom *atom,
2944 int (*process)(t_moldyn *moldyn,t_atom *atom,t_atom *natom,
2945 void *data,u8 bc)) {
2955 t_list neighbour[27];
2964 /* neighbour indexing */
2965 link_cell_neighbour_index(moldyn,
2966 (atom->r.x+moldyn->dim.x/2)/lc->x,
2967 (atom->r.y+moldyn->dim.y/2)/lc->x,
2968 (atom->r.z+moldyn->dim.z/2)/lc->x,
2973 bc=(j<lc->dnlc)?0:1;
2978 while(neighbour[j][p]!=-1) {
2980 natom=&(moldyn->atom[neighbour[j][p]]);
2987 natom=&(moldyn->atom[p]);
2988 p=lc->subcell->list[p];
2990 this=&(neighbour[j]);
2993 if(this->start==NULL)
2998 natom=this->current->data;
3002 process(moldyn,atom,natom,data,bc);
3009 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
3018 * post processing functions
3021 int get_line(int fd,char *line,int max) {
3028 if(count==max) return count;
3029 ret=read(fd,line+count,1);
3030 if(ret<=0) return ret;
3031 if(line[count]=='\n') {
3032 memset(line+count,0,max-count-1);
3040 int pair_correlation_init(t_moldyn *moldyn,double dr) {
3046 int calculate_diffusion_coefficient(t_moldyn *moldyn,double *dc) {
3062 for(i=0;i<moldyn->count;i++) {
3064 v3_sub(&dist,&(atom[i].r),&(atom[i].r_0));
3065 check_per_bound(moldyn,&dist);
3066 d2=v3_absolute_square(&dist);
3080 dc[0]*=(1.0/(6.0*moldyn->time*a_cnt));
3081 dc[1]*=(1.0/(6.0*moldyn->time*b_cnt));
3082 dc[2]*=(1.0/(6.0*moldyn->time*moldyn->count));
3087 int bonding_analyze(t_moldyn *moldyn,double *cnt) {
3092 int calculate_pair_correlation_process(t_moldyn *moldyn,t_atom *itom,
3093 t_atom *jtom,void *data,u8 bc) {
3100 /* only count pairs once,
3101 * skip same atoms */
3102 if(itom->tag>=jtom->tag)
3106 * pair correlation calc
3113 v3_sub(&dist,&(jtom->r),&(itom->r));
3114 if(bc) check_per_bound(moldyn,&dist);
3115 d=v3_absolute_square(&dist);
3117 /* ignore if greater cutoff */
3118 if(d>moldyn->cutoff_square)
3121 /* fill the slots */
3125 /* should never happen but it does 8) -
3126 * related to -ffloat-store problem! */
3128 printf("[moldyn] WARNING: pcc (%d/%d)",
3134 if(itom->brand!=jtom->brand) {
3139 /* type a - type a bonds */
3141 pcc->stat[s+pcc->o1]+=1;
3143 /* type b - type b bonds */
3144 pcc->stat[s+pcc->o2]+=1;
3150 int calculate_pair_correlation(t_moldyn *moldyn,double dr,void *ptr) {
3157 pcc.o1=moldyn->cutoff/dr;
3160 if(pcc.o1*dr<=moldyn->cutoff)
3161 printf("[moldyn] WARNING: pcc (low #slots)\n");
3163 printf("[moldyn] pair correlation calc info:\n");
3164 printf(" time: %f\n",moldyn->time);
3165 printf(" count: %d\n",moldyn->count);
3166 printf(" cutoff: %f\n",moldyn->cutoff);
3167 printf(" temperature: cur=%f avg=%f\n",moldyn->t,moldyn->t_avg);
3170 pcc.stat=(double *)ptr;
3173 pcc.stat=(double *)malloc(3*pcc.o1*sizeof(double));
3174 if(pcc.stat==NULL) {
3175 perror("[moldyn] pair correlation malloc");
3180 memset(pcc.stat,0,3*pcc.o1*sizeof(double));
3183 process_2b_bonds(moldyn,&pcc,calculate_pair_correlation_process);
3186 for(i=1;i<pcc.o1;i++) {
3187 // normalization: 4 pi r^2 dr
3188 // here: not double counting pairs -> 2 pi r r dr
3189 // ... and actually it's a constant times r^2
3192 pcc.stat[pcc.o1+i]/=norm;
3193 pcc.stat[pcc.o2+i]/=norm;
3198 /* todo: store/print pair correlation function */
3205 int bond_analyze_process(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,
3212 if(itom->tag>=jtom->tag)
3216 v3_sub(&dist,&(jtom->r),&(itom->r));
3217 if(bc) check_per_bound(moldyn,&dist);
3218 d=v3_absolute_square(&dist);
3220 /* ignore if greater or equal cutoff */
3221 if(d>moldyn->cutoff_square)
3224 /* check for potential bond */
3225 if(moldyn->check_2b_bond(moldyn,itom,jtom,bc)==FALSE)
3228 /* now count this bonding ... */
3231 /* increase total bond counter
3236 ba->acnt[jtom->tag]+=1;
3238 ba->bcnt[jtom->tag]+=1;
3241 ba->acnt[itom->tag]+=1;
3243 ba->bcnt[itom->tag]+=1;
3248 int bond_analyze(t_moldyn *moldyn,double *quality) {
3259 ba.acnt=malloc(moldyn->count*sizeof(int));
3261 perror("[moldyn] bond analyze malloc (a)");
3264 memset(ba.acnt,0,moldyn->count*sizeof(int));
3266 ba.bcnt=malloc(moldyn->count*sizeof(int));
3268 perror("[moldyn] bond analyze malloc (b)");
3271 memset(ba.bcnt,0,moldyn->count*sizeof(int));
3280 process_2b_bonds(moldyn,&ba,bond_analyze_process);
3282 for(i=0;i<moldyn->count;i++) {
3283 if(atom[i].brand==0) {
3284 if((ba.acnt[i]==0)&(ba.bcnt[i]==4))
3286 if((ba.acnt[i]==0)&(ba.bcnt[i]==3))
3290 if((ba.acnt[i]==4)&(ba.bcnt[i]==0)) {
3294 if((ba.acnt[i]==3)&(ba.bcnt[i]==0)) {
3303 quality[0]=1.0*ccnt4/bcnt;
3304 quality[1]=1.0*ccnt3/bcnt;
3307 printf("[moldyn] bond analyze: %f %f\n",
3308 1.0*ccnt4/bcnt,1.0*ccnt3/bcnt);
3315 * visualization code
3318 int visual_init(t_moldyn *moldyn,char *filebase) {
3320 strncpy(moldyn->vis.fb,filebase,128);
3325 int visual_bonds_process(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,
3332 if(itom->tag>=jtom->tag)
3335 if(moldyn->check_2b_bond(moldyn,itom,jtom,bc)==FALSE)
3338 if((itom->attr&ATOM_ATTR_VB)|(jtom->attr&ATOM_ATTR_VB))
3339 dprintf(vb->fd,"# [B] %f %f %f %f %f %f\n",
3340 itom->r.x,itom->r.y,itom->r.z,
3341 jtom->r.x,jtom->r.y,jtom->r.z);
3346 #ifdef VISUAL_THREAD
3347 void *visual_atoms(void *ptr) {
3349 int visual_atoms(t_moldyn *moldyn) {
3360 #ifdef VISUAL_THREAD
3374 sprintf(file,"%s/atomic_conf_%08.f.xyz",v->fb,moldyn->time);
3375 vb.fd=open(file,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
3377 perror("open visual save file fd");
3378 #ifndef VISUAL_THREAD
3383 /* write the actual data file */
3386 dprintf(vb.fd,"# [P] %d %08.f <%f,%f,%f>\n",
3387 moldyn->count,moldyn->time,help/40.0,help/40.0,-0.8*help);
3389 // atomic configuration
3390 for(i=0;i<moldyn->count;i++) {
3391 v3_sub(&strain,&(atom[i].r),&(atom[i].r_0));
3392 check_per_bound(moldyn,&strain);
3393 // atom type, positions, color and kinetic energy
3394 dprintf(vb.fd,"%s %f %f %f %s %f\n",pse_name[atom[i].element],
3398 pse_col[atom[i].element],
3400 sqrt(v3_absolute_square(&strain)));
3403 // bonds between atoms
3404 #ifndef VISUAL_THREAD
3405 process_2b_bonds(moldyn,&vb,visual_bonds_process);
3410 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3411 -dim.x/2,-dim.y/2,-dim.z/2,
3412 dim.x/2,-dim.y/2,-dim.z/2);
3413 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3414 -dim.x/2,-dim.y/2,-dim.z/2,
3415 -dim.x/2,dim.y/2,-dim.z/2);
3416 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3417 dim.x/2,dim.y/2,-dim.z/2,
3418 dim.x/2,-dim.y/2,-dim.z/2);
3419 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3420 -dim.x/2,dim.y/2,-dim.z/2,
3421 dim.x/2,dim.y/2,-dim.z/2);
3423 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3424 -dim.x/2,-dim.y/2,dim.z/2,
3425 dim.x/2,-dim.y/2,dim.z/2);
3426 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3427 -dim.x/2,-dim.y/2,dim.z/2,
3428 -dim.x/2,dim.y/2,dim.z/2);
3429 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3430 dim.x/2,dim.y/2,dim.z/2,
3431 dim.x/2,-dim.y/2,dim.z/2);
3432 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3433 -dim.x/2,dim.y/2,dim.z/2,
3434 dim.x/2,dim.y/2,dim.z/2);
3436 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3437 -dim.x/2,-dim.y/2,dim.z/2,
3438 -dim.x/2,-dim.y/2,-dim.z/2);
3439 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3440 -dim.x/2,dim.y/2,dim.z/2,
3441 -dim.x/2,dim.y/2,-dim.z/2);
3442 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3443 dim.x/2,-dim.y/2,dim.z/2,
3444 dim.x/2,-dim.y/2,-dim.z/2);
3445 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3446 dim.x/2,dim.y/2,dim.z/2,
3447 dim.x/2,dim.y/2,-dim.z/2);
3452 #ifdef VISUAL_THREAD
3463 * fpu cntrol functions
3466 // set rounding to double (eliminates -ffloat-store!)
3467 int fpu_set_rtd(void) {
3473 ctrl&=~_FPU_EXTENDED;