Remove all unnecessary HAVE_CONFIG_H
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEwSh_VdwLJEwSh_GeomW3P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 /*
48  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJEwSh_GeomW3P1_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            LJEwald
51  * Geometry:                   Water3-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW3P1_VF_c
56                     (t_nblist                    * gmx_restrict       nlist,
57                      rvec                        * gmx_restrict          xx,
58                      rvec                        * gmx_restrict          ff,
59                      t_forcerec                  * gmx_restrict          fr,
60                      t_mdatoms                   * gmx_restrict     mdatoms,
61                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
62                      t_nrnb                      * gmx_restrict        nrnb)
63 {
64     int              i_shift_offset,i_coord_offset,j_coord_offset;
65     int              j_index_start,j_index_end;
66     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
67     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
68     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
69     real             *shiftvec,*fshift,*x,*f;
70     int              vdwioffset0;
71     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72     int              vdwioffset1;
73     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74     int              vdwioffset2;
75     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
76     int              vdwjidx0;
77     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
78     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
79     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
80     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
81     real             velec,felec,velecsum,facel,crf,krf,krf2;
82     real             *charge;
83     int              nvdwtype;
84     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
85     int              *vdwtype;
86     real             *vdwparam;
87     real             c6grid_00;
88     real             c6grid_10;
89     real             c6grid_20;
90     real             ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
91     real             *vdwgridparam;
92     int              ewitab;
93     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
94     real             *ewtab;
95
96     x                = xx[0];
97     f                = ff[0];
98
99     nri              = nlist->nri;
100     iinr             = nlist->iinr;
101     jindex           = nlist->jindex;
102     jjnr             = nlist->jjnr;
103     shiftidx         = nlist->shift;
104     gid              = nlist->gid;
105     shiftvec         = fr->shift_vec[0];
106     fshift           = fr->fshift[0];
107     facel            = fr->epsfac;
108     charge           = mdatoms->chargeA;
109     nvdwtype         = fr->ntype;
110     vdwparam         = fr->nbfp;
111     vdwtype          = mdatoms->typeA;
112     vdwgridparam     = fr->ljpme_c6grid;
113     ewclj            = fr->ewaldcoeff_lj;
114     sh_lj_ewald      = fr->ic->sh_lj_ewald;
115     ewclj2           = ewclj*ewclj;
116     ewclj6           = ewclj2*ewclj2*ewclj2;
117
118     sh_ewald         = fr->ic->sh_ewald;
119     ewtab            = fr->ic->tabq_coul_FDV0;
120     ewtabscale       = fr->ic->tabq_scale;
121     ewtabhalfspace   = 0.5/ewtabscale;
122
123     /* Setup water-specific parameters */
124     inr              = nlist->iinr[0];
125     iq0              = facel*charge[inr+0];
126     iq1              = facel*charge[inr+1];
127     iq2              = facel*charge[inr+2];
128     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
129
130     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
131     rcutoff          = fr->rcoulomb;
132     rcutoff2         = rcutoff*rcutoff;
133
134     sh_vdw_invrcut6  = fr->ic->sh_invrc6;
135     rvdw             = fr->rvdw;
136
137     outeriter        = 0;
138     inneriter        = 0;
139
140     /* Start outer loop over neighborlists */
141     for(iidx=0; iidx<nri; iidx++)
142     {
143         /* Load shift vector for this list */
144         i_shift_offset   = DIM*shiftidx[iidx];
145         shX              = shiftvec[i_shift_offset+XX];
146         shY              = shiftvec[i_shift_offset+YY];
147         shZ              = shiftvec[i_shift_offset+ZZ];
148
149         /* Load limits for loop over neighbors */
150         j_index_start    = jindex[iidx];
151         j_index_end      = jindex[iidx+1];
152
153         /* Get outer coordinate index */
154         inr              = iinr[iidx];
155         i_coord_offset   = DIM*inr;
156
157         /* Load i particle coords and add shift vector */
158         ix0              = shX + x[i_coord_offset+DIM*0+XX];
159         iy0              = shY + x[i_coord_offset+DIM*0+YY];
160         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
161         ix1              = shX + x[i_coord_offset+DIM*1+XX];
162         iy1              = shY + x[i_coord_offset+DIM*1+YY];
163         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
164         ix2              = shX + x[i_coord_offset+DIM*2+XX];
165         iy2              = shY + x[i_coord_offset+DIM*2+YY];
166         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
167
168         fix0             = 0.0;
169         fiy0             = 0.0;
170         fiz0             = 0.0;
171         fix1             = 0.0;
172         fiy1             = 0.0;
173         fiz1             = 0.0;
174         fix2             = 0.0;
175         fiy2             = 0.0;
176         fiz2             = 0.0;
177
178         /* Reset potential sums */
179         velecsum         = 0.0;
180         vvdwsum          = 0.0;
181
182         /* Start inner kernel loop */
183         for(jidx=j_index_start; jidx<j_index_end; jidx++)
184         {
185             /* Get j neighbor index, and coordinate index */
186             jnr              = jjnr[jidx];
187             j_coord_offset   = DIM*jnr;
188
189             /* load j atom coordinates */
190             jx0              = x[j_coord_offset+DIM*0+XX];
191             jy0              = x[j_coord_offset+DIM*0+YY];
192             jz0              = x[j_coord_offset+DIM*0+ZZ];
193
194             /* Calculate displacement vector */
195             dx00             = ix0 - jx0;
196             dy00             = iy0 - jy0;
197             dz00             = iz0 - jz0;
198             dx10             = ix1 - jx0;
199             dy10             = iy1 - jy0;
200             dz10             = iz1 - jz0;
201             dx20             = ix2 - jx0;
202             dy20             = iy2 - jy0;
203             dz20             = iz2 - jz0;
204
205             /* Calculate squared distance and things based on it */
206             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
207             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
208             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
209
210             rinv00           = gmx_invsqrt(rsq00);
211             rinv10           = gmx_invsqrt(rsq10);
212             rinv20           = gmx_invsqrt(rsq20);
213
214             rinvsq00         = rinv00*rinv00;
215             rinvsq10         = rinv10*rinv10;
216             rinvsq20         = rinv20*rinv20;
217
218             /* Load parameters for j particles */
219             jq0              = charge[jnr+0];
220             vdwjidx0         = 2*vdwtype[jnr+0];
221
222             /**************************
223              * CALCULATE INTERACTIONS *
224              **************************/
225
226             if (rsq00<rcutoff2)
227             {
228
229             r00              = rsq00*rinv00;
230
231             qq00             = iq0*jq0;
232             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
233             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
234             c6grid_00        = vdwgridparam[vdwioffset0+vdwjidx0];
235
236             /* EWALD ELECTROSTATICS */
237
238             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
239             ewrt             = r00*ewtabscale;
240             ewitab           = ewrt;
241             eweps            = ewrt-ewitab;
242             ewitab           = 4*ewitab;
243             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
244             velec            = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
245             felec            = qq00*rinv00*(rinvsq00-felec);
246
247             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
248             ewcljrsq         = ewclj2*rsq00;
249             exponent         = exp(-ewcljrsq);
250             poly             = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
251             vvdw6            = (c6_00-c6grid_00*(1.0-poly))*rinvsix;
252             vvdw12           = c12_00*rinvsix*rinvsix;
253             vvdw             = (vvdw12 - c12_00*sh_vdw_invrcut6*sh_vdw_invrcut6)*(1.0/12.0) - (vvdw6 - c6_00*sh_vdw_invrcut6 - c6grid_00*sh_lj_ewald)*(1.0/6.0);
254             fvdw             = (vvdw12 - vvdw6 - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
255
256             /* Update potential sums from outer loop */
257             velecsum        += velec;
258             vvdwsum         += vvdw;
259
260             fscal            = felec+fvdw;
261
262             /* Calculate temporary vectorial force */
263             tx               = fscal*dx00;
264             ty               = fscal*dy00;
265             tz               = fscal*dz00;
266
267             /* Update vectorial force */
268             fix0            += tx;
269             fiy0            += ty;
270             fiz0            += tz;
271             f[j_coord_offset+DIM*0+XX] -= tx;
272             f[j_coord_offset+DIM*0+YY] -= ty;
273             f[j_coord_offset+DIM*0+ZZ] -= tz;
274
275             }
276
277             /**************************
278              * CALCULATE INTERACTIONS *
279              **************************/
280
281             if (rsq10<rcutoff2)
282             {
283
284             r10              = rsq10*rinv10;
285
286             qq10             = iq1*jq0;
287
288             /* EWALD ELECTROSTATICS */
289
290             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
291             ewrt             = r10*ewtabscale;
292             ewitab           = ewrt;
293             eweps            = ewrt-ewitab;
294             ewitab           = 4*ewitab;
295             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
296             velec            = qq10*((rinv10-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
297             felec            = qq10*rinv10*(rinvsq10-felec);
298
299             /* Update potential sums from outer loop */
300             velecsum        += velec;
301
302             fscal            = felec;
303
304             /* Calculate temporary vectorial force */
305             tx               = fscal*dx10;
306             ty               = fscal*dy10;
307             tz               = fscal*dz10;
308
309             /* Update vectorial force */
310             fix1            += tx;
311             fiy1            += ty;
312             fiz1            += tz;
313             f[j_coord_offset+DIM*0+XX] -= tx;
314             f[j_coord_offset+DIM*0+YY] -= ty;
315             f[j_coord_offset+DIM*0+ZZ] -= tz;
316
317             }
318
319             /**************************
320              * CALCULATE INTERACTIONS *
321              **************************/
322
323             if (rsq20<rcutoff2)
324             {
325
326             r20              = rsq20*rinv20;
327
328             qq20             = iq2*jq0;
329
330             /* EWALD ELECTROSTATICS */
331
332             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
333             ewrt             = r20*ewtabscale;
334             ewitab           = ewrt;
335             eweps            = ewrt-ewitab;
336             ewitab           = 4*ewitab;
337             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
338             velec            = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
339             felec            = qq20*rinv20*(rinvsq20-felec);
340
341             /* Update potential sums from outer loop */
342             velecsum        += velec;
343
344             fscal            = felec;
345
346             /* Calculate temporary vectorial force */
347             tx               = fscal*dx20;
348             ty               = fscal*dy20;
349             tz               = fscal*dz20;
350
351             /* Update vectorial force */
352             fix2            += tx;
353             fiy2            += ty;
354             fiz2            += tz;
355             f[j_coord_offset+DIM*0+XX] -= tx;
356             f[j_coord_offset+DIM*0+YY] -= ty;
357             f[j_coord_offset+DIM*0+ZZ] -= tz;
358
359             }
360
361             /* Inner loop uses 158 flops */
362         }
363         /* End of innermost loop */
364
365         tx = ty = tz = 0;
366         f[i_coord_offset+DIM*0+XX] += fix0;
367         f[i_coord_offset+DIM*0+YY] += fiy0;
368         f[i_coord_offset+DIM*0+ZZ] += fiz0;
369         tx                         += fix0;
370         ty                         += fiy0;
371         tz                         += fiz0;
372         f[i_coord_offset+DIM*1+XX] += fix1;
373         f[i_coord_offset+DIM*1+YY] += fiy1;
374         f[i_coord_offset+DIM*1+ZZ] += fiz1;
375         tx                         += fix1;
376         ty                         += fiy1;
377         tz                         += fiz1;
378         f[i_coord_offset+DIM*2+XX] += fix2;
379         f[i_coord_offset+DIM*2+YY] += fiy2;
380         f[i_coord_offset+DIM*2+ZZ] += fiz2;
381         tx                         += fix2;
382         ty                         += fiy2;
383         tz                         += fiz2;
384         fshift[i_shift_offset+XX]  += tx;
385         fshift[i_shift_offset+YY]  += ty;
386         fshift[i_shift_offset+ZZ]  += tz;
387
388         ggid                        = gid[iidx];
389         /* Update potential energies */
390         kernel_data->energygrp_elec[ggid] += velecsum;
391         kernel_data->energygrp_vdw[ggid] += vvdwsum;
392
393         /* Increment number of inner iterations */
394         inneriter                  += j_index_end - j_index_start;
395
396         /* Outer loop uses 32 flops */
397     }
398
399     /* Increment number of outer iterations */
400     outeriter        += nri;
401
402     /* Update outer/inner flops */
403
404     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*158);
405 }
406 /*
407  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJEwSh_GeomW3P1_F_c
408  * Electrostatics interaction: Ewald
409  * VdW interaction:            LJEwald
410  * Geometry:                   Water3-Particle
411  * Calculate force/pot:        Force
412  */
413 void
414 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW3P1_F_c
415                     (t_nblist                    * gmx_restrict       nlist,
416                      rvec                        * gmx_restrict          xx,
417                      rvec                        * gmx_restrict          ff,
418                      t_forcerec                  * gmx_restrict          fr,
419                      t_mdatoms                   * gmx_restrict     mdatoms,
420                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
421                      t_nrnb                      * gmx_restrict        nrnb)
422 {
423     int              i_shift_offset,i_coord_offset,j_coord_offset;
424     int              j_index_start,j_index_end;
425     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
426     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
427     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
428     real             *shiftvec,*fshift,*x,*f;
429     int              vdwioffset0;
430     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
431     int              vdwioffset1;
432     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
433     int              vdwioffset2;
434     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
435     int              vdwjidx0;
436     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
437     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
438     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
439     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
440     real             velec,felec,velecsum,facel,crf,krf,krf2;
441     real             *charge;
442     int              nvdwtype;
443     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
444     int              *vdwtype;
445     real             *vdwparam;
446     real             c6grid_00;
447     real             c6grid_10;
448     real             c6grid_20;
449     real             ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,sh_lj_ewald;
450     real             *vdwgridparam;
451     int              ewitab;
452     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
453     real             *ewtab;
454
455     x                = xx[0];
456     f                = ff[0];
457
458     nri              = nlist->nri;
459     iinr             = nlist->iinr;
460     jindex           = nlist->jindex;
461     jjnr             = nlist->jjnr;
462     shiftidx         = nlist->shift;
463     gid              = nlist->gid;
464     shiftvec         = fr->shift_vec[0];
465     fshift           = fr->fshift[0];
466     facel            = fr->epsfac;
467     charge           = mdatoms->chargeA;
468     nvdwtype         = fr->ntype;
469     vdwparam         = fr->nbfp;
470     vdwtype          = mdatoms->typeA;
471     vdwgridparam     = fr->ljpme_c6grid;
472     ewclj            = fr->ewaldcoeff_lj;
473     sh_lj_ewald      = fr->ic->sh_lj_ewald;
474     ewclj2           = ewclj*ewclj;
475     ewclj6           = ewclj2*ewclj2*ewclj2;
476
477     sh_ewald         = fr->ic->sh_ewald;
478     ewtab            = fr->ic->tabq_coul_F;
479     ewtabscale       = fr->ic->tabq_scale;
480     ewtabhalfspace   = 0.5/ewtabscale;
481
482     /* Setup water-specific parameters */
483     inr              = nlist->iinr[0];
484     iq0              = facel*charge[inr+0];
485     iq1              = facel*charge[inr+1];
486     iq2              = facel*charge[inr+2];
487     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
488
489     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
490     rcutoff          = fr->rcoulomb;
491     rcutoff2         = rcutoff*rcutoff;
492
493     sh_vdw_invrcut6  = fr->ic->sh_invrc6;
494     rvdw             = fr->rvdw;
495
496     outeriter        = 0;
497     inneriter        = 0;
498
499     /* Start outer loop over neighborlists */
500     for(iidx=0; iidx<nri; iidx++)
501     {
502         /* Load shift vector for this list */
503         i_shift_offset   = DIM*shiftidx[iidx];
504         shX              = shiftvec[i_shift_offset+XX];
505         shY              = shiftvec[i_shift_offset+YY];
506         shZ              = shiftvec[i_shift_offset+ZZ];
507
508         /* Load limits for loop over neighbors */
509         j_index_start    = jindex[iidx];
510         j_index_end      = jindex[iidx+1];
511
512         /* Get outer coordinate index */
513         inr              = iinr[iidx];
514         i_coord_offset   = DIM*inr;
515
516         /* Load i particle coords and add shift vector */
517         ix0              = shX + x[i_coord_offset+DIM*0+XX];
518         iy0              = shY + x[i_coord_offset+DIM*0+YY];
519         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
520         ix1              = shX + x[i_coord_offset+DIM*1+XX];
521         iy1              = shY + x[i_coord_offset+DIM*1+YY];
522         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
523         ix2              = shX + x[i_coord_offset+DIM*2+XX];
524         iy2              = shY + x[i_coord_offset+DIM*2+YY];
525         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
526
527         fix0             = 0.0;
528         fiy0             = 0.0;
529         fiz0             = 0.0;
530         fix1             = 0.0;
531         fiy1             = 0.0;
532         fiz1             = 0.0;
533         fix2             = 0.0;
534         fiy2             = 0.0;
535         fiz2             = 0.0;
536
537         /* Start inner kernel loop */
538         for(jidx=j_index_start; jidx<j_index_end; jidx++)
539         {
540             /* Get j neighbor index, and coordinate index */
541             jnr              = jjnr[jidx];
542             j_coord_offset   = DIM*jnr;
543
544             /* load j atom coordinates */
545             jx0              = x[j_coord_offset+DIM*0+XX];
546             jy0              = x[j_coord_offset+DIM*0+YY];
547             jz0              = x[j_coord_offset+DIM*0+ZZ];
548
549             /* Calculate displacement vector */
550             dx00             = ix0 - jx0;
551             dy00             = iy0 - jy0;
552             dz00             = iz0 - jz0;
553             dx10             = ix1 - jx0;
554             dy10             = iy1 - jy0;
555             dz10             = iz1 - jz0;
556             dx20             = ix2 - jx0;
557             dy20             = iy2 - jy0;
558             dz20             = iz2 - jz0;
559
560             /* Calculate squared distance and things based on it */
561             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
562             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
563             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
564
565             rinv00           = gmx_invsqrt(rsq00);
566             rinv10           = gmx_invsqrt(rsq10);
567             rinv20           = gmx_invsqrt(rsq20);
568
569             rinvsq00         = rinv00*rinv00;
570             rinvsq10         = rinv10*rinv10;
571             rinvsq20         = rinv20*rinv20;
572
573             /* Load parameters for j particles */
574             jq0              = charge[jnr+0];
575             vdwjidx0         = 2*vdwtype[jnr+0];
576
577             /**************************
578              * CALCULATE INTERACTIONS *
579              **************************/
580
581             if (rsq00<rcutoff2)
582             {
583
584             r00              = rsq00*rinv00;
585
586             qq00             = iq0*jq0;
587             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
588             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
589             c6grid_00        = vdwgridparam[vdwioffset0+vdwjidx0];
590
591             /* EWALD ELECTROSTATICS */
592
593             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
594             ewrt             = r00*ewtabscale;
595             ewitab           = ewrt;
596             eweps            = ewrt-ewitab;
597             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
598             felec            = qq00*rinv00*(rinvsq00-felec);
599
600             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
601             ewcljrsq         = ewclj2*rsq00;
602             exponent         = exp(-ewcljrsq);
603             poly             = exponent*(1.0 + ewcljrsq + ewcljrsq*ewcljrsq*0.5);
604             fvdw             = (((c12_00*rinvsix - c6_00 + c6grid_00*(1.0-poly))*rinvsix) - c6grid_00*(1.0/6.0)*exponent*ewclj6)*rinvsq00;
605
606             fscal            = felec+fvdw;
607
608             /* Calculate temporary vectorial force */
609             tx               = fscal*dx00;
610             ty               = fscal*dy00;
611             tz               = fscal*dz00;
612
613             /* Update vectorial force */
614             fix0            += tx;
615             fiy0            += ty;
616             fiz0            += tz;
617             f[j_coord_offset+DIM*0+XX] -= tx;
618             f[j_coord_offset+DIM*0+YY] -= ty;
619             f[j_coord_offset+DIM*0+ZZ] -= tz;
620
621             }
622
623             /**************************
624              * CALCULATE INTERACTIONS *
625              **************************/
626
627             if (rsq10<rcutoff2)
628             {
629
630             r10              = rsq10*rinv10;
631
632             qq10             = iq1*jq0;
633
634             /* EWALD ELECTROSTATICS */
635
636             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
637             ewrt             = r10*ewtabscale;
638             ewitab           = ewrt;
639             eweps            = ewrt-ewitab;
640             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
641             felec            = qq10*rinv10*(rinvsq10-felec);
642
643             fscal            = felec;
644
645             /* Calculate temporary vectorial force */
646             tx               = fscal*dx10;
647             ty               = fscal*dy10;
648             tz               = fscal*dz10;
649
650             /* Update vectorial force */
651             fix1            += tx;
652             fiy1            += ty;
653             fiz1            += tz;
654             f[j_coord_offset+DIM*0+XX] -= tx;
655             f[j_coord_offset+DIM*0+YY] -= ty;
656             f[j_coord_offset+DIM*0+ZZ] -= tz;
657
658             }
659
660             /**************************
661              * CALCULATE INTERACTIONS *
662              **************************/
663
664             if (rsq20<rcutoff2)
665             {
666
667             r20              = rsq20*rinv20;
668
669             qq20             = iq2*jq0;
670
671             /* EWALD ELECTROSTATICS */
672
673             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
674             ewrt             = r20*ewtabscale;
675             ewitab           = ewrt;
676             eweps            = ewrt-ewitab;
677             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
678             felec            = qq20*rinv20*(rinvsq20-felec);
679
680             fscal            = felec;
681
682             /* Calculate temporary vectorial force */
683             tx               = fscal*dx20;
684             ty               = fscal*dy20;
685             tz               = fscal*dz20;
686
687             /* Update vectorial force */
688             fix2            += tx;
689             fiy2            += ty;
690             fiz2            += tz;
691             f[j_coord_offset+DIM*0+XX] -= tx;
692             f[j_coord_offset+DIM*0+YY] -= ty;
693             f[j_coord_offset+DIM*0+ZZ] -= tz;
694
695             }
696
697             /* Inner loop uses 123 flops */
698         }
699         /* End of innermost loop */
700
701         tx = ty = tz = 0;
702         f[i_coord_offset+DIM*0+XX] += fix0;
703         f[i_coord_offset+DIM*0+YY] += fiy0;
704         f[i_coord_offset+DIM*0+ZZ] += fiz0;
705         tx                         += fix0;
706         ty                         += fiy0;
707         tz                         += fiz0;
708         f[i_coord_offset+DIM*1+XX] += fix1;
709         f[i_coord_offset+DIM*1+YY] += fiy1;
710         f[i_coord_offset+DIM*1+ZZ] += fiz1;
711         tx                         += fix1;
712         ty                         += fiy1;
713         tz                         += fiz1;
714         f[i_coord_offset+DIM*2+XX] += fix2;
715         f[i_coord_offset+DIM*2+YY] += fiy2;
716         f[i_coord_offset+DIM*2+ZZ] += fiz2;
717         tx                         += fix2;
718         ty                         += fiy2;
719         tz                         += fiz2;
720         fshift[i_shift_offset+XX]  += tx;
721         fshift[i_shift_offset+YY]  += ty;
722         fshift[i_shift_offset+ZZ]  += tz;
723
724         /* Increment number of inner iterations */
725         inneriter                  += j_index_end - j_index_start;
726
727         /* Outer loop uses 30 flops */
728     }
729
730     /* Increment number of outer iterations */
731     outeriter        += nri;
732
733     /* Update outer/inner flops */
734
735     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*123);
736 }