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