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