4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
30 * Getting the Right Output Means no Artefacts in Calculating Stuff
33 /* This file is completely threadsafe - keep it that way! */
40 #include "shift_util.h"
44 void symmetrize_ghat(int nx
,int ny
,int nz
,real
***ghat
)
50 /* fprintf(stderr,"Symmetrizing Ghat function\n"); */
51 /* Only the lower octant of the rectangle has been saved,
52 * so we must construct the other 7 octants by symmetry operations.
54 for(i
=0; (i
<=nx
/2); i
++) {
56 for(j
=0; (j
<=ny
/2); j
++) {
58 for(k
=0; (k
<=nz
/2); k
++) {
61 ghat
[i
] [jjp
][k
] = ggg
;
62 ghat
[i
] [j
] [kkp
] = ggg
;
63 ghat
[i
] [jjp
][kkp
] = ggg
;
64 ghat
[iip
][j
] [k
] = ggg
;
65 ghat
[iip
][jjp
][k
] = ggg
;
66 ghat
[iip
][j
] [kkp
] = ggg
;
67 ghat
[iip
][jjp
][kkp
] = ggg
;
73 void mk_ghat(FILE *fp
,int nx
,int ny
,int nz
,real
***ghat
,
74 rvec box
,real r1
,real rc
,bool bSym
,bool bOld
)
77 int ixmax
,iymax
,izmax
;
93 /* Loop over lattice vectors in fourier space */
94 for(ix
=0; (ix
< ixmax
); ix
++) {
95 for(iy
=0; (iy
< iymax
); iy
++) {
96 for(iz
=0; (iz
< izmax
); iz
++) {
97 calc_k(lll
,ix
,iy
,iz
,nx
,ny
,nz
,k
);
99 if ((ix
== 0) && (iy
== 0) && (iz
== 0))
103 ggg
= gk(sqrt(k2
),rc
,r1
)/(k2
*EPSILON0
);
105 ggg
= gknew(sqrt(k2
),rc
,r1
)/(k2
*EPSILON0
);
107 ghat
[ix
][iy
][iz
]=ggg
;
112 symmetrize_ghat(nx
,ny
,nz
,ghat
);
115 void wr_ghat(char *fn
,int n1max
,int n2max
,int n3max
,real h1
,real h2
,real h3
,
116 real
***ghat
,int nalias
,int porder
,int niter
,bool bSym
,rvec beta
,
117 real r1
,real rc
,real pval
,real zval
,real eref
,real qopt
)
120 int N1MAX
,N2MAX
,N3MAX
;
126 fprintf(fp
,"%8d %8d %8d %15.10e %15.10e %15.10e\n",
127 n1max
,n2max
,n3max
,h1
,h2
,h3
);
128 fprintf(fp
,"%8d %8d %8d %8d %15.10e %15.10e %15.10e\n",
129 nalias
,porder
,niter
,bSym
,beta
[XX
],beta
[YY
],beta
[ZZ
]);
130 fprintf(fp
,"%10g %10g %10g %10g %10g %10g\n",
131 rc
,r1
,pval
,zval
,eref
,qopt
);
143 for(ii
=0; (ii
<N1MAX
); ii
++) {
144 for(jj
=0; (jj
<N2MAX
); jj
++) {
145 for(kk
=0,nn
=1; (kk
<N3MAX
); kk
++,nn
++) {
147 fprintf(fp
," %12.5e",ghat
[ii
][jj
][kk
]);
159 fp
=xvgropen("ghat.xvg","G-Hat","k","gk");
160 for(ii
=0; (ii
<N1MAX
); ii
++) {
161 rx
=sqr((real
)(ii
*h1
));
162 for(jj
=0; (jj
<N2MAX
); jj
++) {
163 ry
=rx
+sqr((real
)(jj
*h2
));
164 for(kk
=0; (kk
<N3MAX
); kk
++) {
165 rz
=ry
+sqr((real
)(kk
*h3
));
166 fprintf(fp
,"%10g %10g\n",sqrt(rz
),ghat
[ii
][jj
][kk
]);
173 void pr_scalar_gk(char *fn
,int nx
,int ny
,int nz
,rvec box
,real
***ghat
)
182 fp
=xvgropen(fn
,"G-Hat","k","gk");
183 for(ii
=0; (ii
<nx
); ii
++) {
184 for(jj
=0; (jj
<ny
); jj
++) {
185 for(kk
=0; (kk
<nz
); kk
++) {
186 calc_k(lll
,ii
,jj
,kk
,nx
,ny
,nz
,k
);
188 fprintf(fp
,"%10g %10g\n",k1
,ghat
[ii
][jj
][kk
]);
195 real
***rd_ghat(FILE *log
,char *fn
,ivec igrid
,rvec gridspace
,
196 rvec beta
,int *porder
,real
*r1
,real
*rc
)
200 double gx
,gy
,gz
,alX
,alY
,alZ
,ddd
;
201 double acut
,pval
,zval
,eref
,qopt
,r11
;
202 int nalias
,niter
,bSym
;
203 int ix
,iy
,iz
,ixmax
,iymax
,izmax
;
206 fscanf(in
,"%d%d%d%lf%lf%lf",&ix
,&iy
,&iz
,&gx
,&gy
,&gz
);
207 igrid
[XX
]=ix
, igrid
[YY
]=iy
, igrid
[ZZ
]=iz
;
208 gridspace
[XX
]=gx
, gridspace
[YY
]=gy
, gridspace
[ZZ
]=gz
;
209 fscanf(in
,"%d%d%d%d%lf%lf%lf",&nalias
,porder
,&niter
,&bSym
,&alX
,&alY
,&alZ
);
210 fscanf(in
,"%lf%lf%lf%lf%lf%lf",&acut
,&r11
,&pval
,&zval
,&eref
,&qopt
);
214 fprintf(log
,"\nOpened %s for reading ghat function\n",fn
);
215 fprintf(log
,"gridsize: %10d %10d %10d\n",ix
,iy
,iz
);
216 fprintf(log
,"spacing: %10g %10g %10g\n",gx
,gy
,gz
);
217 fprintf(log
," nalias porder niter bSym beta[X-Z]\n"
218 "%10d%10d%10d%10d%10g%10g%10g\n",
219 nalias
,*porder
,niter
,bSym
,alX
,alY
,alZ
);
220 fprintf(log
," acut r1 pval zval eref qopt\n"
221 "%10g%10g%10g%10g%10g%10g\n",acut
,*r1
,pval
,zval
,eref
,qopt
);
228 gh
= mk_rgrid(ix
,iy
,iz
);
239 fprintf(log
,"Reading ghat of %d %d %d\n",ixmax
,iymax
,izmax
);
240 for(ix
=0; (ix
<ixmax
); ix
++)
241 for(iy
=0; (iy
<iymax
); iy
++)
242 for(iz
=0; (iz
<izmax
); iz
++) {
243 fscanf(in
,"%lf",&ddd
);
244 gh
[ix
][iy
][iz
] = ddd
;
248 wr_ghat("output.hat",igrid
[XX
],igrid
[YY
],igrid
[ZZ
],gx
,gy
,gz
,gh
,
249 nalias
,*porder
,niter
,bSym
,beta
,
250 *r1
,*rc
,pval
,zval
,eref
,qopt
);
253 symmetrize_ghat(igrid
[XX
],igrid
[YY
],igrid
[ZZ
],gh
);
255 fprintf(log
,"\nSuccessfully read ghat function!\n");