Commit 32ea2e9d authored by Peter Eastman's avatar Peter Eastman
Browse files

Changing box vectors does not change positions

parent 9e66f0b1
...@@ -187,7 +187,7 @@ public: ...@@ -187,7 +187,7 @@ public:
* @param b the vector defining the second edge of the periodic box * @param b the vector defining the second edge of the periodic box
* @param c the vector defining the third edge of the periodic box * @param c the vector defining the third edge of the periodic box
*/ */
virtual void setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) const = 0; virtual void setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) = 0;
/** /**
* Create a checkpoint recording the current state of the Context. * Create a checkpoint recording the current state of the Context.
* *
......
...@@ -178,7 +178,7 @@ public: ...@@ -178,7 +178,7 @@ public:
* @param b the vector defining the second edge of the periodic box * @param b the vector defining the second edge of the periodic box
* @param c the vector defining the third edge of the periodic box * @param c the vector defining the third edge of the periodic box
*/ */
void setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) const; void setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c);
/** /**
* Create a checkpoint recording the current state of the Context. * Create a checkpoint recording the current state of the Context.
* *
......
...@@ -340,10 +340,27 @@ void CudaUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, Vec3 ...@@ -340,10 +340,27 @@ void CudaUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, Vec3
cu.getPeriodicBoxVectors(a, b, c); cu.getPeriodicBoxVectors(a, b, c);
} }
void CudaUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) const { void CudaUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) {
vector<CudaContext*>& contexts = cu.getPlatformData().contexts; vector<CudaContext*>& contexts = cu.getPlatformData().contexts;
// If any particles have been wrapped to the first periodic box, we need to unwrap them
// to avoid changing their positions.
vector<Vec3> positions;
for (int i = 0; i < (int) cu.getPosCellOffsets().size(); i++) {
int4& offset = cu.getPosCellOffsets()[i];
if (offset.x != 0 || offset.y != 0 || offset.z != 0) {
getPositions(context, positions);
break;
}
}
// Update the vectors.
for (int i = 0; i < (int) contexts.size(); i++) for (int i = 0; i < (int) contexts.size(); i++)
contexts[i]->setPeriodicBoxVectors(a, b, c); contexts[i]->setPeriodicBoxVectors(a, b, c);
if (positions.size() > 0)
setPositions(context, positions);
} }
void CudaUpdateStateDataKernel::createCheckpoint(ContextImpl& context, ostream& stream) { void CudaUpdateStateDataKernel::createCheckpoint(ContextImpl& context, ostream& stream) {
......
...@@ -156,7 +156,7 @@ public: ...@@ -156,7 +156,7 @@ public:
* @param b the vector defining the second edge of the periodic box * @param b the vector defining the second edge of the periodic box
* @param c the vector defining the third edge of the periodic box * @param c the vector defining the third edge of the periodic box
*/ */
void setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) const; void setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c);
/** /**
* Create a checkpoint recording the current state of the Context. * Create a checkpoint recording the current state of the Context.
* *
......
...@@ -369,10 +369,27 @@ void OpenCLUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, Ve ...@@ -369,10 +369,27 @@ void OpenCLUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, Ve
cl.getPeriodicBoxVectors(a, b, c); cl.getPeriodicBoxVectors(a, b, c);
} }
void OpenCLUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) const { void OpenCLUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) {
vector<OpenCLContext*>& contexts = cl.getPlatformData().contexts; vector<OpenCLContext*>& contexts = cl.getPlatformData().contexts;
// If any particles have been wrapped to the first periodic box, we need to unwrap them
// to avoid changing their positions.
vector<Vec3> positions;
for (int i = 0; i < (int) cl.getPosCellOffsets().size(); i++) {
mm_int4& offset = cl.getPosCellOffsets()[i];
if (offset.x != 0 || offset.y != 0 || offset.z != 0) {
getPositions(context, positions);
break;
}
}
// Update the vectors.
for (int i = 0; i < (int) contexts.size(); i++) for (int i = 0; i < (int) contexts.size(); i++)
contexts[i]->setPeriodicBoxVectors(a, b, c); contexts[i]->setPeriodicBoxVectors(a, b, c);
if (positions.size() > 0)
setPositions(context, positions);
} }
void OpenCLUpdateStateDataKernel::createCheckpoint(ContextImpl& context, ostream& stream) { void OpenCLUpdateStateDataKernel::createCheckpoint(ContextImpl& context, ostream& stream) {
......
...@@ -172,7 +172,7 @@ public: ...@@ -172,7 +172,7 @@ public:
* @param b the vector defining the second edge of the periodic box * @param b the vector defining the second edge of the periodic box
* @param c the vector defining the third edge of the periodic box * @param c the vector defining the third edge of the periodic box
*/ */
void setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) const; void setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c);
/** /**
* Create a checkpoint recording the current state of the Context. * Create a checkpoint recording the current state of the Context.
* *
......
...@@ -280,7 +280,7 @@ void ReferenceUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context, ...@@ -280,7 +280,7 @@ void ReferenceUpdateStateDataKernel::getPeriodicBoxVectors(ContextImpl& context,
c = vectors[2]; c = vectors[2];
} }
void ReferenceUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) const { void ReferenceUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context, const Vec3& a, const Vec3& b, const Vec3& c) {
RealVec& box = extractBoxSize(context); RealVec& box = extractBoxSize(context);
box[0] = (RealOpenMM) a[0]; box[0] = (RealOpenMM) a[0];
box[1] = (RealOpenMM) b[1]; box[1] = (RealOpenMM) b[1];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment