Unverified Commit 7f87c446 authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #2387 from peastman/cleanup

Minor code cleanup to reference platform
parents ba9f33c7 6e306f2c
......@@ -319,17 +319,8 @@ other Platforms.
When using the reference Platform, the “platform-specific data” stored in
ContextImpl is of type ReferencePlatform::PlatformData, which is declared in
ReferencePlatform.h. Several of the fields in this class are declared as void*
to avoid having to include SimTKOpenMMRealType.h in ReferencePlatform.h. If you
look in ReferenceKernels.cpp, you will find code for extracting the correct
values of these fields. For example:
::
static vector<Vec3>& extractPositions(ContextImpl& context) {
ReferencePlatform::PlatformData* data =
reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->positions);
}
ReferencePlatform.h. It has fields for storing positions, velocities, box
vectors, and other types of data.
The PlatformData’s vector of forces contains one element for each particle. At
the start of each force evaluation, all elements of it are set to zero. Each
......
......@@ -58,37 +58,37 @@ using namespace std;
static vector<Vec3>& extractPositions(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->positions);
return *data->positions;
}
static vector<Vec3>& extractVelocities(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->velocities);
return *data->velocities;
}
static vector<Vec3>& extractForces(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->forces);
return *data->forces;
}
static Vec3& extractBoxSize(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *(Vec3*) data->periodicBoxSize;
return *data->periodicBoxSize;
}
static Vec3* extractBoxVectors(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return (Vec3*) data->periodicBoxVectors;
return data->periodicBoxVectors;
}
static ReferenceConstraints& extractConstraints(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *(ReferenceConstraints*) data->constraints;
return *data->constraints;
}
static map<string, double>& extractEnergyParameterDerivatives(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((map<string, double>*) data->energyParameterDerivatives);
return *data->energyParameterDerivatives;
}
/**
......
......@@ -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) 2008-2016 Stanford University and the Authors. *
* Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -35,6 +35,9 @@
#include "openmm/Platform.h"
#include "openmm/System.h"
#include "openmm/internal/windowsExport.h"
#include "ReferenceConstraints.h"
#include <map>
#include <vector>
namespace OpenMM {
......@@ -62,13 +65,13 @@ public:
~PlatformData();
int numParticles, stepCount;
double time;
void* positions;
void* velocities;
void* forces;
void* periodicBoxSize;
void* periodicBoxVectors;
void* constraints;
void* energyParameterDerivatives;
std::vector<Vec3>* positions;
std::vector<Vec3>* velocities;
std::vector<Vec3>* forces;
Vec3* periodicBoxSize;
Vec3* periodicBoxVectors;
ReferenceConstraints* constraints;
std::map<std::string, double>* energyParameterDerivatives;
};
} // namespace OpenMM
......
......@@ -91,37 +91,37 @@ using namespace std;
static vector<Vec3>& extractPositions(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->positions);
return *data->positions;
}
static vector<Vec3>& extractVelocities(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->velocities);
return *data->velocities;
}
static vector<Vec3>& extractForces(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->forces);
return *data->forces;
}
static Vec3& extractBoxSize(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *(Vec3*) data->periodicBoxSize;
return *data->periodicBoxSize;
}
static Vec3* extractBoxVectors(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return (Vec3*) data->periodicBoxVectors;
return data->periodicBoxVectors;
}
static ReferenceConstraints& extractConstraints(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *(ReferenceConstraints*) data->constraints;
return *data->constraints;
}
static map<string, double>& extractEnergyParameterDerivatives(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((map<string, double>*) data->energyParameterDerivatives);
return *data->energyParameterDerivatives;
}
/**
......
......@@ -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) 2008-2016 Stanford University and the Authors. *
* Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -30,14 +30,11 @@
* -------------------------------------------------------------------------- */
#include "ReferencePlatform.h"
#include "ReferenceConstraints.h"
#include "ReferenceKernelFactory.h"
#include "ReferenceKernels.h"
#include "openmm/internal/ContextImpl.h"
#include "SimTKOpenMMRealType.h"
#include "openmm/Vec3.h"
#include <map>
#include <vector>
using namespace OpenMM;
using namespace std;
......@@ -107,11 +104,11 @@ ReferencePlatform::PlatformData::PlatformData(const System& system) : time(0.0),
}
ReferencePlatform::PlatformData::~PlatformData() {
delete (vector<Vec3>*) positions;
delete (vector<Vec3>*) velocities;
delete (vector<Vec3>*) forces;
delete (Vec3*) periodicBoxSize;
delete[] (Vec3*) periodicBoxVectors;
delete (ReferenceConstraints*) constraints;
delete (map<string, double>*) energyParameterDerivatives;
delete positions;
delete velocities;
delete forces;
delete periodicBoxSize;
delete[] periodicBoxVectors;
delete constraints;
delete energyParameterDerivatives;
}
......@@ -58,27 +58,27 @@ using namespace std;
static vector<Vec3>& extractPositions(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->positions);
return *data->positions;
}
static vector<Vec3>& extractVelocities(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->velocities);
return *data->velocities;
}
static vector<Vec3>& extractForces(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->forces);
return *data->forces;
}
static Vec3& extractBoxSize(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *(Vec3*) data->periodicBoxSize;
return *data->periodicBoxSize;
}
static Vec3* extractBoxVectors(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return (Vec3*) data->periodicBoxVectors;
return data->periodicBoxVectors;
}
// ***************************************************************************
......
......@@ -43,22 +43,22 @@ using namespace std;
static vector<Vec3>& extractPositions(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->positions);
return *data->positions;
}
static vector<Vec3>& extractVelocities(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->velocities);
return *data->velocities;
}
static vector<Vec3>& extractForces(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->forces);
return *data->forces;
}
static ReferenceConstraints& extractConstraints(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *(ReferenceConstraints*) data->constraints;
return *data->constraints;
}
static double computeShiftedKineticEnergy(ContextImpl& context, vector<double>& inverseMasses, double timeShift) {
......
......@@ -39,17 +39,17 @@ using namespace std;
static vector<Vec3>& extractPositions(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->positions);
return *data->positions;
}
static vector<Vec3>& extractVelocities(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->velocities);
return *data->velocities;
}
static vector<Vec3>& extractForces(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<Vec3>*) data->forces);
return *data->forces;
}
ReferenceIntegrateRPMDStepKernel::~ReferenceIntegrateRPMDStepKernel() {
......
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