a04f5c1b6c1f9f08d59e8c648bb64f33f2043dff
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCoul_VdwLJ_GeomW4P1_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 #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 "gromacs/math/vec.h"
47 #include "nrnb.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_c
51  * Electrostatics interaction: Coulomb
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water4-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_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              vdwioffset3;
79     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
80     int              vdwjidx0;
81     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
82     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
83     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
84     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
85     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
86     real             velec,felec,velecsum,facel,crf,krf,krf2;
87     real             *charge;
88     int              nvdwtype;
89     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
90     int              *vdwtype;
91     real             *vdwparam;
92
93     x                = xx[0];
94     f                = ff[0];
95
96     nri              = nlist->nri;
97     iinr             = nlist->iinr;
98     jindex           = nlist->jindex;
99     jjnr             = nlist->jjnr;
100     shiftidx         = nlist->shift;
101     gid              = nlist->gid;
102     shiftvec         = fr->shift_vec[0];
103     fshift           = fr->fshift[0];
104     facel            = fr->epsfac;
105     charge           = mdatoms->chargeA;
106     nvdwtype         = fr->ntype;
107     vdwparam         = fr->nbfp;
108     vdwtype          = mdatoms->typeA;
109
110     /* Setup water-specific parameters */
111     inr              = nlist->iinr[0];
112     iq1              = facel*charge[inr+1];
113     iq2              = facel*charge[inr+2];
114     iq3              = facel*charge[inr+3];
115     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
116
117     outeriter        = 0;
118     inneriter        = 0;
119
120     /* Start outer loop over neighborlists */
121     for(iidx=0; iidx<nri; iidx++)
122     {
123         /* Load shift vector for this list */
124         i_shift_offset   = DIM*shiftidx[iidx];
125         shX              = shiftvec[i_shift_offset+XX];
126         shY              = shiftvec[i_shift_offset+YY];
127         shZ              = shiftvec[i_shift_offset+ZZ];
128
129         /* Load limits for loop over neighbors */
130         j_index_start    = jindex[iidx];
131         j_index_end      = jindex[iidx+1];
132
133         /* Get outer coordinate index */
134         inr              = iinr[iidx];
135         i_coord_offset   = DIM*inr;
136
137         /* Load i particle coords and add shift vector */
138         ix0              = shX + x[i_coord_offset+DIM*0+XX];
139         iy0              = shY + x[i_coord_offset+DIM*0+YY];
140         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
141         ix1              = shX + x[i_coord_offset+DIM*1+XX];
142         iy1              = shY + x[i_coord_offset+DIM*1+YY];
143         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
144         ix2              = shX + x[i_coord_offset+DIM*2+XX];
145         iy2              = shY + x[i_coord_offset+DIM*2+YY];
146         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
147         ix3              = shX + x[i_coord_offset+DIM*3+XX];
148         iy3              = shY + x[i_coord_offset+DIM*3+YY];
149         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
150
151         fix0             = 0.0;
152         fiy0             = 0.0;
153         fiz0             = 0.0;
154         fix1             = 0.0;
155         fiy1             = 0.0;
156         fiz1             = 0.0;
157         fix2             = 0.0;
158         fiy2             = 0.0;
159         fiz2             = 0.0;
160         fix3             = 0.0;
161         fiy3             = 0.0;
162         fiz3             = 0.0;
163
164         /* Reset potential sums */
165         velecsum         = 0.0;
166         vvdwsum          = 0.0;
167
168         /* Start inner kernel loop */
169         for(jidx=j_index_start; jidx<j_index_end; jidx++)
170         {
171             /* Get j neighbor index, and coordinate index */
172             jnr              = jjnr[jidx];
173             j_coord_offset   = DIM*jnr;
174
175             /* load j atom coordinates */
176             jx0              = x[j_coord_offset+DIM*0+XX];
177             jy0              = x[j_coord_offset+DIM*0+YY];
178             jz0              = x[j_coord_offset+DIM*0+ZZ];
179
180             /* Calculate displacement vector */
181             dx00             = ix0 - jx0;
182             dy00             = iy0 - jy0;
183             dz00             = iz0 - jz0;
184             dx10             = ix1 - jx0;
185             dy10             = iy1 - jy0;
186             dz10             = iz1 - jz0;
187             dx20             = ix2 - jx0;
188             dy20             = iy2 - jy0;
189             dz20             = iz2 - jz0;
190             dx30             = ix3 - jx0;
191             dy30             = iy3 - jy0;
192             dz30             = iz3 - jz0;
193
194             /* Calculate squared distance and things based on it */
195             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
196             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
197             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
198             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
199
200             rinv10           = gmx_invsqrt(rsq10);
201             rinv20           = gmx_invsqrt(rsq20);
202             rinv30           = gmx_invsqrt(rsq30);
203
204             rinvsq00         = 1.0/rsq00;
205             rinvsq10         = rinv10*rinv10;
206             rinvsq20         = rinv20*rinv20;
207             rinvsq30         = rinv30*rinv30;
208
209             /* Load parameters for j particles */
210             jq0              = charge[jnr+0];
211             vdwjidx0         = 2*vdwtype[jnr+0];
212
213             /**************************
214              * CALCULATE INTERACTIONS *
215              **************************/
216
217             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
218             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
219
220             /* LENNARD-JONES DISPERSION/REPULSION */
221
222             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
223             vvdw6            = c6_00*rinvsix;
224             vvdw12           = c12_00*rinvsix*rinvsix;
225             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
226             fvdw             = (vvdw12-vvdw6)*rinvsq00;
227
228             /* Update potential sums from outer loop */
229             vvdwsum         += vvdw;
230
231             fscal            = fvdw;
232
233             /* Calculate temporary vectorial force */
234             tx               = fscal*dx00;
235             ty               = fscal*dy00;
236             tz               = fscal*dz00;
237
238             /* Update vectorial force */
239             fix0            += tx;
240             fiy0            += ty;
241             fiz0            += tz;
242             f[j_coord_offset+DIM*0+XX] -= tx;
243             f[j_coord_offset+DIM*0+YY] -= ty;
244             f[j_coord_offset+DIM*0+ZZ] -= tz;
245
246             /**************************
247              * CALCULATE INTERACTIONS *
248              **************************/
249
250             qq10             = iq1*jq0;
251
252             /* COULOMB ELECTROSTATICS */
253             velec            = qq10*rinv10;
254             felec            = velec*rinvsq10;
255
256             /* Update potential sums from outer loop */
257             velecsum        += velec;
258
259             fscal            = felec;
260
261             /* Calculate temporary vectorial force */
262             tx               = fscal*dx10;
263             ty               = fscal*dy10;
264             tz               = fscal*dz10;
265
266             /* Update vectorial force */
267             fix1            += tx;
268             fiy1            += ty;
269             fiz1            += tz;
270             f[j_coord_offset+DIM*0+XX] -= tx;
271             f[j_coord_offset+DIM*0+YY] -= ty;
272             f[j_coord_offset+DIM*0+ZZ] -= tz;
273
274             /**************************
275              * CALCULATE INTERACTIONS *
276              **************************/
277
278             qq20             = iq2*jq0;
279
280             /* COULOMB ELECTROSTATICS */
281             velec            = qq20*rinv20;
282             felec            = velec*rinvsq20;
283
284             /* Update potential sums from outer loop */
285             velecsum        += velec;
286
287             fscal            = felec;
288
289             /* Calculate temporary vectorial force */
290             tx               = fscal*dx20;
291             ty               = fscal*dy20;
292             tz               = fscal*dz20;
293
294             /* Update vectorial force */
295             fix2            += tx;
296             fiy2            += ty;
297             fiz2            += tz;
298             f[j_coord_offset+DIM*0+XX] -= tx;
299             f[j_coord_offset+DIM*0+YY] -= ty;
300             f[j_coord_offset+DIM*0+ZZ] -= tz;
301
302             /**************************
303              * CALCULATE INTERACTIONS *
304              **************************/
305
306             qq30             = iq3*jq0;
307
308             /* COULOMB ELECTROSTATICS */
309             velec            = qq30*rinv30;
310             felec            = velec*rinvsq30;
311
312             /* Update potential sums from outer loop */
313             velecsum        += velec;
314
315             fscal            = felec;
316
317             /* Calculate temporary vectorial force */
318             tx               = fscal*dx30;
319             ty               = fscal*dy30;
320             tz               = fscal*dz30;
321
322             /* Update vectorial force */
323             fix3            += tx;
324             fiy3            += ty;
325             fiz3            += tz;
326             f[j_coord_offset+DIM*0+XX] -= tx;
327             f[j_coord_offset+DIM*0+YY] -= ty;
328             f[j_coord_offset+DIM*0+ZZ] -= tz;
329
330             /* Inner loop uses 116 flops */
331         }
332         /* End of innermost loop */
333
334         tx = ty = tz = 0;
335         f[i_coord_offset+DIM*0+XX] += fix0;
336         f[i_coord_offset+DIM*0+YY] += fiy0;
337         f[i_coord_offset+DIM*0+ZZ] += fiz0;
338         tx                         += fix0;
339         ty                         += fiy0;
340         tz                         += fiz0;
341         f[i_coord_offset+DIM*1+XX] += fix1;
342         f[i_coord_offset+DIM*1+YY] += fiy1;
343         f[i_coord_offset+DIM*1+ZZ] += fiz1;
344         tx                         += fix1;
345         ty                         += fiy1;
346         tz                         += fiz1;
347         f[i_coord_offset+DIM*2+XX] += fix2;
348         f[i_coord_offset+DIM*2+YY] += fiy2;
349         f[i_coord_offset+DIM*2+ZZ] += fiz2;
350         tx                         += fix2;
351         ty                         += fiy2;
352         tz                         += fiz2;
353         f[i_coord_offset+DIM*3+XX] += fix3;
354         f[i_coord_offset+DIM*3+YY] += fiy3;
355         f[i_coord_offset+DIM*3+ZZ] += fiz3;
356         tx                         += fix3;
357         ty                         += fiy3;
358         tz                         += fiz3;
359         fshift[i_shift_offset+XX]  += tx;
360         fshift[i_shift_offset+YY]  += ty;
361         fshift[i_shift_offset+ZZ]  += tz;
362
363         ggid                        = gid[iidx];
364         /* Update potential energies */
365         kernel_data->energygrp_elec[ggid] += velecsum;
366         kernel_data->energygrp_vdw[ggid] += vvdwsum;
367
368         /* Increment number of inner iterations */
369         inneriter                  += j_index_end - j_index_start;
370
371         /* Outer loop uses 41 flops */
372     }
373
374     /* Increment number of outer iterations */
375     outeriter        += nri;
376
377     /* Update outer/inner flops */
378
379     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*41 + inneriter*116);
380 }
381 /*
382  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_c
383  * Electrostatics interaction: Coulomb
384  * VdW interaction:            LennardJones
385  * Geometry:                   Water4-Particle
386  * Calculate force/pot:        Force
387  */
388 void
389 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_c
390                     (t_nblist                    * gmx_restrict       nlist,
391                      rvec                        * gmx_restrict          xx,
392                      rvec                        * gmx_restrict          ff,
393                      t_forcerec                  * gmx_restrict          fr,
394                      t_mdatoms                   * gmx_restrict     mdatoms,
395                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
396                      t_nrnb                      * gmx_restrict        nrnb)
397 {
398     int              i_shift_offset,i_coord_offset,j_coord_offset;
399     int              j_index_start,j_index_end;
400     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
401     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
402     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
403     real             *shiftvec,*fshift,*x,*f;
404     int              vdwioffset0;
405     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
406     int              vdwioffset1;
407     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
408     int              vdwioffset2;
409     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
410     int              vdwioffset3;
411     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
412     int              vdwjidx0;
413     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
414     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
415     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
416     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
417     real             dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30,cexp1_30,cexp2_30;
418     real             velec,felec,velecsum,facel,crf,krf,krf2;
419     real             *charge;
420     int              nvdwtype;
421     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
422     int              *vdwtype;
423     real             *vdwparam;
424
425     x                = xx[0];
426     f                = ff[0];
427
428     nri              = nlist->nri;
429     iinr             = nlist->iinr;
430     jindex           = nlist->jindex;
431     jjnr             = nlist->jjnr;
432     shiftidx         = nlist->shift;
433     gid              = nlist->gid;
434     shiftvec         = fr->shift_vec[0];
435     fshift           = fr->fshift[0];
436     facel            = fr->epsfac;
437     charge           = mdatoms->chargeA;
438     nvdwtype         = fr->ntype;
439     vdwparam         = fr->nbfp;
440     vdwtype          = mdatoms->typeA;
441
442     /* Setup water-specific parameters */
443     inr              = nlist->iinr[0];
444     iq1              = facel*charge[inr+1];
445     iq2              = facel*charge[inr+2];
446     iq3              = facel*charge[inr+3];
447     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
448
449     outeriter        = 0;
450     inneriter        = 0;
451
452     /* Start outer loop over neighborlists */
453     for(iidx=0; iidx<nri; iidx++)
454     {
455         /* Load shift vector for this list */
456         i_shift_offset   = DIM*shiftidx[iidx];
457         shX              = shiftvec[i_shift_offset+XX];
458         shY              = shiftvec[i_shift_offset+YY];
459         shZ              = shiftvec[i_shift_offset+ZZ];
460
461         /* Load limits for loop over neighbors */
462         j_index_start    = jindex[iidx];
463         j_index_end      = jindex[iidx+1];
464
465         /* Get outer coordinate index */
466         inr              = iinr[iidx];
467         i_coord_offset   = DIM*inr;
468
469         /* Load i particle coords and add shift vector */
470         ix0              = shX + x[i_coord_offset+DIM*0+XX];
471         iy0              = shY + x[i_coord_offset+DIM*0+YY];
472         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
473         ix1              = shX + x[i_coord_offset+DIM*1+XX];
474         iy1              = shY + x[i_coord_offset+DIM*1+YY];
475         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
476         ix2              = shX + x[i_coord_offset+DIM*2+XX];
477         iy2              = shY + x[i_coord_offset+DIM*2+YY];
478         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
479         ix3              = shX + x[i_coord_offset+DIM*3+XX];
480         iy3              = shY + x[i_coord_offset+DIM*3+YY];
481         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
482
483         fix0             = 0.0;
484         fiy0             = 0.0;
485         fiz0             = 0.0;
486         fix1             = 0.0;
487         fiy1             = 0.0;
488         fiz1             = 0.0;
489         fix2             = 0.0;
490         fiy2             = 0.0;
491         fiz2             = 0.0;
492         fix3             = 0.0;
493         fiy3             = 0.0;
494         fiz3             = 0.0;
495
496         /* Start inner kernel loop */
497         for(jidx=j_index_start; jidx<j_index_end; jidx++)
498         {
499             /* Get j neighbor index, and coordinate index */
500             jnr              = jjnr[jidx];
501             j_coord_offset   = DIM*jnr;
502
503             /* load j atom coordinates */
504             jx0              = x[j_coord_offset+DIM*0+XX];
505             jy0              = x[j_coord_offset+DIM*0+YY];
506             jz0              = x[j_coord_offset+DIM*0+ZZ];
507
508             /* Calculate displacement vector */
509             dx00             = ix0 - jx0;
510             dy00             = iy0 - jy0;
511             dz00             = iz0 - jz0;
512             dx10             = ix1 - jx0;
513             dy10             = iy1 - jy0;
514             dz10             = iz1 - jz0;
515             dx20             = ix2 - jx0;
516             dy20             = iy2 - jy0;
517             dz20             = iz2 - jz0;
518             dx30             = ix3 - jx0;
519             dy30             = iy3 - jy0;
520             dz30             = iz3 - jz0;
521
522             /* Calculate squared distance and things based on it */
523             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
524             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
525             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
526             rsq30            = dx30*dx30+dy30*dy30+dz30*dz30;
527
528             rinv10           = gmx_invsqrt(rsq10);
529             rinv20           = gmx_invsqrt(rsq20);
530             rinv30           = gmx_invsqrt(rsq30);
531
532             rinvsq00         = 1.0/rsq00;
533             rinvsq10         = rinv10*rinv10;
534             rinvsq20         = rinv20*rinv20;
535             rinvsq30         = rinv30*rinv30;
536
537             /* Load parameters for j particles */
538             jq0              = charge[jnr+0];
539             vdwjidx0         = 2*vdwtype[jnr+0];
540
541             /**************************
542              * CALCULATE INTERACTIONS *
543              **************************/
544
545             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
546             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
547
548             /* LENNARD-JONES DISPERSION/REPULSION */
549
550             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
551             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
552
553             fscal            = fvdw;
554
555             /* Calculate temporary vectorial force */
556             tx               = fscal*dx00;
557             ty               = fscal*dy00;
558             tz               = fscal*dz00;
559
560             /* Update vectorial force */
561             fix0            += tx;
562             fiy0            += ty;
563             fiz0            += tz;
564             f[j_coord_offset+DIM*0+XX] -= tx;
565             f[j_coord_offset+DIM*0+YY] -= ty;
566             f[j_coord_offset+DIM*0+ZZ] -= tz;
567
568             /**************************
569              * CALCULATE INTERACTIONS *
570              **************************/
571
572             qq10             = iq1*jq0;
573
574             /* COULOMB ELECTROSTATICS */
575             velec            = qq10*rinv10;
576             felec            = velec*rinvsq10;
577
578             fscal            = felec;
579
580             /* Calculate temporary vectorial force */
581             tx               = fscal*dx10;
582             ty               = fscal*dy10;
583             tz               = fscal*dz10;
584
585             /* Update vectorial force */
586             fix1            += tx;
587             fiy1            += ty;
588             fiz1            += tz;
589             f[j_coord_offset+DIM*0+XX] -= tx;
590             f[j_coord_offset+DIM*0+YY] -= ty;
591             f[j_coord_offset+DIM*0+ZZ] -= tz;
592
593             /**************************
594              * CALCULATE INTERACTIONS *
595              **************************/
596
597             qq20             = iq2*jq0;
598
599             /* COULOMB ELECTROSTATICS */
600             velec            = qq20*rinv20;
601             felec            = velec*rinvsq20;
602
603             fscal            = felec;
604
605             /* Calculate temporary vectorial force */
606             tx               = fscal*dx20;
607             ty               = fscal*dy20;
608             tz               = fscal*dz20;
609
610             /* Update vectorial force */
611             fix2            += tx;
612             fiy2            += ty;
613             fiz2            += tz;
614             f[j_coord_offset+DIM*0+XX] -= tx;
615             f[j_coord_offset+DIM*0+YY] -= ty;
616             f[j_coord_offset+DIM*0+ZZ] -= tz;
617
618             /**************************
619              * CALCULATE INTERACTIONS *
620              **************************/
621
622             qq30             = iq3*jq0;
623
624             /* COULOMB ELECTROSTATICS */
625             velec            = qq30*rinv30;
626             felec            = velec*rinvsq30;
627
628             fscal            = felec;
629
630             /* Calculate temporary vectorial force */
631             tx               = fscal*dx30;
632             ty               = fscal*dy30;
633             tz               = fscal*dz30;
634
635             /* Update vectorial force */
636             fix3            += tx;
637             fiy3            += ty;
638             fiz3            += tz;
639             f[j_coord_offset+DIM*0+XX] -= tx;
640             f[j_coord_offset+DIM*0+YY] -= ty;
641             f[j_coord_offset+DIM*0+ZZ] -= tz;
642
643             /* Inner loop uses 108 flops */
644         }
645         /* End of innermost loop */
646
647         tx = ty = tz = 0;
648         f[i_coord_offset+DIM*0+XX] += fix0;
649         f[i_coord_offset+DIM*0+YY] += fiy0;
650         f[i_coord_offset+DIM*0+ZZ] += fiz0;
651         tx                         += fix0;
652         ty                         += fiy0;
653         tz                         += fiz0;
654         f[i_coord_offset+DIM*1+XX] += fix1;
655         f[i_coord_offset+DIM*1+YY] += fiy1;
656         f[i_coord_offset+DIM*1+ZZ] += fiz1;
657         tx                         += fix1;
658         ty                         += fiy1;
659         tz                         += fiz1;
660         f[i_coord_offset+DIM*2+XX] += fix2;
661         f[i_coord_offset+DIM*2+YY] += fiy2;
662         f[i_coord_offset+DIM*2+ZZ] += fiz2;
663         tx                         += fix2;
664         ty                         += fiy2;
665         tz                         += fiz2;
666         f[i_coord_offset+DIM*3+XX] += fix3;
667         f[i_coord_offset+DIM*3+YY] += fiy3;
668         f[i_coord_offset+DIM*3+ZZ] += fiz3;
669         tx                         += fix3;
670         ty                         += fiy3;
671         tz                         += fiz3;
672         fshift[i_shift_offset+XX]  += tx;
673         fshift[i_shift_offset+YY]  += ty;
674         fshift[i_shift_offset+ZZ]  += tz;
675
676         /* Increment number of inner iterations */
677         inneriter                  += j_index_end - j_index_start;
678
679         /* Outer loop uses 39 flops */
680     }
681
682     /* Increment number of outer iterations */
683     outeriter        += nri;
684
685     /* Update outer/inner flops */
686
687     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*39 + inneriter*108);
688 }