GridforceFullMainGrid Class Reference

#include <GridForceGrid.h>

Inheritance diagram for GridforceFullMainGrid:

GridforceGrid GridforceFullBaseGrid List of all members.

Public Member Functions

 GridforceFullMainGrid (int gridnum)
virtual ~GridforceFullMainGrid ()
void initialize (char *potfilename, SimParameters *simParams, MGridforceParams *mgridParams, int border)
void initialize (char *potfilename, SimParameters *simParams, MGridforceParams *mgridParams)
void reinitialize (SimParameters *simParams, MGridforceParams *mgridParams)
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
int get_k0 (void) const
int get_k1 (void) const
int get_k2 (void) const
int get_border (void) const
int compute_VdV (Position pos, float &V, Vector &dV) const
int get_total_grids (void) const
void set_scale (Vector s)

Protected Member Functions

void pack (MOStream *msg) const
void unpack (MIStream *msg)
long int get_all_gridvals (float **all_gridvals) const
void set_all_gridvals (float *all_gridvals, long int sz)
void compute_b (float *b, int *inds, Vector gapscale) const
void buildSubgridsFlat (void)

Protected Attributes

char filename [129]
int totalGrids
GridforceFullSubGrid ** subgrids_flat
int border

Static Protected Attributes

static const int default_border = 1

Friends

class GridforceFullBaseGrid
class GridforceFullSubGrid

Detailed Description

Definition at line 191 of file GridForceGrid.h.


Constructor & Destructor Documentation

GridforceFullMainGrid::GridforceFullMainGrid ( int  gridnum  )  [explicit]

Definition at line 354 of file GridForceGrid.C.

References GridforceFullBaseGrid::generation, GridforceGrid::GridforceGridTypeFull, GridforceGrid::mygridnum, subgrids_flat, and GridforceGrid::type.

00355 {
00356     mygridnum = gridnum;
00357     generation = 0;
00358     subgrids_flat = NULL;
00359     type = GridforceGridTypeFull;
00360 }

GridforceFullMainGrid::~GridforceFullMainGrid (  )  [virtual]

Definition at line 363 of file GridForceGrid.C.

References subgrids_flat.

00364 {
00365     delete[] subgrids_flat;
00366 }


Member Function Documentation

void GridforceFullMainGrid::buildSubgridsFlat ( void   )  [protected]

Definition at line 407 of file GridForceGrid.C.

References GridforceFullSubGrid::addToSubgridsFlat(), DebugM, endi(), GridforceFullBaseGrid::numSubgrids, GridforceFullBaseGrid::subgrids, subgrids_flat, and totalGrids.

Referenced by initialize(), and unpack().

00408 {
00409     DebugM(4, "buildSubgridsFlat() called, totalGrids-1 = " << totalGrids-1 << "\n" << endi);
00410     delete[] subgrids_flat;
00411     subgrids_flat = new GridforceFullSubGrid *[totalGrids-1];
00412     for (int i = 0; i < numSubgrids; i++) {
00413         DebugM(3, "adding to subgridsFlat\n" << endi);
00414         subgrids[i]->addToSubgridsFlat();
00415         DebugM(3, "success!\n" << endi);
00416     }
00417     for (int i = 0; i < totalGrids-1; i++) {
00418         DebugM(4, "subgrids_flat[" << i << "]->numSubgrids = " << subgrids_flat[i]->numSubgrids << "\n" << endi);
00419     }
00420     for (int i = 0; i < numSubgrids; i++) {
00421         DebugM(4, "subgrids[" << i << "]->numSubgrids = " << subgrids[i]->numSubgrids << "\n" << endi);
00422     }
00423 }

void GridforceFullMainGrid::compute_b ( float *  b,
int *  inds,
Vector  gapscale 
) const [protected, virtual]

Implements GridforceFullBaseGrid.

Definition at line 782 of file GridForceGrid.C.

References DebugM, endi(), FALSE, GridforceFullBaseGrid::gap, GridforceFullBaseGrid::get_grid(), GridforceFullBaseGrid::get_grid_d(), GridforceFullBaseGrid::offset, and TRUE.

