NAMD
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
GridforceFullSubGrid Class Reference

#include <GridForceGrid.h>

Inheritance diagram for GridforceFullSubGrid:
GridforceFullBaseGrid

Public Member Functions

 GridforceFullSubGrid (GridforceFullBaseGrid *parent_in)
 
void initialize (SimParameters *simParams, MGridforceParams *mgridParams)
 
int get_border (void) const
 
Tensor tensorMult (const Tensor &t1, const Tensor &t2)
 
- Public Member Functions inherited from GridforceFullBaseGrid
 GridforceFullBaseGrid (void)
 
virtual ~GridforceFullBaseGrid ()
 
Position get_center (void) const
 
Position get_origin (void) const
 
Tensor get_e (void) const
 
Tensor get_inv (void) const
 
Vector get_scale (void) const
 
Bool get_checksize (void) const
 
float get_grid (int i0, int i1, int i2) const
 
double get_grid_d (int i0, int i1, int i2) const
 
void set_grid (int i0, int i1, int i2, float V)
 
void set_scale (Vector s)
 
int compute_VdV (Position pos, float &V, Vector &dV) const
 
int get_k0 (void) const
 
int get_k1 (void) const
 
int get_k2 (void) const
 
void readHeader (SimParameters *simParams, MGridforceParams *mgridParams)
 
long int grid_index (int i0, int i1, int i2) const
 
int get_inds (Position pos, int *inds, Vector &dg, Vector &gapscale) const
 
void compute_a (float *a, float *b) const
 
float compute_V (float *a, float *x, float *y, float *z) const
 
Vector compute_dV (float *a, float *x, float *y, float *z) const
 
Vector compute_d2V (float *a, float *x, float *y, float *z) const
 
float compute_d3V (float *a, float *x, float *y, float *z) const
 
void readSubgridHierarchy (FILE *poten, int &totalGrids)
 

Protected Member Functions

void pack (MOStream *msg) const
 
void unpack (MIStream *msg)
 
void compute_b (float *b, int *inds, Vector gapscale) const
 
void addToSubgridsFlat (void)
 

Protected Attributes

Tensor scale_dV
 
Tensor scale_d2V
 
float scale_d3V
 
GridforceFullBaseGridparent
 
int pmin [3]
 
int pmax [3]
 
GridforceFullMainGridmaingrid
 
int subgridIdx
 

Friends

class GridforceFullBaseGrid
 
class GridforceFullMainGrid
 

Additional Inherited Members

- Public Attributes inherited from GridforceFullBaseGrid
FILE * poten_fp
 
float * grid
 
GridforceFullSubGrid ** subgrids
 
int numSubgrids
 
int generation
 
int k [3]
 
int k_nopad [3]
 
long int size
 
long int size_nopad
 
long int dk [3]
 
long int dk_nopad [3]
 
float factor
 
Position origin
 
Position center
 
Tensor e
 
Tensor inv
 
double p_sum [3]
 
double n_sum [3]
 
double pad_p [3]
 
double pad_n [3]
 
Bool cont [3]
 
float offset [3]
 
float gap [3]
 
float gapinv [3]
 
Vector scale
 
Bool checksize
 

Detailed Description

Definition at line 241 of file GridForceGrid.h.

Constructor & Destructor Documentation

◆ GridforceFullSubGrid()

GridforceFullSubGrid::GridforceFullSubGrid ( GridforceFullBaseGrid parent_in)

Definition at line 900 of file GridForceGrid.C.

References DebugM, endi(), GridforceFullBaseGrid::generation, maingrid, parent, and GridforceFullBaseGrid::poten_fp.

900  {
901  parent = parent_in;
905  while (tmp->generation > 0) {
906  tmp = ((GridforceFullSubGrid *)tmp)->parent;
907  }
909  DebugM(4, "generation = " << generation << "\n" << endi);
910 }
#define DebugM(x, y)
Definition: Debug.h:75
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
GridforceFullMainGrid * maingrid
GridforceFullBaseGrid * parent

Member Function Documentation

◆ addToSubgridsFlat()

void GridforceFullSubGrid::addToSubgridsFlat ( void  )
protected

Definition at line 1150 of file GridForceGrid.C.

References addToSubgridsFlat(), DebugM, endi(), maingrid, GridforceFullBaseGrid::numSubgrids, subgridIdx, GridforceFullBaseGrid::subgrids, and GridforceFullMainGrid::subgrids_flat.

Referenced by addToSubgridsFlat(), and GridforceFullMainGrid::buildSubgridsFlat().

1151 {
1152  DebugM(4, "addToSubgridsFlat() called, subgridIdx = " << subgridIdx << ", maingrid->numSubgrids = " << maingrid->numSubgrids << "\n" << endi);
1153  maingrid->subgrids_flat[subgridIdx-1] = this;
1154  for (int i = 0; i < numSubgrids; i++) {
1156  }
1157 }
#define DebugM(x, y)
Definition: Debug.h:75
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
GridforceFullMainGrid * maingrid
GridforceFullSubGrid ** subgrids
GridforceFullSubGrid ** subgrids_flat
void addToSubgridsFlat(void)

◆ compute_b()

void GridforceFullSubGrid::compute_b ( float *  b,
int *  inds,
Vector  gapscale 
) const
protectedvirtual

Implements GridforceFullBaseGrid.

Definition at line 1160 of file GridForceGrid.C.

References GridforceFullBaseGrid::compute_a(), GridforceFullBaseGrid::compute_b(), GridforceFullBaseGrid::compute_d2V(), GridforceFullBaseGrid::compute_d3V(), GridforceFullBaseGrid::compute_dV(), GridforceFullBaseGrid::compute_V(), GridforceFullBaseGrid::cont, DebugM, GridforceFullBaseGrid::e, endi(), GridforceFullBaseGrid::gap, GridforceFullBaseGrid::get_grid(), GridforceFullBaseGrid::get_grid_d(), GridforceFullBaseGrid::inv, GridforceFullBaseGrid::k, GridforceFullBaseGrid::offset, GridforceFullBaseGrid::origin, parent, scale_d2V, scale_d3V, scale_dV, Vector::x, Vector::y, and Vector::z.

