-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.cpp
More file actions
161 lines (132 loc) · 4.49 KB
/
grid.cpp
File metadata and controls
161 lines (132 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <gromacs/typedefs.h>
#include <gromacs/pbc.h>
#include <gromacs/xvgr.h>
#include <gromacs/vec.h>
#include <gromacs/princ.h>
#include "grid.h"
grid::grid(real spacing_, rvec minr_, rvec maxr_) :
spacing(spacing_), //minr(minr_), maxr(maxr_),
nx((size_t)( (maxr_[XX] - minr_[XX])/spacing_)),
ny((size_t)( (maxr_[YY] - minr_[YY])/spacing_)),
nz((size_t)( (maxr_[ZZ] - minr_[ZZ])/spacing_)),
grid_N(nx*ny*nz),
grid_sum(nx*ny*nz),
grid_inv_sum(nx*ny*nz)
{
//copy_rvec(minr_, minr);
//copy_rvec(maxr_, maxr);
//zero_r[XX] =
// the grid indices of the zero coordinates
int zx=int(0.5-minr_[XX]/spacing);
if (zx < 1)
zx=1;
int zy=int(0.5-minr_[YY]/spacing);
if (zy < 1)
zy=1;
int zz=int(0.5-minr_[ZZ]/spacing);
if (zz < 1)
zz=1;
minr[XX] = (-zx+0.5)*spacing;
minr[YY] = (-zy+0.5)*spacing;
minr[ZZ] = (-zz+0.5)*spacing;
maxr[XX] = minr[XX] + nx*spacing;
maxr[YY] = minr[YY] + ny*spacing;
maxr[ZZ] = minr[ZZ] + nz*spacing;
printf("Allocating grid: (%g -- %g, %g -- %g, %g -- %g)\n",
minr_[XX], maxr_[XX],
minr_[YY], maxr_[YY],
minr_[ZZ], maxr_[ZZ]);
printf("Allowed positions: (%g -- %g, %g -- %g, %g -- %g)\n",
minr[XX], maxr[XX],
minr[YY], maxr[YY],
minr[ZZ], maxr[ZZ]);
printf(" Grid size: (%lu, %lu, %lu)\n", nx, ny, nz);
//printf(" Grid zero point: (%ld, %ld, %ld)\n", zx, zy, zz);
printf(" %gM grid points\n", (nx*ny*nz)/(1024.*1024.));
printf("\n");
for(size_t i=0; i<grid_N.size(); ++i)
{
grid_N[i] = 0;
grid_sum[i] = 0.;
}
sample_count=0;
}
void grid::avg(real &arithmetic, real &harmonic, size_t &Na, size_t &Nh)
{
real asum=0;
real hsum=0;
Na=0;
Nh=0;
for(size_t i=0;i<grid_N.size();i++)
{
int N=grid_N[i];
real gsum=grid_sum[i];
hsum += N/gsum;
Nh++;
if (N>0)
{
asum += gsum/N;
Na++;
}
}
arithmetic=asum/Na;
harmonic=Nh/hsum;
}
void write_grids(const char *filename, const grid *ref_grid,
const grid *pers_grid,
const grid *exch_grid)
{
if ( (exch_grid->get_nx() != pers_grid->get_nx()) ||
(exch_grid->get_ny() != pers_grid->get_ny()) ||
(exch_grid->get_nz() != pers_grid->get_nz()) )
{
fprintf(stderr, "ERROR ERROR grids unequal in write_grids!!!!");
fprintf(stdout, "ERROR ERROR grids unequal in write_grids!!!!");
exit(1);
}
size_t nx=exch_grid->get_nx();
size_t ny=exch_grid->get_ny();
size_t nz=exch_grid->get_nz();
const rvec &minr(exch_grid->get_minr());
double spacing=exch_grid->get_spacing();
double zx=(0 - minr[XX])/spacing;
double zy=(0 - minr[YY])/spacing;
double zz=(0 - minr[ZZ])/spacing;
size_t sample_count=ref_grid->get_sample_count();
size_t sample_size=ref_grid->get_sample_size();
//double ref_norm=((double)sample_count * (double)sample_size);
double ref_norm=((double)sample_count)*spacing*spacing*spacing;
FILE *outf=fopen(filename, "w");
fprintf(outf, "# Nx Ny Nz spacing zero_x zero_y zero_z\n");
fprintf(outf, "%lu %lu %lu %g %g %g %g\n", nx, ny, nz,
spacing, zx, zy, zz);
fprintf(outf, "# ix iy iz N_ref N_pers sum<t_pers> sum<1/t_pers> N_exch sum<t_exch> sum<1/t_exch>\n");
for(size_t iz=0; iz<nz; ++iz)
{
for(size_t iy=0; iy<ny; ++iy)
{
for(size_t ix=0; ix<nx; ++ix)
{
size_t index=pers_grid->get_index(ix, iy, iz);
unsigned int N_ref = ref_grid->get_N(index);
double N_ref_norm = N_ref/ref_norm;
unsigned int N_pers = pers_grid->get_N(index);
double sumt_pers = pers_grid->get_sum(index);
double suminv_pers = pers_grid->get_inv_sum(index);
unsigned int N_exch = exch_grid->get_N(index);
double sumt_exch = exch_grid->get_sum(index);
double suminv_exch = exch_grid->get_inv_sum(index);
fprintf(outf, "%lu %lu %lu %g %u %g %g %u %g %g\n",
ix, iy, iz, N_ref_norm,
N_pers, sumt_pers, suminv_pers,
N_exch, sumt_exch, suminv_exch);
}
}
}
fclose(outf);
}