00783 {
00784     for (int i0 = 0; i0 < 8; i0++) {
00785         int inds2[3];
00786         int zero_derivs = FALSE;
00787         
00788         float voff = 0.0;
00789         int bit = 1;    // bit = 2^i1 in the below loop
00790         for (int i1 = 0; i1 < 3; i1++) {
00791             inds2[i1] = (inds[i1] + ((i0 & bit) ? 1 : 0)) % k[i1];
00792             
00793             // Deal with voltage offsets
00794             if (cont[i1] && inds[i1] == (k[i1]-1) && inds2[i1] == 0) {
00795                 voff += offset[i1];
00796                 DebugM(3, "offset[" << i1 << "] = " << offset[i1] << "\n" << endi);
00797             }
00798             
00799             bit <<= 1;  // i.e. multiply by 2
00800         }
00801         
00802         DebugM(1, "inds2 = " << inds2[0] << " " << inds2[1] << " " << inds2[2] << "\n" << endi);
00803         
00804         // NOTE: leaving everything in terms of unit cell coordinates for now,
00805         // eventually will multiply by inv tensor when applying the force
00806         
00807         // First set variables 'dk_{hi,lo}' (glob notation). The 'hi'
00808         // ('lo') variable in a given dimension is the number added (subtracted)
00809         // to go up (down) one grid point in that dimension; both are normally
00810         // just the corresponding 'dk[i]'. However, if we are sitting on a
00811         // boundary and we are using a continuous grid, then we want to map the
00812         // next point off the grid back around to the other side. e.g. point
00813         // (k[0], i1, k) maps to point (0, i1, k), which would be
00814         // accomplished by changing 'dk1_hi' to -(k[0]-1)*dk1.
00815         
00816         int d_hi[3] = {1, 1, 1};
00817         int d_lo[3] = {1, 1, 1};
00818         float voffs[3];
00819         float dscales[3] = {0.5, 0.5, 0.5};
00820         for (int i1 = 0; i1 < 3; i1++) {
00821             if (inds2[i1] == 0) {
00822                 if (cont[i1]) {
00823                     d_lo[i1] = -(k[i1]-1);
00824                     voffs[i1] = offset[i1];
00825                     dscales[i1] = 1.0/(1.0 + gap[i1]) * 1.0/gapscale[i1];
00826                 }
00827                 else zero_derivs = TRUE;
00828             }
00829             else if (inds2[i1] == k[i1]-1) {
00830                 if (cont[i1]) {
00831                     d_hi[i1] = -(k[i1]-1);
00832                     voffs[i1] = offset[i1];
00833                     dscales[i1] = 1.0/(1.0 + gap[i1]) * 1.0/gapscale[i1];
00834                 }
00835                 else zero_derivs = TRUE;
00836             }
00837             else {
00838                 voffs[i1] = 0.0;
00839             }
00840         }
00841         
00842 //      DebugM(2, "cont = " << cont[0] << " " << cont[1] << " " << cont[2] << "\n" << endi);
00843 //      DebugM(2, "zero_derivs = " << zero_derivs << "\n" << endi);
00844 //      DebugM(2, "d_hi = " << d_hi[0] << " " << d_hi[1] << " " << d_hi[2] << "\n" << endi);
00845 //      DebugM(2, "d_lo = " << d_lo[0] << " " << d_lo[1] << " " << d_lo[2] << "\n" << endi);
00846         DebugM(1, "dscales = " << dscales[0] << " " << dscales[1] << " " << dscales[2] << "\n" << endi);
00847         DebugM(1, "voffs = " << voffs[0] << " " << voffs[1] << " " << voffs[2] << "\n" << endi);
00848         
00849         // V
00850         b[i0] = get_grid(inds2[0],inds2[1],inds2[2]) + voff;
00851         
00852         if (zero_derivs) {
00853             DebugM(2, "zero_derivs\n" << endi);
00854             b[8+i0] = 0.0;
00855             b[16+i0] = 0.0;
00856             b[24+i0] = 0.0;
00857             b[32+i0] = 0.0;
00858             b[40+i0] = 0.0;
00859             b[48+i0] = 0.0;
00860             b[56+i0] = 0.0;
00861         } else {
00862             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
00863             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
00864             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
00865             b[32+i0] = dscales[0] * dscales[1]
00866                 * (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]) -
00867                    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
00868             b[40+i0] = dscales[0] * dscales[2]
00869                 * (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]) -
00870                    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
00871             b[48+i0] = dscales[1] * dscales[2]
00872                 * (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]) -
00873                    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
00874         
00875             b[56+i0] = dscales[0] * dscales[1] * dscales[2]                                     // d3V/dxdydz
00876                 * (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]) -
00877                    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]) +
00878                    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]) +
00879                    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]));
00880         }
00881         
00882         DebugM(1, "V = " << b[i0] << "\n");
00883         
00884         DebugM(1, "dV/dx = " << b[8+i0] << "\n");
00885         DebugM(1, "dV/dy = " << b[16+i0] << "\n");
00886         DebugM(1, "dV/dz = " << b[24+i0] << "\n");
00887         
00888         DebugM(1, "d2V/dxdy = " << b[32+i0] << "\n");
00889         DebugM(1, "d2V/dxdz = " << b[40+i0] << "\n");
00890         DebugM(1, "d2V/dydz = " << b[48+i0] << "\n");
00891         
00892         DebugM(1, "d3V/dxdydz = " << b[56+i0] << "\n" << endi);
00893     }
00894 }