1161 {
1162  for (int i0 = 0; i0 < 8; i0++) {
1163  int inds2[3];
1164 
1165  float voff = 0.0;
1166  int bit = 1; // bit = 2^i1 in the below loop
1167  for (int i1 = 0; i1 < 3; i1++) {
1168  inds2[i1] = (inds[i1] + ((i0 & bit) ? 1 : 0)) % k[i1];
1169 
1170  // Deal with voltage offsets
1171  if (cont[i1] && inds[i1] == (k[i1]-1) && inds2[i1] == 0) {
1172  voff += offset[i1];
1173  DebugM(3, "offset[" << i1 << "] = " << offset[i1] << "\n" << endi);
1174  }
1175 
1176  bit <<= 1; // i.e. multiply by 2
1177  }
1178 
1179  DebugM(3, "inds2 = " << inds2[0] << " " << inds2[1] << " " << inds2[2] << "\n" << endi);
1180 
1181  int d_hi[3] = {1, 1, 1};
1182  int d_lo[3] = {1, 1, 1};
1183  float voffs[3];
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);
1188  voffs[i1] = offset[i1];
1189  dscales[i1] = 1.0/(1.0 + gap[i1]) * 1.0/gapscale[i1];
1190  }
1191  else if (inds2[i1] == k[i1]-1 && cont[i1]) {
1192  d_hi[i1] = -(k[i1]-1);
1193  voffs[i1] = offset[i1];
1194  dscales[i1] = 1.0/(1.0 + gap[i1]) * 1.0/gapscale[i1];
1195  }
1196  else {
1197  voffs[i1] = 0.0;
1198  }
1199  }
1200 
1201  bool edge = false;
1202  for (int i1 = 0; i1 < 3; i1++) {
1203  if (!cont[i1] && (inds2[i1] == 0 || inds2[i1] == k[i1]-1)) {
1204  edge = true;
1205  }
1206  }
1207 
1208  if (inds2[2] == 0) {
1209 // DebugM(3, "cont = " << cont[0] << " " << cont[1] << " " << cont[2] << " d_hi = " << d_hi[0] << " " << d_hi[1] << " " << d_hi[2] << " d_lo = " << d_lo[0] << " " << d_lo[1] << " " << d_lo[2] << " dscales = " << dscales[0] << " " << dscales[1] << " " << dscales[2] << "\n" << endi);
1210  DebugM(3, "cont = " << cont[0] << " " << cont[1] << " " << cont[2] << "\n" << endi);
1211  }
1212 
1213  if (edge) {
1214  DebugM(2, "Edge!\n" << endi);
1215 
1216  // Must get derivatives from parent
1217  Position pos = e * Vector(inds2[0], inds2[1], inds2[2]) + origin; // Gridpoint position in realspace
1218  Vector g = parent->inv * (pos - parent->origin); // Gridpoint position in parent's gridspace
1219  Vector dg;
1220  int inds3[3];
1221 
1222  DebugM(2, "g = " << g << "\n" << endi);
1223 
1224  for (int i = 0; i < 3; i++) {
1225  inds3[i] = (int)floor(g[i]);
1226  dg[i] = g[i] - inds3[i];
1227  }
1228 
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);
1238  }
1239 
1240  // Compute parent matrices
1241  float b_parent[64];
1242  parent->compute_b(b_parent, inds3, gapscale);
1243 
1244  float a_parent[64];
1245  parent->compute_a(a_parent, b_parent);
1246 
1247  // Compute parent derivatives
1248  float V = parent->compute_V(a_parent, x, y, z);
1249  Vector dV = scale_dV * parent->compute_dV(a_parent, x, y, z);
1250  Vector d2V = scale_d2V * parent->compute_d2V(a_parent, x, y, z);
1251  float d3V = scale_d3V * parent->compute_d3V(a_parent, x, y, z);
1252 
1253  b[i0] = V;
1254  b[8+i0] = dV[0];
1255  b[16+i0] = dV[1];
1256  b[24+i0] = dV[2];
1257  b[32+i0] = d2V[0];
1258  b[40+i0] = d2V[1];
1259  b[48+i0] = d2V[2];
1260  b[56+i0] = d3V;
1261  } else {
1262  b[i0] = get_grid(inds2[0],inds2[1],inds2[2]) + voff; // V
1263 
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]); // dV/dx
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]); // dV/dy
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]); // dV/dz
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])); // d2V/dxdy
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])); // d2V/dxdz
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])); // d2V/dydz
1276 
1277  b[56+i0] = dscales[0] * dscales[1] * dscales[2] // d3V/dxdydz
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]));
1282  }
1283 
1284  if (inds2[0] == 1 && inds2[1] == 1 && inds2[2] == 0) {
1285  DebugM(1, "Sub V = " << b[i0] << "\n");
1286 
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");
1290 
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");
1294 
1295  DebugM(1, "Sub d3V/dxdydz = " << b[56+i0] << "\n" << endi);
1296  }
1297  }
1298 }
float compute_V(float *a, float *x, float *y, float *z) const
Definition: Vector.h:72
virtual void compute_b(float *b, int *inds, Vector gapscale) const =0
Vector compute_d2V(float *a, float *x, float *y, float *z) const
#define DebugM(x, y)
Definition: Debug.h:75
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
float compute_d3V(float *a, float *x, float *y, float *z) const
GridforceFullBaseGrid * parent
float get_grid(int i0, int i1, int i2) const
BigReal x
Definition: Vector.h:74
BigReal y
Definition: Vector.h:74
Vector compute_dV(float *a, float *x, float *y, float *z) const
double get_grid_d(int i0, int i1, int i2) const
void compute_a(float *a, float *b) const

◆ get_border()

int GridforceFullSubGrid::get_border ( void  ) const
inlinevirtual

Implements GridforceFullBaseGrid.

Definition at line 250 of file GridForceGrid.h.

250 { return 0; }

◆ initialize()

void GridforceFullSubGrid::initialize ( SimParameters simParams,
MGridforceParams mgridParams 
)

Definition at line 913 of file GridForceGrid.C.

