21 #define MIN_DEBUG_LEVEL 4 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);
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);
258 long int poten_offset;
263 }
while (line[0] ==
'#');
264 fseek(
poten_fp, poten_offset, SEEK_SET);
267 fscanf(
poten_fp,
"object %*d class gridpositions counts %d %d %d\n",
272 fscanf(
poten_fp,
"origin %lf %lf %lf\n",
284 fscanf(
poten_fp,
"object %*d class gridconnections counts %*lf %*lf %*lf\n");
285 fscanf(
poten_fp,
"object %*d class array type double rank 0 items %*d data follows\n");
302 DebugM(4,
"e = " <<
e <<
"\n");
308 DebugM(4,
"Beginning of readSubgridHierarchy, generation = " <<
generation <<
", totalGrids = " << totalGrids <<
"\n" <<
endi);
310 int elems, generation_in;
316 elems = fscanf(
poten_fp,
"# namdnugrid subgrid %d generation %d min %d %d %d max %d %d %d subgrids count %d\n",
317 &
subgrids[i]->subgridIdx, &generation_in,
323 sprintf(msg,
"Problem reading Gridforce potential file! (%d < 9)", elems);
329 if (
subgrids[i]->subgridIdx != (totalGrids - 1)) {
331 sprintf(msg,
"Problem reading Gridforce potential file! (%d != %d)",
subgrids[i]->subgridIdx, totalGrids - 1);
336 sprintf(msg,
"Problem reading Gridforce potential file! (%d != %d)",
subgrids[i]->
generation, generation_in);
378 DebugM(3,
"calling GridforceFullBaseGrid::pack\n" <<
endi);
412 DebugM(3,
"adding to subgridsFlat\n" <<
endi);
437 NAMD_die(
"Problem reading grid force potential file");
449 long int poten_offset;
454 flag = sscanf(line,
"# namdnugrid version %f\n", &version);
455 }
while (line[0] ==
'#' && !flag);
458 if (version != 1.0) {
459 NAMD_die(
"Unsupported version of non-uniform grid file format!");
465 fseek(
poten_fp, poten_offset, SEEK_SET);
483 for (
long int count = 0; count <
size_nopad; count++) {
484 int err = fscanf(
poten_fp,
"%f", &tmp2);
485 if (err == EOF || err == 0) {
486 NAMD_die(
"Grid force potential file incorrectly formatted");
488 grid_nopad[count] = tmp2 *
factor;
507 for (
int i0 = 0; i0 < 3; i0++) {
511 for (
int i1 = 0; i1 < 3; i1++) {
512 if (cross(Avec[i0].unit(), Kvec[i1].unit()).length() < 1
e-4) {
517 gap[i1] = (
inv * (Avec[i0] - Kvec[i1])).length();
521 NAMD_die(
"Gridforce Grid overlap!");
524 DebugM(4,
"cont[" << i1 <<
"] = " <<
cont[i1] <<
"\n");
525 DebugM(4,
"gap[" << i1 <<
"] = " <<
gap[i1] <<
"\n");
531 NAMD_die(
"No Gridforce unit vector found parallel to requested continuous grid direction!");
541 for (
int i = 0; i < 3; i++) {
549 DebugM(4,
"delta = " <<
e * delta <<
" (" << delta <<
")\n" <<
endi);
556 sprintf(errmsg,
"Warning: Periodic cell basis too small for Gridforce grid %d. Set gridforcechecksize off in configuration file to ignore.\n",
mygridnum);
573 for (
int i0 = 0; i0 <
k_nopad[0]; i0++) {
574 for (
int i1 = 0; i1 <
k_nopad[1]; i1++) {
575 for (
int i2 = 0; i2 <
k_nopad[2]; i2++) {
584 long int ind = j0*
dk[0] + j1*
dk[1] + j2*
dk[2];
586 if (i0 == 0)
n_sum[0] += grid_nopad[ind_nopad];
587 else if (i0 ==
k_nopad[0]-1)
p_sum[0] += grid_nopad[ind_nopad];
588 if (i1 == 0)
n_sum[1] += grid_nopad[ind_nopad];
589 else if (i1 ==
k_nopad[1]-1)
p_sum[1] += grid_nopad[ind_nopad];
590 if (i2 == 0)
n_sum[2] += grid_nopad[ind_nopad];
591 else if (i2 ==
k_nopad[2]-1)
p_sum[2] += grid_nopad[ind_nopad];
594 set_grid(j0, j1, j2, grid_nopad[ind_nopad]);
603 for (
int i0 = 0; i0 < 3; i0++) {
604 int i1 = (i0 + 1) % 3;
605 int i2 = (i0 + 2) % 3;
609 if (
cont[i0] && fabs(
offset[i0] - (p_avg[i0]-n_avg[i0])) > modThresh)
611 iout <<
iWARN <<
"GRID FORCE POTENTIAL DIFFERENCE IN K" << i0
613 <<
offset[i0] - (p_avg[i0]-n_avg[i0])
614 <<
" KCAL/MOL*E\n" <<
endi;
638 for (
int i = 0; i < 3; i++) {
639 pad_n[i] = (
cont[i]) ? 0.0 : (twoPadVals) ? n_avg[i] : padVal;
640 pad_p[i] = (
cont[i]) ? 0.0 : (twoPadVals) ? p_avg[i] : padVal;
641 DebugM(4,
"pad_n[" << i <<
"] = " <<
pad_n[i] <<
"\n");
651 for (
int i0 = 0; i0 <
k[0]; i0++) {
652 for (
int i1 = 0; i1 <
k[1]; i1++) {
653 for (
int i2 = 0; i2 <
k[2]; i2++) {
662 long int ind = i0*
dk[0] + i1*
dk[1] + i2*
dk[2];
665 int var[3] = {i0, i1, i2};
667 for (
int dir = 0; dir < 3; dir++) {
674 }
else if (var[dir] >=
k[dir]-
border) {
687 for (
int i0 = 0; i0 <
k[0]; i0++) {
688 for (
int i1 = 0; i1 <
k[1]; i1++) {
689 for (
int i2 = 0; i2 <
k[2]; i2++) {
690 DebugM(1,
"grid[" << i0 <<
", " << i1 <<
", " << i2 <<
"] = " <<
get_grid(i0,i1,i2) <<
"\n" <<
endi);
724 DebugM(4,
"get_all_gridvals called\n" <<
endi);
733 float *grid_vals =
new float[sz];
735 for (
long int i = 0; i <
size; i++) {
736 grid_vals[idx++] =
grid[i];
743 CmiAssert(idx == sz);
745 *all_gridvals = grid_vals;
747 DebugM(4,
"get_all_gridvals finished\n" <<
endi);
755 DebugM(4,
"set_all_gridvals called\n" <<
endi);
757 long int sz_calc = 0;
762 CmiAssert(sz == sz_calc);
765 for (
long int i = 0; i <
size; i++) {
766 DebugM(1,
"all_gridvals[" << idx <<
"] = " << all_gridvals[idx] <<
"\n" <<
endi);
767 grid[i] = all_gridvals[idx++];
771 DebugM(1,
"all_gridvals[" << idx <<
"] = " << all_gridvals[idx] <<
"\n" <<
endi);
775 CmiAssert(idx == sz);
777 DebugM(4,
"set_all_gridvals finished\n" <<
endi);
783 for (
int i0 = 0; i0 < 8; i0++) {
785 int zero_derivs =
FALSE;
789 for (
int i1 = 0; i1 < 3; i1++) {
790 inds2[i1] = (inds[i1] + ((i0 & bit) ? 1 : 0)) %
k[i1];
793 if (
cont[i1] && inds[i1] == (
k[i1]-1) && inds2[i1] == 0) {
801 DebugM(1,
"inds2 = " << inds2[0] <<
" " << inds2[1] <<
" " << inds2[2] <<
"\n" <<
endi);
815 int d_hi[3] = {1, 1, 1};
816 int d_lo[3] = {1, 1, 1};
818 float dscales[3] = {0.5, 0.5, 0.5};
819 for (
int i1 = 0; i1 < 3; i1++) {
820 if (inds2[i1] == 0) {
822 d_lo[i1] = -(
k[i1]-1);
824 dscales[i1] = 1.0/(1.0 +
gap[i1]) * 1.0/gapscale[i1];
826 else zero_derivs =
TRUE;
828 else if (inds2[i1] ==
k[i1]-1) {
830 d_hi[i1] = -(
k[i1]-1);
832 dscales[i1] = 1.0/(1.0 +
gap[i1]) * 1.0/gapscale[i1];
834 else zero_derivs =
TRUE;
845 DebugM(1,
"dscales = " << dscales[0] <<
" " << dscales[1] <<
" " << dscales[2] <<
"\n" <<
endi);
846 DebugM(1,
"voffs = " << voffs[0] <<
" " << voffs[1] <<
" " << voffs[2] <<
"\n" <<
endi);
849 b[i0] =
get_grid(inds2[0],inds2[1],inds2[2]) + voff;
861 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]);
862 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]);
863 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]);
864 b[32+i0] = dscales[0] * dscales[1]
865 * (
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]) -
866 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]));
867 b[40+i0] = dscales[0] * dscales[2]
868 * (
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]) -
869 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]));
870 b[48+i0] = dscales[1] * dscales[2]
871 * (
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]) -
872 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]));
874 b[56+i0] = dscales[0] * dscales[1] * dscales[2]
875 * (
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]) -
876 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]) +
877 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]) +
878 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]));
881 DebugM(1,
"V = " << b[i0] <<
"\n");
883 DebugM(1,
"dV/dx = " << b[8+i0] <<
"\n");
884 DebugM(1,
"dV/dy = " << b[16+i0] <<
"\n");
885 DebugM(1,
"dV/dz = " << b[24+i0] <<
"\n");
887 DebugM(1,
"d2V/dxdy = " << b[32+i0] <<
"\n");
888 DebugM(1,
"d2V/dxdz = " << b[40+i0] <<
"\n");
889 DebugM(1,
"d2V/dydz = " << b[48+i0] <<
"\n");
891 DebugM(1,
"d3V/dxdydz = " << b[56+i0] <<
"\n" <<
endi);
917 long int poten_offset;
920 DebugM(3,
"Skipping 'attribute' keywords...\n" <<
endi);
926 DebugM(4,
"Read line " << str <<
" " << line <<
endi);
927 }
while (strcmp(str,
"attribute") == 0);
928 fseek(
poten_fp, poten_offset, SEEK_SET);
931 DebugM(3,
"Skipping 'field' object\n" <<
endi);
934 n = fscanf(
poten_fp,
"\"%[^\"]\" class field\n", str);
936 n = fscanf(
poten_fp,
"%d class field\n", &tmp);
940 NAMD_die(
"Error reading gridforce grid! Could not find field object!\n");
944 DebugM(3,
"Skipping 'component' keywords\n" <<
endi);
949 }
while (strcmp(str,
"component") == 0);
950 fseek(
poten_fp, poten_offset, SEEK_SET);
963 for (
int i = 0; i < 3; i++) {
971 for (
int i = 0; i < 3; i++) {
972 if ((
k[i] - 1) % (
pmax[i] -
pmin[i] + 1) != 0) {
974 NAMD_die(
"Error reading gridforce grid! Subgrid dimensions must be an integral number spanned parent cells!");
978 for (
int i = 0; i < 3; i++) {
981 DebugM(3,
"pmin[" << i <<
"] = " <<
pmin[i] <<
" pmax[" << i <<
"] = " <<
pmax[i] <<
" parent->k[" << i <<
"] = " <<
parent->
k[i] <<
" cont[" << i <<
"] = " <<
cont[i] <<
"\n" <<
endi);
998 for (
int i = 0; i < 3; i++) {
999 escale[i] = double(
pmax[i] -
pmin[i] + 1)/(
k[i]-1);
1000 invscale[i] = 1.0/escale[i];
1008 if (pow(origin2.
x-
origin.
x, 2) > TOL2 ||
1009 pow(origin2.
y-
origin.
y, 2) > TOL2 ||
1010 pow(origin2.
z-
origin.
z, 2) > TOL2 ||
1011 pow(e2.
xx-
e.
xx, 2) > TOL2 ||
1012 pow(e2.
xy-
e.
xy, 2) > TOL2 ||
1013 pow(e2.
xz-
e.
xz, 2) > TOL2 ||
1014 pow(e2.
yx-
e.
yx, 2) > TOL2 ||
1015 pow(e2.
yy-
e.
yy, 2) > TOL2 ||
1016 pow(e2.
yz-
e.
yz, 2) > TOL2 ||
1017 pow(e2.
zx-
e.
zx, 2) > TOL2 ||
1018 pow(e2.
zy-
e.
zy, 2) > TOL2 ||
1019 pow(e2.
zz-
e.
zz, 2) > TOL2)
1021 NAMD_die(
"Error reading gridforce grid! Subgrid lattice does not match!");
1029 for (
int i = 0; i < 3; i++) {
1037 DebugM(4,
"e = " <<
e <<
"\n");
1039 DebugM(4,
"gap = " <<
gap[0] <<
" " <<
gap[2] <<
" " <<
gap[2] <<
" " <<
"\n");
1042 DebugM(4,
"k = " <<
k[0] <<
" " <<
k[1] <<
" " <<
k[2] <<
"\n");
1043 DebugM(4,
"escale = " << escale <<
"\n");
1044 DebugM(4,
"invscale = " << invscale <<
"\n" <<
endi);
1048 dk[0] =
k[1] *
k[2];
1061 float *grid_tmp =
new float[
size];
1065 for (
long int count = 0; count <
size_nopad; count++) {
1072 int err = fscanf(
poten_fp,
"%f", &tmp2);
1073 if (err == EOF || err == 0) {
1074 NAMD_die(
"Grid force potential file incorrectly formatted");
1076 grid_tmp[count] = tmp2 *
factor;
1084 for (
int i0 = 0; i0 <
k_nopad[0]; i0++) {
1085 for (
int i1 = 0; i1 <
k_nopad[1]; i1++) {
1086 for (
int i2 = 0; i2 <
k_nopad[2]; i2++) {
1087 long int ind = i0*
dk[0] + i1*
dk[1] + i2*
dk[2];
1088 set_grid(i0, i1, i2, grid_tmp[ind]);
1093 for (
int i0 = 0; i0 <
k[0]; i0++) {
1094 for (
int i1 = 0; i1 <
k[1]; i1++) {
1095 for (
int i2 = 0; i2 <
k[2]; i2++) {
1096 DebugM(1,
"grid[" << i0 <<
", " << i1 <<
", " << i2 <<
"] = " <<
get_grid(i0,i1,i2) <<
"\n" <<
endi);
1119 msg->
put(3*
sizeof(
int), (
char*)
pmin);
1120 msg->
put(3*
sizeof(
int), (
char*)
pmax);
1123 DebugM(3,
"calling GridforceFullBaseGrid::pack\n" <<
endi);
1137 msg->
get(3*
sizeof(
int), (
char*)
pmin);
1138 msg->
get(3*
sizeof(
int), (
char*)
pmax);
1162 for (
int i0 = 0; i0 < 8; i0++) {
1167 for (
int i1 = 0; i1 < 3; i1++) {
1168 inds2[i1] = (inds[i1] + ((i0 & bit) ? 1 : 0)) %
k[i1];
1171 if (
cont[i1] && inds[i1] == (
k[i1]-1) && inds2[i1] == 0) {
1179 DebugM(3,
"inds2 = " << inds2[0] <<
" " << inds2[1] <<
" " << inds2[2] <<
"\n" <<
endi);
1181 int d_hi[3] = {1, 1, 1};
1182 int d_lo[3] = {1, 1, 1};
1184 float dscales[3] = {0.5, 0.5, 0.5};
1185 for (
int i1 = 0; i1 < 3; i1++) {
1186 if (inds2[i1] == 0 &&
cont[i1]) {
1187 d_lo[i1] = -(
k[i1]-1);
1189 dscales[i1] = 1.0/(1.0 +
gap[i1]) * 1.0/gapscale[i1];
1191 else if (inds2[i1] ==
k[i1]-1 &&
cont[i1]) {
1192 d_hi[i1] = -(
k[i1]-1);
1194 dscales[i1] = 1.0/(1.0 +
gap[i1]) * 1.0/gapscale[i1];
1202 for (
int i1 = 0; i1 < 3; i1++) {
1203 if (!
cont[i1] && (inds2[i1] == 0 || inds2[i1] ==
k[i1]-1)) {
1208 if (inds2[2] == 0) {
1224 for (
int i = 0; i < 3; i++) {
1225 inds3[i] = (int)floor(g[i]);
1226 dg[i] = g[i] - inds3[i];
1229 float x[4], y[4], z[4];
1230 x[0] = 1; y[0] = 1; z[0] = 1;
1231 for (
int j = 1; j < 4; j++) {
1232 x[j] = x[j-1] * dg.
x;
1233 y[j] = y[j-1] * dg.
y;
1234 z[j] = z[j-1] * dg.
z;
1235 DebugM(1,
"x[" << j <<
"] = " << x[j] <<
"\n");
1236 DebugM(1,
"y[" << j <<
"] = " << y[j] <<
"\n");
1237 DebugM(1,
"z[" << j <<
"] = " << z[j] <<
"\n" <<
endi);
1262 b[i0] =
get_grid(inds2[0],inds2[1],inds2[2]) + voff;
1264 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]);
1265 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]);
1266 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]);
1267 b[32+i0] = dscales[0] * dscales[1]
1268 * (
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]) -
1269 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]));
1270 b[40+i0] = dscales[0] * dscales[2]
1271 * (
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]) -
1272 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]));
1273 b[48+i0] = dscales[1] * dscales[2]
1274 * (
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]) -
1275 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]));
1277 b[56+i0] = dscales[0] * dscales[1] * dscales[2]
1278 * (
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]) -
1279 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]) +
1280 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]) +
1281 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]));
1284 if (inds2[0] == 1 && inds2[1] == 1 && inds2[2] == 0) {
1285 DebugM(1,
"Sub V = " << b[i0] <<
"\n");
1287 DebugM(1,
"Sub dV/dx = " << b[8+i0] <<
"\n");
1288 DebugM(1,
"Sub dV/dy = " << b[16+i0] <<
"\n");
1289 DebugM(1,
"Sub dV/dz = " << b[24+i0] <<
"\n");
1291 DebugM(1,
"Sub d2V/dxdy = " << b[32+i0] <<
"\n");
1292 DebugM(1,
"Sub d2V/dxdz = " << b[40+i0] <<
"\n");
1293 DebugM(1,
"Sub d2V/dydz = " << b[48+i0] <<
"\n");
1295 DebugM(1,
"Sub d3V/dxdydz = " << b[56+i0] <<
"\n" <<
endi);
1326 NAMD_die(
"Cannot use gridforcelite option with multi-resolution grid!");
1345 dk[0] =
k[1] *
k[2] *
k[3];
1346 dk[1] =
k[2] *
k[3];
1353 for (
int i0 = 0; i0 <
k[0]; i0++) {
1354 for (
int i1 = 0; i1 <
k[1]; i1++) {
1355 for (
int i2 = 0; i2 <
k[2]; i2++) {
1356 float V = tmp_grid->
get_grid(i0, i1, i2);
1358 DebugM(1,
"V[" << i0 <<
"," << i1 <<
"," << i2 <<
"] = " <<
get_grid(i0, i1, i2, 0) <<
"(" << V <<
")\n" <<
endi);
1373 for (
int i0 = 0; i0 <
k[0]; i0++) {
1374 for (
int i1 = 0; i1 <
k[1]; i1++) {
1375 for (
int i2 = 0; i2 <
k[2]; i2++) {
1377 if (i0 == 0 || i0 ==
k[0]-1 || i1 == 0 || i1 ==
k[1]-1 || i2 == 0 || i2 ==
k[2]-1) {
1390 DebugM(1,
"dx[" << i0 <<
"," << i1 <<
"," << i2 <<
"] = " <<
get_grid(i0, i1, i2, 1) <<
"(" << dx <<
")\n" <<
endi);
1391 DebugM(1,
"dy[" << i0 <<
"," << i1 <<
"," << i2 <<
"] = " <<
get_grid(i0, i1, i2, 2) <<
"(" << dy <<
")\n" <<
endi);
1392 DebugM(1,
"dz[" << i0 <<
"," << i1 <<
"," << i2 <<
"] = " <<
get_grid(i0, i1, i2, 3) <<
"(" << dz <<
")\n" <<
endi);
1407 msg->
put(4*
sizeof(
int), (
char*)
k);
1409 msg->
put(4*
sizeof(
long int), (
char*)
dk);
1429 msg->
get(4*
sizeof(
int), (
char*)
k);
1431 msg->
get(4*
sizeof(
long int), (
char*)
dk);
1456 DebugM(4,
"GridforceLiteGrid::get_all_gridvals called\n" <<
endi);
1461 float *grid_vals =
new float[sz];
1463 for (
long int i = 0; i <
size; i++) {
1464 grid_vals[idx++] =
grid[i];
1466 CmiAssert(idx == sz);
1468 *all_gridvals = grid_vals;
1470 DebugM(4,
"GridforceLiteGrid::get_all_gridvals finished\n" <<
endi);
1478 DebugM(4,
"GridforceLiteGrid::set_all_gridvals called\n" <<
endi);
1480 long int sz_calc =
size;
1481 CmiAssert(sz == sz_calc);
1484 for (
long int i = 0; i <
size; i++) {
1485 grid[i] = all_gridvals[idx++];
1487 CmiAssert(idx == sz);
1491 DebugM(4,
"GridforceLiteGrid::set_all_gridvals finished\n" <<
endi);
void reinitialize(SimParameters *simParams, MGridforceParams *mgridParams)
void pack(MOStream *msg) const
int get_total_grids(void) const
GridforceFullBaseGrid(void)
friend class GridforceFullSubGrid
float compute_V(float *a, float *x, float *y, float *z) 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)
long int get_all_gridvals(float **all_gridvals) const
static void pack_grid(GridforceGrid *grid, MOStream *msg)
Vector compute_d2V(float *a, float *x, float *y, float *z) const
virtual Position get_origin(void) const =0
std::ostream & endi(std::ostream &s)
double get_grid_d(int i0, int i1, int i2, int i3) const
float compute_d3V(float *a, float *x, float *y, float *z) const
std::ostream & iWARN(std::ostream &s)
MIStream * get(char &data)
virtual ~GridforceLiteGrid()
virtual int get_k2(void) const =0
char filename[NAMD_FILENAME_BUFFER_SIZE]
GridforceFullMainGrid * maingrid
void readHeader(SimParameters *simParams, MGridforceParams *mgridParams)
void unpack(MIStream *msg)
void compute_b(float *b, int *inds, Vector gapscale) const
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)
virtual void pack(MOStream *msg) const
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)
void compute_b(float *b, int *inds, Vector gapscale) const
Position get_center(void) const
GridforceFullSubGrid ** subgrids_flat
GridforceFullMainGrid(int gridnum)
virtual Position get_center(void) const =0
void reinitialize(SimParameters *simParams, MGridforceParams *mgridParams)
static NAMD_HOST_DEVICE Tensor diagonal(const Vector &v1)
virtual ~GridforceFullBaseGrid()
void set_all_gridvals(float *all_gridvals, long int sz)
FILE * Fopen(const char *filename, const char *mode)
long int get_all_gridvals(float **all_gridvals) const
float get_grid(int i0, int i1, int i2) const
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)
void set_all_gridvals(float *all_gridvals, long int sz)
Vector get_scale(void) const
char filename[NAMD_FILENAME_BUFFER_SIZE]
Tensor get_inv(void) const
void initialize(char *potfilename, SimParameters *simParams, MGridforceParams *mgridParams)
static GridforceGrid * unpack_grid(int gridnum, MIStream *msg)
void buildSubgridsFlat(void)
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 compute_dV(float *a, float *x, float *y, float *z) const
void pack(MOStream *msg) const
virtual ~GridforceFullMainGrid()
MOStream * put(char data)
GridforceGridType get_grid_type(void)
static const int default_border
float get_grid(int i0, int i1, int i2, int i3) const
void pack(MOStream *msg) const
Position get_origin(void) const
double get_grid_d(int i0, int i1, int i2) const
void initialize(SimParameters *simParams, MGridforceParams *mgridParams)
void unpack(MIStream *msg)
void unpack(MIStream *msg)
void compute_a(float *a, float *b) const