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
 

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 Member Functions inherited from GridforceFullBaseGrid
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 Attributes

Tensor scale_dV
 
Tensor scale_d2V
 
float scale_d3V
 
GridforceFullBaseGridparent
 
int pmin [3]
 
int pmax [3]
 
GridforceFullMainGridmaingrid
 
int subgridIdx
 
- Protected 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
 

Friends

class GridforceFullBaseGrid
 
class GridforceFullMainGrid
 

Detailed Description

Definition at line 242 of file GridForceGrid.h.

Constructor & Destructor Documentation

GridforceFullSubGrid::GridforceFullSubGrid ( GridforceFullBaseGrid parent_in)

Definition at line 901 of file GridForceGrid.C.

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

901  {
902  parent = parent_in;
906  while (tmp->generation > 0) {
907  tmp = ((GridforceFullSubGrid *)tmp)->parent;
908  }
910  DebugM(4, "generation = " << generation << "\n" << endi);
911 }
#define DebugM(x, y)
Definition: Debug.h:59
GridforceFullMainGrid * maingrid
GridforceFullBaseGrid * parent
infostream & endi(infostream &s)
Definition: InfoStream.C:38

Member Function Documentation

void GridforceFullSubGrid::addToSubgridsFlat ( void  )
protected

Definition at line 1151 of file GridForceGrid.C.

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

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

1152 {
1153  DebugM(4, "addToSubgridsFlat() called, subgridIdx = " << subgridIdx << ", maingrid->numSubgrids = " << maingrid->numSubgrids << "\n" << endi);
1154  maingrid->subgrids_flat[subgridIdx-1] = this;
1155  for (int i = 0; i < numSubgrids; i++) {
1157  }
1158 }
#define DebugM(x, y)
Definition: Debug.h:59
GridforceFullMainGrid * maingrid
GridforceFullSubGrid ** subgrids
GridforceFullSubGrid ** subgrids_flat
void addToSubgridsFlat(void)
infostream & endi(infostream &s)
Definition: InfoStream.C:38
void GridforceFullSubGrid::compute_b ( float *  b,
int *  inds,
Vector  gapscale 
) const
protectedvirtual

Implements GridforceFullBaseGrid.

Definition at line 1161 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, x, Vector::y, y, Vector::z, and z.

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

Implements GridforceFullBaseGrid.

Definition at line 251 of file GridForceGrid.h.

251 { return 0; }
void GridforceFullSubGrid::initialize ( SimParameters simParams,
MGridforceParams mgridParams 
)

Definition at line 914 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(), 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().

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

Reimplemented from GridforceFullBaseGrid.

Definition at line 1112 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().

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

Definition at line 253 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().

253  {
254  Tensor tmp;
255  tmp.xx = t1.xx * t2.xx + t1.xy * t2.yx + t1.xz * t2.zx;
256  tmp.xy = t1.xx * t2.xy + t1.xy * t2.yy + t1.xz * t2.zy;
257  tmp.xz = t1.xx * t2.xz + t1.xy * t2.yz + t1.xz * t2.zz;
258  tmp.yx = t1.yx * t2.xx + t1.yy * t2.yx + t1.yz * t2.zx;
259  tmp.yy = t1.yx * t2.xy + t1.yy * t2.yy + t1.yz * t2.zy;
260  tmp.yz = t1.yx * t2.xz + t1.yy * t2.yz + t1.yz * t2.zz;
261  tmp.zx = t1.zx * t2.xx + t1.zy * t2.yx + t1.zz * t2.zx;
262  tmp.zy = t1.zx * t2.xy + t1.zy * t2.yy + t1.zz * t2.zy;
263  tmp.zz = t1.zx * t2.xz + t1.zy * t2.yz + t1.zz * t2.zz;
264  return tmp;
265  }
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
void GridforceFullSubGrid::unpack ( MIStream msg)
protectedvirtual

Reimplemented from GridforceFullBaseGrid.

Definition at line 1130 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().

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

Friends And Related Function Documentation

friend class GridforceFullBaseGrid
friend

Definition at line 243 of file GridForceGrid.h.

friend class GridforceFullMainGrid
friend

Definition at line 244 of file GridForceGrid.h.

Member Data Documentation

GridforceFullMainGrid* GridforceFullSubGrid::maingrid
protected

Definition at line 282 of file GridForceGrid.h.

Referenced by addToSubgridsFlat(), and GridforceFullSubGrid().

GridforceFullBaseGrid* GridforceFullSubGrid::parent
protected

Definition at line 280 of file GridForceGrid.h.

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

int GridforceFullSubGrid::pmax[3]
protected

Definition at line 281 of file GridForceGrid.h.

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

int GridforceFullSubGrid::pmin[3]
protected

Definition at line 281 of file GridForceGrid.h.

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

Tensor GridforceFullSubGrid::scale_d2V
protected

Definition at line 277 of file GridForceGrid.h.

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

float GridforceFullSubGrid::scale_d3V
protected

Definition at line 278 of file GridForceGrid.h.

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

Tensor GridforceFullSubGrid::scale_dV
protected

Definition at line 276 of file GridForceGrid.h.

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

int GridforceFullSubGrid::subgridIdx
protected

Definition at line 283 of file GridForceGrid.h.

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


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