7e06ab8554aed3c3844c95aa1f1dd9cd1e167241
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEwSh_VdwLJSh_GeomW3W3_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_ElecEwSh_VdwLJSh_GeomW3W3_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            LennardJones
51  * Geometry:                   Water3-Water3
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEwSh_VdwLJSh_GeomW3W3_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     int              vdwjidx1;
79     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
80     int              vdwjidx2;
81     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
82     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
83     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
84     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
85     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
86     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
87     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
88     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
89     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
90     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
91     real             velec,felec,velecsum,facel,crf,krf,krf2;
92     real             *charge;
93     int              nvdwtype;
94     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
95     int              *vdwtype;
96     real             *vdwparam;
97     int              ewitab;
98     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
99     real             *ewtab;
100
101     x                = xx[0];
102     f                = ff[0];
103
104     nri              = nlist->nri;
105     iinr             = nlist->iinr;
106     jindex           = nlist->jindex;
107     jjnr             = nlist->jjnr;
108     shiftidx         = nlist->shift;
109     gid              = nlist->gid;
110     shiftvec         = fr->shift_vec[0];
111     fshift           = fr->fshift[0];
112     facel            = fr->epsfac;
113     charge           = mdatoms->chargeA;
114     nvdwtype         = fr->ntype;
115     vdwparam         = fr->nbfp;
116     vdwtype          = mdatoms->typeA;
117
118     sh_ewald         = fr->ic->sh_ewald;
119     ewtab            = fr->ic->tabq_coul_FDV0;
120     ewtabscale       = fr->ic->tabq_scale;
121     ewtabhalfspace   = 0.5/ewtabscale;
122
123     /* Setup water-specific parameters */
124     inr              = nlist->iinr[0];
125     iq0              = facel*charge[inr+0];
126     iq1              = facel*charge[inr+1];
127     iq2              = facel*charge[inr+2];
128     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
129
130     jq0              = charge[inr+0];
131     jq1              = charge[inr+1];
132     jq2              = charge[inr+2];
133     vdwjidx0         = 2*vdwtype[inr+0];
134     qq00             = iq0*jq0;
135     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
136     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
137     qq01             = iq0*jq1;
138     qq02             = iq0*jq2;
139     qq10             = iq1*jq0;
140     qq11             = iq1*jq1;
141     qq12             = iq1*jq2;
142     qq20             = iq2*jq0;
143     qq21             = iq2*jq1;
144     qq22             = iq2*jq2;
145
146     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
147     rcutoff          = fr->rcoulomb;
148     rcutoff2         = rcutoff*rcutoff;
149
150     sh_vdw_invrcut6  = fr->ic->sh_invrc6;
151     rvdw             = fr->rvdw;
152
153     outeriter        = 0;
154     inneriter        = 0;
155
156     /* Start outer loop over neighborlists */
157     for(iidx=0; iidx<nri; iidx++)
158     {
159         /* Load shift vector for this list */
160         i_shift_offset   = DIM*shiftidx[iidx];
161         shX              = shiftvec[i_shift_offset+XX];
162         shY              = shiftvec[i_shift_offset+YY];
163         shZ              = shiftvec[i_shift_offset+ZZ];
164
165         /* Load limits for loop over neighbors */
166         j_index_start    = jindex[iidx];
167         j_index_end      = jindex[iidx+1];
168
169         /* Get outer coordinate index */
170         inr              = iinr[iidx];
171         i_coord_offset   = DIM*inr;
172
173         /* Load i particle coords and add shift vector */
174         ix0              = shX + x[i_coord_offset+DIM*0+XX];
175         iy0              = shY + x[i_coord_offset+DIM*0+YY];
176         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
177         ix1              = shX + x[i_coord_offset+DIM*1+XX];
178         iy1              = shY + x[i_coord_offset+DIM*1+YY];
179         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
180         ix2              = shX + x[i_coord_offset+DIM*2+XX];
181         iy2              = shY + x[i_coord_offset+DIM*2+YY];
182         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
183
184         fix0             = 0.0;
185         fiy0             = 0.0;
186         fiz0             = 0.0;
187         fix1             = 0.0;
188         fiy1             = 0.0;
189         fiz1             = 0.0;
190         fix2             = 0.0;
191         fiy2             = 0.0;
192         fiz2             = 0.0;
193
194         /* Reset potential sums */
195         velecsum         = 0.0;
196         vvdwsum          = 0.0;
197
198         /* Start inner kernel loop */
199         for(jidx=j_index_start; jidx<j_index_end; jidx++)
200         {
201             /* Get j neighbor index, and coordinate index */
202             jnr              = jjnr[jidx];
203             j_coord_offset   = DIM*jnr;
204
205             /* load j atom coordinates */
206             jx0              = x[j_coord_offset+DIM*0+XX];
207             jy0              = x[j_coord_offset+DIM*0+YY];
208             jz0              = x[j_coord_offset+DIM*0+ZZ];
209             jx1              = x[j_coord_offset+DIM*1+XX];
210             jy1              = x[j_coord_offset+DIM*1+YY];
211             jz1              = x[j_coord_offset+DIM*1+ZZ];
212             jx2              = x[j_coord_offset+DIM*2+XX];
213             jy2              = x[j_coord_offset+DIM*2+YY];
214             jz2              = x[j_coord_offset+DIM*2+ZZ];
215
216             /* Calculate displacement vector */
217             dx00             = ix0 - jx0;
218             dy00             = iy0 - jy0;
219             dz00             = iz0 - jz0;
220             dx01             = ix0 - jx1;
221             dy01             = iy0 - jy1;
222             dz01             = iz0 - jz1;
223             dx02             = ix0 - jx2;
224             dy02             = iy0 - jy2;
225             dz02             = iz0 - jz2;
226             dx10             = ix1 - jx0;
227             dy10             = iy1 - jy0;
228             dz10             = iz1 - jz0;
229             dx11             = ix1 - jx1;
230             dy11             = iy1 - jy1;
231             dz11             = iz1 - jz1;
232             dx12             = ix1 - jx2;
233             dy12             = iy1 - jy2;
234             dz12             = iz1 - jz2;
235             dx20             = ix2 - jx0;
236             dy20             = iy2 - jy0;
237             dz20             = iz2 - jz0;
238             dx21             = ix2 - jx1;
239             dy21             = iy2 - jy1;
240             dz21             = iz2 - jz1;
241             dx22             = ix2 - jx2;
242             dy22             = iy2 - jy2;
243             dz22             = iz2 - jz2;
244
245             /* Calculate squared distance and things based on it */
246             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
247             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
248             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
249             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
250             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
251             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
252             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
253             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
254             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
255
256             rinv00           = gmx_invsqrt(rsq00);
257             rinv01           = gmx_invsqrt(rsq01);
258             rinv02           = gmx_invsqrt(rsq02);
259             rinv10           = gmx_invsqrt(rsq10);
260             rinv11           = gmx_invsqrt(rsq11);
261             rinv12           = gmx_invsqrt(rsq12);
262             rinv20           = gmx_invsqrt(rsq20);
263             rinv21           = gmx_invsqrt(rsq21);
264             rinv22           = gmx_invsqrt(rsq22);
265
266             rinvsq00         = rinv00*rinv00;
267             rinvsq01         = rinv01*rinv01;
268             rinvsq02         = rinv02*rinv02;
269             rinvsq10         = rinv10*rinv10;
270             rinvsq11         = rinv11*rinv11;
271             rinvsq12         = rinv12*rinv12;
272             rinvsq20         = rinv20*rinv20;
273             rinvsq21         = rinv21*rinv21;
274             rinvsq22         = rinv22*rinv22;
275
276             /**************************
277              * CALCULATE INTERACTIONS *
278              **************************/
279
280             if (rsq00<rcutoff2)
281             {
282
283             r00              = rsq00*rinv00;
284
285             /* EWALD ELECTROSTATICS */
286
287             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
288             ewrt             = r00*ewtabscale;
289             ewitab           = ewrt;
290             eweps            = ewrt-ewitab;
291             ewitab           = 4*ewitab;
292             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
293             velec            = qq00*((rinv00-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
294             felec            = qq00*rinv00*(rinvsq00-felec);
295
296             /* LENNARD-JONES DISPERSION/REPULSION */
297
298             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
299             vvdw6            = c6_00*rinvsix;
300             vvdw12           = c12_00*rinvsix*rinvsix;
301             vvdw             = (vvdw12 - c12_00*sh_vdw_invrcut6*sh_vdw_invrcut6)*(1.0/12.0) - (vvdw6 - c6_00*sh_vdw_invrcut6)*(1.0/6.0);
302             fvdw             = (vvdw12-vvdw6)*rinvsq00;
303
304             /* Update potential sums from outer loop */
305             velecsum        += velec;
306             vvdwsum         += vvdw;
307
308             fscal            = felec+fvdw;
309
310             /* Calculate temporary vectorial force */
311             tx               = fscal*dx00;
312             ty               = fscal*dy00;
313             tz               = fscal*dz00;
314
315             /* Update vectorial force */
316             fix0            += tx;
317             fiy0            += ty;
318             fiz0            += tz;
319             f[j_coord_offset+DIM*0+XX] -= tx;
320             f[j_coord_offset+DIM*0+YY] -= ty;
321             f[j_coord_offset+DIM*0+ZZ] -= tz;
322
323             }
324
325             /**************************
326              * CALCULATE INTERACTIONS *
327              **************************/
328
329             if (rsq01<rcutoff2)
330             {
331
332             r01              = rsq01*rinv01;
333
334             /* EWALD ELECTROSTATICS */
335
336             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
337             ewrt             = r01*ewtabscale;
338             ewitab           = ewrt;
339             eweps            = ewrt-ewitab;
340             ewitab           = 4*ewitab;
341             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
342             velec            = qq01*((rinv01-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
343             felec            = qq01*rinv01*(rinvsq01-felec);
344
345             /* Update potential sums from outer loop */
346             velecsum        += velec;
347
348             fscal            = felec;
349
350             /* Calculate temporary vectorial force */
351             tx               = fscal*dx01;
352             ty               = fscal*dy01;
353             tz               = fscal*dz01;
354
355             /* Update vectorial force */
356             fix0            += tx;
357             fiy0            += ty;
358             fiz0            += tz;
359             f[j_coord_offset+DIM*1+XX] -= tx;
360             f[j_coord_offset+DIM*1+YY] -= ty;
361             f[j_coord_offset+DIM*1+ZZ] -= tz;
362
363             }
364
365             /**************************
366              * CALCULATE INTERACTIONS *
367              **************************/
368
369             if (rsq02<rcutoff2)
370             {
371
372             r02              = rsq02*rinv02;
373
374             /* EWALD ELECTROSTATICS */
375
376             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
377             ewrt             = r02*ewtabscale;
378             ewitab           = ewrt;
379             eweps            = ewrt-ewitab;
380             ewitab           = 4*ewitab;
381             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
382             velec            = qq02*((rinv02-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
383             felec            = qq02*rinv02*(rinvsq02-felec);
384
385             /* Update potential sums from outer loop */
386             velecsum        += velec;
387
388             fscal            = felec;
389
390             /* Calculate temporary vectorial force */
391             tx               = fscal*dx02;
392             ty               = fscal*dy02;
393             tz               = fscal*dz02;
394
395             /* Update vectorial force */
396             fix0            += tx;
397             fiy0            += ty;
398             fiz0            += tz;
399             f[j_coord_offset+DIM*2+XX] -= tx;
400             f[j_coord_offset+DIM*2+YY] -= ty;
401             f[j_coord_offset+DIM*2+ZZ] -= tz;
402
403             }
404
405             /**************************
406              * CALCULATE INTERACTIONS *
407              **************************/
408
409             if (rsq10<rcutoff2)
410             {
411
412             r10              = rsq10*rinv10;
413
414             /* EWALD ELECTROSTATICS */
415
416             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
417             ewrt             = r10*ewtabscale;
418             ewitab           = ewrt;
419             eweps            = ewrt-ewitab;
420             ewitab           = 4*ewitab;
421             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
422             velec            = qq10*((rinv10-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
423             felec            = qq10*rinv10*(rinvsq10-felec);
424
425             /* Update potential sums from outer loop */
426             velecsum        += velec;
427
428             fscal            = felec;
429
430             /* Calculate temporary vectorial force */
431             tx               = fscal*dx10;
432             ty               = fscal*dy10;
433             tz               = fscal*dz10;
434
435             /* Update vectorial force */
436             fix1            += tx;
437             fiy1            += ty;
438             fiz1            += tz;
439             f[j_coord_offset+DIM*0+XX] -= tx;
440             f[j_coord_offset+DIM*0+YY] -= ty;
441             f[j_coord_offset+DIM*0+ZZ] -= tz;
442
443             }
444
445             /**************************
446              * CALCULATE INTERACTIONS *
447              **************************/
448
449             if (rsq11<rcutoff2)
450             {
451
452             r11              = rsq11*rinv11;
453
454             /* EWALD ELECTROSTATICS */
455
456             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
457             ewrt             = r11*ewtabscale;
458             ewitab           = ewrt;
459             eweps            = ewrt-ewitab;
460             ewitab           = 4*ewitab;
461             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
462             velec            = qq11*((rinv11-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
463             felec            = qq11*rinv11*(rinvsq11-felec);
464
465             /* Update potential sums from outer loop */
466             velecsum        += velec;
467
468             fscal            = felec;
469
470             /* Calculate temporary vectorial force */
471             tx               = fscal*dx11;
472             ty               = fscal*dy11;
473             tz               = fscal*dz11;
474
475             /* Update vectorial force */
476             fix1            += tx;
477             fiy1            += ty;
478             fiz1            += tz;
479             f[j_coord_offset+DIM*1+XX] -= tx;
480             f[j_coord_offset+DIM*1+YY] -= ty;
481             f[j_coord_offset+DIM*1+ZZ] -= tz;
482
483             }
484
485             /**************************
486              * CALCULATE INTERACTIONS *
487              **************************/
488
489             if (rsq12<rcutoff2)
490             {
491
492             r12              = rsq12*rinv12;
493
494             /* EWALD ELECTROSTATICS */
495
496             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
497             ewrt             = r12*ewtabscale;
498             ewitab           = ewrt;
499             eweps            = ewrt-ewitab;
500             ewitab           = 4*ewitab;
501             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
502             velec            = qq12*((rinv12-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
503             felec            = qq12*rinv12*(rinvsq12-felec);
504
505             /* Update potential sums from outer loop */
506             velecsum        += velec;
507
508             fscal            = felec;
509
510             /* Calculate temporary vectorial force */
511             tx               = fscal*dx12;
512             ty               = fscal*dy12;
513             tz               = fscal*dz12;
514
515             /* Update vectorial force */
516             fix1            += tx;
517             fiy1            += ty;
518             fiz1            += tz;
519             f[j_coord_offset+DIM*2+XX] -= tx;
520             f[j_coord_offset+DIM*2+YY] -= ty;
521             f[j_coord_offset+DIM*2+ZZ] -= tz;
522
523             }
524
525             /**************************
526              * CALCULATE INTERACTIONS *
527              **************************/
528
529             if (rsq20<rcutoff2)
530             {
531
532             r20              = rsq20*rinv20;
533
534             /* EWALD ELECTROSTATICS */
535
536             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
537             ewrt             = r20*ewtabscale;
538             ewitab           = ewrt;
539             eweps            = ewrt-ewitab;
540             ewitab           = 4*ewitab;
541             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
542             velec            = qq20*((rinv20-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
543             felec            = qq20*rinv20*(rinvsq20-felec);
544
545             /* Update potential sums from outer loop */
546             velecsum        += velec;
547
548             fscal            = felec;
549
550             /* Calculate temporary vectorial force */
551             tx               = fscal*dx20;
552             ty               = fscal*dy20;
553             tz               = fscal*dz20;
554
555             /* Update vectorial force */
556             fix2            += tx;
557             fiy2            += ty;
558             fiz2            += tz;
559             f[j_coord_offset+DIM*0+XX] -= tx;
560             f[j_coord_offset+DIM*0+YY] -= ty;
561             f[j_coord_offset+DIM*0+ZZ] -= tz;
562
563             }
564
565             /**************************
566              * CALCULATE INTERACTIONS *
567              **************************/
568
569             if (rsq21<rcutoff2)
570             {
571
572             r21              = rsq21*rinv21;
573
574             /* EWALD ELECTROSTATICS */
575
576             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
577             ewrt             = r21*ewtabscale;
578             ewitab           = ewrt;
579             eweps            = ewrt-ewitab;
580             ewitab           = 4*ewitab;
581             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
582             velec            = qq21*((rinv21-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
583             felec            = qq21*rinv21*(rinvsq21-felec);
584
585             /* Update potential sums from outer loop */
586             velecsum        += velec;
587
588             fscal            = felec;
589
590             /* Calculate temporary vectorial force */
591             tx               = fscal*dx21;
592             ty               = fscal*dy21;
593             tz               = fscal*dz21;
594
595             /* Update vectorial force */
596             fix2            += tx;
597             fiy2            += ty;
598             fiz2            += tz;
599             f[j_coord_offset+DIM*1+XX] -= tx;
600             f[j_coord_offset+DIM*1+YY] -= ty;
601             f[j_coord_offset+DIM*1+ZZ] -= tz;
602
603             }
604
605             /**************************
606              * CALCULATE INTERACTIONS *
607              **************************/
608
609             if (rsq22<rcutoff2)
610             {
611
612             r22              = rsq22*rinv22;
613
614             /* EWALD ELECTROSTATICS */
615
616             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
617             ewrt             = r22*ewtabscale;
618             ewitab           = ewrt;
619             eweps            = ewrt-ewitab;
620             ewitab           = 4*ewitab;
621             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
622             velec            = qq22*((rinv22-sh_ewald)-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
623             felec            = qq22*rinv22*(rinvsq22-felec);
624
625             /* Update potential sums from outer loop */
626             velecsum        += velec;
627
628             fscal            = felec;
629
630             /* Calculate temporary vectorial force */
631             tx               = fscal*dx22;
632             ty               = fscal*dy22;
633             tz               = fscal*dz22;
634
635             /* Update vectorial force */
636             fix2            += tx;
637             fiy2            += ty;
638             fiz2            += tz;
639             f[j_coord_offset+DIM*2+XX] -= tx;
640             f[j_coord_offset+DIM*2+YY] -= ty;
641             f[j_coord_offset+DIM*2+ZZ] -= tz;
642
643             }
644
645             /* Inner loop uses 386 flops */
646         }
647         /* End of innermost loop */
648
649         tx = ty = tz = 0;
650         f[i_coord_offset+DIM*0+XX] += fix0;
651         f[i_coord_offset+DIM*0+YY] += fiy0;
652         f[i_coord_offset+DIM*0+ZZ] += fiz0;
653         tx                         += fix0;
654         ty                         += fiy0;
655         tz                         += fiz0;
656         f[i_coord_offset+DIM*1+XX] += fix1;
657         f[i_coord_offset+DIM*1+YY] += fiy1;
658         f[i_coord_offset+DIM*1+ZZ] += fiz1;
659         tx                         += fix1;
660         ty                         += fiy1;
661         tz                         += fiz1;
662         f[i_coord_offset+DIM*2+XX] += fix2;
663         f[i_coord_offset+DIM*2+YY] += fiy2;
664         f[i_coord_offset+DIM*2+ZZ] += fiz2;
665         tx                         += fix2;
666         ty                         += fiy2;
667         tz                         += fiz2;
668         fshift[i_shift_offset+XX]  += tx;
669         fshift[i_shift_offset+YY]  += ty;
670         fshift[i_shift_offset+ZZ]  += tz;
671
672         ggid                        = gid[iidx];
673         /* Update potential energies */
674         kernel_data->energygrp_elec[ggid] += velecsum;
675         kernel_data->energygrp_vdw[ggid] += vvdwsum;
676
677         /* Increment number of inner iterations */
678         inneriter                  += j_index_end - j_index_start;
679
680         /* Outer loop uses 32 flops */
681     }
682
683     /* Increment number of outer iterations */
684     outeriter        += nri;
685
686     /* Update outer/inner flops */
687
688     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*32 + inneriter*386);
689 }
690 /*
691  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomW3W3_F_c
692  * Electrostatics interaction: Ewald
693  * VdW interaction:            LennardJones
694  * Geometry:                   Water3-Water3
695  * Calculate force/pot:        Force
696  */
697 void
698 nb_kernel_ElecEwSh_VdwLJSh_GeomW3W3_F_c
699                     (t_nblist                    * gmx_restrict       nlist,
700                      rvec                        * gmx_restrict          xx,
701                      rvec                        * gmx_restrict          ff,
702                      t_forcerec                  * gmx_restrict          fr,
703                      t_mdatoms                   * gmx_restrict     mdatoms,
704                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
705                      t_nrnb                      * gmx_restrict        nrnb)
706 {
707     int              i_shift_offset,i_coord_offset,j_coord_offset;
708     int              j_index_start,j_index_end;
709     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
710     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
711     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
712     real             *shiftvec,*fshift,*x,*f;
713     int              vdwioffset0;
714     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
715     int              vdwioffset1;
716     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
717     int              vdwioffset2;
718     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
719     int              vdwjidx0;
720     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
721     int              vdwjidx1;
722     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
723     int              vdwjidx2;
724     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
725     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
726     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
727     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
728     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
729     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
730     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
731     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
732     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
733     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
734     real             velec,felec,velecsum,facel,crf,krf,krf2;
735     real             *charge;
736     int              nvdwtype;
737     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
738     int              *vdwtype;
739     real             *vdwparam;
740     int              ewitab;
741     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
742     real             *ewtab;
743
744     x                = xx[0];
745     f                = ff[0];
746
747     nri              = nlist->nri;
748     iinr             = nlist->iinr;
749     jindex           = nlist->jindex;
750     jjnr             = nlist->jjnr;
751     shiftidx         = nlist->shift;
752     gid              = nlist->gid;
753     shiftvec         = fr->shift_vec[0];
754     fshift           = fr->fshift[0];
755     facel            = fr->epsfac;
756     charge           = mdatoms->chargeA;
757     nvdwtype         = fr->ntype;
758     vdwparam         = fr->nbfp;
759     vdwtype          = mdatoms->typeA;
760
761     sh_ewald         = fr->ic->sh_ewald;
762     ewtab            = fr->ic->tabq_coul_F;
763     ewtabscale       = fr->ic->tabq_scale;
764     ewtabhalfspace   = 0.5/ewtabscale;
765
766     /* Setup water-specific parameters */
767     inr              = nlist->iinr[0];
768     iq0              = facel*charge[inr+0];
769     iq1              = facel*charge[inr+1];
770     iq2              = facel*charge[inr+2];
771     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
772
773     jq0              = charge[inr+0];
774     jq1              = charge[inr+1];
775     jq2              = charge[inr+2];
776     vdwjidx0         = 2*vdwtype[inr+0];
777     qq00             = iq0*jq0;
778     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
779     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
780     qq01             = iq0*jq1;
781     qq02             = iq0*jq2;
782     qq10             = iq1*jq0;
783     qq11             = iq1*jq1;
784     qq12             = iq1*jq2;
785     qq20             = iq2*jq0;
786     qq21             = iq2*jq1;
787     qq22             = iq2*jq2;
788
789     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
790     rcutoff          = fr->rcoulomb;
791     rcutoff2         = rcutoff*rcutoff;
792
793     sh_vdw_invrcut6  = fr->ic->sh_invrc6;
794     rvdw             = fr->rvdw;
795
796     outeriter        = 0;
797     inneriter        = 0;
798
799     /* Start outer loop over neighborlists */
800     for(iidx=0; iidx<nri; iidx++)
801     {
802         /* Load shift vector for this list */
803         i_shift_offset   = DIM*shiftidx[iidx];
804         shX              = shiftvec[i_shift_offset+XX];
805         shY              = shiftvec[i_shift_offset+YY];
806         shZ              = shiftvec[i_shift_offset+ZZ];
807
808         /* Load limits for loop over neighbors */
809         j_index_start    = jindex[iidx];
810         j_index_end      = jindex[iidx+1];
811
812         /* Get outer coordinate index */
813         inr              = iinr[iidx];
814         i_coord_offset   = DIM*inr;
815
816         /* Load i particle coords and add shift vector */
817         ix0              = shX + x[i_coord_offset+DIM*0+XX];
818         iy0              = shY + x[i_coord_offset+DIM*0+YY];
819         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
820         ix1              = shX + x[i_coord_offset+DIM*1+XX];
821         iy1              = shY + x[i_coord_offset+DIM*1+YY];
822         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
823         ix2              = shX + x[i_coord_offset+DIM*2+XX];
824         iy2              = shY + x[i_coord_offset+DIM*2+YY];
825         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
826
827         fix0             = 0.0;
828         fiy0             = 0.0;
829         fiz0             = 0.0;
830         fix1             = 0.0;
831         fiy1             = 0.0;
832         fiz1             = 0.0;
833         fix2             = 0.0;
834         fiy2             = 0.0;
835         fiz2             = 0.0;
836
837         /* Start inner kernel loop */
838         for(jidx=j_index_start; jidx<j_index_end; jidx++)
839         {
840             /* Get j neighbor index, and coordinate index */
841             jnr              = jjnr[jidx];
842             j_coord_offset   = DIM*jnr;
843
844             /* load j atom coordinates */
845             jx0              = x[j_coord_offset+DIM*0+XX];
846             jy0              = x[j_coord_offset+DIM*0+YY];
847             jz0              = x[j_coord_offset+DIM*0+ZZ];
848             jx1              = x[j_coord_offset+DIM*1+XX];
849             jy1              = x[j_coord_offset+DIM*1+YY];
850             jz1              = x[j_coord_offset+DIM*1+ZZ];
851             jx2              = x[j_coord_offset+DIM*2+XX];
852             jy2              = x[j_coord_offset+DIM*2+YY];
853             jz2              = x[j_coord_offset+DIM*2+ZZ];
854
855             /* Calculate displacement vector */
856             dx00             = ix0 - jx0;
857             dy00             = iy0 - jy0;
858             dz00             = iz0 - jz0;
859             dx01             = ix0 - jx1;
860             dy01             = iy0 - jy1;
861             dz01             = iz0 - jz1;
862             dx02             = ix0 - jx2;
863             dy02             = iy0 - jy2;
864             dz02             = iz0 - jz2;
865             dx10             = ix1 - jx0;
866             dy10             = iy1 - jy0;
867             dz10             = iz1 - jz0;
868             dx11             = ix1 - jx1;
869             dy11             = iy1 - jy1;
870             dz11             = iz1 - jz1;
871             dx12             = ix1 - jx2;
872             dy12             = iy1 - jy2;
873             dz12             = iz1 - jz2;
874             dx20             = ix2 - jx0;
875             dy20             = iy2 - jy0;
876             dz20             = iz2 - jz0;
877             dx21             = ix2 - jx1;
878             dy21             = iy2 - jy1;
879             dz21             = iz2 - jz1;
880             dx22             = ix2 - jx2;
881             dy22             = iy2 - jy2;
882             dz22             = iz2 - jz2;
883
884             /* Calculate squared distance and things based on it */
885             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
886             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
887             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
888             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
889             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
890             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
891             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
892             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
893             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
894
895             rinv00           = gmx_invsqrt(rsq00);
896             rinv01           = gmx_invsqrt(rsq01);
897             rinv02           = gmx_invsqrt(rsq02);
898             rinv10           = gmx_invsqrt(rsq10);
899             rinv11           = gmx_invsqrt(rsq11);
900             rinv12           = gmx_invsqrt(rsq12);
901             rinv20           = gmx_invsqrt(rsq20);
902             rinv21           = gmx_invsqrt(rsq21);
903             rinv22           = gmx_invsqrt(rsq22);
904
905             rinvsq00         = rinv00*rinv00;
906             rinvsq01         = rinv01*rinv01;
907             rinvsq02         = rinv02*rinv02;
908             rinvsq10         = rinv10*rinv10;
909             rinvsq11         = rinv11*rinv11;
910             rinvsq12         = rinv12*rinv12;
911             rinvsq20         = rinv20*rinv20;
912             rinvsq21         = rinv21*rinv21;
913             rinvsq22         = rinv22*rinv22;
914
915             /**************************
916              * CALCULATE INTERACTIONS *
917              **************************/
918
919             if (rsq00<rcutoff2)
920             {
921
922             r00              = rsq00*rinv00;
923
924             /* EWALD ELECTROSTATICS */
925
926             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
927             ewrt             = r00*ewtabscale;
928             ewitab           = ewrt;
929             eweps            = ewrt-ewitab;
930             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
931             felec            = qq00*rinv00*(rinvsq00-felec);
932
933             /* LENNARD-JONES DISPERSION/REPULSION */
934
935             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
936             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
937
938             fscal            = felec+fvdw;
939
940             /* Calculate temporary vectorial force */
941             tx               = fscal*dx00;
942             ty               = fscal*dy00;
943             tz               = fscal*dz00;
944
945             /* Update vectorial force */
946             fix0            += tx;
947             fiy0            += ty;
948             fiz0            += tz;
949             f[j_coord_offset+DIM*0+XX] -= tx;
950             f[j_coord_offset+DIM*0+YY] -= ty;
951             f[j_coord_offset+DIM*0+ZZ] -= tz;
952
953             }
954
955             /**************************
956              * CALCULATE INTERACTIONS *
957              **************************/
958
959             if (rsq01<rcutoff2)
960             {
961
962             r01              = rsq01*rinv01;
963
964             /* EWALD ELECTROSTATICS */
965
966             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
967             ewrt             = r01*ewtabscale;
968             ewitab           = ewrt;
969             eweps            = ewrt-ewitab;
970             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
971             felec            = qq01*rinv01*(rinvsq01-felec);
972
973             fscal            = felec;
974
975             /* Calculate temporary vectorial force */
976             tx               = fscal*dx01;
977             ty               = fscal*dy01;
978             tz               = fscal*dz01;
979
980             /* Update vectorial force */
981             fix0            += tx;
982             fiy0            += ty;
983             fiz0            += tz;
984             f[j_coord_offset+DIM*1+XX] -= tx;
985             f[j_coord_offset+DIM*1+YY] -= ty;
986             f[j_coord_offset+DIM*1+ZZ] -= tz;
987
988             }
989
990             /**************************
991              * CALCULATE INTERACTIONS *
992              **************************/
993
994             if (rsq02<rcutoff2)
995             {
996
997             r02              = rsq02*rinv02;
998
999             /* EWALD ELECTROSTATICS */
1000
1001             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1002             ewrt             = r02*ewtabscale;
1003             ewitab           = ewrt;
1004             eweps            = ewrt-ewitab;
1005             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1006             felec            = qq02*rinv02*(rinvsq02-felec);
1007
1008             fscal            = felec;
1009
1010             /* Calculate temporary vectorial force */
1011             tx               = fscal*dx02;
1012             ty               = fscal*dy02;
1013             tz               = fscal*dz02;
1014
1015             /* Update vectorial force */
1016             fix0            += tx;
1017             fiy0            += ty;
1018             fiz0            += tz;
1019             f[j_coord_offset+DIM*2+XX] -= tx;
1020             f[j_coord_offset+DIM*2+YY] -= ty;
1021             f[j_coord_offset+DIM*2+ZZ] -= tz;
1022
1023             }
1024
1025             /**************************
1026              * CALCULATE INTERACTIONS *
1027              **************************/
1028
1029             if (rsq10<rcutoff2)
1030             {
1031
1032             r10              = rsq10*rinv10;
1033
1034             /* EWALD ELECTROSTATICS */
1035
1036             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1037             ewrt             = r10*ewtabscale;
1038             ewitab           = ewrt;
1039             eweps            = ewrt-ewitab;
1040             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1041             felec            = qq10*rinv10*(rinvsq10-felec);
1042
1043             fscal            = felec;
1044
1045             /* Calculate temporary vectorial force */
1046             tx               = fscal*dx10;
1047             ty               = fscal*dy10;
1048             tz               = fscal*dz10;
1049
1050             /* Update vectorial force */
1051             fix1            += tx;
1052             fiy1            += ty;
1053             fiz1            += tz;
1054             f[j_coord_offset+DIM*0+XX] -= tx;
1055             f[j_coord_offset+DIM*0+YY] -= ty;
1056             f[j_coord_offset+DIM*0+ZZ] -= tz;
1057
1058             }
1059
1060             /**************************
1061              * CALCULATE INTERACTIONS *
1062              **************************/
1063
1064             if (rsq11<rcutoff2)
1065             {
1066
1067             r11              = rsq11*rinv11;
1068
1069             /* EWALD ELECTROSTATICS */
1070
1071             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1072             ewrt             = r11*ewtabscale;
1073             ewitab           = ewrt;
1074             eweps            = ewrt-ewitab;
1075             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1076             felec            = qq11*rinv11*(rinvsq11-felec);
1077
1078             fscal            = felec;
1079
1080             /* Calculate temporary vectorial force */
1081             tx               = fscal*dx11;
1082             ty               = fscal*dy11;
1083             tz               = fscal*dz11;
1084
1085             /* Update vectorial force */
1086             fix1            += tx;
1087             fiy1            += ty;
1088             fiz1            += tz;
1089             f[j_coord_offset+DIM*1+XX] -= tx;
1090             f[j_coord_offset+DIM*1+YY] -= ty;
1091             f[j_coord_offset+DIM*1+ZZ] -= tz;
1092
1093             }
1094
1095             /**************************
1096              * CALCULATE INTERACTIONS *
1097              **************************/
1098
1099             if (rsq12<rcutoff2)
1100             {
1101
1102             r12              = rsq12*rinv12;
1103
1104             /* EWALD ELECTROSTATICS */
1105
1106             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1107             ewrt             = r12*ewtabscale;
1108             ewitab           = ewrt;
1109             eweps            = ewrt-ewitab;
1110             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1111             felec            = qq12*rinv12*(rinvsq12-felec);
1112
1113             fscal            = felec;
1114
1115             /* Calculate temporary vectorial force */
1116             tx               = fscal*dx12;
1117             ty               = fscal*dy12;
1118             tz               = fscal*dz12;
1119
1120             /* Update vectorial force */
1121             fix1            += tx;
1122             fiy1            += ty;
1123             fiz1            += tz;
1124             f[j_coord_offset+DIM*2+XX] -= tx;
1125             f[j_coord_offset+DIM*2+YY] -= ty;
1126             f[j_coord_offset+DIM*2+ZZ] -= tz;
1127
1128             }
1129
1130             /**************************
1131              * CALCULATE INTERACTIONS *
1132              **************************/
1133
1134             if (rsq20<rcutoff2)
1135             {
1136
1137             r20              = rsq20*rinv20;
1138
1139             /* EWALD ELECTROSTATICS */
1140
1141             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1142             ewrt             = r20*ewtabscale;
1143             ewitab           = ewrt;
1144             eweps            = ewrt-ewitab;
1145             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1146             felec            = qq20*rinv20*(rinvsq20-felec);
1147
1148             fscal            = felec;
1149
1150             /* Calculate temporary vectorial force */
1151             tx               = fscal*dx20;
1152             ty               = fscal*dy20;
1153             tz               = fscal*dz20;
1154
1155             /* Update vectorial force */
1156             fix2            += tx;
1157             fiy2            += ty;
1158             fiz2            += tz;
1159             f[j_coord_offset+DIM*0+XX] -= tx;
1160             f[j_coord_offset+DIM*0+YY] -= ty;
1161             f[j_coord_offset+DIM*0+ZZ] -= tz;
1162
1163             }
1164
1165             /**************************
1166              * CALCULATE INTERACTIONS *
1167              **************************/
1168
1169             if (rsq21<rcutoff2)
1170             {
1171
1172             r21              = rsq21*rinv21;
1173
1174             /* EWALD ELECTROSTATICS */
1175
1176             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1177             ewrt             = r21*ewtabscale;
1178             ewitab           = ewrt;
1179             eweps            = ewrt-ewitab;
1180             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1181             felec            = qq21*rinv21*(rinvsq21-felec);
1182
1183             fscal            = felec;
1184
1185             /* Calculate temporary vectorial force */
1186             tx               = fscal*dx21;
1187             ty               = fscal*dy21;
1188             tz               = fscal*dz21;
1189
1190             /* Update vectorial force */
1191             fix2            += tx;
1192             fiy2            += ty;
1193             fiz2            += tz;
1194             f[j_coord_offset+DIM*1+XX] -= tx;
1195             f[j_coord_offset+DIM*1+YY] -= ty;
1196             f[j_coord_offset+DIM*1+ZZ] -= tz;
1197
1198             }
1199
1200             /**************************
1201              * CALCULATE INTERACTIONS *
1202              **************************/
1203
1204             if (rsq22<rcutoff2)
1205             {
1206
1207             r22              = rsq22*rinv22;
1208
1209             /* EWALD ELECTROSTATICS */
1210
1211             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1212             ewrt             = r22*ewtabscale;
1213             ewitab           = ewrt;
1214             eweps            = ewrt-ewitab;
1215             felec            = (1.0-eweps)*ewtab[ewitab]+eweps*ewtab[ewitab+1];
1216             felec            = qq22*rinv22*(rinvsq22-felec);
1217
1218             fscal            = felec;
1219
1220             /* Calculate temporary vectorial force */
1221             tx               = fscal*dx22;
1222             ty               = fscal*dy22;
1223             tz               = fscal*dz22;
1224
1225             /* Update vectorial force */
1226             fix2            += tx;
1227             fiy2            += ty;
1228             fiz2            += tz;
1229             f[j_coord_offset+DIM*2+XX] -= tx;
1230             f[j_coord_offset+DIM*2+YY] -= ty;
1231             f[j_coord_offset+DIM*2+ZZ] -= tz;
1232
1233             }
1234
1235             /* Inner loop uses 304 flops */
1236         }
1237         /* End of innermost loop */
1238
1239         tx = ty = tz = 0;
1240         f[i_coord_offset+DIM*0+XX] += fix0;
1241         f[i_coord_offset+DIM*0+YY] += fiy0;
1242         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1243         tx                         += fix0;
1244         ty                         += fiy0;
1245         tz                         += fiz0;
1246         f[i_coord_offset+DIM*1+XX] += fix1;
1247         f[i_coord_offset+DIM*1+YY] += fiy1;
1248         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1249         tx                         += fix1;
1250         ty                         += fiy1;
1251         tz                         += fiz1;
1252         f[i_coord_offset+DIM*2+XX] += fix2;
1253         f[i_coord_offset+DIM*2+YY] += fiy2;
1254         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1255         tx                         += fix2;
1256         ty                         += fiy2;
1257         tz                         += fiz2;
1258         fshift[i_shift_offset+XX]  += tx;
1259         fshift[i_shift_offset+YY]  += ty;
1260         fshift[i_shift_offset+ZZ]  += tz;
1261
1262         /* Increment number of inner iterations */
1263         inneriter                  += j_index_end - j_index_start;
1264
1265         /* Outer loop uses 30 flops */
1266     }
1267
1268     /* Increment number of outer iterations */
1269     outeriter        += nri;
1270
1271     /* Update outer/inner flops */
1272
1273     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*30 + inneriter*304);
1274 }