Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / src / mdlib / wnblist.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team,
6  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 /* This file is completely threadsafe - keep it that way! */
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 #include <stdio.h>
44 #include <string.h>
45 #include "string2.h"
46 #include "force.h"
47 #include "smalloc.h"
48 #include "ns.h"
49 #include "nrnb.h"
50 #include "gmx_fatal.h"
51 #include "macros.h"
52 #include "futil.h"
53 #include "names.h"
54 #include "domdec.h"
55 #include "gmxfio.h"
56
57 #define header "Neighborlist:"
58
59 static void write_nblist(FILE *out,gmx_domdec_t *dd,t_nblist *nblist,int nDNL)
60 {
61   int i,nii,ii,j,zi,zj0,zj1,aj,zj,nj;
62   int ca1[DD_MAXZONE],np[DD_MAXZONE];
63   gmx_domdec_zones_t *dd_zones;
64
65   if (nblist->nri > 0) {  
66     fprintf(out,"ielec: %d, ivdw: %d, free_energy: %d, Solvent opt: %s\n",
67             nblist->ielec,nblist->ivdw,nblist->free_energy,
68             gmx_nblist_geometry_names[nblist->igeometry]);
69     fprintf(out,"nri: %d  npair: %d\n",nblist->nri,nblist->nrj);
70     if (dd) {
71       dd_zones = domdec_zones(dd);
72
73       for(zi=0; zi<dd_zones->n; zi++)
74         ca1[zi] = dd->cgindex[dd_zones->cg_range[zi+1]];
75       i = 0;
76       for(zi=0; zi<dd_zones->nizone; zi++) {
77         zj0 = dd_zones->izone[zi].j0;
78         zj1 = dd_zones->izone[zi].j1;
79         for(zj=zj0; zj<zj1; zj++)
80           np[zj] = 0;
81         while(i < nblist->nri && nblist->iinr[i] < ca1[zi]) {
82           for(j=nblist->jindex[i]; (j<nblist->jindex[i+1]); j++) {
83             aj = nblist->jjnr[j];
84             zj = zj0;
85             while (aj >= ca1[zj])
86               zj++;
87             np[zj]++;
88           }
89           i++;
90         }
91         fprintf(out,"DD zone %d:",zi);
92         for(zj=zj0; zj<zj1; zj++)
93           fprintf(out," %d %d",zj,np[zj]);
94         fprintf(out,"\n");
95       }
96     }
97     if (nDNL >= 2) {
98       for(i=0; i<nblist->nri; i++) {
99         nii = 1;
100         if (nDNL >= 3 && nblist->igeometry != GMX_NBLIST_GEOMETRY_PARTICLE_PARTICLE)
101           nii = 3;
102         nj = nblist->jindex[i+1] - nblist->jindex[i];
103         fprintf(out,"i: %d shift: %d gid: %d nj: %d\n",
104                 ddglatnr(dd,nblist->iinr[i]),
105                 nblist->shift[i],nblist->gid[i],nj);
106         for(ii=0; ii<nii; ii++) {
107           for(j=nblist->jindex[i]; (j<nblist->jindex[i+1]); j++) {
108             fprintf(out,"  i: %5d  j: %5d\n",
109                     ddglatnr(dd,nblist->iinr[i]+ii),
110                     ddglatnr(dd,nblist->jjnr[j]));
111           }
112         }
113       }
114     }
115     fflush(out);
116   }
117 }
118
119 static void set_mat(FILE *fp,int **mat,int i0,int ni,int j0,int nj,
120                     gmx_bool bSymm,int shift)
121 {
122   int i,j;
123   
124   for(i=i0; (i<i0+ni); i++) {
125     for(j=j0; (j<j0+nj); j++) {
126       if (mat[i][j] != 0)
127         fprintf(fp,"mat[%d][%d] changing from %d to %d\n",
128                 i,j,mat[i][j],shift+1);
129       mat[i][j] = shift+1;
130       if (bSymm)
131         mat[j][i] = 27-shift;
132     }
133   }
134 }
135
136
137
138 void dump_nblist(FILE *out,t_commrec *cr,t_forcerec *fr,int nDNL)
139 {
140 #if 0
141   static FILE *fp=NULL;
142   char buf[STRLEN];
143   int  n,i;
144
145   if (fp == NULL) {
146     if (PAR(cr)) {
147       sprintf(buf,"nlist_n%d.txt",cr->nodeid);
148     } else {
149       sprintf(buf,"nlist.txt");
150     }
151     fp = gmx_fio_fopen(buf,"w");
152   }
153   fprintf(fp,"%s\n",header);
154
155   for(n=0; (n<fr->nnblists); n++)
156     for(i=0; (i<eNL_NR); i++) 
157       write_nblist(fp,cr->dd,&fr->nblists[n].nlist_sr[i],nDNL);
158 #endif
159   char buf[STRLEN];
160   int  n,i;
161
162   fprintf(out,"%s\n",header);
163
164   for(n=0; (n<fr->nnblists); n++)
165     for(i=0; (i<eNL_NR); i++) 
166       write_nblist(out,cr->dd,&fr->nblists[n].nlist_sr[i],nDNL);
167
168 }
169