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