Unverified Commit 11a1982a authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Fixed inconsistency in computing kinetic energy (#3574)

parent c8981916
...@@ -113,7 +113,7 @@ static double computeShiftedKineticEnergy(ContextImpl& context, vector<double>& ...@@ -113,7 +113,7 @@ static double computeShiftedKineticEnergy(ContextImpl& context, vector<double>&
int numParticles = context.getSystem().getNumParticles(); int numParticles = context.getSystem().getNumParticles();
// Compute the shifted velocities. // Compute the shifted velocities.
vector<Vec3> shiftedVel(numParticles); vector<Vec3> shiftedVel(numParticles);
for (int i = 0; i < numParticles; ++i) { for (int i = 0; i < numParticles; ++i) {
if (masses[i] > 0) if (masses[i] > 0)
...@@ -123,11 +123,13 @@ static double computeShiftedKineticEnergy(ContextImpl& context, vector<double>& ...@@ -123,11 +123,13 @@ static double computeShiftedKineticEnergy(ContextImpl& context, vector<double>&
} }
// Apply constraints to them. // Apply constraints to them.
vector<double> inverseMasses(numParticles); if (timeShift != 0) {
for (int i = 0; i < numParticles; i++) vector<double> inverseMasses(numParticles);
inverseMasses[i] = (masses[i] == 0 ? 0 : 1/masses[i]); for (int i = 0; i < numParticles; i++)
extractConstraints(context).applyToVelocities(posData, shiftedVel, inverseMasses, 1e-4); inverseMasses[i] = (masses[i] == 0 ? 0 : 1/masses[i]);
extractConstraints(context).applyToVelocities(posData, shiftedVel, inverseMasses, 1e-4);
}
// Compute the kinetic energy. // Compute the kinetic energy.
......
...@@ -262,8 +262,9 @@ void ReferenceUpdateStateDataKernel::computeShiftedVelocities(ContextImpl& conte ...@@ -262,8 +262,9 @@ void ReferenceUpdateStateDataKernel::computeShiftedVelocities(ContextImpl& conte
} }
// Apply constraints to them. // Apply constraints to them.
extractConstraints(context).applyToVelocities(posData, velocities, inverseMasses, 1e-4); if (timeShift != 0)
extractConstraints(context).applyToVelocities(posData, velocities, inverseMasses, 1e-4);
} }
void ReferenceUpdateStateDataKernel::getForces(ContextImpl& context, std::vector<Vec3>& forces) { void ReferenceUpdateStateDataKernel::getForces(ContextImpl& context, std::vector<Vec3>& forces) {
......
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