Unverified Commit 7af565ed authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Use more efficient version of updateContextState() (#4054)

parent 86f07082
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
const GayBerneForce& getOwner() const { const GayBerneForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
const MonteCarloAnisotropicBarostat& getOwner() const { const MonteCarloAnisotropicBarostat& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context); void updateContextState(ContextImpl& context, bool& forcesInvalid);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) { double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) {
// This force doesn't apply forces to particles. // This force doesn't apply forces to particles.
return 0.0; return 0.0;
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
const MonteCarloMembraneBarostat& getOwner() const { const MonteCarloMembraneBarostat& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context); void updateContextState(ContextImpl& context, bool& forcesInvalid);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) { double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) {
// This force doesn't apply forces to particles. // This force doesn't apply forces to particles.
return 0.0; return 0.0;
......
...@@ -62,7 +62,7 @@ void MonteCarloAnisotropicBarostatImpl::initialize(ContextImpl& context) { ...@@ -62,7 +62,7 @@ void MonteCarloAnisotropicBarostatImpl::initialize(ContextImpl& context) {
SimTKOpenMMUtilities::setRandomNumberSeed(owner.getRandomNumberSeed()); SimTKOpenMMUtilities::setRandomNumberSeed(owner.getRandomNumberSeed());
} }
void MonteCarloAnisotropicBarostatImpl::updateContextState(ContextImpl& context) { void MonteCarloAnisotropicBarostatImpl::updateContextState(ContextImpl& context, bool& forcesInvalid) {
if (++step < owner.getFrequency() || owner.getFrequency() == 0) if (++step < owner.getFrequency() || owner.getFrequency() == 0)
return; return;
if (!owner.getScaleX() && !owner.getScaleY() && !owner.getScaleZ()) if (!owner.getScaleX() && !owner.getScaleY() && !owner.getScaleZ())
...@@ -123,8 +123,10 @@ void MonteCarloAnisotropicBarostatImpl::updateContextState(ContextImpl& context) ...@@ -123,8 +123,10 @@ void MonteCarloAnisotropicBarostatImpl::updateContextState(ContextImpl& context)
context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]); context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]);
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context); kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
} }
else else {
numAccepted[axis]++; numAccepted[axis]++;
forcesInvalid = true;
}
numAttempted[axis]++; numAttempted[axis]++;
if (numAttempted[axis] >= 10) { if (numAttempted[axis] >= 10) {
if (numAccepted[axis] < 0.25*numAttempted[axis]) { if (numAccepted[axis] < 0.25*numAttempted[axis]) {
......
...@@ -62,7 +62,7 @@ void MonteCarloMembraneBarostatImpl::initialize(ContextImpl& context) { ...@@ -62,7 +62,7 @@ void MonteCarloMembraneBarostatImpl::initialize(ContextImpl& context) {
SimTKOpenMMUtilities::setRandomNumberSeed(owner.getRandomNumberSeed()); SimTKOpenMMUtilities::setRandomNumberSeed(owner.getRandomNumberSeed());
} }
void MonteCarloMembraneBarostatImpl::updateContextState(ContextImpl& context) { void MonteCarloMembraneBarostatImpl::updateContextState(ContextImpl& context, bool& forcesInvalid) {
if (++step < owner.getFrequency() || owner.getFrequency() == 0) if (++step < owner.getFrequency() || owner.getFrequency() == 0)
return; return;
step = 0; step = 0;
...@@ -124,8 +124,10 @@ void MonteCarloMembraneBarostatImpl::updateContextState(ContextImpl& context) { ...@@ -124,8 +124,10 @@ void MonteCarloMembraneBarostatImpl::updateContextState(ContextImpl& context) {
context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]); context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]);
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context); kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
} }
else else {
numAccepted[axis]++; numAccepted[axis]++;
forcesInvalid = true;
}
numAttempted[axis]++; numAttempted[axis]++;
if (numAttempted[axis] >= 10) { if (numAttempted[axis] >= 10) {
if (numAccepted[axis] < 0.25*numAttempted[axis]) { if (numAccepted[axis] < 0.25*numAttempted[axis]) {
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
return owner; return owner;
} }
void updateRPMDState(ContextImpl& context); void updateRPMDState(ContextImpl& context);
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This is unused, since the updating is done in updateRPMDState(). // This is unused, since the updating is done in updateRPMDState().
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) { double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) {
......
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