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