References GridforceFullBaseGrid::center, GridforceFullBaseGrid::checksize, GridforceFullBaseGrid::cont, DebugM, Tensor::diagonal(), GridforceFullBaseGrid::dk, GridforceFullBaseGrid::e, endi(), GridforceFullBaseGrid::factor, FALSE, GridforceFullBaseGrid::gap, GridforceFullBaseGrid::gapinv, GridforceFullBaseGrid::generation, GridforceFullBaseGrid::get_border(), GridforceFullBaseGrid::get_grid(), GridforceFullBaseGrid::grid, MGridforceParams::gridforceCheckSize, MGridforceParams::gridforceScale, MGridforceParams::gridforceVolts, initialize(), GridforceFullBaseGrid::inv, iout, GridforceFullBaseGrid::k, GridforceFullBaseGrid::k_nopad, NAMD_die(), GridforceFullBaseGrid::numSubgrids, GridforceFullBaseGrid::offset, GridforceFullBaseGrid::origin, parent, pmax, pmin, GridforceFullBaseGrid::poten_fp, GridforceFullBaseGrid::readHeader(), GridforceFullBaseGrid::scale, scale_d2V, scale_d3V, scale_dV, GridforceFullBaseGrid::set_grid(), simParams, GridforceFullBaseGrid::size, GridforceFullBaseGrid::size_nopad, GridforceFullBaseGrid::subgrids, tensorMult(), TRUE, Vector::x, Tensor::xx, Tensor::xy, Tensor::xz, Vector::y, Tensor::yx, Tensor::yy, Tensor::yz, Vector::z, Tensor::zx, Tensor::zy, and Tensor::zz.

Referenced by GridforceFullMainGrid::initialize(), and initialize().

