96cd89f39e438a7bc1e400fa7f35048b28801f9d
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCoul_VdwNone_GeomW3P1_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_ElecCoul_VdwNone_GeomW3P1_VF_c
49  * Electrostatics interaction: Coulomb
50  * VdW interaction:            None
51  * Geometry:                   Water3-Particle
52  * Calculate force/pot:        PotentialAndForce
53  */
54 void
55 nb_kernel_ElecCoul_VdwNone_GeomW3P1_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              vdwjidx0;
77     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
78     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
79     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
80     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
81     real             velec,felec,velecsum,facel,crf,krf,krf2;
82     real             *charge;
83
84     x                = xx[0];
85     f                = ff[0];
86
87     nri              = nlist->nri;
88     iinr             = nlist->iinr;
89     jindex           = nlist->jindex;
90     jjnr             = nlist->jjnr;
91     shiftidx         = nlist->shift;
92     gid              = nlist->gid;
93     shiftvec         = fr->shift_vec[0];
94     fshift           = fr->fshift[0];
95     facel            = fr->epsfac;
96     charge           = mdatoms->chargeA;
97
98     /* Setup water-specific parameters */
99     inr              = nlist->iinr[0];
100     iq0              = facel*charge[inr+0];
101     iq1              = facel*charge[inr+1];
102     iq2              = facel*charge[inr+2];
103
104     outeriter        = 0;
105     inneriter        = 0;
106
107     /* Start outer loop over neighborlists */
108     for(iidx=0; iidx<nri; iidx++)
109     {
110         /* Load shift vector for this list */
111         i_shift_offset   = DIM*shiftidx[iidx];
112         shX              = shiftvec[i_shift_offset+XX];
113         shY              = shiftvec[i_shift_offset+YY];
114         shZ              = shiftvec[i_shift_offset+ZZ];
115
116         /* Load limits for loop over neighbors */
117         j_index_start    = jindex[iidx];
118         j_index_end      = jindex[iidx+1];
119
120         /* Get outer coordinate index */
121         inr              = iinr[iidx];
122         i_coord_offset   = DIM*inr;
123
124         /* Load i particle coords and add shift vector */
125         ix0              = shX + x[i_coord_offset+DIM*0+XX];
126         iy0              = shY + x[i_coord_offset+DIM*0+YY];
127         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
128         ix1              = shX + x[i_coord_offset+DIM*1+XX];
129         iy1              = shY + x[i_coord_offset+DIM*1+YY];
130         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
131         ix2              = shX + x[i_coord_offset+DIM*2+XX];
132         iy2              = shY + x[i_coord_offset+DIM*2+YY];
133         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
134
135         fix0             = 0.0;
136         fiy0             = 0.0;
137         fiz0             = 0.0;
138         fix1             = 0.0;
139         fiy1             = 0.0;
140         fiz1             = 0.0;
141         fix2             = 0.0;
142         fiy2             = 0.0;
143         fiz2             = 0.0;
144
145         /* Reset potential sums */
146         velecsum         = 0.0;
147
148         /* Start inner kernel loop */
149         for(jidx=j_index_start; jidx<j_index_end; jidx++)
150         {
151             /* Get j neighbor index, and coordinate index */
152             jnr              = jjnr[jidx];
153             j_coord_offset   = DIM*jnr;
154
155             /* load j atom coordinates */
156             jx0              = x[j_coord_offset+DIM*0+XX];
157             jy0              = x[j_coord_offset+DIM*0+YY];
158             jz0              = x[j_coord_offset+DIM*0+ZZ];
159
160             /* Calculate displacement vector */
161             dx00             = ix0 - jx0;
162             dy00             = iy0 - jy0;
163             dz00             = iz0 - jz0;
164             dx10             = ix1 - jx0;
165             dy10             = iy1 - jy0;
166             dz10             = iz1 - jz0;
167             dx20             = ix2 - jx0;
168             dy20             = iy2 - jy0;
169             dz20             = iz2 - jz0;
170
171             /* Calculate squared distance and things based on it */
172             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
173             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
174             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
175
176             rinv00           = gmx_invsqrt(rsq00);
177             rinv10           = gmx_invsqrt(rsq10);
178             rinv20           = gmx_invsqrt(rsq20);
179
180             rinvsq00         = rinv00*rinv00;
181             rinvsq10         = rinv10*rinv10;
182             rinvsq20         = rinv20*rinv20;
183
184             /* Load parameters for j particles */
185             jq0              = charge[jnr+0];
186
187             /**************************
188              * CALCULATE INTERACTIONS *
189              **************************/
190
191             qq00             = iq0*jq0;
192
193             /* COULOMB ELECTROSTATICS */
194             velec            = qq00*rinv00;
195             felec            = velec*rinvsq00;
196
197             /* Update potential sums from outer loop */
198             velecsum        += velec;
199
200             fscal            = felec;
201
202             /* Calculate temporary vectorial force */
203             tx               = fscal*dx00;
204             ty               = fscal*dy00;
205             tz               = fscal*dz00;
206
207             /* Update vectorial force */
208             fix0            += tx;
209             fiy0            += ty;
210             fiz0            += tz;
211             f[j_coord_offset+DIM*0+XX] -= tx;
212             f[j_coord_offset+DIM*0+YY] -= ty;
213             f[j_coord_offset+DIM*0+ZZ] -= tz;
214
215             /**************************
216              * CALCULATE INTERACTIONS *
217              **************************/
218
219             qq10             = iq1*jq0;
220
221             /* COULOMB ELECTROSTATICS */
222             velec            = qq10*rinv10;
223             felec            = velec*rinvsq10;
224
225             /* Update potential sums from outer loop */
226             velecsum        += velec;
227
228             fscal            = felec;
229
230             /* Calculate temporary vectorial force */
231             tx               = fscal*dx10;
232             ty               = fscal*dy10;
233             tz               = fscal*dz10;
234
235             /* Update vectorial force */
236             fix1            += tx;
237             fiy1            += ty;
238             fiz1            += tz;
239             f[j_coord_offset+DIM*0+XX] -= tx;
240             f[j_coord_offset+DIM*0+YY] -= ty;
241             f[j_coord_offset+DIM*0+ZZ] -= tz;
242
243             /**************************
244              * CALCULATE INTERACTIONS *
245              **************************/
246
247             qq20             = iq2*jq0;
248
249             /* COULOMB ELECTROSTATICS */
250             velec            = qq20*rinv20;
251             felec            = velec*rinvsq20;
252
253             /* Update potential sums from outer loop */
254             velecsum        += velec;
255
256             fscal            = felec;
257
258             /* Calculate temporary vectorial force */
259             tx               = fscal*dx20;
260             ty               = fscal*dy20;
261             tz               = fscal*dz20;
262
263             /* Update vectorial force */
264             fix2            += tx;
265             fiy2            += ty;
266             fiz2            += tz;
267             f[j_coord_offset+DIM*0+XX] -= tx;
268             f[j_coord_offset+DIM*0+YY] -= ty;
269             f[j_coord_offset+DIM*0+ZZ] -= tz;
270
271             /* Inner loop uses 84 flops */
272         }
273         /* End of innermost loop */
274
275         tx = ty = tz = 0;
276         f[i_coord_offset+DIM*0+XX] += fix0;
277         f[i_coord_offset+DIM*0+YY] += fiy0;
278         f[i_coord_offset+DIM*0+ZZ] += fiz0;
279         tx                         += fix0;
280         ty                         += fiy0;
281         tz                         += fiz0;
282         f[i_coord_offset+DIM*1+XX] += fix1;
283         f[i_coord_offset+DIM*1+YY] += fiy1;
284         f[i_coord_offset+DIM*1+ZZ] += fiz1;
285         tx                         += fix1;
286         ty                         += fiy1;
287         tz                         += fiz1;
288         f[i_coord_offset+DIM*2+XX] += fix2;
289         f[i_coord_offset+DIM*2+YY] += fiy2;
290         f[i_coord_offset+DIM*2+ZZ] += fiz2;
291         tx                         += fix2;
292         ty                         += fiy2;
293         tz                         += fiz2;
294         fshift[i_shift_offset+XX]  += tx;
295         fshift[i_shift_offset+YY]  += ty;
296         fshift[i_shift_offset+ZZ]  += tz;
297
298         ggid                        = gid[iidx];
299         /* Update potential energies */
300         kernel_data->energygrp_elec[ggid] += velecsum;
301
302         /* Increment number of inner iterations */
303         inneriter                  += j_index_end - j_index_start;
304
305         /* Outer loop uses 31 flops */
306     }
307
308     /* Increment number of outer iterations */
309     outeriter        += nri;
310
311     /* Update outer/inner flops */
312
313     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*31 + inneriter*84);
314 }
315 /*
316  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwNone_GeomW3P1_F_c
317  * Electrostatics interaction: Coulomb
318  * VdW interaction:            None
319  * Geometry:                   Water3-Particle
320  * Calculate force/pot:        Force
321  */
322 void
323 nb_kernel_ElecCoul_VdwNone_GeomW3P1_F_c
324                     (t_nblist                    * gmx_restrict       nlist,
325                      rvec                        * gmx_restrict          xx,
326                      rvec                        * gmx_restrict          ff,
327                      t_forcerec                  * gmx_restrict          fr,
328                      t_mdatoms                   * gmx_restrict     mdatoms,
329                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
330                      t_nrnb                      * gmx_restrict        nrnb)
331 {
332     int              i_shift_offset,i_coord_offset,j_coord_offset;
333     int              j_index_start,j_index_end;
334     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
335     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
336     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
337     real             *shiftvec,*fshift,*x,*f;
338     int              vdwioffset0;
339     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
340     int              vdwioffset1;
341     real             ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
342     int              vdwioffset2;
343     real             ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
344     int              vdwjidx0;
345     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
346     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
347     real             dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10,cexp1_10,cexp2_10;
348     real             dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20,cexp1_20,cexp2_20;
349     real             velec,felec,velecsum,facel,crf,krf,krf2;
350     real             *charge;
351
352     x                = xx[0];
353     f                = ff[0];
354
355     nri              = nlist->nri;
356     iinr             = nlist->iinr;
357     jindex           = nlist->jindex;
358     jjnr             = nlist->jjnr;
359     shiftidx         = nlist->shift;
360     gid              = nlist->gid;
361     shiftvec         = fr->shift_vec[0];
362     fshift           = fr->fshift[0];
363     facel            = fr->epsfac;
364     charge           = mdatoms->chargeA;
365
366     /* Setup water-specific parameters */
367     inr              = nlist->iinr[0];
368     iq0              = facel*charge[inr+0];
369     iq1              = facel*charge[inr+1];
370     iq2              = facel*charge[inr+2];
371
372     outeriter        = 0;
373     inneriter        = 0;
374
375     /* Start outer loop over neighborlists */
376     for(iidx=0; iidx<nri; iidx++)
377     {
378         /* Load shift vector for this list */
379         i_shift_offset   = DIM*shiftidx[iidx];
380         shX              = shiftvec[i_shift_offset+XX];
381         shY              = shiftvec[i_shift_offset+YY];
382         shZ              = shiftvec[i_shift_offset+ZZ];
383
384         /* Load limits for loop over neighbors */
385         j_index_start    = jindex[iidx];
386         j_index_end      = jindex[iidx+1];
387
388         /* Get outer coordinate index */
389         inr              = iinr[iidx];
390         i_coord_offset   = DIM*inr;
391
392         /* Load i particle coords and add shift vector */
393         ix0              = shX + x[i_coord_offset+DIM*0+XX];
394         iy0              = shY + x[i_coord_offset+DIM*0+YY];
395         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
396         ix1              = shX + x[i_coord_offset+DIM*1+XX];
397         iy1              = shY + x[i_coord_offset+DIM*1+YY];
398         iz1              = shZ + x[i_coord_offset+DIM*1+ZZ];
399         ix2              = shX + x[i_coord_offset+DIM*2+XX];
400         iy2              = shY + x[i_coord_offset+DIM*2+YY];
401         iz2              = shZ + x[i_coord_offset+DIM*2+ZZ];
402
403         fix0             = 0.0;
404         fiy0             = 0.0;
405         fiz0             = 0.0;
406         fix1             = 0.0;
407         fiy1             = 0.0;
408         fiz1             = 0.0;
409         fix2             = 0.0;
410         fiy2             = 0.0;
411         fiz2             = 0.0;
412
413         /* Start inner kernel loop */
414         for(jidx=j_index_start; jidx<j_index_end; jidx++)
415         {
416             /* Get j neighbor index, and coordinate index */
417             jnr              = jjnr[jidx];
418             j_coord_offset   = DIM*jnr;
419
420             /* load j atom coordinates */
421             jx0              = x[j_coord_offset+DIM*0+XX];
422             jy0              = x[j_coord_offset+DIM*0+YY];
423             jz0              = x[j_coord_offset+DIM*0+ZZ];
424
425             /* Calculate displacement vector */
426             dx00             = ix0 - jx0;
427             dy00             = iy0 - jy0;
428             dz00             = iz0 - jz0;
429             dx10             = ix1 - jx0;
430             dy10             = iy1 - jy0;
431             dz10             = iz1 - jz0;
432             dx20             = ix2 - jx0;
433             dy20             = iy2 - jy0;
434             dz20             = iz2 - jz0;
435
436             /* Calculate squared distance and things based on it */
437             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
438             rsq10            = dx10*dx10+dy10*dy10+dz10*dz10;
439             rsq20            = dx20*dx20+dy20*dy20+dz20*dz20;
440
441             rinv00           = gmx_invsqrt(rsq00);
442             rinv10           = gmx_invsqrt(rsq10);
443             rinv20           = gmx_invsqrt(rsq20);
444
445             rinvsq00         = rinv00*rinv00;
446             rinvsq10         = rinv10*rinv10;
447             rinvsq20         = rinv20*rinv20;
448
449             /* Load parameters for j particles */
450             jq0              = charge[jnr+0];
451
452             /**************************
453              * CALCULATE INTERACTIONS *
454              **************************/
455
456             qq00             = iq0*jq0;
457
458             /* COULOMB ELECTROSTATICS */
459             velec            = qq00*rinv00;
460             felec            = velec*rinvsq00;
461
462             fscal            = felec;
463
464             /* Calculate temporary vectorial force */
465             tx               = fscal*dx00;
466             ty               = fscal*dy00;
467             tz               = fscal*dz00;
468
469             /* Update vectorial force */
470             fix0            += tx;
471             fiy0            += ty;
472             fiz0            += tz;
473             f[j_coord_offset+DIM*0+XX] -= tx;
474             f[j_coord_offset+DIM*0+YY] -= ty;
475             f[j_coord_offset+DIM*0+ZZ] -= tz;
476
477             /**************************
478              * CALCULATE INTERACTIONS *
479              **************************/
480
481             qq10             = iq1*jq0;
482
483             /* COULOMB ELECTROSTATICS */
484             velec            = qq10*rinv10;
485             felec            = velec*rinvsq10;
486
487             fscal            = felec;
488
489             /* Calculate temporary vectorial force */
490             tx               = fscal*dx10;
491             ty               = fscal*dy10;
492             tz               = fscal*dz10;
493
494             /* Update vectorial force */
495             fix1            += tx;
496             fiy1            += ty;
497             fiz1            += tz;
498             f[j_coord_offset+DIM*0+XX] -= tx;
499             f[j_coord_offset+DIM*0+YY] -= ty;
500             f[j_coord_offset+DIM*0+ZZ] -= tz;
501
502             /**************************
503              * CALCULATE INTERACTIONS *
504              **************************/
505
506             qq20             = iq2*jq0;
507
508             /* COULOMB ELECTROSTATICS */
509             velec            = qq20*rinv20;
510             felec            = velec*rinvsq20;
511
512             fscal            = felec;
513
514             /* Calculate temporary vectorial force */
515             tx               = fscal*dx20;
516             ty               = fscal*dy20;
517             tz               = fscal*dz20;
518
519             /* Update vectorial force */
520             fix2            += tx;
521             fiy2            += ty;
522             fiz2            += tz;
523             f[j_coord_offset+DIM*0+XX] -= tx;
524             f[j_coord_offset+DIM*0+YY] -= ty;
525             f[j_coord_offset+DIM*0+ZZ] -= tz;
526
527             /* Inner loop uses 81 flops */
528         }
529         /* End of innermost loop */
530
531         tx = ty = tz = 0;
532         f[i_coord_offset+DIM*0+XX] += fix0;
533         f[i_coord_offset+DIM*0+YY] += fiy0;
534         f[i_coord_offset+DIM*0+ZZ] += fiz0;
535         tx                         += fix0;
536         ty                         += fiy0;
537         tz                         += fiz0;
538         f[i_coord_offset+DIM*1+XX] += fix1;
539         f[i_coord_offset+DIM*1+YY] += fiy1;
540         f[i_coord_offset+DIM*1+ZZ] += fiz1;
541         tx                         += fix1;
542         ty                         += fiy1;
543         tz                         += fiz1;
544         f[i_coord_offset+DIM*2+XX] += fix2;
545         f[i_coord_offset+DIM*2+YY] += fiy2;
546         f[i_coord_offset+DIM*2+ZZ] += fiz2;
547         tx                         += fix2;
548         ty                         += fiy2;
549         tz                         += fiz2;
550         fshift[i_shift_offset+XX]  += tx;
551         fshift[i_shift_offset+YY]  += ty;
552         fshift[i_shift_offset+ZZ]  += tz;
553
554         /* Increment number of inner iterations */
555         inneriter                  += j_index_end - j_index_start;
556
557         /* Outer loop uses 30 flops */
558     }
559
560     /* Increment number of outer iterations */
561     outeriter        += nri;
562
563     /* Update outer/inner flops */
564
565     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*30 + inneriter*81);
566 }