36bef38c2eebf09649d57cc6b345faef02885baa
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_c / nb_kernel_ElecCoul_VdwNone_GeomP1P1_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_VdwNone_GeomP1P1_VF_c
35  * Electrostatics interaction: Coulomb
36  * VdW interaction:            None
37  * Geometry:                   Particle-Particle
38  * Calculate force/pot:        PotentialAndForce
39  */
40 void
41 nb_kernel_ElecCoul_VdwNone_GeomP1P1_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              vdwjidx0;
59     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
60     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
61     real             velec,felec,velecsum,facel,crf,krf,krf2;
62     real             *charge;
63
64     x                = xx[0];
65     f                = ff[0];
66
67     nri              = nlist->nri;
68     iinr             = nlist->iinr;
69     jindex           = nlist->jindex;
70     jjnr             = nlist->jjnr;
71     shiftidx         = nlist->shift;
72     gid              = nlist->gid;
73     shiftvec         = fr->shift_vec[0];
74     fshift           = fr->fshift[0];
75     facel            = fr->epsfac;
76     charge           = mdatoms->chargeA;
77
78     outeriter        = 0;
79     inneriter        = 0;
80
81     /* Start outer loop over neighborlists */
82     for(iidx=0; iidx<nri; iidx++)
83     {
84         /* Load shift vector for this list */
85         i_shift_offset   = DIM*shiftidx[iidx];
86         shX              = shiftvec[i_shift_offset+XX];
87         shY              = shiftvec[i_shift_offset+YY];
88         shZ              = shiftvec[i_shift_offset+ZZ];
89
90         /* Load limits for loop over neighbors */
91         j_index_start    = jindex[iidx];
92         j_index_end      = jindex[iidx+1];
93
94         /* Get outer coordinate index */
95         inr              = iinr[iidx];
96         i_coord_offset   = DIM*inr;
97
98         /* Load i particle coords and add shift vector */
99         ix0              = shX + x[i_coord_offset+DIM*0+XX];
100         iy0              = shY + x[i_coord_offset+DIM*0+YY];
101         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
102
103         fix0             = 0.0;
104         fiy0             = 0.0;
105         fiz0             = 0.0;
106
107         /* Load parameters for i particles */
108         iq0              = facel*charge[inr+0];
109
110         /* Reset potential sums */
111         velecsum         = 0.0;
112
113         /* Start inner kernel loop */
114         for(jidx=j_index_start; jidx<j_index_end; jidx++)
115         {
116             /* Get j neighbor index, and coordinate index */
117             jnr              = jjnr[jidx];
118             j_coord_offset   = DIM*jnr;
119
120             /* load j atom coordinates */
121             jx0              = x[j_coord_offset+DIM*0+XX];
122             jy0              = x[j_coord_offset+DIM*0+YY];
123             jz0              = x[j_coord_offset+DIM*0+ZZ];
124
125             /* Calculate displacement vector */
126             dx00             = ix0 - jx0;
127             dy00             = iy0 - jy0;
128             dz00             = iz0 - jz0;
129
130             /* Calculate squared distance and things based on it */
131             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
132
133             rinv00           = gmx_invsqrt(rsq00);
134
135             rinvsq00         = rinv00*rinv00;
136
137             /* Load parameters for j particles */
138             jq0              = charge[jnr+0];
139
140             /**************************
141              * CALCULATE INTERACTIONS *
142              **************************/
143
144             qq00             = iq0*jq0;
145
146             /* COULOMB ELECTROSTATICS */
147             velec            = qq00*rinv00;
148             felec            = velec*rinvsq00;
149
150             /* Update potential sums from outer loop */
151             velecsum        += velec;
152
153             fscal            = felec;
154
155             /* Calculate temporary vectorial force */
156             tx               = fscal*dx00;
157             ty               = fscal*dy00;
158             tz               = fscal*dz00;
159
160             /* Update vectorial force */
161             fix0            += tx;
162             fiy0            += ty;
163             fiz0            += tz;
164             f[j_coord_offset+DIM*0+XX] -= tx;
165             f[j_coord_offset+DIM*0+YY] -= ty;
166             f[j_coord_offset+DIM*0+ZZ] -= tz;
167
168             /* Inner loop uses 28 flops */
169         }
170         /* End of innermost loop */
171
172         tx = ty = tz = 0;
173         f[i_coord_offset+DIM*0+XX] += fix0;
174         f[i_coord_offset+DIM*0+YY] += fiy0;
175         f[i_coord_offset+DIM*0+ZZ] += fiz0;
176         tx                         += fix0;
177         ty                         += fiy0;
178         tz                         += fiz0;
179         fshift[i_shift_offset+XX]  += tx;
180         fshift[i_shift_offset+YY]  += ty;
181         fshift[i_shift_offset+ZZ]  += tz;
182
183         ggid                        = gid[iidx];
184         /* Update potential energies */
185         kernel_data->energygrp_elec[ggid] += velecsum;
186
187         /* Increment number of inner iterations */
188         inneriter                  += j_index_end - j_index_start;
189
190         /* Outer loop uses 14 flops */
191     }
192
193     /* Increment number of outer iterations */
194     outeriter        += nri;
195
196     /* Update outer/inner flops */
197
198     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*14 + inneriter*28);
199 }
200 /*
201  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwNone_GeomP1P1_F_c
202  * Electrostatics interaction: Coulomb
203  * VdW interaction:            None
204  * Geometry:                   Particle-Particle
205  * Calculate force/pot:        Force
206  */
207 void
208 nb_kernel_ElecCoul_VdwNone_GeomP1P1_F_c
209                     (t_nblist * gmx_restrict                nlist,
210                      rvec * gmx_restrict                    xx,
211                      rvec * gmx_restrict                    ff,
212                      t_forcerec * gmx_restrict              fr,
213                      t_mdatoms * gmx_restrict               mdatoms,
214                      nb_kernel_data_t * gmx_restrict        kernel_data,
215                      t_nrnb * gmx_restrict                  nrnb)
216 {
217     int              i_shift_offset,i_coord_offset,j_coord_offset;
218     int              j_index_start,j_index_end;
219     int              nri,inr,ggid,iidx,jidx,jnr,outeriter,inneriter;
220     real             shX,shY,shZ,tx,ty,tz,fscal,rcutoff,rcutoff2;
221     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
222     real             *shiftvec,*fshift,*x,*f;
223     int              vdwioffset0;
224     real             ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
225     int              vdwjidx0;
226     real             jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
227     real             dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00,cexp1_00,cexp2_00;
228     real             velec,felec,velecsum,facel,crf,krf,krf2;
229     real             *charge;
230
231     x                = xx[0];
232     f                = ff[0];
233
234     nri              = nlist->nri;
235     iinr             = nlist->iinr;
236     jindex           = nlist->jindex;
237     jjnr             = nlist->jjnr;
238     shiftidx         = nlist->shift;
239     gid              = nlist->gid;
240     shiftvec         = fr->shift_vec[0];
241     fshift           = fr->fshift[0];
242     facel            = fr->epsfac;
243     charge           = mdatoms->chargeA;
244
245     outeriter        = 0;
246     inneriter        = 0;
247
248     /* Start outer loop over neighborlists */
249     for(iidx=0; iidx<nri; iidx++)
250     {
251         /* Load shift vector for this list */
252         i_shift_offset   = DIM*shiftidx[iidx];
253         shX              = shiftvec[i_shift_offset+XX];
254         shY              = shiftvec[i_shift_offset+YY];
255         shZ              = shiftvec[i_shift_offset+ZZ];
256
257         /* Load limits for loop over neighbors */
258         j_index_start    = jindex[iidx];
259         j_index_end      = jindex[iidx+1];
260
261         /* Get outer coordinate index */
262         inr              = iinr[iidx];
263         i_coord_offset   = DIM*inr;
264
265         /* Load i particle coords and add shift vector */
266         ix0              = shX + x[i_coord_offset+DIM*0+XX];
267         iy0              = shY + x[i_coord_offset+DIM*0+YY];
268         iz0              = shZ + x[i_coord_offset+DIM*0+ZZ];
269
270         fix0             = 0.0;
271         fiy0             = 0.0;
272         fiz0             = 0.0;
273
274         /* Load parameters for i particles */
275         iq0              = facel*charge[inr+0];
276
277         /* Start inner kernel loop */
278         for(jidx=j_index_start; jidx<j_index_end; jidx++)
279         {
280             /* Get j neighbor index, and coordinate index */
281             jnr              = jjnr[jidx];
282             j_coord_offset   = DIM*jnr;
283
284             /* load j atom coordinates */
285             jx0              = x[j_coord_offset+DIM*0+XX];
286             jy0              = x[j_coord_offset+DIM*0+YY];
287             jz0              = x[j_coord_offset+DIM*0+ZZ];
288
289             /* Calculate displacement vector */
290             dx00             = ix0 - jx0;
291             dy00             = iy0 - jy0;
292             dz00             = iz0 - jz0;
293
294             /* Calculate squared distance and things based on it */
295             rsq00            = dx00*dx00+dy00*dy00+dz00*dz00;
296
297             rinv00           = gmx_invsqrt(rsq00);
298
299             rinvsq00         = rinv00*rinv00;
300
301             /* Load parameters for j particles */
302             jq0              = charge[jnr+0];
303
304             /**************************
305              * CALCULATE INTERACTIONS *
306              **************************/
307
308             qq00             = iq0*jq0;
309
310             /* COULOMB ELECTROSTATICS */
311             velec            = qq00*rinv00;
312             felec            = velec*rinvsq00;
313
314             fscal            = felec;
315
316             /* Calculate temporary vectorial force */
317             tx               = fscal*dx00;
318             ty               = fscal*dy00;
319             tz               = fscal*dz00;
320
321             /* Update vectorial force */
322             fix0            += tx;
323             fiy0            += ty;
324             fiz0            += tz;
325             f[j_coord_offset+DIM*0+XX] -= tx;
326             f[j_coord_offset+DIM*0+YY] -= ty;
327             f[j_coord_offset+DIM*0+ZZ] -= tz;
328
329             /* Inner loop uses 27 flops */
330         }
331         /* End of innermost loop */
332
333         tx = ty = tz = 0;
334         f[i_coord_offset+DIM*0+XX] += fix0;
335         f[i_coord_offset+DIM*0+YY] += fiy0;
336         f[i_coord_offset+DIM*0+ZZ] += fiz0;
337         tx                         += fix0;
338         ty                         += fiy0;
339         tz                         += fiz0;
340         fshift[i_shift_offset+XX]  += tx;
341         fshift[i_shift_offset+YY]  += ty;
342         fshift[i_shift_offset+ZZ]  += tz;
343
344         /* Increment number of inner iterations */
345         inneriter                  += j_index_end - j_index_start;
346
347         /* Outer loop uses 13 flops */
348     }
349
350     /* Increment number of outer iterations */
351     outeriter        += nri;
352
353     /* Update outer/inner flops */
354
355     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*13 + inneriter*27);
356 }