a04f56e5cb40066998a89a34d397784497fc5338
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCoul_VdwLJ_GeomW3P1_c.c
1 /*
2  * Note: this file was generated by the Gromacs c kernel generator.
3  *
4  *                This source code is part of
5  *
6  *                 G   R   O   M   A   C   S
7  *
8  * Copyright (c) 2001-2012, The GROMACS Development Team
9  *
10  * Gromacs is a library for molecular simulation and trajectory analysis,
11  * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12  * a full list of developers and information, check out http://www.gromacs.org
13  *
14  * This program is free software; you can redistribute it and/or modify it under
15  * the terms of the GNU Lesser General Public License as published by the Free
16  * Software Foundation; either version 2 of the License, or (at your option) any
17  * later version.
18  *
19  * To help fund GROMACS development, we humbly ask that you cite
20  * the papers people have written on it - you can find them on the website.
21  */
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <math.h>
27
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
30 #include "vec.h"
31 #include "nrnb.h"
32
33 /*
34  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW3P1_VF_c
35  * Electrostatics interaction: Coulomb
36  * VdW interaction:            LennardJones
37  * Geometry:                   Water3-Particle
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecCoul_VdwLJ_GeomW3P1_VF_c
42                     (t_nblist * gmx_restrict                nlist,
43                      rvec * gmx_restrict                    xx,
44                      rvec * gmx_restrict                    ff,
45                      t_forcerec * gmx_restrict              fr,
46                      t_mdatoms * gmx_restrict               mdatoms,
47                      nb_kernel_data_t * gmx_restrict        kernel_data,
48                      t_nrnb * gmx_restrict                  nrnb)
49 {
50     int              i_shift_offset,i_coord_offset,j_coord_offset;
51     int              j_index_start,j_index_end;
52     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
53     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
54     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
55     real             *shiftvec,*fshift,*x,*f;
56     int              vdwioffset0;
57     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
58     int              vdwioffset1;
59     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
60     int              vdwioffset2;
61     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
62     int              vdwjidx0;
63     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
64     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
65     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
66     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
67     real             velec,felec,velecsum,facel,crf,krf,krf2;
68     real             *charge;
69     int              nvdwtype;
70     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
71     int              *vdwtype;
72     real             *vdwparam;
73
74     x                = xx[0];
75     f                = ff[0];
76
77     nri              = nlist->nri;
78     iinr             = nlist->iinr;
79     jindex           = nlist->jindex;
80     jjnr             = nlist->jjnr;
81     shiftidx         = nlist->shift;
82     gid              = nlist->gid;
83     shiftvec         = fr->shift_vec[0];
84     fshift           = fr->fshift[0];
85     facel            = fr->epsfac;
86     charge           = mdatoms->chargeA;
87     nvdwtype         = fr->ntype;
88     vdwparam         = fr->nbfp;
89     vdwtype          = mdatoms->typeA;
90
91     /* Setup water-specific parameters */
92     inr              = nlist->iinr[0];
93     iq0              = facel*charge[inr+0];
94     iq1              = facel*charge[inr+1];
95     iq2              = facel*charge[inr+2];
96     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
97
98     outeriter        = 0;
99     inneriter        = 0;
100
101     /* Start outer loop over neighborlists */
102     for(iidx=0; iidx<nri; iidx++)
103     {
104         /* Load shift vector for this list */
105         i_shift_offset   = DIM*shiftidx[iidx];
106         shX              = shiftvec[i_shift_offset+XX];
107         shY              = shiftvec[i_shift_offset+YY];
108         shZ              = shiftvec[i_shift_offset+ZZ];
109
110         /* Load limits for loop over neighbors */
111         j_index_start    = jindex[iidx];
112         j_index_end      = jindex[iidx+1];
113
114         /* Get outer coordinate index */
115         inr              = iinr[iidx];
116         i_coord_offset   = DIM*inr;
117
118         /* Load i particle coords and add shift vector */
119         ix0              = shX + x[i_coord_offset+DIM*0+XX];
120         iy0              = shY + x[i_coord_offset+DIM*0+YY];
121         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
122         ix1              = shX + x[i_coord_offset+DIM*1+XX];
123         iy1              = shY + x[i_coord_offset+DIM*1+YY];
124         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
125         ix2              = shX + x[i_coord_offset+DIM*2+XX];
126         iy2              = shY + x[i_coord_offset+DIM*2+YY];
127         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
128
129         fix0             = 0.0;
130         fiy0             = 0.0;
131         fiz0             = 0.0;
132         fix1             = 0.0;
133         fiy1             = 0.0;
134         fiz1             = 0.0;
135         fix2             = 0.0;
136         fiy2             = 0.0;
137         fiz2             = 0.0;
138
139         /* Reset potential sums */
140         velecsum         = 0.0;
141         vvdwsum          = 0.0;
142
143         /* Start inner kernel loop */
144         for(jidx=j_index_start; jidx<j_index_end; jidx++)
145         {
146             /* Get j neighbor index, and coordinate index */
147             jnr              = jjnr[jidx];
148             j_coord_offset   = DIM*jnr;
149
150             /* load j atom coordinates */
151             jx0              = x[j_coord_offset+DIM*0+XX];
152             jy0              = x[j_coord_offset+DIM*0+YY];
153             jz0              = x[j_coord_offset+DIM*0+ZZ];
154
155             /* Calculate displacement vector */
156             dx00             = ix0 - jx0;
157             dy00             = iy0 - jy0;
158             dz00             = iz0 - jz0;
159             dx10             = ix1 - jx0;
160             dy10             = iy1 - jy0;
161             dz10             = iz1 - jz0;
162             dx20             = ix2 - jx0;
163             dy20             = iy2 - jy0;
164             dz20             = iz2 - jz0;
165
166             /* Calculate squared distance and things based on it */
167             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
168             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
169             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
170
171             rinv00           = gmx_invsqrt(rsq00);
172             rinv10           = gmx_invsqrt(rsq10);
173             rinv20           = gmx_invsqrt(rsq20);
174
175             rinvsq00         = rinv00*rinv00;
176             rinvsq10         = rinv10*rinv10;
177             rinvsq20         = rinv20*rinv20;
178
179             /* Load parameters for j particles */
180             jq0              = charge[jnr+0];
181             vdwjidx0         = 2*vdwtype[jnr+0];
182
183             /**************************
184              * CALCULATE INTERACTIONS *
185              **************************/
186
187             qq00             = iq0*jq0;
188             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
189             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
190
191             /* COULOMB ELECTROSTATICS */
192             velec            = qq00*rinv00;
193             felec            = velec*rinvsq00;
194
195             /* LENNARD-JONES DISPERSION/REPULSION */
196
197             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
198             vvdw6            = c6_00*rinvsix;
199             vvdw12           = c12_00*rinvsix*rinvsix;
200             vvdw             = vvdw12*(1.0/12.0) - vvdw6*(1.0/6.0);
201             fvdw             = (vvdw12-vvdw6)*rinvsq00;
202
203             /* Update potential sums from outer loop */
204             velecsum        += velec;
205             vvdwsum         += vvdw;
206
207             fscal            = felec+fvdw;
208
209             /* Calculate temporary vectorial force */
210             tx               = fscal*dx00;
211             ty               = fscal*dy00;
212             tz               = fscal*dz00;
213
214             /* Update vectorial force */
215             fix0            += tx;
216             fiy0            += ty;
217             fiz0            += tz;
218             f[j_coord_offset+DIM*0+XX] -= tx;
219             f[j_coord_offset+DIM*0+YY] -= ty;
220             f[j_coord_offset+DIM*0+ZZ] -= tz;
221
222             /**************************
223              * CALCULATE INTERACTIONS *
224              **************************/
225
226             qq10             = iq1*jq0;
227
228             /* COULOMB ELECTROSTATICS */
229             velec            = qq10*rinv10;
230             felec            = velec*rinvsq10;
231
232             /* Update potential sums from outer loop */
233             velecsum        += velec;
234
235             fscal            = felec;
236
237             /* Calculate temporary vectorial force */
238             tx               = fscal*dx10;
239             ty               = fscal*dy10;
240             tz               = fscal*dz10;
241
242             /* Update vectorial force */
243             fix1            += tx;
244             fiy1            += ty;
245             fiz1            += tz;
246             f[j_coord_offset+DIM*0+XX] -= tx;
247             f[j_coord_offset+DIM*0+YY] -= ty;
248             f[j_coord_offset+DIM*0+ZZ] -= tz;
249
250             /**************************
251              * CALCULATE INTERACTIONS *
252              **************************/
253
254             qq20             = iq2*jq0;
255
256             /* COULOMB ELECTROSTATICS */
257             velec            = qq20*rinv20;
258             felec            = velec*rinvsq20;
259
260             /* Update potential sums from outer loop */
261             velecsum        += velec;
262
263             fscal            = felec;
264
265             /* Calculate temporary vectorial force */
266             tx               = fscal*dx20;
267             ty               = fscal*dy20;
268             tz               = fscal*dz20;
269
270             /* Update vectorial force */
271             fix2            += tx;
272             fiy2            += ty;
273             fiz2            += tz;
274             f[j_coord_offset+DIM*0+XX] -= tx;
275             f[j_coord_offset+DIM*0+YY] -= ty;
276             f[j_coord_offset+DIM*0+ZZ] -= tz;
277
278             /* Inner loop uses 96 flops */
279         }
280         /* End of innermost loop */
281
282         tx = ty = tz = 0;
283         f[i_coord_offset+DIM*0+XX] += fix0;
284         f[i_coord_offset+DIM*0+YY] += fiy0;
285         f[i_coord_offset+DIM*0+ZZ] += fiz0;
286         tx                         += fix0;
287         ty                         += fiy0;
288         tz                         += fiz0;
289         f[i_coord_offset+DIM*1+XX] += fix1;
290         f[i_coord_offset+DIM*1+YY] += fiy1;
291         f[i_coord_offset+DIM*1+ZZ] += fiz1;
292         tx                         += fix1;
293         ty                         += fiy1;
294         tz                         += fiz1;
295         f[i_coord_offset+DIM*2+XX] += fix2;
296         f[i_coord_offset+DIM*2+YY] += fiy2;
297         f[i_coord_offset+DIM*2+ZZ] += fiz2;
298         tx                         += fix2;
299         ty                         += fiy2;
300         tz                         += fiz2;
301         fshift[i_shift_offset+XX]  += tx;
302         fshift[i_shift_offset+YY]  += ty;
303         fshift[i_shift_offset+ZZ]  += tz;
304
305         ggid                        = gid[iidx];
306         /* Update potential energies */
307         kernel_data->energygrp_elec[ggid] += velecsum;
308         kernel_data->energygrp_vdw[ggid] += vvdwsum;
309
310         /* Increment number of inner iterations */
311         inneriter                  += j_index_end - j_index_start;
312
313         /* Outer loop uses 32 flops */
314     }
315
316     /* Increment number of outer iterations */
317     outeriter        += nri;
318
319     /* Update outer/inner flops */
320
321     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*32 + inneriter*96);
322 }
323 /*
324  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW3P1_F_c
325  * Electrostatics interaction: Coulomb
326  * VdW interaction:            LennardJones
327  * Geometry:                   Water3-Particle
328  * Calculate force/pot:        Force
329  */
330 void
331 nb_kernel_ElecCoul_VdwLJ_GeomW3P1_F_c
332                     (t_nblist * gmx_restrict                nlist,
333                      rvec * gmx_restrict                    xx,
334                      rvec * gmx_restrict                    ff,
335                      t_forcerec * gmx_restrict              fr,
336                      t_mdatoms * gmx_restrict               mdatoms,
337                      nb_kernel_data_t * gmx_restrict        kernel_data,
338                      t_nrnb * gmx_restrict                  nrnb)
339 {
340     int              i_shift_offset,i_coord_offset,j_coord_offset;
341     int              j_index_start,j_index_end;
342     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
343     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
344     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
345     real             *shiftvec,*fshift,*x,*f;
346     int              vdwioffset0;
347     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
348     int              vdwioffset1;
349     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
350     int              vdwioffset2;
351     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
352     int              vdwjidx0;
353     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
354     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
355     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
356     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
357     real             velec,felec,velecsum,facel,crf,krf,krf2;
358     real             *charge;
359     int              nvdwtype;
360     real             rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,br,vvdwexp,sh_vdw_invrcut6;
361     int              *vdwtype;
362     real             *vdwparam;
363
364     x                = xx[0];
365     f                = ff[0];
366
367     nri              = nlist->nri;
368     iinr             = nlist->iinr;
369     jindex           = nlist->jindex;
370     jjnr             = nlist->jjnr;
371     shiftidx         = nlist->shift;
372     gid              = nlist->gid;
373     shiftvec         = fr->shift_vec[0];
374     fshift           = fr->fshift[0];
375     facel            = fr->epsfac;
376     charge           = mdatoms->chargeA;
377     nvdwtype         = fr->ntype;
378     vdwparam         = fr->nbfp;
379     vdwtype          = mdatoms->typeA;
380
381     /* Setup water-specific parameters */
382     inr              = nlist->iinr[0];
383     iq0              = facel*charge[inr+0];
384     iq1              = facel*charge[inr+1];
385     iq2              = facel*charge[inr+2];
386     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
387
388     outeriter        = 0;
389     inneriter        = 0;
390
391     /* Start outer loop over neighborlists */
392     for(iidx=0; iidx<nri; iidx++)
393     {
394         /* Load shift vector for this list */
395         i_shift_offset   = DIM*shiftidx[iidx];
396         shX              = shiftvec[i_shift_offset+XX];
397         shY              = shiftvec[i_shift_offset+YY];
398         shZ              = shiftvec[i_shift_offset+ZZ];
399
400         /* Load limits for loop over neighbors */
401         j_index_start    = jindex[iidx];
402         j_index_end      = jindex[iidx+1];
403
404         /* Get outer coordinate index */
405         inr              = iinr[iidx];
406         i_coord_offset   = DIM*inr;
407
408         /* Load i particle coords and add shift vector */
409         ix0              = shX + x[i_coord_offset+DIM*0+XX];
410         iy0              = shY + x[i_coord_offset+DIM*0+YY];
411         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
412         ix1              = shX + x[i_coord_offset+DIM*1+XX];
413         iy1              = shY + x[i_coord_offset+DIM*1+YY];
414         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
415         ix2              = shX + x[i_coord_offset+DIM*2+XX];
416         iy2              = shY + x[i_coord_offset+DIM*2+YY];
417         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
418
419         fix0             = 0.0;
420         fiy0             = 0.0;
421         fiz0             = 0.0;
422         fix1             = 0.0;
423         fiy1             = 0.0;
424         fiz1             = 0.0;
425         fix2             = 0.0;
426         fiy2             = 0.0;
427         fiz2             = 0.0;
428
429         /* Start inner kernel loop */
430         for(jidx=j_index_start; jidx<j_index_end; jidx++)
431         {
432             /* Get j neighbor index, and coordinate index */
433             jnr              = jjnr[jidx];
434             j_coord_offset   = DIM*jnr;
435
436             /* load j atom coordinates */
437             jx0              = x[j_coord_offset+DIM*0+XX];
438             jy0              = x[j_coord_offset+DIM*0+YY];
439             jz0              = x[j_coord_offset+DIM*0+ZZ];
440
441             /* Calculate displacement vector */
442             dx00             = ix0 - jx0;
443             dy00             = iy0 - jy0;
444             dz00             = iz0 - jz0;
445             dx10             = ix1 - jx0;
446             dy10             = iy1 - jy0;
447             dz10             = iz1 - jz0;
448             dx20             = ix2 - jx0;
449             dy20             = iy2 - jy0;
450             dz20             = iz2 - jz0;
451
452             /* Calculate squared distance and things based on it */
453             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
454             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
455             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
456
457             rinv00           = gmx_invsqrt(rsq00);
458             rinv10           = gmx_invsqrt(rsq10);
459             rinv20           = gmx_invsqrt(rsq20);
460
461             rinvsq00         = rinv00*rinv00;
462             rinvsq10         = rinv10*rinv10;
463             rinvsq20         = rinv20*rinv20;
464
465             /* Load parameters for j particles */
466             jq0              = charge[jnr+0];
467             vdwjidx0         = 2*vdwtype[jnr+0];
468
469             /**************************
470              * CALCULATE INTERACTIONS *
471              **************************/
472
473             qq00             = iq0*jq0;
474             c6_00            = vdwparam[vdwioffset0+vdwjidx0];
475             c12_00           = vdwparam[vdwioffset0+vdwjidx0+1];
476
477             /* COULOMB ELECTROSTATICS */
478             velec            = qq00*rinv00;
479             felec            = velec*rinvsq00;
480
481             /* LENNARD-JONES DISPERSION/REPULSION */
482
483             rinvsix          = rinvsq00*rinvsq00*rinvsq00;
484             fvdw             = (c12_00*rinvsix-c6_00)*rinvsix*rinvsq00;
485
486             fscal            = felec+fvdw;
487
488             /* Calculate temporary vectorial force */
489             tx               = fscal*dx00;
490             ty               = fscal*dy00;
491             tz               = fscal*dz00;
492
493             /* Update vectorial force */
494             fix0            += tx;
495             fiy0            += ty;
496             fiz0            += tz;
497             f[j_coord_offset+DIM*0+XX] -= tx;
498             f[j_coord_offset+DIM*0+YY] -= ty;
499             f[j_coord_offset+DIM*0+ZZ] -= tz;
500
501             /**************************
502              * CALCULATE INTERACTIONS *
503              **************************/
504
505             qq10             = iq1*jq0;
506
507             /* COULOMB ELECTROSTATICS */
508             velec            = qq10*rinv10;
509             felec            = velec*rinvsq10;
510
511             fscal            = felec;
512
513             /* Calculate temporary vectorial force */
514             tx               = fscal*dx10;
515             ty               = fscal*dy10;
516             tz               = fscal*dz10;
517
518             /* Update vectorial force */
519             fix1            += tx;
520             fiy1            += ty;
521             fiz1            += tz;
522             f[j_coord_offset+DIM*0+XX] -= tx;
523             f[j_coord_offset+DIM*0+YY] -= ty;
524             f[j_coord_offset+DIM*0+ZZ] -= tz;
525
526             /**************************
527              * CALCULATE INTERACTIONS *
528              **************************/
529
530             qq20             = iq2*jq0;
531
532             /* COULOMB ELECTROSTATICS */
533             velec            = qq20*rinv20;
534             felec            = velec*rinvsq20;
535
536             fscal            = felec;
537
538             /* Calculate temporary vectorial force */
539             tx               = fscal*dx20;
540             ty               = fscal*dy20;
541             tz               = fscal*dz20;
542
543             /* Update vectorial force */
544             fix2            += tx;
545             fiy2            += ty;
546             fiz2            += tz;
547             f[j_coord_offset+DIM*0+XX] -= tx;
548             f[j_coord_offset+DIM*0+YY] -= ty;
549             f[j_coord_offset+DIM*0+ZZ] -= tz;
550
551             /* Inner loop uses 88 flops */
552         }
553         /* End of innermost loop */
554
555         tx = ty = tz = 0;
556         f[i_coord_offset+DIM*0+XX] += fix0;
557         f[i_coord_offset+DIM*0+YY] += fiy0;
558         f[i_coord_offset+DIM*0+ZZ] += fiz0;
559         tx                         += fix0;
560         ty                         += fiy0;
561         tz                         += fiz0;
562         f[i_coord_offset+DIM*1+XX] += fix1;
563         f[i_coord_offset+DIM*1+YY] += fiy1;
564         f[i_coord_offset+DIM*1+ZZ] += fiz1;
565         tx                         += fix1;
566         ty                         += fiy1;
567         tz                         += fiz1;
568         f[i_coord_offset+DIM*2+XX] += fix2;
569         f[i_coord_offset+DIM*2+YY] += fiy2;
570         f[i_coord_offset+DIM*2+ZZ] += fiz2;
571         tx                         += fix2;
572         ty                         += fiy2;
573         tz                         += fiz2;
574         fshift[i_shift_offset+XX]  += tx;
575         fshift[i_shift_offset+YY]  += ty;
576         fshift[i_shift_offset+ZZ]  += tz;
577
578         /* Increment number of inner iterations */
579         inneriter                  += j_index_end - j_index_start;
580
581         /* Outer loop uses 30 flops */
582     }
583
584     /* Increment number of outer iterations */
585     outeriter        += nri;
586
587     /* Update outer/inner flops */
588
589     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*30 + inneriter*88);
590 }