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