int GridforceFullMainGrid::compute_VdV ( Position  pos,
float &  V,
Vector dV 
) const [inline]

Reimplemented from GridforceGrid.

Definition at line 216 of file GridForceGrid.h.

References GridforceFullBaseGrid::compute_VdV().

00216 { return GridforceFullBaseGrid::compute_VdV(pos, V, dV); };

long int GridforceFullMainGrid::get_all_gridvals ( float **  all_gridvals  )  const [protected, virtual]

Implements GridforceGrid.

Definition at line 718 of file GridForceGrid.C.

References DebugM, endi(), GridforceFullBaseGrid::grid, j, GridforceFullBaseGrid::size, subgrids_flat, and totalGrids.

00719 {
00720     // Creates a flat array of all grid values, including subgrids,
00721     // and puts it in the value pointed to by the 'grids'
00722     // argument. Returns the resulting array size. Caller is
00723     // responsible for destroying the array via 'delete[]'
00724     
00725     DebugM(4, "get_all_gridvals called\n" << endi);
00726     
00727     long int sz = 0;
00728     sz += size;
00729     for (int i = 0; i < totalGrids-1; i++) {
00730         sz += subgrids_flat[i]->size;
00731     }
00732     DebugM(4, "size = " << sz << "\n" << endi);
00733     
00734     float *grid_vals = new float[sz];
00735     long int idx = 0;
00736     for (long int i = 0; i < size; i++) {
00737         grid_vals[idx++] = grid[i];
00738     }
00739     for (int j = 0; j < totalGrids-1; j++) {
00740         for (long int i = 0; i < subgrids_flat[j]->size; i++) {
00741             grid_vals[idx++] = subgrids_flat[j]->grid[i];
00742         }
00743     }
00744     CmiAssert(idx == sz);
00745     
00746     *all_gridvals = grid_vals;
00747     
00748     DebugM(4, "get_all_gridvals finished\n" << endi);
00749     
00750     return sz;
00751 }

int GridforceFullMainGrid::get_border ( void   )  const [inline, virtual]

Implements GridforceFullBaseGrid.

Definition at line 214 of file GridForceGrid.h.

References border.

00214 { return border; }

Position GridforceFullMainGrid::get_center ( void   )  const [inline, virtual]

Implements GridforceGrid.

Definition at line 205 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_center().

Referenced by GridforceLiteGrid::initialize().

00205 { return GridforceFullBaseGrid::get_center(); };

Bool GridforceFullMainGrid::get_checksize ( void   )  const [inline, virtual]

Implements GridforceGrid.

Definition at line 210 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_checksize().

Tensor GridforceFullMainGrid::get_e ( void   )  const [inline, virtual]

Implements GridforceGrid.

Definition at line 207 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_e().

Referenced by GridforceLiteGrid::initialize().

00207 { return GridforceFullBaseGrid::get_e(); };

Tensor GridforceFullMainGrid::get_inv ( void   )  const [inline, virtual]

Implements GridforceGrid.

Definition at line 208 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_inv().

Referenced by GridforceLiteGrid::initialize().

00208 { return GridforceFullBaseGrid::get_inv(); };

int GridforceFullMainGrid::get_k0 ( void   )  const [inline, virtual]

Implements GridforceGrid.

Definition at line 211 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_k0().

Referenced by GridforceLiteGrid::initialize().

00211 { return GridforceFullBaseGrid::get_k0(); };

int GridforceFullMainGrid::get_k1 ( void   )  const [inline, virtual]

