Merge remote-tracking branch 'origin/release-4-6' into HEAD
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_adress_c / nb_kernel111_c_adress.c
1 /*
2  * Copyright (c) Erik Lindahl, David van der Spoel 2003
3  * 
4  * This file is generated automatically at compile time
5  * by the program mknb in the Gromacs distribution.
6  *
7  * Options used when generation this file:
8  * Language:         c
9  * Precision:        single
10  * Threads:          yes
11  * Software invsqrt: no
12  * PowerPC invsqrt:  no
13  * Prefetch forces:  no
14  * Adress kernel:  yes
15  * Comments:         no
16  */
17 #ifdef HAVE_CONFIG_H
18 #include<config.h>
19 #endif
20 #ifdef GMX_THREAD_SHM_FDECOMP
21 #include<thread_mpi.h>
22 #endif
23 #define ALMOST_ZERO 1e-30
24 #define ALMOST_ONE 1-(1e-30)
25 #include<math.h>
26
27 #include "nb_kernel111_adress.h"
28
29
30
31 /*
32  * Gromacs nonbonded kernel nb_kernel111_adress_cg
33  * Coulomb interaction:     Normal Coulomb
34  * VdW interaction:         Lennard-Jones
35  * water optimization:      SPC/TIP3P - other atoms
36  * Calculate forces:        yes
37  */
38 void nb_kernel111_adress_cg(
39                     int *           p_nri,
40                     int *           iinr,
41                     int *           jindex,
42                     int *           jjnr,
43                     int *           shift,
44                     real *         shiftvec,
45                     real *         fshift,
46                     int *           gid,
47                     real *         pos,
48                     real *         faction,
49                     real *         charge,
50                     real *         p_facel,
51                     real *         p_krf,
52                     real *         p_crf,
53                     real *         Vc,
54                     int *           type,
55                     int *           p_ntype,
56                     real *         vdwparam,
57                     real *         Vvdw,
58                     real *         p_tabscale,
59                     real *         VFtab,
60                     real *         invsqrta,
61                     real *         dvda,
62                     real *         p_gbtabscale,
63                     real *         GBtab,
64                     int *           p_nthreads,
65                     int *           count,
66                     void *          mtx,
67                     int *           outeriter,
68                     int *           inneriter,
69                     real           force_cap,
70                     real *         wf)
71 {
72     int           nri,ntype,nthreads;
73     real         facel,krf,crf,tabscale,gbtabscale;
74     int           n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid;
75     int           nn0,nn1,nouter,ninner;
76     real         shX,shY,shZ;
77     real         fscal,tx,ty,tz;
78     real         rinvsq;
79     real         jq;
80     real         qq,vcoul,vctot;
81     int           nti;
82     int           tj;
83     real         rinvsix;
84     real         Vvdw6,Vvdwtot;
85     real         Vvdw12;
86     real         ix1,iy1,iz1,fix1,fiy1,fiz1;
87     real         ix2,iy2,iz2,fix2,fiy2,fiz2;
88     real         ix3,iy3,iz3,fix3,fiy3,fiz3;
89     real         jx1,jy1,jz1,fjx1,fjy1,fjz1;
90     real         dx11,dy11,dz11,rsq11,rinv11;
91     real         dx21,dy21,dz21,rsq21,rinv21;
92     real         dx31,dy31,dz31,rsq31,rinv31;
93     real         qO,qH;
94     real         c6,c12;
95     real         weight_cg1, weight_cg2, weight_product;
96     real         hybscal;
97
98     nri              = *p_nri;         
99     ntype            = *p_ntype;       
100     nthreads         = *p_nthreads;    
101     facel            = *p_facel;       
102     krf              = *p_krf;         
103     crf              = *p_crf;         
104     tabscale         = *p_tabscale;    
105     ii               = iinr[0];        
106     qO               = facel*charge[ii];
107     qH               = facel*charge[ii+1];
108     nti              = 2*ntype*type[ii];
109
110     nouter           = 0;              
111     ninner           = 0;              
112     
113     do
114     {
115         #ifdef GMX_THREAD_SHM_FDECOMP
116         tMPI_Thread_mutex_lock((tMPI_Thread_mutex_t *)mtx);
117         nn0              = *count;         
118         nn1              = nn0+(nri-nn0)/(2*nthreads)+10;
119         *count           = nn1;            
120         tMPI_Thread_mutex_unlock((tMPI_Thread_mutex_t *)mtx);
121         if(nn1>nri) nn1=nri;
122         #else
123         nn0 = 0;
124         nn1 = nri;
125         #endif
126         
127         for(n=nn0; (n<nn1); n++)
128         {
129             is3              = 3*shift[n];     
130             shX              = shiftvec[is3];  
131             shY              = shiftvec[is3+1];
132             shZ              = shiftvec[is3+2];
133             nj0              = jindex[n];      
134             nj1              = jindex[n+1];    
135             ii               = iinr[n];        
136             ii3              = 3*ii;           
137             ix1              = shX + pos[ii3+0];
138             iy1              = shY + pos[ii3+1];
139             iz1              = shZ + pos[ii3+2];
140             ix2              = shX + pos[ii3+3];
141             iy2              = shY + pos[ii3+4];
142             iz2              = shZ + pos[ii3+5];
143             ix3              = shX + pos[ii3+6];
144             iy3              = shY + pos[ii3+7];
145             iz3              = shZ + pos[ii3+8];
146             weight_cg1       = wf[ii];         
147             vctot            = 0;              
148             Vvdwtot          = 0;              
149             fix1             = 0;              
150             fiy1             = 0;              
151             fiz1             = 0;              
152             fix2             = 0;              
153             fiy2             = 0;              
154             fiz2             = 0;              
155             fix3             = 0;              
156             fiy3             = 0;              
157             fiz3             = 0;              
158             
159             for(k=nj0; (k<nj1); k++)
160             {
161                 jnr              = jjnr[k];        
162                 weight_cg2       = wf[jnr];        
163                 weight_product   = weight_cg1*weight_cg2;
164                 if (weight_product < ALMOST_ZERO) {
165                        hybscal = 1.0;
166                 }
167                 else if (weight_product >= ALMOST_ONE)
168                 {
169                   /* force is zero, skip this molecule */
170                        continue;
171                 }
172                 else
173                 {
174                    hybscal = 1.0 - weight_product;
175                 }
176                 j3               = 3*jnr;          
177                 jx1              = pos[j3+0];      
178                 jy1              = pos[j3+1];      
179                 jz1              = pos[j3+2];      
180                 dx11             = ix1 - jx1;      
181                 dy11             = iy1 - jy1;      
182                 dz11             = iz1 - jz1;      
183                 rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
184                 dx21             = ix2 - jx1;      
185                 dy21             = iy2 - jy1;      
186                 dz21             = iz2 - jz1;      
187                 rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
188                 dx31             = ix3 - jx1;      
189                 dy31             = iy3 - jy1;      
190                 dz31             = iz3 - jz1;      
191                 rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
192                 rinv11           = 1.0/sqrt(rsq11);
193                 rinv21           = 1.0/sqrt(rsq21);
194                 rinv31           = 1.0/sqrt(rsq31);
195                 jq               = charge[jnr+0];  
196                 qq               = qO*jq;          
197                 tj               = nti+2*type[jnr];
198                 c6               = vdwparam[tj];   
199                 c12              = vdwparam[tj+1]; 
200                 rinvsq           = rinv11*rinv11;  
201                 vcoul            = qq*rinv11;      
202                 vctot            = vctot+vcoul;    
203                 rinvsix          = rinvsq*rinvsq*rinvsq;
204                 Vvdw6            = c6*rinvsix;     
205                 Vvdw12           = c12*rinvsix*rinvsix;
206                 Vvdwtot          = Vvdwtot+Vvdw12-Vvdw6;
207                 fscal            = (vcoul+12.0*Vvdw12-6.0*Vvdw6)*rinvsq;
208                 fscal *= hybscal;
209                 tx               = fscal*dx11;     
210                 ty               = fscal*dy11;     
211                 tz               = fscal*dz11;     
212                 fix1             = fix1 + tx;      
213                 fiy1             = fiy1 + ty;      
214                 fiz1             = fiz1 + tz;      
215                 fjx1             = faction[j3+0] - tx;
216                 fjy1             = faction[j3+1] - ty;
217                 fjz1             = faction[j3+2] - tz;
218                 qq               = qH*jq;          
219                 rinvsq           = rinv21*rinv21;  
220                 vcoul            = qq*rinv21;      
221                 vctot            = vctot+vcoul;    
222                 fscal            = (vcoul)*rinvsq; 
223                 fscal *= hybscal;
224                 tx               = fscal*dx21;     
225                 ty               = fscal*dy21;     
226                 tz               = fscal*dz21;     
227                 fix2             = fix2 + tx;      
228                 fiy2             = fiy2 + ty;      
229                 fiz2             = fiz2 + tz;      
230                 fjx1             = fjx1 - tx;      
231                 fjy1             = fjy1 - ty;      
232                 fjz1             = fjz1 - tz;      
233                 rinvsq           = rinv31*rinv31;  
234                 vcoul            = qq*rinv31;      
235                 vctot            = vctot+vcoul;    
236                 fscal            = (vcoul)*rinvsq; 
237                 fscal *= hybscal;
238                 tx               = fscal*dx31;     
239                 ty               = fscal*dy31;     
240                 tz               = fscal*dz31;     
241                 fix3             = fix3 + tx;      
242                 fiy3             = fiy3 + ty;      
243                 fiz3             = fiz3 + tz;      
244                 faction[j3+0]    = fjx1 - tx;      
245                 faction[j3+1]    = fjy1 - ty;      
246                 faction[j3+2]    = fjz1 - tz;      
247             }
248             
249             faction[ii3+0]   = faction[ii3+0] + fix1;
250             faction[ii3+1]   = faction[ii3+1] + fiy1;
251             faction[ii3+2]   = faction[ii3+2] + fiz1;
252             faction[ii3+3]   = faction[ii3+3] + fix2;
253             faction[ii3+4]   = faction[ii3+4] + fiy2;
254             faction[ii3+5]   = faction[ii3+5] + fiz2;
255             faction[ii3+6]   = faction[ii3+6] + fix3;
256             faction[ii3+7]   = faction[ii3+7] + fiy3;
257             faction[ii3+8]   = faction[ii3+8] + fiz3;
258             fshift[is3]      = fshift[is3]+fix1+fix2+fix3;
259             fshift[is3+1]    = fshift[is3+1]+fiy1+fiy2+fiy3;
260             fshift[is3+2]    = fshift[is3+2]+fiz1+fiz2+fiz3;
261             ggid             = gid[n];         
262             Vc[ggid]         = Vc[ggid] + vctot;
263             Vvdw[ggid]       = Vvdw[ggid] + Vvdwtot;
264             ninner           = ninner + nj1 - nj0;
265         }
266         
267         nouter           = nouter + nn1 - nn0;
268     }
269     while (nn1<nri);
270     
271     *outeriter       = nouter;         
272     *inneriter       = ninner;         
273 }
274
275
276
277
278
279 /*
280  * Gromacs nonbonded kernel nb_kernel111_adress_ex
281  * Coulomb interaction:     Normal Coulomb
282  * VdW interaction:         Lennard-Jones
283  * water optimization:      SPC/TIP3P - other atoms
284  * Calculate forces:        yes
285  */
286 void nb_kernel111_adress_ex(
287                     int *           p_nri,
288                     int *           iinr,
289                     int *           jindex,
290                     int *           jjnr,
291                     int *           shift,
292                     real *         shiftvec,
293                     real *         fshift,
294                     int *           gid,
295                     real *         pos,
296                     real *         faction,
297                     real *         charge,
298                     real *         p_facel,
299                     real *         p_krf,
300                     real *         p_crf,
301                     real *         Vc,
302                     int *           type,
303                     int *           p_ntype,
304                     real *         vdwparam,
305                     real *         Vvdw,
306                     real *         p_tabscale,
307                     real *         VFtab,
308                     real *         invsqrta,
309                     real *         dvda,
310                     real *         p_gbtabscale,
311                     real *         GBtab,
312                     int *           p_nthreads,
313                     int *           count,
314                     void *          mtx,
315                     int *           outeriter,
316                     int *           inneriter,
317                     real           force_cap,
318                     real *         wf)
319 {
320     int           nri,ntype,nthreads;
321     real         facel,krf,crf,tabscale,gbtabscale;
322     int           n,ii,is3,ii3,k,nj0,nj1,jnr,j3,ggid;
323     int           nn0,nn1,nouter,ninner;
324     real         shX,shY,shZ;
325     real         fscal,tx,ty,tz;
326     real         rinvsq;
327     real         jq;
328     real         qq,vcoul,vctot;
329     int           nti;
330     int           tj;
331     real         rinvsix;
332     real         Vvdw6,Vvdwtot;
333     real         Vvdw12;
334     real         ix1,iy1,iz1,fix1,fiy1,fiz1;
335     real         ix2,iy2,iz2,fix2,fiy2,fiz2;
336     real         ix3,iy3,iz3,fix3,fiy3,fiz3;
337     real         jx1,jy1,jz1,fjx1,fjy1,fjz1;
338     real         dx11,dy11,dz11,rsq11,rinv11;
339     real         dx21,dy21,dz21,rsq21,rinv21;
340     real         dx31,dy31,dz31,rsq31,rinv31;
341     real         qO,qH;
342     real         c6,c12;
343     real         weight_cg1, weight_cg2, weight_product;
344     real         hybscal;
345
346     nri              = *p_nri;         
347     ntype            = *p_ntype;       
348     nthreads         = *p_nthreads;    
349     facel            = *p_facel;       
350     krf              = *p_krf;         
351     crf              = *p_crf;         
352     tabscale         = *p_tabscale;    
353     ii               = iinr[0];        
354     qO               = facel*charge[ii];
355     qH               = facel*charge[ii+1];
356     nti              = 2*ntype*type[ii];
357
358     nouter           = 0;              
359     ninner           = 0;              
360     
361     do
362     {
363         #ifdef GMX_THREAD_SHM_FDECOMP
364         tMPI_Thread_mutex_lock((tMPI_Thread_mutex_t *)mtx);
365         nn0              = *count;         
366         nn1              = nn0+(nri-nn0)/(2*nthreads)+10;
367         *count           = nn1;            
368         tMPI_Thread_mutex_unlock((tMPI_Thread_mutex_t *)mtx);
369         if(nn1>nri) nn1=nri;
370         #else
371         nn0 = 0;
372         nn1 = nri;
373         #endif
374         
375         for(n=nn0; (n<nn1); n++)
376         {
377             is3              = 3*shift[n];     
378             shX              = shiftvec[is3];  
379             shY              = shiftvec[is3+1];
380             shZ              = shiftvec[is3+2];
381             nj0              = jindex[n];      
382             nj1              = jindex[n+1];    
383             ii               = iinr[n];        
384             ii3              = 3*ii;           
385             ix1              = shX + pos[ii3+0];
386             iy1              = shY + pos[ii3+1];
387             iz1              = shZ + pos[ii3+2];
388             ix2              = shX + pos[ii3+3];
389             iy2              = shY + pos[ii3+4];
390             iz2              = shZ + pos[ii3+5];
391             ix3              = shX + pos[ii3+6];
392             iy3              = shY + pos[ii3+7];
393             iz3              = shZ + pos[ii3+8];
394             weight_cg1       = wf[ii];         
395             vctot            = 0;              
396             Vvdwtot          = 0;              
397             fix1             = 0;              
398             fiy1             = 0;              
399             fiz1             = 0;              
400             fix2             = 0;              
401             fiy2             = 0;              
402             fiz2             = 0;              
403             fix3             = 0;              
404             fiy3             = 0;              
405             fiz3             = 0;              
406             
407             for(k=nj0; (k<nj1); k++)
408             {
409                 jnr              = jjnr[k];        
410                 weight_cg2       = wf[jnr];        
411                 weight_product   = weight_cg1*weight_cg2;
412                 if (weight_product < ALMOST_ZERO) {
413                 /* force is zero, skip this molecule */
414                  continue;
415                 }
416                 else if (weight_product >= ALMOST_ONE)
417                 {
418                        hybscal = 1.0;
419                 }
420                 else
421                 {
422                    hybscal = weight_product;
423                 }
424                 j3               = 3*jnr;          
425                 jx1              = pos[j3+0];      
426                 jy1              = pos[j3+1];      
427                 jz1              = pos[j3+2];      
428                 dx11             = ix1 - jx1;      
429                 dy11             = iy1 - jy1;      
430                 dz11             = iz1 - jz1;      
431                 rsq11            = dx11*dx11+dy11*dy11+dz11*dz11;
432                 dx21             = ix2 - jx1;      
433                 dy21             = iy2 - jy1;      
434                 dz21             = iz2 - jz1;      
435                 rsq21            = dx21*dx21+dy21*dy21+dz21*dz21;
436                 dx31             = ix3 - jx1;      
437                 dy31             = iy3 - jy1;      
438                 dz31             = iz3 - jz1;      
439                 rsq31            = dx31*dx31+dy31*dy31+dz31*dz31;
440                 rinv11           = 1.0/sqrt(rsq11);
441                 rinv21           = 1.0/sqrt(rsq21);
442                 rinv31           = 1.0/sqrt(rsq31);
443                 jq               = charge[jnr+0];  
444                 qq               = qO*jq;          
445                 tj               = nti+2*type[jnr];
446                 c6               = vdwparam[tj];   
447                 c12              = vdwparam[tj+1]; 
448                 rinvsq           = rinv11*rinv11;  
449                 vcoul            = qq*rinv11;      
450                 vctot            = vctot+vcoul;    
451                 rinvsix          = rinvsq*rinvsq*rinvsq;
452                 Vvdw6            = c6*rinvsix;     
453                 Vvdw12           = c12*rinvsix*rinvsix;
454                 Vvdwtot          = Vvdwtot+Vvdw12-Vvdw6;
455                 fscal            = (vcoul+12.0*Vvdw12-6.0*Vvdw6)*rinvsq;
456                 fscal *= hybscal;
457                 if(force_cap>0 && (fabs(fscal)> force_cap)){
458                 fscal=force_cap*fscal/fabs(fscal);
459                 }
460                 tx               = fscal*dx11;     
461                 ty               = fscal*dy11;     
462                 tz               = fscal*dz11;     
463                 fix1             = fix1 + tx;      
464                 fiy1             = fiy1 + ty;      
465                 fiz1             = fiz1 + tz;      
466                 fjx1             = faction[j3+0] - tx;
467                 fjy1             = faction[j3+1] - ty;
468                 fjz1             = faction[j3+2] - tz;
469                 qq               = qH*jq;          
470                 rinvsq           = rinv21*rinv21;  
471                 vcoul            = qq*rinv21;      
472                 vctot            = vctot+vcoul;    
473                 fscal            = (vcoul)*rinvsq; 
474                 fscal *= hybscal;
475                 if(force_cap>0 && (fabs(fscal)> force_cap)){
476                 fscal=force_cap*fscal/fabs(fscal);
477                 }
478                 tx               = fscal*dx21;     
479                 ty               = fscal*dy21;     
480                 tz               = fscal*dz21;     
481                 fix2             = fix2 + tx;      
482                 fiy2             = fiy2 + ty;      
483                 fiz2             = fiz2 + tz;      
484                 fjx1             = fjx1 - tx;      
485                 fjy1             = fjy1 - ty;      
486                 fjz1             = fjz1 - tz;      
487                 rinvsq           = rinv31*rinv31;  
488                 vcoul            = qq*rinv31;      
489                 vctot            = vctot+vcoul;    
490                 fscal            = (vcoul)*rinvsq; 
491                 fscal *= hybscal;
492                 if(force_cap>0 && (fabs(fscal)> force_cap)){
493                 fscal=force_cap*fscal/fabs(fscal);
494                 }
495                 tx               = fscal*dx31;     
496                 ty               = fscal*dy31;     
497                 tz               = fscal*dz31;     
498                 fix3             = fix3 + tx;      
499                 fiy3             = fiy3 + ty;      
500                 fiz3             = fiz3 + tz;      
501                 faction[j3+0]    = fjx1 - tx;      
502                 faction[j3+1]    = fjy1 - ty;      
503                 faction[j3+2]    = fjz1 - tz;      
504             }
505             
506             faction[ii3+0]   = faction[ii3+0] + fix1;
507             faction[ii3+1]   = faction[ii3+1] + fiy1;
508             faction[ii3+2]   = faction[ii3+2] + fiz1;
509             faction[ii3+3]   = faction[ii3+3] + fix2;
510             faction[ii3+4]   = faction[ii3+4] + fiy2;
511             faction[ii3+5]   = faction[ii3+5] + fiz2;
512             faction[ii3+6]   = faction[ii3+6] + fix3;
513             faction[ii3+7]   = faction[ii3+7] + fiy3;
514             faction[ii3+8]   = faction[ii3+8] + fiz3;
515             fshift[is3]      = fshift[is3]+fix1+fix2+fix3;
516             fshift[is3+1]    = fshift[is3+1]+fiy1+fiy2+fiy3;
517             fshift[is3+2]    = fshift[is3+2]+fiz1+fiz2+fiz3;
518             ggid             = gid[n];         
519             Vc[ggid]         = Vc[ggid] + vctot;
520             Vvdw[ggid]       = Vvdw[ggid] + Vvdwtot;
521             ninner           = ninner + nj1 - nj0;
522         }
523         
524         nouter           = nouter + nn1 - nn0;
525     }
526     while (nn1<nri);
527     
528     *outeriter       = nouter;         
529     *inneriter       = ninner;         
530 }
531
532