--- branches/development/src/brains/Snapshot.cpp 2010/07/09 23:08:25 1465 +++ branches/development/src/brains/Snapshot.cpp 2012/05/22 21:55:31 1715 @@ -36,7 +36,8 @@ * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ /** @@ -56,40 +57,33 @@ namespace OpenMD { namespace OpenMD { void Snapshot::setHmat(const Mat3x3d& m) { - hmat_ = m; - invHmat_ = hmat_.inverse(); + frameData.hmat = m; + frameData.invHmat = frameData.hmat.inverse(); - - //prepare fortran Hmat - RealType fortranHmat[9]; - RealType fortranInvHmat[9]; - hmat_.getArray(fortranHmat); - invHmat_.getArray(fortranInvHmat); - //determine whether the box is orthoTolerance or not - int oldOrthoRhombic = orthoRhombic_; + bool oldOrthoRhombic = frameData.orthoRhombic; - RealType smallDiag = fabs(hmat_(0, 0)); - if(smallDiag > fabs(hmat_(1, 1))) smallDiag = fabs(hmat_(1, 1)); - if(smallDiag > fabs(hmat_(2, 2))) smallDiag = fabs(hmat_(2, 2)); + RealType smallDiag = fabs(frameData.hmat(0, 0)); + if(smallDiag > fabs(frameData.hmat(1, 1))) smallDiag = fabs(frameData.hmat(1, 1)); + if(smallDiag > fabs(frameData.hmat(2, 2))) smallDiag = fabs(frameData.hmat(2, 2)); RealType tol = smallDiag * orthoTolerance_; - orthoRhombic_ = 1; + frameData.orthoRhombic = true; for (int i = 0; i < 3; i++ ) { for (int j = 0 ; j < 3; j++) { if (i != j) { - if (orthoRhombic_) { - if ( fabs(hmat_(i, j)) >= tol) - orthoRhombic_ = 0; + if (frameData.orthoRhombic) { + if ( fabs(frameData.hmat(i, j)) >= tol) + frameData.orthoRhombic = false; } } } } - if( oldOrthoRhombic != orthoRhombic_ ){ + if( oldOrthoRhombic != frameData.orthoRhombic){ - if( orthoRhombic_ ) { + if( frameData.orthoRhombic ) { sprintf( painCave.errMsg, "OpenMD is switching from the default Non-Orthorhombic\n" "\tto the faster Orthorhombic periodic boundary computations.\n" @@ -113,58 +107,49 @@ namespace OpenMD { simError(); } } - - //notify fortran simulation box has changed - setFortranBox(fortranHmat, fortranInvHmat, &orthoRhombic_); } void Snapshot::wrapVector(Vector3d& pos) { + + Vector3d scaled = scaleVector(pos); + + for (int i = 0; i < 3; i++) + scaled[i] -= roundMe(scaled[i]); - int i; - Vector3d scaled; + if( !frameData.orthoRhombic ) + pos = frameData.hmat * scaled; + else { - if( !orthoRhombic_ ){ - - // calc the scaled coordinates. - scaled = invHmat_* pos; - - // wrap the scaled coordinates - for (i = 0; i < 3; ++i) { - scaled[i] -= roundMe(scaled[i]); - } - // calc the wrapped real coordinates from the wrapped scaled coordinates - pos = hmat_ * scaled; + for (int i=0; i<3; i++) { + pos[i] = scaled[i] * frameData.hmat(i, i); + } + } + } - } else {//if it is orthoRhombic, we could improve efficiency by only caculating the diagonal element + inline Vector3d Snapshot::scaleVector(Vector3d& pos) { - // calc the scaled coordinates. - for (i=0; i<3; i++) { - scaled[i] = pos[i] * invHmat_(i, i); - } - - // wrap the scaled coordinates - for (i = 0; i < 3; ++i) { - scaled[i] -= roundMe(scaled[i]); - } + Vector3d scaled; - // calc the wrapped real coordinates from the wrapped scaled coordinates - for (i=0; i<3; i++) { - pos[i] = scaled[i] * hmat_(i, i); - } - + if( !frameData.orthoRhombic ) + scaled = frameData.invHmat * pos; + else { + // calc the scaled coordinates. + for (int i=0; i<3; i++) + scaled[i] = pos[i] * frameData.invHmat(i, i); } + return scaled; } - + Vector3d Snapshot::getCOM() { if( !hasCOM_ ) { sprintf( painCave.errMsg, "COM was requested before COM was computed!\n"); painCave.severity = OPENMD_ERROR; simError(); } - return COM_; + return frameData.COM; } Vector3d Snapshot::getCOMvel() { @@ -173,7 +158,7 @@ namespace OpenMD { painCave.severity = OPENMD_ERROR; simError(); } - return COMvel_; + return frameData.COMvel; } Vector3d Snapshot::getCOMw() { @@ -182,8 +167,7 @@ namespace OpenMD { painCave.severity = OPENMD_ERROR; simError(); } - return COMw_; + return frameData.COMw; } - }