Use full path for legacyheaders
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecEwSw_VdwLJSw_GeomW4W4_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_ElecEwSw_VdwLJSw_GeomW4W4_VF_c
49  * Electrostatics interaction: Ewald
50  * VdW interaction:            LennardJones
51  * Geometry:                   Water4-Water4
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecEwSw_VdwLJSw_GeomW4W4_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     int              vdwjidx1;
81     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
82     int              vdwjidx2;
83     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
84     int              vdwjidx3;
85     real             jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
86     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
87     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
88     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
89     real             dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13,cexp1_13,cexp2_13;
90     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
91     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
92     real             dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23,cexp1_23,cexp2_23;
93     real             dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31,cexp1_31,cexp2_31;
94     real             dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32,cexp1_32,cexp2_32;
95     real             dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33,cexp1_33,cexp2_33;
96     real             velec,felec,velecsum,facel,crf,krf,krf2;
97     real             *charge;
98     int              nvdwtype;
99     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
100     int              *vdwtype;
101     real             *vdwparam;
102     int              ewitab;
103     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
104     real             *ewtab;
105     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
106
107     x                = xx[0];
108     f                = ff[0];
109
110     nri              = nlist->nri;
111     iinr             = nlist->iinr;
112     jindex           = nlist->jindex;
113     jjnr             = nlist->jjnr;
114     shiftidx         = nlist->shift;
115     gid              = nlist->gid;
116     shiftvec         = fr->shift_vec[0];
117     fshift           = fr->fshift[0];
118     facel            = fr->epsfac;
119     charge           = mdatoms->chargeA;
120     nvdwtype         = fr->ntype;
121     vdwparam         = fr->nbfp;
122     vdwtype          = mdatoms->typeA;
123
124     sh_ewald         = fr->ic->sh_ewald;
125     ewtab            = fr->ic->tabq_coul_FDV0;
126     ewtabscale       = fr->ic->tabq_scale;
127     ewtabhalfspace   = 0.5/ewtabscale;
128
129     /* Setup water-specific parameters */
130     inr              = nlist->iinr[0];
131     iq1              = facel*charge[inr+1];
132     iq2              = facel*charge[inr+2];
133     iq3              = facel*charge[inr+3];
134     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
135
136     jq1              = charge[inr+1];
137     jq2              = charge[inr+2];
138     jq3              = charge[inr+3];
139     vdwjidx0         = 2*vdwtype[inr+0];
140     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
141     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
142     qq11             = iq1*jq1;
143     qq12             = iq1*jq2;
144     qq13             = iq1*jq3;
145     qq21             = iq2*jq1;
146     qq22             = iq2*jq2;
147     qq23             = iq2*jq3;
148     qq31             = iq3*jq1;
149     qq32             = iq3*jq2;
150     qq33             = iq3*jq3;
151
152     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
153     rcutoff          = fr->rcoulomb;
154     rcutoff2         = rcutoff*rcutoff;
155
156     rswitch          = fr->rcoulomb_switch;
157     /* Setup switch parameters */
158     d                = rcutoff-rswitch;
159     swV3             = -10.0/(d*d*d);
160     swV4             =  15.0/(d*d*d*d);
161     swV5             =  -6.0/(d*d*d*d*d);
162     swF2             = -30.0/(d*d*d);
163     swF3             =  60.0/(d*d*d*d);
164     swF4             = -30.0/(d*d*d*d*d);
165
166     outeriter        = 0;
167     inneriter        = 0;
168
169     /* Start outer loop over neighborlists */
170     for(iidx=0; iidx<nri; iidx++)
171     {
172         /* Load shift vector for this list */
173         i_shift_offset   = DIM*shiftidx[iidx];
174         shX              = shiftvec[i_shift_offset+XX];
175         shY              = shiftvec[i_shift_offset+YY];
176         shZ              = shiftvec[i_shift_offset+ZZ];
177
178         /* Load limits for loop over neighbors */
179         j_index_start    = jindex[iidx];
180         j_index_end      = jindex[iidx+1];
181
182         /* Get outer coordinate index */
183         inr              = iinr[iidx];
184         i_coord_offset   = DIM*inr;
185
186         /* Load i particle coords and add shift vector */
187         ix0              = shX + x[i_coord_offset+DIM*0+XX];
188         iy0              = shY + x[i_coord_offset+DIM*0+YY];
189         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
190         ix1              = shX + x[i_coord_offset+DIM*1+XX];
191         iy1              = shY + x[i_coord_offset+DIM*1+YY];
192         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
193         ix2              = shX + x[i_coord_offset+DIM*2+XX];
194         iy2              = shY + x[i_coord_offset+DIM*2+YY];
195         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
196         ix3              = shX + x[i_coord_offset+DIM*3+XX];
197         iy3              = shY + x[i_coord_offset+DIM*3+YY];
198         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
199
200         fix0             = 0.0;
201         fiy0             = 0.0;
202         fiz0             = 0.0;
203         fix1             = 0.0;
204         fiy1             = 0.0;
205         fiz1             = 0.0;
206         fix2             = 0.0;
207         fiy2             = 0.0;
208         fiz2             = 0.0;
209         fix3             = 0.0;
210         fiy3             = 0.0;
211         fiz3             = 0.0;
212
213         /* Reset potential sums */
214         velecsum         = 0.0;
215         vvdwsum          = 0.0;
216
217         /* Start inner kernel loop */
218         for(jidx=j_index_start; jidx<j_index_end; jidx++)
219         {
220             /* Get j neighbor index, and coordinate index */
221             jnr              = jjnr[jidx];
222             j_coord_offset   = DIM*jnr;
223
224             /* load j atom coordinates */
225             jx0              = x[j_coord_offset+DIM*0+XX];
226             jy0              = x[j_coord_offset+DIM*0+YY];
227             jz0              = x[j_coord_offset+DIM*0+ZZ];
228             jx1              = x[j_coord_offset+DIM*1+XX];
229             jy1              = x[j_coord_offset+DIM*1+YY];
230             jz1              = x[j_coord_offset+DIM*1+ZZ];
231             jx2              = x[j_coord_offset+DIM*2+XX];
232             jy2              = x[j_coord_offset+DIM*2+YY];
233             jz2              = x[j_coord_offset+DIM*2+ZZ];
234             jx3              = x[j_coord_offset+DIM*3+XX];
235             jy3              = x[j_coord_offset+DIM*3+YY];
236             jz3              = x[j_coord_offset+DIM*3+ZZ];
237
238             /* Calculate displacement vector */
239             dx00             = ix0 - jx0;
240             dy00             = iy0 - jy0;
241             dz00             = iz0 - jz0;
242             dx11             = ix1 - jx1;
243             dy11             = iy1 - jy1;
244             dz11             = iz1 - jz1;
245             dx12             = ix1 - jx2;
246             dy12             = iy1 - jy2;
247             dz12             = iz1 - jz2;
248             dx13             = ix1 - jx3;
249             dy13             = iy1 - jy3;
250             dz13             = iz1 - jz3;
251             dx21             = ix2 - jx1;
252             dy21             = iy2 - jy1;
253             dz21             = iz2 - jz1;
254             dx22             = ix2 - jx2;
255             dy22             = iy2 - jy2;
256             dz22             = iz2 - jz2;
257             dx23             = ix2 - jx3;
258             dy23             = iy2 - jy3;
259             dz23             = iz2 - jz3;
260             dx31             = ix3 - jx1;
261             dy31             = iy3 - jy1;
262             dz31             = iz3 - jz1;
263             dx32             = ix3 - jx2;
264             dy32             = iy3 - jy2;
265             dz32             = iz3 - jz2;
266             dx33             = ix3 - jx3;
267             dy33             = iy3 - jy3;
268             dz33             = iz3 - jz3;
269
270             /* Calculate squared distance and things based on it */
271             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
272             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
273             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
274             rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
275             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
276             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
277             rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
278             rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
279             rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
280             rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
281
282             rinv00           = gmx_invsqrt(rsq00);
283             rinv11           = gmx_invsqrt(rsq11);
284             rinv12           = gmx_invsqrt(rsq12);
285             rinv13           = gmx_invsqrt(rsq13);
286             rinv21           = gmx_invsqrt(rsq21);
287             rinv22           = gmx_invsqrt(rsq22);
288             rinv23           = gmx_invsqrt(rsq23);
289             rinv31           = gmx_invsqrt(rsq31);
290             rinv32           = gmx_invsqrt(rsq32);
291             rinv33           = gmx_invsqrt(rsq33);
292
293             rinvsq00         = rinv00*rinv00;
294             rinvsq11         = rinv11*rinv11;
295             rinvsq12         = rinv12*rinv12;
296             rinvsq13         = rinv13*rinv13;
297             rinvsq21         = rinv21*rinv21;
298             rinvsq22         = rinv22*rinv22;
299             rinvsq23         = rinv23*rinv23;
300             rinvsq31         = rinv31*rinv31;
301             rinvsq32         = rinv32*rinv32;
302             rinvsq33         = rinv33*rinv33;
303
304             /**************************
305              * CALCULATE INTERACTIONS *
306              **************************/
307
308             if (rsq00<rcutoff2)
309             {
310
311             r00              = rsq00*rinv00;
312
313             /* LENNARD-JONES DISPERSION/REPULSION */
314
315             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
316             vvdw6            = c6_00*rinvsix;
317             vvdw12           = c12_00*rinvsix*rinvsix;
318             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
319             fvdw             = (vvdw12-vvdw6)*rinvsq00;
320
321             d                = r00-rswitch;
322             d                = (d>0.0) ? d : 0.0;
323             d2               = d*d;
324             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
325
326             dsw              = d2*(swF2+d*(swF3+d*swF4));
327
328             /* Evaluate switch function */
329             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
330             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
331             vvdw            *= sw;
332
333             /* Update potential sums from outer loop */
334             vvdwsum         += vvdw;
335
336             fscal            = fvdw;
337
338             /* Calculate temporary vectorial force */
339             tx               = fscal*dx00;
340             ty               = fscal*dy00;
341             tz               = fscal*dz00;
342
343             /* Update vectorial force */
344             fix0            += tx;
345             fiy0            += ty;
346             fiz0            += tz;
347             f[j_coord_offset+DIM*0+XX] -= tx;
348             f[j_coord_offset+DIM*0+YY] -= ty;
349             f[j_coord_offset+DIM*0+ZZ] -= tz;
350
351             }
352
353             /**************************
354              * CALCULATE INTERACTIONS *
355              **************************/
356
357             if (rsq11<rcutoff2)
358             {
359
360             r11              = rsq11*rinv11;
361
362             /* EWALD ELECTROSTATICS */
363
364             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
365             ewrt             = r11*ewtabscale;
366             ewitab           = ewrt;
367             eweps            = ewrt-ewitab;
368             ewitab           = 4*ewitab;
369             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
370             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
371             felec            = qq11*rinv11*(rinvsq11-felec);
372
373             d                = r11-rswitch;
374             d                = (d>0.0) ? d : 0.0;
375             d2               = d*d;
376             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
377
378             dsw              = d2*(swF2+d*(swF3+d*swF4));
379
380             /* Evaluate switch function */
381             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
382             felec            = felec*sw - rinv11*velec*dsw;
383             velec           *= sw;
384
385             /* Update potential sums from outer loop */
386             velecsum        += velec;
387
388             fscal            = felec;
389
390             /* Calculate temporary vectorial force */
391             tx               = fscal*dx11;
392             ty               = fscal*dy11;
393             tz               = fscal*dz11;
394
395             /* Update vectorial force */
396             fix1            += tx;
397             fiy1            += ty;
398             fiz1            += tz;
399             f[j_coord_offset+DIM*1+XX] -= tx;
400             f[j_coord_offset+DIM*1+YY] -= ty;
401             f[j_coord_offset+DIM*1+ZZ] -= tz;
402
403             }
404
405             /**************************
406              * CALCULATE INTERACTIONS *
407              **************************/
408
409             if (rsq12<rcutoff2)
410             {
411
412             r12              = rsq12*rinv12;
413
414             /* EWALD ELECTROSTATICS */
415
416             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
417             ewrt             = r12*ewtabscale;
418             ewitab           = ewrt;
419             eweps            = ewrt-ewitab;
420             ewitab           = 4*ewitab;
421             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
422             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
423             felec            = qq12*rinv12*(rinvsq12-felec);
424
425             d                = r12-rswitch;
426             d                = (d>0.0) ? d : 0.0;
427             d2               = d*d;
428             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
429
430             dsw              = d2*(swF2+d*(swF3+d*swF4));
431
432             /* Evaluate switch function */
433             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
434             felec            = felec*sw - rinv12*velec*dsw;
435             velec           *= sw;
436
437             /* Update potential sums from outer loop */
438             velecsum        += velec;
439
440             fscal            = felec;
441
442             /* Calculate temporary vectorial force */
443             tx               = fscal*dx12;
444             ty               = fscal*dy12;
445             tz               = fscal*dz12;
446
447             /* Update vectorial force */
448             fix1            += tx;
449             fiy1            += ty;
450             fiz1            += tz;
451             f[j_coord_offset+DIM*2+XX] -= tx;
452             f[j_coord_offset+DIM*2+YY] -= ty;
453             f[j_coord_offset+DIM*2+ZZ] -= tz;
454
455             }
456
457             /**************************
458              * CALCULATE INTERACTIONS *
459              **************************/
460
461             if (rsq13<rcutoff2)
462             {
463
464             r13              = rsq13*rinv13;
465
466             /* EWALD ELECTROSTATICS */
467
468             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
469             ewrt             = r13*ewtabscale;
470             ewitab           = ewrt;
471             eweps            = ewrt-ewitab;
472             ewitab           = 4*ewitab;
473             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
474             velec            = qq13*(rinv13-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
475             felec            = qq13*rinv13*(rinvsq13-felec);
476
477             d                = r13-rswitch;
478             d                = (d>0.0) ? d : 0.0;
479             d2               = d*d;
480             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
481
482             dsw              = d2*(swF2+d*(swF3+d*swF4));
483
484             /* Evaluate switch function */
485             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
486             felec            = felec*sw - rinv13*velec*dsw;
487             velec           *= sw;
488
489             /* Update potential sums from outer loop */
490             velecsum        += velec;
491
492             fscal            = felec;
493
494             /* Calculate temporary vectorial force */
495             tx               = fscal*dx13;
496             ty               = fscal*dy13;
497             tz               = fscal*dz13;
498
499             /* Update vectorial force */
500             fix1            += tx;
501             fiy1            += ty;
502             fiz1            += tz;
503             f[j_coord_offset+DIM*3+XX] -= tx;
504             f[j_coord_offset+DIM*3+YY] -= ty;
505             f[j_coord_offset+DIM*3+ZZ] -= tz;
506
507             }
508
509             /**************************
510              * CALCULATE INTERACTIONS *
511              **************************/
512
513             if (rsq21<rcutoff2)
514             {
515
516             r21              = rsq21*rinv21;
517
518             /* EWALD ELECTROSTATICS */
519
520             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
521             ewrt             = r21*ewtabscale;
522             ewitab           = ewrt;
523             eweps            = ewrt-ewitab;
524             ewitab           = 4*ewitab;
525             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
526             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
527             felec            = qq21*rinv21*(rinvsq21-felec);
528
529             d                = r21-rswitch;
530             d                = (d>0.0) ? d : 0.0;
531             d2               = d*d;
532             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
533
534             dsw              = d2*(swF2+d*(swF3+d*swF4));
535
536             /* Evaluate switch function */
537             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
538             felec            = felec*sw - rinv21*velec*dsw;
539             velec           *= sw;
540
541             /* Update potential sums from outer loop */
542             velecsum        += velec;
543
544             fscal            = felec;
545
546             /* Calculate temporary vectorial force */
547             tx               = fscal*dx21;
548             ty               = fscal*dy21;
549             tz               = fscal*dz21;
550
551             /* Update vectorial force */
552             fix2            += tx;
553             fiy2            += ty;
554             fiz2            += tz;
555             f[j_coord_offset+DIM*1+XX] -= tx;
556             f[j_coord_offset+DIM*1+YY] -= ty;
557             f[j_coord_offset+DIM*1+ZZ] -= tz;
558
559             }
560
561             /**************************
562              * CALCULATE INTERACTIONS *
563              **************************/
564
565             if (rsq22<rcutoff2)
566             {
567
568             r22              = rsq22*rinv22;
569
570             /* EWALD ELECTROSTATICS */
571
572             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
573             ewrt             = r22*ewtabscale;
574             ewitab           = ewrt;
575             eweps            = ewrt-ewitab;
576             ewitab           = 4*ewitab;
577             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
578             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
579             felec            = qq22*rinv22*(rinvsq22-felec);
580
581             d                = r22-rswitch;
582             d                = (d>0.0) ? d : 0.0;
583             d2               = d*d;
584             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
585
586             dsw              = d2*(swF2+d*(swF3+d*swF4));
587
588             /* Evaluate switch function */
589             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
590             felec            = felec*sw - rinv22*velec*dsw;
591             velec           *= sw;
592
593             /* Update potential sums from outer loop */
594             velecsum        += velec;
595
596             fscal            = felec;
597
598             /* Calculate temporary vectorial force */
599             tx               = fscal*dx22;
600             ty               = fscal*dy22;
601             tz               = fscal*dz22;
602
603             /* Update vectorial force */
604             fix2            += tx;
605             fiy2            += ty;
606             fiz2            += tz;
607             f[j_coord_offset+DIM*2+XX] -= tx;
608             f[j_coord_offset+DIM*2+YY] -= ty;
609             f[j_coord_offset+DIM*2+ZZ] -= tz;
610
611             }
612
613             /**************************
614              * CALCULATE INTERACTIONS *
615              **************************/
616
617             if (rsq23<rcutoff2)
618             {
619
620             r23              = rsq23*rinv23;
621
622             /* EWALD ELECTROSTATICS */
623
624             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
625             ewrt             = r23*ewtabscale;
626             ewitab           = ewrt;
627             eweps            = ewrt-ewitab;
628             ewitab           = 4*ewitab;
629             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
630             velec            = qq23*(rinv23-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
631             felec            = qq23*rinv23*(rinvsq23-felec);
632
633             d                = r23-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             felec            = felec*sw - rinv23*velec*dsw;
643             velec           *= sw;
644
645             /* Update potential sums from outer loop */
646             velecsum        += velec;
647
648             fscal            = felec;
649
650             /* Calculate temporary vectorial force */
651             tx               = fscal*dx23;
652             ty               = fscal*dy23;
653             tz               = fscal*dz23;
654
655             /* Update vectorial force */
656             fix2            += tx;
657             fiy2            += ty;
658             fiz2            += tz;
659             f[j_coord_offset+DIM*3+XX] -= tx;
660             f[j_coord_offset+DIM*3+YY] -= ty;
661             f[j_coord_offset+DIM*3+ZZ] -= tz;
662
663             }
664
665             /**************************
666              * CALCULATE INTERACTIONS *
667              **************************/
668
669             if (rsq31<rcutoff2)
670             {
671
672             r31              = rsq31*rinv31;
673
674             /* EWALD ELECTROSTATICS */
675
676             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
677             ewrt             = r31*ewtabscale;
678             ewitab           = ewrt;
679             eweps            = ewrt-ewitab;
680             ewitab           = 4*ewitab;
681             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
682             velec            = qq31*(rinv31-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
683             felec            = qq31*rinv31*(rinvsq31-felec);
684
685             d                = r31-rswitch;
686             d                = (d>0.0) ? d : 0.0;
687             d2               = d*d;
688             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
689
690             dsw              = d2*(swF2+d*(swF3+d*swF4));
691
692             /* Evaluate switch function */
693             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
694             felec            = felec*sw - rinv31*velec*dsw;
695             velec           *= sw;
696
697             /* Update potential sums from outer loop */
698             velecsum        += velec;
699
700             fscal            = felec;
701
702             /* Calculate temporary vectorial force */
703             tx               = fscal*dx31;
704             ty               = fscal*dy31;
705             tz               = fscal*dz31;
706
707             /* Update vectorial force */
708             fix3            += tx;
709             fiy3            += ty;
710             fiz3            += tz;
711             f[j_coord_offset+DIM*1+XX] -= tx;
712             f[j_coord_offset+DIM*1+YY] -= ty;
713             f[j_coord_offset+DIM*1+ZZ] -= tz;
714
715             }
716
717             /**************************
718              * CALCULATE INTERACTIONS *
719              **************************/
720
721             if (rsq32<rcutoff2)
722             {
723
724             r32              = rsq32*rinv32;
725
726             /* EWALD ELECTROSTATICS */
727
728             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
729             ewrt             = r32*ewtabscale;
730             ewitab           = ewrt;
731             eweps            = ewrt-ewitab;
732             ewitab           = 4*ewitab;
733             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
734             velec            = qq32*(rinv32-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
735             felec            = qq32*rinv32*(rinvsq32-felec);
736
737             d                = r32-rswitch;
738             d                = (d>0.0) ? d : 0.0;
739             d2               = d*d;
740             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
741
742             dsw              = d2*(swF2+d*(swF3+d*swF4));
743
744             /* Evaluate switch function */
745             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
746             felec            = felec*sw - rinv32*velec*dsw;
747             velec           *= sw;
748
749             /* Update potential sums from outer loop */
750             velecsum        += velec;
751
752             fscal            = felec;
753
754             /* Calculate temporary vectorial force */
755             tx               = fscal*dx32;
756             ty               = fscal*dy32;
757             tz               = fscal*dz32;
758
759             /* Update vectorial force */
760             fix3            += tx;
761             fiy3            += ty;
762             fiz3            += tz;
763             f[j_coord_offset+DIM*2+XX] -= tx;
764             f[j_coord_offset+DIM*2+YY] -= ty;
765             f[j_coord_offset+DIM*2+ZZ] -= tz;
766
767             }
768
769             /**************************
770              * CALCULATE INTERACTIONS *
771              **************************/
772
773             if (rsq33<rcutoff2)
774             {
775
776             r33              = rsq33*rinv33;
777
778             /* EWALD ELECTROSTATICS */
779
780             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
781             ewrt             = r33*ewtabscale;
782             ewitab           = ewrt;
783             eweps            = ewrt-ewitab;
784             ewitab           = 4*ewitab;
785             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
786             velec            = qq33*(rinv33-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
787             felec            = qq33*rinv33*(rinvsq33-felec);
788
789             d                = r33-rswitch;
790             d                = (d>0.0) ? d : 0.0;
791             d2               = d*d;
792             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
793
794             dsw              = d2*(swF2+d*(swF3+d*swF4));
795
796             /* Evaluate switch function */
797             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
798             felec            = felec*sw - rinv33*velec*dsw;
799             velec           *= sw;
800
801             /* Update potential sums from outer loop */
802             velecsum        += velec;
803
804             fscal            = felec;
805
806             /* Calculate temporary vectorial force */
807             tx               = fscal*dx33;
808             ty               = fscal*dy33;
809             tz               = fscal*dz33;
810
811             /* Update vectorial force */
812             fix3            += tx;
813             fiy3            += ty;
814             fiz3            += tz;
815             f[j_coord_offset+DIM*3+XX] -= tx;
816             f[j_coord_offset+DIM*3+YY] -= ty;
817             f[j_coord_offset+DIM*3+ZZ] -= tz;
818
819             }
820
821             /* Inner loop uses 575 flops */
822         }
823         /* End of innermost loop */
824
825         tx = ty = tz = 0;
826         f[i_coord_offset+DIM*0+XX] += fix0;
827         f[i_coord_offset+DIM*0+YY] += fiy0;
828         f[i_coord_offset+DIM*0+ZZ] += fiz0;
829         tx                         += fix0;
830         ty                         += fiy0;
831         tz                         += fiz0;
832         f[i_coord_offset+DIM*1+XX] += fix1;
833         f[i_coord_offset+DIM*1+YY] += fiy1;
834         f[i_coord_offset+DIM*1+ZZ] += fiz1;
835         tx                         += fix1;
836         ty                         += fiy1;
837         tz                         += fiz1;
838         f[i_coord_offset+DIM*2+XX] += fix2;
839         f[i_coord_offset+DIM*2+YY] += fiy2;
840         f[i_coord_offset+DIM*2+ZZ] += fiz2;
841         tx                         += fix2;
842         ty                         += fiy2;
843         tz                         += fiz2;
844         f[i_coord_offset+DIM*3+XX] += fix3;
845         f[i_coord_offset+DIM*3+YY] += fiy3;
846         f[i_coord_offset+DIM*3+ZZ] += fiz3;
847         tx                         += fix3;
848         ty                         += fiy3;
849         tz                         += fiz3;
850         fshift[i_shift_offset+XX]  += tx;
851         fshift[i_shift_offset+YY]  += ty;
852         fshift[i_shift_offset+ZZ]  += tz;
853
854         ggid                        = gid[iidx];
855         /* Update potential energies */
856         kernel_data->energygrp_elec[ggid] += velecsum;
857         kernel_data->energygrp_vdw[ggid] += vvdwsum;
858
859         /* Increment number of inner iterations */
860         inneriter                  += j_index_end - j_index_start;
861
862         /* Outer loop uses 41 flops */
863     }
864
865     /* Increment number of outer iterations */
866     outeriter        += nri;
867
868     /* Update outer/inner flops */
869
870     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*41 + inneriter*575);
871 }
872 /*
873  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSw_VdwLJSw_GeomW4W4_F_c
874  * Electrostatics interaction: Ewald
875  * VdW interaction:            LennardJones
876  * Geometry:                   Water4-Water4
877  * Calculate force/pot:        Force
878  */
879 void
880 nb_kernel_ElecEwSw_VdwLJSw_GeomW4W4_F_c
881                     (t_nblist                    * gmx_restrict       nlist,
882                      rvec                        * gmx_restrict          xx,
883                      rvec                        * gmx_restrict          ff,
884                      t_forcerec                  * gmx_restrict          fr,
885                      t_mdatoms                   * gmx_restrict     mdatoms,
886                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
887                      t_nrnb                      * gmx_restrict        nrnb)
888 {
889     int              i_shift_offset,i_coord_offset,j_coord_offset;
890     int              j_index_start,j_index_end;
891     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
892     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
893     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
894     real             *shiftvec,*fshift,*x,*f;
895     int              vdwioffset0;
896     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
897     int              vdwioffset1;
898     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
899     int              vdwioffset2;
900     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
901     int              vdwioffset3;
902     real             ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
903     int              vdwjidx0;
904     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
905     int              vdwjidx1;
906     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
907     int              vdwjidx2;
908     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
909     int              vdwjidx3;
910     real             jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
911     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
912     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
913     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
914     real             dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13,cexp1_13,cexp2_13;
915     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
916     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
917     real             dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23,cexp1_23,cexp2_23;
918     real             dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31,cexp1_31,cexp2_31;
919     real             dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32,cexp1_32,cexp2_32;
920     real             dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33,cexp1_33,cexp2_33;
921     real             velec,felec,velecsum,facel,crf,krf,krf2;
922     real             *charge;
923     int              nvdwtype;
924     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
925     int              *vdwtype;
926     real             *vdwparam;
927     int              ewitab;
928     real             ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace;
929     real             *ewtab;
930     real             rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
931
932     x                = xx[0];
933     f                = ff[0];
934
935     nri              = nlist->nri;
936     iinr             = nlist->iinr;
937     jindex           = nlist->jindex;
938     jjnr             = nlist->jjnr;
939     shiftidx         = nlist->shift;
940     gid              = nlist->gid;
941     shiftvec         = fr->shift_vec[0];
942     fshift           = fr->fshift[0];
943     facel            = fr->epsfac;
944     charge           = mdatoms->chargeA;
945     nvdwtype         = fr->ntype;
946     vdwparam         = fr->nbfp;
947     vdwtype          = mdatoms->typeA;
948
949     sh_ewald         = fr->ic->sh_ewald;
950     ewtab            = fr->ic->tabq_coul_FDV0;
951     ewtabscale       = fr->ic->tabq_scale;
952     ewtabhalfspace   = 0.5/ewtabscale;
953
954     /* Setup water-specific parameters */
955     inr              = nlist->iinr[0];
956     iq1              = facel*charge[inr+1];
957     iq2              = facel*charge[inr+2];
958     iq3              = facel*charge[inr+3];
959     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
960
961     jq1              = charge[inr+1];
962     jq2              = charge[inr+2];
963     jq3              = charge[inr+3];
964     vdwjidx0         = 2*vdwtype[inr+0];
965     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
966     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
967     qq11             = iq1*jq1;
968     qq12             = iq1*jq2;
969     qq13             = iq1*jq3;
970     qq21             = iq2*jq1;
971     qq22             = iq2*jq2;
972     qq23             = iq2*jq3;
973     qq31             = iq3*jq1;
974     qq32             = iq3*jq2;
975     qq33             = iq3*jq3;
976
977     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
978     rcutoff          = fr->rcoulomb;
979     rcutoff2         = rcutoff*rcutoff;
980
981     rswitch          = fr->rcoulomb_switch;
982     /* Setup switch parameters */
983     d                = rcutoff-rswitch;
984     swV3             = -10.0/(d*d*d);
985     swV4             =  15.0/(d*d*d*d);
986     swV5             =  -6.0/(d*d*d*d*d);
987     swF2             = -30.0/(d*d*d);
988     swF3             =  60.0/(d*d*d*d);
989     swF4             = -30.0/(d*d*d*d*d);
990
991     outeriter        = 0;
992     inneriter        = 0;
993
994     /* Start outer loop over neighborlists */
995     for(iidx=0; iidx<nri; iidx++)
996     {
997         /* Load shift vector for this list */
998         i_shift_offset   = DIM*shiftidx[iidx];
999         shX              = shiftvec[i_shift_offset+XX];
1000         shY              = shiftvec[i_shift_offset+YY];
1001         shZ              = shiftvec[i_shift_offset+ZZ];
1002
1003         /* Load limits for loop over neighbors */
1004         j_index_start    = jindex[iidx];
1005         j_index_end      = jindex[iidx+1];
1006
1007         /* Get outer coordinate index */
1008         inr              = iinr[iidx];
1009         i_coord_offset   = DIM*inr;
1010
1011         /* Load i particle coords and add shift vector */
1012         ix0              = shX + x[i_coord_offset+DIM*0+XX];
1013         iy0              = shY + x[i_coord_offset+DIM*0+YY];
1014         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
1015         ix1              = shX + x[i_coord_offset+DIM*1+XX];
1016         iy1              = shY + x[i_coord_offset+DIM*1+YY];
1017         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
1018         ix2              = shX + x[i_coord_offset+DIM*2+XX];
1019         iy2              = shY + x[i_coord_offset+DIM*2+YY];
1020         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
1021         ix3              = shX + x[i_coord_offset+DIM*3+XX];
1022         iy3              = shY + x[i_coord_offset+DIM*3+YY];
1023         iz3              = shZ + x[i_coord_offset+DIM*3+ZZ];
1024
1025         fix0             = 0.0;
1026         fiy0             = 0.0;
1027         fiz0             = 0.0;
1028         fix1             = 0.0;
1029         fiy1             = 0.0;
1030         fiz1             = 0.0;
1031         fix2             = 0.0;
1032         fiy2             = 0.0;
1033         fiz2             = 0.0;
1034         fix3             = 0.0;
1035         fiy3             = 0.0;
1036         fiz3             = 0.0;
1037
1038         /* Start inner kernel loop */
1039         for(jidx=j_index_start; jidx<j_index_end; jidx++)
1040         {
1041             /* Get j neighbor index, and coordinate index */
1042             jnr              = jjnr[jidx];
1043             j_coord_offset   = DIM*jnr;
1044
1045             /* load j atom coordinates */
1046             jx0              = x[j_coord_offset+DIM*0+XX];
1047             jy0              = x[j_coord_offset+DIM*0+YY];
1048             jz0              = x[j_coord_offset+DIM*0+ZZ];
1049             jx1              = x[j_coord_offset+DIM*1+XX];
1050             jy1              = x[j_coord_offset+DIM*1+YY];
1051             jz1              = x[j_coord_offset+DIM*1+ZZ];
1052             jx2              = x[j_coord_offset+DIM*2+XX];
1053             jy2              = x[j_coord_offset+DIM*2+YY];
1054             jz2              = x[j_coord_offset+DIM*2+ZZ];
1055             jx3              = x[j_coord_offset+DIM*3+XX];
1056             jy3              = x[j_coord_offset+DIM*3+YY];
1057             jz3              = x[j_coord_offset+DIM*3+ZZ];
1058
1059             /* Calculate displacement vector */
1060             dx00             = ix0 - jx0;
1061             dy00             = iy0 - jy0;
1062             dz00             = iz0 - jz0;
1063             dx11             = ix1 - jx1;
1064             dy11             = iy1 - jy1;
1065             dz11             = iz1 - jz1;
1066             dx12             = ix1 - jx2;
1067             dy12             = iy1 - jy2;
1068             dz12             = iz1 - jz2;
1069             dx13             = ix1 - jx3;
1070             dy13             = iy1 - jy3;
1071             dz13             = iz1 - jz3;
1072             dx21             = ix2 - jx1;
1073             dy21             = iy2 - jy1;
1074             dz21             = iz2 - jz1;
1075             dx22             = ix2 - jx2;
1076             dy22             = iy2 - jy2;
1077             dz22             = iz2 - jz2;
1078             dx23             = ix2 - jx3;
1079             dy23             = iy2 - jy3;
1080             dz23             = iz2 - jz3;
1081             dx31             = ix3 - jx1;
1082             dy31             = iy3 - jy1;
1083             dz31             = iz3 - jz1;
1084             dx32             = ix3 - jx2;
1085             dy32             = iy3 - jy2;
1086             dz32             = iz3 - jz2;
1087             dx33             = ix3 - jx3;
1088             dy33             = iy3 - jy3;
1089             dz33             = iz3 - jz3;
1090
1091             /* Calculate squared distance and things based on it */
1092             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
1093             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
1094             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
1095             rsq13            = dx13*dx13+dy13*dy13+dz13*dz13;
1096             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
1097             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
1098             rsq23            = dx23*dx23+dy23*dy23+dz23*dz23;
1099             rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
1100             rsq32            = dx32*dx32+dy32*dy32+dz32*dz32;
1101             rsq33            = dx33*dx33+dy33*dy33+dz33*dz33;
1102
1103             rinv00           = gmx_invsqrt(rsq00);
1104             rinv11           = gmx_invsqrt(rsq11);
1105             rinv12           = gmx_invsqrt(rsq12);
1106             rinv13           = gmx_invsqrt(rsq13);
1107             rinv21           = gmx_invsqrt(rsq21);
1108             rinv22           = gmx_invsqrt(rsq22);
1109             rinv23           = gmx_invsqrt(rsq23);
1110             rinv31           = gmx_invsqrt(rsq31);
1111             rinv32           = gmx_invsqrt(rsq32);
1112             rinv33           = gmx_invsqrt(rsq33);
1113
1114             rinvsq00         = rinv00*rinv00;
1115             rinvsq11         = rinv11*rinv11;
1116             rinvsq12         = rinv12*rinv12;
1117             rinvsq13         = rinv13*rinv13;
1118             rinvsq21         = rinv21*rinv21;
1119             rinvsq22         = rinv22*rinv22;
1120             rinvsq23         = rinv23*rinv23;
1121             rinvsq31         = rinv31*rinv31;
1122             rinvsq32         = rinv32*rinv32;
1123             rinvsq33         = rinv33*rinv33;
1124
1125             /**************************
1126              * CALCULATE INTERACTIONS *
1127              **************************/
1128
1129             if (rsq00<rcutoff2)
1130             {
1131
1132             r00              = rsq00*rinv00;
1133
1134             /* LENNARD-JONES DISPERSION/REPULSION */
1135
1136             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
1137             vvdw6            = c6_00*rinvsix;
1138             vvdw12           = c12_00*rinvsix*rinvsix;
1139             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
1140             fvdw             = (vvdw12-vvdw6)*rinvsq00;
1141
1142             d                = r00-rswitch;
1143             d                = (d>0.0) ? d : 0.0;
1144             d2               = d*d;
1145             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1146
1147             dsw              = d2*(swF2+d*(swF3+d*swF4));
1148
1149             /* Evaluate switch function */
1150             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1151             fvdw             = fvdw*sw - rinv00*vvdw*dsw;
1152
1153             fscal            = fvdw;
1154
1155             /* Calculate temporary vectorial force */
1156             tx               = fscal*dx00;
1157             ty               = fscal*dy00;
1158             tz               = fscal*dz00;
1159
1160             /* Update vectorial force */
1161             fix0            += tx;
1162             fiy0            += ty;
1163             fiz0            += tz;
1164             f[j_coord_offset+DIM*0+XX] -= tx;
1165             f[j_coord_offset+DIM*0+YY] -= ty;
1166             f[j_coord_offset+DIM*0+ZZ] -= tz;
1167
1168             }
1169
1170             /**************************
1171              * CALCULATE INTERACTIONS *
1172              **************************/
1173
1174             if (rsq11<rcutoff2)
1175             {
1176
1177             r11              = rsq11*rinv11;
1178
1179             /* EWALD ELECTROSTATICS */
1180
1181             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1182             ewrt             = r11*ewtabscale;
1183             ewitab           = ewrt;
1184             eweps            = ewrt-ewitab;
1185             ewitab           = 4*ewitab;
1186             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1187             velec            = qq11*(rinv11-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1188             felec            = qq11*rinv11*(rinvsq11-felec);
1189
1190             d                = r11-rswitch;
1191             d                = (d>0.0) ? d : 0.0;
1192             d2               = d*d;
1193             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1194
1195             dsw              = d2*(swF2+d*(swF3+d*swF4));
1196
1197             /* Evaluate switch function */
1198             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1199             felec            = felec*sw - rinv11*velec*dsw;
1200
1201             fscal            = felec;
1202
1203             /* Calculate temporary vectorial force */
1204             tx               = fscal*dx11;
1205             ty               = fscal*dy11;
1206             tz               = fscal*dz11;
1207
1208             /* Update vectorial force */
1209             fix1            += tx;
1210             fiy1            += ty;
1211             fiz1            += tz;
1212             f[j_coord_offset+DIM*1+XX] -= tx;
1213             f[j_coord_offset+DIM*1+YY] -= ty;
1214             f[j_coord_offset+DIM*1+ZZ] -= tz;
1215
1216             }
1217
1218             /**************************
1219              * CALCULATE INTERACTIONS *
1220              **************************/
1221
1222             if (rsq12<rcutoff2)
1223             {
1224
1225             r12              = rsq12*rinv12;
1226
1227             /* EWALD ELECTROSTATICS */
1228
1229             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1230             ewrt             = r12*ewtabscale;
1231             ewitab           = ewrt;
1232             eweps            = ewrt-ewitab;
1233             ewitab           = 4*ewitab;
1234             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1235             velec            = qq12*(rinv12-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1236             felec            = qq12*rinv12*(rinvsq12-felec);
1237
1238             d                = r12-rswitch;
1239             d                = (d>0.0) ? d : 0.0;
1240             d2               = d*d;
1241             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1242
1243             dsw              = d2*(swF2+d*(swF3+d*swF4));
1244
1245             /* Evaluate switch function */
1246             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1247             felec            = felec*sw - rinv12*velec*dsw;
1248
1249             fscal            = felec;
1250
1251             /* Calculate temporary vectorial force */
1252             tx               = fscal*dx12;
1253             ty               = fscal*dy12;
1254             tz               = fscal*dz12;
1255
1256             /* Update vectorial force */
1257             fix1            += tx;
1258             fiy1            += ty;
1259             fiz1            += tz;
1260             f[j_coord_offset+DIM*2+XX] -= tx;
1261             f[j_coord_offset+DIM*2+YY] -= ty;
1262             f[j_coord_offset+DIM*2+ZZ] -= tz;
1263
1264             }
1265
1266             /**************************
1267              * CALCULATE INTERACTIONS *
1268              **************************/
1269
1270             if (rsq13<rcutoff2)
1271             {
1272
1273             r13              = rsq13*rinv13;
1274
1275             /* EWALD ELECTROSTATICS */
1276
1277             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1278             ewrt             = r13*ewtabscale;
1279             ewitab           = ewrt;
1280             eweps            = ewrt-ewitab;
1281             ewitab           = 4*ewitab;
1282             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1283             velec            = qq13*(rinv13-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1284             felec            = qq13*rinv13*(rinvsq13-felec);
1285
1286             d                = r13-rswitch;
1287             d                = (d>0.0) ? d : 0.0;
1288             d2               = d*d;
1289             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1290
1291             dsw              = d2*(swF2+d*(swF3+d*swF4));
1292
1293             /* Evaluate switch function */
1294             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1295             felec            = felec*sw - rinv13*velec*dsw;
1296
1297             fscal            = felec;
1298
1299             /* Calculate temporary vectorial force */
1300             tx               = fscal*dx13;
1301             ty               = fscal*dy13;
1302             tz               = fscal*dz13;
1303
1304             /* Update vectorial force */
1305             fix1            += tx;
1306             fiy1            += ty;
1307             fiz1            += tz;
1308             f[j_coord_offset+DIM*3+XX] -= tx;
1309             f[j_coord_offset+DIM*3+YY] -= ty;
1310             f[j_coord_offset+DIM*3+ZZ] -= tz;
1311
1312             }
1313
1314             /**************************
1315              * CALCULATE INTERACTIONS *
1316              **************************/
1317
1318             if (rsq21<rcutoff2)
1319             {
1320
1321             r21              = rsq21*rinv21;
1322
1323             /* EWALD ELECTROSTATICS */
1324
1325             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1326             ewrt             = r21*ewtabscale;
1327             ewitab           = ewrt;
1328             eweps            = ewrt-ewitab;
1329             ewitab           = 4*ewitab;
1330             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1331             velec            = qq21*(rinv21-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1332             felec            = qq21*rinv21*(rinvsq21-felec);
1333
1334             d                = r21-rswitch;
1335             d                = (d>0.0) ? d : 0.0;
1336             d2               = d*d;
1337             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1338
1339             dsw              = d2*(swF2+d*(swF3+d*swF4));
1340
1341             /* Evaluate switch function */
1342             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1343             felec            = felec*sw - rinv21*velec*dsw;
1344
1345             fscal            = felec;
1346
1347             /* Calculate temporary vectorial force */
1348             tx               = fscal*dx21;
1349             ty               = fscal*dy21;
1350             tz               = fscal*dz21;
1351
1352             /* Update vectorial force */
1353             fix2            += tx;
1354             fiy2            += ty;
1355             fiz2            += tz;
1356             f[j_coord_offset+DIM*1+XX] -= tx;
1357             f[j_coord_offset+DIM*1+YY] -= ty;
1358             f[j_coord_offset+DIM*1+ZZ] -= tz;
1359
1360             }
1361
1362             /**************************
1363              * CALCULATE INTERACTIONS *
1364              **************************/
1365
1366             if (rsq22<rcutoff2)
1367             {
1368
1369             r22              = rsq22*rinv22;
1370
1371             /* EWALD ELECTROSTATICS */
1372
1373             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1374             ewrt             = r22*ewtabscale;
1375             ewitab           = ewrt;
1376             eweps            = ewrt-ewitab;
1377             ewitab           = 4*ewitab;
1378             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1379             velec            = qq22*(rinv22-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1380             felec            = qq22*rinv22*(rinvsq22-felec);
1381
1382             d                = r22-rswitch;
1383             d                = (d>0.0) ? d : 0.0;
1384             d2               = d*d;
1385             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1386
1387             dsw              = d2*(swF2+d*(swF3+d*swF4));
1388
1389             /* Evaluate switch function */
1390             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1391             felec            = felec*sw - rinv22*velec*dsw;
1392
1393             fscal            = felec;
1394
1395             /* Calculate temporary vectorial force */
1396             tx               = fscal*dx22;
1397             ty               = fscal*dy22;
1398             tz               = fscal*dz22;
1399
1400             /* Update vectorial force */
1401             fix2            += tx;
1402             fiy2            += ty;
1403             fiz2            += tz;
1404             f[j_coord_offset+DIM*2+XX] -= tx;
1405             f[j_coord_offset+DIM*2+YY] -= ty;
1406             f[j_coord_offset+DIM*2+ZZ] -= tz;
1407
1408             }
1409
1410             /**************************
1411              * CALCULATE INTERACTIONS *
1412              **************************/
1413
1414             if (rsq23<rcutoff2)
1415             {
1416
1417             r23              = rsq23*rinv23;
1418
1419             /* EWALD ELECTROSTATICS */
1420
1421             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1422             ewrt             = r23*ewtabscale;
1423             ewitab           = ewrt;
1424             eweps            = ewrt-ewitab;
1425             ewitab           = 4*ewitab;
1426             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1427             velec            = qq23*(rinv23-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1428             felec            = qq23*rinv23*(rinvsq23-felec);
1429
1430             d                = r23-rswitch;
1431             d                = (d>0.0) ? d : 0.0;
1432             d2               = d*d;
1433             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1434
1435             dsw              = d2*(swF2+d*(swF3+d*swF4));
1436
1437             /* Evaluate switch function */
1438             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1439             felec            = felec*sw - rinv23*velec*dsw;
1440
1441             fscal            = felec;
1442
1443             /* Calculate temporary vectorial force */
1444             tx               = fscal*dx23;
1445             ty               = fscal*dy23;
1446             tz               = fscal*dz23;
1447
1448             /* Update vectorial force */
1449             fix2            += tx;
1450             fiy2            += ty;
1451             fiz2            += tz;
1452             f[j_coord_offset+DIM*3+XX] -= tx;
1453             f[j_coord_offset+DIM*3+YY] -= ty;
1454             f[j_coord_offset+DIM*3+ZZ] -= tz;
1455
1456             }
1457
1458             /**************************
1459              * CALCULATE INTERACTIONS *
1460              **************************/
1461
1462             if (rsq31<rcutoff2)
1463             {
1464
1465             r31              = rsq31*rinv31;
1466
1467             /* EWALD ELECTROSTATICS */
1468
1469             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1470             ewrt             = r31*ewtabscale;
1471             ewitab           = ewrt;
1472             eweps            = ewrt-ewitab;
1473             ewitab           = 4*ewitab;
1474             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1475             velec            = qq31*(rinv31-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1476             felec            = qq31*rinv31*(rinvsq31-felec);
1477
1478             d                = r31-rswitch;
1479             d                = (d>0.0) ? d : 0.0;
1480             d2               = d*d;
1481             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1482
1483             dsw              = d2*(swF2+d*(swF3+d*swF4));
1484
1485             /* Evaluate switch function */
1486             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1487             felec            = felec*sw - rinv31*velec*dsw;
1488
1489             fscal            = felec;
1490
1491             /* Calculate temporary vectorial force */
1492             tx               = fscal*dx31;
1493             ty               = fscal*dy31;
1494             tz               = fscal*dz31;
1495
1496             /* Update vectorial force */
1497             fix3            += tx;
1498             fiy3            += ty;
1499             fiz3            += tz;
1500             f[j_coord_offset+DIM*1+XX] -= tx;
1501             f[j_coord_offset+DIM*1+YY] -= ty;
1502             f[j_coord_offset+DIM*1+ZZ] -= tz;
1503
1504             }
1505
1506             /**************************
1507              * CALCULATE INTERACTIONS *
1508              **************************/
1509
1510             if (rsq32<rcutoff2)
1511             {
1512
1513             r32              = rsq32*rinv32;
1514
1515             /* EWALD ELECTROSTATICS */
1516
1517             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1518             ewrt             = r32*ewtabscale;
1519             ewitab           = ewrt;
1520             eweps            = ewrt-ewitab;
1521             ewitab           = 4*ewitab;
1522             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1523             velec            = qq32*(rinv32-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1524             felec            = qq32*rinv32*(rinvsq32-felec);
1525
1526             d                = r32-rswitch;
1527             d                = (d>0.0) ? d : 0.0;
1528             d2               = d*d;
1529             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1530
1531             dsw              = d2*(swF2+d*(swF3+d*swF4));
1532
1533             /* Evaluate switch function */
1534             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1535             felec            = felec*sw - rinv32*velec*dsw;
1536
1537             fscal            = felec;
1538
1539             /* Calculate temporary vectorial force */
1540             tx               = fscal*dx32;
1541             ty               = fscal*dy32;
1542             tz               = fscal*dz32;
1543
1544             /* Update vectorial force */
1545             fix3            += tx;
1546             fiy3            += ty;
1547             fiz3            += tz;
1548             f[j_coord_offset+DIM*2+XX] -= tx;
1549             f[j_coord_offset+DIM*2+YY] -= ty;
1550             f[j_coord_offset+DIM*2+ZZ] -= tz;
1551
1552             }
1553
1554             /**************************
1555              * CALCULATE INTERACTIONS *
1556              **************************/
1557
1558             if (rsq33<rcutoff2)
1559             {
1560
1561             r33              = rsq33*rinv33;
1562
1563             /* EWALD ELECTROSTATICS */
1564
1565             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1566             ewrt             = r33*ewtabscale;
1567             ewitab           = ewrt;
1568             eweps            = ewrt-ewitab;
1569             ewitab           = 4*ewitab;
1570             felec            = ewtab[ewitab]+eweps*ewtab[ewitab+1];
1571             velec            = qq33*(rinv33-(ewtab[ewitab+2]-ewtabhalfspace*eweps*(ewtab[ewitab]+felec)));
1572             felec            = qq33*rinv33*(rinvsq33-felec);
1573
1574             d                = r33-rswitch;
1575             d                = (d>0.0) ? d : 0.0;
1576             d2               = d*d;
1577             sw               = 1.0+d2*d*(swV3+d*(swV4+d*swV5));
1578
1579             dsw              = d2*(swF2+d*(swF3+d*swF4));
1580
1581             /* Evaluate switch function */
1582             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1583             felec            = felec*sw - rinv33*velec*dsw;
1584
1585             fscal            = felec;
1586
1587             /* Calculate temporary vectorial force */
1588             tx               = fscal*dx33;
1589             ty               = fscal*dy33;
1590             tz               = fscal*dz33;
1591
1592             /* Update vectorial force */
1593             fix3            += tx;
1594             fiy3            += ty;
1595             fiz3            += tz;
1596             f[j_coord_offset+DIM*3+XX] -= tx;
1597             f[j_coord_offset+DIM*3+YY] -= ty;
1598             f[j_coord_offset+DIM*3+ZZ] -= tz;
1599
1600             }
1601
1602             /* Inner loop uses 555 flops */
1603         }
1604         /* End of innermost loop */
1605
1606         tx = ty = tz = 0;
1607         f[i_coord_offset+DIM*0+XX] += fix0;
1608         f[i_coord_offset+DIM*0+YY] += fiy0;
1609         f[i_coord_offset+DIM*0+ZZ] += fiz0;
1610         tx                         += fix0;
1611         ty                         += fiy0;
1612         tz                         += fiz0;
1613         f[i_coord_offset+DIM*1+XX] += fix1;
1614         f[i_coord_offset+DIM*1+YY] += fiy1;
1615         f[i_coord_offset+DIM*1+ZZ] += fiz1;
1616         tx                         += fix1;
1617         ty                         += fiy1;
1618         tz                         += fiz1;
1619         f[i_coord_offset+DIM*2+XX] += fix2;
1620         f[i_coord_offset+DIM*2+YY] += fiy2;
1621         f[i_coord_offset+DIM*2+ZZ] += fiz2;
1622         tx                         += fix2;
1623         ty                         += fiy2;
1624         tz                         += fiz2;
1625         f[i_coord_offset+DIM*3+XX] += fix3;
1626         f[i_coord_offset+DIM*3+YY] += fiy3;
1627         f[i_coord_offset+DIM*3+ZZ] += fiz3;
1628         tx                         += fix3;
1629         ty                         += fiy3;
1630         tz                         += fiz3;
1631         fshift[i_shift_offset+XX]  += tx;
1632         fshift[i_shift_offset+YY]  += ty;
1633         fshift[i_shift_offset+ZZ]  += tz;
1634
1635         /* Increment number of inner iterations */
1636         inneriter                  += j_index_end - j_index_start;
1637
1638         /* Outer loop uses 39 flops */
1639     }
1640
1641     /* Increment number of outer iterations */
1642     outeriter        += nri;
1643
1644     /* Update outer/inner flops */
1645
1646     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*39 + inneriter*555);
1647 }