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