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