Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

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
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

Protected Member Functions

void pack (MOStream *msg) const
void unpack (MIStream *msg)
int get_all_gridvals (float **all_gridvals) const
void set_all_gridvals (float *all_gridvals, 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

const int default_border = 1

Friends

class GridforceFullBaseGrid
class GridforceFullSubGrid

Constructor & Destructor Documentation

GridforceFullMainGrid::GridforceFullMainGrid int  gridnum  )  [explicit]
 

Definition at line 344 of file GridForceGrid.C.

References subgrids_flat.

00345 {
00346     mygridnum = gridnum;
00347     generation = 0;
00348     subgrids_flat = NULL;
00349     type = GridforceGridTypeFull;
00350 }

GridforceFullMainGrid::~GridforceFullMainGrid  )  [virtual]
 

Definition at line 353 of file GridForceGrid.C.

00354 {
00355     delete[] subgrids_flat;
00356 }


Member Function Documentation

void GridforceFullMainGrid::buildSubgridsFlat void   )  [protected]
 

Definition at line 397 of file GridForceGrid.C.

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

Referenced by initialize(), and unpack().

00398 {
00399     DebugM(4, "buildSubgridsFlat() called, totalGrids-1 = " << totalGrids-1 << "\n" << endi);
00400     delete[] subgrids_flat;
00401     subgrids_flat = new GridforceFullSubGrid *[totalGrids-1];
00402     for (int i = 0; i < numSubgrids; i++) {
00403         DebugM(3, "adding to subgridsFlat\n" << endi);
00404         subgrids[i]->addToSubgridsFlat();
00405         DebugM(3, "success!\n" << endi);
00406     }
00407     for (int i = 0; i < totalGrids-1; i++) {
00408         DebugM(4, "subgrids_flat[" << i << "]->numSubgrids = " << subgrids_flat[i]->numSubgrids << "\n" << endi);
00409     }
00410     for (int i = 0; i < numSubgrids; i++) {
00411         DebugM(4, "subgrids[" << i << "]->numSubgrids = " << subgrids[i]->numSubgrids << "\n" << endi);
00412     }
00413 }

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

Implements GridforceFullBaseGrid.

Definition at line 769 of file GridForceGrid.C.

References DebugM, endi(), GridforceFullBaseGrid::get_grid(), and GridforceFullBaseGrid::get_grid_d().

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

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

Reimplemented from GridforceGrid.

Definition at line 207 of file GridForceGrid.h.

References GridforceFullBaseGrid::compute_VdV(), and Position.

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

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

Implements GridforceGrid.

Definition at line 705 of file GridForceGrid.C.

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

00706 {
00707     // Creates a flat array of all grid values, including subgrids,
00708     // and puts it in the value pointed to by the 'grids'
00709     // argument. Returns the resulting array size. Caller is
00710     // responsible for destroying the array via 'delete[]'
00711     
00712     DebugM(4, "get_all_gridvals called\n" << endi);
00713     
00714     int sz = 0;
00715     sz += size;
00716     for (int i = 0; i < totalGrids-1; i++) {
00717         sz += subgrids_flat[i]->size;
00718     }
00719     DebugM(4, "size = " << sz << "\n" << endi);
00720     
00721     float *grid_vals = new float[sz];
00722     int idx = 0;
00723     for (int i = 0; i < size; i++) {
00724         grid_vals[idx++] = grid[i];
00725     }
00726     for (int j = 0; j < totalGrids-1; j++) {
00727         for (int i = 0; i < subgrids_flat[j]->size; i++) {
00728             grid_vals[idx++] = subgrids_flat[j]->grid[i];
00729         }
00730     }
00731     CmiAssert(idx == sz);
00732     
00733     *all_gridvals = grid_vals;
00734     
00735     DebugM(4, "get_all_gridvals finished\n" << endi);
00736     
00737     return sz;
00738 }

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

Implements GridforceFullBaseGrid.

Definition at line 205 of file GridForceGrid.h.

00205 { return border; }

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

Implements GridforceGrid.

Definition at line 197 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_center(), and Position.

Referenced by GridforceLiteGrid::initialize().

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

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

Implements GridforceGrid.

Definition at line 199 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_e().

Referenced by GridforceLiteGrid::initialize().

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

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

Implements GridforceGrid.

Definition at line 200 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_inv().

Referenced by GridforceLiteGrid::initialize().

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

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

Implements GridforceGrid.

Definition at line 202 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_k0().

Referenced by GridforceLiteGrid::initialize().

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

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

Implements GridforceGrid.

Definition at line 203 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_k1().

Referenced by GridforceLiteGrid::initialize().

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

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

Implements GridforceGrid.

Definition at line 204 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_k2().

Referenced by GridforceLiteGrid::initialize().

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

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

Implements GridforceGrid.

Definition at line 198 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_origin(), and Position.

Referenced by GridforceLiteGrid::initialize().

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

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

Implements GridforceGrid.

Definition at line 201 of file GridForceGrid.h.

References GridforceFullBaseGrid::get_scale().

Referenced by GridforceLiteGrid::initialize().

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

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

Implements GridforceGrid.

Definition at line 209 of file GridForceGrid.h.

Referenced by GridforceLiteGrid::initialize().

00209 { return totalGrids; }

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

Implements GridforceGrid.

Definition at line 192 of file GridForceGrid.h.

References default_border, initialize(), and simParams.

00192                                                                                                        {
00193         initialize(potfilename, simParams, mgridParams, default_border);
00194     }

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

Definition at line 416 of file GridForceGrid.C.

References Lattice::a(), Lattice::b(), BigReal, Bool, border, buildSubgridsFlat(), Lattice::c(), DebugM, endi(), filename, GridforceGrid::fits_lattice(), Fopen(), GridforceFullBaseGrid::get_grid(), MGridforceParams::gridforceCont, MGridforceParams::gridforceScale, MGridforceParams::gridforceVOffset, MGridforceParams::gridforceVolts, GridforceFullSubGrid::initialize(), iout, iWARN(), SimParameters::lattice, Vector::length(), NAMD_die(), Position, GridforceFullBaseGrid::poten_fp, GridforceFullBaseGrid::readHeader(), GridforceFullBaseGrid::readSubgridHierarchy(), GridforceFullBaseGrid::set_grid(), simParams, and totalGrids.

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

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

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

Implements GridforceGrid.

Definition at line 359 of file GridForceGrid.C.

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

00360 {
00361     DebugM(4, "Packing maingrid\n" << endi);
00362     
00363 //     msg->put(3*sizeof(float), (char*)pad_p);
00364 //     msg->put(3*sizeof(float), (char*)pad_n);
00365     msg->put(totalGrids);
00366     msg->put(mygridnum);
00367     msg->put(129*sizeof(char), (char*)filename);
00368     
00369     DebugM(3, "calling GridforceFullBaseGrid::pack\n" << endi);
00370     
00371     GridforceFullBaseGrid::pack(msg);
00372 }

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

Implements GridforceGrid.

Definition at line 698 of file GridForceGrid.C.

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

00699 {
00700     DebugM(4, "reinitializing grid\n" << endi);
00701     initialize(filename, simParams, mgridParams);
00702 }

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

Implements GridforceGrid.

Definition at line 741 of file GridForceGrid.C.

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

00742 {
00743     DebugM(4, "set_all_gridvals called\n" << endi);
00744     
00745     int sz_calc = 0;
00746     sz_calc += size;
00747     for (int i = 0; i < totalGrids-1; i++) {
00748         sz_calc += subgrids_flat[i]->size;
00749     }
00750     CmiAssert(sz == sz_calc);
00751     
00752     int idx = 0;
00753     for (int i = 0; i < size; i++) {
00754         DebugM(1, "all_gridvals[" << idx << "] = " << all_gridvals[idx] << "\n" << endi);
00755         grid[i] = all_gridvals[idx++];
00756     }
00757     for (int j = 0; j < totalGrids-1; j++) {
00758         for (int i = 0; i < subgrids_flat[j]->size; i++) {
00759             DebugM(1, "all_gridvals[" << idx << "] = " << all_gridvals[idx] << "\n" << endi);
00760             subgrids_flat[j]->grid[i] = all_gridvals[idx++];
00761         }
00762     }
00763     CmiAssert(idx == sz);
00764 
00765     DebugM(4, "set_all_gridvals finished\n" << endi);
00766 }

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

Implements GridforceGrid.

Definition at line 375 of file GridForceGrid.C.

References buildSubgridsFlat(), DebugM, endi(), filename, MIStream::get(), totalGrids, and GridforceFullBaseGrid::unpack().

00376 {
00377     DebugM(4, "Unpacking maingrid\n" << endi);
00378     
00379 //     msg->get(3*sizeof(float), (char*)pad_p);
00380 //     msg->get(3*sizeof(float), (char*)pad_n);
00381     msg->get(totalGrids);
00382     msg->get(mygridnum);
00383     msg->get(129*sizeof(char), (char*)filename);
00384     
00385     GridforceFullBaseGrid::unpack(msg);
00386     
00387     DebugM(4, "size  = " << size << "\n");
00388     DebugM(4, "numSubgrids = " << numSubgrids << "\n");
00389     DebugM(4, "gapinv = " << gapinv[0] << " " << gapinv[2] << " " << gapinv[2] << " " << "\n");
00390     DebugM(4, "generation = " << generation << "\n" << endi);
00391     DebugM(4, "filename = " << filename << "\n" << endi);
00392     
00393     buildSubgridsFlat();
00394 }


Friends And Related Function Documentation

friend class GridforceFullBaseGrid [friend]
 

Definition at line 184 of file GridForceGrid.h.

friend class GridforceFullSubGrid [friend]
 

Reimplemented from GridforceFullBaseGrid.

Definition at line 185 of file GridForceGrid.h.


Member Data Documentation

int GridforceFullMainGrid::border [protected]
 

Definition at line 228 of file GridForceGrid.h.

Referenced by initialize().

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

Definition at line 227 of file GridForceGrid.h.

Referenced by initialize().

char GridforceFullMainGrid::filename[129] [protected]
 

Definition at line 222 of file GridForceGrid.h.

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

GridforceFullSubGrid** GridforceFullMainGrid::subgrids_flat [protected]
 

Definition at line 224 of file GridForceGrid.h.

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

int GridforceFullMainGrid::totalGrids [protected]
 

Definition at line 223 of file GridForceGrid.h.

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


The documentation for this class was generated from the following files:
Generated on Fri May 25 04:07:22 2012 for NAMD by  doxygen 1.3.9.1