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