"csrc/sm90/prefill/vscode:/vscode.git/clone" did not exist on "c3cf875a2fa607ae0c3d62fb228f5643d9606ce6"
Commit 5ee23330 authored by peastman's avatar peastman
Browse files

CompoundIntegrator handles checkpoints correctly

parent 62394b00
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2015-2016 Stanford University and the Authors. *
* Portions copyright (c) 2015-2020 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -194,6 +194,16 @@ protected:
double getVelocityTimeOffset() const {
return getIntegrator(0).getVelocityTimeOffset();
}
/**
* This is called while writing checkpoints. It gives the integrator a chance to write
* its own data.
*/
void createCheckpoint(std::ostream& stream) const;
/**
* This is called while loading a checkpoint. The integrator should read in whatever
* data it wrote in createCheckpoint() and update its internal state accordingly.
*/
void loadCheckpoint(std::istream& stream);
private:
int currentIntegrator;
std::vector<Integrator*> integrators;
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2015-2016 Stanford University and the Authors. *
* Portions copyright (c) 2015-2020 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -128,3 +128,13 @@ void CompoundIntegrator::stateChanged(State::DataType changed) {
double CompoundIntegrator::computeKineticEnergy() {
return integrators[currentIntegrator]->computeKineticEnergy();
}
void CompoundIntegrator::createCheckpoint(std::ostream& stream) const {
for (int i = 0; i < integrators.size(); i++)
integrators[i]->createCheckpoint(stream);
}
void CompoundIntegrator::loadCheckpoint(std::istream& stream) {
for (int i = 0; i < integrators.size(); i++)
integrators[i]->loadCheckpoint(stream);
}
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2015 Stanford University and the Authors. *
* Portions copyright (c) 2015-2020 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -33,6 +33,7 @@
#include "openmm/BrownianIntegrator.h"
#include "openmm/CompoundIntegrator.h"
#include "openmm/Context.h"
#include "openmm/CustomIntegrator.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/System.h"
......@@ -208,6 +209,33 @@ void testDifferentStepSizes() {
}
}
void testCheckpoint() {
// Test that member integrators get loaded correctly from checkpoints.
System system;
system.addParticle(1.0);
CustomIntegrator* custom = new CustomIntegrator(0.001);
custom->addGlobalVariable("a", 1.0);
custom->addPerDofVariable("b", 2.0);
CompoundIntegrator integrator;
integrator.addIntegrator(custom);
Context context(system, integrator, platform);
vector<Vec3> positions(1, Vec3());
context.setPositions(positions);
custom->setGlobalVariable(0, 5.0);
vector<Vec3> b1(1, Vec3(1, 2, 3));
custom->setPerDofVariable(0, b1);
stringstream checkpoint;
context.createCheckpoint(checkpoint);
custom->setGlobalVariable(0, 10.0);
vector<Vec3> b2(1, Vec3(4, 5, 6));
custom->setPerDofVariable(0, b2);
context.loadCheckpoint(checkpoint);
ASSERT_EQUAL(5.0, custom->getGlobalVariable(0));
vector<Vec3> b3;
custom->getPerDofVariable(0, b3);
ASSERT_EQUAL_VEC(b1[0], b3[0], 1e-6);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
......@@ -216,6 +244,7 @@ int main(int argc, char* argv[]) {
testChangingIntegrator();
testChangingParameters();
testDifferentStepSizes();
testCheckpoint();
runPlatformTests();
}
catch(const exception& e) {
......
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