Implements GridforceGrid.

Definition at line 212 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_k1().

Referenced by GridforceLiteGrid::initialize().

00212 { return GridforceFullBaseGrid::get_k1(); };

int GridforceFullMainGrid::get_k2 ( void   )  const [inline, virtual]

Implements GridforceGrid.

Definition at line 213 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_k2().

Referenced by GridforceLiteGrid::initialize().

00213 { return GridforceFullBaseGrid::get_k2(); };

Position GridforceFullMainGrid::get_origin ( void   )  const [inline, virtual]

Implements GridforceGrid.

Definition at line 206 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_origin().

Referenced by GridforceLiteGrid::initialize().

00206 { return GridforceFullBaseGrid::get_origin(); };

Vector GridforceFullMainGrid::get_scale ( void   )  const [inline, virtual]

Implements GridforceGrid.

Definition at line 209 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_scale().

Referenced by GridforceLiteGrid::initialize().

00209 { return GridforceFullBaseGrid::get_scale(); };

int GridforceFullMainGrid::get_total_grids ( void   )  const [inline, virtual]

Implements GridforceGrid.

Definition at line 218 of file GridForceGrid.h.

References totalGrids.

Referenced by GridforceLiteGrid::initialize().

00218 { return totalGrids; }    

void GridforceFullMainGrid::initialize ( char *  potfilename,
SimParameters simParams,
MGridforceParams mgridParams 
) [inline, virtual]

Implements GridforceGrid.

Definition at line 200 of file GridForceGrid.h.

References default_border, initialize(), and simParams.

00200                                                                                                        {
00201         initialize(potfilename, simParams, mgridParams, default_border);
00202     }

void GridforceFullMainGrid::initialize ( char *  potfilename,
SimParameters simParams,
MGridforceParams mgridParams,
int  border 
)

Definition at line 426 of file GridForceGrid.C.

References border, buildSubgridsFlat(), GridforceFullBaseGrid::checksize, GridforceFullBaseGrid::cont, cross(), DebugM, default_border, GridforceFullBaseGrid::dk_nopad, GridforceFullBaseGrid::e, endi(), GridforceFullBaseGrid::factor, FALSE, filename, Fopen(), GridforceFullBaseGrid::gap, GridforceFullBaseGrid::gapinv, MGridforceParams::gridforceCheckSize, MGridforceParams::gridforceCont, MGridforceParams::gridforceScale, MGridforceParams::gridforceVOffset, MGridforceParams::gridforceVolts, GridforceFullBaseGrid::inv, GridforceFullBaseGrid::k_nopad, NAMD_die(), GridforceFullBaseGrid::numSubgrids, GridforceFullBaseGrid::offset, GridforceFullBaseGrid::poten_fp, GridforceFullBaseGrid::readHeader(), GridforceFullBaseGrid::readSubgridHierarchy(), GridforceFullBaseGrid::scale, simParams, GridforceFullBaseGrid::size_nopad, totalGrids, and TRUE.

Referenced by initialize(), GridforceLiteGrid::initialize(), and reinitialize().

