"platforms/opencl/tests/TestOpenCLGayBerneForce.cpp" did not exist on "ba2503b5d17458e991f3bb649332b4f021f97e4d"
Commit f5aebbd4 authored by Peter Eastman's avatar Peter Eastman
Browse files

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

parent 21d67074
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
namespace OpenMM { namespace OpenMM {
/** /**
* A Kernel encapsulates a particular implementation of a calculation that can be performed on Streams. * A Kernel encapsulates a particular implementation of a calculation that can be performed on the data
* Kernel objects are created by Platforms: * in a Context. Kernel objects are created by Platforms:
* *
* <pre> * <pre>
* Kernel kernel = platform.createKernel(kernelName); * Kernel kernel = platform.createKernel(kernelName);
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "Stream.h"
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -44,12 +43,11 @@ class Context; ...@@ -44,12 +43,11 @@ class Context;
class ContextImpl; class ContextImpl;
class Kernel; class Kernel;
class KernelFactory; class KernelFactory;
class StreamFactory;
/** /**
* A Platform defines an implementation of all the kernels and streams needed to perform some calculation. * A Platform defines an implementation of all the kernels needed to perform some calculation.
* More precisely, a Platform object acts as a registry for a set of KernelFactory and StreamFactory * More precisely, a Platform object acts as a registry for a set of KernelFactory
* objects which together implement the kernels and streams. The Platform class, in turn, provides a * objects which together implement the kernels. The Platform class, in turn, provides a
* static registry of all available Platform objects. * static registry of all available Platform objects.
* *
* To get a Platform object, call * To get a Platform object, call
...@@ -60,7 +58,7 @@ class StreamFactory; ...@@ -60,7 +58,7 @@ class StreamFactory;
* *
* passing in the names of all kernels that will be required for the calculation you plan to perform. It * passing in the names of all kernels that will be required for the calculation you plan to perform. It
* will return the fastest available Platform which provides implementations of all the specified kernels. * will return the fastest available Platform which provides implementations of all the specified kernels.
* You can then call createKernel() and createStream() to construct particular kernels and streams as needed. * You can then call createKernel() to construct particular kernels as needed.
*/ */
class OPENMM_EXPORT Platform { class OPENMM_EXPORT Platform {
...@@ -79,7 +77,7 @@ public: ...@@ -79,7 +77,7 @@ public:
virtual double getSpeed() const = 0; virtual double getSpeed() const = 0;
/** /**
* Get whether this Platform supports double precision arithmetic. If this returns false, the platform * Get whether this Platform supports double precision arithmetic. If this returns false, the platform
* is permitted to implement double precision streams internally as single precision. * is permitted to represent double precision values internally as single precision.
*/ */
virtual bool supportsDoublePrecision() const = 0; virtual bool supportsDoublePrecision() const = 0;
/** /**
...@@ -118,11 +116,6 @@ public: ...@@ -118,11 +116,6 @@ public:
* @param value the value to set for the property * @param value the value to set for the property
*/ */
void setPropertyDefaultValue(const std::string& property, const std::string& value); void setPropertyDefaultValue(const std::string& property, const std::string& value);
/**
* Get the default StreamFactory for this Platform. It will be used to create Streams whenever a
* different StreamFactory has not been registered for the requested stream name.
*/
virtual const StreamFactory& getDefaultStreamFactory() const = 0;
/** /**
* This is called whenever a new Context is created. It gives the Platform a chance to initialize * This is called whenever a new Context is created. It gives the Platform a chance to initialize
* the context and store platform-specific data in it. * the context and store platform-specific data in it.
...@@ -142,15 +135,6 @@ public: ...@@ -142,15 +135,6 @@ public:
* @param factory the factory to use for creating Kernels with the specified name * @param factory the factory to use for creating Kernels with the specified name
*/ */
void registerKernelFactory(const std::string& name, KernelFactory* factory); void registerKernelFactory(const std::string& name, KernelFactory* factory);
/**
* Register a StreamFactory which should be used to create Streams with a particular name.
* The Platform takes over ownership of the factory, and will delete it when the Platform itself
* is deleted.
*
* @param name the stream name for which the factory should be used
* @param factory the factory to use for creating Streams with the specified name
*/
void registerStreamFactory(const std::string& name, StreamFactory* factory);
/** /**
* Determine whether this Platforms provides implementations of a set of kernels. * Determine whether this Platforms provides implementations of a set of kernels.
* *
...@@ -172,20 +156,6 @@ public: ...@@ -172,20 +156,6 @@ public:
* @return a newly created Kernel object * @return a newly created Kernel object
*/ */
Kernel createKernel(const std::string& name, ContextImpl& context) const; Kernel createKernel(const std::string& name, ContextImpl& context) const;
/**
* Create a Stream object. If you call this method multiple times for different contexts with the same name,
* the returned Streams are independent and do not interact with each other. This means
* that it is possible to have multiple simulations in progress at one time without them
* interfering.
*
* If a StreamFactory has been registered for the specified name, it will be used to create
* the Stream. Otherwise, the default StreamFactory will be used.
*
* @param name the name of the Stream to get
* @param context the context for which to create a Stream
* @return a newly created Stream object
*/
Stream createStream(const std::string& name, int size, Stream::DataType type, ContextImpl& context) const;
/** /**
* Register a new Platform. * Register a new Platform.
*/ */
...@@ -249,7 +219,6 @@ protected: ...@@ -249,7 +219,6 @@ protected:
std::vector<std::string> platformProperties; std::vector<std::string> platformProperties;
private: private:
std::map<std::string, KernelFactory*> kernelFactories; std::map<std::string, KernelFactory*> kernelFactories;
std::map<std::string, StreamFactory*> streamFactories;
std::map<std::string, std::string> defaultProperties; std::map<std::string, std::string> defaultProperties;
static std::vector<Platform*>& getPlatforms(); static std::vector<Platform*>& getPlatforms();
}; };
......
#ifndef OPENMM_STREAM_H_
#define OPENMM_STREAM_H_
/* -------------------------------------------------------------------------- *
* 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 <string>
#include "openmm/internal/windowsExport.h"
namespace OpenMM {
class OPENMM_EXPORT StreamImpl;
/**
* A Stream encapsulates a particular implementation of a stream of data elements. A Stream has three
* fundamental properties:
*
* <ul>
* <li>A name. Although a Stream's name has no impact on the API for working with it, a particular platform
* may choose to implement different Streams in different ways. The name allows it to distinguish them.</li>
* <li>A size. This is the number of data elements contained in the stream.</li>
* <li>A data type. There are three basic data types: 32 bit floating point (Float), 64 bit floating point
* (Double), and 32 bit signed integers (Integer). In addition, there are compound data types which allow
* a single stream element to contain multiple values. For example, the data type Float3 indicates that
* each stream element is an array of three 32 bit floats.</li>
* </ul>
* Stream objects are created by Platforms:
*
* <pre>
* Stream stream = platform.createStream(streamName, size, dataType);
* </pre>
*
* A Stream is an opaque reference to the stream data. You cannot access stream elements directly. Instead,
* you must query or modify the stream data by calling methods such as loadFromArray() and saveToArray().
* These are potentially expensive operations, since they may involve transferring data between main memory
* and video memory, so they should be called sparing.
*
* It is important to remember that the data type dictates only the API for working with the Stream, not how
* it is represented internally. For example, even if a Stream object has type Double, a particular Platform
* may choose to implement it internally with single precision values.
*/
class OPENMM_EXPORT Stream {
public:
Stream();
Stream(const Stream& copy);
~Stream();
Stream& operator=(const Stream& copy);
/**
* This is an enumeration of the allowed data types for a Stream.
*/
enum DataType {Float, Float2, Float3, Float4, Double, Double2, Double3, Double4, Integer, Integer2, Integer3, Integer4};
/**
* Get the name of this Stream.
*/
std::string getName() const;
/**
* Get the number of elements in this stream.
*/
int getSize() const;
/**
* Get the data type of each element in the stream.
*/
Stream::DataType getDataType() const;
/**
* Copy the contents of an array into this stream.
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct data type for this stream. If the stream has a compound data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
void loadFromArray(const void* array);
/**
* Copy the contents of this stream into an array.
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct data type for this stream. If the stream has a compound data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
void saveToArray(void* array) const;
/**
* Set every element of this stream to the same value.
*
* @param a pointer to the value. It is assumed to be of the correct data type for this stream.
*/
void fillWithValue(void* value);
/**
* Get the object which implements this Stream.
*/
const StreamImpl& getImpl() const;
/**
* Get the object which implements this Stream.
*/
StreamImpl& getImpl();
private:
friend class Platform;
/**
* Create a StreamImpl.
*
* @param name the name of the stream to create
*/
Stream(StreamImpl* impl);
StreamImpl* impl;
};
} // namespace OpenMM
#endif /*OPENMM_STREAM_H_*/
#ifndef OPENMM_STREAMFACTORY_H_
#define OPENMM_STREAMFACTORY_H_
/* -------------------------------------------------------------------------- *
* 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 "StreamImpl.h"
#include "openmm/internal/windowsExport.h"
namespace OpenMM {
/**
* A StreamFactory is an object that can create StreamImpls. This is an abstract class.
* Each Platform maintains a list of StreamFactory objects that it uses to create
* StreamImpls as needed.
*/
class OPENMM_EXPORT StreamFactory {
public:
/**
* Create a StreamImpl.
*
* @param name the name of the stream to create
* @param size the number of elements in the stream
* @param type the data type of each element in the stream
* @param context the context the kernel will belong to
*/
virtual StreamImpl* createStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform, ContextImpl& context) const = 0;
virtual ~StreamFactory() {
}
};
} // namespace OpenMM
#endif /*OPENMM_STREAMFACTORY_H_*/
#ifndef OPENMM_STREAMIMPL_H_
#define OPENMM_STREAMIMPL_H_
/* -------------------------------------------------------------------------- *
* 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 "Platform.h"
#include "Stream.h"
#include <string>
#include <cassert>
namespace OpenMM {
/**
* A StreamImpl defines the internal implementation of a Stream object.
*/
class OPENMM_EXPORT StreamImpl {
public:
/**
* Create a StreamImpl.
*
* @param name the name of the stream to create
* @param size the number of elements in the stream
* @param type the data type of each element in the stream
* @param platform the Platform that created this kernel
*/
StreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform);
virtual ~StreamImpl() {
assert(referenceCount == 0);
}
/**
* Get the name of this stream.
*/
std::string getName() const;
/**
* Get the number of elements in this stream.
*/
int getSize() const;
/**
* Get the data type of each element in the stream.
*/
Stream::DataType getDataType() const;
/**
* Get the Platform that created this KernelImpl.
*/
const Platform& getPlatform();
/**
* Copy the contents of an array into this stream.
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct data type for this stream. If the stream has a compound data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
virtual void loadFromArray(const void* array) = 0;
/**
* Copy the contents of this stream into an array.
*
* @param array a pointer to the start of the array. The array is assumed to have the same length as this stream,
* and to contain elements of the correct data type for this stream. If the stream has a compound data type, all
* the values should be packed into a single array: all the values for the first element, followed by all the values
* for the next element, etc.
*/
virtual void saveToArray(void* array) = 0;
/**
* Set every element of this stream to the same value.
*
* @param a pointer to the value. It is assumed to be of the correct data type for this stream.
*/
virtual void fillWithValue(void* value) = 0;
private:
friend class Stream;
std::string name;
int size;
Stream::DataType type;
const Platform* platform;
int referenceCount;
};
} // namespace OpenMM
#endif /*OPENMM_STREAMIMPL_H_*/
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
#include "openmm/PeriodicTorsionForce.h" #include "openmm/PeriodicTorsionForce.h"
#include "openmm/RBTorsionForce.h" #include "openmm/RBTorsionForce.h"
#include "openmm/NonbondedForce.h" #include "openmm/NonbondedForce.h"
#include "openmm/Stream.h"
#include "openmm/System.h" #include "openmm/System.h"
#include "openmm/VariableLangevinIntegrator.h" #include "openmm/VariableLangevinIntegrator.h"
#include "openmm/VariableVerletIntegrator.h" #include "openmm/VariableVerletIntegrator.h"
...@@ -108,14 +107,15 @@ public: ...@@ -108,14 +107,15 @@ 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 UpdateTimeKernel : public KernelImpl { class UpdateStateDataKernel : public KernelImpl {
public: public:
static std::string Name() { static std::string Name() {
return "UpdateTime"; return "UpdateTime";
} }
UpdateTimeKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) { UpdateStateDataKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel. * Initialize the kernel.
...@@ -136,6 +136,36 @@ public: ...@@ -136,6 +136,36 @@ public:
* @param time the time * @param time the time
*/ */
virtual void setTime(ContextImpl& context, double time) = 0; virtual void setTime(ContextImpl& context, double time) = 0;
/**
* Get the positions of all particles.
*
* @param positions on exit, this contains the particle positions
*/
virtual void getPositions(ContextImpl& context, std::vector<Vec3>& positions) = 0;
/**
* Set the positions of all particles.
*
* @param positions a vector containg the particle positions
*/
virtual void setPositions(ContextImpl& context, const std::vector<Vec3>& positions) = 0;
/**
* Get the velocities of all particles.
*
* @param velocities on exit, this contains the particle velocities
*/
virtual void getVelocities(ContextImpl& context, std::vector<Vec3>& velocities) = 0;
/**
* Set the velocities of all particles.
*
* @param velocities a vector containg the particle velocities
*/
virtual void setVelocities(ContextImpl& context, const std::vector<Vec3>& velocities) = 0;
/**
* Get the current forces on all particles.
*
* @param forces on exit, this contains the forces
*/
virtual void getForces(ContextImpl& context, std::vector<Vec3>& forces) = 0;
}; };
/** /**
......
...@@ -33,9 +33,7 @@ ...@@ -33,9 +33,7 @@
#include "openmm/Context.h" #include "openmm/Context.h"
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "openmm/Kernel.h" #include "openmm/Kernel.h"
#include "openmm/Stream.h"
#include "openmm/KernelFactory.h" #include "openmm/KernelFactory.h"
#include "openmm/StreamFactory.h"
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#include <sstream> #include <sstream>
...@@ -64,15 +62,10 @@ static int platformInitializer = registerPlatforms(); ...@@ -64,15 +62,10 @@ static int platformInitializer = registerPlatforms();
Platform::~Platform() { Platform::~Platform() {
set<KernelFactory*> uniqueKernelFactories; set<KernelFactory*> uniqueKernelFactories;
set<StreamFactory*> uniqueStreamFactories;
for (map<string, KernelFactory*>::const_iterator iter = kernelFactories.begin(); iter != kernelFactories.end(); ++iter) for (map<string, KernelFactory*>::const_iterator iter = kernelFactories.begin(); iter != kernelFactories.end(); ++iter)
uniqueKernelFactories.insert(iter->second); uniqueKernelFactories.insert(iter->second);
for (map<string, StreamFactory*>::const_iterator iter = streamFactories.begin(); iter != streamFactories.end(); ++iter)
uniqueStreamFactories.insert(iter->second);
for (set<KernelFactory*>::const_iterator iter = uniqueKernelFactories.begin(); iter != uniqueKernelFactories.end(); ++iter) for (set<KernelFactory*>::const_iterator iter = uniqueKernelFactories.begin(); iter != uniqueKernelFactories.end(); ++iter)
delete *iter; delete *iter;
for (set<StreamFactory*>::const_iterator iter = uniqueStreamFactories.begin(); iter != uniqueStreamFactories.end(); ++iter)
delete *iter;
} }
const vector<string>& Platform::getPropertyNames() { const vector<string>& Platform::getPropertyNames() {
...@@ -108,10 +101,6 @@ void Platform::registerKernelFactory(const string& name, KernelFactory* factory) ...@@ -108,10 +101,6 @@ void Platform::registerKernelFactory(const string& name, KernelFactory* factory)
kernelFactories[name] = factory; kernelFactories[name] = factory;
} }
void Platform::registerStreamFactory(const string& name, StreamFactory* factory) {
streamFactories[name] = factory;
}
bool Platform::supportsKernels(const vector<string>& kernelNames) const { bool Platform::supportsKernels(const vector<string>& kernelNames) const {
for (int i = 0; i < (int) kernelNames.size(); ++i) for (int i = 0; i < (int) kernelNames.size(); ++i)
if (kernelFactories.find(kernelNames[i]) == kernelFactories.end()) if (kernelFactories.find(kernelNames[i]) == kernelFactories.end())
...@@ -125,12 +114,6 @@ Kernel Platform::createKernel(const string& name, ContextImpl& context) const { ...@@ -125,12 +114,6 @@ Kernel Platform::createKernel(const string& name, ContextImpl& context) const {
return Kernel(kernelFactories.find(name)->second->createKernelImpl(name, *this, context)); return Kernel(kernelFactories.find(name)->second->createKernelImpl(name, *this, context));
} }
Stream Platform::createStream(const string& name, int size, Stream::DataType type, ContextImpl& context) const {
if (streamFactories.find(name) == streamFactories.end())
return Stream(getDefaultStreamFactory().createStreamImpl(name, size, type, *this, context));
return Stream(streamFactories.find(name)->second->createStreamImpl(name, size, type, *this, context));
}
vector<Platform*>& Platform::getPlatforms() { vector<Platform*>& Platform::getPlatforms() {
static vector<Platform*> platforms; static vector<Platform*> platforms;
return platforms; return platforms;
......
/* -------------------------------------------------------------------------- *
* 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/Stream.h"
#include "openmm/StreamImpl.h"
using namespace OpenMM;
using namespace std;
Stream::Stream() : impl(0) {
}
Stream::Stream(StreamImpl* impl) : impl(impl) {
}
Stream::Stream(const Stream& copy) : impl(copy.impl) {
impl->referenceCount++;
}
Stream::~Stream() {
if (impl) {
impl->referenceCount--;
if (impl->referenceCount == 0)
delete impl;
}
}
Stream& Stream::operator=(const Stream& copy) {
impl = copy.impl;
impl->referenceCount++;
return *this;
}
string Stream::getName() const {
return impl->getName();
}
int Stream::getSize() const {
return impl->getSize();
}
Stream::DataType Stream::getDataType() const {
return impl->getDataType();
}
void Stream::loadFromArray(const void* array) {
impl->loadFromArray(array);
}
void Stream::saveToArray(void* array) const {
impl->saveToArray(array);
}
void Stream::fillWithValue(void* value) {
impl->fillWithValue(value);
}
const StreamImpl& Stream::getImpl() const {
return *impl;
}
StreamImpl& Stream::getImpl() {
return *impl;
}
/* -------------------------------------------------------------------------- *
* 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/StreamImpl.h"
using namespace OpenMM;
using namespace std;
StreamImpl::StreamImpl(string name, int size, Stream::DataType type, const Platform& platform) : name(name), size(size), type(type), platform(&platform), referenceCount(1) {
}
std::string StreamImpl::getName() const {
return name;
}
int StreamImpl::getSize() const {
return size;
}
Stream::DataType StreamImpl::getDataType() const {
return type;
}
const Platform& StreamImpl::getPlatform() {
return *platform;
}
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
return owner; return owner;
} }
void updateContextState(ContextImpl& context); void updateContextState(ContextImpl& context);
void calcForces(ContextImpl& context, Stream& forces) { void calcForces(ContextImpl& context) {
// This force doesn't apply forces to particles. // This force doesn't apply forces to particles.
} }
double calcEnergy(ContextImpl& context) { double calcEnergy(ContextImpl& context) {
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
return owner; return owner;
} }
void updateContextState(ContextImpl& context); void updateContextState(ContextImpl& context);
void calcForces(ContextImpl& context, Stream& forces) { void calcForces(ContextImpl& context) {
// This force doesn't apply forces to particles. // This force doesn't apply forces to particles.
} }
double calcEnergy(ContextImpl& context) { double calcEnergy(ContextImpl& context) {
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "openmm/Kernel.h" #include "openmm/Kernel.h"
#include "openmm/Platform.h" #include "openmm/Platform.h"
#include "openmm/Stream.h" #include "openmm/Vec3.h"
#include <map> #include <map>
#include <vector> #include <vector>
...@@ -81,32 +81,43 @@ public: ...@@ -81,32 +81,43 @@ public:
return *platform; return *platform;
} }
/** /**
* Get the Stream containing the current position of each particle. * Get the current time (in picoseconds).
*/ */
Stream& getPositions() { double getTime() const;
return positions;
}
/** /**
* Get the Stream containing the current velocity of each particle. * Set the current time (in picoseconds).
*/ */
Stream& getVelocities() { void setTime(double t);
return velocities;
}
/** /**
* Get the Stream containing the force on each particle that was calculated by * Get the positions of all particles.
* the most recent call to calcForces(). *
* @param positions on exit, this contains the particle positions
*/ */
Stream& getForces() { void getPositions(std::vector<Vec3>& positions);
return forces;
}
/** /**
* Get the current time (in picoseconds). * Set the positions of all particles.
*
* @param positions a vector containg the particle positions
*/ */
double getTime() const; void setPositions(const std::vector<Vec3>& positions);
/** /**
* Set the current time (in picoseconds). * Get the velocities of all particles.
*
* @param velocities on exit, this contains the particle velocities
*/ */
void setTime(double t); void getVelocities(std::vector<Vec3>& velocities);
/**
* Set the velocities of all particles.
*
* @param velocities a vector containg the particle velocities
*/
void setVelocities(const std::vector<Vec3>& velocities);
/**
* Get the current forces on all particles.
*
* @param forces on exit, this contains the forces
*/
void getForces(std::vector<Vec3>& forces);
/** /**
* Get the value of an adjustable parameter. If there is no parameter with the specified name, this * Get the value of an adjustable parameter. If there is no parameter with the specified name, this
* throws an exception. * throws an exception.
...@@ -160,8 +171,7 @@ private: ...@@ -160,8 +171,7 @@ private:
std::vector<ForceImpl*> forceImpls; std::vector<ForceImpl*> forceImpls;
std::map<std::string, double> parameters; std::map<std::string, double> parameters;
Platform* platform; Platform* platform;
Stream positions, velocities, forces; Kernel initializeForcesKernel, kineticEnergyKernel, updateStateDataKernel;
Kernel initializeForcesKernel, kineticEnergyKernel, updateTimeKernel;
void* platformData; void* platformData;
}; };
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context, Stream& forces); void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context); double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
......
...@@ -40,7 +40,6 @@ namespace OpenMM { ...@@ -40,7 +40,6 @@ namespace OpenMM {
class Force; class Force;
class ContextImpl; class ContextImpl;
class Stream;
/** /**
* A ForceImpl provides the internal implementation of a Force. When a Context is * A ForceImpl provides the internal implementation of a Force. When a Context is
...@@ -82,7 +81,7 @@ public: ...@@ -82,7 +81,7 @@ public:
* @param context the context in which the system is being simulated * @param context the context in which the system is being simulated
* @param forces new forces should be added to the value already stored in this * @param forces new forces should be added to the value already stored in this
*/ */
virtual void calcForces(ContextImpl& context, Stream& forces) = 0; virtual void calcForces(ContextImpl& context) = 0;
/** /**
* Calculate this ForceImpl's contribution to the potential energy of the system. * Calculate this ForceImpl's contribution to the potential energy of the system.
* *
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context, Stream& forces); void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context); double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context, Stream& forces); void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context); double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context, Stream& forces); void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context); double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context, Stream& forces); void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context); double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context, Stream& forces); void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context); double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context, Stream& forces); void calcForces(ContextImpl& context);
double calcEnergy(ContextImpl& context); double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
......
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