Commit cc6a0ac8 authored by Andy Simmonett's avatar Andy Simmonett
Browse files

Fix precision issues in Drude tests

parent 012f6eb4
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "openmm/internal/AssertionUtilities.h" #include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h" #include "openmm/Context.h"
#include "openmm/NonbondedForce.h" #include "openmm/NonbondedForce.h"
#include "openmm/OpenMMException.h"
#include "openmm/Platform.h" #include "openmm/Platform.h"
#include "openmm/System.h" #include "openmm/System.h"
#include "openmm/VerletIntegrator.h" #include "openmm/VerletIntegrator.h"
...@@ -43,8 +44,6 @@ ...@@ -43,8 +44,6 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
bool doublePrecision = false;
void validateForce(System& system, vector<Vec3>& positions, double expectedEnergy) { void validateForce(System& system, vector<Vec3>& positions, double expectedEnergy) {
// Given a System containing a Drude force, check that its energy has the expected value. // Given a System containing a Drude force, check that its energy has the expected value.
...@@ -55,9 +54,16 @@ void validateForce(System& system, vector<Vec3>& positions, double expectedEnerg ...@@ -55,9 +54,16 @@ void validateForce(System& system, vector<Vec3>& positions, double expectedEnerg
ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), 1e-5); ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), 1e-5);
// Try moving each particle along each axis, and see if the energy changes by the correct amount. // Try moving each particle along each axis, and see if the energy changes by the correct amount.
double offset = 1e-3;
double offset = doublePrecision ? 1e-3 : 1e-2; double TOL = 1e-5;
const double TOL = doublePrecision ? 1e-5 : 5e-4; try {
if (platform.getPropertyValue(context, "Precision") != "double") {
offset = 1e-2;
TOL = 5e-4;
}
} catch(OpenMMException) {
// The defaults above are for double precision, which is assumed in this case
}
for (int i = 0; i < system.getNumParticles(); i++) for (int i = 0; i < system.getNumParticles(); i++)
for (int j = 0; j < 3; j++) { for (int j = 0; j < 3; j++) {
vector<Vec3> offsetPos = positions; vector<Vec3> offsetPos = positions;
...@@ -196,7 +202,6 @@ void runPlatformTests(); ...@@ -196,7 +202,6 @@ void runPlatformTests();
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
try { try {
setupKernels(argc, argv); setupKernels(argc, argv);
if (argc > 0 && std::string(argv[1]) == "double") doublePrecision = true;
testSingleParticle(); testSingleParticle();
testAnisotropicParticle(); testAnisotropicParticle();
testThole(); testThole();
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "openmm/internal/AssertionUtilities.h" #include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h" #include "openmm/Context.h"
#include "openmm/NonbondedForce.h" #include "openmm/NonbondedForce.h"
#include "openmm/OpenMMException.h"
#include "openmm/Platform.h" #include "openmm/Platform.h"
#include "openmm/System.h" #include "openmm/System.h"
#include "openmm/VirtualSite.h" #include "openmm/VirtualSite.h"
...@@ -106,6 +107,14 @@ void testWater() { ...@@ -106,6 +107,14 @@ void testWater() {
State state = context.getState(State::Energy); State state = context.getState(State::Energy);
double initialEnergy; double initialEnergy;
int numSteps = 1000; int numSteps = 1000;
double maxNorm = 1.0;
try {
if (platform.getPropertyValue(context, "Precision") != "double") {
maxNorm = 5.0;
}
} catch(OpenMMException) {
// The defaults above are for double precision, which is assumed in this case
}
for (int i = 0; i < numSteps; i++) { for (int i = 0; i < numSteps; i++) {
integ.step(1); integ.step(1);
state = context.getState(State::Energy | State::Forces); state = context.getState(State::Energy | State::Forces);
...@@ -118,7 +127,7 @@ void testWater() { ...@@ -118,7 +127,7 @@ void testWater() {
for (int j = 1; j < (int) force.size(); j += 5) for (int j = 1; j < (int) force.size(); j += 5)
norm += sqrt(force[j].dot(force[j])); norm += sqrt(force[j].dot(force[j]));
norm = (norm/numMolecules); norm = (norm/numMolecules);
ASSERT(norm < 1.0); ASSERT(norm < maxNorm);
} }
} }
......
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