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