914 {
915  int tmp;
916  char line[256];
917  long int poten_offset;
918 
919  // Skip 'attribute's
920  DebugM(3, "Skipping 'attribute' keywords...\n" << endi);
921  char str[256];
922  do {
923  poten_offset = ftell(poten_fp);
924  fscanf(poten_fp, "%s", str);
925  fgets(line, 256, poten_fp);
926  DebugM(4, "Read line " << str << " " << line << endi);
927  } while (strcmp(str, "attribute") == 0);
928  fseek(poten_fp, poten_offset, SEEK_SET);
929 
930  // Skip 'field' object
931  DebugM(3, "Skipping 'field' object\n" << endi);
932  fscanf(poten_fp, "object");
933  int n;
934  n = fscanf(poten_fp, "\"%[^\"]\" class field\n", str);
935  if (n == 0) {
936  n = fscanf(poten_fp, "%d class field\n", &tmp);
937  }
938 
939  if (n == 0) {
940  NAMD_die("Error reading gridforce grid! Could not find field object!\n");
941  }
942 
943  // Skip 'component's
944  DebugM(3, "Skipping 'component' keywords\n" << endi);
945  do {
946  poten_offset = ftell(poten_fp);
947  fscanf(poten_fp, "%s", str);
948  fgets(line, 256, poten_fp);
949  } while (strcmp(str, "component") == 0);
950  fseek(poten_fp, poten_offset, SEEK_SET);
951 
952  // Read header
953  readHeader(simParams, mgridParams);
954 
955  factor = 1.0;
956  if (mgridParams->gridforceVolts)
957  {
958  factor /= 0.0434; // convert V -> kcal/mol*e
959  }
960  scale = mgridParams->gridforceScale;
961  checksize = mgridParams->gridforceCheckSize;
962 
963  for (int i = 0; i < 3; i++) {
964  k[i] = k_nopad[i]; // subgrids aren't padded
965  }
966 
967  // Make sure that each subgrid dimension is an integral
968  // number of spanned supergrid cells. This is to ensure that no
969  // supergrid nodes land in the middle of a subgrid, because in
970  // this case forces could not be matched properly.
971  for (int i = 0; i < 3; i++) {
972  if ((k[i] - 1) % (pmax[i] - pmin[i] + 1) != 0) {
973  iout << (k[i] - 1) << " % " << (pmax[i] - pmin[i] + 1) << " != 0\n" << endi;
974  NAMD_die("Error reading gridforce grid! Subgrid dimensions must be an integral number spanned parent cells!");
975  }
976  }
977 
978  for (int i = 0; i < 3; i++) {
979  if (parent->cont[i]) {
980  cont[i] = (pmin[i] == 0 && pmax[i] == parent->k[i]-2) ? TRUE : FALSE;
981  DebugM(3, "pmin[" << i << "] = " << pmin[i] << " pmax[" << i << "] = " << pmax[i] << " parent->k[" << i << "] = " << parent->k[i] << " cont[" << i << "] = " << cont[i] << "\n" << endi);
982  } else {
983  cont[i] = false;
984  if (parent->generation == 0) {
985  // Add to pmin, pmax since parent got extra gridpoint layer(s) (maybe)
986  int brd = parent->get_border();
987  pmin[i] += brd;
988  pmax[i] += brd;
989  }
990  }
991  }
992 
993  DebugM(4, "pmin = " << pmin[0] << " " << pmin[1] << " " << pmin[2] << "\n");
994  DebugM(4, "pmax = " << pmax[0] << " " << pmax[1] << " " << pmax[2] << "\n" << endi);
995 
996  Vector origin2 = parent->origin + parent->e * Position(pmin[0], pmin[1], pmin[2]);
997  Vector escale, invscale;
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];
1001  if (cont[i]) { pmax[i]++; }
1002  }
1003  Tensor e2 = tensorMult(parent->e, Tensor::diagonal(escale));
1004 
1005  // Check that lattice parameters agree with min and max numbers
1006  // from subgrid hierarchy.
1007  double TOL2 = 1e-4; // Totally arbitrary
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)
1020  {
1021  NAMD_die("Error reading gridforce grid! Subgrid lattice does not match!");
1022  }
1023 
1024  // Overwrite what was read from the header
1025  origin = origin2;
1026  e = e2;
1027 
1028  inv = tensorMult(Tensor::diagonal(invscale), parent->inv);
1029  for (int i = 0; i < 3; i++) {
1030  gap[i] = escale[i] * parent->gap[i];
1031  gapinv[i] = invscale[i] * parent->gapinv[i];
1032  offset[i] = parent->offset[i];
1033  }
1034  center = origin + e * 0.5 * Position(k[0], k[1], k[2]);
1035 
1036  DebugM(4, "origin = " << origin << "\n");
1037  DebugM(4, "e = " << e << "\n");
1038  DebugM(4, "inv = " << inv << "\n");
1039  DebugM(4, "gap = " << gap[0] << " " << gap[2] << " " << gap[2] << " " << "\n");
1040  DebugM(4, "gapinv = " << gapinv[0] << " " << gapinv[2] << " " << gapinv[2] << " " << "\n");
1041  DebugM(4, "numSubgrids = " << numSubgrids << "\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);
1045 
1046  /*** Set members ***/
1047  size = k[0] * k[1] * k[2];
1048  dk[0] = k[1] * k[2];
1049  dk[1] = k[2];
1050  dk[2] = 1;
1051 
1052  scale_dV = Tensor::diagonal(escale);
1053  scale_d2V = Tensor::diagonal(Vector(escale.x*escale.y, escale.x*escale.z, escale.y*escale.z));
1054  scale_d3V = escale.x * escale.y * escale.z;
1055 
1056  DebugM(4, "scale_dV = " << scale_dV << "\n");
1057  DebugM(4, "scale_d2V = " << scale_d2V << "\n");
1058  DebugM(4, "scale_d3V = " << scale_d3V << "\n" << endi);
1059 
1060  // Allocate storage for potential and read it
1061  float *grid_tmp = new float[size];
1062 
1063  float tmp2;
1064  DebugM(3, "size_nopad = " << size_nopad << "\n");
1065  for (long int count = 0; count < size_nopad; count++) {
1066 // poten_offset = ftell(poten_fp);
1067 // fscanf(poten_fp, "%s", str);
1068 // fgets(line, 256, poten_fp);
1069 // DebugM(4, "Read line " << str << " " << line << endi);
1070 // fseek(poten_fp, poten_offset, SEEK_SET);
1071 
1072  int err = fscanf(poten_fp, "%f", &tmp2);
1073  if (err == EOF || err == 0) {
1074  NAMD_die("Grid force potential file incorrectly formatted");
1075  }
1076  grid_tmp[count] = tmp2 * factor;
1077  }
1078  fscanf(poten_fp, "\n");
1079 
1080  // Set real grid
1081  DebugM(3, "allocating grid\n" << endi);
1082  delete[] grid;
1083  grid = new float[size];
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]);
1089  }
1090  }
1091  }
1092 
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);
1097  }
1098  }
1099  }
1100 
1101  // Clean up
1102  delete[] grid_tmp;
1103 
1104  // Call initialize for each subgrid
1105  for (int i = 0; i < numSubgrids; i++) {
1106  subgrids[i]->initialize(simParams, mgridParams);
1107  }
1108 }
BigReal zy
Definition: Tensor.h:19
BigReal xz
Definition: Tensor.h:17
Definition: Vector.h:72
#define DebugM(x, y)
Definition: Debug.h:75
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
#define FALSE
Definition: common.h:127
BigReal yz
Definition: Tensor.h:18
#define iout
Definition: InfoStream.h:51
void readHeader(SimParameters *simParams, MGridforceParams *mgridParams)
GridforceFullSubGrid ** subgrids
GridforceFullBaseGrid * parent
void set_grid(int i0, int i1, int i2, float V)
BigReal yx
Definition: Tensor.h:18
static NAMD_HOST_DEVICE Tensor diagonal(const Vector &v1)
Definition: Tensor.h:37
float get_grid(int i0, int i1, int i2) const
Vector Position
Definition: NamdTypes.h:24
BigReal x
Definition: Vector.h:74
void NAMD_die(const char *err_msg)
Definition: common.C:147
virtual int get_border(void) const =0
BigReal xx
Definition: Tensor.h:17
BigReal zz
Definition: Tensor.h:19
#define simParams
Definition: Output.C:129
Definition: Tensor.h:15
BigReal xy
Definition: Tensor.h:17
Tensor tensorMult(const Tensor &t1, const Tensor &t2)
BigReal y
Definition: Vector.h:74
BigReal yy
Definition: Tensor.h:18
void initialize(SimParameters *simParams, MGridforceParams *mgridParams)
BigReal zx
Definition: Tensor.h:19
#define TRUE
Definition: common.h:128