00427 {
00428     if (brd >= 0) {
00429         border = brd;
00430     } else {
00431         border = default_border;
00432     }
00433     
00434     // FROM init1
00435     //FILE *poten = Fopen(potfilename, "r");
00436     poten_fp = Fopen(potfilename, "r");
00437     if (!poten_fp) {
00438         NAMD_die("Problem reading grid force potential file");
00439     }
00440     
00441     // save file name so that grid can be re-read via Tcl
00442     strcpy(filename, potfilename);
00443     
00444     // Read special comment fields and create subgrid objects
00445     totalGrids = 1;
00446     char line[256];
00447     Bool flag = FALSE;
00448     numSubgrids = 0;
00449     float version;
00450     long int poten_offset;
00451     do {
00452         poten_offset = ftell(poten_fp);
00453         fgets(line, 256, poten_fp);     // Read comment lines
00454         //flag = sscanf(line, "# maingrid subgrids count %d\n", &numSubgrids);
00455         flag = sscanf(line, "# namdnugrid version %f\n", &version);
00456     } while (line[0] == '#' && !flag);
00457     
00458     if (flag) {
00459         if (version != 1.0) {
00460             NAMD_die("Unsupported version of non-uniform grid file format!");
00461         }
00462         fscanf(poten_fp, "# namdnugrid maingrid subgrids count %d\n", &numSubgrids);
00463         readSubgridHierarchy(poten_fp, totalGrids);
00464         buildSubgridsFlat();
00465     } else {
00466         fseek(poten_fp, poten_offset, SEEK_SET);
00467     }
00468     
00469     // Read header
00470     readHeader(simParams, mgridParams);
00471     
00472     factor = 1.0;
00473     if (mgridParams->gridforceVolts)
00474     {
00475         factor /= 0.0434;  // convert V -> kcal/mol*e
00476     }
00477     scale = mgridParams->gridforceScale;
00478     checksize = mgridParams->gridforceCheckSize;
00479 
00480     // Allocate storage for potential and read it
00481     float *grid_nopad = new float[size_nopad];
00482     
00483     float tmp2;
00484     for (long int count = 0; count < size_nopad; count++) {
00485         int err = fscanf(poten_fp, "%f", &tmp2);
00486         if (err == EOF || err == 0) {
00487             NAMD_die("Grid force potential file incorrectly formatted");
00488         }
00489         grid_nopad[count] = tmp2 * factor;      // temporary, so just store flat
00490     }
00491     fscanf(poten_fp, "\n");
00492     
00493     // Shortcuts for accessing 1-D array with four indices
00494     dk_nopad[0] = k_nopad[1] * k_nopad[2];
00495     dk_nopad[1] = k_nopad[2];
00496     dk_nopad[2] = 1;
00497     
00498     Vector Kvec[3];
00499     Kvec[0] = e * Position(k_nopad[0]-1, 0, 0);
00500     Kvec[1] = e * Position(0, k_nopad[1]-1, 0);
00501     Kvec[2] = e * Position(0, 0, k_nopad[2]-1);
00502     Vector Avec[3];
00503     Avec[0] = simParams->lattice.a();
00504     Avec[1] = simParams->lattice.b();
00505     Avec[2] = simParams->lattice.c();
00506     
00507     // Decide whether we're wrapping
00508     for (int i0 = 0; i0 < 3; i0++) {
00509         if (mgridParams->gridforceCont[i0])
00510         {
00511             Bool found = FALSE;
00512             for (int i1 = 0; i1 < 3; i1++) {
00513                 if (cross(Avec[i0].unit(), Kvec[i1].unit()).length() < 1e-4) {
00514                     found = TRUE;
00515                     cont[i1] = TRUE;
00516                     offset[i1] = mgridParams->gridforceVOffset[i0] * factor;
00517                     // want in grid-point units (normal = 1)
00518                     gap[i1] = (inv * (Avec[i0] - Kvec[i1])).length();   
00519                     gapinv[i1] = 1.0/gap[i1];
00520                     
00521                     if (gap[i1] < 0) {
00522                         NAMD_die("Gridforce Grid overlap!");
00523                     }
00524                     
00525                     DebugM(4, "cont[" << i1 << "] = " << cont[i1] << "\n");
00526                     DebugM(4, "gap[" << i1 << "] = " << gap[i1] << "\n");
00527                     DebugM(4, "gapinv[" << i1 << "] = " << gapinv[i1] << "\n" << endi);
00528                 }
00529             }
00530             
00531             if (!found) {
00532                 NAMD_die("No Gridforce unit vector found parallel to requested continuous grid direction!");
00533             }
00534         } else {
00535             // check for grid overlap in non-wrapping dimensions
00536             // occurs below
00537         }
00538     }
00539     
00540     // Figure out size of true grid (padded on non-periodic sides)
00541     Vector delta = 0;
00542     for (int i = 0; i < 3; i++) {
00543         if (cont[i]) {
00544             k[i] = k_nopad[i];
00545         } else {
00546             k[i] = k_nopad[i] + 2*border;
00547             delta[i] -= border;
00548         }
00549     }
00550     DebugM(4, "delta = " << e * delta << " (" << delta << ")\n" << endi);
00551     origin += e * delta;
00552     
00553     // Check for grid overlap
00554     if (!fits_lattice(simParams->lattice)) {
00555       char errmsg[512];
00556       if (checksize) {
00557         sprintf(errmsg, "Warning: Periodic cell basis too small for Gridforce grid %d.  Set gridforcechecksize off in configuration file to ignore.\n", mygridnum);
00558         NAMD_die(errmsg);      
00559       }
00560     }
00561     
00562     size = k[0] * k[1] * k[2];
00563     dk[0] = k[1] * k[2];
00564     dk[1] = k[2];
00565     dk[2] = 1;
00566     
00567     DebugM(3, "size = " << size << ", size_nopad = " << size_nopad << "\n" << endi);
00568     
00569     delete[] grid;
00570     grid = new float[size];
00571     
00572     n_sum[0] = n_sum[1] = n_sum[2] = 0;
00573     p_sum[0] = p_sum[1] = p_sum[2] = 0;
00574     for (int i0 = 0; i0 < k_nopad[0]; i0++) {
00575         for (int i1 = 0; i1 < k_nopad[1]; i1++) {
00576             for (int i2 = 0; i2 < k_nopad[2]; i2++) {
00577                 // Edges are special cases -- take force there to be
00578                 // zero for smooth transition across potential
00579                 // boundary
00580                 
00581                 long int ind_nopad = i0*dk_nopad[0] + i1*dk_nopad[1] + i2*dk_nopad[2];
00582                 int j0 = (cont[0]) ? i0 : i0 + border;
00583                 int j1 = (cont[1]) ? i1 : i1 + border;
00584                 int j2 = (cont[2]) ? i2 : i2 + border;
00585                 long int ind = j0*dk[0] + j1*dk[1] + j2*dk[2];
00586                 
00587                 if (i0 == 0)                    n_sum[0] += grid_nopad[ind_nopad];
00588                 else if (i0 == k_nopad[0]-1)    p_sum[0] += grid_nopad[ind_nopad];
00589                 if (i1 == 0)                    n_sum[1] += grid_nopad[ind_nopad];
00590                 else if (i1 == k_nopad[1]-1)    p_sum[1] += grid_nopad[ind_nopad];
00591                 if (i2 == 0)                    n_sum[2] += grid_nopad[ind_nopad];
00592                 else if (i2 == k_nopad[2]-1)    p_sum[2] += grid_nopad[ind_nopad];
00593                 
00594                 //grid[ind] = grid_nopad[ind_nopad];
00595                 set_grid(j0, j1, j2, grid_nopad[ind_nopad]);
00596             }
00597         }
00598     }
00599     
00600     const BigReal modThresh = 1.0;
00601     
00602     BigReal n_avg[3], p_avg[3];
00603     int i0;
00604     for (int i0 = 0; i0 < 3; i0++) {
00605         int i1 = (i0 + 1) % 3;
00606         int i2 = (i0 + 2) % 3;
00607         n_avg[i0] = n_sum[i0] / (k_nopad[i1] * k_nopad[i2]);
00608         p_avg[i0] = p_sum[i0] / (k_nopad[i1] * k_nopad[i2]);
00609         
00610         if (cont[i0] && fabs(offset[i0] - (p_avg[i0]-n_avg[i0])) > modThresh) 
00611         {
00612             iout << iWARN << "GRID FORCE POTENTIAL DIFFERENCE IN K" << i0
00613                  << " DIRECTION IS " 
00614                  << offset[i0] - (p_avg[i0]-n_avg[i0]) 
00615                  << " KCAL/MOL*E\n" << endi;
00616         }
00617     }
00618     
00619     Bool twoPadVals = (cont[0] + cont[1] + cont[2] == 2);
00620     double padVal = 0.0;
00621     long int weight = 0;
00622     if (!twoPadVals) {
00623         // Determine pad value (must average)
00624         if (!cont[0]) {
00625             padVal += p_sum[0] + n_sum[0];
00626             weight += 2 * k_nopad[1] * k_nopad[2];
00627         }
00628         if (!cont[1]) {
00629             padVal += p_sum[1] + n_sum[1];
00630             weight += 2 * k_nopad[0] * k_nopad[2];
00631         }
00632         if (!cont[2]) {
00633             padVal += p_sum[2] + n_sum[2];
00634             weight += 2 * k_nopad[0] * k_nopad[1];
00635         }
00636         padVal /= weight;
00637     }
00638     
00639     for (int i = 0; i < 3; i++) {
00640         pad_n[i] = (cont[i]) ? 0.0 : (twoPadVals) ? n_avg[i] : padVal;
00641         pad_p[i] = (cont[i]) ? 0.0 : (twoPadVals) ? p_avg[i] : padVal;
00642         DebugM(4, "pad_n[" << i << "] = " << pad_n[i] << "\n");
00643         DebugM(4, "pad_p[" << i << "] = " << pad_p[i] << "\n" << endi);
00644     }
00645     
00646     if (cont[0] && cont[1] && cont[2]) {
00647         // Nothing to do
00648         return;
00649     }
00650     
00651     // Now fill in rest of new grid
00652     for (int i0 = 0; i0 < k[0]; i0++) {
00653         for (int i1 = 0; i1 < k[1]; i1++) {
00654             for (int i2 = 0; i2 < k[2]; i2++) {
00655                 if ( (cont[0] || (i0 >= border && i0 < k[0]-border)) 
00656                      && (cont[1] || (i1 >= border && i1 < k[1]-border)) 
00657                      && (cont[2] || i2 == border) )
00658                 {
00659                     i2 += k_nopad[2]-1;
00660                     continue;
00661                 }
00662                 
00663                 long int ind = i0*dk[0] + i1*dk[1] + i2*dk[2];
00664 
00665                 Position pos = e * Position(i0, i1, i2);
00666                 int var[3] = {i0, i1, i2};
00667                 
00668                 for (int dir = 0; dir < 3; dir++) {
00669                     if (cont[dir]) 
00670                         continue;
00671                     
00672                     if (var[dir] < border) {
00673                         //grid[ind] = pad_n[dir];
00674                         set_grid(i0, i1, i2, pad_n[dir]);
00675                     } else if (var[dir] >= k[dir]-border) {
00676                         //grid[ind] = pad_p[dir];
00677                         set_grid(i0, i1, i2, pad_p[dir]);
00678                     }
00679                 }
00680                 
00681 //              DebugM(2, "grid[" << ind << "; " << i0 << ", " << i1
00682 //                     << ", " << i2 << "] = " << get_grid(ind)
00683 //                     << "\n" << endi);
00684             }
00685         }
00686     }
00687     
00688     for (int i0 = 0; i0 < k[0]; i0++) {
00689         for (int i1 = 0; i1 < k[1]; i1++) {
00690             for (int i2 = 0; i2 < k[2]; i2++) {
00691                 DebugM(1, "grid[" << i0 << ", " << i1 << ", " << i2 << "] = " << get_grid(i0,i1,i2) << "\n" << endi);
00692             }
00693         }
00694     }
00695     
00696     // Clean up
00697     DebugM(3, "clean up\n" << endi);
00698     delete[] grid_nopad;
00699     
00700     // Call initialize for each subgrid
00701     for (int i = 0; i < numSubgrids; i++) {
00702         subgrids[i]->poten_fp = poten_fp;
00703         subgrids[i]->initialize(simParams, mgridParams);
00704     }
00705     
00706     // close file pointer
00707     fclose(poten_fp);
00708 }

