2 * lennard_jones.c - lennard jones potential
4 * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
12 #include <sys/types.h>
18 #include "../moldyn.h"
19 #include "../math/math.h"
20 #include "lennard_jones.h"
22 int lennard_jones(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
25 t_3dvec force,distance;
27 double eps,sig6,sig12;
29 params=moldyn->pot_params;
32 sig12=params->sigma12;
36 v3_sub(&distance,&(aj->r),&(ai->r));
37 if(bc) check_per_bound(moldyn,&distance);
38 d=v3_absolute_square(&distance); /* r^2 */
39 if(d<=moldyn->cutoff_square) {
43 h1=h2*h2; /* 1/r^12 */
44 moldyn->energy+=(eps*(sig12*h1-sig6*h2)-params->uc);
51 v3_scale(&force,&distance,d);
52 v3_add(&(aj->f),&(aj->f),&force);
53 v3_scale(&force,&force,-1.0); /* f = - grad E */
54 v3_add(&(ai->f),&(ai->f),&force);
55 virial_calc(ai,&force,&distance);
56 virial_calc(aj,&force,&distance); /* f and d signe switched */