4 * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
12 #include <sys/types.h>
29 #include "../moldyn.h"
30 #include "../math/math.h"
34 extern pthread_mutex_t *amutex;
35 extern pthread_mutex_t emutex;
42 #define albe_v_calc(a,f,d) a->virial.xx+=f->x*d->x; \
43 a->virial.yy+=f->y*d->y; \
44 a->virial.zz+=f->z*d->z; \
45 a->virial.xy+=f->x*d->y; \
46 a->virial.xz+=f->x*d->z; \
47 a->virial.yz+=f->y*d->z
51 int albe_potential_force_calc(t_moldyn *moldyn) {
54 t_atom *itom,*jtom,*ktom;
64 t_list neighbour_i[27];
65 t_list neighbour_i2[27];
73 pthread_t kthread[27];
80 t_albe_mult_params *params;
81 t_albe_exchange *exchange;
95 double cos_theta,h_cos,d2_h_cos2,frac,g,dg,s_r,arg;
96 double f_c_ik,df_c_ik;
99 double f_a,df_a,b,db,f_c,df_c;
108 double dijdik_inv,fcdg,dfcg;
109 t_3dvec dcosdrj,dcosdrk;
126 params=moldyn->pot_params;
127 exchange=&(params->exchange);
133 /* reset global virial */
134 memset(&(moldyn->gvir),0,sizeof(t_virial));
136 /* reset force, site energy and virial of every atom */
138 #pragma omp parallel for private(virial)
140 for(i=0;i<count;i++) {
143 v3_zero(&(itom[i].f));
146 virial=(&(itom[i].virial));
154 /* reset site energy */
159 /* get energy, force and virial of every atom */
161 /* first (and only) loop over atoms i */
162 for(i=0;i<count;i++) {
164 if(!(itom[i].attr&ATOM_ATTR_3BP))
167 link_cell_neighbour_index(moldyn,
168 (itom[i].r.x+moldyn->dim.x/2)/lc->x,
169 (itom[i].r.y+moldyn->dim.y/2)/lc->y,
170 (itom[i].r.z+moldyn->dim.z/2)/lc->z,
175 /* copy the neighbour lists */
179 memcpy(neighbour_i2,neighbour_i,27*sizeof(t_list));
185 /* loop over atoms j */
192 while(neighbour_i[j][p]!=-1) {
194 jtom=&(itom[neighbour_i[j][p]]);
202 p=lc->subcell->list[p];
204 this=&(neighbour_i[j]);
207 if(this->start==NULL)
212 jtom=this->current->data;
218 if(!(jtom->attr&ATOM_ATTR_3BP))
225 /* j1 func here ... */
226 /* albe 3 body potential function (first ij loop) */
232 * set ij depending values
235 if(brand_i==jtom->brand) {
236 S2=params->S2[brand_i];
243 v3_sub(&dist_ij,&(jtom->r),&(ai->r));
244 if(bc_ij) check_per_bound(moldyn,&dist_ij);
245 d_ij2=v3_absolute_square(&dist_ij);
247 /* if d_ij2 > S2 => no force & potential energy contribution */
254 /* reset k counter for first k loop */
257 /* first loop over atoms k */
264 while(neighbour_i[k][q]!=-1) {
266 ktom=&(itom[neighbour_i[k][q]]);
274 q=lc->subcell->list[q];
276 that=&(neighbour_i2[k]);
279 if(that->start==NULL)
283 ktom=that->current->data;
286 if(!(ktom->attr&ATOM_ATTR_3BP))
295 /* k1 func here ... */
296 /* albe 3 body potential function (first k loop) */
298 if(kcount>ALBE_MAXN) {
299 printf("FATAL: neighbours = %d\n",kcount);
300 printf(" -> %d %d %d\n",ai->tag,jtom->tag,ktom->tag);
304 if(brand_i==ktom->brand) {
305 Rk=params->R[brand_i];
306 Sk=params->S[brand_i];
307 Sk2=params->S2[brand_i];
308 /* albe needs i,k depending c,d,h and gamma values */
309 gamma_i=params->gamma[brand_i];
310 c_i=params->c[brand_i];
311 d_i=params->d[brand_i];
312 h_i=params->h[brand_i];
313 ci2=params->c2[brand_i];
314 di2=params->d2[brand_i];
315 ci2di2=params->c2d2[brand_i];
321 /* albe needs i,k depending c,d,h and gamma values */
322 gamma_i=params->gamma_m;
326 ci2=params->c2_mixed;
327 di2=params->d2_mixed;
328 ci2di2=params->c2d2_m;
332 v3_sub(&dist_ik,&(ktom->r),&(ai->r));
333 if(bc_ik) check_per_bound(moldyn,&dist_ik);
334 d_ik2=v3_absolute_square(&dist_ik);
336 /* store data for second k loop */
337 exchange->dist_ik[kcount]=dist_ik;
338 exchange->d_ik2[kcount]=d_ik2;
340 /* return if not within cutoff */
350 cos_theta=v3_scalar_product(&dist_ij,&dist_ik)/(d_ij*d_ik);
353 h_cos=*(exchange->h_i)+cos_theta; // + in albe formalism
354 d2_h_cos2=exchange->di2+(h_cos*h_cos);
355 frac=exchange->ci2/d2_h_cos2;
356 g=*(exchange->gamma_i)*(1.0+exchange->ci2di2-frac);
357 dg=2.0*frac**(exchange->gamma_i)*h_cos/d2_h_cos2; // + in albe f..
360 h_cos=h_i+cos_theta; // + in albe formalism
361 d2_h_cos2=di2+(h_cos*h_cos);
363 g=gamma_i*(1.0+ci2di2-frac);
364 dg=2.0*frac*gamma_i*h_cos/d2_h_cos2; // + in albe f..
366 /* zeta sum += f_c_ik * g_ijk */
374 arg=M_PI*(d_ik-Rk)/s_r;
375 f_c_ik=0.5+0.5*cos(arg);
376 df_c_ik=0.5*sin(arg)*(M_PI/(s_r*d_ik));
380 /* store even more data for second k loop */
381 exchange->g[kcount]=g;
382 exchange->dg[kcount]=dg;
383 exchange->d_ik[kcount]=d_ik;
384 exchange->cos_theta[kcount]=cos_theta;
385 exchange->f_c_ik[kcount]=f_c_ik;
386 exchange->df_c_ik[kcount]=df_c_ik;
388 /* increase k counter */
396 } while(list_next_f(that)!=\
402 /* j2 func here ... */
405 if(brand_i==jtom->brand) {
406 S=params->S[brand_i];
407 R=params->R[brand_i];
408 B=params->B[brand_i];
409 A=params->A[brand_i];
410 r0=params->r0[brand_i];
411 mu=params->mu[brand_i];
412 lambda=params->lambda[brand_i];
421 lambda=params->lambda_m;
431 arg=M_PI*(d_ij-R)/s_r;
432 f_c=0.5+0.5*cos(arg);
433 df_c=0.5*sin(arg)*(M_PI/(s_r*d_ij));
437 f_a=-B*exp(-mu*(d_ij-r0));
441 f_r=A*exp(-lambda*(d_ij-r0));
442 df_r=lambda*f_r/d_ij;
450 b=1.0/sqrt(1.0+zeta_ij);
451 db=-0.5*b/(1.0+zeta_ij);
454 /* force contribution for atom i */
455 scale=-0.5*(f_c*(df_r-b*df_a)+df_c*(f_r-b*f_a)); // - in albe formalism
456 v3_scale(&force,&(dist_ij),scale);
457 v3_add(&(ai->f),&(ai->f),&force);
459 /* force contribution for atom j */
460 v3_scale(&force,&force,-1.0); // dri rij = - drj rij
461 v3_add(&(jtom->f),&(jtom->f),&force);
464 virial_calc(ai,&force,&(dist_ij));
467 if(moldyn->time>DSTART&&moldyn->time<DEND) {
468 if((ai==&(moldyn->atom[DATOM]))|(jtom==&(moldyn->atom[DATOM]))) {
469 printf("force 3bp (j2): [%d %d sum]\n",ai->tag,jtom->tag);
470 printf(" adding %f %f %f\n",force.x,force.y,force.z);
471 if(ai==&(moldyn->atom[0]))
472 printf(" total i: %f %f %f\n",ai->f.x,ai->f.y,ai->f.z);
473 if(jtom==&(moldyn->atom[0]))
474 printf(" total j: %f %f %f\n",jtom->f.x,jtom->f.y,jtom->f.z);
475 printf(" energy: %f = %f %f %f %f\n",0.5*f_c*(b*f_a+f_r),
477 printf(" %f %f %f\n",zeta_ij,.0,.0);
482 /* dzeta prefactor = - f_c f_a db, (* -0.5 due to force calc) */
483 pre_dzeta=0.5*f_a*f_c*db;
485 /* energy contribution */
486 energy=0.5*f_c*(f_r-b*f_a); // - in albe formalism
487 moldyn->energy+=energy;
490 /* reset k counter for second k loop */
494 /* second loop over atoms k */
501 while(neighbour_i[k][q]!=-1) {
503 ktom=&(itom[neighbour_i[k][q]]);
511 q=lc->subcell->list[q];
513 that=&(neighbour_i2[k]);
516 if(that->start==NULL)
520 ktom=that->current->data;
523 if(!(ktom->attr&ATOM_ATTR_3BP))
533 /* k2 func here ... */
534 /* albe 3 body potential function (second k loop) */
537 printf("FATAL: neighbours!\n");
540 d_ik2=exchange->d_ik2[kcount];
542 if(brand_i==ktom->brand)
543 Sk2=params->S2[brand_i];
547 /* return if d_ik > S */
554 dist_ik=exchange->dist_ik[kcount];
555 d_ik=exchange->d_ik[kcount];
557 /* f_c_ik, df_c_ik */
558 f_c_ik=exchange->f_c_ik[kcount];
559 df_c_ik=exchange->df_c_ik[kcount];
561 /* g, dg, cos_theta */
562 g=exchange->g[kcount];
563 dg=exchange->dg[kcount];
564 cos_theta=exchange->cos_theta[kcount];
566 /* cos_theta derivatives wrt j,k */
567 dijdik_inv=1.0/(d_ij*d_ik);
568 v3_scale(&dcosdrj,&dist_ik,dijdik_inv); // j
569 v3_scale(&tmp,&dist_ij,-cos_theta/d_ij2);
570 v3_add(&dcosdrj,&dcosdrj,&tmp);
571 v3_scale(&dcosdrk,&dist_ij,dijdik_inv); // k
572 v3_scale(&tmp,&dist_ik,-cos_theta/d_ik2);
573 v3_add(&dcosdrk,&dcosdrk,&tmp);
575 /* f_c_ik * dg, df_c_ik * g */
579 /* derivative wrt j */
580 v3_scale(&force,&dcosdrj,fcdg*pre_dzeta);
582 /* force contribution */
583 v3_add(&(jtom->f),&(jtom->f),&force);
586 if(moldyn->time>DSTART&&moldyn->time<DEND) {
587 if(jtom==&(moldyn->atom[DATOM])) {
588 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,jtom->tag,ktom->tag);
589 printf(" adding %f %f %f\n",force.x,force.y,force.z);
590 printf(" total j: %f %f %f\n",jtom->f.x,jtom->f.y,jtom->f.z);
591 printf(" angle: %f\n",acos(cos_theta)*360.0/(2*M_PI));
592 printf(" d ij ik = %f %f\n",d_ij,d_ik);
598 virial_calc(ai,&force,&dist_ij);
600 /* force contribution to atom i */
601 v3_scale(&force,&force,-1.0);
602 v3_add(&(ai->f),&(ai->f),&force);
604 /* derivative wrt k */
605 v3_scale(&force,&dist_ik,-1.0*dfcg); // dri rik = - drk rik
606 v3_scale(&tmp,&dcosdrk,fcdg);
607 v3_add(&force,&force,&tmp);
608 v3_scale(&force,&force,pre_dzeta);
610 /* force contribution */
611 v3_add(&(ktom->f),&(ktom->f),&force);
614 if(moldyn->time>DSTART&&moldyn->time<DEND) {
615 if(ktom==&(moldyn->atom[DATOM])) {
616 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,jtom->tag,ktom->tag);
617 printf(" adding %f %f %f\n",force.x,force.y,force.z);
618 printf(" total k: %f %f %f\n",ktom->f.x,ktom->f.y,ktom->f.z);
619 printf(" angle: %f\n",acos(cos_theta)*360.0/(2*M_PI));
620 printf(" d ij ik = %f %f\n",d_ij,d_ik);
626 virial_calc(ai,&force,&dist_ik);
628 /* force contribution to atom i */
629 v3_scale(&force,&force,-1.0);
630 v3_add(&(ai->f),&(ai->f),&force);
632 /* increase k counter */
642 } while(list_next_f(that)!=\
653 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
668 //printf("\nATOM 0: %f %f %f\n\n",itom->f.x,itom->f.y,itom->f.z);
669 if(moldyn->time>DSTART&&moldyn->time<DEND) {
671 printf(" x: %0.40f\n",moldyn->atom[DATOM].f.x);
672 printf(" y: %0.40f\n",moldyn->atom[DATOM].f.y);
673 printf(" z: %0.40f\n",moldyn->atom[DATOM].f.z);
677 /* some postprocessing */
679 #pragma omp parallel for
681 for(i=0;i<count;i++) {
682 /* calculate global virial */
683 moldyn->gvir.xx+=itom[i].r.x*itom[i].f.x;
684 moldyn->gvir.yy+=itom[i].r.y*itom[i].f.y;
685 moldyn->gvir.zz+=itom[i].r.z*itom[i].f.z;
686 moldyn->gvir.xy+=itom[i].r.y*itom[i].f.x;
687 moldyn->gvir.xz+=itom[i].r.z*itom[i].f.x;
688 moldyn->gvir.yz+=itom[i].r.z*itom[i].f.y;
690 /* check forces regarding the given timestep */
691 if(v3_norm(&(itom[i].f))>\
692 0.1*moldyn->nnd*itom[i].mass/moldyn->tau_square)
693 printf("[moldyn] WARNING: pfc (high force: atom %d)\n",
704 typedef struct s_pft_data {
709 void *potential_force_thread(void *ptr) {
711 t_pft_data *pft_data;
716 t_atom *itom,*jtom,*ktom;
719 int *neighbour_i[27];
725 t_list neighbour_i[27];
726 t_list neighbour_i2[27];
736 t_albe_mult_params *params;
737 t_albe_exchange *exchange;
751 double cos_theta,h_cos,d2_h_cos2,frac,g,dg,s_r,arg;
752 double f_c_ik,df_c_ik;
755 double f_a,df_a,b,db,f_c,df_c;
764 double dijdik_inv,fcdg,dfcg;
765 t_3dvec dcosdrj,dcosdrk;
778 moldyn=pft_data->moldyn;
786 params=moldyn->pot_params;
789 /* get energy, force and virial of every atom */
791 /* first (and only) loop over atoms i */
792 for(i=0;i<count;i++) {
794 if(!(itom[i].attr&ATOM_ATTR_3BP))
797 link_cell_neighbour_index(moldyn,
798 (itom[i].r.x+moldyn->dim.x/2)/lc->x,
799 (itom[i].r.y+moldyn->dim.y/2)/lc->y,
800 (itom[i].r.z+moldyn->dim.z/2)/lc->z,
805 /* copy the neighbour lists */
809 memcpy(neighbour_i2,neighbour_i,27*sizeof(t_list));
815 /* loop over atoms j */
822 while(neighbour_i[j][p]!=-1) {
824 jtom=&(itom[neighbour_i[j][p]]);
832 p=lc->subcell->list[p];
834 this=&(neighbour_i[j]);
837 if(this->start==NULL)
842 jtom=this->current->data;
848 if(!(jtom->attr&ATOM_ATTR_3BP))
855 /* j1 func here ... */
856 /* albe 3 body potential function (first ij loop) */
862 * set ij depending values
865 if(brand_i==jtom->brand) {
866 S2=params->S2[brand_i];
873 v3_sub(&dist_ij,&(jtom->r),&(ai->r));
874 if(bc_ij) check_per_bound(moldyn,&dist_ij);
875 d_ij2=v3_absolute_square(&dist_ij);
877 /* if d_ij2 > S2 => no force & potential energy contribution */
884 /* reset k counter for first k loop */
887 /* first loop over atoms k */
894 while(neighbour_i[k][q]!=-1) {
896 ktom=&(itom[neighbour_i[k][q]]);
904 q=lc->subcell->list[q];
906 that=&(neighbour_i2[k]);
909 if(that->start==NULL)
913 ktom=that->current->data;
916 if(!(ktom->attr&ATOM_ATTR_3BP))
925 /* k1 func here ... */
926 /* albe 3 body potential function (first k loop) */
928 if(kcount>ALBE_MAXN) {
929 printf("FATAL: neighbours = %d\n",kcount);
930 printf(" -> %d %d %d\n",ai->tag,jtom->tag,ktom->tag);
934 if(brand_i==ktom->brand) {
935 Rk=params->R[brand_i];
936 Sk=params->S[brand_i];
937 Sk2=params->S2[brand_i];
938 /* albe needs i,k depending c,d,h and gamma values */
939 gamma_i=params->gamma[brand_i];
940 c_i=params->c[brand_i];
941 d_i=params->d[brand_i];
942 h_i=params->h[brand_i];
943 ci2=params->c2[brand_i];
944 di2=params->d2[brand_i];
945 ci2di2=params->c2d2[brand_i];
951 /* albe needs i,k depending c,d,h and gamma values */
952 gamma_i=params->gamma_m;
956 ci2=params->c2_mixed;
957 di2=params->d2_mixed;
958 ci2di2=params->c2d2_m;
962 v3_sub(&dist_ik,&(ktom->r),&(ai->r));
963 if(bc_ik) check_per_bound(moldyn,&dist_ik);
964 d_ik2=v3_absolute_square(&dist_ik);
966 /* store data for second k loop */
967 exchange->dist_ik[kcount]=dist_ik;
968 exchange->d_ik2[kcount]=d_ik2;
970 /* return if not within cutoff */
980 cos_theta=v3_scalar_product(&dist_ij,&dist_ik)/(d_ij*d_ik);
983 h_cos=*(exchange->h_i)+cos_theta; // + in albe formalism
984 d2_h_cos2=exchange->di2+(h_cos*h_cos);
985 frac=exchange->ci2/d2_h_cos2;
986 g=*(exchange->gamma_i)*(1.0+exchange->ci2di2-frac);
987 dg=2.0*frac**(exchange->gamma_i)*h_cos/d2_h_cos2; // + in albe f..
990 h_cos=h_i+cos_theta; // + in albe formalism
991 d2_h_cos2=di2+(h_cos*h_cos);
993 g=gamma_i*(1.0+ci2di2-frac);
994 dg=2.0*frac*gamma_i*h_cos/d2_h_cos2; // + in albe f..
996 /* zeta sum += f_c_ik * g_ijk */
1004 arg=M_PI*(d_ik-Rk)/s_r;
1005 f_c_ik=0.5+0.5*cos(arg);
1006 df_c_ik=0.5*sin(arg)*(M_PI/(s_r*d_ik));
1010 /* store even more data for second k loop */
1011 exchange->g[kcount]=g;
1012 exchange->dg[kcount]=dg;
1013 exchange->d_ik[kcount]=d_ik;
1014 exchange->cos_theta[kcount]=cos_theta;
1015 exchange->f_c_ik[kcount]=f_c_ik;
1016 exchange->df_c_ik[kcount]=df_c_ik;
1018 /* increase k counter */
1026 } while(list_next_f(that)!=\
1032 /* j2 func here ... */
1035 if(brand_i==jtom->brand) {
1036 S=params->S[brand_i];
1037 R=params->R[brand_i];
1038 B=params->B[brand_i];
1039 A=params->A[brand_i];
1040 r0=params->r0[brand_i];
1041 mu=params->mu[brand_i];
1042 lambda=params->lambda[brand_i];
1049 r0=params->r0_mixed;
1051 lambda=params->lambda_m;
1061 arg=M_PI*(d_ij-R)/s_r;
1062 f_c=0.5+0.5*cos(arg);
1063 df_c=0.5*sin(arg)*(M_PI/(s_r*d_ij));
1067 f_a=-B*exp(-mu*(d_ij-r0));
1071 f_r=A*exp(-lambda*(d_ij-r0));
1072 df_r=lambda*f_r/d_ij;
1080 b=1.0/sqrt(1.0+zeta_ij);
1081 db=-0.5*b/(1.0+zeta_ij);
1084 /* force contribution for atom i */
1085 scale=-0.5*(f_c*(df_r-b*df_a)+df_c*(f_r-b*f_a)); // - in albe formalism
1086 v3_scale(&force,&(dist_ij),scale);
1087 pthread_mutex_lock(&(amutex[ai->tag]));
1088 v3_add(&(ai->f),&(ai->f),&force);
1089 pthread_mutex_unlock(&(amutex[ai->tag]));
1091 /* force contribution for atom j */
1092 v3_scale(&force,&force,-1.0); // dri rij = - drj rij
1093 pthread_mutex_lock(&(amutex[jtom->tag]));
1094 v3_add(&(jtom->f),&(jtom->f),&force);
1095 pthread_mutex_unlock(&(amutex[jtom->tag]));
1098 pthread_mutex_lock(&(amutex[ai->tag]));
1099 virial_calc(ai,&force,&(dist_ij));
1100 pthread_mutex_unlock(&(amutex[ai->tag]));
1103 if(moldyn->time>DSTART&&moldyn->time<DEND) {
1104 if((ai==&(moldyn->atom[DATOM]))|(jtom==&(moldyn->atom[DATOM]))) {
1105 printf("force 3bp (j2): [%d %d sum]\n",ai->tag,jtom->tag);
1106 printf(" adding %f %f %f\n",force.x,force.y,force.z);
1107 if(ai==&(moldyn->atom[0]))
1108 printf(" total i: %f %f %f\n",ai->f.x,ai->f.y,ai->f.z);
1109 if(jtom==&(moldyn->atom[0]))
1110 printf(" total j: %f %f %f\n",jtom->f.x,jtom->f.y,jtom->f.z);
1111 printf(" energy: %f = %f %f %f %f\n",0.5*f_c*(b*f_a+f_r),
1113 printf(" %f %f %f\n",zeta_ij,.0,.0);
1118 /* dzeta prefactor = - f_c f_a db, (* -0.5 due to force calc) */
1119 pre_dzeta=0.5*f_a*f_c*db;
1121 /* energy contribution */
1122 energy=0.5*f_c*(f_r-b*f_a); // - in albe formalism
1123 pthread_mutex_lock(&emutex);
1124 moldyn->energy+=energy;
1125 pthread_mutex_unlock(&emutex);
1126 pthread_mutex_lock(&(amutex[ai->tag]));
1128 pthread_mutex_unlock(&(amutex[ai->tag]));
1130 /* reset k counter for second k loop */
1134 /* second loop over atoms k */
1141 while(neighbour_i[k][q]!=-1) {
1143 ktom=&(itom[neighbour_i[k][q]]);
1151 q=lc->subcell->list[q];
1153 that=&(neighbour_i2[k]);
1156 if(that->start==NULL)
1160 ktom=that->current->data;
1163 if(!(ktom->attr&ATOM_ATTR_3BP))
1169 if(ktom==&(itom[i]))
1173 /* k2 func here ... */
1174 /* albe 3 body potential function (second k loop) */
1176 if(kcount>ALBE_MAXN)
1177 printf("FATAL: neighbours!\n");
1180 d_ik2=exchange->d_ik2[kcount];
1182 if(brand_i==ktom->brand)
1183 Sk2=params->S2[brand_i];
1185 Sk2=params->S2mixed;
1187 /* return if d_ik > S */
1194 dist_ik=exchange->dist_ik[kcount];
1195 d_ik=exchange->d_ik[kcount];
1197 /* f_c_ik, df_c_ik */
1198 f_c_ik=exchange->f_c_ik[kcount];
1199 df_c_ik=exchange->df_c_ik[kcount];
1201 /* g, dg, cos_theta */
1202 g=exchange->g[kcount];
1203 dg=exchange->dg[kcount];
1204 cos_theta=exchange->cos_theta[kcount];
1206 /* cos_theta derivatives wrt j,k */
1207 dijdik_inv=1.0/(d_ij*d_ik);
1208 v3_scale(&dcosdrj,&dist_ik,dijdik_inv); // j
1209 v3_scale(&tmp,&dist_ij,-cos_theta/d_ij2);
1210 v3_add(&dcosdrj,&dcosdrj,&tmp);
1211 v3_scale(&dcosdrk,&dist_ij,dijdik_inv); // k
1212 v3_scale(&tmp,&dist_ik,-cos_theta/d_ik2);
1213 v3_add(&dcosdrk,&dcosdrk,&tmp);
1215 /* f_c_ik * dg, df_c_ik * g */
1219 /* derivative wrt j */
1220 v3_scale(&force,&dcosdrj,fcdg*pre_dzeta);
1222 /* force contribution */
1223 pthread_mutex_lock(&(amutex[jtom->tag]));
1224 v3_add(&(jtom->f),&(jtom->f),&force);
1225 pthread_mutex_unlock(&(amutex[jtom->tag]));
1228 if(moldyn->time>DSTART&&moldyn->time<DEND) {
1229 if(jtom==&(moldyn->atom[DATOM])) {
1230 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,jtom->tag,ktom->tag);
1231 printf(" adding %f %f %f\n",force.x,force.y,force.z);
1232 printf(" total j: %f %f %f\n",jtom->f.x,jtom->f.y,jtom->f.z);
1233 printf(" angle: %f\n",acos(cos_theta)*360.0/(2*M_PI));
1234 printf(" d ij ik = %f %f\n",d_ij,d_ik);
1240 pthread_mutex_lock(&(amutex[ai->tag]));
1241 virial_calc(ai,&force,&dist_ij);
1243 /* force contribution to atom i */
1244 v3_scale(&force,&force,-1.0);
1245 v3_add(&(ai->f),&(ai->f),&force);
1246 pthread_mutex_unlock(&(amutex[ai->tag]));
1248 /* derivative wrt k */
1249 v3_scale(&force,&dist_ik,-1.0*dfcg); // dri rik = - drk rik
1250 v3_scale(&tmp,&dcosdrk,fcdg);
1251 v3_add(&force,&force,&tmp);
1252 v3_scale(&force,&force,pre_dzeta);
1254 /* force contribution */
1255 pthread_mutex_lock(&(amutex[ktom->tag]));
1256 v3_add(&(ktom->f),&(ktom->f),&force);
1257 pthread_mutex_unlock(&(amutex[ktom->tag]));
1260 if(moldyn->time>DSTART&&moldyn->time<DEND) {
1261 if(ktom==&(moldyn->atom[DATOM])) {
1262 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,jtom->tag,ktom->tag);
1263 printf(" adding %f %f %f\n",force.x,force.y,force.z);
1264 printf(" total k: %f %f %f\n",ktom->f.x,ktom->f.y,ktom->f.z);
1265 printf(" angle: %f\n",acos(cos_theta)*360.0/(2*M_PI));
1266 printf(" d ij ik = %f %f\n",d_ij,d_ik);
1272 pthread_mutex_lock(&(amutex[ai->tag]));
1273 virial_calc(ai,&force,&dist_ik);
1275 /* force contribution to atom i */
1276 v3_scale(&force,&force,-1.0);
1277 v3_add(&(ai->f),&(ai->f),&force);
1278 pthread_mutex_unlock(&(amutex[ai->tag]));
1280 /* increase k counter */
1290 } while(list_next_f(that)!=\
1301 } while(list_next_f(this)!=L_NO_NEXT_ELEMENT);
1316 //printf("\nATOM 0: %f %f %f\n\n",itom->f.x,itom->f.y,itom->f.z);
1317 if(moldyn->time>DSTART&&moldyn->time<DEND) {
1319 printf(" x: %0.40f\n",moldyn->atom[DATOM].f.x);
1320 printf(" y: %0.40f\n",moldyn->atom[DATOM].f.y);
1321 printf(" z: %0.40f\n",moldyn->atom[DATOM].f.z);
1330 int albe_potential_force_calc(t_moldyn *moldyn) {
1333 t_pft_data pft_data[MAX_THREADS];
1335 pthread_t pft_thread[MAX_THREADS];
1339 count=moldyn->count;
1345 /* reset global virial */
1346 memset(&(moldyn->gvir),0,sizeof(t_virial));
1348 /* reset force, site energy and virial of every atom */
1349 for(i=0;i<count;i++) {
1352 v3_zero(&(itom[i].f));
1355 virial=&(itom[i].virial);
1363 /* reset site energy */
1372 for(j=0;j<MAX_THREADS;j++) {
1374 /* break if all atoms are processed */
1378 /* prepare thread data */
1379 pft_data[j].moldyn=moldyn;
1382 ret=pthread_create(&(pft_thread[j]),NULL,
1383 potential_force_thread,
1386 perror("[albe fast] pf thread create");
1391 //printf("threads created! %d\n",j);
1394 for(j=0;j<MAX_THREADS;j++) {
1399 ret=pthread_join(pft_thread[j],NULL);
1401 perror("[albe fast] pf thread join");
1406 /* increment counter */
1409 //printf("threads joined! -> %d\n",i);
1413 /* some postprocessing */
1414 for(i=0;i<count;i++) {
1415 /* calculate global virial */
1416 moldyn->gvir.xx+=itom[i].r.x*itom[i].f.x;
1417 moldyn->gvir.yy+=itom[i].r.y*itom[i].f.y;
1418 moldyn->gvir.zz+=itom[i].r.z*itom[i].f.z;
1419 moldyn->gvir.xy+=itom[i].r.y*itom[i].f.x;
1420 moldyn->gvir.xz+=itom[i].r.z*itom[i].f.x;
1421 moldyn->gvir.yz+=itom[i].r.z*itom[i].f.y;
1423 /* check forces regarding the given timestep */
1424 if(v3_norm(&(itom[i].f))>\
1425 0.1*moldyn->nnd*itom[i].mass/moldyn->tau_square)
1426 printf("[moldyn] WARNING: pfc (high force: atom %d)\n",