void GridforceFullMainGrid::pack ( MOStream msg  )  const [protected, virtual]

Implements GridforceGrid.

Definition at line 369 of file GridForceGrid.C.

References DebugM, endi(), filename, GridforceGrid::mygridnum, GridforceFullBaseGrid::pack(), MOStream::put(), and totalGrids.

00370 {
00371     DebugM(4, "Packing maingrid\n" << endi);
00372     
00373 //     msg->put(3*sizeof(float), (char*)pad_p);
00374 //     msg->put(3*sizeof(float), (char*)pad_n);
00375     msg->put(totalGrids);
00376     msg->put(mygridnum);
00377     msg->put(129*sizeof(char), (char*)filename);
00378     
00379     DebugM(3, "calling GridforceFullBaseGrid::pack\n" << endi);
00380     
00381     GridforceFullBaseGrid::pack(msg);
00382 }

void GridforceFullMainGrid::reinitialize ( SimParameters simParams,
MGridforceParams mgridParams 
) [virtual]

Implements GridforceGrid.

Definition at line 711 of file GridForceGrid.C.

References DebugM, endi(), filename, initialize(), and simParams.

00712 {
00713     DebugM(4, "reinitializing grid\n" << endi);
00714     initialize(filename, simParams, mgridParams);
00715 }

