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