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