Introduce gmxpre.h for truly global definitions
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwLJ_GeomW4P1_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 "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomW4P1_VF_c
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water4-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEw_VdwLJ_GeomW4P1_VF_c
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      t_forcerec                  * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     int              i_shift_offset,i_coord_offset,j_coord_offset;
67     int              j_index_start,j_index_end;
68     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
69     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
70     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
71     real             *shiftvec,*fshift,*x,*f;
72     int              vdwioffset0;
73     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
74     int              vdwioffset1;
75     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
76     int              vdwioffset2;
77     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
78     int              vdwioffset3;
79     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
80     int              vdwjidx0;
81     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
82     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
83     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
84     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
85     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
86     real             velec,felec,velecsum,facel,crf,krf,krf2;
87     real             *charge;
88     int              nvdwtype;
89     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
90     int              *vdwtype;
91     real             *vdwparam;
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
113     sh_ewald         = fr->ic->sh_ewald;
114     ewtab            = fr->ic->tabq_coul_FDV0;
115     ewtabscale       = fr->ic->tabq_scale;
116     ewtabhalfspace   = 0.5/ewtabscale;
117
118     /* Setup water-specific parameters */
119     inr              = nlist->iinr[0];
120     iq1              = facel*charge[inr+1];
121     iq2              = facel*charge[inr+2];
122     iq3              = facel*charge[inr+3];
123     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
124
125     outeriter        = 0;
126     inneriter        = 0;
127
128     /* Start outer loop over neighborlists */
129     for(iidx=0; iidx<nri; iidx++)
130     {
131         /* Load shift vector for this list */
132         i_shift_offset   = DIM*shiftidx[iidx];
133         shX              = shiftvec[i_shift_offset+XX];
134         shY              = shiftvec[i_shift_offset+YY];
135         shZ              = shiftvec[i_shift_offset+ZZ];
136
137         /* Load limits for loop over neighbors */
138         j_index_start    = jindex[iidx];
139         j_index_end      = jindex[iidx+1];
140
141         /* Get outer coordinate index */
142         inr              = iinr[iidx];
143         i_coord_offset   = DIM*inr;
144
145         /* Load i particle coords and add shift vector */
146         ix0              = shX + x[i_coord_offset+DIM*0+XX];
147         iy0              = shY + x[i_coord_offset+DIM*0+YY];
148         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
149         ix1              = shX + x[i_coord_offset+DIM*1+XX];
150         iy1              = shY + x[i_coord_offset+DIM*1+YY];
151         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
152         ix2              = shX + x[i_coord_offset+DIM*2+XX];
153         iy2              = shY + x[i_coord_offset+DIM*2+YY];
154         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
155         ix3              = shX + x[i_coord_offset+DIM*3+XX];
156         iy3              = shY + x[i_coord_offset+DIM*3+YY];
157         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
158
159         fix0             = 0.0;
160         fiy0             = 0.0;
161         fiz0             = 0.0;
162         fix1             = 0.0;
163         fiy1             = 0.0;
164         fiz1             = 0.0;
165         fix2             = 0.0;
166         fiy2             = 0.0;
167         fiz2             = 0.0;
168         fix3             = 0.0;
169         fiy3             = 0.0;
170         fiz3             = 0.0;
171
172         /* Reset potential sums */
173         velecsum         = 0.0;
174         vvdwsum          = 0.0;
175
176         /* Start inner kernel loop */
177         for(jidx=j_index_start; jidx<j_index_end; jidx++)
178         {
179             /* Get j neighbor index, and coordinate index */
180             jnr              = jjnr[jidx];
181             j_coord_offset   = DIM*jnr;
182
183             /* load j atom coordinates */
184             jx0              = x[j_coord_offset+DIM*0+XX];
185             jy0              = x[j_coord_offset+DIM*0+YY];
186             jz0              = x[j_coord_offset+DIM*0+ZZ];
187
188             /* Calculate displacement vector */
189             dx00             = ix0 - jx0;
190             dy00             = iy0 - jy0;
191             dz00             = iz0 - jz0;
192             dx10             = ix1 - jx0;
193             dy10             = iy1 - jy0;
194             dz10             = iz1 - jz0;
195             dx20             = ix2 - jx0;
196             dy20             = iy2 - jy0;
197             dz20             = iz2 - jz0;
198             dx30             = ix3 - jx0;
199             dy30             = iy3 - jy0;
200             dz30             = iz3 - jz0;
201
202             /* Calculate squared distance and things based on it */
203             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
204             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
205             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
206             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
207
208             rinv10           = gmx_invsqrt(rsq10);
209             rinv20           = gmx_invsqrt(rsq20);
210             rinv30           = gmx_invsqrt(rsq30);
211
212             rinvsq00         = 1.0/rsq00;
213             rinvsq10         = rinv10*rinv10;
214             rinvsq20         = rinv20*rinv20;
215             rinvsq30         = rinv30*rinv30;
216
217             /* Load parameters for j particles */
218             jq0              = charge[jnr+0];
219             vdwjidx0         = 2*vdwtype[jnr+0];
220
221             /**************************
222              * CALCULATE INTERACTIONS *
223              **************************/
224
225             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
226             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
227
228             /* LENNARD-JONES DISPERSION/REPULSION */
229
230             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
231             vvdw6            = c6_00*rinvsix;
232             vvdw12           = c12_00*rinvsix*rinvsix;
233             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
234             fvdw             = (vvdw12-vvdw6)*rinvsq00;
235
236             /* Update potential sums from outer loop */
237             vvdwsum         += vvdw;
238
239             fscal            = fvdw;
240
241             /* Calculate temporary vectorial force */
242             tx               = fscal*dx00;
243             ty               = fscal*dy00;
244             tz               = fscal*dz00;
245
246             /* Update vectorial force */
247             fix0            += tx;
248             fiy0            += ty;
249             fiz0            += tz;
250             f[j_coord_offset+DIM*0+XX] -= tx;
251             f[j_coord_offset+DIM*0+YY] -= ty;
252             f[j_coord_offset+DIM*0+ZZ] -= tz;
253
254             /**************************
255              * CALCULATE INTERACTIONS *
256              **************************/
257
258             r10              = rsq10*rinv10;
259
260             qq10             = iq1*jq0;
261
262             /* EWALD ELECTROSTATICS */
263
264             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
265             ewrt             = r10*ewtabscale;
266             ewitab           = ewrt;
267             eweps            = ewrt-ewitab;
268             ewitab           = 4*ewitab;
269             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
270             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
271             felec            = qq10*rinv10*(rinvsq10-felec);
272
273             /* Update potential sums from outer loop */
274             velecsum        += velec;
275
276             fscal            = felec;
277
278             /* Calculate temporary vectorial force */
279             tx               = fscal*dx10;
280             ty               = fscal*dy10;
281             tz               = fscal*dz10;
282
283             /* Update vectorial force */
284             fix1            += tx;
285             fiy1            += ty;
286             fiz1            += tz;
287             f[j_coord_offset+DIM*0+XX] -= tx;
288             f[j_coord_offset+DIM*0+YY] -= ty;
289             f[j_coord_offset+DIM*0+ZZ] -= tz;
290
291             /**************************
292              * CALCULATE INTERACTIONS *
293              **************************/
294
295             r20              = rsq20*rinv20;
296
297             qq20             = iq2*jq0;
298
299             /* EWALD ELECTROSTATICS */
300
301             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
302             ewrt             = r20*ewtabscale;
303             ewitab           = ewrt;
304             eweps            = ewrt-ewitab;
305             ewitab           = 4*ewitab;
306             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
307             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
308             felec            = qq20*rinv20*(rinvsq20-felec);
309
310             /* Update potential sums from outer loop */
311             velecsum        += velec;
312
313             fscal            = felec;
314
315             /* Calculate temporary vectorial force */
316             tx               = fscal*dx20;
317             ty               = fscal*dy20;
318             tz               = fscal*dz20;
319
320             /* Update vectorial force */
321             fix2            += tx;
322             fiy2            += ty;
323             fiz2            += tz;
324             f[j_coord_offset+DIM*0+XX] -= tx;
325             f[j_coord_offset+DIM*0+YY] -= ty;
326             f[j_coord_offset+DIM*0+ZZ] -= tz;
327
328             /**************************
329              * CALCULATE INTERACTIONS *
330              **************************/
331
332             r30              = rsq30*rinv30;
333
334             qq30             = iq3*jq0;
335
336             /* EWALD ELECTROSTATICS */
337
338             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
339             ewrt             = r30*ewtabscale;
340             ewitab           = ewrt;
341             eweps            = ewrt-ewitab;
342             ewitab           = 4*ewitab;
343             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
344             velec            = qq30*(rinv30-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
345             felec            = qq30*rinv30*(rinvsq30-felec);
346
347             /* Update potential sums from outer loop */
348             velecsum        += velec;
349
350             fscal            = felec;
351
352             /* Calculate temporary vectorial force */
353             tx               = fscal*dx30;
354             ty               = fscal*dy30;
355             tz               = fscal*dz30;
356
357             /* Update vectorial force */
358             fix3            += tx;
359             fiy3            += ty;
360             fiz3            += tz;
361             f[j_coord_offset+DIM*0+XX] -= tx;
362             f[j_coord_offset+DIM*0+YY] -= ty;
363             f[j_coord_offset+DIM*0+ZZ] -= tz;
364
365             /* Inner loop uses 155 flops */
366         }
367         /* End of innermost loop */
368
369         tx = ty = tz = 0;
370         f[i_coord_offset+DIM*0+XX] += fix0;
371         f[i_coord_offset+DIM*0+YY] += fiy0;
372         f[i_coord_offset+DIM*0+ZZ] += fiz0;
373         tx                         += fix0;
374         ty                         += fiy0;
375         tz                         += fiz0;
376         f[i_coord_offset+DIM*1+XX] += fix1;
377         f[i_coord_offset+DIM*1+YY] += fiy1;
378         f[i_coord_offset+DIM*1+ZZ] += fiz1;
379         tx                         += fix1;
380         ty                         += fiy1;
381         tz                         += fiz1;
382         f[i_coord_offset+DIM*2+XX] += fix2;
383         f[i_coord_offset+DIM*2+YY] += fiy2;
384         f[i_coord_offset+DIM*2+ZZ] += fiz2;
385         tx                         += fix2;
386         ty                         += fiy2;
387         tz                         += fiz2;
388         f[i_coord_offset+DIM*3+XX] += fix3;
389         f[i_coord_offset+DIM*3+YY] += fiy3;
390         f[i_coord_offset+DIM*3+ZZ] += fiz3;
391         tx                         += fix3;
392         ty                         += fiy3;
393         tz                         += fiz3;
394         fshift[i_shift_offset+XX]  += tx;
395         fshift[i_shift_offset+YY]  += ty;
396         fshift[i_shift_offset+ZZ]  += tz;
397
398         ggid                        = gid[iidx];
399         /* Update potential energies */
400         kernel_data->energygrp_elec[ggid] += velecsum;
401         kernel_data->energygrp_vdw[ggid] += vvdwsum;
402
403         /* Increment number of inner iterations */
404         inneriter                  += j_index_end - j_index_start;
405
406         /* Outer loop uses 41 flops */
407     }
408
409     /* Increment number of outer iterations */
410     outeriter        += nri;
411
412     /* Update outer/inner flops */
413
414     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*155);
415 }
416 /*
417  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomW4P1_F_c
418  * Electrostatics interaction: Ewald
419  * VdW interaction:            LennardJones
420  * Geometry:                   Water4-Particle
421  * Calculate force/pot:        Force
422  */
423 void
424 nb_kernel_ElecEw_VdwLJ_GeomW4P1_F_c
425                     (t_nblist                    * gmx_restrict       nlist,
426                      rvec                        * gmx_restrict          xx,
427                      rvec                        * gmx_restrict          ff,
428                      t_forcerec                  * gmx_restrict          fr,
429                      t_mdatoms                   * gmx_restrict     mdatoms,
430                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
431                      t_nrnb                      * gmx_restrict        nrnb)
432 {
433     int              i_shift_offset,i_coord_offset,j_coord_offset;
434     int              j_index_start,j_index_end;
435     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
436     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
437     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
438     real             *shiftvec,*fshift,*x,*f;
439     int              vdwioffset0;
440     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
441     int              vdwioffset1;
442     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
443     int              vdwioffset2;
444     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
445     int              vdwioffset3;
446     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
447     int              vdwjidx0;
448     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
449     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
450     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
451     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
452     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
453     real             velec,felec,velecsum,facel,crf,krf,krf2;
454     real             *charge;
455     int              nvdwtype;
456     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
457     int              *vdwtype;
458     real             *vdwparam;
459     int              ewitab;
460     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
461     real             *ewtab;
462
463     x                = xx[0];
464     f                = ff[0];
465
466     nri              = nlist->nri;
467     iinr             = nlist->iinr;
468     jindex           = nlist->jindex;
469     jjnr             = nlist->jjnr;
470     shiftidx         = nlist->shift;
471     gid              = nlist->gid;
472     shiftvec         = fr->shift_vec[0];
473     fshift           = fr->fshift[0];
474     facel            = fr->epsfac;
475     charge           = mdatoms->chargeA;
476     nvdwtype         = fr->ntype;
477     vdwparam         = fr->nbfp;
478     vdwtype          = mdatoms->typeA;
479
480     sh_ewald         = fr->ic->sh_ewald;
481     ewtab            = fr->ic->tabq_coul_F;
482     ewtabscale       = fr->ic->tabq_scale;
483     ewtabhalfspace   = 0.5/ewtabscale;
484
485     /* Setup water-specific parameters */
486     inr              = nlist->iinr[0];
487     iq1              = facel*charge[inr+1];
488     iq2              = facel*charge[inr+2];
489     iq3              = facel*charge[inr+3];
490     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
491
492     outeriter        = 0;
493     inneriter        = 0;
494
495     /* Start outer loop over neighborlists */
496     for(iidx=0; iidx<nri; iidx++)
497     {
498         /* Load shift vector for this list */
499         i_shift_offset   = DIM*shiftidx[iidx];
500         shX              = shiftvec[i_shift_offset+XX];
501         shY              = shiftvec[i_shift_offset+YY];
502         shZ              = shiftvec[i_shift_offset+ZZ];
503
504         /* Load limits for loop over neighbors */
505         j_index_start    = jindex[iidx];
506         j_index_end      = jindex[iidx+1];
507
508         /* Get outer coordinate index */
509         inr              = iinr[iidx];
510         i_coord_offset   = DIM*inr;
511
512         /* Load i particle coords and add shift vector */
513         ix0              = shX + x[i_coord_offset+DIM*0+XX];
514         iy0              = shY + x[i_coord_offset+DIM*0+YY];
515         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
516         ix1              = shX + x[i_coord_offset+DIM*1+XX];
517         iy1              = shY + x[i_coord_offset+DIM*1+YY];
518         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
519         ix2              = shX + x[i_coord_offset+DIM*2+XX];
520         iy2              = shY + x[i_coord_offset+DIM*2+YY];
521         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
522         ix3              = shX + x[i_coord_offset+DIM*3+XX];
523         iy3              = shY + x[i_coord_offset+DIM*3+YY];
524         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
525
526         fix0             = 0.0;
527         fiy0             = 0.0;
528         fiz0             = 0.0;
529         fix1             = 0.0;
530         fiy1             = 0.0;
531         fiz1             = 0.0;
532         fix2             = 0.0;
533         fiy2             = 0.0;
534         fiz2             = 0.0;
535         fix3             = 0.0;
536         fiy3             = 0.0;
537         fiz3             = 0.0;
538
539         /* Start inner kernel loop */
540         for(jidx=j_index_start; jidx<j_index_end; jidx++)
541         {
542             /* Get j neighbor index, and coordinate index */
543             jnr              = jjnr[jidx];
544             j_coord_offset   = DIM*jnr;
545
546             /* load j atom coordinates */
547             jx0              = x[j_coord_offset+DIM*0+XX];
548             jy0              = x[j_coord_offset+DIM*0+YY];
549             jz0              = x[j_coord_offset+DIM*0+ZZ];
550
551             /* Calculate displacement vector */
552             dx00             = ix0 - jx0;
553             dy00             = iy0 - jy0;
554             dz00             = iz0 - jz0;
555             dx10             = ix1 - jx0;
556             dy10             = iy1 - jy0;
557             dz10             = iz1 - jz0;
558             dx20             = ix2 - jx0;
559             dy20             = iy2 - jy0;
560             dz20             = iz2 - jz0;
561             dx30             = ix3 - jx0;
562             dy30             = iy3 - jy0;
563             dz30             = iz3 - jz0;
564
565             /* Calculate squared distance and things based on it */
566             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
567             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
568             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
569             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
570
571             rinv10           = gmx_invsqrt(rsq10);
572             rinv20           = gmx_invsqrt(rsq20);
573             rinv30           = gmx_invsqrt(rsq30);
574
575             rinvsq00         = 1.0/rsq00;
576             rinvsq10         = rinv10*rinv10;
577             rinvsq20         = rinv20*rinv20;
578             rinvsq30         = rinv30*rinv30;
579
580             /* Load parameters for j particles */
581             jq0              = charge[jnr+0];
582             vdwjidx0         = 2*vdwtype[jnr+0];
583
584             /**************************
585              * CALCULATE INTERACTIONS *
586              **************************/
587
588             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
589             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
590
591             /* LENNARD-JONES DISPERSION/REPULSION */
592
593             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
594             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
595
596             fscal            = fvdw;
597
598             /* Calculate temporary vectorial force */
599             tx               = fscal*dx00;
600             ty               = fscal*dy00;
601             tz               = fscal*dz00;
602
603             /* Update vectorial force */
604             fix0            += tx;
605             fiy0            += ty;
606             fiz0            += tz;
607             f[j_coord_offset+DIM*0+XX] -= tx;
608             f[j_coord_offset+DIM*0+YY] -= ty;
609             f[j_coord_offset+DIM*0+ZZ] -= tz;
610
611             /**************************
612              * CALCULATE INTERACTIONS *
613              **************************/
614
615             r10              = rsq10*rinv10;
616
617             qq10             = iq1*jq0;
618
619             /* EWALD ELECTROSTATICS */
620
621             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
622             ewrt             = r10*ewtabscale;
623             ewitab           = ewrt;
624             eweps            = ewrt-ewitab;
625             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
626             felec            = qq10*rinv10*(rinvsq10-felec);
627
628             fscal            = felec;
629
630             /* Calculate temporary vectorial force */
631             tx               = fscal*dx10;
632             ty               = fscal*dy10;
633             tz               = fscal*dz10;
634
635             /* Update vectorial force */
636             fix1            += tx;
637             fiy1            += ty;
638             fiz1            += tz;
639             f[j_coord_offset+DIM*0+XX] -= tx;
640             f[j_coord_offset+DIM*0+YY] -= ty;
641             f[j_coord_offset+DIM*0+ZZ] -= tz;
642
643             /**************************
644              * CALCULATE INTERACTIONS *
645              **************************/
646
647             r20              = rsq20*rinv20;
648
649             qq20             = iq2*jq0;
650
651             /* EWALD ELECTROSTATICS */
652
653             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
654             ewrt             = r20*ewtabscale;
655             ewitab           = ewrt;
656             eweps            = ewrt-ewitab;
657             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
658             felec            = qq20*rinv20*(rinvsq20-felec);
659
660             fscal            = felec;
661
662             /* Calculate temporary vectorial force */
663             tx               = fscal*dx20;
664             ty               = fscal*dy20;
665             tz               = fscal*dz20;
666
667             /* Update vectorial force */
668             fix2            += tx;
669             fiy2            += ty;
670             fiz2            += tz;
671             f[j_coord_offset+DIM*0+XX] -= tx;
672             f[j_coord_offset+DIM*0+YY] -= ty;
673             f[j_coord_offset+DIM*0+ZZ] -= tz;
674
675             /**************************
676              * CALCULATE INTERACTIONS *
677              **************************/
678
679             r30              = rsq30*rinv30;
680
681             qq30             = iq3*jq0;
682
683             /* EWALD ELECTROSTATICS */
684
685             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
686             ewrt             = r30*ewtabscale;
687             ewitab           = ewrt;
688             eweps            = ewrt-ewitab;
689             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
690             felec            = qq30*rinv30*(rinvsq30-felec);
691
692             fscal            = felec;
693
694             /* Calculate temporary vectorial force */
695             tx               = fscal*dx30;
696             ty               = fscal*dy30;
697             tz               = fscal*dz30;
698
699             /* Update vectorial force */
700             fix3            += tx;
701             fiy3            += ty;
702             fiz3            += tz;
703             f[j_coord_offset+DIM*0+XX] -= tx;
704             f[j_coord_offset+DIM*0+YY] -= ty;
705             f[j_coord_offset+DIM*0+ZZ] -= tz;
706
707             /* Inner loop uses 129 flops */
708         }
709         /* End of innermost loop */
710
711         tx = ty = tz = 0;
712         f[i_coord_offset+DIM*0+XX] += fix0;
713         f[i_coord_offset+DIM*0+YY] += fiy0;
714         f[i_coord_offset+DIM*0+ZZ] += fiz0;
715         tx                         += fix0;
716         ty                         += fiy0;
717         tz                         += fiz0;
718         f[i_coord_offset+DIM*1+XX] += fix1;
719         f[i_coord_offset+DIM*1+YY] += fiy1;
720         f[i_coord_offset+DIM*1+ZZ] += fiz1;
721         tx                         += fix1;
722         ty                         += fiy1;
723         tz                         += fiz1;
724         f[i_coord_offset+DIM*2+XX] += fix2;
725         f[i_coord_offset+DIM*2+YY] += fiy2;
726         f[i_coord_offset+DIM*2+ZZ] += fiz2;
727         tx                         += fix2;
728         ty                         += fiy2;
729         tz                         += fiz2;
730         f[i_coord_offset+DIM*3+XX] += fix3;
731         f[i_coord_offset+DIM*3+YY] += fiy3;
732         f[i_coord_offset+DIM*3+ZZ] += fiz3;
733         tx                         += fix3;
734         ty                         += fiy3;
735         tz                         += fiz3;
736         fshift[i_shift_offset+XX]  += tx;
737         fshift[i_shift_offset+YY]  += ty;
738         fshift[i_shift_offset+ZZ]  += tz;
739
740         /* Increment number of inner iterations */
741         inneriter                  += j_index_end - j_index_start;
742
743         /* Outer loop uses 39 flops */
744     }
745
746     /* Increment number of outer iterations */
747     outeriter        += nri;
748
749     /* Update outer/inner flops */
750
751     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*129);
752 }