Commit 1c7d6312 authored by peastman's avatar peastman
Browse files

Merge pull request #716 from peastman/master

CustomIntegrator throws an exception if variable names are ambiguous
parents dbd7fd3a ad5821ff
......@@ -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) 2011-2012 Stanford University and the Authors. *
* Portions copyright (c) 2011-2014 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -36,11 +36,11 @@
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/kernels.h"
#include <set>
#include <string>
using namespace OpenMM;
using std::string;
using std::vector;
using namespace std;
CustomIntegrator::CustomIntegrator(double stepSize) : globalsAreCurrent(true), forcesAreValid(false) {
setStepSize(stepSize);
......@@ -52,6 +52,18 @@ CustomIntegrator::CustomIntegrator(double stepSize) : globalsAreCurrent(true), f
void CustomIntegrator::initialize(ContextImpl& contextRef) {
if (owner != NULL && &contextRef.getOwner() != owner)
throw OpenMMException("This Integrator is already bound to a context");
vector<std::string> variableList;
set<std::string> variableSet;
variableList.insert(variableList.end(), globalNames.begin(), globalNames.end());
variableList.insert(variableList.end(), perDofNames.begin(), perDofNames.end());
for (int i = 0; i < (int) variableList.size(); i++) {
string& name = variableList[i];
if (variableSet.find(name) != variableSet.end())
throw OpenMMException("The Integrator defines two variables with the same name: "+name);
variableSet.insert(name);
if (contextRef.getParameters().find(name) != contextRef.getParameters().end())
throw OpenMMException("The Integrator defines a variable with the same name as a Context parameter: "+name);
}
context = &contextRef;
owner = &contextRef.getOwner();
kernel = context->getPlatform().createKernel(IntegrateCustomStepKernel::Name(), contextRef);
......
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