Commit f5aebbd4 authored by Peter Eastman's avatar Peter Eastman
Browse files

Eliminated Stream and related classes, replacing their functionality with UpdateStateDataKernel.

parent 21d67074
......@@ -99,11 +99,12 @@ public:
};
/**
* This kernel is invoked to get or set the current time.
* This kernel provides methods for setting and retrieving various state data: time, positions,
* velocities, and forces.
*/
class ReferenceUpdateTimeKernel : public UpdateTimeKernel {
class ReferenceUpdateStateDataKernel : public UpdateStateDataKernel {
public:
ReferenceUpdateTimeKernel(std::string name, const Platform& platform, ReferencePlatform::PlatformData& data) : UpdateTimeKernel(name, platform), data(data) {
ReferenceUpdateStateDataKernel(std::string name, const Platform& platform, ReferencePlatform::PlatformData& data) : UpdateStateDataKernel(name, platform), data(data) {
}
/**
* Initialize the kernel.
......@@ -123,6 +124,36 @@ public:
* @param context the context in which to execute this kernel
*/
void setTime(ContextImpl& context, double time);
/**
* Get the positions of all particles.
*
* @param positions on exit, this contains the particle positions
*/
void getPositions(ContextImpl& context, std::vector<Vec3>& positions);
/**
* Set the positions of all particles.
*
* @param positions a vector containg the particle positions
*/
void setPositions(ContextImpl& context, const std::vector<Vec3>& positions);
/**
* Get the velocities of all particles.
*
* @param velocities on exit, this contains the particle velocities
*/
void getVelocities(ContextImpl& context, std::vector<Vec3>& velocities);
/**
* Set the velocities of all particles.
*
* @param velocities a vector containg the particle velocities
*/
void setVelocities(ContextImpl& context, const std::vector<Vec3>& velocities);
/**
* Get the current forces on all particles.
*
* @param forces on exit, this contains the forces
*/
void getForces(ContextImpl& context, std::vector<Vec3>& forces);
private:
ReferencePlatform::PlatformData& data;
};
......
......@@ -40,7 +40,7 @@ using namespace OpenMM;
ReferencePlatform::ReferencePlatform() {
ReferenceKernelFactory* factory = new ReferenceKernelFactory();
registerKernelFactory(CalcForcesAndEnergyKernel::Name(), factory);
registerKernelFactory(UpdateTimeKernel::Name(), factory);
registerKernelFactory(UpdateStateDataKernel::Name(), factory);
registerKernelFactory(CalcHarmonicBondForceKernel::Name(), factory);
registerKernelFactory(CalcHarmonicAngleForceKernel::Name(), factory);
registerKernelFactory(CalcPeriodicTorsionForceKernel::Name(), factory);
......@@ -63,15 +63,39 @@ bool ReferencePlatform::supportsDoublePrecision() const {
return (sizeof(RealOpenMM) >= sizeof(double));
}
const StreamFactory& ReferencePlatform::getDefaultStreamFactory() const {
return defaultStreamFactory;
}
void ReferencePlatform::contextCreated(ContextImpl& context) const {
context.setPlatformData(new PlatformData());
context.setPlatformData(new PlatformData(context.getSystem().getNumParticles()));
}
void ReferencePlatform::contextDestroyed(ContextImpl& context) const {
PlatformData* data = reinterpret_cast<PlatformData*>(context.getPlatformData());
delete data;
}
ReferencePlatform::PlatformData::PlatformData(int numParticles) : time(0.0), stepCount(0), numParticles(numParticles) {
RealOpenMM** positions = new RealOpenMM*[numParticles];
RealOpenMM** velocities = new RealOpenMM*[numParticles];
RealOpenMM** forces = new RealOpenMM*[numParticles];
for (int i = 0; i < numParticles; ++i) {
positions[i] = new RealOpenMM[3];
velocities[i] = new RealOpenMM[3];
forces[i] = new RealOpenMM[3];
}
this->positions = positions;
this->velocities = velocities;
this->forces = forces;
}
ReferencePlatform::PlatformData::~PlatformData() {
RealOpenMM** positions = (RealOpenMM**) this->positions;
RealOpenMM** velocities = (RealOpenMM**) this->velocities;
RealOpenMM** forces = (RealOpenMM**) this->forces;
for (int i = 0; i < numParticles; ++i) {
delete[] positions[i];
delete[] velocities[i];
delete[] forces[i];
}
delete[] positions;
delete[] velocities;
delete[] forces;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/OpenMMException.h"
#include "ReferenceStreamFactory.h"
#include "ReferenceFloatStreamImpl.h"
#include "ReferenceIntStreamImpl.h"
using namespace OpenMM;
StreamImpl* ReferenceStreamFactory::createStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform, ContextImpl& context) const {
switch (type) {
case Stream::Float:
case Stream::Float2:
case Stream::Float3:
case Stream::Float4:
case Stream::Double:
case Stream::Double2:
case Stream::Double3:
case Stream::Double4:
return new ReferenceFloatStreamImpl(name, size, type, platform);
case Stream::Integer:
case Stream::Integer2:
case Stream::Integer3:
case Stream::Integer4:
return new ReferenceIntStreamImpl(name, size, type, platform);
}
throw OpenMMException("Tried to create a Stream with an illegal DataType.");
}
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