Unverified Commit 90f0d823 authored by Andy Simmonett's avatar Andy Simmonett
Browse files

Attempt to apply KE computation optimization and corresponding fix from #2524

parent 61a248ca
...@@ -264,6 +264,10 @@ protected: ...@@ -264,6 +264,10 @@ protected:
* Compute the kinetic energy of the system at the current time. * Compute the kinetic energy of the system at the current time.
*/ */
virtual double computeKineticEnergy(); virtual double computeKineticEnergy();
/**
* Computing kinetic energy for this integrator does not require forces.
*/
bool kineticEnergyRequiresForce() const override;
std::vector<NoseHooverChain> noseHooverChains; std::vector<NoseHooverChain> noseHooverChains;
std::vector<int> allAtoms; std::vector<int> allAtoms;
......
...@@ -267,6 +267,7 @@ void NoseHooverIntegrator::setRelativeCollisionFrequency(double frequency, int c ...@@ -267,6 +267,7 @@ void NoseHooverIntegrator::setRelativeCollisionFrequency(double frequency, int c
} }
double NoseHooverIntegrator::computeKineticEnergy() { double NoseHooverIntegrator::computeKineticEnergy() {
forcesAreValid = false;
double kE = 0.0; double kE = 0.0;
if(noseHooverChains.size() > 0) { if(noseHooverChains.size() > 0) {
for (const auto &nhc: noseHooverChains){ for (const auto &nhc: noseHooverChains){
...@@ -278,6 +279,10 @@ double NoseHooverIntegrator::computeKineticEnergy() { ...@@ -278,6 +279,10 @@ double NoseHooverIntegrator::computeKineticEnergy() {
return kE; return kE;
} }
bool NoseHooverIntegrator::kineticEnergyRequiresForce() const {
return false;
}
double NoseHooverIntegrator::computeHeatBathEnergy() { double NoseHooverIntegrator::computeHeatBathEnergy() {
double energy = 0; double energy = 0;
for(auto &nhc : noseHooverChains) { for(auto &nhc : noseHooverChains) {
...@@ -340,7 +345,8 @@ void NoseHooverIntegrator::step(int steps) { ...@@ -340,7 +345,8 @@ void NoseHooverIntegrator::step(int steps) {
throw OpenMMException("This Integrator is not bound to a context!"); throw OpenMMException("This Integrator is not bound to a context!");
std::pair<double, double> scale, kineticEnergy; std::pair<double, double> scale, kineticEnergy;
for (int i = 0; i < steps; ++i) { for (int i = 0; i < steps; ++i) {
context->updateContextState(); if(context->updateContextState())
forcesAreValid = false;
for(auto &nhc : noseHooverChains) { for(auto &nhc : noseHooverChains) {
kineticEnergy = nhcKernel.getAs<NoseHooverChainKernel>().computeMaskedKineticEnergy(*context, nhc, false); kineticEnergy = nhcKernel.getAs<NoseHooverChainKernel>().computeMaskedKineticEnergy(*context, nhc, false);
scale = nhcKernel.getAs<NoseHooverChainKernel>().propagateChain(*context, nhc, kineticEnergy, getStepSize()); scale = nhcKernel.getAs<NoseHooverChainKernel>().propagateChain(*context, nhc, kineticEnergy, getStepSize());
......
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