Commit 84165803 authored by Yutong Zhao's avatar Yutong Zhao
Browse files

Removed redundant overload of == operator in AssertionUtilities.h. Removed...

Removed redundant overload of == operator in AssertionUtilities.h. Removed extraneous version check for serialized integrators and state. Updated unit test to include more details. 
parent a6882a28
......@@ -38,7 +38,6 @@
#include "windowsExport.h"
#include <cmath>
#include <string>
#include <sstream>
namespace OpenMM {
......@@ -47,16 +46,10 @@ void OPENMM_EXPORT throwException(const char* file, int line, const std::string&
} // namespace OpenMM
static inline bool operator==(const std::string& lhs, const std::string &rhs) {
if(lhs.compare(rhs) == 0)
return true;
return false;
}
#define ASSERT(cond) {if (!(cond)) throwException(__FILE__, __LINE__, "");};
#define ASSERT_EQUAL(expected, found) {if (!((expected) == (found))) {std::stringstream details; details << "Expected "<<(expected)<<", found "<<(found); throwException(__FILE__, __LINE__, details.str());}};
#define ASSERT_EQUAL_TOL(expected, found, tol) {double _scale_ = std::abs(expected) > 1.0 ? std::abs(expected) : 1.0; if (!(std::abs((expected)-(found))/_scale_ <= (tol))) {std::stringstream details; details << "Expected "<<(expected)<<", found "<<(found); throwException(__FILE__, __LINE__, details.str());}};
#define ASSERT_EQUAL_VEC(expected, found, tol) {double _norm_ = std::sqrt((expected).dot(expected)); double _scale_ = _norm_ > 1.0 ? _norm_ : 1.0; if ((std::abs(((expected)[0])-((found)[0]))/_scale_ > (tol)) || (std::abs(((expected)[1])-((found)[1]))/_scale_ > (tol)) || (std::abs(((expected)[2])-((found)[2]))/_scale_ > (tol))) {std::stringstream details; details << " Expected "<<(expected)<<", found "<<(found); throwException(__FILE__, __LINE__, details.str());}};
......
......@@ -42,7 +42,7 @@ BrownianIntegratorProxy::BrownianIntegratorProxy() : SerializationProxy("Brownia
void BrownianIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const BrownianIntegrator& integrator = *reinterpret_cast<const BrownianIntegrator*>(object);
node.setDoubleProperty("stepSizeInPs", integrator.getStepSize());
node.setDoubleProperty("stepSize", integrator.getStepSize());
node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance());
node.setDoubleProperty("temperature", integrator.getTemperature());
node.setDoubleProperty("friction", integrator.getFriction());
......@@ -50,11 +50,11 @@ void BrownianIntegratorProxy::serialize(const void* object, SerializationNode& n
}
void* BrownianIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
if (node.getIntProperty("version") != 1)
throw OpenMMException("Unsupported version number");
BrownianIntegrator *integrator = new BrownianIntegrator(node.getDoubleProperty("temperature"),
node.getDoubleProperty("friction"),
node.getDoubleProperty("stepSizeInPs"));
node.getDoubleProperty("stepSize"));
integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
integrator->setRandomNumberSeed(node.getIntProperty("randomSeed"));
return integrator;
......
......@@ -65,14 +65,14 @@ void CustomIntegratorProxy::serialize(const void* object, SerializationNode& nod
}
node.setStringProperty("kineticEnergyExpression",integrator.getKineticEnergyExpression());
node.setIntProperty("randomSeed",integrator.getRandomNumberSeed());
node.setDoubleProperty("stepSizeInPs",integrator.getStepSize());
node.setDoubleProperty("stepSize",integrator.getStepSize());
node.setDoubleProperty("constraintTolerance",integrator.getConstraintTolerance());
}
void* CustomIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
if (node.getIntProperty("version") != 1)
throw OpenMMException("Unsupported version number");
CustomIntegrator* integrator = new CustomIntegrator(node.getDoubleProperty("stepSizeInPs"));
CustomIntegrator* integrator = new CustomIntegrator(node.getDoubleProperty("stepSize"));
const SerializationNode& globalVariablesNode = node.getChildNode("GlobalVariables");
const map<string, string> &globalVariableProp = globalVariablesNode.getProperties();
for(map<string, string>::const_iterator cit = globalVariableProp.begin(); cit != globalVariableProp.end(); cit++) {
......@@ -95,25 +95,24 @@ void* CustomIntegratorProxy::deserialize(const SerializationNode& node) const {
for(vector<SerializationNode>::const_iterator cit = computationsList.begin(); cit != computationsList.end(); cit++) {
CustomIntegrator::ComputationType computationType = static_cast<CustomIntegrator::ComputationType>(cit->getIntProperty("computationType"));
// make sure that the int casts to a valid enum
if(computationType == CustomIntegrator::ComputationType::ComputeGlobal) {
if(computationType == CustomIntegrator::ComputeGlobal) {
integrator->addComputeGlobal(cit->getStringProperty("computationVariable"), cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::ComputationType::ComputePerDof) {
} else if(computationType == CustomIntegrator::ComputePerDof) {
integrator->addComputePerDof(cit->getStringProperty("computationVariable"), cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::ComputationType::ComputeSum) {
} else if(computationType == CustomIntegrator::ComputeSum) {
integrator->addComputeSum(cit->getStringProperty("computationVariable"), cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::ComputationType::ConstrainPositions) {
} else if(computationType == CustomIntegrator::ConstrainPositions) {
integrator->addConstrainPositions();
} else if(computationType == CustomIntegrator::ComputationType::ConstrainVelocities) {
integrator->addConstrainVelocities();
} else if(computationType == CustomIntegrator::ComputationType::UpdateContextState) {
} else if(computationType == CustomIntegrator::ConstrainVelocities) {
integrator->addConstrainVelocities();
} else if(computationType == CustomIntegrator::UpdateContextState) {
integrator->addUpdateContextState();
} else {
throw(OpenMMException("Custom Integrator Deserialization: Unknown computation type"));
}
}
integrator->setKineticEnergyExpression(node.getStringProperty("kineticEnergyExpression"));
integrator->setRandomNumberSeed(node.getIntProperty("randomSeed"));
integrator->setStepSize(node.getDoubleProperty("stepSizeInPs"));
integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
return integrator;
}
\ No newline at end of file
......@@ -42,7 +42,7 @@ LangevinIntegratorProxy::LangevinIntegratorProxy() : SerializationProxy("Langevi
void LangevinIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const LangevinIntegrator& integrator = *reinterpret_cast<const LangevinIntegrator*>(object);
node.setDoubleProperty("stepSizeInPs", integrator.getStepSize());
node.setDoubleProperty("stepSize", integrator.getStepSize());
node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance());
node.setDoubleProperty("temperature", integrator.getTemperature());
node.setDoubleProperty("friction", integrator.getFriction());
......@@ -50,11 +50,11 @@ void LangevinIntegratorProxy::serialize(const void* object, SerializationNode& n
}
void* LangevinIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
if (node.getIntProperty("version") != 1)
throw OpenMMException("Unsupported version number");
LangevinIntegrator *integrator = new LangevinIntegrator(node.getDoubleProperty("temperature"),
node.getDoubleProperty("friction"),
node.getDoubleProperty("stepSizeInPs"));
node.getDoubleProperty("stepSize"));
integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
integrator->setRandomNumberSeed(node.getIntProperty("randomSeed"));
return integrator;
......
......@@ -102,7 +102,7 @@ void StateProxy::serialize(const void* object, SerializationNode& node) const {
}
void* StateProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
if (node.getIntProperty("version") != 1)
throw OpenMMException("Unsupported version number");
double outTime = node.getDoubleProperty("time");
const SerializationNode& boxVectorsNode = node.getChildNode("PeriodicBoxVectors");
......
......@@ -42,7 +42,7 @@ VariableLangevinIntegratorProxy::VariableLangevinIntegratorProxy() : Serializati
void VariableLangevinIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const VariableLangevinIntegrator& integrator = *reinterpret_cast<const VariableLangevinIntegrator*>(object);
node.setDoubleProperty("stepSizeInPs", integrator.getStepSize());
node.setDoubleProperty("stepSize", integrator.getStepSize());
node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance());
node.setDoubleProperty("temperature", integrator.getTemperature());
node.setDoubleProperty("friction", integrator.getFriction());
......@@ -51,12 +51,12 @@ void VariableLangevinIntegratorProxy::serialize(const void* object, Serializatio
}
void* VariableLangevinIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
if (node.getIntProperty("version") != 1)
throw OpenMMException("Unsupported version number");
VariableLangevinIntegrator *integrator = new VariableLangevinIntegrator(node.getDoubleProperty("temperature"),
node.getDoubleProperty("friction"),
node.getDoubleProperty("errorTol"));
integrator->setStepSize(node.getDoubleProperty("stepSizeInPs"));
integrator->setStepSize(node.getDoubleProperty("stepSize"));
integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
integrator->setRandomNumberSeed(node.getIntProperty("randomSeed"));
return integrator;
......
......@@ -43,15 +43,15 @@ void VariableVerletIntegratorProxy::serialize(const void* object, SerializationN
node.setIntProperty("version", 1);
const VariableVerletIntegrator& integrator = *reinterpret_cast<const VariableVerletIntegrator*>(object);
node.setDoubleProperty("errorTol", integrator.getErrorTolerance());
node.setDoubleProperty("stepSizeInPs", integrator.getStepSize());
node.setDoubleProperty("stepSize", integrator.getStepSize());
node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance());
}
void* VariableVerletIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
if (node.getIntProperty("version") != 1)
throw OpenMMException("Unsupported version number");
VariableVerletIntegrator *integrator = new VariableVerletIntegrator(node.getDoubleProperty("errorTol"));
integrator->setStepSize(node.getDoubleProperty("stepSizeInPs"));
integrator->setStepSize(node.getDoubleProperty("stepSize"));
integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
return integrator;
}
\ No newline at end of file
......@@ -42,14 +42,14 @@ VerletIntegratorProxy::VerletIntegratorProxy() : SerializationProxy("VerletInteg
void VerletIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
node.setIntProperty("version", 1);
const VerletIntegrator& integrator = *reinterpret_cast<const VerletIntegrator*>(object);
node.setDoubleProperty("stepSizeInPs", integrator.getStepSize());
node.setDoubleProperty("stepSize", integrator.getStepSize());
node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance());
}
void* VerletIntegratorProxy::deserialize(const SerializationNode& node) const {
if (node.getIntProperty("version") != 1 && node.getIntProperty("version") != 2)
if (node.getIntProperty("version") != 1)
throw OpenMMException("Unsupported version number");
VerletIntegrator *integrator = new VerletIntegrator(node.getDoubleProperty("stepSizeInPs"));
VerletIntegrator *integrator = new VerletIntegrator(node.getDoubleProperty("stepSize"));
integrator->setConstraintTolerance(node.getDoubleProperty("constraintTolerance"));
return integrator;
}
\ No newline at end of file
......@@ -127,6 +127,9 @@ void testSerializeCustomIntegrator() {
intg->addComputePerDof("x", "x+dt*v");
intg->addConstrainPositions();
intg->addComputePerDof("v", "(x-oldx)/dt");
intg->addUpdateContextState();
intg->addConstrainVelocities();
intg->addComputeSum("summand", "x*x+v*v");
intg->addPerDofVariable("outf", 0);
intg->addPerDofVariable("outf1", 0);
intg->addPerDofVariable("outf2", 0);
......@@ -139,6 +142,9 @@ void testSerializeCustomIntegrator() {
intg->addComputeGlobal("oute", "energy");
intg->addComputeGlobal("oute1", "energy1");
intg->addComputeGlobal("oute2", "energy2");
intg->addUpdateContextState();
intg->addConstrainVelocities();
intg->addComputeSum("summand2", "v*v+f*f");
intg->setConstraintTolerance(1e-5);
intg->setKineticEnergyExpression("m*v1*v1/2; v1=v+0.5*dt*f/m");
stringstream ss;
......
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