void GridforceFullMainGrid::set_all_gridvals ( float *  all_gridvals,
long int  sz 
) [protected, virtual]

Implements GridforceGrid.

Definition at line 754 of file GridForceGrid.C.

References DebugM, endi(), GridforceFullBaseGrid::grid, j, GridforceFullBaseGrid::size, subgrids_flat, and totalGrids.

00755 {
00756     DebugM(4, "set_all_gridvals called\n" << endi);
00757     
00758     long int sz_calc = 0;
00759     sz_calc += size;
00760     for (int i = 0; i < totalGrids-1; i++) {
00761         sz_calc += subgrids_flat[i]->size;
00762     }
00763     CmiAssert(sz == sz_calc);
00764     
00765     long int idx = 0;
00766     for (long int i = 0; i < size; i++) {
00767         DebugM(1, "all_gridvals[" << idx << "] = " << all_gridvals[idx] << "\n" << endi);
00768         grid[i] = all_gridvals[idx++];
00769     }
00770     for (int j = 0; j < totalGrids-1; j++) {
00771         for (long int i = 0; i < subgrids_flat[j]->size; i++) {
00772             DebugM(1, "all_gridvals[" << idx << "] = " << all_gridvals[idx] << "\n" << endi);
00773             subgrids_flat[j]->grid[i] = all_gridvals[idx++];
00774         }
00775     }
00776     CmiAssert(idx == sz);
00777 
00778     DebugM(4, "set_all_gridvals finished\n" << endi);
00779 }

