21 #define MIN_DEBUG_LEVEL 4
43 grid->
initialize(potfilename, simParams, mgridParams);
76 NAMD_bug(
"GridforceGrid::unpack_grid called with unknown grid type!");
88 DebugM(4,
"Checking whether grid fits periodic cell\n");
90 for (
int i = 0; i < 8; i++) {
93 if ((pos - pos_wrapped).length() > 1.) {
94 DebugM(5,
"(" << pos <<
") != (" << pos_wrapped <<
")\n" <<
endi);
113 if (idx >= 8 || idx < 0) {
116 }
else if (corners[idx] !=
Vector()) {
123 if (idx & (1 << 0)) pos += e *
Vector(
get_k0()-1, 0, 0);
124 if (idx & (1 << 1)) pos += e * Vector(0,
get_k1()-1, 0);
125 if (idx & (1 << 2)) pos += e * Vector(0, 0,
get_k2()-1);
127 DebugM(4,
"corner " << idx <<
" = " << pos <<
"\n" <<
endi);
162 msg->
put(3*
sizeof(
int), (
char*)
k);
166 msg->
put(3*
sizeof(
long int), (
char*)
dk);
178 msg->
put(3*
sizeof(
float), (
char*)
offset);
179 msg->
put(3*
sizeof(
float), (
char*)
gap);
180 msg->
put(3*
sizeof(
float), (
char*)
gapinv);
209 msg->
get(numSubgrids);
212 DebugM(3,
"numSubgrids = " << numSubgrids <<
"\n");
215 msg->
get(3*
sizeof(
int), (
char*)
k);
219 msg->
get(3*
sizeof(
long int), (
char*)
dk);
233 msg->
get(3*
sizeof(
float), (
char*)
offset);
234 msg->
get(3*
sizeof(
float), (
char*)
gap);
235 msg->
get(3*
sizeof(
float), (
char*)
gapinv);
246 DebugM(3,
"Creating subgrids array, size " << numSubgrids <<
"\n" <<
endi);
259 long int poten_offset;
264 }
while (line[0] ==
'#');
265 fseek(
poten_fp, poten_offset, SEEK_SET);
268 fscanf(
poten_fp,
"object %*d class gridpositions counts %d %d %d\n",
273 fscanf(
poten_fp,
"origin %lf %lf %lf\n",
283 *
Position(k_nopad[0]-1, k_nopad[1]-1, k_nopad[2]-1);
285 fscanf(
poten_fp,
"object %*d class gridconnections counts %*lf %*lf %*lf\n");
286 fscanf(
poten_fp,
"object %*d class array type double rank 0 items %*d data follows\n");
303 DebugM(4,
"e = " <<
e <<
"\n");
309 DebugM(4,
"Beginning of readSubgridHierarchy, generation = " <<
generation <<
", totalGrids = " << totalGrids <<
"\n" <<
endi);
311 int elems, generation_in;
317 elems = fscanf(
poten_fp,
"# namdnugrid subgrid %d generation %d min %d %d %d max %d %d %d subgrids count %d\n",
318 &
subgrids[i]->subgridIdx, &generation_in,
324 sprintf(msg,
"Problem reading Gridforce potential file! (%d < 9)", elems);
330 if (
subgrids[i]->subgridIdx != (totalGrids - 1)) {
332 sprintf(msg,
"Problem reading Gridforce potential file! (%d != %d)",
subgrids[i]->subgridIdx, totalGrids - 1);
337 sprintf(msg,
"Problem reading Gridforce potential file! (%d != %d)",
subgrids[i]->
generation, generation_in);
379 DebugM(3,
"calling GridforceFullBaseGrid::pack\n" <<
endi);
413 DebugM(3,
"adding to subgridsFlat\n" <<
endi);
421 DebugM(4,
"subgrids[" << i <<
"]->numSubgrids = " <<
subgrids[i]->numSubgrids <<
"\n" <<
endi);
438 NAMD_die(
"Problem reading grid force potential file");
450 long int poten_offset;
455 flag = sscanf(line,
"# namdnugrid version %f\n", &version);
456 }
while (line[0] ==
'#' && !flag);
459 if (version != 1.0) {
460 NAMD_die(
"Unsupported version of non-uniform grid file format!");
466 fseek(
poten_fp, poten_offset, SEEK_SET);
484 for (
long int count = 0; count <
size_nopad; count++) {
485 int err = fscanf(
poten_fp,
"%f", &tmp2);
486 if (err == EOF || err == 0) {
487 NAMD_die(
"Grid force potential file incorrectly formatted");
489 grid_nopad[count] = tmp2 *
factor;
499 Kvec[0] =
e *
Position(k_nopad[0]-1, 0, 0);
500 Kvec[1] =
e *
Position(0, k_nopad[1]-1, 0);
501 Kvec[2] =
e *
Position(0, 0, k_nopad[2]-1);
508 for (
int i0 = 0; i0 < 3; i0++) {
512 for (
int i1 = 0; i1 < 3; i1++) {
513 if (
cross(Avec[i0].unit(), Kvec[i1].unit()).length() < 1
e-4) {
518 gap[i1] = (
inv * (Avec[i0] - Kvec[i1])).length();
522 NAMD_die(
"Gridforce Grid overlap!");
525 DebugM(4,
"cont[" << i1 <<
"] = " <<
cont[i1] <<
"\n");
526 DebugM(4,
"gap[" << i1 <<
"] = " <<
gap[i1] <<
"\n");
532 NAMD_die(
"No Gridforce unit vector found parallel to requested continuous grid direction!");
542 for (
int i = 0; i < 3; i++) {
550 DebugM(4,
"delta = " <<
e * delta <<
" (" << delta <<
")\n" <<
endi);
557 sprintf(errmsg,
"Warning: Periodic cell basis too small for Gridforce grid %d. Set gridforcechecksize off in configuration file to ignore.\n",
mygridnum);
567 DebugM(3,
"size = " <<
size <<
", size_nopad = " << size_nopad <<
"\n" <<
endi);
574 for (
int i0 = 0; i0 < k_nopad[0]; i0++) {
575 for (
int i1 = 0; i1 < k_nopad[1]; i1++) {
576 for (
int i2 = 0; i2 < k_nopad[2]; i2++) {
585 long int ind = j0*
dk[0] + j1*
dk[1] + j2*
dk[2];
587 if (i0 == 0)
n_sum[0] += grid_nopad[ind_nopad];
588 else if (i0 == k_nopad[0]-1)
p_sum[0] += grid_nopad[ind_nopad];
589 if (i1 == 0)
n_sum[1] += grid_nopad[ind_nopad];
590 else if (i1 == k_nopad[1]-1)
p_sum[1] += grid_nopad[ind_nopad];
591 if (i2 == 0)
n_sum[2] += grid_nopad[ind_nopad];
592 else if (i2 == k_nopad[2]-1)
p_sum[2] += grid_nopad[ind_nopad];
595 set_grid(j0, j1, j2, grid_nopad[ind_nopad]);
604 for (
int i0 = 0; i0 < 3; i0++) {
605 int i1 = (i0 + 1) % 3;
606 int i2 = (i0 + 2) % 3;
607 n_avg[i0] =
n_sum[i0] / (k_nopad[i1] * k_nopad[i2]);
608 p_avg[i0] =
p_sum[i0] / (k_nopad[i1] * k_nopad[i2]);
610 if (
cont[i0] && fabs(
offset[i0] - (p_avg[i0]-n_avg[i0])) > modThresh)
612 iout <<
iWARN <<
"GRID FORCE POTENTIAL DIFFERENCE IN K" << i0
614 <<
offset[i0] - (p_avg[i0]-n_avg[i0])
615 <<
" KCAL/MOL*E\n" <<
endi;
626 weight += 2 * k_nopad[1] * k_nopad[2];
630 weight += 2 * k_nopad[0] * k_nopad[2];
634 weight += 2 * k_nopad[0] * k_nopad[1];
639 for (
int i = 0; i < 3; i++) {
640 pad_n[i] = (cont[i]) ? 0.0 : (twoPadVals) ? n_avg[i] : padVal;
641 pad_p[i] = (cont[i]) ? 0.0 : (twoPadVals) ? p_avg[i] : padVal;
642 DebugM(4,
"pad_n[" << i <<
"] = " <<
pad_n[i] <<
"\n");
646 if (cont[0] && cont[1] && cont[2]) {
652 for (
int i0 = 0; i0 < k[0]; i0++) {
653 for (
int i1 = 0; i1 < k[1]; i1++) {
654 for (
int i2 = 0; i2 < k[2]; i2++) {
657 && (cont[2] || i2 ==
border) )
663 long int ind = i0*
dk[0] + i1*
dk[1] + i2*
dk[2];
666 int var[3] = {i0, i1, i2};
668 for (
int dir = 0; dir < 3; dir++) {
675 }
else if (var[dir] >= k[dir]-
border) {
688 for (
int i0 = 0; i0 < k[0]; i0++) {
689 for (
int i1 = 0; i1 < k[1]; i1++) {
690 for (
int i2 = 0; i2 < k[2]; i2++) {
691 DebugM(1,
"grid[" << i0 <<
", " << i1 <<
", " << i2 <<
"] = " <<
get_grid(i0,i1,i2) <<
"\n" <<
endi);
725 DebugM(4,
"get_all_gridvals called\n" <<
endi);
734 float *grid_vals =
new float[sz];
736 for (
long int i = 0; i <
size; i++) {
737 grid_vals[idx++] =
grid[i];
739 for (
int j = 0; j < totalGrids-1; j++) {
744 CmiAssert(idx == sz);
746 *all_gridvals = grid_vals;
748 DebugM(4,
"get_all_gridvals finished\n" <<
endi);
756 DebugM(4,
"set_all_gridvals called\n" <<
endi);
758 long int sz_calc = 0;
763 CmiAssert(sz == sz_calc);
766 for (
long int i = 0; i <
size; i++) {
767 DebugM(1,
"all_gridvals[" << idx <<
"] = " << all_gridvals[idx] <<
"\n" <<
endi);
768 grid[i] = all_gridvals[idx++];
770 for (
int j = 0; j < totalGrids-1; j++) {
772 DebugM(1,
"all_gridvals[" << idx <<
"] = " << all_gridvals[idx] <<
"\n" <<
endi);
776 CmiAssert(idx == sz);
778 DebugM(4,
"set_all_gridvals finished\n" <<
endi);
784 for (
int i0 = 0; i0 < 8; i0++) {
786 int zero_derivs =
FALSE;
790 for (
int i1 = 0; i1 < 3; i1++) {
791 inds2[i1] = (inds[i1] + ((i0 & bit) ? 1 : 0)) %
k[i1];
794 if (
cont[i1] && inds[i1] == (
k[i1]-1) && inds2[i1] == 0) {
802 DebugM(1,
"inds2 = " << inds2[0] <<
" " << inds2[1] <<
" " << inds2[2] <<
"\n" <<
endi);
816 int d_hi[3] = {1, 1, 1};
817 int d_lo[3] = {1, 1, 1};
819 float dscales[3] = {0.5, 0.5, 0.5};
820 for (
int i1 = 0; i1 < 3; i1++) {
821 if (inds2[i1] == 0) {
823 d_lo[i1] = -(
k[i1]-1);
825 dscales[i1] = 1.0/(1.0 +
gap[i1]) * 1.0/gapscale[i1];
827 else zero_derivs =
TRUE;
829 else if (inds2[i1] ==
k[i1]-1) {
831 d_hi[i1] = -(
k[i1]-1);
833 dscales[i1] = 1.0/(1.0 +
gap[i1]) * 1.0/gapscale[i1];
835 else zero_derivs =
TRUE;
846 DebugM(1,
"dscales = " << dscales[0] <<
" " << dscales[1] <<
" " << dscales[2] <<
"\n" <<
endi);
847 DebugM(1,
"voffs = " << voffs[0] <<
" " << voffs[1] <<
" " << voffs[2] <<
"\n" <<
endi);
850 b[i0] =
get_grid(inds2[0],inds2[1],inds2[2]) + voff;
862 b[8+i0] = dscales[0] * (
get_grid_d(inds2[0]+d_hi[0],inds2[1],inds2[2]) -
get_grid_d(inds2[0]-d_lo[0],inds2[1],inds2[2]) + voffs[0]);
863 b[16+i0] = dscales[1] * (
get_grid_d(inds2[0],inds2[1]+d_hi[1],inds2[2]) -
get_grid_d(inds2[0],inds2[1]-d_lo[1],inds2[2]) + voffs[1]);
864 b[24+i0] = dscales[2] * (
get_grid_d(inds2[0],inds2[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0],inds2[1],inds2[2]-d_lo[2]) + voffs[2]);
865 b[32+i0] = dscales[0] * dscales[1]
866 * (
get_grid_d(inds2[0]+d_hi[0],inds2[1]+d_hi[1],inds2[2]) -
get_grid_d(inds2[0]-d_lo[0],inds2[1]+d_hi[1],inds2[2]) -
867 get_grid_d(inds2[0]+d_hi[0],inds2[1]-d_lo[1],inds2[2]) +
get_grid_d(inds2[0]-d_lo[0],inds2[1]-d_lo[1],inds2[2]));
868 b[40+i0] = dscales[0] * dscales[2]
869 * (
get_grid_d(inds2[0]+d_hi[0],inds2[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0]-d_lo[0],inds2[1],inds2[2]+d_hi[2]) -
870 get_grid_d(inds2[0]+d_hi[0],inds2[1],inds2[2]-d_lo[2]) +
get_grid_d(inds2[0]-d_lo[0],inds2[1],inds2[2]-d_lo[2]));
871 b[48+i0] = dscales[1] * dscales[2]
872 * (
get_grid_d(inds2[0],inds2[1]+d_hi[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0],inds2[1]-d_lo[1],inds2[2]+d_hi[2]) -
873 get_grid_d(inds2[0],inds2[1]+d_hi[1],inds2[2]-d_lo[2]) +
get_grid_d(inds2[0],inds2[1]-d_lo[1],inds2[2]-d_lo[2]));
875 b[56+i0] = dscales[0] * dscales[1] * dscales[2]
876 * (
get_grid_d(inds2[0]+d_hi[0],inds2[1]+d_hi[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0]+d_hi[0],inds2[1]+d_hi[1],inds2[2]-d_lo[2]) -
877 get_grid_d(inds2[0]+d_hi[0],inds2[1]-d_lo[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0]-d_lo[0],inds2[1]+d_hi[1],inds2[2]+d_hi[2]) +
878 get_grid_d(inds2[0]+d_hi[0],inds2[1]-d_lo[1],inds2[2]-d_lo[2]) +
get_grid_d(inds2[0]-d_lo[0],inds2[1]+d_hi[1],inds2[2]-d_lo[2]) +
879 get_grid_d(inds2[0]-d_lo[0],inds2[1]-d_lo[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0]-d_lo[0],inds2[1]-d_lo[1],inds2[2]-d_lo[2]));
882 DebugM(1,
"V = " << b[i0] <<
"\n");
884 DebugM(1,
"dV/dx = " << b[8+i0] <<
"\n");
885 DebugM(1,
"dV/dy = " << b[16+i0] <<
"\n");
886 DebugM(1,
"dV/dz = " << b[24+i0] <<
"\n");
888 DebugM(1,
"d2V/dxdy = " << b[32+i0] <<
"\n");
889 DebugM(1,
"d2V/dxdz = " << b[40+i0] <<
"\n");
890 DebugM(1,
"d2V/dydz = " << b[48+i0] <<
"\n");
892 DebugM(1,
"d3V/dxdydz = " << b[56+i0] <<
"\n" <<
endi);
918 long int poten_offset;
921 DebugM(3,
"Skipping 'attribute' keywords...\n" <<
endi);
927 DebugM(4,
"Read line " << str <<
" " << line <<
endi);
928 }
while (strcmp(str,
"attribute") == 0);
929 fseek(
poten_fp, poten_offset, SEEK_SET);
932 DebugM(3,
"Skipping 'field' object\n" <<
endi);
935 n = fscanf(
poten_fp,
"\"%[^\"]\" class field\n", str);
937 n = fscanf(
poten_fp,
"%d class field\n", &tmp);
941 NAMD_die(
"Error reading gridforce grid! Could not find field object!\n");
945 DebugM(3,
"Skipping 'component' keywords\n" <<
endi);
950 }
while (strcmp(str,
"component") == 0);
951 fseek(
poten_fp, poten_offset, SEEK_SET);
964 for (
int i = 0; i < 3; i++) {
972 for (
int i = 0; i < 3; i++) {
973 if ((
k[i] - 1) % (
pmax[i] -
pmin[i] + 1) != 0) {
975 NAMD_die(
"Error reading gridforce grid! Subgrid dimensions must be an integral number spanned parent cells!");
979 for (
int i = 0; i < 3; i++) {
982 DebugM(3,
"pmin[" << i <<
"] = " <<
pmin[i] <<
" pmax[" << i <<
"] = " <<
pmax[i] <<
" parent->k[" << i <<
"] = " <<
parent->
k[i] <<
" cont[" << i <<
"] = " <<
cont[i] <<
"\n" <<
endi);
999 for (
int i = 0; i < 3; i++) {
1000 escale[i] = double(
pmax[i] -
pmin[i] + 1)/(
k[i]-1);
1001 invscale[i] = 1.0/escale[i];
1009 if (pow(origin2.
x-
origin.
x, 2) > TOL2 ||
1010 pow(origin2.
y-
origin.
y, 2) > TOL2 ||
1011 pow(origin2.
z-
origin.
z, 2) > TOL2 ||
1012 pow(e2.
xx-
e.
xx, 2) > TOL2 ||
1013 pow(e2.
xy-
e.
xy, 2) > TOL2 ||
1014 pow(e2.
xz-
e.
xz, 2) > TOL2 ||
1015 pow(e2.
yx-
e.
yx, 2) > TOL2 ||
1016 pow(e2.
yy-
e.
yy, 2) > TOL2 ||
1017 pow(e2.
yz-
e.
yz, 2) > TOL2 ||
1018 pow(e2.
zx-
e.
zx, 2) > TOL2 ||
1019 pow(e2.
zy-
e.
zy, 2) > TOL2 ||
1020 pow(e2.
zz-
e.
zz, 2) > TOL2)
1022 NAMD_die(
"Error reading gridforce grid! Subgrid lattice does not match!");
1030 for (
int i = 0; i < 3; i++) {
1038 DebugM(4,
"e = " <<
e <<
"\n");
1040 DebugM(4,
"gap = " <<
gap[0] <<
" " <<
gap[2] <<
" " <<
gap[2] <<
" " <<
"\n");
1043 DebugM(4,
"k = " <<
k[0] <<
" " <<
k[1] <<
" " <<
k[2] <<
"\n");
1044 DebugM(4,
"escale = " << escale <<
"\n");
1045 DebugM(4,
"invscale = " << invscale <<
"\n" <<
endi);
1049 dk[0] = k[1] * k[2];
1062 float *grid_tmp =
new float[
size];
1066 for (
long int count = 0; count <
size_nopad; count++) {
1073 int err = fscanf(
poten_fp,
"%f", &tmp2);
1074 if (err == EOF || err == 0) {
1075 NAMD_die(
"Grid force potential file incorrectly formatted");
1077 grid_tmp[count] = tmp2 *
factor;
1085 for (
int i0 = 0; i0 <
k_nopad[0]; i0++) {
1086 for (
int i1 = 0; i1 < k_nopad[1]; i1++) {
1087 for (
int i2 = 0; i2 < k_nopad[2]; i2++) {
1088 long int ind = i0*
dk[0] + i1*
dk[1] + i2*
dk[2];
1089 set_grid(i0, i1, i2, grid_tmp[ind]);
1094 for (
int i0 = 0; i0 < k[0]; i0++) {
1095 for (
int i1 = 0; i1 < k[1]; i1++) {
1096 for (
int i2 = 0; i2 < k[2]; i2++) {
1097 DebugM(1,
"grid[" << i0 <<
", " << i1 <<
", " << i2 <<
"] = " <<
get_grid(i0,i1,i2) <<
"\n" <<
endi);
1120 msg->
put(3*
sizeof(
int), (
char*)
pmin);
1121 msg->
put(3*
sizeof(
int), (
char*)
pmax);
1124 DebugM(3,
"calling GridforceFullBaseGrid::pack\n" <<
endi);
1138 msg->
get(3*
sizeof(
int), (
char*)
pmin);
1139 msg->
get(3*
sizeof(
int), (
char*)
pmax);
1163 for (
int i0 = 0; i0 < 8; i0++) {
1168 for (
int i1 = 0; i1 < 3; i1++) {
1169 inds2[i1] = (inds[i1] + ((i0 & bit) ? 1 : 0)) %
k[i1];
1172 if (
cont[i1] && inds[i1] == (
k[i1]-1) && inds2[i1] == 0) {
1180 DebugM(3,
"inds2 = " << inds2[0] <<
" " << inds2[1] <<
" " << inds2[2] <<
"\n" <<
endi);
1182 int d_hi[3] = {1, 1, 1};
1183 int d_lo[3] = {1, 1, 1};
1185 float dscales[3] = {0.5, 0.5, 0.5};
1186 for (
int i1 = 0; i1 < 3; i1++) {
1187 if (inds2[i1] == 0 &&
cont[i1]) {
1188 d_lo[i1] = -(
k[i1]-1);
1190 dscales[i1] = 1.0/(1.0 +
gap[i1]) * 1.0/gapscale[i1];
1192 else if (inds2[i1] ==
k[i1]-1 &&
cont[i1]) {
1193 d_hi[i1] = -(
k[i1]-1);
1195 dscales[i1] = 1.0/(1.0 +
gap[i1]) * 1.0/gapscale[i1];
1203 for (
int i1 = 0; i1 < 3; i1++) {
1204 if (!
cont[i1] && (inds2[i1] == 0 || inds2[i1] ==
k[i1]-1)) {
1209 if (inds2[2] == 0) {
1225 for (
int i = 0; i < 3; i++) {
1226 inds3[i] = (int)floor(g[i]);
1227 dg[i] = g[i] - inds3[i];
1230 float x[4],
y[4],
z[4];
1231 x[0] = 1; y[0] = 1; z[0] = 1;
1232 for (
int j = 1; j < 4; j++) {
1233 x[j] = x[j-1] * dg.
x;
1234 y[j] = y[j-1] * dg.
y;
1235 z[j] = z[j-1] * dg.
z;
1236 DebugM(1,
"x[" << j <<
"] = " << x[j] <<
"\n");
1237 DebugM(1,
"y[" << j <<
"] = " << y[j] <<
"\n");
1238 DebugM(1,
"z[" << j <<
"] = " << z[j] <<
"\n" <<
endi);
1263 b[i0] =
get_grid(inds2[0],inds2[1],inds2[2]) + voff;
1265 b[8+i0] = dscales[0] * (
get_grid_d(inds2[0]+d_hi[0],inds2[1],inds2[2]) -
get_grid_d(inds2[0]-d_lo[0],inds2[1],inds2[2]) + voffs[0]);
1266 b[16+i0] = dscales[1] * (
get_grid_d(inds2[0],inds2[1]+d_hi[1],inds2[2]) -
get_grid_d(inds2[0],inds2[1]-d_lo[1],inds2[2]) + voffs[1]);
1267 b[24+i0] = dscales[2] * (
get_grid_d(inds2[0],inds2[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0],inds2[1],inds2[2]-d_lo[2]) + voffs[2]);
1268 b[32+i0] = dscales[0] * dscales[1]
1269 * (
get_grid_d(inds2[0]+d_hi[0],inds2[1]+d_hi[1],inds2[2]) -
get_grid_d(inds2[0]-d_lo[0],inds2[1]+d_hi[1],inds2[2]) -
1270 get_grid_d(inds2[0]+d_hi[0],inds2[1]-d_lo[1],inds2[2]) +
get_grid_d(inds2[0]-d_lo[0],inds2[1]-d_lo[1],inds2[2]));
1271 b[40+i0] = dscales[0] * dscales[2]
1272 * (
get_grid_d(inds2[0]+d_hi[0],inds2[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0]-d_lo[0],inds2[1],inds2[2]+d_hi[2]) -
1273 get_grid_d(inds2[0]+d_hi[0],inds2[1],inds2[2]-d_lo[2]) +
get_grid_d(inds2[0]-d_lo[0],inds2[1],inds2[2]-d_lo[2]));
1274 b[48+i0] = dscales[1] * dscales[2]
1275 * (
get_grid_d(inds2[0],inds2[1]+d_hi[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0],inds2[1]-d_lo[1],inds2[2]+d_hi[2]) -
1276 get_grid_d(inds2[0],inds2[1]+d_hi[1],inds2[2]-d_lo[2]) +
get_grid_d(inds2[0],inds2[1]-d_lo[1],inds2[2]-d_lo[2]));
1278 b[56+i0] = dscales[0] * dscales[1] * dscales[2]
1279 * (
get_grid_d(inds2[0]+d_hi[0],inds2[1]+d_hi[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0]+d_hi[0],inds2[1]+d_hi[1],inds2[2]-d_lo[2]) -
1280 get_grid_d(inds2[0]+d_hi[0],inds2[1]-d_lo[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0]-d_lo[0],inds2[1]+d_hi[1],inds2[2]+d_hi[2]) +
1281 get_grid_d(inds2[0]+d_hi[0],inds2[1]-d_lo[1],inds2[2]-d_lo[2]) +
get_grid_d(inds2[0]-d_lo[0],inds2[1]+d_hi[1],inds2[2]-d_lo[2]) +
1282 get_grid_d(inds2[0]-d_lo[0],inds2[1]-d_lo[1],inds2[2]+d_hi[2]) -
get_grid_d(inds2[0]-d_lo[0],inds2[1]-d_lo[1],inds2[2]-d_lo[2]));
1285 if (inds2[0] == 1 && inds2[1] == 1 && inds2[2] == 0) {
1286 DebugM(1,
"Sub V = " << b[i0] <<
"\n");
1288 DebugM(1,
"Sub dV/dx = " << b[8+i0] <<
"\n");
1289 DebugM(1,
"Sub dV/dy = " << b[16+i0] <<
"\n");
1290 DebugM(1,
"Sub dV/dz = " << b[24+i0] <<
"\n");
1292 DebugM(1,
"Sub d2V/dxdy = " << b[32+i0] <<
"\n");
1293 DebugM(1,
"Sub d2V/dxdz = " << b[40+i0] <<
"\n");
1294 DebugM(1,
"Sub d2V/dydz = " << b[48+i0] <<
"\n");
1296 DebugM(1,
"Sub d3V/dxdydz = " << b[56+i0] <<
"\n" <<
endi);
1324 tmp_grid->
initialize(potfilename, simParams, mgridParams, 1);
1327 NAMD_die(
"Cannot use gridforcelite option with multi-resolution grid!");
1346 dk[0] = k[1] * k[2] * k[3];
1347 dk[1] = k[2] * k[3];
1354 for (
int i0 = 0; i0 < k[0]; i0++) {
1355 for (
int i1 = 0; i1 < k[1]; i1++) {
1356 for (
int i2 = 0; i2 < k[2]; i2++) {
1357 float V = tmp_grid->
get_grid(i0, i1, i2);
1359 DebugM(1,
"V[" << i0 <<
"," << i1 <<
"," << i2 <<
"] = " <<
get_grid(i0, i1, i2, 0) <<
"(" << V <<
")\n" <<
endi);
1374 for (
int i0 = 0; i0 <
k[0]; i0++) {
1375 for (
int i1 = 0; i1 < k[1]; i1++) {
1376 for (
int i2 = 0; i2 < k[2]; i2++) {
1378 if (i0 == 0 || i0 == k[0]-1 || i1 == 0 || i1 == k[1]-1 || i2 == 0 || i2 == k[2]-1) {
1391 DebugM(1,
"dx[" << i0 <<
"," << i1 <<
"," << i2 <<
"] = " <<
get_grid(i0, i1, i2, 1) <<
"(" << dx <<
")\n" <<
endi);
1392 DebugM(1,
"dy[" << i0 <<
"," << i1 <<
"," << i2 <<
"] = " <<
get_grid(i0, i1, i2, 2) <<
"(" << dy <<
")\n" <<
endi);
1393 DebugM(1,
"dz[" << i0 <<
"," << i1 <<
"," << i2 <<
"] = " <<
get_grid(i0, i1, i2, 3) <<
"(" << dz <<
")\n" <<
endi);
1408 msg->
put(4*
sizeof(
int), (
char*)
k);
1410 msg->
put(4*
sizeof(
long int), (
char*)
dk);
1430 msg->
get(4*
sizeof(
int), (
char*)
k);
1432 msg->
get(4*
sizeof(
long int), (
char*)
dk);
1457 DebugM(4,
"GridforceLiteGrid::get_all_gridvals called\n" <<
endi);
1462 float *grid_vals =
new float[sz];
1464 for (
long int i = 0; i <
size; i++) {
1465 grid_vals[idx++] =
grid[i];
1467 CmiAssert(idx == sz);
1469 *all_gridvals = grid_vals;
1471 DebugM(4,
"GridforceLiteGrid::get_all_gridvals finished\n" <<
endi);
1479 DebugM(4,
"GridforceLiteGrid::set_all_gridvals called\n" <<
endi);
1481 long int sz_calc =
size;
1482 CmiAssert(sz == sz_calc);
1485 for (
long int i = 0; i <
size; i++) {
1486 grid[i] = all_gridvals[idx++];
1488 CmiAssert(idx == sz);
1492 DebugM(4,
"GridforceLiteGrid::set_all_gridvals finished\n" <<
endi);
void reinitialize(SimParameters *simParams, MGridforceParams *mgridParams)
void compute_b(float *b, int *inds, Vector gapscale) const
void pack(MOStream *msg) const
float compute_V(float *a, float *x, float *y, float *z) const
double get_grid_d(int i0, int i1, int i2, int i3) const
GridforceFullBaseGrid(void)
friend class GridforceFullSubGrid
static Tensor diagonal(const Vector &v1)
float get_grid(int i0, int i1, int i2) const
static GridforceGrid * new_grid(int gridnum, char *potfilename, SimParameters *simParams, MGridforceParams *mgridParams)
virtual void compute_b(float *b, int *inds, Vector gapscale) const =0
void initialize(char *potfilename, SimParameters *simParams, MGridforceParams *mgridParams, int border)
Vector compute_dV(float *a, float *x, float *y, float *z) const
static void pack_grid(GridforceGrid *grid, MOStream *msg)
virtual Position get_origin(void) const =0
__device__ __forceinline__ float3 cross(const float3 v1, const float3 v2)
std::ostream & endi(std::ostream &s)
std::ostream & iWARN(std::ostream &s)
MIStream * get(char &data)
virtual ~GridforceLiteGrid()
void pack(MOStream *msg) const
virtual int get_k2(void) const =0
void compute_a(float *a, float *b) const
char filename[NAMD_FILENAME_BUFFER_SIZE]
float get_grid(int i0, int i1, int i2, int i3) const
void compute_b(float *b, int *inds, Vector gapscale) const
float compute_d3V(float *a, float *x, float *y, float *z) const
virtual void pack(MOStream *msg) const
GridforceFullMainGrid * maingrid
void readHeader(SimParameters *simParams, MGridforceParams *mgridParams)
void unpack(MIStream *msg)
void compute_derivative_grids(void)
void set_grid(int i0, int i1, int i2, int i3, float V)
GridforceFullSubGrid ** subgrids
GridforceFullBaseGrid * parent
bool fits_lattice(const Lattice &lattice)
void set_grid(int i0, int i1, int i2, float V)
virtual void pack(MOStream *msg) const =0
void NAMD_bug(const char *err_msg)
GridforceFullSubGrid ** subgrids_flat
GridforceFullMainGrid(int gridnum)
virtual Position get_center(void) const =0
void reinitialize(SimParameters *simParams, MGridforceParams *mgridParams)
virtual ~GridforceFullBaseGrid()
void set_all_gridvals(float *all_gridvals, long int sz)
FILE * Fopen(const char *filename, const char *mode)
GridforceFullSubGrid(GridforceFullBaseGrid *parent_in)
virtual void initialize(char *potfilename, SimParameters *simParams, MGridforceParams *mgridParams)=0
void readSubgridHierarchy(FILE *poten, int &totalGrids)
GridforceLiteGrid(int gridnum)
void addToSubgridsFlat(void)
void NAMD_die(const char *err_msg)
virtual int get_border(void) const =0
virtual void unpack(MIStream *msg)
long int get_all_gridvals(float **all_gridvals) const
void set_all_gridvals(float *all_gridvals, long int sz)
Position get_origin(void) const
char filename[NAMD_FILENAME_BUFFER_SIZE]
void initialize(char *potfilename, SimParameters *simParams, MGridforceParams *mgridParams)
int get_total_grids(void) const
long int get_all_gridvals(float **all_gridvals) const
static GridforceGrid * unpack_grid(int gridnum, MIStream *msg)
void buildSubgridsFlat(void)
Tensor get_inv(void) const
Tensor tensorMult(const Tensor &t1, const Tensor &t2)
virtual int get_k0(void) const =0
Position get_corner(int idx)
virtual int get_k1(void) const =0
Position wrap_position(const Position &pos, const Lattice &lattice)
virtual void unpack(MIStream *msg)=0
virtual Tensor get_e(void) const =0
Vector get_scale(void) const
virtual ~GridforceFullMainGrid()
MOStream * put(char data)
GridforceGridType get_grid_type(void)
double get_grid_d(int i0, int i1, int i2) const
static const int default_border
void initialize(SimParameters *simParams, MGridforceParams *mgridParams)
void pack(MOStream *msg) const
Vector compute_d2V(float *a, float *x, float *y, float *z) const
Position get_center(void) const
void unpack(MIStream *msg)
void unpack(MIStream *msg)