◆ pack()

void GridforceFullSubGrid::pack ( MOStream msg) const
protectedvirtual

Reimplemented from GridforceFullBaseGrid.

Definition at line 1111 of file GridForceGrid.C.

References DebugM, endi(), GridforceFullBaseGrid::pack(), pmax, pmin, MOStream::put(), scale_d2V, scale_d3V, scale_dV, and subgridIdx.

Referenced by GridforceFullBaseGrid::pack().

1112 {
1113  DebugM(4, "Packing subgrid\n" << endi);
1114 
1115  msg->put(sizeof(Tensor), (char*)&scale_dV);
1116  msg->put(sizeof(Tensor), (char*)&scale_d2V);
1117  msg->put(sizeof(float), (char*)&scale_d3V);
1118 
1119  msg->put(3*sizeof(int), (char*)pmin);
1120  msg->put(3*sizeof(int), (char*)pmax);
1121  msg->put(subgridIdx);
1122 
1123  DebugM(3, "calling GridforceFullBaseGrid::pack\n" << endi);
1124 
1126 }
#define DebugM(x, y)
Definition: Debug.h:75
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
virtual void pack(MOStream *msg) const
Definition: Tensor.h:15
MOStream * put(char data)
Definition: MStream.h:112

◆ tensorMult()

Tensor GridforceFullSubGrid::tensorMult ( const Tensor t1,
const Tensor t2 
)
inline

Definition at line 252 of file GridForceGrid.h.

References Tensor::xx, Tensor::xy, Tensor::xz, Tensor::yx, Tensor::yy, Tensor::yz, Tensor::zx, Tensor::zy, and Tensor::zz.

Referenced by initialize().

252  {
253  Tensor tmp;
254  tmp.xx = t1.xx * t2.xx + t1.xy * t2.yx + t1.xz * t2.zx;
255  tmp.xy = t1.xx * t2.xy + t1.xy * t2.yy + t1.xz * t2.zy;
256  tmp.xz = t1.xx * t2.xz + t1.xy * t2.yz + t1.xz * t2.zz;
257  tmp.yx = t1.yx * t2.xx + t1.yy * t2.yx + t1.yz * t2.zx;
258  tmp.yy = t1.yx * t2.xy + t1.yy * t2.yy + t1.yz * t2.zy;
259  tmp.yz = t1.yx * t2.xz + t1.yy * t2.yz + t1.yz * t2.zz;
260  tmp.zx = t1.zx * t2.xx + t1.zy * t2.yx + t1.zz * t2.zx;
261  tmp.zy = t1.zx * t2.xy + t1.zy * t2.yy + t1.zz * t2.zy;
262  tmp.zz = t1.zx * t2.xz + t1.zy * t2.yz + t1.zz * t2.zz;
263  return tmp;
264  }
BigReal zy
Definition: Tensor.h:19
BigReal xz
Definition: Tensor.h:17
BigReal yz
Definition: Tensor.h:18
BigReal yx
Definition: Tensor.h:18
BigReal xx
Definition: Tensor.h:17
BigReal zz
Definition: Tensor.h:19
Definition: Tensor.h:15
BigReal xy
Definition: Tensor.h:17
BigReal yy
Definition: Tensor.h:18
BigReal zx
Definition: Tensor.h:19

◆ unpack()

void GridforceFullSubGrid::unpack ( MIStream msg)
protectedvirtual

Reimplemented from GridforceFullBaseGrid.

Definition at line 1129 of file GridForceGrid.C.

References DebugM, endi(), GridforceFullBaseGrid::gapinv, GridforceFullBaseGrid::generation, MIStream::get(), GridforceFullBaseGrid::numSubgrids, pmax, pmin, scale_d2V, scale_d3V, scale_dV, GridforceFullBaseGrid::size, subgridIdx, and GridforceFullBaseGrid::unpack().

Referenced by GridforceFullBaseGrid::unpack().

1130 {
1131  DebugM(4, "Unpacking subgrid\n" << endi);
1132 
1133  msg->get(sizeof(Tensor), (char*)&scale_dV);
1134  msg->get(sizeof(Tensor), (char*)&scale_d2V);
1135  msg->get(sizeof(float), (char*)&scale_d3V);
1136 
1137  msg->get(3*sizeof(int), (char*)pmin);
1138  msg->get(3*sizeof(int), (char*)pmax);
1139  msg->get(subgridIdx);
1140 
1142 
1143  DebugM(4, "size = " << size << "\n");
1144  DebugM(4, "numSubgrids = " << numSubgrids << "\n");
1145  DebugM(4, "gapinv = " << gapinv[0] << " " << gapinv[2] << " " << gapinv[2] << " " << "\n");
1146  DebugM(4, "generation = " << generation << "\n" << endi);
1147 }
#define DebugM(x, y)
Definition: Debug.h:75
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
MIStream * get(char &data)
Definition: MStream.h:29
virtual void unpack(MIStream *msg)
Definition: Tensor.h:15

Friends And Related Function Documentation

◆ GridforceFullBaseGrid

friend class GridforceFullBaseGrid
friend

Definition at line 242 of file GridForceGrid.h.

◆ GridforceFullMainGrid

friend class GridforceFullMainGrid
friend

Definition at line 243 of file GridForceGrid.h.

Member Data Documentation

◆ maingrid

GridforceFullMainGrid* GridforceFullSubGrid::maingrid
protected

Definition at line 281 of file GridForceGrid.h.

Referenced by addToSubgridsFlat(), and GridforceFullSubGrid().

◆ parent

GridforceFullBaseGrid* GridforceFullSubGrid::parent
protected

Definition at line 279 of file GridForceGrid.h.

Referenced by compute_b(), GridforceFullSubGrid(), and initialize().

◆ pmax

int GridforceFullSubGrid::pmax[3]
protected

Definition at line 280 of file GridForceGrid.h.

Referenced by initialize(), pack(), and unpack().

◆ pmin

int GridforceFullSubGrid::pmin[3]
protected

Definition at line 280 of file GridForceGrid.h.

Referenced by initialize(), pack(), and unpack().

◆ scale_d2V

Tensor GridforceFullSubGrid::scale_d2V
protected

Definition at line 276 of file GridForceGrid.h.

Referenced by compute_b(), initialize(), pack(), and unpack().

◆ scale_d3V

float GridforceFullSubGrid::scale_d3V
protected

Definition at line 277 of file GridForceGrid.h.

Referenced by compute_b(), initialize(), pack(), and unpack().

◆ scale_dV

Tensor GridforceFullSubGrid::scale_dV
protected

Definition at line 275 of file GridForceGrid.h.

Referenced by compute_b(), initialize(), pack(), and unpack().

◆ subgridIdx

int GridforceFullSubGrid::subgridIdx
protected

Definition at line 282 of file GridForceGrid.h.

Referenced by addToSubgridsFlat(), pack(), and unpack().


The documentation for this class was generated from the following files: