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

GridForceGrid.inl

Go to the documentation of this file.
00001 
00007 #ifndef GRIDFORCEGRID_INL
00008 #define GRIDFORCEGRID_INL
00009 
00010 #include "GridForceGrid.h"
00011 
00012 inline int GridforceFullBaseGrid::compute_VdV(Position pos, float &V, Vector &dV) const
00013 {
00014     //SimParameters *simParams = Node::Object()->simParameters;
00015     int inds[3];
00016     Vector g, dg;
00017     Vector gapscale = Vector(1, 1, 1);
00018     
00019     int err = get_inds(pos, inds, dg, gapscale);
00020     if (err) {
00021         return -1;
00022     }
00023     
00024     DebugM(1, "gapscale = " << gapscale << "\n");
00025     DebugM(1, "dg = " << dg << "\n");
00026     DebugM(1, "ind + dg = " << inds[0]+dg[0] << " " << inds[1]+dg[1] << " " << inds[2]+dg[2] << "\n");
00027     DebugM(3, "compute_VdV: generation = " << generation << "\n" << endi);
00028     
00029     // Pass to subgrid if one exists here
00030     for (int i = 0; i < numSubgrids; i++) {
00031         if (((inds[0] >= subgrids[i]->pmin[0] && inds[0] <= subgrids[i]->pmax[0]) || subgrids[i]->cont[0]) &&
00032             ((inds[1] >= subgrids[i]->pmin[1] && inds[1] <= subgrids[i]->pmax[1]) || subgrids[i]->cont[1]) &&
00033             ((inds[2] >= subgrids[i]->pmin[2] && inds[2] <= subgrids[i]->pmax[2]) || subgrids[i]->cont[2]))
00034         {
00035             return subgrids[i]->compute_VdV(pos, V, dV);
00036         }
00037     }
00038     
00039     // Compute b
00040     float b[64];        // Matrix of values at 8 box corners
00041     compute_b(b, inds, gapscale);
00042     for (int j = 0; j < 64; j++) DebugM(1, "b[" << j << "] = " << b[j] << "\n" << endi);
00043     
00044     // Compute a
00045     float a[64];
00046     compute_a(a, b);
00047     for (int j = 0; j < 64; j++) DebugM(1, "a[" << j << "] = " << a[j] << "\n" << endi);
00048             
00049     // Calculate powers of x, y, z for later use
00050     // e.g. x[2] = x^2
00051     float x[4], y[4], z[4];
00052     x[0] = 1; y[0] = 1; z[0] = 1;
00053     for (int j = 1; j < 4; j++) {
00054         x[j] = x[j-1] * dg.x;
00055         y[j] = y[j-1] * dg.y;
00056         z[j] = z[j-1] * dg.z;
00057     }
00058     
00059     V = compute_V(a, x, y, z);
00060     dV = Tensor::diagonal(gapscale) * (compute_dV(a, x, y, z) * inv);
00061     
00062     return 0;
00063 }
00064 
00065 
00066 inline int GridforceLiteGrid::compute_VdV(Position pos, float &V, Vector &dV) const
00067 {
00068     int inds[3];
00069     Vector g, dg;
00070     
00071     int err = get_inds(pos, inds, dg);
00072     if (err) {
00073         return -1;
00074     }
00075     
00076     float wts[8];
00077     float results[4];
00078     
00079     compute_wts(wts, dg);
00080     for (int i = 0; i < 4; i++) {
00081         results[i] = linear_interpolate(inds[0], inds[1], inds[2], i, wts);
00082     }
00083     
00084     V = results[0];
00085     dV = Vector(results[1], results[2], results[3]) * inv;
00086     
00087     return 0;
00088 }
00089 
00090 
00091 inline int GridforceFullBaseGrid::get_inds(Position pos, int *inds, Vector &dg, Vector &gapscale) const
00092 {
00093     Vector p = pos - origin;
00094     Vector g;
00095     
00096     g = inv * p;
00097     
00098     for (int i = 0; i < 3; i++) {
00099         inds[i] = (int)floor(g[i]);
00100         dg[i] = g[i] - inds[i];
00101     }
00102     
00103     for (int i = 0; i < 3; i++) {
00104         if (inds[i] < 0 || inds[i] >= k[i]-1) {
00105             if (cont[i]) inds[i] = k[i]-1;
00106             else return -1;     // Outside potential and grid is not continuous
00107         }
00108         if (cont[i] && inds[i] == k[i]-1) {
00109             // Correct for non-unit spacing between continuous grid images
00110             gapscale[i] *= gapinv[i];
00111             if (g[i] < 0.0) dg[i] = 1.0 + g[i]*gapinv[i]; // = (gap[i] + g[i]) * gapinv[i]
00112             else dg[i] = (g[i] - inds[i]) * gapinv[i];
00113         }
00114     }
00115     
00116     return 0;
00117 }
00118 
00119 
00120 inline float GridforceFullBaseGrid::compute_V(float *a, float *x, float *y, float *z) const
00121 {
00122     float V = 0.0;
00123     int ind = 0;
00124     for (int l = 0; l < 4; l++) {
00125         for (int k = 0; k < 4; k++) {
00126             for (int j = 0; j < 4; j++) {
00127                 V += a[ind] * x[j] * y[k] * z[l];
00128                 ind++;
00129             }
00130         }
00131     }
00132     return V;
00133 }
00134 
00135 
00136 inline Vector GridforceFullBaseGrid::compute_dV(float *a, float *x, float *y, float *z) const
00137 {
00138     Vector dV = 0;
00139     int ind = 0;
00140     for (int l = 0; l < 4; l++) {
00141         for (int k = 0; k < 4; k++) {
00142             for (int j = 0; j < 4; j++) {
00143                 if (j > 0) dV.x += a[ind] * j * x[j-1] * y[k]   * z[l];         // dV/dx
00144                 if (k > 0) dV.y += a[ind] * k * x[j]   * y[k-1] * z[l];         // dV/dy
00145                 if (l > 0) dV.z += a[ind] * l * x[j]   * y[k]   * z[l-1];       // dV/dz
00146                 ind++;
00147             }
00148         }
00149     }
00150     return dV;
00151 }
00152 
00153 
00154 inline Vector GridforceFullBaseGrid::compute_d2V(float *a, float *x, float *y, float *z) const
00155 {
00156     Vector d2V = 0;
00157     int ind = 0;
00158     for (int l = 0; l < 4; l++) {
00159         for (int k = 0; k < 4; k++) {
00160             for (int j = 0; j < 4; j++) {
00161                 if (j > 0 && k > 0) d2V.x += a[ind] * j * k * x[j-1] * y[k-1] * z[l];   // d2V/dxdy
00162                 if (j > 0 && l > 0) d2V.y += a[ind] * j * l * x[j-1] * y[k]   * z[l-1]; // d2V/dxdz
00163                 if (k > 0 && l > 0) d2V.z += a[ind] * k * l * x[j]   * y[k-1] * z[l-1]; // d2V/dydz
00164                 ind++;
00165             }
00166         }
00167     }
00168     return d2V;
00169 }
00170 
00171 
00172 inline float GridforceFullBaseGrid::compute_d3V(float *a, float *x, float *y, float *z) const
00173 {
00174     float d3V = 0.0;
00175     int ind = 0;
00176     for (int l = 0; l < 4; l++) {
00177         for (int k = 0; k < 4; k++) {
00178             for (int j = 0; j < 4; j++) {
00179                 if (j > 0 && k > 0 && l > 0) d3V += a[ind] * j * k * l * x[j-1] * y[k-1] * z[l-1];      // d3V/dxdydz
00180                 ind++;
00181             }
00182         }
00183     }
00184     return d3V;
00185 }
00186 
00187 
00188 inline void GridforceFullBaseGrid::compute_a(float *a, float *b) const
00189 {
00190     // Static sparse 64x64 matrix times vector ... nicer looking way than this?
00191     a[0] = b[0];
00192     a[1] = b[8];
00193     a[2] = -3*b[0] + 3*b[1] - 2*b[8] - b[9];
00194     a[3] = 2*b[0] - 2*b[1] + b[8] + b[9];
00195     a[4] = b[16];
00196     a[5] = b[32];
00197     a[6] = -3*b[16] + 3*b[17] - 2*b[32] - b[33];
00198     a[7] = 2*b[16] - 2*b[17] + b[32] + b[33];
00199     a[8] = -3*b[0] + 3*b[2] - 2*b[16] - b[18];
00200     a[9] = -3*b[8] + 3*b[10] - 2*b[32] - b[34];
00201     a[10] = 9*b[0] - 9*b[1] - 9*b[2] + 9*b[3] + 6*b[8] + 3*b[9] - 6*b[10] - 3*b[11]
00202         + 6*b[16] - 6*b[17] + 3*b[18] - 3*b[19] + 4*b[32] + 2*b[33] + 2*b[34] + b[35];
00203     a[11] = -6*b[0] + 6*b[1] + 6*b[2] - 6*b[3] - 3*b[8] - 3*b[9] + 3*b[10] + 3*b[11]
00204         - 4*b[16] + 4*b[17] - 2*b[18] + 2*b[19] - 2*b[32] - 2*b[33] - b[34] - b[35];
00205     a[12] = 2*b[0] - 2*b[2] + b[16] + b[18];
00206     a[13] = 2*b[8] - 2*b[10] + b[32] + b[34];
00207     a[14] = -6*b[0] + 6*b[1] + 6*b[2] - 6*b[3] - 4*b[8] - 2*b[9] + 4*b[10] + 2*b[11]
00208         - 3*b[16] + 3*b[17] - 3*b[18] + 3*b[19] - 2*b[32] - b[33] - 2*b[34] - b[35];
00209     a[15] = 4*b[0] - 4*b[1] - 4*b[2] + 4*b[3] + 2*b[8] + 2*b[9] - 2*b[10] - 2*b[11]
00210         + 2*b[16] - 2*b[17] + 2*b[18] - 2*b[19] + b[32] + b[33] + b[34] + b[35];
00211     a[16] = b[24];
00212     a[17] = b[40];
00213     a[18] = -3*b[24] + 3*b[25] - 2*b[40] - b[41];
00214     a[19] = 2*b[24] - 2*b[25] + b[40] + b[41];
00215     a[20] = b[48];
00216     a[21] = b[56];
00217     a[22] = -3*b[48] + 3*b[49] - 2*b[56] - b[57];
00218     a[23] = 2*b[48] - 2*b[49] + b[56] + b[57];
00219     a[24] = -3*b[24] + 3*b[26] - 2*b[48] - b[50];
00220     a[25] = -3*b[40] + 3*b[42] - 2*b[56] - b[58];
00221     a[26] = 9*b[24] - 9*b[25] - 9*b[26] + 9*b[27] + 6*b[40] + 3*b[41] - 6*b[42] - 3*b[43]
00222         + 6*b[48] - 6*b[49] + 3*b[50] - 3*b[51] + 4*b[56] + 2*b[57] + 2*b[58] + b[59];
00223     a[27] = -6*b[24] + 6*b[25] + 6*b[26] - 6*b[27] - 3*b[40] - 3*b[41] + 3*b[42] + 3*b[43]
00224         - 4*b[48] + 4*b[49] - 2*b[50] + 2*b[51] - 2*b[56] - 2*b[57] - b[58] - b[59];
00225     a[28] = 2*b[24] - 2*b[26] + b[48] + b[50];
00226     a[29] = 2*b[40] - 2*b[42] + b[56] + b[58];
00227     a[30] = -6*b[24] + 6*b[25] + 6*b[26] - 6*b[27] - 4*b[40] - 2*b[41] + 4*b[42] + 2*b[43]
00228         - 3*b[48] + 3*b[49] - 3*b[50] + 3*b[51] - 2*b[56] - b[57] - 2*b[58] - b[59];
00229     a[31] = 4*b[24] - 4*b[25] - 4*b[26] + 4*b[27] + 2*b[40] + 2*b[41] - 2*b[42] - 2*b[43]
00230         + 2*b[48] - 2*b[49] + 2*b[50] - 2*b[51] + b[56] + b[57] + b[58] + b[59];
00231     a[32] = -3*b[0] + 3*b[4] - 2*b[24] - b[28];
00232     a[33] = -3*b[8] + 3*b[12] - 2*b[40] - b[44];
00233     a[34] = 9*b[0] - 9*b[1] - 9*b[4] + 9*b[5] + 6*b[8] + 3*b[9] - 6*b[12] - 3*b[13]
00234         + 6*b[24] - 6*b[25] + 3*b[28] - 3*b[29] + 4*b[40] + 2*b[41] + 2*b[44] + b[45];
00235     a[35] = -6*b[0] + 6*b[1] + 6*b[4] - 6*b[5] - 3*b[8] - 3*b[9] + 3*b[12] + 3*b[13]
00236         - 4*b[24] + 4*b[25] - 2*b[28] + 2*b[29] - 2*b[40] - 2*b[41] - b[44] - b[45];
00237     a[36] = -3*b[16] + 3*b[20] - 2*b[48] - b[52];
00238     a[37] = -3*b[32] + 3*b[36] - 2*b[56] - b[60];
00239     a[38] = 9*b[16] - 9*b[17] - 9*b[20] + 9*b[21] + 6*b[32] + 3*b[33] - 6*b[36] - 3*b[37]
00240         + 6*b[48] - 6*b[49] + 3*b[52] - 3*b[53] + 4*b[56] + 2*b[57] + 2*b[60] + b[61];
00241     a[39] = -6*b[16] + 6*b[17] + 6*b[20] - 6*b[21] - 3*b[32] - 3*b[33] + 3*b[36] + 3*b[37]
00242         - 4*b[48] + 4*b[49] - 2*b[52] + 2*b[53] - 2*b[56] - 2*b[57] - b[60] - b[61];
00243     a[40] = 9*b[0] - 9*b[2] - 9*b[4] + 9*b[6] + 6*b[16] + 3*b[18] - 6*b[20] - 3*b[22]
00244         + 6*b[24] - 6*b[26] + 3*b[28] - 3*b[30] + 4*b[48] + 2*b[50] + 2*b[52] + b[54];
00245     a[41] = 9*b[8] - 9*b[10] - 9*b[12] + 9*b[14] + 6*b[32] + 3*b[34] - 6*b[36] - 3*b[38]
00246         + 6*b[40] - 6*b[42] + 3*b[44] - 3*b[46] + 4*b[56] + 2*b[58] + 2*b[60] + b[62];
00247     a[42] = -27*b[0] + 27*b[1] + 27*b[2] - 27*b[3] + 27*b[4] - 27*b[5] - 27*b[6] + 27*b[7]
00248         - 18*b[8] - 9*b[9] + 18*b[10] + 9*b[11] + 18*b[12] + 9*b[13] - 18*b[14] - 9*b[15]
00249         - 18*b[16] + 18*b[17] - 9*b[18] + 9*b[19] + 18*b[20] - 18*b[21] + 9*b[22] - 9*b[23]
00250         - 18*b[24] + 18*b[25] + 18*b[26] - 18*b[27] - 9*b[28] + 9*b[29] + 9*b[30] - 9*b[31]
00251         - 12*b[32] - 6*b[33] - 6*b[34] - 3*b[35] + 12*b[36] + 6*b[37] + 6*b[38] + 3*b[39]
00252         - 12*b[40] - 6*b[41] + 12*b[42] + 6*b[43] - 6*b[44] - 3*b[45] + 6*b[46] + 3*b[47]
00253         - 12*b[48] + 12*b[49] - 6*b[50] + 6*b[51] - 6*b[52] + 6*b[53] - 3*b[54] + 3*b[55]
00254         - 8*b[56] - 4*b[57] - 4*b[58] - 2*b[59] - 4*b[60] - 2*b[61] - 2*b[62] - b[63];
00255     a[43] = 18*b[0] - 18*b[1] - 18*b[2] + 18*b[3] - 18*b[4] + 18*b[5] + 18*b[6] - 18*b[7]
00256         + 9*b[8] + 9*b[9] - 9*b[10] - 9*b[11] - 9*b[12] - 9*b[13] + 9*b[14] + 9*b[15]
00257         + 12*b[16] - 12*b[17] + 6*b[18] - 6*b[19] - 12*b[20] + 12*b[21] - 6*b[22] + 6*b[23]
00258         + 12*b[24] - 12*b[25] - 12*b[26] + 12*b[27] + 6*b[28] - 6*b[29] - 6*b[30] + 6*b[31]
00259         + 6*b[32] + 6*b[33] + 3*b[34] + 3*b[35] - 6*b[36] - 6*b[37] - 3*b[38] - 3*b[39]
00260         + 6*b[40] + 6*b[41] - 6*b[42] - 6*b[43] + 3*b[44] + 3*b[45] - 3*b[46] - 3*b[47]
00261         + 8*b[48] - 8*b[49] + 4*b[50] - 4*b[51] + 4*b[52] - 4*b[53] + 2*b[54] - 2*b[55]
00262         + 4*b[56] + 4*b[57] + 2*b[58] + 2*b[59] + 2*b[60] + 2*b[61] + b[62] + b[63];
00263     a[44] = -6*b[0] + 6*b[2] + 6*b[4] - 6*b[6] - 3*b[16] - 3*b[18] + 3*b[20] + 3*b[22]
00264         - 4*b[24] + 4*b[26] - 2*b[28] + 2*b[30] - 2*b[48] - 2*b[50] - b[52] - b[54];
00265     a[45] = -6*b[8] + 6*b[10] + 6*b[12] - 6*b[14] - 3*b[32] - 3*b[34] + 3*b[36] + 3*b[38]
00266         - 4*b[40] + 4*b[42] - 2*b[44] + 2*b[46] - 2*b[56] - 2*b[58] - b[60] - b[62];
00267     a[46] = 18*b[0] - 18*b[1] - 18*b[2] + 18*b[3] - 18*b[4] + 18*b[5] + 18*b[6] - 18*b[7]
00268         + 12*b[8] + 6*b[9] - 12*b[10] - 6*b[11] - 12*b[12] - 6*b[13] + 12*b[14] + 6*b[15]
00269         + 9*b[16] - 9*b[17] + 9*b[18] - 9*b[19] - 9*b[20] + 9*b[21] - 9*b[22] + 9*b[23]
00270         + 12*b[24] - 12*b[25] - 12*b[26] + 12*b[27] + 6*b[28] - 6*b[29] - 6*b[30] + 6*b[31]
00271         + 6*b[32] + 3*b[33] + 6*b[34] + 3*b[35] - 6*b[36] - 3*b[37] - 6*b[38] - 3*b[39]
00272         + 8*b[40] + 4*b[41] - 8*b[42] - 4*b[43] + 4*b[44] + 2*b[45] - 4*b[46] - 2*b[47]
00273         + 6*b[48] - 6*b[49] + 6*b[50] - 6*b[51] + 3*b[52] - 3*b[53] + 3*b[54] - 3*b[55]
00274         + 4*b[56] + 2*b[57] + 4*b[58] + 2*b[59] + 2*b[60] + b[61] + 2*b[62] + b[63];
00275     a[47] = -12*b[0] + 12*b[1] + 12*b[2] - 12*b[3] + 12*b[4] - 12*b[5] - 12*b[6] + 12*b[7]
00276         - 6*b[8] - 6*b[9] + 6*b[10] + 6*b[11] + 6*b[12] + 6*b[13] - 6*b[14] - 6*b[15]
00277         - 6*b[16] + 6*b[17] - 6*b[18] + 6*b[19] + 6*b[20] - 6*b[21] + 6*b[22] - 6*b[23]
00278         - 8*b[24] + 8*b[25] + 8*b[26] - 8*b[27] - 4*b[28] + 4*b[29] + 4*b[30] - 4*b[31]
00279         - 3*b[32] - 3*b[33] - 3*b[34] - 3*b[35] + 3*b[36] + 3*b[37] + 3*b[38] + 3*b[39]
00280         - 4*b[40] - 4*b[41] + 4*b[42] + 4*b[43] - 2*b[44] - 2*b[45] + 2*b[46] + 2*b[47]
00281         - 4*b[48] + 4*b[49] - 4*b[50] + 4*b[51] - 2*b[52] + 2*b[53] - 2*b[54] + 2*b[55]
00282         - 2*b[56] - 2*b[57] - 2*b[58] - 2*b[59] - b[60] - b[61] - b[62] - b[63];
00283     a[48] = 2*b[0] - 2*b[4] + b[24] + b[28];
00284     a[49] = 2*b[8] - 2*b[12] + b[40] + b[44];
00285     a[50] = -6*b[0] + 6*b[1] + 6*b[4] - 6*b[5] - 4*b[8] - 2*b[9] + 4*b[12] + 2*b[13]
00286         - 3*b[24] + 3*b[25] - 3*b[28] + 3*b[29] - 2*b[40] - b[41] - 2*b[44] - b[45];
00287     a[51] = 4*b[0] - 4*b[1] - 4*b[4] + 4*b[5] + 2*b[8] + 2*b[9] - 2*b[12] - 2*b[13]
00288         + 2*b[24] - 2*b[25] + 2*b[28] - 2*b[29] + b[40] + b[41] + b[44] + b[45];
00289     a[52] = 2*b[16] - 2*b[20] + b[48] + b[52];
00290     a[53] = 2*b[32] - 2*b[36] + b[56] + b[60];
00291     a[54] = -6*b[16] + 6*b[17] + 6*b[20] - 6*b[21] - 4*b[32] - 2*b[33] + 4*b[36] + 2*b[37]
00292         - 3*b[48] + 3*b[49] - 3*b[52] + 3*b[53] - 2*b[56] - b[57] - 2*b[60] - b[61];
00293     a[55] = 4*b[16] - 4*b[17] - 4*b[20] + 4*b[21] + 2*b[32] + 2*b[33] - 2*b[36] - 2*b[37]
00294         + 2*b[48] - 2*b[49] + 2*b[52] - 2*b[53] + b[56] + b[57] + b[60] + b[61];
00295     a[56] = -6*b[0] + 6*b[2] + 6*b[4] - 6*b[6] - 4*b[16] - 2*b[18] + 4*b[20] + 2*b[22]
00296         - 3*b[24] + 3*b[26] - 3*b[28] + 3*b[30] - 2*b[48] - b[50] - 2*b[52] - b[54];
00297     a[57] = -6*b[8] + 6*b[10] + 6*b[12] - 6*b[14] - 4*b[32] - 2*b[34] + 4*b[36] + 2*b[38]
00298         - 3*b[40] + 3*b[42] - 3*b[44] + 3*b[46] - 2*b[56] - b[58] - 2*b[60] - b[62];
00299     a[58] = 18*b[0] - 18*b[1] - 18*b[2] + 18*b[3] - 18*b[4] + 18*b[5] + 18*b[6] - 18*b[7]
00300         + 12*b[8] + 6*b[9] - 12*b[10] - 6*b[11] - 12*b[12] - 6*b[13] + 12*b[14] + 6*b[15]
00301         + 12*b[16] - 12*b[17] + 6*b[18] - 6*b[19] - 12*b[20] + 12*b[21] - 6*b[22] + 6*b[23]
00302         + 9*b[24] - 9*b[25] - 9*b[26] + 9*b[27] + 9*b[28] - 9*b[29] - 9*b[30] + 9*b[31]
00303         + 8*b[32] + 4*b[33] + 4*b[34] + 2*b[35] - 8*b[36] - 4*b[37] - 4*b[38] - 2*b[39]
00304         + 6*b[40] + 3*b[41] - 6*b[42] - 3*b[43] + 6*b[44] + 3*b[45] - 6*b[46] - 3*b[47]
00305         + 6*b[48] - 6*b[49] + 3*b[50] - 3*b[51] + 6*b[52] - 6*b[53] + 3*b[54] - 3*b[55]
00306         + 4*b[56] + 2*b[57] + 2*b[58] + b[59] + 4*b[60] + 2*b[61] + 2*b[62] + b[63];
00307     a[59] = -12*b[0] + 12*b[1] + 12*b[2] - 12*b[3] + 12*b[4] - 12*b[5] - 12*b[6] + 12*b[7]
00308         - 6*b[8] - 6*b[9] + 6*b[10] + 6*b[11] + 6*b[12] + 6*b[13] - 6*b[14] - 6*b[15]
00309         - 8*b[16] + 8*b[17] - 4*b[18] + 4*b[19] + 8*b[20] - 8*b[21] + 4*b[22] - 4*b[23]
00310         - 6*b[24] + 6*b[25] + 6*b[26] - 6*b[27] - 6*b[28] + 6*b[29] + 6*b[30] - 6*b[31]
00311         - 4*b[32] - 4*b[33] - 2*b[34] - 2*b[35] + 4*b[36] + 4*b[37] + 2*b[38] + 2*b[39]
00312         - 3*b[40] - 3*b[41] + 3*b[42] + 3*b[43] - 3*b[44] - 3*b[45] + 3*b[46] + 3*b[47]
00313         - 4*b[48] + 4*b[49] - 2*b[50] + 2*b[51] - 4*b[52] + 4*b[53] - 2*b[54] + 2*b[55]
00314         - 2*b[56] - 2*b[57] - b[58] - b[59] - 2*b[60] - 2*b[61] - b[62] - b[63];
00315     a[60] = 4*b[0] - 4*b[2] - 4*b[4] + 4*b[6] + 2*b[16] + 2*b[18] - 2*b[20] - 2*b[22]
00316         + 2*b[24] - 2*b[26] + 2*b[28] - 2*b[30] + b[48] + b[50] + b[52] + b[54];
00317     a[61] = 4*b[8] - 4*b[10] - 4*b[12] + 4*b[14] + 2*b[32] + 2*b[34] - 2*b[36] - 2*b[38]
00318         + 2*b[40] - 2*b[42] + 2*b[44] - 2*b[46] + b[56] + b[58] + b[60] + b[62];
00319     a[62] = -12*b[0] + 12*b[1] + 12*b[2] - 12*b[3] + 12*b[4] - 12*b[5] - 12*b[6] + 12*b[7]
00320         - 8*b[8] - 4*b[9] + 8*b[10] + 4*b[11] + 8*b[12] + 4*b[13] - 8*b[14] - 4*b[15]
00321         - 6*b[16] + 6*b[17] - 6*b[18] + 6*b[19] + 6*b[20] - 6*b[21] + 6*b[22] - 6*b[23]
00322         - 6*b[24] + 6*b[25] + 6*b[26] - 6*b[27] - 6*b[28] + 6*b[29] + 6*b[30] - 6*b[31]
00323         - 4*b[32] - 2*b[33] - 4*b[34] - 2*b[35] + 4*b[36] + 2*b[37] + 4*b[38] + 2*b[39]
00324         - 4*b[40] - 2*b[41] + 4*b[42] + 2*b[43] - 4*b[44] - 2*b[45] + 4*b[46] + 2*b[47]
00325         - 3*b[48] + 3*b[49] - 3*b[50] + 3*b[51] - 3*b[52] + 3*b[53] - 3*b[54] + 3*b[55]
00326         - 2*b[56] - b[57] - 2*b[58] - b[59] - 2*b[60] - b[61] - 2*b[62] - b[63];
00327     a[63] = 8*b[0] - 8*b[1] - 8*b[2] + 8*b[3] - 8*b[4] + 8*b[5] + 8*b[6] - 8*b[7]
00328         + 4*b[8] + 4*b[9] - 4*b[10] - 4*b[11] - 4*b[12] - 4*b[13] + 4*b[14] + 4*b[15]
00329         + 4*b[16] - 4*b[17] + 4*b[18] - 4*b[19] - 4*b[20] + 4*b[21] - 4*b[22] + 4*b[23]
00330         + 4*b[24] - 4*b[25] - 4*b[26] + 4*b[27] + 4*b[28] - 4*b[29] - 4*b[30] + 4*b[31]
00331         + 2*b[32] + 2*b[33] + 2*b[34] + 2*b[35] - 2*b[36] - 2*b[37] - 2*b[38] - 2*b[39]
00332         + 2*b[40] + 2*b[41] - 2*b[42] - 2*b[43] + 2*b[44] + 2*b[45] - 2*b[46] - 2*b[47]
00333         + 2*b[48] - 2*b[49] + 2*b[50] - 2*b[51] + 2*b[52] - 2*b[53] + 2*b[54] - 2*b[55]
00334         + b[56] + b[57] + b[58] + b[59] + b[60] + b[61] + b[62] + b[63];
00335 }
00336 
00337 
00338 inline int GridforceLiteGrid::get_inds(Position pos, int *inds, Vector &dg) const
00339 {
00340     Vector p = pos - origin;
00341     Vector g;
00342     
00343     g = inv * p;
00344     
00345     for (int i = 0; i < 3; i++) {
00346         inds[i] = (int)floor(g[i]);
00347         dg[i] = g[i] - inds[i];
00348     }
00349     
00350     for (int i = 0; i < 3; i++) {
00351         if (inds[i] < 0 || inds[i] >= k[i]-1) {
00352             return -1;  // Outside potential and grid is not continuous
00353         }
00354     }
00355     
00356     return 0;
00357 }
00358 
00359 
00360 inline void GridforceLiteGrid::compute_wts(float *wts, const Vector &dg) const
00361 {
00362     wts[0] = (1-dg.x) * (1-dg.y) * (1-dg.z);
00363     wts[1] = (1-dg.x) * (1-dg.y) *   dg.z;
00364     wts[2] = (1-dg.x) *   dg.y   * (1-dg.z);
00365     wts[3] = (1-dg.x) *   dg.y   *   dg.z;
00366     wts[4] =   dg.x   * (1-dg.y) * (1-dg.z);
00367     wts[5] =   dg.x   * (1-dg.y) *   dg.z;
00368     wts[6] =   dg.x   *   dg.y   * (1-dg.z);
00369     wts[7] =   dg.x   *   dg.y   *   dg.z;
00370     DebugM(2, "dg = " << dg << "\n" << endi);
00371 }
00372 
00373 
00374 inline float GridforceLiteGrid::linear_interpolate(int i0, int i1, int i2, int i3, const float *wts) const
00375 {
00376 #ifdef DEBUGM
00377     float vals[8];
00378     vals[0] = get_grid(i0,   i1,   i2,   i3);
00379     vals[1] = get_grid(i0,   i1,   i2+1, i3);
00380     vals[2] = get_grid(i0,   i1+1, i2,   i3);
00381     vals[3] = get_grid(i0,   i1+1, i2+1, i3);
00382     vals[4] = get_grid(i0+1, i1,   i2,   i3);
00383     vals[5] = get_grid(i0+1, i1,   i2+1, i3);
00384     vals[6] = get_grid(i0+1, i1+1, i2,   i3);
00385     vals[7] = get_grid(i0+1, i1+1, i2+1, i3);
00386     
00387     switch (i3) {
00388     case 0:
00389         DebugM(2, "V\n" << endi);
00390         break;
00391     case 1:
00392         DebugM(2, "dV/dx\n" << endi);
00393         break;
00394     case 2:
00395         DebugM(2, "dV/dy\n" << endi);
00396         break;
00397     case 3:
00398         DebugM(2, "dV/dz\n" << endi);
00399         break;
00400     }
00401     
00402     for (int i = 0; i < 8; i++) {
00403         DebugM(2, "vals[" << i << "] = " << vals[i] << " wts[" << i << "] = " << wts[i] << "\n" << endi);
00404     }
00405 #endif
00406     
00407     float result =
00408         wts[0] * get_grid(i0,   i1,   i2,   i3) +
00409         wts[1] * get_grid(i0,   i1,   i2+1, i3) +
00410         wts[2] * get_grid(i0,   i1+1, i2,   i3) +
00411         wts[3] * get_grid(i0,   i1+1, i2+1, i3) +
00412         wts[4] * get_grid(i0+1, i1,   i2,   i3) +
00413         wts[5] * get_grid(i0+1, i1,   i2+1, i3) +
00414         wts[6] * get_grid(i0+1, i1+1, i2,   i3) +
00415         wts[7] * get_grid(i0+1, i1+1, i2+1, i3);
00416     
00417     DebugM(2, "result = " << result << "\n" << endi);
00418     
00419     return result;
00420 }
00421 
00422 
00423 inline Position GridforceGrid::wrap_position(const Position &pos, const Lattice &lattice)
00424 {
00425     // Wrap 'pos' about grid center, using periodic cell information in 'lattice'
00426     // Position pos_wrapped = pos;
00427     // Position center = get_center();
00428     // pos_wrapped += lattice.wrap_delta(pos);
00429     // pos_wrapped += lattice.delta(pos_wrapped, center) - (pos_wrapped - center);
00430     
00431     Position pos_wrapped = pos + lattice.wrap_delta(pos - get_center() + lattice.origin());
00432     
00433     return pos_wrapped;
00434 }
00435 
00436 #endif

Generated on Sun May 19 04:07:46 2013 for NAMD by  doxygen 1.3.9.1