2 * moldyn.c - molecular dynamics library main file
4 * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
12 #include <sys/types.h>
20 int moldyn_init(t_moldyn *moldyn,int argc,char **argv) {
22 printf("[moldyn] init\n");
24 memset(moldyn,0,sizeof(t_moldyn));
26 rand_init(&(moldyn->random),NULL,1);
27 moldyn->random.status|=RAND_STAT_VERBOSE;
32 int moldyn_shutdown(t_moldyn *moldyn) {
34 printf("[moldyn] shutdown\n");
36 moldyn_log_shutdown(moldyn);
37 link_cell_shutdown(moldyn);
38 rand_close(&(moldyn->random));
44 int set_int_alg(t_moldyn *moldyn,u8 algo) {
46 printf("[moldyn] integration algorithm: ");
49 case MOLDYN_INTEGRATE_VERLET:
50 moldyn->integrate=velocity_verlet;
51 printf("velocity verlet\n");
54 printf("unknown integration algorithm: %02x\n",algo);
62 int set_cutoff(t_moldyn *moldyn,double cutoff) {
64 moldyn->cutoff=cutoff;
66 printf("[moldyn] cutoff [A]: %f\n",moldyn->cutoff);
71 int set_temperature(t_moldyn *moldyn,double t_ref) {
75 printf("[moldyn] temperature: %f\n",moldyn->t_ref);
80 int set_pressure(t_moldyn *moldyn,double p_ref) {
84 printf("[moldyn] pressure: %f\n",moldyn->p_ref);
89 int set_pt_scale(t_moldyn *moldyn,u8 ptype,double ptc,u8 ttype,double ttc) {
91 moldyn->pt_scale=(ptype|ttype);
95 printf("[moldyn] p/t scaling:\n");
97 printf(" p: %s",ptype?"yes":"no ");
99 printf(" | type: %02x | factor: %f",ptype,ptc);
102 printf(" t: %s",ttype?"yes":"no ");
104 printf(" | type: %02x | factor: %f",ttype,ttc);
110 int set_dim(t_moldyn *moldyn,double x,double y,double z,u8 visualize) {
116 moldyn->volume=x*y*z;
124 printf("[moldyn] dimensions in A and A^3 respectively:\n");
125 printf(" x: %f\n",moldyn->dim.x);
126 printf(" y: %f\n",moldyn->dim.y);
127 printf(" z: %f\n",moldyn->dim.z);
128 printf(" volume: %f\n",moldyn->volume);
129 printf(" visualize simulation box: %s\n",visualize?"yes":"no");
134 int set_nn_dist(t_moldyn *moldyn,double dist) {
141 int set_pbc(t_moldyn *moldyn,u8 x,u8 y,u8 z) {
143 printf("[moldyn] periodic boundary conditions:\n");
146 moldyn->status|=MOLDYN_STAT_PBX;
149 moldyn->status|=MOLDYN_STAT_PBY;
152 moldyn->status|=MOLDYN_STAT_PBZ;
154 printf(" x: %s\n",x?"yes":"no");
155 printf(" y: %s\n",y?"yes":"no");
156 printf(" z: %s\n",z?"yes":"no");
161 int set_potential1b(t_moldyn *moldyn,pf_func1b func,void *params) {
164 moldyn->pot1b_params=params;
169 int set_potential2b(t_moldyn *moldyn,pf_func2b func,void *params) {
172 moldyn->pot2b_params=params;
177 int set_potential2b_post(t_moldyn *moldyn,pf_func2b_post func,void *params) {
179 moldyn->func2b_post=func;
180 moldyn->pot2b_params=params;
185 int set_potential3b(t_moldyn *moldyn,pf_func3b func,void *params) {
188 moldyn->pot3b_params=params;
193 int moldyn_set_log_dir(t_moldyn *moldyn,char *dir) {
195 strncpy(moldyn->vlsdir,dir,127);
200 int moldyn_set_log(t_moldyn *moldyn,u8 type,int timer) {
205 printf("[moldyn] set log: ");
208 case LOG_TOTAL_ENERGY:
209 moldyn->ewrite=timer;
210 snprintf(filename,127,"%s/energy",moldyn->vlsdir);
211 moldyn->efd=open(filename,
212 O_WRONLY|O_CREAT|O_EXCL,
215 perror("[moldyn] energy log fd open");
218 dprintf(moldyn->efd,"# total energy log file\n");
219 printf("total energy (%d)\n",timer);
221 case LOG_TOTAL_MOMENTUM:
222 moldyn->mwrite=timer;
223 snprintf(filename,127,"%s/momentum",moldyn->vlsdir);
224 moldyn->mfd=open(filename,
225 O_WRONLY|O_CREAT|O_EXCL,
228 perror("[moldyn] momentum log fd open");
231 dprintf(moldyn->efd,"# total momentum log file\n");
232 printf("total momentum (%d)\n",timer);
235 moldyn->swrite=timer;
236 printf("save file (%d)\n",timer);
239 moldyn->vwrite=timer;
240 ret=visual_init(&(moldyn->vis),moldyn->vlsdir);
242 printf("[moldyn] visual init failure\n");
245 printf("visual file (%d)\n",timer);
248 printf("unknown log type: %02x\n",type);
255 int moldyn_log_shutdown(t_moldyn *moldyn) {
257 printf("[moldyn] log shutdown\n");
258 if(moldyn->efd) close(moldyn->efd);
259 if(moldyn->mfd) close(moldyn->mfd);
260 if(&(moldyn->vis)) visual_tini(&(moldyn->vis));
266 * creating lattice functions
269 int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
270 u8 attr,u8 brand,int a,int b,int c) {
281 /* how many atoms do we expect */
282 if(type==FCC) new*=4;
283 if(type==DIAMOND) new*=8;
285 /* allocate space for atoms */
286 ptr=realloc(moldyn->atom,(count+new)*sizeof(t_atom));
288 perror("[moldyn] realloc (create lattice)");
292 atom=&(moldyn->atom[count]);
298 ret=fcc_init(a,b,c,lc,atom,&origin);
301 ret=diamond_init(a,b,c,lc,atom,&origin);
304 printf("unknown lattice type (%02x)\n",type);
310 printf("[moldyn] creating lattice failed\n");
311 printf(" amount of atoms\n");
312 printf(" - expected: %d\n",new);
313 printf(" - created: %d\n",ret);
318 printf("[moldyn] created lattice with %d atoms\n",new);
320 for(ret=0;ret<new;ret++) {
321 atom[ret].element=element;
324 atom[ret].brand=brand;
325 atom[ret].tag=count+ret;
326 check_per_bound(moldyn,&(atom[ret].r));
332 /* fcc lattice init */
333 int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
346 if(origin) v3_copy(&o,origin);
349 /* construct the basis */
352 if(i!=j) help[j]=0.5*lc;
355 v3_set(&basis[i],help);
361 /* fill up the room */
368 v3_copy(&(atom[count].r),&r);
369 atom[count].element=1;
372 v3_add(&n,&r,&basis[i]);
376 v3_copy(&(atom[count].r),&n);
387 /* coordinate transformation */
393 v3_sub(&(atom[i].r),&(atom[i].r),&n);
398 int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
403 count=fcc_init(a,b,c,lc,atom,origin);
409 if(origin) v3_add(&o,&o,origin);
411 count+=fcc_init(a,b,c,lc,&atom[count],&o);
416 int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr,
417 t_3dvec *r,t_3dvec *v) {
424 count=(moldyn->count)++;
426 ptr=realloc(atom,(count+1)*sizeof(t_atom));
428 perror("[moldyn] realloc (add atom)");
436 atom[count].element=element;
437 atom[count].mass=mass;
438 atom[count].brand=brand;
439 atom[count].tag=count;
440 atom[count].attr=attr;
445 int destroy_atoms(t_moldyn *moldyn) {
447 if(moldyn->atom) free(moldyn->atom);
452 int thermal_init(t_moldyn *moldyn,u8 equi_init) {
455 * - gaussian distribution of velocities
456 * - zero total momentum
457 * - velocity scaling (E = 3/2 N k T), E: kinetic energy
462 t_3dvec p_total,delta;
467 random=&(moldyn->random);
469 printf("[moldyn] thermal init (equi init: %s)\n",equi_init?"yes":"no");
471 /* gaussian distribution of velocities */
473 for(i=0;i<moldyn->count;i++) {
474 sigma=sqrt(2.0*K_BOLTZMANN*moldyn->t_ref/atom[i].mass);
476 v=sigma*rand_get_gauss(random);
478 p_total.x+=atom[i].mass*v;
480 v=sigma*rand_get_gauss(random);
482 p_total.y+=atom[i].mass*v;
484 v=sigma*rand_get_gauss(random);
486 p_total.z+=atom[i].mass*v;
489 /* zero total momentum */
490 v3_scale(&p_total,&p_total,1.0/moldyn->count);
491 for(i=0;i<moldyn->count;i++) {
492 v3_scale(&delta,&p_total,1.0/atom[i].mass);
493 v3_sub(&(atom[i].v),&(atom[i].v),&delta);
496 /* velocity scaling */
497 scale_velocity(moldyn,equi_init);
502 double temperature_calc(t_moldyn *moldyn) {
510 for(i=0;i<moldyn->count;i++)
511 double_ekin+=atom[i].mass*v3_absolute_square(&(atom[i].v));
513 /* kinetic energy = 3/2 N k_B T */
514 moldyn->t=double_ekin/(3.0*K_BOLTZMANN*moldyn->count);
519 double get_temperature(t_moldyn *moldyn) {
524 int scale_velocity(t_moldyn *moldyn,u8 equi_init) {
534 * - velocity scaling (E = 3/2 N k T), E: kinetic energy
537 /* get kinetic energy / temperature & count involved atoms */
540 for(i=0;i<moldyn->count;i++) {
541 if((equi_init&TRUE)||(atom[i].attr&ATOM_ATTR_HB)) {
542 e+=atom[i].mass*v3_absolute_square(&(atom[i].v));
547 if(count!=0) moldyn->t=e/(1.5*count*K_BOLTZMANN);
548 else return 0; /* no atoms involved in scaling! */
550 /* (temporary) hack for e,t = 0 */
553 if(moldyn->t_ref!=0.0) {
554 thermal_init(moldyn,equi_init);
558 return 0; /* no scaling needed */
562 /* get scaling factor */
563 scale=moldyn->t_ref/moldyn->t;
567 if(moldyn->pt_scale&T_SCALE_BERENDSEN)
568 scale=1.0+(scale-1.0)/moldyn->t_tc;
571 /* velocity scaling */
572 for(i=0;i<moldyn->count;i++) {
573 if((equi_init&TRUE)||(atom[i].attr&ATOM_ATTR_HB))
574 v3_scale(&(atom[i].v),&(atom[i].v),scale);
580 double pressure_calc(t_moldyn *moldyn) {
586 for(i=0;i<moldyn->count;i++) {
591 p1=(moldyn->count*K_BOLTZMANN*moldyn->t-ONE_THIRD*moldyn->vt1);
594 p2=(moldyn->count*K_BOLTZMANN*moldyn->t-ONE_THIRD*moldyn->vt2);
597 printf("compare pressures: %f %f\n",p1/ATM,p2/ATM);
602 double get_pressure(t_moldyn *moldyn) {
608 int scale_volume(t_moldyn *moldyn) {
619 vdim=&(moldyn->vis.dim);
622 memset(&virial,0,sizeof(t_virial));
624 for(i=0;i<moldyn->count;i++) {
625 virial.xx+=atom[i].virial.xx;
626 virial.yy+=atom[i].virial.yy;
627 virial.zz+=atom[i].virial.zz;
628 virial.xy+=atom[i].virial.xy;
629 virial.xz+=atom[i].virial.xz;
630 virial.yz+=atom[i].virial.yz;
633 /* just a guess so far ... */
634 v=virial.xx+virial.yy+virial.zz;
637 /* get pressure from virial */
638 moldyn->p=moldyn->count*K_BOLTZMANN*moldyn->t+ONE_THIRD*v;
639 moldyn->p/=moldyn->volume;
640 printf("%f | %f\n",moldyn->p/(ATM),moldyn->p_ref/ATM);
643 if(moldyn->pt_scale&P_SCALE_BERENDSEN)
644 scale=3*sqrt(1-(moldyn->p_ref-moldyn->p)/moldyn->p_tc);
646 /* should actually never be used */
647 scale=pow(moldyn->p/moldyn->p_ref,1.0/3.0);
649 printf("scale = %f\n",scale);
654 if(vdim->x) vdim->x=dim->x;
655 if(vdim->y) vdim->y=dim->y;
656 if(vdim->z) vdim->z=dim->z;
657 moldyn->volume*=(scale*scale*scale);
659 /* check whether we need a new linkcell init */
660 if((dim->x/moldyn->cutoff!=lc->nx)||
661 (dim->y/moldyn->cutoff!=lc->ny)||
662 (dim->z/moldyn->cutoff!=lc->nx)) {
663 link_cell_shutdown(moldyn);
664 link_cell_init(moldyn);
671 double get_e_kin(t_moldyn *moldyn) {
679 for(i=0;i<moldyn->count;i++)
680 moldyn->ekin+=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v));
685 double update_e_kin(t_moldyn *moldyn) {
687 return(get_e_kin(moldyn));
690 double get_total_energy(t_moldyn *moldyn) {
692 return(moldyn->ekin+moldyn->energy);
695 t_3dvec get_total_p(t_moldyn *moldyn) {
704 for(i=0;i<moldyn->count;i++) {
705 v3_scale(&p,&(atom[i].v),atom[i].mass);
706 v3_add(&p_total,&p_total,&p);
712 double estimate_time_step(t_moldyn *moldyn,double nn_dist) {
716 /* nn_dist is the nearest neighbour distance */
718 tau=(0.05*nn_dist*moldyn->atom[0].mass)/sqrt(3.0*K_BOLTZMANN*moldyn->t);
727 /* linked list / cell method */
729 int link_cell_init(t_moldyn *moldyn) {
736 /* partitioning the md cell */
737 lc->nx=moldyn->dim.x/moldyn->cutoff;
738 lc->x=moldyn->dim.x/lc->nx;
739 lc->ny=moldyn->dim.y/moldyn->cutoff;
740 lc->y=moldyn->dim.y/lc->ny;
741 lc->nz=moldyn->dim.z/moldyn->cutoff;
742 lc->z=moldyn->dim.z/lc->nz;
744 lc->cells=lc->nx*lc->ny*lc->nz;
745 lc->subcell=malloc(lc->cells*sizeof(t_list));
748 printf("[moldyn] FATAL: less then 27 subcells!\n");
750 printf("[moldyn] initializing linked cells (%d)\n",lc->cells);
752 for(i=0;i<lc->cells;i++)
753 list_init_f(&(lc->subcell[i]));
755 link_cell_update(moldyn);
760 int link_cell_update(t_moldyn *moldyn) {
778 for(i=0;i<lc->cells;i++)
779 list_destroy_f(&(lc->subcell[i]));
781 for(count=0;count<moldyn->count;count++) {
782 i=((atom[count].r.x+(moldyn->dim.x/2))/lc->x);
783 j=((atom[count].r.y+(moldyn->dim.y/2))/lc->y);
784 k=((atom[count].r.z+(moldyn->dim.z/2))/lc->z);
785 list_add_immediate_f(&(moldyn->lc.subcell[i+j*nx+k*nx*ny]),
792 int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell) {
810 cell[0]=lc->subcell[i+j*nx+k*a];
811 for(ci=-1;ci<=1;ci++) {
818 for(cj=-1;cj<=1;cj++) {
825 for(ck=-1;ck<=1;ck++) {
832 if(!(ci|cj|ck)) continue;
834 cell[--count2]=lc->subcell[x+y*nx+z*a];
837 cell[count1++]=lc->subcell[x+y*nx+z*a];
848 int link_cell_shutdown(t_moldyn *moldyn) {
855 for(i=0;i<lc->nx*lc->ny*lc->nz;i++)
856 list_destroy_f(&(moldyn->lc.subcell[i]));
863 int moldyn_add_schedule(t_moldyn *moldyn,int runs,double tau) {
867 t_moldyn_schedule *schedule;
869 schedule=&(moldyn->schedule);
870 count=++(schedule->total_sched);
872 ptr=realloc(schedule->runs,count*sizeof(int));
874 perror("[moldyn] realloc (runs)");
878 schedule->runs[count-1]=runs;
880 ptr=realloc(schedule->tau,count*sizeof(double));
882 perror("[moldyn] realloc (tau)");
886 schedule->tau[count-1]=tau;
888 printf("[moldyn] schedule added:\n");
889 printf(" number: %d | runs: %d | tau: %f\n",count-1,runs,tau);
895 int moldyn_set_schedule_hook(t_moldyn *moldyn,set_hook hook,void *hook_params) {
897 moldyn->schedule.hook=hook;
898 moldyn->schedule.hook_params=hook_params;
905 * 'integration of newtons equation' - algorithms
909 /* start the integration */
911 int moldyn_integrate(t_moldyn *moldyn) {
914 unsigned int e,m,s,v;
916 t_moldyn_schedule *sched;
922 sched=&(moldyn->schedule);
925 /* initialize linked cell method */
926 link_cell_init(moldyn);
928 /* logging & visualization */
934 /* sqaure of some variables */
935 moldyn->tau_square=moldyn->tau*moldyn->tau;
936 moldyn->cutoff_square=moldyn->cutoff*moldyn->cutoff;
938 /* calculate initial forces */
939 potential_force_calc(moldyn);
941 /* some stupid checks before we actually start calculating bullshit */
942 if(moldyn->cutoff>0.5*moldyn->dim.x)
943 printf("[moldyn] warning: cutoff > 0.5 x dim.x\n");
944 if(moldyn->cutoff>0.5*moldyn->dim.y)
945 printf("[moldyn] warning: cutoff > 0.5 x dim.y\n");
946 if(moldyn->cutoff>0.5*moldyn->dim.z)
947 printf("[moldyn] warning: cutoff > 0.5 x dim.z\n");
948 ds=0.5*atom[0].f.x*moldyn->tau_square/atom[0].mass;
949 if(ds>0.05*moldyn->nnd)
950 printf("[moldyn] warning: forces too high / tau too small!\n");
952 /* zero absolute time */
955 /* debugging, ignore */
959 printf("[moldyn] integration start, go get a coffee ...\n");
961 /* executing the schedule */
962 for(sched->count=0;sched->count<sched->total_sched;sched->count++) {
964 /* setting amount of runs and finite time step size */
965 moldyn->tau=sched->tau[sched->count];
966 moldyn->tau_square=moldyn->tau*moldyn->tau;
967 moldyn->time_steps=sched->runs[sched->count];
969 /* integration according to schedule */
971 for(i=0;i<moldyn->time_steps;i++) {
973 /* integration step */
974 moldyn->integrate(moldyn);
977 if(moldyn->pt_scale&(T_SCALE_BERENDSEN|T_SCALE_DIRECT))
978 scale_velocity(moldyn,FALSE);
979 if(moldyn->pt_scale&(P_SCALE_BERENDSEN|P_SCALE_DIRECT))
980 scale_volume(moldyn);
982 /* check for log & visualization */
989 //ax=((0.28-0.25)*sqrt(3)*LC_SI/2)*cos(ao*i);
990 //av=ao*(0.28-0.25)*sqrt(3)*LC_SI/2*sin(ao*i);
991 update_e_kin(moldyn);
994 moldyn->time,moldyn->ekin,
996 get_total_energy(moldyn));
997 //moldyn->atom[0].r.x,ax,av*av*M_SI,0.1*ax*ax,av*av*M_SI+0.1*ax*ax);
1001 p=get_total_p(moldyn);
1002 dprintf(moldyn->mfd,
1003 "%f %f\n",moldyn->time,v3_norm(&p));
1008 snprintf(dir,128,"%s/s-%07.f.save",
1009 moldyn->vlsdir,moldyn->time);
1010 fd=open(dir,O_WRONLY|O_TRUNC|O_CREAT);
1011 if(fd<0) perror("[moldyn] save fd open");
1013 write(fd,moldyn,sizeof(t_moldyn));
1014 write(fd,moldyn->atom,
1015 moldyn->count*sizeof(t_atom));
1022 visual_atoms(&(moldyn->vis),moldyn->time,
1023 moldyn->atom,moldyn->count);
1024 printf("\rsched: %d, steps: %d, debug: %d",
1025 sched->count,i,moldyn->debug);
1030 /* increase absolute time */
1031 moldyn->time+=moldyn->tau;
1035 /* check for hooks */
1037 sched->hook(moldyn,sched->hook_params);
1039 /* get a new info line */
1047 /* velocity verlet */
1049 int velocity_verlet(t_moldyn *moldyn) {
1052 double tau,tau_square,h;
1057 count=moldyn->count;
1059 tau_square=moldyn->tau_square;
1061 for(i=0;i<count;i++) {
1064 v3_scale(&delta,&(atom[i].v),tau);
1065 v3_add(&(atom[i].r),&(atom[i].r),&delta);
1066 v3_scale(&delta,&(atom[i].f),h*tau_square);
1067 v3_add(&(atom[i].r),&(atom[i].r),&delta);
1068 check_per_bound(moldyn,&(atom[i].r));
1070 /* velocities [actually v(t+tau/2)] */
1071 v3_scale(&delta,&(atom[i].f),h*tau);
1072 v3_add(&(atom[i].v),&(atom[i].v),&delta);
1075 /* neighbour list update */
1076 link_cell_update(moldyn);
1078 /* forces depending on chosen potential */
1079 potential_force_calc(moldyn);
1081 for(i=0;i<count;i++) {
1082 /* again velocities [actually v(t+tau)] */
1083 v3_scale(&delta,&(atom[i].f),0.5*tau/atom[i].mass);
1084 v3_add(&(atom[i].v),&(atom[i].v),&delta);
1093 * potentials & corresponding forces & virial routine
1097 /* generic potential and force calculation */
1099 int potential_force_calc(t_moldyn *moldyn) {
1102 t_atom *itom,*jtom,*ktom;
1105 t_list neighbour_i[27];
1106 t_list neighbour_i2[27];
1111 count=moldyn->count;
1120 /* get energy and force of every atom */
1121 for(i=0;i<count;i++) {
1124 v3_zero(&(itom[i].f));
1126 /* reset viral of atom i */
1127 virial=&(itom[i].virial);
1136 /* reset site energy */
1139 /* single particle potential/force */
1140 if(itom[i].attr&ATOM_ATTR_1BP)
1141 moldyn->func1b(moldyn,&(itom[i]));
1143 if(!(itom[i].attr&(ATOM_ATTR_2BP|ATOM_ATTR_3BP)))
1146 /* 2 body pair potential/force */
1148 link_cell_neighbour_index(moldyn,
1149 (itom[i].r.x+moldyn->dim.x/2)/lc->x,
1150 (itom[i].r.y+moldyn->dim.y/2)/lc->y,
1151 (itom[i].r.z+moldyn->dim.z/2)/lc->z,
1158 this=&(neighbour_i[j]);
1161 if(this->start==NULL)
1167 jtom=this->current->data;
1169 if(jtom==&(itom[i]))
1172 if((jtom->attr&ATOM_ATTR_2BP)&
1173 (itom[i].attr&ATOM_ATTR_2BP)) {
1174 moldyn->func2b(moldyn,
1180 /* 3 body potential/force */
1182 if(!(itom[i].attr&ATOM_ATTR_3BP)||
1183 !(jtom->attr&ATOM_ATTR_3BP))
1186 /* copy the neighbour lists */
1187 memcpy(neighbour_i2,neighbour_i,
1190 /* get neighbours of i */
1193 that=&(neighbour_i2[k]);
1196 if(that->start==NULL)
1203 ktom=that->current->data;
1205 if(!(ktom->attr&ATOM_ATTR_3BP))
1211 if(ktom==&(itom[i]))
1214 moldyn->func3b(moldyn,
1220 } while(list_next_f(that)!=\
1225 /* 2bp post function */
1226 if(moldyn->func2b_post) {
1227 moldyn->func2b_post(moldyn,
1232 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
1245 for(i=0;i<count;i++)
1246 moldyn->vt2-=v3_scalar_product(&(itom[i].r),&(itom[i].f));
1248 //printf("compare: vt1: %f vt2: %f\n",moldyn->vt1,moldyn->vt2);
1250 //pressure_calc(moldyn);
1256 * virial calculation
1259 inline int virial_calc(t_atom *a,t_3dvec *f,t_3dvec *d) {
1261 a->virial.xx-=f->x*d->x;
1262 a->virial.yy-=f->y*d->y;
1263 a->virial.zz-=f->z*d->z;
1264 a->virial.xy-=f->x*d->y;
1265 a->virial.xz-=f->x*d->z;
1266 a->virial.yz-=f->y*d->z;
1272 * periodic boundayr checking
1275 inline int check_per_bound(t_moldyn *moldyn,t_3dvec *a) {
1286 if(moldyn->status&MOLDYN_STAT_PBX) {
1287 if(a->x>=x) a->x-=dim->x;
1288 else if(-a->x>x) a->x+=dim->x;
1290 if(moldyn->status&MOLDYN_STAT_PBY) {
1291 if(a->y>=y) a->y-=dim->y;
1292 else if(-a->y>y) a->y+=dim->y;
1294 if(moldyn->status&MOLDYN_STAT_PBZ) {
1295 if(a->z>=z) a->z-=dim->z;
1296 else if(-a->z>z) a->z+=dim->z;
1304 * example potentials
1307 /* harmonic oscillator potential and force */
1309 int harmonic_oscillator(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
1311 t_ho_params *params;
1312 t_3dvec force,distance;
1314 double sc,equi_dist;
1316 params=moldyn->pot2b_params;
1317 sc=params->spring_constant;
1318 equi_dist=params->equilibrium_distance;
1322 v3_sub(&distance,&(aj->r),&(ai->r));
1324 if(bc) check_per_bound(moldyn,&distance);
1325 d=v3_norm(&distance);
1326 if(d<=moldyn->cutoff) {
1327 moldyn->energy+=(0.5*sc*(d-equi_dist)*(d-equi_dist));
1328 /* f = -grad E; grad r_ij = -1 1/r_ij distance */
1329 f=sc*(1.0-equi_dist/d);
1330 v3_scale(&force,&distance,f);
1331 v3_add(&(ai->f),&(ai->f),&force);
1332 virial_calc(ai,&force,&distance);
1333 virial_calc(aj,&force,&distance); /* f and d signe switched */
1334 v3_scale(&force,&distance,-f);
1335 v3_add(&(aj->f),&(aj->f),&force);
1341 /* lennard jones potential & force for one sort of atoms */
1343 int lennard_jones(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
1345 t_lj_params *params;
1346 t_3dvec force,distance;
1348 double eps,sig6,sig12;
1350 params=moldyn->pot2b_params;
1351 eps=params->epsilon4;
1352 sig6=params->sigma6;
1353 sig12=params->sigma12;
1357 v3_sub(&distance,&(aj->r),&(ai->r));
1358 if(bc) check_per_bound(moldyn,&distance);
1359 d=v3_absolute_square(&distance); /* 1/r^2 */
1360 if(d<=moldyn->cutoff_square) {
1361 d=1.0/d; /* 1/r^2 */
1364 h1=h2*h2; /* 1/r^12 */
1365 moldyn->energy+=(eps*(sig12*h1-sig6*h2)-params->uc);
1372 v3_scale(&force,&distance,d);
1373 v3_add(&(aj->f),&(aj->f),&force);
1374 v3_scale(&force,&distance,-1.0*d); /* f = - grad E */
1375 v3_add(&(ai->f),&(ai->f),&force);
1376 virial_calc(ai,&force,&distance);
1377 virial_calc(aj,&force,&distance); /* f and d signe switched */
1378 moldyn->vt1-=v3_scalar_product(&force,&distance);
1385 * tersoff potential & force for 2 sorts of atoms
1388 /* create mixed terms from parameters and set them */
1389 int tersoff_mult_complete_params(t_tersoff_mult_params *p) {
1391 printf("[moldyn] tersoff parameter completion\n");
1392 p->S2[0]=p->S[0]*p->S[0];
1393 p->S2[1]=p->S[1]*p->S[1];
1394 p->Smixed=sqrt(p->S[0]*p->S[1]);
1395 p->S2mixed=p->Smixed*p->Smixed;
1396 p->Rmixed=sqrt(p->R[0]*p->R[1]);
1397 p->Amixed=sqrt(p->A[0]*p->A[1]);
1398 p->Bmixed=sqrt(p->B[0]*p->B[1]);
1399 p->lambda_m=0.5*(p->lambda[0]+p->lambda[1]);
1400 p->mu_m=0.5*(p->mu[0]+p->mu[1]);
1402 printf("[moldyn] tersoff mult parameter info:\n");
1403 printf(" S (A) | %f | %f | %f\n",p->S[0],p->S[1],p->Smixed);
1404 printf(" R (A) | %f | %f | %f\n",p->R[0],p->R[1],p->Rmixed);
1405 printf(" A (eV) | %f | %f | %f\n",p->A[0]/EV,p->A[1]/EV,p->Amixed/EV);
1406 printf(" B (eV) | %f | %f | %f\n",p->B[0]/EV,p->B[1]/EV,p->Bmixed/EV);
1407 printf(" lambda | %f | %f | %f\n",p->lambda[0],p->lambda[1],
1409 printf(" mu | %f | %f | %f\n",p->mu[0],p->mu[1],p->mu_m);
1410 printf(" beta | %.10f | %.10f\n",p->beta[0],p->beta[1]);
1411 printf(" n | %f | %f\n",p->n[0],p->n[1]);
1412 printf(" c | %f | %f\n",p->c[0],p->c[1]);
1413 printf(" d | %f | %f\n",p->d[0],p->d[1]);
1414 printf(" h | %f | %f\n",p->h[0],p->h[1]);
1415 printf(" chi | %f \n",p->chi);
1420 /* tersoff 1 body part */
1421 int tersoff_mult_1bp(t_moldyn *moldyn,t_atom *ai) {
1424 t_tersoff_mult_params *params;
1425 t_tersoff_exchange *exchange;
1428 params=moldyn->pot1b_params;
1429 exchange=&(params->exchange);
1432 * simple: point constant parameters only depending on atom i to
1433 * their right values
1436 exchange->beta_i=&(params->beta[brand]);
1437 exchange->n_i=&(params->n[brand]);
1438 exchange->c_i=&(params->c[brand]);
1439 exchange->d_i=&(params->d[brand]);
1440 exchange->h_i=&(params->h[brand]);
1442 exchange->betaini=pow(*(exchange->beta_i),*(exchange->n_i));
1443 exchange->ci2=params->c[brand]*params->c[brand];
1444 exchange->di2=params->d[brand]*params->d[brand];
1445 exchange->ci2di2=exchange->ci2/exchange->di2;
1450 /* tersoff 2 body part */
1451 int tersoff_mult_2bp(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
1453 t_tersoff_mult_params *params;
1454 t_tersoff_exchange *exchange;
1455 t_3dvec dist_ij,force;
1457 double A,B,R,S,S2,lambda,mu;
1464 params=moldyn->pot2b_params;
1466 exchange=&(params->exchange);
1468 /* clear 3bp and 2bp post run */
1470 exchange->run2bp_post=0;
1472 /* reset S > r > R mark */
1473 exchange->d_ij_between_rs=0;
1476 * calc of 2bp contribution of V_ij and dV_ij/ji
1478 * for Vij and dV_ij we need:
1482 * for dV_ji we need:
1483 * - f_c_ji = f_c_ij, df_c_ji = df_c_ij
1484 * - f_r_ji = f_r_ij; df_r_ji = df_r_ij
1489 if(brand==ai->brand) {
1491 S2=params->S2[brand];
1495 lambda=params->lambda[brand];
1496 mu=params->mu[brand];
1505 lambda=params->lambda_m;
1507 params->exchange.chi=params->chi;
1511 v3_sub(&dist_ij,&(aj->r),&(ai->r));
1512 if(bc) check_per_bound(moldyn,&dist_ij);
1513 d_ij2=v3_absolute_square(&dist_ij);
1515 /* if d_ij2 > S2 => no force & potential energy contribution */
1519 /* now we will need the distance */
1520 //d_ij=v3_norm(&dist_ij);
1523 /* save for use in 3bp */
1524 exchange->d_ij=d_ij;
1525 exchange->d_ij2=d_ij2;
1526 exchange->dist_ij=dist_ij;
1528 /* more constants */
1529 exchange->beta_j=&(params->beta[brand]);
1530 exchange->n_j=&(params->n[brand]);
1531 exchange->c_j=&(params->c[brand]);
1532 exchange->d_j=&(params->d[brand]);
1533 exchange->h_j=&(params->h[brand]);
1534 if(brand==ai->brand) {
1535 exchange->betajnj=exchange->betaini;
1536 exchange->cj2=exchange->ci2;
1537 exchange->dj2=exchange->di2;
1538 exchange->cj2dj2=exchange->ci2di2;
1541 exchange->betajnj=pow(*(exchange->beta_j),*(exchange->n_j));
1542 exchange->cj2=params->c[brand]*params->c[brand];
1543 exchange->dj2=params->d[brand]*params->d[brand];
1544 exchange->cj2dj2=exchange->cj2/exchange->dj2;
1547 /* f_r_ij = f_r_ji, df_r_ij = df_r_ji */
1548 f_r=A*exp(-lambda*d_ij);
1549 df_r=lambda*f_r/d_ij;
1551 /* f_a, df_a calc (again, same for ij and ji) | save for later use! */
1552 exchange->f_a=-B*exp(-mu*d_ij);
1553 exchange->df_a=mu*exchange->f_a/d_ij;
1555 /* f_c, df_c calc (again, same for ij and ji) */
1557 /* f_c = 1, df_c = 0 */
1560 /* two body contribution (ij, ji) */
1561 v3_scale(&force,&dist_ij,-df_r);
1565 arg=M_PI*(d_ij-R)/s_r;
1566 f_c=0.5+0.5*cos(arg);
1567 df_c=0.5*sin(arg)*(M_PI/(s_r*d_ij));
1568 /* two body contribution (ij, ji) */
1569 v3_scale(&force,&dist_ij,-df_c*f_r-df_r*f_c);
1570 /* tell 3bp that S > r > R */
1571 exchange->d_ij_between_rs=1;
1574 /* add forces of 2bp (ij, ji) contribution
1575 * dVij = dVji and we sum up both: no 1/2) */
1576 v3_add(&(ai->f),&(ai->f),&force);
1579 ai->virial.xx-=force.x*dist_ij.x;
1580 ai->virial.yy-=force.y*dist_ij.y;
1581 ai->virial.zz-=force.z*dist_ij.z;
1582 ai->virial.xy-=force.x*dist_ij.y;
1583 ai->virial.xz-=force.x*dist_ij.z;
1584 ai->virial.yz-=force.y*dist_ij.z;
1587 if(ai==&(moldyn->atom[0])) {
1588 printf("dVij, dVji (2bp) contrib:\n");
1589 printf("%f | %f\n",force.x,ai->f.x);
1590 printf("%f | %f\n",force.y,ai->f.y);
1591 printf("%f | %f\n",force.z,ai->f.z);
1595 if(ai==&(moldyn->atom[0])) {
1596 printf("dVij, dVji (2bp) contrib:\n");
1597 printf("%f | %f\n",force.x*dist_ij.x,ai->virial.xx);
1598 printf("%f | %f\n",force.y*dist_ij.y,ai->virial.yy);
1599 printf("%f | %f\n",force.z*dist_ij.z,ai->virial.zz);
1603 /* energy 2bp contribution (ij, ji) is 0.5 f_r f_c ... */
1604 moldyn->energy+=(0.5*f_r*f_c);
1606 /* save for use in 3bp */
1608 exchange->df_c=df_c;
1610 /* enable the run of 3bp function and 2bp post processing */
1612 exchange->run2bp_post=1;
1614 /* reset 3bp sums */
1615 exchange->zeta_ij=0.0;
1616 exchange->zeta_ji=0.0;
1617 v3_zero(&(exchange->dzeta_ij));
1618 v3_zero(&(exchange->dzeta_ji));
1623 /* tersoff 2 body post part */
1625 int tersoff_mult_post_2bp(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
1628 * here we have to allow for the 3bp sums
1631 * - zeta_ij, dzeta_ij
1632 * - zeta_ji, dzeta_ji
1634 * to compute the 3bp contribution to:
1640 t_tersoff_mult_params *params;
1641 t_tersoff_exchange *exchange;
1646 double f_c,df_c,f_a,df_a;
1647 double chi,ni,betaini,nj,betajnj;
1650 params=moldyn->pot2b_params;
1651 exchange=&(params->exchange);
1653 /* we do not run if f_c_ij was detected to be 0! */
1654 if(!(exchange->run2bp_post))
1658 df_c=exchange->df_c;
1660 df_a=exchange->df_a;
1661 betaini=exchange->betaini;
1662 betajnj=exchange->betajnj;
1663 ni=*(exchange->n_i);
1664 nj=*(exchange->n_j);
1666 dist_ij=&(exchange->dist_ij);
1669 zeta=exchange->zeta_ij;
1671 moldyn->debug++; /* just for debugging ... */
1673 v3_scale(&force,dist_ij,df_a*b*f_c);
1676 tmp=betaini*pow(zeta,ni-1.0); /* beta^n * zeta^n-1 */
1677 b=(1+zeta*tmp); /* 1 + beta^n zeta^n */
1678 db=chi*pow(b,-1.0/(2*ni)-1); /* x(...)^(-1/2n - 1) */
1680 db*=-0.5*tmp; /* db_ij */
1681 v3_scale(&force,&(exchange->dzeta_ij),f_a*db);
1682 v3_scale(&temp,dist_ij,df_a*b);
1683 v3_add(&force,&force,&temp);
1684 v3_scale(&force,&force,f_c);
1686 v3_scale(&temp,dist_ij,df_c*b*f_a);
1687 v3_add(&force,&force,&temp);
1688 v3_scale(&force,&force,-0.5);
1691 v3_add(&(ai->f),&(ai->f),&force);
1694 ai->virial.xx-=force.x*dist_ij->x;
1695 ai->virial.yy-=force.y*dist_ij->y;
1696 ai->virial.zz-=force.z*dist_ij->z;
1697 ai->virial.xy-=force.x*dist_ij->y;
1698 ai->virial.xz-=force.x*dist_ij->z;
1699 ai->virial.yz-=force.y*dist_ij->z;
1702 if(ai==&(moldyn->atom[0])) {
1703 printf("dVij (3bp) contrib:\n");
1704 printf("%f | %f\n",force.x,ai->f.x);
1705 printf("%f | %f\n",force.y,ai->f.y);
1706 printf("%f | %f\n",force.z,ai->f.z);
1710 if(ai==&(moldyn->atom[0])) {
1711 printf("dVij (3bp) contrib:\n");
1712 printf("%f | %f\n",force.x*dist_ij->x,ai->virial.xx);
1713 printf("%f | %f\n",force.y*dist_ij->y,ai->virial.yy);
1714 printf("%f | %f\n",force.z*dist_ij->z,ai->virial.zz);
1718 /* add energy of 3bp sum */
1719 moldyn->energy+=(0.5*f_c*b*f_a);
1722 zeta=exchange->zeta_ji;
1726 v3_scale(&force,dist_ij,df_a*b*f_c);
1729 tmp=betajnj*pow(zeta,nj-1.0); /* beta^n * zeta^n-1 */
1730 b=(1+zeta*tmp); /* 1 + beta^n zeta^n */
1731 db=chi*pow(b,-1.0/(2*nj)-1); /* x(...)^(-1/2n - 1) */
1733 db*=-0.5*tmp; /* db_ij */
1734 v3_scale(&force,&(exchange->dzeta_ji),f_a*db);
1735 v3_scale(&temp,dist_ij,df_a*b);
1736 v3_add(&force,&force,&temp);
1737 v3_scale(&force,&force,f_c);
1739 v3_scale(&temp,dist_ij,df_c*b*f_a);
1740 v3_add(&force,&force,&temp);
1741 v3_scale(&force,&force,-0.5);
1744 v3_add(&(ai->f),&(ai->f),&force);
1746 /* virial - plus sign, as dist_ij = - dist_ji - (really??) */
1747 // TEST ... with a minus instead
1748 ai->virial.xx-=force.x*dist_ij->x;
1749 ai->virial.yy-=force.y*dist_ij->y;
1750 ai->virial.zz-=force.z*dist_ij->z;
1751 ai->virial.xy-=force.x*dist_ij->y;
1752 ai->virial.xz-=force.x*dist_ij->z;
1753 ai->virial.yz-=force.y*dist_ij->z;
1756 if(ai==&(moldyn->atom[0])) {
1757 printf("dVji (3bp) contrib:\n");
1758 printf("%f | %f\n",force.x,ai->f.x);
1759 printf("%f | %f\n",force.y,ai->f.y);
1760 printf("%f | %f\n",force.z,ai->f.z);
1764 if(ai==&(moldyn->atom[0])) {
1765 printf("dVji (3bp) contrib:\n");
1766 printf("%f | %f\n",force.x*dist_ij->x,ai->virial.xx);
1767 printf("%f | %f\n",force.y*dist_ij->y,ai->virial.yy);
1768 printf("%f | %f\n",force.z*dist_ij->z,ai->virial.zz);
1775 /* tersoff 3 body part */
1777 int tersoff_mult_3bp(t_moldyn *moldyn,t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
1779 t_tersoff_mult_params *params;
1780 t_tersoff_exchange *exchange;
1781 t_3dvec dist_ij,dist_ik,dist_jk;
1782 t_3dvec temp1,temp2;
1786 double d_ij,d_ik,d_jk,d_ij2,d_ik2,d_jk2;
1789 double f_c_ik,df_c_ik,arg;
1793 double cos_theta,d_costheta1,d_costheta2;
1794 double h_cos,d2_h_cos2;
1795 double frac,g,zeta,chi;
1799 params=moldyn->pot3b_params;
1800 exchange=&(params->exchange);
1802 if(!(exchange->run3bp))
1806 * calc of 3bp contribution of V_ij and dV_ij/ji/jk &
1807 * 2bp contribution of dV_jk
1809 * for Vij and dV_ij we still need:
1810 * - b_ij, db_ij (zeta_ij)
1811 * - f_c_ik, df_c_ik, constants_i, cos_theta_ijk, d_costheta_ijk
1813 * for dV_ji we still need:
1814 * - b_ji, db_ji (zeta_ji)
1815 * - f_c_jk, d_c_jk, constants_j, cos_theta_jik, d_costheta_jik
1817 * for dV_jk we need:
1821 * - f_c_ji, df_c_ji, constants_j, cos_theta_jki, d_costheta_jki
1829 /* dist_ij, d_ij - this is < S_ij ! */
1830 dist_ij=exchange->dist_ij;
1831 d_ij=exchange->d_ij;
1832 d_ij2=exchange->d_ij2;
1834 /* f_c_ij, df_c_ij (same for ji) */
1836 df_c=exchange->df_c;
1839 * calculate unknown values now ...
1842 /* V_ij and dV_ij stuff (in b_ij there is f_c_ik) */
1845 v3_sub(&dist_ik,&(ak->r),&(ai->r));
1846 if(bc) check_per_bound(moldyn,&dist_ik);
1847 d_ik2=v3_absolute_square(&dist_ik);
1851 if(brand==ak->brand) {
1854 S2=params->S2[brand];
1862 /* zeta_ij/dzeta_ij contribution only for d_ik < S */
1865 /* now we need d_ik */
1868 /* get constants_i from exchange data */
1875 c2d2=exchange->ci2di2;
1877 /* cosine of theta_ijk by scalaproduct */
1878 rr=v3_scalar_product(&dist_ij,&dist_ik);
1884 d_costheta1=cos_theta/d_ij2-tmp;
1885 d_costheta2=cos_theta/d_ik2-tmp;
1887 /* some usefull values */
1888 h_cos=(h-cos_theta);
1889 d2_h_cos2=d2+(h_cos*h_cos);
1890 frac=c2/(d2_h_cos2);
1895 /* d_costheta_ij and dg(cos_theta) - needed in any case! */
1896 v3_scale(&temp1,&dist_ij,d_costheta1);
1897 v3_scale(&temp2,&dist_ik,d_costheta2);
1898 v3_add(&temp1,&temp1,&temp2);
1899 v3_scale(&temp1,&temp1,-2.0*frac*h_cos/d2_h_cos2); /* dg */
1901 /* f_c_ik & df_c_ik + {d,}zeta contribution */
1902 dzeta=&(exchange->dzeta_ij);
1906 // => df_c_ik=0.0; of course we do not set this!
1909 exchange->zeta_ij+=g;
1912 v3_add(dzeta,dzeta,&temp1);
1917 arg=M_PI*(d_ik-R)/s_r;
1918 f_c_ik=0.5+0.5*cos(arg);
1919 df_c_ik=0.5*sin(arg)*(M_PI/(s_r*d_ik));
1922 exchange->zeta_ij+=f_c_ik*g;
1925 v3_scale(&temp1,&temp1,f_c_ik);
1926 v3_scale(&temp2,&dist_ik,g*df_c_ik);
1927 v3_add(&temp1,&temp1,&temp2);
1928 v3_add(dzeta,dzeta,&temp1);
1932 /* dV_ji stuff (in b_ji there is f_c_jk) + dV_jk stuff! */
1935 v3_sub(&dist_jk,&(ak->r),&(aj->r));
1936 if(bc) check_per_bound(moldyn,&dist_jk);
1937 d_jk2=v3_absolute_square(&dist_jk);
1941 if(brand==ak->brand) {
1944 S2=params->S2[brand];
1946 mu=params->mu[brand];
1958 /* zeta_ji/dzeta_ji contribution only for d_jk < S_jk */
1961 /* now we need d_ik */
1964 /* constants_j from exchange data */
1971 c2d2=exchange->cj2dj2;
1973 /* cosine of theta_jik by scalaproduct */
1974 rr=-v3_scalar_product(&dist_ij,&dist_jk); /* -1, as ij -> ji */
1980 d_costheta2=cos_theta/d_ij2;
1982 /* some usefull values */
1983 h_cos=(h-cos_theta);
1984 d2_h_cos2=d2+(h_cos*h_cos);
1985 frac=c2/(d2_h_cos2);
1990 /* d_costheta_jik and dg(cos_theta) - needed in any case! */
1991 v3_scale(&temp1,&dist_jk,d_costheta1);
1992 v3_scale(&temp2,&dist_ij,-d_costheta2); /* ji -> ij => -1 */
1993 //v3_add(&temp1,&temp1,&temp2);
1994 v3_sub(&temp1,&temp1,&temp2); /* there is a minus! */
1995 v3_scale(&temp1,&temp1,-2.0*frac*h_cos/d2_h_cos2); /* dg */
1997 /* store dg in temp2 and use it for dVjk later */
1998 v3_copy(&temp2,&temp1);
2000 /* f_c_jk + {d,}zeta contribution (df_c_jk = 0) */
2001 dzeta=&(exchange->dzeta_ji);
2007 exchange->zeta_ji+=g;
2010 v3_add(dzeta,dzeta,&temp1);
2015 arg=M_PI*(d_jk-R)/s_r;
2016 f_c_jk=0.5+0.5*cos(arg);
2019 exchange->zeta_ji+=f_c_jk*g;
2022 v3_scale(&temp1,&temp1,f_c_jk);
2023 v3_add(dzeta,dzeta,&temp1);
2026 /* dV_jk stuff | add force contribution on atom i immediately */
2027 if(exchange->d_ij_between_rs) {
2029 v3_scale(&temp1,&temp2,f_c);
2030 v3_scale(&temp2,&dist_ij,df_c*g);
2031 v3_add(&temp2,&temp2,&temp1); /* -> dzeta_jk in temp2 */
2035 // dzeta_jk is simply dg, which is stored in temp2
2037 /* betajnj * zeta_jk ^ nj-1 */
2038 tmp=exchange->betajnj*pow(zeta,(n-1.0));
2039 tmp=-chi/2.0*pow((1+tmp*zeta),(-1.0/(2.0*n)-1))*tmp;
2040 v3_scale(&temp2,&temp2,tmp*B*exp(-mu*d_jk)*f_c_jk*0.5);
2041 v3_add(&(ai->f),&(ai->f),&temp2); /* -1 skipped in f_a calc ^ */
2042 /* scaled with 0.5 ^ */
2045 ai->virial.xx-=temp2.x*dist_jk.x;
2046 ai->virial.yy-=temp2.y*dist_jk.y;
2047 ai->virial.zz-=temp2.z*dist_jk.z;
2048 ai->virial.xy-=temp2.x*dist_jk.y;
2049 ai->virial.xz-=temp2.x*dist_jk.z;
2050 ai->virial.yz-=temp2.y*dist_jk.z;
2053 if(ai==&(moldyn->atom[0])) {
2054 printf("dVjk (3bp) contrib:\n");
2055 printf("%f | %f\n",temp2.x,ai->f.x);
2056 printf("%f | %f\n",temp2.y,ai->f.y);
2057 printf("%f | %f\n",temp2.z,ai->f.z);
2061 if(ai==&(moldyn->atom[0])) {
2062 printf("dVjk (3bp) contrib:\n");
2063 printf("%f | %f\n",temp2.x*dist_jk.x,ai->virial.xx);
2064 printf("%f | %f\n",temp2.y*dist_jk.y,ai->virial.yy);
2065 printf("%f | %f\n",temp2.z*dist_jk.z,ai->virial.zz);
2076 * debugging / critical check functions
2079 int moldyn_bc_check(t_moldyn *moldyn) {
2092 for(i=0;i<moldyn->count;i++) {
2093 if(atom[i].r.x>=dim->x/2||-atom[i].r.x>dim->x/2) {
2094 printf("FATAL: atom %d: x: %.20f (%.20f)\n",
2095 i,atom[i].r.x,dim->x/2);
2096 printf("diagnostic:\n");
2097 printf("-----------\natom.r.x:\n");
2099 memcpy(&byte,(u8 *)(&(atom[i].r.x))+j,1);
2102 ((byte)&(1<<k))?1:0,
2105 printf("---------------\nx=dim.x/2:\n");
2107 memcpy(&byte,(u8 *)(&x)+j,1);
2110 ((byte)&(1<<k))?1:0,
2113 if(atom[i].r.x==x) printf("the same!\n");
2114 else printf("different!\n");
2116 if(atom[i].r.y>=dim->y/2||-atom[i].r.y>dim->y/2)
2117 printf("FATAL: atom %d: y: %.20f (%.20f)\n",
2118 i,atom[i].r.y,dim->y/2);
2119 if(atom[i].r.z>=dim->z/2||-atom[i].r.z>dim->z/2)
2120 printf("FATAL: atom %d: z: %.20f (%.20f)\n",
2121 i,atom[i].r.z,dim->z/2);