--- trunk/src/brains/Snapshot.cpp 2009/11/25 20:02:06 1390 +++ branches/development/src/brains/Snapshot.cpp 2011/05/25 16:20:37 1568 @@ -51,13 +51,14 @@ #include "utils/NumericConstant.hpp" #include "utils/simError.h" #include "utils/Utility.hpp" +#include + namespace OpenMD { void Snapshot::setHmat(const Mat3x3d& m) { hmat_ = m; invHmat_ = hmat_.inverse(); - //prepare fortran Hmat RealType fortranHmat[9]; RealType fortranInvHmat[9]; @@ -113,49 +114,43 @@ namespace OpenMD { } //notify fortran simulation box has changed - setFortranBox(fortranHmat, fortranInvHmat, &orthoRhombic_); + // 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( !orthoRhombic_ ) + pos = 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] * 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( !orthoRhombic_ ) + scaled = invHmat_* pos; + else { + // calc the scaled coordinates. + for (int i=0; i<3; i++) + scaled[i] = pos[i] * invHmat_(i, i); } + return scaled; } - + Vector3d Snapshot::getCOM() { if( !hasCOM_ ) { sprintf( painCave.errMsg, "COM was requested before COM was computed!\n"); @@ -182,6 +177,5 @@ namespace OpenMD { } return COMw_; } - }