void GridforceFullMainGrid::set_scale ( Vector  s  )  [inline, virtual]

Implements GridforceGrid.

Definition at line 219 of file GridForceGrid.h.

References GridforceFullBaseGrid::scale.

00219 { scale = s; }

void GridforceFullMainGrid::unpack ( MIStream msg  )  [protected, virtual]

Implements GridforceGrid.

Definition at line 385 of file GridForceGrid.C.

References buildSubgridsFlat(), DebugM, endi(), filename, GridforceFullBaseGrid::gapinv, GridforceFullBaseGrid::generation, MIStream::get(), GridforceGrid::mygridnum, GridforceFullBaseGrid::numSubgrids, GridforceFullBaseGrid::size, totalGrids, and GridforceFullBaseGrid::unpack().

00386 {
00387     DebugM(4, "Unpacking maingrid\n" << endi);
00388     
00389 //     msg->get(3*sizeof(float), (char*)pad_p);
00390 //     msg->get(3*sizeof(float), (char*)pad_n);
00391     msg->get(totalGrids);
00392     msg->get(mygridnum);
00393     msg->get(129*sizeof(char), (char*)filename);
00394     
00395     GridforceFullBaseGrid::unpack(msg);
00396     
00397     DebugM(4, "size  = " << size << "\n");
00398     DebugM(4, "numSubgrids = " << numSubgrids << "\n");
00399     DebugM(4, "gapinv = " << gapinv[0] << " " << gapinv[2] << " " << gapinv[2] << " " << "\n");
00400     DebugM(4, "generation = " << generation << "\n" << endi);
00401     DebugM(4, "filename = " << filename << "\n" << endi);
00402     
00403     buildSubgridsFlat();
00404 }


Friends And Related Function Documentation

friend class GridforceFullBaseGrid [friend]

Definition at line 192 of file GridForceGrid.h.

friend class GridforceFullSubGrid [friend]

Reimplemented from GridforceFullBaseGrid.

Definition at line 193 of file GridForceGrid.h.


Member Data Documentation

int GridforceFullMainGrid::border [protected]

Definition at line 238 of file GridForceGrid.h.

Referenced by get_border(), and initialize().

const int GridforceFullMainGrid::default_border = 1 [static, protected]

Definition at line 237 of file GridForceGrid.h.

Referenced by initialize().

char GridforceFullMainGrid::filename[129] [protected]

Definition at line 232 of file GridForceGrid.h.

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

GridforceFullSubGrid** GridforceFullMainGrid::subgrids_flat [protected]

Definition at line 234 of file GridForceGrid.h.

Referenced by GridforceFullSubGrid::addToSubgridsFlat(), buildSubgridsFlat(), get_all_gridvals(), GridforceFullMainGrid(), set_all_gridvals(), and ~GridforceFullMainGrid().

int GridforceFullMainGrid::totalGrids [protected]

Definition at line 233 of file GridForceGrid.h.

Referenced by buildSubgridsFlat(), get_all_gridvals(), get_total_grids(), initialize(), pack(), set_all_gridvals(), and unpack().


The documentation for this class was generated from the following files:
Generated on Thu Nov 23 01:17:18 2017 for NAMD by  doxygen 1.4.7