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