Remove no-inline-max-size and suppress remark
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEw_VdwBham_GeomW4P1_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013, 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 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "vec.h"
47 #include "nrnb.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwBham_GeomW4P1_VF_c
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            Buckingham
53  * Geometry:                   Water4-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEw_VdwBham_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      = 3*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             rinv00           = gmx_invsqrt(rsq00);
209             rinv10           = gmx_invsqrt(rsq10);
210             rinv20           = gmx_invsqrt(rsq20);
211             rinv30           = gmx_invsqrt(rsq30);
212
213             rinvsq00         = rinv00*rinv00;
214             rinvsq10         = rinv10*rinv10;
215             rinvsq20         = rinv20*rinv20;
216             rinvsq30         = rinv30*rinv30;
217
218             /* Load parameters for j particles */
219             jq0              = charge[jnr+0];
220             vdwjidx0         = 3*vdwtype[jnr+0];
221
222             /**************************
223              * CALCULATE INTERACTIONS *
224              **************************/
225
226             r00              = rsq00*rinv00;
227
228             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
229             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
230             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
231
232             /* BUCKINGHAM DISPERSION/REPULSION */
233             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
234             vvdw6            = c6_00*rinvsix;
235             br               = cexp2_00*r00;
236             vvdwexp          = cexp1_00*exp(-br);
237             vvdw             = vvdwexp - vvdw6*(1.0/6.0);
238             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
239
240             /* Update potential sums from outer loop */
241             vvdwsum         += vvdw;
242
243             fscal            = fvdw;
244
245             /* Calculate temporary vectorial force */
246             tx               = fscal*dx00;
247             ty               = fscal*dy00;
248             tz               = fscal*dz00;
249
250             /* Update vectorial force */
251             fix0            += tx;
252             fiy0            += ty;
253             fiz0            += tz;
254             f[j_coord_offset+DIM*0+XX] -= tx;
255             f[j_coord_offset+DIM*0+YY] -= ty;
256             f[j_coord_offset+DIM*0+ZZ] -= tz;
257
258             /**************************
259              * CALCULATE INTERACTIONS *
260              **************************/
261
262             r10              = rsq10*rinv10;
263
264             qq10             = iq1*jq0;
265
266             /* EWALD ELECTROSTATICS */
267
268             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
269             ewrt             = r10*ewtabscale;
270             ewitab           = ewrt;
271             eweps            = ewrt-ewitab;
272             ewitab           = 4*ewitab;
273             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
274             velec            = qq10*(rinv10-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
275             felec            = qq10*rinv10*(rinvsq10-felec);
276
277             /* Update potential sums from outer loop */
278             velecsum        += velec;
279
280             fscal            = felec;
281
282             /* Calculate temporary vectorial force */
283             tx               = fscal*dx10;
284             ty               = fscal*dy10;
285             tz               = fscal*dz10;
286
287             /* Update vectorial force */
288             fix1            += tx;
289             fiy1            += ty;
290             fiz1            += tz;
291             f[j_coord_offset+DIM*0+XX] -= tx;
292             f[j_coord_offset+DIM*0+YY] -= ty;
293             f[j_coord_offset+DIM*0+ZZ] -= tz;
294
295             /**************************
296              * CALCULATE INTERACTIONS *
297              **************************/
298
299             r20              = rsq20*rinv20;
300
301             qq20             = iq2*jq0;
302
303             /* EWALD ELECTROSTATICS */
304
305             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
306             ewrt             = r20*ewtabscale;
307             ewitab           = ewrt;
308             eweps            = ewrt-ewitab;
309             ewitab           = 4*ewitab;
310             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
311             velec            = qq20*(rinv20-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
312             felec            = qq20*rinv20*(rinvsq20-felec);
313
314             /* Update potential sums from outer loop */
315             velecsum        += velec;
316
317             fscal            = felec;
318
319             /* Calculate temporary vectorial force */
320             tx               = fscal*dx20;
321             ty               = fscal*dy20;
322             tz               = fscal*dz20;
323
324             /* Update vectorial force */
325             fix2            += tx;
326             fiy2            += ty;
327             fiz2            += tz;
328             f[j_coord_offset+DIM*0+XX] -= tx;
329             f[j_coord_offset+DIM*0+YY] -= ty;
330             f[j_coord_offset+DIM*0+ZZ] -= tz;
331
332             /**************************
333              * CALCULATE INTERACTIONS *
334              **************************/
335
336             r30              = rsq30*rinv30;
337
338             qq30             = iq3*jq0;
339
340             /* EWALD ELECTROSTATICS */
341
342             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
343             ewrt             = r30*ewtabscale;
344             ewitab           = ewrt;
345             eweps            = ewrt-ewitab;
346             ewitab           = 4*ewitab;
347             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
348             velec            = qq30*(rinv30-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
349             felec            = qq30*rinv30*(rinvsq30-felec);
350
351             /* Update potential sums from outer loop */
352             velecsum        += velec;
353
354             fscal            = felec;
355
356             /* Calculate temporary vectorial force */
357             tx               = fscal*dx30;
358             ty               = fscal*dy30;
359             tz               = fscal*dz30;
360
361             /* Update vectorial force */
362             fix3            += tx;
363             fiy3            += ty;
364             fiz3            += tz;
365             f[j_coord_offset+DIM*0+XX] -= tx;
366             f[j_coord_offset+DIM*0+YY] -= ty;
367             f[j_coord_offset+DIM*0+ZZ] -= tz;
368
369             /* Inner loop uses 184 flops */
370         }
371         /* End of innermost loop */
372
373         tx = ty = tz = 0;
374         f[i_coord_offset+DIM*0+XX] += fix0;
375         f[i_coord_offset+DIM*0+YY] += fiy0;
376         f[i_coord_offset+DIM*0+ZZ] += fiz0;
377         tx                         += fix0;
378         ty                         += fiy0;
379         tz                         += fiz0;
380         f[i_coord_offset+DIM*1+XX] += fix1;
381         f[i_coord_offset+DIM*1+YY] += fiy1;
382         f[i_coord_offset+DIM*1+ZZ] += fiz1;
383         tx                         += fix1;
384         ty                         += fiy1;
385         tz                         += fiz1;
386         f[i_coord_offset+DIM*2+XX] += fix2;
387         f[i_coord_offset+DIM*2+YY] += fiy2;
388         f[i_coord_offset+DIM*2+ZZ] += fiz2;
389         tx                         += fix2;
390         ty                         += fiy2;
391         tz                         += fiz2;
392         f[i_coord_offset+DIM*3+XX] += fix3;
393         f[i_coord_offset+DIM*3+YY] += fiy3;
394         f[i_coord_offset+DIM*3+ZZ] += fiz3;
395         tx                         += fix3;
396         ty                         += fiy3;
397         tz                         += fiz3;
398         fshift[i_shift_offset+XX]  += tx;
399         fshift[i_shift_offset+YY]  += ty;
400         fshift[i_shift_offset+ZZ]  += tz;
401
402         ggid                        = gid[iidx];
403         /* Update potential energies */
404         kernel_data->energygrp_elec[ggid] += velecsum;
405         kernel_data->energygrp_vdw[ggid] += vvdwsum;
406
407         /* Increment number of inner iterations */
408         inneriter                  += j_index_end - j_index_start;
409
410         /* Outer loop uses 41 flops */
411     }
412
413     /* Increment number of outer iterations */
414     outeriter        += nri;
415
416     /* Update outer/inner flops */
417
418     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*184);
419 }
420 /*
421  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwBham_GeomW4P1_F_c
422  * Electrostatics interaction: Ewald
423  * VdW interaction:            Buckingham
424  * Geometry:                   Water4-Particle
425  * Calculate force/pot:        Force
426  */
427 void
428 nb_kernel_ElecEw_VdwBham_GeomW4P1_F_c
429                     (t_nblist                    * gmx_restrict       nlist,
430                      rvec                        * gmx_restrict          xx,
431                      rvec                        * gmx_restrict          ff,
432                      t_forcerec                  * gmx_restrict          fr,
433                      t_mdatoms                   * gmx_restrict     mdatoms,
434                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
435                      t_nrnb                      * gmx_restrict        nrnb)
436 {
437     int              i_shift_offset,i_coord_offset,j_coord_offset;
438     int              j_index_start,j_index_end;
439     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
440     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
441     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
442     real             *shiftvec,*fshift,*x,*f;
443     int              vdwioffset0;
444     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
445     int              vdwioffset1;
446     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
447     int              vdwioffset2;
448     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
449     int              vdwioffset3;
450     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
451     int              vdwjidx0;
452     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
453     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
454     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
455     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
456     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
457     real             velec,felec,velecsum,facel,crf,krf,krf2;
458     real             *charge;
459     int              nvdwtype;
460     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
461     int              *vdwtype;
462     real             *vdwparam;
463     int              ewitab;
464     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
465     real             *ewtab;
466
467     x                = xx[0];
468     f                = ff[0];
469
470     nri              = nlist->nri;
471     iinr             = nlist->iinr;
472     jindex           = nlist->jindex;
473     jjnr             = nlist->jjnr;
474     shiftidx         = nlist->shift;
475     gid              = nlist->gid;
476     shiftvec         = fr->shift_vec[0];
477     fshift           = fr->fshift[0];
478     facel            = fr->epsfac;
479     charge           = mdatoms->chargeA;
480     nvdwtype         = fr->ntype;
481     vdwparam         = fr->nbfp;
482     vdwtype          = mdatoms->typeA;
483
484     sh_ewald         = fr->ic->sh_ewald;
485     ewtab            = fr->ic->tabq_coul_F;
486     ewtabscale       = fr->ic->tabq_scale;
487     ewtabhalfspace   = 0.5/ewtabscale;
488
489     /* Setup water-specific parameters */
490     inr              = nlist->iinr[0];
491     iq1              = facel*charge[inr+1];
492     iq2              = facel*charge[inr+2];
493     iq3              = facel*charge[inr+3];
494     vdwioffset0      = 3*nvdwtype*vdwtype[inr+0];
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         ix3              = shX + x[i_coord_offset+DIM*3+XX];
527         iy3              = shY + x[i_coord_offset+DIM*3+YY];
528         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
529
530         fix0             = 0.0;
531         fiy0             = 0.0;
532         fiz0             = 0.0;
533         fix1             = 0.0;
534         fiy1             = 0.0;
535         fiz1             = 0.0;
536         fix2             = 0.0;
537         fiy2             = 0.0;
538         fiz2             = 0.0;
539         fix3             = 0.0;
540         fiy3             = 0.0;
541         fiz3             = 0.0;
542
543         /* Start inner kernel loop */
544         for(jidx=j_index_start; jidx<j_index_end; jidx++)
545         {
546             /* Get j neighbor index, and coordinate index */
547             jnr              = jjnr[jidx];
548             j_coord_offset   = DIM*jnr;
549
550             /* load j atom coordinates */
551             jx0              = x[j_coord_offset+DIM*0+XX];
552             jy0              = x[j_coord_offset+DIM*0+YY];
553             jz0              = x[j_coord_offset+DIM*0+ZZ];
554
555             /* Calculate displacement vector */
556             dx00             = ix0 - jx0;
557             dy00             = iy0 - jy0;
558             dz00             = iz0 - jz0;
559             dx10             = ix1 - jx0;
560             dy10             = iy1 - jy0;
561             dz10             = iz1 - jz0;
562             dx20             = ix2 - jx0;
563             dy20             = iy2 - jy0;
564             dz20             = iz2 - jz0;
565             dx30             = ix3 - jx0;
566             dy30             = iy3 - jy0;
567             dz30             = iz3 - jz0;
568
569             /* Calculate squared distance and things based on it */
570             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
571             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
572             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
573             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
574
575             rinv00           = gmx_invsqrt(rsq00);
576             rinv10           = gmx_invsqrt(rsq10);
577             rinv20           = gmx_invsqrt(rsq20);
578             rinv30           = gmx_invsqrt(rsq30);
579
580             rinvsq00         = rinv00*rinv00;
581             rinvsq10         = rinv10*rinv10;
582             rinvsq20         = rinv20*rinv20;
583             rinvsq30         = rinv30*rinv30;
584
585             /* Load parameters for j particles */
586             jq0              = charge[jnr+0];
587             vdwjidx0         = 3*vdwtype[jnr+0];
588
589             /**************************
590              * CALCULATE INTERACTIONS *
591              **************************/
592
593             r00              = rsq00*rinv00;
594
595             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
596             cexp1_00         = vdwparam[vdwioffset0+vdwjidx0+1];
597             cexp2_00         = vdwparam[vdwioffset0+vdwjidx0+2];
598
599             /* BUCKINGHAM DISPERSION/REPULSION */
600             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
601             vvdw6            = c6_00*rinvsix;
602             br               = cexp2_00*r00;
603             vvdwexp          = cexp1_00*exp(-br);
604             fvdw             = (br*vvdwexp-vvdw6)*rinvsq00;
605
606             fscal            = 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              * CALCULATE INTERACTIONS *
623              **************************/
624
625             r10              = rsq10*rinv10;
626
627             qq10             = iq1*jq0;
628
629             /* EWALD ELECTROSTATICS */
630
631             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
632             ewrt             = r10*ewtabscale;
633             ewitab           = ewrt;
634             eweps            = ewrt-ewitab;
635             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
636             felec            = qq10*rinv10*(rinvsq10-felec);
637
638             fscal            = felec;
639
640             /* Calculate temporary vectorial force */
641             tx               = fscal*dx10;
642             ty               = fscal*dy10;
643             tz               = fscal*dz10;
644
645             /* Update vectorial force */
646             fix1            += tx;
647             fiy1            += ty;
648             fiz1            += tz;
649             f[j_coord_offset+DIM*0+XX] -= tx;
650             f[j_coord_offset+DIM*0+YY] -= ty;
651             f[j_coord_offset+DIM*0+ZZ] -= tz;
652
653             /**************************
654              * CALCULATE INTERACTIONS *
655              **************************/
656
657             r20              = rsq20*rinv20;
658
659             qq20             = iq2*jq0;
660
661             /* EWALD ELECTROSTATICS */
662
663             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
664             ewrt             = r20*ewtabscale;
665             ewitab           = ewrt;
666             eweps            = ewrt-ewitab;
667             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
668             felec            = qq20*rinv20*(rinvsq20-felec);
669
670             fscal            = felec;
671
672             /* Calculate temporary vectorial force */
673             tx               = fscal*dx20;
674             ty               = fscal*dy20;
675             tz               = fscal*dz20;
676
677             /* Update vectorial force */
678             fix2            += tx;
679             fiy2            += ty;
680             fiz2            += tz;
681             f[j_coord_offset+DIM*0+XX] -= tx;
682             f[j_coord_offset+DIM*0+YY] -= ty;
683             f[j_coord_offset+DIM*0+ZZ] -= tz;
684
685             /**************************
686              * CALCULATE INTERACTIONS *
687              **************************/
688
689             r30              = rsq30*rinv30;
690
691             qq30             = iq3*jq0;
692
693             /* EWALD ELECTROSTATICS */
694
695             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
696             ewrt             = r30*ewtabscale;
697             ewitab           = ewrt;
698             eweps            = ewrt-ewitab;
699             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
700             felec            = qq30*rinv30*(rinvsq30-felec);
701
702             fscal            = felec;
703
704             /* Calculate temporary vectorial force */
705             tx               = fscal*dx30;
706             ty               = fscal*dy30;
707             tz               = fscal*dz30;
708
709             /* Update vectorial force */
710             fix3            += tx;
711             fiy3            += ty;
712             fiz3            += tz;
713             f[j_coord_offset+DIM*0+XX] -= tx;
714             f[j_coord_offset+DIM*0+YY] -= ty;
715             f[j_coord_offset+DIM*0+ZZ] -= tz;
716
717             /* Inner loop uses 160 flops */
718         }
719         /* End of innermost loop */
720
721         tx = ty = tz = 0;
722         f[i_coord_offset+DIM*0+XX] += fix0;
723         f[i_coord_offset+DIM*0+YY] += fiy0;
724         f[i_coord_offset+DIM*0+ZZ] += fiz0;
725         tx                         += fix0;
726         ty                         += fiy0;
727         tz                         += fiz0;
728         f[i_coord_offset+DIM*1+XX] += fix1;
729         f[i_coord_offset+DIM*1+YY] += fiy1;
730         f[i_coord_offset+DIM*1+ZZ] += fiz1;
731         tx                         += fix1;
732         ty                         += fiy1;
733         tz                         += fiz1;
734         f[i_coord_offset+DIM*2+XX] += fix2;
735         f[i_coord_offset+DIM*2+YY] += fiy2;
736         f[i_coord_offset+DIM*2+ZZ] += fiz2;
737         tx                         += fix2;
738         ty                         += fiy2;
739         tz                         += fiz2;
740         f[i_coord_offset+DIM*3+XX] += fix3;
741         f[i_coord_offset+DIM*3+YY] += fiy3;
742         f[i_coord_offset+DIM*3+ZZ] += fiz3;
743         tx                         += fix3;
744         ty                         += fiy3;
745         tz                         += fiz3;
746         fshift[i_shift_offset+XX]  += tx;
747         fshift[i_shift_offset+YY]  += ty;
748         fshift[i_shift_offset+ZZ]  += tz;
749
750         /* Increment number of inner iterations */
751         inneriter                  += j_index_end - j_index_start;
752
753         /* Outer loop uses 39 flops */
754     }
755
756     /* Increment number of outer iterations */
757     outeriter        += nri;
758
759     /* Update outer/inner flops */
760
761     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*160);
762 }