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:\
808 case DEFECT_STYPE_DB_R:\
811 printf("[moldyn] WARNING: unknown defect\n");\
814 v3_add(&dr,&pos,&d_o);\
815 v3_copy(&(atom[count].r),&dr);\
817 v3_add(&dr,&pos,&d_d);\
818 v3_copy(&(atom[count].r),&dr);\
822 v3_copy(&(atom[count].r),&pos);\
827 int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin,
828 t_part_params *p_params,t_defect_params *d_params) {
848 /* shift partition values */
850 p.x=p_params->p.x+(a*lc)/2.0;
851 p.y=p_params->p.y+(b*lc)/2.0;
852 p.z=p_params->p.z+(c*lc)/2.0;
861 switch(p_params->type) {
864 if(v3_absolute_square(&dist)<
865 (p_params->r*p_params->r)) {
866 set_atom_positions(r);
871 if(v3_absolute_square(&dist)>=
872 (p_params->r*p_params->r)) {
873 set_atom_positions(r);
878 if((fabs(dist.x)<p_params->d.x)&&
879 (fabs(dist.y)<p_params->d.y)&&
880 (fabs(dist.z)<p_params->d.z)) {
881 set_atom_positions(r);
886 if((fabs(dist.x)>=p_params->d.x)||
887 (fabs(dist.y)>=p_params->d.y)||
888 (fabs(dist.z)>=p_params->d.z)) {
889 set_atom_positions(r);
893 set_atom_positions(r);
903 for(i=0;i<count;i++) {
904 atom[i].r.x-=(a*lc)/2.0;
905 atom[i].r.y-=(b*lc)/2.0;
906 atom[i].r.z-=(c*lc)/2.0;
912 /* fcc lattice init */
913 int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin,
914 t_part_params *p_params,t_defect_params *d_params) {
932 /* construct the basis */
933 memset(basis,0,3*sizeof(t_3dvec));
941 /* shift partition values */
943 p.x=p_params->p.x+(a*lc)/2.0;
944 p.y=p_params->p.y+(b*lc)/2.0;
945 p.z=p_params->p.z+(c*lc)/2.0;
948 /* fill up the room */
956 switch(p_params->type) {
959 if(v3_absolute_square(&dist)<
960 (p_params->r*p_params->r)) {
961 set_atom_positions(r);
966 if(v3_absolute_square(&dist)>=
967 (p_params->r*p_params->r)) {
968 set_atom_positions(r);
973 if((fabs(dist.x)<p_params->d.x)&&
974 (fabs(dist.y)<p_params->d.y)&&
975 (fabs(dist.z)<p_params->d.z)) {
976 set_atom_positions(r);
981 if((fabs(dist.x)>=p_params->d.x)||
982 (fabs(dist.y)>=p_params->d.y)||
983 (fabs(dist.z)>=p_params->d.z)) {
984 set_atom_positions(r);
988 set_atom_positions(r);
991 /* the three face centered atoms */
993 v3_add(&n,&r,&basis[l]);
994 switch(p_params->type) {
997 if(v3_absolute_square(&dist)<
998 (p_params->r*p_params->r)) {
999 set_atom_positions(n);
1002 case PART_OUTSIDE_R:
1003 v3_sub(&dist,&n,&p);
1004 if(v3_absolute_square(&dist)>=
1005 (p_params->r*p_params->r)) {
1006 set_atom_positions(n);
1010 v3_sub(&dist,&n,&p);
1011 if((fabs(dist.x)<p_params->d.x)&&
1012 (fabs(dist.y)<p_params->d.y)&&
1013 (fabs(dist.z)<p_params->d.z)) {
1014 set_atom_positions(n);
1017 case PART_OUTSIDE_D:
1018 v3_sub(&dist,&n,&p);
1019 if((fabs(dist.x)>=p_params->d.x)||
1020 (fabs(dist.y)>=p_params->d.y)||
1021 (fabs(dist.z)>=p_params->d.z)) {
1022 set_atom_positions(n);
1026 set_atom_positions(n);
1037 /* coordinate transformation */
1038 for(i=0;i<count;i++) {
1039 atom[i].r.x-=(a*lc)/2.0;
1040 atom[i].r.y-=(b*lc)/2.0;
1041 atom[i].r.z-=(c*lc)/2.0;
1047 int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin,
1048 t_part_params *p_params,t_defect_params *d_params) {
1053 count=fcc_init(a,b,c,lc,atom,origin,p_params,d_params);
1059 if(origin) v3_add(&o,&o,origin);
1061 count+=fcc_init(a,b,c,lc,&atom[count],&o,p_params,d_params);
1066 int destroy_atoms(t_moldyn *moldyn) {
1068 if(moldyn->atom) free(moldyn->atom);
1073 int thermal_init(t_moldyn *moldyn,u8 equi_init) {
1076 * - gaussian distribution of velocities
1077 * - zero total momentum
1078 * - velocity scaling (E = 3/2 N k T), E: kinetic energy
1083 t_3dvec p_total,delta;
1088 random=&(moldyn->random);
1090 printf("[moldyn] thermal init (equi init: %s)\n",equi_init?"yes":"no");
1092 /* gaussian distribution of velocities */
1094 for(i=0;i<moldyn->count;i++) {
1095 sigma=sqrt(2.0*K_BOLTZMANN*moldyn->t_ref/atom[i].mass);
1097 v=sigma*rand_get_gauss(random);
1099 p_total.x+=atom[i].mass*v;
1101 v=sigma*rand_get_gauss(random);
1103 p_total.y+=atom[i].mass*v;
1105 v=sigma*rand_get_gauss(random);
1107 p_total.z+=atom[i].mass*v;
1110 /* zero total momentum */
1111 v3_scale(&p_total,&p_total,1.0/moldyn->count);
1112 for(i=0;i<moldyn->count;i++) {
1113 v3_scale(&delta,&p_total,1.0/atom[i].mass);
1114 v3_sub(&(atom[i].v),&(atom[i].v),&delta);
1117 /* velocity scaling */
1118 scale_velocity(moldyn,equi_init);
1123 double total_mass_calc(t_moldyn *moldyn) {
1129 for(i=0;i<moldyn->count;i++)
1130 moldyn->mass+=moldyn->atom[i].mass;
1132 return moldyn->mass;
1135 double temperature_calc(t_moldyn *moldyn) {
1137 /* assume up to date kinetic energy, which is 3/2 N k_B T */
1140 moldyn->t=(2.0*moldyn->ekin)/(3.0*K_BOLTZMANN*moldyn->count);
1146 double get_temperature(t_moldyn *moldyn) {
1151 int scale_velocity(t_moldyn *moldyn,u8 equi_init) {
1161 * - velocity scaling (E = 3/2 N k T), E: kinetic energy
1164 /* get kinetic energy / temperature & count involved atoms */
1167 for(i=0;i<moldyn->count;i++) {
1168 if((equi_init&TRUE)||(atom[i].attr&ATOM_ATTR_HB)) {
1169 e+=atom[i].mass*v3_absolute_square(&(atom[i].v));
1174 if(count!=0) moldyn->t=e/(1.5*count*K_BOLTZMANN);
1175 else return 0; /* no atoms involved in scaling! */
1177 /* (temporary) hack for e,t = 0 */
1180 if(moldyn->t_ref!=0.0) {
1181 thermal_init(moldyn,equi_init);
1185 return 0; /* no scaling needed */
1189 /* get scaling factor */
1190 scale=moldyn->t_ref/moldyn->t;
1194 if(moldyn->pt_scale&T_SCALE_BERENDSEN)
1195 scale=1.0+(scale-1.0)*moldyn->tau/moldyn->t_tc;
1198 /* velocity scaling */
1199 for(i=0;i<moldyn->count;i++) {
1200 if((equi_init&TRUE)||(atom[i].attr&ATOM_ATTR_HB))
1201 v3_scale(&(atom[i].v),&(atom[i].v),scale);
1207 double ideal_gas_law_pressure(t_moldyn *moldyn) {
1211 p=moldyn->count*moldyn->t*K_BOLTZMANN/moldyn->volume;
1216 double virial_sum(t_moldyn *moldyn) {
1221 /* virial (sum over atom virials) */
1229 for(i=0;i<moldyn->count;i++) {
1230 virial=&(moldyn->atom[i].virial);
1231 moldyn->virial+=(virial->xx+virial->yy+virial->zz);
1232 moldyn->vir.xx+=virial->xx;
1233 moldyn->vir.yy+=virial->yy;
1234 moldyn->vir.zz+=virial->zz;
1235 moldyn->vir.xy+=virial->xy;
1236 moldyn->vir.xz+=virial->xz;
1237 moldyn->vir.yz+=virial->yz;
1240 /* global virial (absolute coordinates) */
1241 //virial=&(moldyn->gvir);
1242 //moldyn->gv=virial->xx+virial->yy+virial->zz;
1244 return moldyn->virial;
1247 double pressure_calc(t_moldyn *moldyn) {
1251 * with W = 1/3 sum_i f_i r_i (- skipped!)
1252 * virial = sum_i f_i r_i
1254 * => P = (2 Ekin + virial) / (3V)
1257 /* assume up to date virial & up to date kinetic energy */
1259 /* pressure (atom virials) */
1260 moldyn->p=2.0*moldyn->ekin+moldyn->virial;
1261 moldyn->p/=(3.0*moldyn->volume);
1263 //moldyn->px=2.0*moldyn->ekinx+moldyn->vir.xx;
1264 //moldyn->px/=moldyn->volume;
1265 //moldyn->py=2.0*moldyn->ekiny+moldyn->vir.yy;
1266 //moldyn->py/=moldyn->volume;
1267 //moldyn->pz=2.0*moldyn->ekinz+moldyn->vir.zz;
1268 //moldyn->pz/=moldyn->volume;
1270 /* pressure (absolute coordinates) */
1271 //moldyn->gp=2.0*moldyn->ekin+moldyn->gv;
1272 //moldyn->gp/=(3.0*moldyn->volume);
1277 int average_reset(t_moldyn *moldyn) {
1279 printf("[moldyn] average reset\n");
1281 /* update skip value */
1282 moldyn->avg_skip=moldyn->total_steps;
1284 /* kinetic energy */
1288 /* potential energy */
1296 moldyn->virial_sum=0.0;
1297 //moldyn->gv_sum=0.0;
1301 //moldyn->gp_sum=0.0;
1307 int average_and_fluctuation_calc(t_moldyn *moldyn) {
1311 if(moldyn->total_steps<moldyn->avg_skip)
1314 denom=moldyn->total_steps+1-moldyn->avg_skip;
1316 /* assume up to date energies, temperature, pressure etc */
1318 /* kinetic energy */
1319 moldyn->k_sum+=moldyn->ekin;
1320 moldyn->k2_sum+=(moldyn->ekin*moldyn->ekin);
1321 moldyn->k_avg=moldyn->k_sum/denom;
1322 moldyn->k2_avg=moldyn->k2_sum/denom;
1323 moldyn->dk2_avg=moldyn->k2_avg-(moldyn->k_avg*moldyn->k_avg);
1325 /* potential energy */
1326 moldyn->v_sum+=moldyn->energy;
1327 moldyn->v2_sum+=(moldyn->energy*moldyn->energy);
1328 moldyn->v_avg=moldyn->v_sum/denom;
1329 moldyn->v2_avg=moldyn->v2_sum/denom;
1330 moldyn->dv2_avg=moldyn->v2_avg-(moldyn->v_avg*moldyn->v_avg);
1333 moldyn->t_sum+=moldyn->t;
1334 moldyn->t_avg=moldyn->t_sum/denom;
1337 moldyn->virial_sum+=moldyn->virial;
1338 moldyn->virial_avg=moldyn->virial_sum/denom;
1339 //moldyn->gv_sum+=moldyn->gv;
1340 //moldyn->gv_avg=moldyn->gv_sum/denom;
1343 moldyn->p_sum+=moldyn->p;
1344 moldyn->p_avg=moldyn->p_sum/denom;
1345 //moldyn->gp_sum+=moldyn->gp;
1346 //moldyn->gp_avg=moldyn->gp_sum/denom;
1347 moldyn->tp_sum+=moldyn->tp;
1348 moldyn->tp_avg=moldyn->tp_sum/denom;
1353 int get_heat_capacity(t_moldyn *moldyn) {
1357 /* averages needed for heat capacity calc */
1358 if(moldyn->total_steps<moldyn->avg_skip)
1361 /* (temperature average)^2 */
1362 temp2=moldyn->t_avg*moldyn->t_avg;
1363 printf("[moldyn] specific heat capacity for T=%f K [J/(kg K)]\n",
1366 /* ideal gas contribution */
1367 ighc=3.0*moldyn->count*K_BOLTZMANN/2.0;
1368 printf(" ideal gas contribution: %f\n",
1369 ighc/moldyn->mass*KILOGRAM/JOULE);
1371 /* specific heat for nvt ensemble */
1372 moldyn->c_v_nvt=moldyn->dv2_avg/(K_BOLTZMANN*temp2)+ighc;
1373 moldyn->c_v_nvt/=moldyn->mass;
1375 /* specific heat for nve ensemble */
1376 moldyn->c_v_nve=ighc/(1.0-(moldyn->dv2_avg/(ighc*K_BOLTZMANN*temp2)));
1377 moldyn->c_v_nve/=moldyn->mass;
1379 printf(" NVE: %f\n",moldyn->c_v_nve*KILOGRAM/JOULE);
1380 printf(" NVT: %f\n",moldyn->c_v_nvt*KILOGRAM/JOULE);
1381 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)));
1386 double thermodynamic_pressure_calc(t_moldyn *moldyn) {
1402 /* store atomic configuration + dimension */
1403 store=malloc(moldyn->count*sizeof(t_atom));
1405 printf("[moldyn] allocating store mem failed\n");
1408 memcpy(store,moldyn->atom,moldyn->count*sizeof(t_atom));
1413 h=(1.0-sd)*(1.0-sd)*(1.0-sd);
1414 su=pow(2.0-h,ONE_THIRD)-1.0;
1415 dv=(1.0-h)*moldyn->volume;
1417 /* scale up dimension and atom positions */
1418 scale_dim(moldyn,SCALE_UP,su,TRUE,TRUE,TRUE);
1419 scale_atoms(moldyn,SCALE_UP,su,TRUE,TRUE,TRUE);
1420 link_cell_shutdown(moldyn);
1421 link_cell_init(moldyn,QUIET);
1422 potential_force_calc(moldyn);
1425 /* restore atomic configuration + dim */
1426 memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
1429 /* scale down dimension and atom positions */
1430 scale_dim(moldyn,SCALE_DOWN,sd,TRUE,TRUE,TRUE);
1431 scale_atoms(moldyn,SCALE_DOWN,sd,TRUE,TRUE,TRUE);
1432 link_cell_shutdown(moldyn);
1433 link_cell_init(moldyn,QUIET);
1434 potential_force_calc(moldyn);
1437 /* calculate pressure */
1438 moldyn->tp=-(y1-y0)/(2.0*dv);
1440 /* restore atomic configuration */
1441 memcpy(moldyn->atom,store,moldyn->count*sizeof(t_atom));
1443 link_cell_shutdown(moldyn);
1444 link_cell_init(moldyn,QUIET);
1445 //potential_force_calc(moldyn);
1447 /* free store buffer */
1454 double get_pressure(t_moldyn *moldyn) {
1460 int scale_dim(t_moldyn *moldyn,u8 dir,double scale,u8 x,u8 y,u8 z) {
1472 if(x) dim->x*=scale;
1473 if(y) dim->y*=scale;
1474 if(z) dim->z*=scale;
1479 int scale_atoms(t_moldyn *moldyn,u8 dir,double scale,u8 x,u8 y,u8 z) {
1490 for(i=0;i<moldyn->count;i++) {
1491 r=&(moldyn->atom[i].r);
1500 int scale_atoms_ind(t_moldyn *moldyn,double x,double y,double z) {
1505 for(i=0;i<moldyn->count;i++) {
1506 r=&(moldyn->atom[i].r);
1515 int scale_dim_ind(t_moldyn *moldyn,double x,double y,double z) {
1528 int scale_volume(t_moldyn *moldyn) {
1535 vdim=&(moldyn->vis.dim);
1539 /* scaling factor */
1540 if(moldyn->pt_scale&P_SCALE_BERENDSEN) {
1541 scale=1.0-(moldyn->p_ref-moldyn->p)*moldyn->p_tc*moldyn->tau;
1542 scale=pow(scale,ONE_THIRD);
1545 scale=pow(moldyn->p/moldyn->p_ref,ONE_THIRD);
1550 sx=1.0-(moldyn->p_ref-moldyn->px)*moldyn->p_tc*moldyn->tau;
1551 sy=1.0-(moldyn->p_ref-moldyn->py)*moldyn->p_tc*moldyn->tau;
1552 sz=1.0-(moldyn->p_ref-moldyn->pz)*moldyn->p_tc*moldyn->tau;
1553 sx=pow(sx,ONE_THIRD);
1554 sy=pow(sy,ONE_THIRD);
1555 sz=pow(sz,ONE_THIRD);
1558 /* scale the atoms and dimensions */
1559 scale_atoms(moldyn,SCALE_DIRECT,scale,TRUE,TRUE,TRUE);
1560 scale_dim(moldyn,SCALE_DIRECT,scale,TRUE,TRUE,TRUE);
1561 //scale_atoms_ind(moldyn,sx,sy,sz);
1562 //scale_dim_ind(moldyn,sx,sy,sz);
1564 /* visualize dimensions */
1571 /* recalculate scaled volume */
1572 moldyn->volume=dim->x*dim->y*dim->z;
1574 /* adjust/reinit linkcell */
1575 if(((int)(dim->x/moldyn->cutoff)!=lc->nx)||
1576 ((int)(dim->y/moldyn->cutoff)!=lc->ny)||
1577 ((int)(dim->z/moldyn->cutoff)!=lc->nx)) {
1578 link_cell_shutdown(moldyn);
1579 link_cell_init(moldyn,QUIET);
1593 double e_kin_calc(t_moldyn *moldyn) {
1600 //moldyn->ekinx=0.0;
1601 //moldyn->ekiny=0.0;
1602 //moldyn->ekinz=0.0;
1604 for(i=0;i<moldyn->count;i++) {
1605 atom[i].ekin=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v));
1606 moldyn->ekin+=atom[i].ekin;
1607 //moldyn->ekinx+=0.5*atom[i].mass*atom[i].v.x*atom[i].v.x;
1608 //moldyn->ekiny+=0.5*atom[i].mass*atom[i].v.y*atom[i].v.y;
1609 //moldyn->ekinz+=0.5*atom[i].mass*atom[i].v.z*atom[i].v.z;
1612 return moldyn->ekin;
1615 double get_total_energy(t_moldyn *moldyn) {
1617 return(moldyn->ekin+moldyn->energy);
1620 t_3dvec get_total_p(t_moldyn *moldyn) {
1629 for(i=0;i<moldyn->count;i++) {
1630 v3_scale(&p,&(atom[i].v),atom[i].mass);
1631 v3_add(&p_total,&p_total,&p);
1637 double estimate_time_step(t_moldyn *moldyn,double nn_dist) {
1641 /* nn_dist is the nearest neighbour distance */
1643 tau=(0.05*nn_dist*moldyn->atom[0].mass)/sqrt(3.0*K_BOLTZMANN*moldyn->t);
1652 /* linked list / cell method */
1654 int link_cell_init(t_moldyn *moldyn,u8 vol) {
1657 #ifndef LOWMEM_LISTS
1663 /* partitioning the md cell */
1664 lc->nx=moldyn->dim.x/moldyn->cutoff;
1665 lc->x=moldyn->dim.x/lc->nx;
1666 lc->ny=moldyn->dim.y/moldyn->cutoff;
1667 lc->y=moldyn->dim.y/lc->ny;
1668 lc->nz=moldyn->dim.z/moldyn->cutoff;
1669 lc->z=moldyn->dim.z/lc->nz;
1670 lc->cells=lc->nx*lc->ny*lc->nz;
1673 lc->subcell=malloc(lc->cells*sizeof(int*));
1675 lc->subcell=malloc(sizeof(t_lowmem_list));
1677 lc->subcell=malloc(lc->cells*sizeof(t_list));
1680 if(lc->subcell==NULL) {
1681 perror("[moldyn] cell init (malloc)");
1686 printf("[moldyn] FATAL: less then 27 subcells! (%d)\n",
1691 printf("[moldyn] initializing 'static' linked cells (%d)\n",
1694 printf("[moldyn] initializing 'lowmem' linked cells (%d)\n",
1697 printf("[moldyn] initializing 'dynamic' linked cells (%d)\n",
1700 printf(" x: %d x %f A\n",lc->nx,lc->x);
1701 printf(" y: %d x %f A\n",lc->ny,lc->y);
1702 printf(" z: %d x %f A\n",lc->nz,lc->z);
1707 for(i=0;i<lc->cells;i++) {
1708 lc->subcell[i]=malloc((MAX_ATOMS_PER_LIST+1)*sizeof(int));
1709 if(lc->subcell[i]==NULL) {
1710 perror("[moldyn] list init (malloc)");
1715 printf(" ---> %d malloc %p (%p)\n",
1716 i,lc->subcell[0],lc->subcell);
1720 lc->subcell->head=malloc(lc->cells*sizeof(int));
1721 if(lc->subcell->head==NULL) {
1722 perror("[moldyn] head init (malloc)");
1725 lc->subcell->list=malloc(moldyn->count*sizeof(int));
1726 if(lc->subcell->list==NULL) {
1727 perror("[moldyn] list init (malloc)");
1731 for(i=0;i<lc->cells;i++)
1732 list_init_f(&(lc->subcell[i]));
1735 /* update the list */
1736 link_cell_update(moldyn);
1741 int link_cell_update(t_moldyn *moldyn) {
1759 for(i=0;i<lc->cells;i++)
1761 memset(lc->subcell[i],-1,(MAX_ATOMS_PER_LIST+1)*sizeof(int));
1763 lc->subcell->head[i]=-1;
1765 list_destroy_f(&(lc->subcell[i]));
1768 for(count=0;count<moldyn->count;count++) {
1769 i=((atom[count].r.x+(moldyn->dim.x/2))/lc->x);
1770 j=((atom[count].r.y+(moldyn->dim.y/2))/lc->y);
1771 k=((atom[count].r.z+(moldyn->dim.z/2))/lc->z);
1775 while(lc->subcell[i+j*nx+k*nxy][p]!=-1)
1778 if(p>=MAX_ATOMS_PER_LIST) {
1779 printf("[moldyn] FATAL: amount of atoms too high!\n");
1783 lc->subcell[i+j*nx+k*nxy][p]=count;
1786 lc->subcell->list[count]=lc->subcell->head[p];
1787 lc->subcell->head[p]=count;
1789 list_add_immediate_f(&(lc->subcell[i+j*nx+k*nxy]),
1793 printf(" ---> %d %d malloc %p (%p)\n",
1794 i,count,lc->subcell[i].current,lc->subcell);
1802 int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,
1828 if(i>=nx||j>=ny||k>=nz)
1829 printf("[moldyn] WARNING: lcni %d/%d %d/%d %d/%d\n",
1832 #ifndef LOWMEM_LISTS
1833 cell[0]=lc->subcell[i+j*nx+k*a];
1835 cell[0]=lc->subcell->head[i+j*nx+k*a];
1837 for(ci=-1;ci<=1;ci++) {
1840 if((x<0)||(x>=nx)) {
1844 for(cj=-1;cj<=1;cj++) {
1847 if((y<0)||(y>=ny)) {
1851 for(ck=-1;ck<=1;ck++) {
1854 if((z<0)||(z>=nz)) {
1858 if(!(ci|cj|ck)) continue;
1860 #ifndef LOWMEM_LISTS
1861 cell[--count2]=lc->subcell[x+y*nx+z*a];
1863 cell[--count2]=lc->subcell->head[x+y*nx+z*a];
1868 #ifndef LOWMEM_LISTS
1869 cell[count1++]=lc->subcell[x+y*nx+z*a];
1871 cell[count1++]=lc->subcell->head[x+y*nx+z*a];
1883 int link_cell_shutdown(t_moldyn *moldyn) {
1885 #ifndef LOWMEM_LISTS
1893 free(lc->subcell->head);
1894 free(lc->subcell->list);
1898 for(i=0;i<lc->cells;i++) {
1900 free(lc->subcell[i]);
1902 //printf(" ---> %d free %p\n",i,lc->subcell[i].start);
1903 list_destroy_f(&(lc->subcell[i]));
1913 int moldyn_add_schedule(t_moldyn *moldyn,int runs,double tau) {
1917 t_moldyn_schedule *schedule;
1919 schedule=&(moldyn->schedule);
1920 count=++(schedule->total_sched);
1922 ptr=realloc(schedule->runs,count*sizeof(int));
1924 perror("[moldyn] realloc (runs)");
1928 schedule->runs[count-1]=runs;
1930 ptr=realloc(schedule->tau,count*sizeof(double));
1932 perror("[moldyn] realloc (tau)");
1936 schedule->tau[count-1]=tau;
1938 printf("[moldyn] schedule added:\n");
1939 printf(" number: %d | runs: %d | tau: %f\n",count-1,runs,tau);
1945 int moldyn_set_schedule_hook(t_moldyn *moldyn,set_hook hook,void *hook_params) {
1947 moldyn->schedule.hook=hook;
1948 moldyn->schedule.hook_params=hook_params;
1955 * 'integration of newtons equation' - algorithms
1959 /* start the integration */
1961 int moldyn_integrate(t_moldyn *moldyn) {
1964 unsigned int e,m,s,v,p,t,a;
1966 t_moldyn_schedule *sched;
1971 double energy_scale;
1972 struct timeval t1,t2;
1975 #ifdef VISUAL_THREAD
1977 pthread_t io_thread;
1986 sched=&(moldyn->schedule);
1989 /* initialize linked cell method */
1990 link_cell_init(moldyn,VERBOSE);
1992 /* logging & visualization */
2001 /* sqaure of some variables */
2002 moldyn->tau_square=moldyn->tau*moldyn->tau;
2004 /* get current time */
2005 gettimeofday(&t1,NULL);
2007 /* calculate initial forces */
2008 potential_force_calc(moldyn);
2013 /* some stupid checks before we actually start calculating bullshit */
2014 if(moldyn->cutoff>0.5*moldyn->dim.x)
2015 printf("[moldyn] WARNING: cutoff > 0.5 x dim.x\n");
2016 if(moldyn->cutoff>0.5*moldyn->dim.y)
2017 printf("[moldyn] WARNING: cutoff > 0.5 x dim.y\n");
2018 if(moldyn->cutoff>0.5*moldyn->dim.z)
2019 printf("[moldyn] WARNING: cutoff > 0.5 x dim.z\n");
2021 ds=0.5*atom[0].f.x*moldyn->tau_square/atom[0].mass;
2022 if(ds>0.05*moldyn->nnd)
2023 printf("[moldyn] WARNING: forces too high / tau too small!\n");
2026 /* zero absolute time */
2027 // should have right values!
2029 //moldyn->total_steps=0;
2031 /* debugging, ignore */
2034 /* zero & init moldyn copy */
2035 #ifdef VISUAL_THREAD
2036 memset(&md_copy,0,sizeof(t_moldyn));
2037 atom_copy=malloc(moldyn->count*sizeof(t_atom));
2038 if(atom_copy==NULL) {
2039 perror("[moldyn] malloc atom copy (init)");
2045 printf("##################\n");
2046 printf("# USING PTHREADS #\n");
2047 printf("##################\n");
2049 /* tell the world */
2050 printf("[moldyn] integration start, go get a coffee ...\n");
2052 /* executing the schedule */
2054 while(sched->count<sched->total_sched) {
2056 /* setting amount of runs and finite time step size */
2057 moldyn->tau=sched->tau[sched->count];
2058 moldyn->tau_square=moldyn->tau*moldyn->tau;
2059 moldyn->time_steps=sched->runs[sched->count];
2061 /* energy scaling factor (might change!) */
2062 energy_scale=moldyn->count*EV;
2064 /* integration according to schedule */
2066 for(i=0;i<moldyn->time_steps;i++) {
2068 /* integration step */
2069 moldyn->integrate(moldyn);
2071 /* calculate kinetic energy, temperature and pressure */
2073 temperature_calc(moldyn);
2075 pressure_calc(moldyn);
2077 thermodynamic_pressure_calc(moldyn);
2078 printf("\n\nDEBUG: numeric pressure calc: %f\n\n",
2082 /* calculate fluctuations + averages */
2083 average_and_fluctuation_calc(moldyn);
2086 if(moldyn->pt_scale&(T_SCALE_BERENDSEN|T_SCALE_DIRECT))
2087 scale_velocity(moldyn,FALSE);
2088 if(moldyn->pt_scale&(P_SCALE_BERENDSEN|P_SCALE_DIRECT))
2089 scale_volume(moldyn);
2091 /* check for log & visualization */
2093 if(!(moldyn->total_steps%e))
2094 dprintf(moldyn->efd,
2095 "%f %f %f %f %f %f\n",
2096 moldyn->time,moldyn->ekin/energy_scale,
2097 moldyn->energy/energy_scale,
2098 get_total_energy(moldyn)/energy_scale,
2099 moldyn->ekin/EV,moldyn->energy/EV);
2102 if(!(moldyn->total_steps%m)) {
2103 momentum=get_total_p(moldyn);
2104 dprintf(moldyn->mfd,
2105 "%f %f %f %f %f\n",moldyn->time,
2106 momentum.x,momentum.y,momentum.z,
2107 v3_norm(&momentum));
2111 if(!(moldyn->total_steps%p)) {
2112 dprintf(moldyn->pfd,
2113 "%f %f %f %f %f %f %f\n",moldyn->time,
2114 moldyn->p/BAR,moldyn->p_avg/BAR,
2115 moldyn->p/BAR,moldyn->p_avg/BAR,
2116 moldyn->tp/BAR,moldyn->tp_avg/BAR);
2120 if(!(moldyn->total_steps%t)) {
2121 dprintf(moldyn->tfd,
2123 moldyn->time,moldyn->t,moldyn->t_avg);
2127 if(!(moldyn->total_steps%v)) {
2128 dprintf(moldyn->vfd,
2129 "%f %f %f %f %f\n",moldyn->time,
2137 if(!(moldyn->total_steps%s)) {
2138 snprintf(dir,128,"%s/s-%08.f.save",
2139 moldyn->vlsdir,moldyn->time);
2140 fd=open(dir,O_WRONLY|O_TRUNC|O_CREAT,
2142 if(fd<0) perror("[moldyn] save fd open");
2144 write(fd,moldyn,sizeof(t_moldyn));
2145 write(fd,moldyn->atom,
2146 moldyn->count*sizeof(t_atom));
2152 if(!(moldyn->total_steps%a)) {
2153 #ifdef VISUAL_THREAD
2154 /* check whether thread has not terminated yet */
2156 ret=pthread_join(io_thread,NULL);
2159 /* prepare and start thread */
2160 if(moldyn->count!=md_copy.count) {
2164 memcpy(&md_copy,moldyn,sizeof(t_moldyn));
2166 atom_copy=malloc(moldyn->count*sizeof(t_atom));
2167 if(atom_copy==NULL) {
2168 perror("[moldyn] malloc atom copy (change)");
2172 md_copy.atom=atom_copy;
2173 memcpy(atom_copy,moldyn->atom,moldyn->count*sizeof(t_atom));
2175 ret=pthread_create(&io_thread,NULL,visual_atoms,&md_copy);
2177 perror("[moldyn] create visual atoms thread\n");
2181 visual_atoms(moldyn);
2186 /* display progress */
2190 /* get current time */
2191 gettimeofday(&t2,NULL);
2193 printf("sched:%d, steps:%d/%d, T:%4.1f/%4.1f P:%4.1f/%4.1f V:%6.1f (%d)\n",
2194 sched->count,i,moldyn->total_steps,
2195 moldyn->t,moldyn->t_avg,
2197 moldyn->p/BAR,moldyn->p_avg/BAR,
2199 moldyn->p/BAR,(moldyn->p-2.0*moldyn->ekin/(3.0*moldyn->volume))/BAR,
2202 (int)(t2.tv_sec-t1.tv_sec));
2206 /* copy over time */
2212 /* increase absolute time */
2213 moldyn->time+=moldyn->tau;
2214 moldyn->total_steps+=1;
2218 /* check for hooks */
2220 printf("\n ## schedule hook %d start ##\n",
2222 sched->hook(moldyn,sched->hook_params);
2223 printf(" ## schedule hook end ##\n");
2226 /* increase the schedule counter */
2234 /* velocity verlet */
2236 int velocity_verlet(t_moldyn *moldyn) {
2239 double tau,tau_square,h;
2244 count=moldyn->count;
2246 tau_square=moldyn->tau_square;
2248 for(i=0;i<count;i++) {
2249 /* check whether fixed atom */
2250 if(atom[i].attr&ATOM_ATTR_FP)
2254 v3_scale(&delta,&(atom[i].v),tau);
2255 v3_add(&(atom[i].r),&(atom[i].r),&delta);
2256 v3_scale(&delta,&(atom[i].f),h*tau_square);
2257 v3_add(&(atom[i].r),&(atom[i].r),&delta);
2258 //check_per_bound_and_care_for_pbc(moldyn,&(atom[i]));
2259 check_per_bound(moldyn,&(atom[i].r));
2261 /* velocities [actually v(t+tau/2)] */
2262 v3_scale(&delta,&(atom[i].f),h*tau);
2263 v3_add(&(atom[i].v),&(atom[i].v),&delta);
2266 /* criticial check */
2267 moldyn_bc_check(moldyn);
2269 /* neighbour list update */
2270 link_cell_update(moldyn);
2272 /* forces depending on chosen potential */
2274 // if albe, use albe force calc routine
2275 //if(moldyn->func3b_j1==albe_mult_3bp_j1)
2276 // albe_potential_force_calc(moldyn);
2278 potential_force_calc(moldyn);
2280 albe_potential_force_calc(moldyn);
2283 for(i=0;i<count;i++) {
2284 /* check whether fixed atom */
2285 if(atom[i].attr&ATOM_ATTR_FP)
2287 /* again velocities [actually v(t+tau)] */
2288 v3_scale(&delta,&(atom[i].f),0.5*tau/atom[i].mass);
2289 v3_add(&(atom[i].v),&(atom[i].v),&delta);
2298 * potentials & corresponding forces & virial routine
2302 /* generic potential and force calculation */
2304 int potential_force_calc(t_moldyn *moldyn) {
2307 t_atom *itom,*jtom,*ktom;
2311 int *neighbour_i[27];
2315 int neighbour_i[27];
2318 t_list neighbour_i[27];
2319 t_list neighbour_i2[27];
2325 count=moldyn->count;
2335 /* reset global virial */
2336 memset(&(moldyn->gvir),0,sizeof(t_virial));
2338 /* reset force, site energy and virial of every atom */
2340 i=omp_get_thread_num();
2341 #pragma omp parallel for private(virial)
2343 for(i=0;i<count;i++) {
2346 v3_zero(&(itom[i].f));
2349 virial=(&(itom[i].virial));
2357 /* reset site energy */
2362 /* get energy, force and virial of every atom */
2364 /* first (and only) loop over atoms i */
2365 for(i=0;i<count;i++) {
2367 /* single particle potential/force */
2368 if(itom[i].attr&ATOM_ATTR_1BP)
2370 moldyn->func1b(moldyn,&(itom[i]));
2372 if(!(itom[i].attr&(ATOM_ATTR_2BP|ATOM_ATTR_3BP)))
2375 /* 2 body pair potential/force */
2377 link_cell_neighbour_index(moldyn,
2378 (itom[i].r.x+moldyn->dim.x/2)/lc->x,
2379 (itom[i].r.y+moldyn->dim.y/2)/lc->y,
2380 (itom[i].r.z+moldyn->dim.z/2)/lc->z,
2385 /* first loop over atoms j */
2386 if(moldyn->func2b) {
2393 while(neighbour_i[j][p]!=-1) {
2395 jtom=&(atom[neighbour_i[j][p]]);
2403 p=lc->subcell->list[p];
2405 this=&(neighbour_i[j]);
2408 if(this->start==NULL)
2412 jtom=this->current->data;
2415 if(jtom==&(itom[i]))
2418 if((jtom->attr&ATOM_ATTR_2BP)&
2419 (itom[i].attr&ATOM_ATTR_2BP)) {
2420 moldyn->func2b(moldyn,
2430 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
2436 /* 3 body potential/force */
2438 if(!(itom[i].attr&ATOM_ATTR_3BP))
2441 /* copy the neighbour lists */
2443 /* no copy needed for static lists */
2445 /* no copy needed for lowmem lists */
2447 memcpy(neighbour_i2,neighbour_i,27*sizeof(t_list));
2450 /* second loop over atoms j */
2457 while(neighbour_i[j][p]!=-1) {
2459 jtom=&(atom[neighbour_i[j][p]]);
2467 p=lc->subcell->list[p];
2469 this=&(neighbour_i[j]);
2472 if(this->start==NULL)
2477 jtom=this->current->data;
2480 if(jtom==&(itom[i]))
2483 if(!(jtom->attr&ATOM_ATTR_3BP))
2489 if(moldyn->func3b_j1)
2490 moldyn->func3b_j1(moldyn,
2495 /* in first j loop, 3bp run can be skipped */
2496 if(!(moldyn->run3bp))
2499 /* first loop over atoms k */
2500 if(moldyn->func3b_k1) {
2508 while(neighbour_i[k][q]!=-1) {
2510 ktom=&(atom[neighbour_i[k][q]]);
2518 q=lc->subcell->list[q];
2520 that=&(neighbour_i2[k]);
2523 if(that->start==NULL)
2527 ktom=that->current->data;
2530 if(!(ktom->attr&ATOM_ATTR_3BP))
2536 if(ktom==&(itom[i]))
2539 moldyn->func3b_k1(moldyn,
2550 } while(list_next_f(that)!=\
2558 if(moldyn->func3b_j2)
2559 moldyn->func3b_j2(moldyn,
2564 /* second loop over atoms k */
2565 if(moldyn->func3b_k2) {
2573 while(neighbour_i[k][q]!=-1) {
2575 ktom=&(atom[neighbour_i[k][q]]);
2583 q=lc->subcell->list[q];
2585 that=&(neighbour_i2[k]);
2588 if(that->start==NULL)
2592 ktom=that->current->data;
2595 if(!(ktom->attr&ATOM_ATTR_3BP))
2601 if(ktom==&(itom[i]))
2604 moldyn->func3b_k2(moldyn,
2615 } while(list_next_f(that)!=\
2623 /* 2bp post function */
2624 if(moldyn->func3b_j3) {
2625 moldyn->func3b_j3(moldyn,
2634 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
2649 //printf("\nATOM 0: %f %f %f\n\n",itom->f.x,itom->f.y,itom->f.z);
2650 if(moldyn->time>DSTART&&moldyn->time<DEND) {
2652 printf(" x: %0.40f\n",moldyn->atom[DATOM].f.x);
2653 printf(" y: %0.40f\n",moldyn->atom[DATOM].f.y);
2654 printf(" z: %0.40f\n",moldyn->atom[DATOM].f.z);
2658 /* some postprocessing */
2660 #pragma omp parallel for
2662 for(i=0;i<count;i++) {
2663 /* calculate global virial */
2664 moldyn->gvir.xx+=itom[i].r.x*itom[i].f.x;
2665 moldyn->gvir.yy+=itom[i].r.y*itom[i].f.y;
2666 moldyn->gvir.zz+=itom[i].r.z*itom[i].f.z;
2667 moldyn->gvir.xy+=itom[i].r.y*itom[i].f.x;
2668 moldyn->gvir.xz+=itom[i].r.z*itom[i].f.x;
2669 moldyn->gvir.yz+=itom[i].r.z*itom[i].f.y;
2671 /* check forces regarding the given timestep */
2672 if(v3_norm(&(itom[i].f))>\
2673 0.1*moldyn->nnd*itom[i].mass/moldyn->tau_square)
2674 printf("[moldyn] WARNING: pfc (high force: atom %d)\n",
2682 * virial calculation
2685 //inline int virial_calc(t_atom *a,t_3dvec *f,t_3dvec *d) {
2686 int virial_calc(t_atom *a,t_3dvec *f,t_3dvec *d) {
2688 a->virial.xx+=f->x*d->x;
2689 a->virial.yy+=f->y*d->y;
2690 a->virial.zz+=f->z*d->z;
2691 a->virial.xy+=f->x*d->y;
2692 a->virial.xz+=f->x*d->z;
2693 a->virial.yz+=f->y*d->z;
2699 * periodic boundary checking
2702 //inline int check_per_bound(t_moldyn *moldyn,t_3dvec *a) {
2703 int check_per_bound(t_moldyn *moldyn,t_3dvec *a) {
2714 if(moldyn->status&MOLDYN_STAT_PBX) {
2715 if(a->x>=x) a->x-=dim->x;
2716 else if(-a->x>x) a->x+=dim->x;
2718 if(moldyn->status&MOLDYN_STAT_PBY) {
2719 if(a->y>=y) a->y-=dim->y;
2720 else if(-a->y>y) a->y+=dim->y;
2722 if(moldyn->status&MOLDYN_STAT_PBZ) {
2723 if(a->z>=z) a->z-=dim->z;
2724 else if(-a->z>z) a->z+=dim->z;
2730 int check_per_bound_and_care_for_pbc(t_moldyn *moldyn,t_atom *a) {
2741 if(moldyn->status&MOLDYN_STAT_PBX) {
2746 else if(-a->r.x>x) {
2751 if(moldyn->status&MOLDYN_STAT_PBY) {
2756 else if(-a->r.y>y) {
2761 if(moldyn->status&MOLDYN_STAT_PBZ) {
2766 else if(-a->r.z>z) {
2776 * debugging / critical check functions
2779 int moldyn_bc_check(t_moldyn *moldyn) {
2792 for(i=0;i<moldyn->count;i++) {
2793 if(atom[i].r.x>=dim->x/2||-atom[i].r.x>dim->x/2) {
2794 printf("FATAL: atom %d: x: %.20f (%.20f)\n",
2795 i,atom[i].r.x,dim->x/2);
2796 printf("diagnostic:\n");
2797 printf("-----------\natom.r.x:\n");
2799 memcpy(&byte,(u8 *)(&(atom[i].r.x))+j,1);
2802 ((byte)&(1<<k))?1:0,
2805 printf("---------------\nx=dim.x/2:\n");
2807 memcpy(&byte,(u8 *)(&x)+j,1);
2810 ((byte)&(1<<k))?1:0,
2813 if(atom[i].r.x==x) printf("the same!\n");
2814 else printf("different!\n");
2816 if(atom[i].r.y>=dim->y/2||-atom[i].r.y>dim->y/2)
2817 printf("FATAL: atom %d: y: %.20f (%.20f)\n",
2818 i,atom[i].r.y,dim->y/2);
2819 if(atom[i].r.z>=dim->z/2||-atom[i].r.z>dim->z/2)
2820 printf("FATAL: atom %d: z: %.20f (%.20f)\n",
2821 i,atom[i].r.z,dim->z/2);
2831 int moldyn_read_save_file(t_moldyn *moldyn,char *file) {
2838 fd=open(file,O_RDONLY);
2840 perror("[moldyn] load save file open");
2844 fsize=lseek(fd,0,SEEK_END);
2845 lseek(fd,0,SEEK_SET);
2847 size=sizeof(t_moldyn);
2850 cnt=read(fd,moldyn,size);
2852 perror("[moldyn] load save file read (moldyn)");
2858 size=moldyn->count*sizeof(t_atom);
2860 /* correcting possible atom data offset */
2862 if(fsize!=sizeof(t_moldyn)+size) {
2863 corr=fsize-sizeof(t_moldyn)-size;
2864 printf("[moldyn] WARNING: lsf (illegal file size)\n");
2865 printf(" moifying offset:\n");
2866 printf(" - current pos: %d\n",sizeof(t_moldyn));
2867 printf(" - atom size: %d\n",size);
2868 printf(" - file size: %d\n",fsize);
2869 printf(" => correction: %d\n",corr);
2870 lseek(fd,corr,SEEK_CUR);
2873 moldyn->atom=(t_atom *)malloc(size);
2874 if(moldyn->atom==NULL) {
2875 perror("[moldyn] load save file malloc (atoms)");
2880 cnt=read(fd,moldyn->atom,size);
2882 perror("[moldyn] load save file read (atoms)");
2889 amutex=malloc(moldyn->count*sizeof(pthread_mutex_t));
2891 perror("[moldyn] load save file (mutexes)");
2894 for(cnt=0;cnt<moldyn->count;cnt++)
2895 pthread_mutex_init(&(amutex[cnt]),NULL);
2903 int moldyn_free_save_file(t_moldyn *moldyn) {
2910 int moldyn_load(t_moldyn *moldyn) {
2918 * function to find/callback all combinations of 2 body bonds
2921 int process_2b_bonds(t_moldyn *moldyn,void *data,
2922 int (*process)(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,
2923 void *data,u8 bc)) {
2933 t_list neighbour[27];
2943 for(i=0;i<moldyn->count;i++) {
2944 /* neighbour indexing */
2945 link_cell_neighbour_index(moldyn,
2946 (itom[i].r.x+moldyn->dim.x/2)/lc->x,
2947 (itom[i].r.y+moldyn->dim.y/2)/lc->x,
2948 (itom[i].r.z+moldyn->dim.z/2)/lc->x,
2953 bc=(j<lc->dnlc)?0:1;
2958 while(neighbour[j][p]!=-1) {
2960 jtom=&(moldyn->atom[neighbour[j][p]]);
2968 p=lc->subcell->list[p];
2970 this=&(neighbour[j]);
2973 if(this->start==NULL)
2978 jtom=this->current->data;
2982 process(moldyn,&(itom[i]),jtom,data,bc);
2989 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
2999 * function to find neighboured atoms
3002 int process_neighbours(t_moldyn *moldyn,void *data,t_atom *atom,
3003 int (*process)(t_moldyn *moldyn,t_atom *atom,t_atom *natom,
3004 void *data,u8 bc)) {
3014 t_list neighbour[27];
3023 /* neighbour indexing */
3024 link_cell_neighbour_index(moldyn,
3025 (atom->r.x+moldyn->dim.x/2)/lc->x,
3026 (atom->r.y+moldyn->dim.y/2)/lc->x,
3027 (atom->r.z+moldyn->dim.z/2)/lc->x,
3032 bc=(j<lc->dnlc)?0:1;
3037 while(neighbour[j][p]!=-1) {
3039 natom=&(moldyn->atom[neighbour[j][p]]);
3046 natom=&(moldyn->atom[p]);
3047 p=lc->subcell->list[p];
3049 this=&(neighbour[j]);
3052 if(this->start==NULL)
3057 natom=this->current->data;
3061 process(moldyn,atom,natom,data,bc);
3068 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
3077 * post processing functions
3080 int get_line(int fd,char *line,int max) {
3087 if(count==max) return count;
3088 ret=read(fd,line+count,1);
3089 if(ret<=0) return ret;
3090 if(line[count]=='\n') {
3091 memset(line+count,0,max-count-1);
3099 int pair_correlation_init(t_moldyn *moldyn,double dr) {
3105 int calculate_diffusion_coefficient(t_moldyn *moldyn,double *dc) {
3122 for(i=0;i<moldyn->count;i++) {
3124 /* care for pb crossing */
3125 final_r.x=atom[i].r.x+atom[i].pbc[0]*moldyn->dim.x;
3126 final_r.y=atom[i].r.y+atom[i].pbc[1]*moldyn->dim.y;
3127 final_r.z=atom[i].r.z+atom[i].pbc[2]*moldyn->dim.z;
3128 /* calculate distance */
3129 v3_sub(&dist,&final_r,&(atom[i].r_0));
3130 d2=v3_absolute_square(&dist);
3144 dc[0]*=(1.0/(6.0*moldyn->time*a_cnt));
3145 dc[1]*=(1.0/(6.0*moldyn->time*b_cnt));
3146 dc[2]*=(1.0/(6.0*moldyn->time*moldyn->count));
3151 int bonding_analyze(t_moldyn *moldyn,double *cnt) {
3156 int calculate_pair_correlation_process(t_moldyn *moldyn,t_atom *itom,
3157 t_atom *jtom,void *data,u8 bc) {
3164 /* only count pairs once,
3165 * skip same atoms */
3166 if(itom->tag>=jtom->tag)
3170 * pair correlation calc
3177 v3_sub(&dist,&(jtom->r),&(itom->r));
3178 if(bc) check_per_bound(moldyn,&dist);
3179 d=v3_absolute_square(&dist);
3181 /* ignore if greater cutoff */
3182 if(d>moldyn->cutoff_square)
3185 /* fill the slots */
3189 /* should never happen but it does 8) -
3190 * related to -ffloat-store problem! */
3192 printf("[moldyn] WARNING: pcc (%d/%d)",
3198 if(itom->brand!=jtom->brand) {
3203 /* type a - type a bonds */
3205 pcc->stat[s+pcc->o1]+=1;
3207 /* type b - type b bonds */
3208 pcc->stat[s+pcc->o2]+=1;
3214 int calculate_pair_correlation(t_moldyn *moldyn,double dr,void *ptr) {
3221 pcc.o1=moldyn->cutoff/dr;
3224 if(pcc.o1*dr<=moldyn->cutoff)
3225 printf("[moldyn] WARNING: pcc (low #slots)\n");
3227 printf("[moldyn] pair correlation calc info:\n");
3228 printf(" time: %f\n",moldyn->time);
3229 printf(" count: %d\n",moldyn->count);
3230 printf(" cutoff: %f\n",moldyn->cutoff);
3231 printf(" temperature: cur=%f avg=%f\n",moldyn->t,moldyn->t_avg);
3234 pcc.stat=(double *)ptr;
3237 pcc.stat=(double *)malloc(3*pcc.o1*sizeof(double));
3238 if(pcc.stat==NULL) {
3239 perror("[moldyn] pair correlation malloc");
3244 memset(pcc.stat,0,3*pcc.o1*sizeof(double));
3247 process_2b_bonds(moldyn,&pcc,calculate_pair_correlation_process);
3250 for(i=1;i<pcc.o1;i++) {
3251 // normalization: 4 pi r^2 dr
3252 // here: not double counting pairs -> 2 pi r r dr
3253 // ... and actually it's a constant times r^2
3256 pcc.stat[pcc.o1+i]/=norm;
3257 pcc.stat[pcc.o2+i]/=norm;
3262 /* todo: store/print pair correlation function */
3269 int bond_analyze_process(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,
3276 if(itom->tag>=jtom->tag)
3280 v3_sub(&dist,&(jtom->r),&(itom->r));
3281 if(bc) check_per_bound(moldyn,&dist);
3282 d=v3_absolute_square(&dist);
3284 /* ignore if greater or equal cutoff */
3285 if(d>moldyn->cutoff_square)
3288 /* check for potential bond */
3289 if(moldyn->check_2b_bond(moldyn,itom,jtom,bc)==FALSE)
3292 /* now count this bonding ... */
3295 /* increase total bond counter
3300 ba->acnt[jtom->tag]+=1;
3302 ba->bcnt[jtom->tag]+=1;
3305 ba->acnt[itom->tag]+=1;
3307 ba->bcnt[itom->tag]+=1;
3312 int bond_analyze(t_moldyn *moldyn,double *quality) {
3323 ba.acnt=malloc(moldyn->count*sizeof(int));
3325 perror("[moldyn] bond analyze malloc (a)");
3328 memset(ba.acnt,0,moldyn->count*sizeof(int));
3330 ba.bcnt=malloc(moldyn->count*sizeof(int));
3332 perror("[moldyn] bond analyze malloc (b)");
3335 memset(ba.bcnt,0,moldyn->count*sizeof(int));
3344 process_2b_bonds(moldyn,&ba,bond_analyze_process);
3346 for(i=0;i<moldyn->count;i++) {
3347 if(atom[i].brand==0) {
3348 if((ba.acnt[i]==0)&(ba.bcnt[i]==4))
3350 if((ba.acnt[i]==0)&(ba.bcnt[i]==3))
3354 if((ba.acnt[i]==4)&(ba.bcnt[i]==0)) {
3358 if((ba.acnt[i]==3)&(ba.bcnt[i]==0)) {
3367 quality[0]=1.0*ccnt4/bcnt;
3368 quality[1]=1.0*ccnt3/bcnt;
3371 printf("[moldyn] bond analyze: %f %f\n",
3372 1.0*ccnt4/bcnt,1.0*ccnt3/bcnt);
3379 * visualization code
3382 int visual_init(t_moldyn *moldyn,char *filebase) {
3384 strncpy(moldyn->vis.fb,filebase,128);
3389 int visual_bonds_process(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,
3396 if(itom->tag>=jtom->tag)
3399 if(moldyn->check_2b_bond(moldyn,itom,jtom,bc)==FALSE)
3402 if((itom->attr&ATOM_ATTR_VB)|(jtom->attr&ATOM_ATTR_VB))
3403 dprintf(vb->fd,"# [B] %f %f %f %f %f %f\n",
3404 itom->r.x,itom->r.y,itom->r.z,
3405 jtom->r.x,jtom->r.y,jtom->r.z);
3410 #ifdef VISUAL_THREAD
3411 void *visual_atoms(void *ptr) {
3413 int visual_atoms(t_moldyn *moldyn) {
3424 #ifdef VISUAL_THREAD
3438 sprintf(file,"%s/atomic_conf_%08.f.xyz",v->fb,moldyn->time);
3439 vb.fd=open(file,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
3441 perror("open visual save file fd");
3442 #ifndef VISUAL_THREAD
3447 /* write the actual data file */
3450 dprintf(vb.fd,"# [P] %d %08.f <%f,%f,%f>\n",
3451 moldyn->count,moldyn->time,help/40.0,help/40.0,-0.8*help);
3453 // atomic configuration
3454 for(i=0;i<moldyn->count;i++) {
3455 v3_sub(&strain,&(atom[i].r),&(atom[i].r_0));
3456 check_per_bound(moldyn,&strain);
3457 // atom type, positions, color and kinetic energy
3458 dprintf(vb.fd,"%s %f %f %f %s %f\n",pse_name[atom[i].element],
3462 pse_col[atom[i].element],
3464 sqrt(v3_absolute_square(&strain)));
3467 // bonds between atoms
3468 #ifndef VISUAL_THREAD
3469 process_2b_bonds(moldyn,&vb,visual_bonds_process);
3474 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3475 -dim.x/2,-dim.y/2,-dim.z/2,
3476 dim.x/2,-dim.y/2,-dim.z/2);
3477 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3478 -dim.x/2,-dim.y/2,-dim.z/2,
3479 -dim.x/2,dim.y/2,-dim.z/2);
3480 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3481 dim.x/2,dim.y/2,-dim.z/2,
3482 dim.x/2,-dim.y/2,-dim.z/2);
3483 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3484 -dim.x/2,dim.y/2,-dim.z/2,
3485 dim.x/2,dim.y/2,-dim.z/2);
3487 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3488 -dim.x/2,-dim.y/2,dim.z/2,
3489 dim.x/2,-dim.y/2,dim.z/2);
3490 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3491 -dim.x/2,-dim.y/2,dim.z/2,
3492 -dim.x/2,dim.y/2,dim.z/2);
3493 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3494 dim.x/2,dim.y/2,dim.z/2,
3495 dim.x/2,-dim.y/2,dim.z/2);
3496 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3497 -dim.x/2,dim.y/2,dim.z/2,
3498 dim.x/2,dim.y/2,dim.z/2);
3500 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3501 -dim.x/2,-dim.y/2,dim.z/2,
3502 -dim.x/2,-dim.y/2,-dim.z/2);
3503 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3504 -dim.x/2,dim.y/2,dim.z/2,
3505 -dim.x/2,dim.y/2,-dim.z/2);
3506 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3507 dim.x/2,-dim.y/2,dim.z/2,
3508 dim.x/2,-dim.y/2,-dim.z/2);
3509 dprintf(vb.fd,"# [D] %f %f %f %f %f %f\n",
3510 dim.x/2,dim.y/2,dim.z/2,
3511 dim.x/2,dim.y/2,-dim.z/2);
3516 #ifdef VISUAL_THREAD
3527 * fpu cntrol functions
3530 // set rounding to double (eliminates -ffloat-store!)
3531 int fpu_set_rtd(void) {
3537 ctrl&=~_FPU_EXTENDED;