Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCoul_VdwLJ_GeomW3W3_c.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS c kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW3W3_VF_c
51  * Electrostatics interaction: Coulomb
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water3-Water3
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecCoul_VdwLJ_GeomW3W3_VF_c
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      t_forcerec                  * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     int              i_shift_offset,i_coord_offset,j_coord_offset;
67     int              j_index_start,j_index_end;
68     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
69     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
70     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
71     real             *shiftvec,*fshift,*x,*f;
72     int              vdwioffset0;
73     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
74     int              vdwioffset1;
75     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
76     int              vdwioffset2;
77     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
78     int              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     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
85     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
86     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
87     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
88     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
89     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
90     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
91     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
92     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
93     real             velec,felec,velecsum,facel,crf,krf,krf2;
94     real             *charge;
95     int              nvdwtype;
96     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
97     int              *vdwtype;
98     real             *vdwparam;
99
100     x                = xx[0];
101     f                = ff[0];
102
103     nri              = nlist->nri;
104     iinr             = nlist->iinr;
105     jindex           = nlist->jindex;
106     jjnr             = nlist->jjnr;
107     shiftidx         = nlist->shift;
108     gid              = nlist->gid;
109     shiftvec         = fr->shift_vec[0];
110     fshift           = fr->fshift[0];
111     facel            = fr->epsfac;
112     charge           = mdatoms->chargeA;
113     nvdwtype         = fr->ntype;
114     vdwparam         = fr->nbfp;
115     vdwtype          = mdatoms->typeA;
116
117     /* Setup water-specific parameters */
118     inr              = nlist->iinr[0];
119     iq0              = facel*charge[inr+0];
120     iq1              = facel*charge[inr+1];
121     iq2              = facel*charge[inr+2];
122     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
123
124     jq0              = charge[inr+0];
125     jq1              = charge[inr+1];
126     jq2              = charge[inr+2];
127     vdwjidx0         = 2*vdwtype[inr+0];
128     qq00             = iq0*jq0;
129     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
130     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
131     qq01             = iq0*jq1;
132     qq02             = iq0*jq2;
133     qq10             = iq1*jq0;
134     qq11             = iq1*jq1;
135     qq12             = iq1*jq2;
136     qq20             = iq2*jq0;
137     qq21             = iq2*jq1;
138     qq22             = iq2*jq2;
139
140     outeriter        = 0;
141     inneriter        = 0;
142
143     /* Start outer loop over neighborlists */
144     for(iidx=0; iidx<nri; iidx++)
145     {
146         /* Load shift vector for this list */
147         i_shift_offset   = DIM*shiftidx[iidx];
148         shX              = shiftvec[i_shift_offset+XX];
149         shY              = shiftvec[i_shift_offset+YY];
150         shZ              = shiftvec[i_shift_offset+ZZ];
151
152         /* Load limits for loop over neighbors */
153         j_index_start    = jindex[iidx];
154         j_index_end      = jindex[iidx+1];
155
156         /* Get outer coordinate index */
157         inr              = iinr[iidx];
158         i_coord_offset   = DIM*inr;
159
160         /* Load i particle coords and add shift vector */
161         ix0              = shX + x[i_coord_offset+DIM*0+XX];
162         iy0              = shY + x[i_coord_offset+DIM*0+YY];
163         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
164         ix1              = shX + x[i_coord_offset+DIM*1+XX];
165         iy1              = shY + x[i_coord_offset+DIM*1+YY];
166         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
167         ix2              = shX + x[i_coord_offset+DIM*2+XX];
168         iy2              = shY + x[i_coord_offset+DIM*2+YY];
169         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
170
171         fix0             = 0.0;
172         fiy0             = 0.0;
173         fiz0             = 0.0;
174         fix1             = 0.0;
175         fiy1             = 0.0;
176         fiz1             = 0.0;
177         fix2             = 0.0;
178         fiy2             = 0.0;
179         fiz2             = 0.0;
180
181         /* Reset potential sums */
182         velecsum         = 0.0;
183         vvdwsum          = 0.0;
184
185         /* Start inner kernel loop */
186         for(jidx=j_index_start; jidx<j_index_end; jidx++)
187         {
188             /* Get j neighbor index, and coordinate index */
189             jnr              = jjnr[jidx];
190             j_coord_offset   = DIM*jnr;
191
192             /* load j atom coordinates */
193             jx0              = x[j_coord_offset+DIM*0+XX];
194             jy0              = x[j_coord_offset+DIM*0+YY];
195             jz0              = x[j_coord_offset+DIM*0+ZZ];
196             jx1              = x[j_coord_offset+DIM*1+XX];
197             jy1              = x[j_coord_offset+DIM*1+YY];
198             jz1              = x[j_coord_offset+DIM*1+ZZ];
199             jx2              = x[j_coord_offset+DIM*2+XX];
200             jy2              = x[j_coord_offset+DIM*2+YY];
201             jz2              = x[j_coord_offset+DIM*2+ZZ];
202
203             /* Calculate displacement vector */
204             dx00             = ix0 - jx0;
205             dy00             = iy0 - jy0;
206             dz00             = iz0 - jz0;
207             dx01             = ix0 - jx1;
208             dy01             = iy0 - jy1;
209             dz01             = iz0 - jz1;
210             dx02             = ix0 - jx2;
211             dy02             = iy0 - jy2;
212             dz02             = iz0 - jz2;
213             dx10             = ix1 - jx0;
214             dy10             = iy1 - jy0;
215             dz10             = iz1 - jz0;
216             dx11             = ix1 - jx1;
217             dy11             = iy1 - jy1;
218             dz11             = iz1 - jz1;
219             dx12             = ix1 - jx2;
220             dy12             = iy1 - jy2;
221             dz12             = iz1 - jz2;
222             dx20             = ix2 - jx0;
223             dy20             = iy2 - jy0;
224             dz20             = iz2 - jz0;
225             dx21             = ix2 - jx1;
226             dy21             = iy2 - jy1;
227             dz21             = iz2 - jz1;
228             dx22             = ix2 - jx2;
229             dy22             = iy2 - jy2;
230             dz22             = iz2 - jz2;
231
232             /* Calculate squared distance and things based on it */
233             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
234             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
235             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
236             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
237             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
238             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
239             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
240             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
241             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
242
243             rinv00           = gmx_invsqrt(rsq00);
244             rinv01           = gmx_invsqrt(rsq01);
245             rinv02           = gmx_invsqrt(rsq02);
246             rinv10           = gmx_invsqrt(rsq10);
247             rinv11           = gmx_invsqrt(rsq11);
248             rinv12           = gmx_invsqrt(rsq12);
249             rinv20           = gmx_invsqrt(rsq20);
250             rinv21           = gmx_invsqrt(rsq21);
251             rinv22           = gmx_invsqrt(rsq22);
252
253             rinvsq00         = rinv00*rinv00;
254             rinvsq01         = rinv01*rinv01;
255             rinvsq02         = rinv02*rinv02;
256             rinvsq10         = rinv10*rinv10;
257             rinvsq11         = rinv11*rinv11;
258             rinvsq12         = rinv12*rinv12;
259             rinvsq20         = rinv20*rinv20;
260             rinvsq21         = rinv21*rinv21;
261             rinvsq22         = rinv22*rinv22;
262
263             /**************************
264              * CALCULATE INTERACTIONS *
265              **************************/
266
267             /* COULOMB ELECTROSTATICS */
268             velec            = qq00*rinv00;
269             felec            = velec*rinvsq00;
270
271             /* LENNARD-JONES DISPERSION/REPULSION */
272
273             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
274             vvdw6            = c6_00*rinvsix;
275             vvdw12           = c12_00*rinvsix*rinvsix;
276             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
277             fvdw             = (vvdw12-vvdw6)*rinvsq00;
278
279             /* Update potential sums from outer loop */
280             velecsum        += velec;
281             vvdwsum         += vvdw;
282
283             fscal            = felec+fvdw;
284
285             /* Calculate temporary vectorial force */
286             tx               = fscal*dx00;
287             ty               = fscal*dy00;
288             tz               = fscal*dz00;
289
290             /* Update vectorial force */
291             fix0            += tx;
292             fiy0            += ty;
293             fiz0            += tz;
294             f[j_coord_offset+DIM*0+XX] -= tx;
295             f[j_coord_offset+DIM*0+YY] -= ty;
296             f[j_coord_offset+DIM*0+ZZ] -= tz;
297
298             /**************************
299              * CALCULATE INTERACTIONS *
300              **************************/
301
302             /* COULOMB ELECTROSTATICS */
303             velec            = qq01*rinv01;
304             felec            = velec*rinvsq01;
305
306             /* Update potential sums from outer loop */
307             velecsum        += velec;
308
309             fscal            = felec;
310
311             /* Calculate temporary vectorial force */
312             tx               = fscal*dx01;
313             ty               = fscal*dy01;
314             tz               = fscal*dz01;
315
316             /* Update vectorial force */
317             fix0            += tx;
318             fiy0            += ty;
319             fiz0            += tz;
320             f[j_coord_offset+DIM*1+XX] -= tx;
321             f[j_coord_offset+DIM*1+YY] -= ty;
322             f[j_coord_offset+DIM*1+ZZ] -= tz;
323
324             /**************************
325              * CALCULATE INTERACTIONS *
326              **************************/
327
328             /* COULOMB ELECTROSTATICS */
329             velec            = qq02*rinv02;
330             felec            = velec*rinvsq02;
331
332             /* Update potential sums from outer loop */
333             velecsum        += velec;
334
335             fscal            = felec;
336
337             /* Calculate temporary vectorial force */
338             tx               = fscal*dx02;
339             ty               = fscal*dy02;
340             tz               = fscal*dz02;
341
342             /* Update vectorial force */
343             fix0            += tx;
344             fiy0            += ty;
345             fiz0            += tz;
346             f[j_coord_offset+DIM*2+XX] -= tx;
347             f[j_coord_offset+DIM*2+YY] -= ty;
348             f[j_coord_offset+DIM*2+ZZ] -= tz;
349
350             /**************************
351              * CALCULATE INTERACTIONS *
352              **************************/
353
354             /* COULOMB ELECTROSTATICS */
355             velec            = qq10*rinv10;
356             felec            = velec*rinvsq10;
357
358             /* Update potential sums from outer loop */
359             velecsum        += velec;
360
361             fscal            = felec;
362
363             /* Calculate temporary vectorial force */
364             tx               = fscal*dx10;
365             ty               = fscal*dy10;
366             tz               = fscal*dz10;
367
368             /* Update vectorial force */
369             fix1            += tx;
370             fiy1            += ty;
371             fiz1            += tz;
372             f[j_coord_offset+DIM*0+XX] -= tx;
373             f[j_coord_offset+DIM*0+YY] -= ty;
374             f[j_coord_offset+DIM*0+ZZ] -= tz;
375
376             /**************************
377              * CALCULATE INTERACTIONS *
378              **************************/
379
380             /* COULOMB ELECTROSTATICS */
381             velec            = qq11*rinv11;
382             felec            = velec*rinvsq11;
383
384             /* Update potential sums from outer loop */
385             velecsum        += velec;
386
387             fscal            = felec;
388
389             /* Calculate temporary vectorial force */
390             tx               = fscal*dx11;
391             ty               = fscal*dy11;
392             tz               = fscal*dz11;
393
394             /* Update vectorial force */
395             fix1            += tx;
396             fiy1            += ty;
397             fiz1            += tz;
398             f[j_coord_offset+DIM*1+XX] -= tx;
399             f[j_coord_offset+DIM*1+YY] -= ty;
400             f[j_coord_offset+DIM*1+ZZ] -= tz;
401
402             /**************************
403              * CALCULATE INTERACTIONS *
404              **************************/
405
406             /* COULOMB ELECTROSTATICS */
407             velec            = qq12*rinv12;
408             felec            = velec*rinvsq12;
409
410             /* Update potential sums from outer loop */
411             velecsum        += velec;
412
413             fscal            = felec;
414
415             /* Calculate temporary vectorial force */
416             tx               = fscal*dx12;
417             ty               = fscal*dy12;
418             tz               = fscal*dz12;
419
420             /* Update vectorial force */
421             fix1            += tx;
422             fiy1            += ty;
423             fiz1            += tz;
424             f[j_coord_offset+DIM*2+XX] -= tx;
425             f[j_coord_offset+DIM*2+YY] -= ty;
426             f[j_coord_offset+DIM*2+ZZ] -= tz;
427
428             /**************************
429              * CALCULATE INTERACTIONS *
430              **************************/
431
432             /* COULOMB ELECTROSTATICS */
433             velec            = qq20*rinv20;
434             felec            = velec*rinvsq20;
435
436             /* Update potential sums from outer loop */
437             velecsum        += velec;
438
439             fscal            = felec;
440
441             /* Calculate temporary vectorial force */
442             tx               = fscal*dx20;
443             ty               = fscal*dy20;
444             tz               = fscal*dz20;
445
446             /* Update vectorial force */
447             fix2            += tx;
448             fiy2            += ty;
449             fiz2            += tz;
450             f[j_coord_offset+DIM*0+XX] -= tx;
451             f[j_coord_offset+DIM*0+YY] -= ty;
452             f[j_coord_offset+DIM*0+ZZ] -= tz;
453
454             /**************************
455              * CALCULATE INTERACTIONS *
456              **************************/
457
458             /* COULOMB ELECTROSTATICS */
459             velec            = qq21*rinv21;
460             felec            = velec*rinvsq21;
461
462             /* Update potential sums from outer loop */
463             velecsum        += velec;
464
465             fscal            = felec;
466
467             /* Calculate temporary vectorial force */
468             tx               = fscal*dx21;
469             ty               = fscal*dy21;
470             tz               = fscal*dz21;
471
472             /* Update vectorial force */
473             fix2            += tx;
474             fiy2            += ty;
475             fiz2            += tz;
476             f[j_coord_offset+DIM*1+XX] -= tx;
477             f[j_coord_offset+DIM*1+YY] -= ty;
478             f[j_coord_offset+DIM*1+ZZ] -= tz;
479
480             /**************************
481              * CALCULATE INTERACTIONS *
482              **************************/
483
484             /* COULOMB ELECTROSTATICS */
485             velec            = qq22*rinv22;
486             felec            = velec*rinvsq22;
487
488             /* Update potential sums from outer loop */
489             velecsum        += velec;
490
491             fscal            = felec;
492
493             /* Calculate temporary vectorial force */
494             tx               = fscal*dx22;
495             ty               = fscal*dy22;
496             tz               = fscal*dz22;
497
498             /* Update vectorial force */
499             fix2            += tx;
500             fiy2            += ty;
501             fiz2            += tz;
502             f[j_coord_offset+DIM*2+XX] -= tx;
503             f[j_coord_offset+DIM*2+YY] -= ty;
504             f[j_coord_offset+DIM*2+ZZ] -= tz;
505
506             /* Inner loop uses 255 flops */
507         }
508         /* End of innermost loop */
509
510         tx = ty = tz = 0;
511         f[i_coord_offset+DIM*0+XX] += fix0;
512         f[i_coord_offset+DIM*0+YY] += fiy0;
513         f[i_coord_offset+DIM*0+ZZ] += fiz0;
514         tx                         += fix0;
515         ty                         += fiy0;
516         tz                         += fiz0;
517         f[i_coord_offset+DIM*1+XX] += fix1;
518         f[i_coord_offset+DIM*1+YY] += fiy1;
519         f[i_coord_offset+DIM*1+ZZ] += fiz1;
520         tx                         += fix1;
521         ty                         += fiy1;
522         tz                         += fiz1;
523         f[i_coord_offset+DIM*2+XX] += fix2;
524         f[i_coord_offset+DIM*2+YY] += fiy2;
525         f[i_coord_offset+DIM*2+ZZ] += fiz2;
526         tx                         += fix2;
527         ty                         += fiy2;
528         tz                         += fiz2;
529         fshift[i_shift_offset+XX]  += tx;
530         fshift[i_shift_offset+YY]  += ty;
531         fshift[i_shift_offset+ZZ]  += tz;
532
533         ggid                        = gid[iidx];
534         /* Update potential energies */
535         kernel_data->energygrp_elec[ggid] += velecsum;
536         kernel_data->energygrp_vdw[ggid] += vvdwsum;
537
538         /* Increment number of inner iterations */
539         inneriter                  += j_index_end - j_index_start;
540
541         /* Outer loop uses 32 flops */
542     }
543
544     /* Increment number of outer iterations */
545     outeriter        += nri;
546
547     /* Update outer/inner flops */
548
549     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*32 + inneriter*255);
550 }
551 /*
552  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW3W3_F_c
553  * Electrostatics interaction: Coulomb
554  * VdW interaction:            LennardJones
555  * Geometry:                   Water3-Water3
556  * Calculate force/pot:        Force
557  */
558 void
559 nb_kernel_ElecCoul_VdwLJ_GeomW3W3_F_c
560                     (t_nblist                    * gmx_restrict       nlist,
561                      rvec                        * gmx_restrict          xx,
562                      rvec                        * gmx_restrict          ff,
563                      t_forcerec                  * gmx_restrict          fr,
564                      t_mdatoms                   * gmx_restrict     mdatoms,
565                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
566                      t_nrnb                      * gmx_restrict        nrnb)
567 {
568     int              i_shift_offset,i_coord_offset,j_coord_offset;
569     int              j_index_start,j_index_end;
570     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
571     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
572     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
573     real             *shiftvec,*fshift,*x,*f;
574     int              vdwioffset0;
575     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
576     int              vdwioffset1;
577     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
578     int              vdwioffset2;
579     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
580     int              vdwjidx0;
581     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
582     int              vdwjidx1;
583     real             jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
584     int              vdwjidx2;
585     real             jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
586     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
587     real             dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01,cexp1_01,cexp2_01;
588     real             dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02,cexp1_02,cexp2_02;
589     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
590     real             dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11,cexp1_11,cexp2_11;
591     real             dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12,cexp1_12,cexp2_12;
592     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
593     real             dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21,cexp1_21,cexp2_21;
594     real             dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22,cexp1_22,cexp2_22;
595     real             velec,felec,velecsum,facel,crf,krf,krf2;
596     real             *charge;
597     int              nvdwtype;
598     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
599     int              *vdwtype;
600     real             *vdwparam;
601
602     x                = xx[0];
603     f                = ff[0];
604
605     nri              = nlist->nri;
606     iinr             = nlist->iinr;
607     jindex           = nlist->jindex;
608     jjnr             = nlist->jjnr;
609     shiftidx         = nlist->shift;
610     gid              = nlist->gid;
611     shiftvec         = fr->shift_vec[0];
612     fshift           = fr->fshift[0];
613     facel            = fr->epsfac;
614     charge           = mdatoms->chargeA;
615     nvdwtype         = fr->ntype;
616     vdwparam         = fr->nbfp;
617     vdwtype          = mdatoms->typeA;
618
619     /* Setup water-specific parameters */
620     inr              = nlist->iinr[0];
621     iq0              = facel*charge[inr+0];
622     iq1              = facel*charge[inr+1];
623     iq2              = facel*charge[inr+2];
624     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
625
626     jq0              = charge[inr+0];
627     jq1              = charge[inr+1];
628     jq2              = charge[inr+2];
629     vdwjidx0         = 2*vdwtype[inr+0];
630     qq00             = iq0*jq0;
631     c6_00            = vdwparam[vdwioffset0+vdwjidx0];
632     c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
633     qq01             = iq0*jq1;
634     qq02             = iq0*jq2;
635     qq10             = iq1*jq0;
636     qq11             = iq1*jq1;
637     qq12             = iq1*jq2;
638     qq20             = iq2*jq0;
639     qq21             = iq2*jq1;
640     qq22             = iq2*jq2;
641
642     outeriter        = 0;
643     inneriter        = 0;
644
645     /* Start outer loop over neighborlists */
646     for(iidx=0; iidx<nri; iidx++)
647     {
648         /* Load shift vector for this list */
649         i_shift_offset   = DIM*shiftidx[iidx];
650         shX              = shiftvec[i_shift_offset+XX];
651         shY              = shiftvec[i_shift_offset+YY];
652         shZ              = shiftvec[i_shift_offset+ZZ];
653
654         /* Load limits for loop over neighbors */
655         j_index_start    = jindex[iidx];
656         j_index_end      = jindex[iidx+1];
657
658         /* Get outer coordinate index */
659         inr              = iinr[iidx];
660         i_coord_offset   = DIM*inr;
661
662         /* Load i particle coords and add shift vector */
663         ix0              = shX + x[i_coord_offset+DIM*0+XX];
664         iy0              = shY + x[i_coord_offset+DIM*0+YY];
665         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
666         ix1              = shX + x[i_coord_offset+DIM*1+XX];
667         iy1              = shY + x[i_coord_offset+DIM*1+YY];
668         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
669         ix2              = shX + x[i_coord_offset+DIM*2+XX];
670         iy2              = shY + x[i_coord_offset+DIM*2+YY];
671         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
672
673         fix0             = 0.0;
674         fiy0             = 0.0;
675         fiz0             = 0.0;
676         fix1             = 0.0;
677         fiy1             = 0.0;
678         fiz1             = 0.0;
679         fix2             = 0.0;
680         fiy2             = 0.0;
681         fiz2             = 0.0;
682
683         /* Start inner kernel loop */
684         for(jidx=j_index_start; jidx<j_index_end; jidx++)
685         {
686             /* Get j neighbor index, and coordinate index */
687             jnr              = jjnr[jidx];
688             j_coord_offset   = DIM*jnr;
689
690             /* load j atom coordinates */
691             jx0              = x[j_coord_offset+DIM*0+XX];
692             jy0              = x[j_coord_offset+DIM*0+YY];
693             jz0              = x[j_coord_offset+DIM*0+ZZ];
694             jx1              = x[j_coord_offset+DIM*1+XX];
695             jy1              = x[j_coord_offset+DIM*1+YY];
696             jz1              = x[j_coord_offset+DIM*1+ZZ];
697             jx2              = x[j_coord_offset+DIM*2+XX];
698             jy2              = x[j_coord_offset+DIM*2+YY];
699             jz2              = x[j_coord_offset+DIM*2+ZZ];
700
701             /* Calculate displacement vector */
702             dx00             = ix0 - jx0;
703             dy00             = iy0 - jy0;
704             dz00             = iz0 - jz0;
705             dx01             = ix0 - jx1;
706             dy01             = iy0 - jy1;
707             dz01             = iz0 - jz1;
708             dx02             = ix0 - jx2;
709             dy02             = iy0 - jy2;
710             dz02             = iz0 - jz2;
711             dx10             = ix1 - jx0;
712             dy10             = iy1 - jy0;
713             dz10             = iz1 - jz0;
714             dx11             = ix1 - jx1;
715             dy11             = iy1 - jy1;
716             dz11             = iz1 - jz1;
717             dx12             = ix1 - jx2;
718             dy12             = iy1 - jy2;
719             dz12             = iz1 - jz2;
720             dx20             = ix2 - jx0;
721             dy20             = iy2 - jy0;
722             dz20             = iz2 - jz0;
723             dx21             = ix2 - jx1;
724             dy21             = iy2 - jy1;
725             dz21             = iz2 - jz1;
726             dx22             = ix2 - jx2;
727             dy22             = iy2 - jy2;
728             dz22             = iz2 - jz2;
729
730             /* Calculate squared distance and things based on it */
731             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
732             rsq01            = dx01*dx01+dy01*dy01+dz01*dz01;
733             rsq02            = dx02*dx02+dy02*dy02+dz02*dz02;
734             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
735             rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
736             rsq12            = dx12*dx12+dy12*dy12+dz12*dz12;
737             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
738             rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
739             rsq22            = dx22*dx22+dy22*dy22+dz22*dz22;
740
741             rinv00           = gmx_invsqrt(rsq00);
742             rinv01           = gmx_invsqrt(rsq01);
743             rinv02           = gmx_invsqrt(rsq02);
744             rinv10           = gmx_invsqrt(rsq10);
745             rinv11           = gmx_invsqrt(rsq11);
746             rinv12           = gmx_invsqrt(rsq12);
747             rinv20           = gmx_invsqrt(rsq20);
748             rinv21           = gmx_invsqrt(rsq21);
749             rinv22           = gmx_invsqrt(rsq22);
750
751             rinvsq00         = rinv00*rinv00;
752             rinvsq01         = rinv01*rinv01;
753             rinvsq02         = rinv02*rinv02;
754             rinvsq10         = rinv10*rinv10;
755             rinvsq11         = rinv11*rinv11;
756             rinvsq12         = rinv12*rinv12;
757             rinvsq20         = rinv20*rinv20;
758             rinvsq21         = rinv21*rinv21;
759             rinvsq22         = rinv22*rinv22;
760
761             /**************************
762              * CALCULATE INTERACTIONS *
763              **************************/
764
765             /* COULOMB ELECTROSTATICS */
766             velec            = qq00*rinv00;
767             felec            = velec*rinvsq00;
768
769             /* LENNARD-JONES DISPERSION/REPULSION */
770
771             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
772             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
773
774             fscal            = felec+fvdw;
775
776             /* Calculate temporary vectorial force */
777             tx               = fscal*dx00;
778             ty               = fscal*dy00;
779             tz               = fscal*dz00;
780
781             /* Update vectorial force */
782             fix0            += tx;
783             fiy0            += ty;
784             fiz0            += tz;
785             f[j_coord_offset+DIM*0+XX] -= tx;
786             f[j_coord_offset+DIM*0+YY] -= ty;
787             f[j_coord_offset+DIM*0+ZZ] -= tz;
788
789             /**************************
790              * CALCULATE INTERACTIONS *
791              **************************/
792
793             /* COULOMB ELECTROSTATICS */
794             velec            = qq01*rinv01;
795             felec            = velec*rinvsq01;
796
797             fscal            = felec;
798
799             /* Calculate temporary vectorial force */
800             tx               = fscal*dx01;
801             ty               = fscal*dy01;
802             tz               = fscal*dz01;
803
804             /* Update vectorial force */
805             fix0            += tx;
806             fiy0            += ty;
807             fiz0            += tz;
808             f[j_coord_offset+DIM*1+XX] -= tx;
809             f[j_coord_offset+DIM*1+YY] -= ty;
810             f[j_coord_offset+DIM*1+ZZ] -= tz;
811
812             /**************************
813              * CALCULATE INTERACTIONS *
814              **************************/
815
816             /* COULOMB ELECTROSTATICS */
817             velec            = qq02*rinv02;
818             felec            = velec*rinvsq02;
819
820             fscal            = felec;
821
822             /* Calculate temporary vectorial force */
823             tx               = fscal*dx02;
824             ty               = fscal*dy02;
825             tz               = fscal*dz02;
826
827             /* Update vectorial force */
828             fix0            += tx;
829             fiy0            += ty;
830             fiz0            += tz;
831             f[j_coord_offset+DIM*2+XX] -= tx;
832             f[j_coord_offset+DIM*2+YY] -= ty;
833             f[j_coord_offset+DIM*2+ZZ] -= tz;
834
835             /**************************
836              * CALCULATE INTERACTIONS *
837              **************************/
838
839             /* COULOMB ELECTROSTATICS */
840             velec            = qq10*rinv10;
841             felec            = velec*rinvsq10;
842
843             fscal            = felec;
844
845             /* Calculate temporary vectorial force */
846             tx               = fscal*dx10;
847             ty               = fscal*dy10;
848             tz               = fscal*dz10;
849
850             /* Update vectorial force */
851             fix1            += tx;
852             fiy1            += ty;
853             fiz1            += tz;
854             f[j_coord_offset+DIM*0+XX] -= tx;
855             f[j_coord_offset+DIM*0+YY] -= ty;
856             f[j_coord_offset+DIM*0+ZZ] -= tz;
857
858             /**************************
859              * CALCULATE INTERACTIONS *
860              **************************/
861
862             /* COULOMB ELECTROSTATICS */
863             velec            = qq11*rinv11;
864             felec            = velec*rinvsq11;
865
866             fscal            = felec;
867
868             /* Calculate temporary vectorial force */
869             tx               = fscal*dx11;
870             ty               = fscal*dy11;
871             tz               = fscal*dz11;
872
873             /* Update vectorial force */
874             fix1            += tx;
875             fiy1            += ty;
876             fiz1            += tz;
877             f[j_coord_offset+DIM*1+XX] -= tx;
878             f[j_coord_offset+DIM*1+YY] -= ty;
879             f[j_coord_offset+DIM*1+ZZ] -= tz;
880
881             /**************************
882              * CALCULATE INTERACTIONS *
883              **************************/
884
885             /* COULOMB ELECTROSTATICS */
886             velec            = qq12*rinv12;
887             felec            = velec*rinvsq12;
888
889             fscal            = felec;
890
891             /* Calculate temporary vectorial force */
892             tx               = fscal*dx12;
893             ty               = fscal*dy12;
894             tz               = fscal*dz12;
895
896             /* Update vectorial force */
897             fix1            += tx;
898             fiy1            += ty;
899             fiz1            += tz;
900             f[j_coord_offset+DIM*2+XX] -= tx;
901             f[j_coord_offset+DIM*2+YY] -= ty;
902             f[j_coord_offset+DIM*2+ZZ] -= tz;
903
904             /**************************
905              * CALCULATE INTERACTIONS *
906              **************************/
907
908             /* COULOMB ELECTROSTATICS */
909             velec            = qq20*rinv20;
910             felec            = velec*rinvsq20;
911
912             fscal            = felec;
913
914             /* Calculate temporary vectorial force */
915             tx               = fscal*dx20;
916             ty               = fscal*dy20;
917             tz               = fscal*dz20;
918
919             /* Update vectorial force */
920             fix2            += tx;
921             fiy2            += ty;
922             fiz2            += tz;
923             f[j_coord_offset+DIM*0+XX] -= tx;
924             f[j_coord_offset+DIM*0+YY] -= ty;
925             f[j_coord_offset+DIM*0+ZZ] -= tz;
926
927             /**************************
928              * CALCULATE INTERACTIONS *
929              **************************/
930
931             /* COULOMB ELECTROSTATICS */
932             velec            = qq21*rinv21;
933             felec            = velec*rinvsq21;
934
935             fscal            = felec;
936
937             /* Calculate temporary vectorial force */
938             tx               = fscal*dx21;
939             ty               = fscal*dy21;
940             tz               = fscal*dz21;
941
942             /* Update vectorial force */
943             fix2            += tx;
944             fiy2            += ty;
945             fiz2            += tz;
946             f[j_coord_offset+DIM*1+XX] -= tx;
947             f[j_coord_offset+DIM*1+YY] -= ty;
948             f[j_coord_offset+DIM*1+ZZ] -= tz;
949
950             /**************************
951              * CALCULATE INTERACTIONS *
952              **************************/
953
954             /* COULOMB ELECTROSTATICS */
955             velec            = qq22*rinv22;
956             felec            = velec*rinvsq22;
957
958             fscal            = felec;
959
960             /* Calculate temporary vectorial force */
961             tx               = fscal*dx22;
962             ty               = fscal*dy22;
963             tz               = fscal*dz22;
964
965             /* Update vectorial force */
966             fix2            += tx;
967             fiy2            += ty;
968             fiz2            += tz;
969             f[j_coord_offset+DIM*2+XX] -= tx;
970             f[j_coord_offset+DIM*2+YY] -= ty;
971             f[j_coord_offset+DIM*2+ZZ] -= tz;
972
973             /* Inner loop uses 241 flops */
974         }
975         /* End of innermost loop */
976
977         tx = ty = tz = 0;
978         f[i_coord_offset+DIM*0+XX] += fix0;
979         f[i_coord_offset+DIM*0+YY] += fiy0;
980         f[i_coord_offset+DIM*0+ZZ] += fiz0;
981         tx                         += fix0;
982         ty                         += fiy0;
983         tz                         += fiz0;
984         f[i_coord_offset+DIM*1+XX] += fix1;
985         f[i_coord_offset+DIM*1+YY] += fiy1;
986         f[i_coord_offset+DIM*1+ZZ] += fiz1;
987         tx                         += fix1;
988         ty                         += fiy1;
989         tz                         += fiz1;
990         f[i_coord_offset+DIM*2+XX] += fix2;
991         f[i_coord_offset+DIM*2+YY] += fiy2;
992         f[i_coord_offset+DIM*2+ZZ] += fiz2;
993         tx                         += fix2;
994         ty                         += fiy2;
995         tz                         += fiz2;
996         fshift[i_shift_offset+XX]  += tx;
997         fshift[i_shift_offset+YY]  += ty;
998         fshift[i_shift_offset+ZZ]  += tz;
999
1000         /* Increment number of inner iterations */
1001         inneriter                  += j_index_end - j_index_start;
1002
1003         /* Outer loop uses 30 flops */
1004     }
1005
1006     /* Increment number of outer iterations */
1007     outeriter        += nri;
1008
1009     /* Update outer/inner flops */
1010
1011     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*30 + inneriter*241);
1012 }