OpenMPCD
CUDA/MPCSolute/Base.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the OpenMPCD::CUDA::MPCSolute::Base class.
4  */
5 
6 #ifndef OPENMPCD_CUDA_MPCSOLUTE_BASE_HPP
7 #define OPENMPCD_CUDA_MPCSOLUTE_BASE_HPP
8 
11 #include <OpenMPCD/Exceptions.hpp>
14 #include <OpenMPCD/Vector3D.hpp>
15 
16 namespace OpenMPCD
17 {
18 namespace CUDA
19 {
20  class Simulation;
21 
22 /**
23  * Namespace for MPC Solute classes.
24  */
25 namespace MPCSolute
26 {
27 
28 /**
29  * Base class for MPC solutes.
30  *
31  * @tparam PositionCoordinate The type to store position coordinates.
32  * @tparam VelocityCoordinate The type to store velocity coordinates.
33  */
34 template<typename PositionCoordinate, typename VelocityCoordinate>
35 class Base
36 {
37 protected:
38  /**
39  * The constructor.
40  */
41  Base();
42 
43 private:
44  Base(const Base&); ///< The copy constructor.
45 
46 public:
47  /**
48  * The destructor.
49  */
50  virtual ~Base();
51 
52 public:
53  /**
54  * Performs, on the Device, an MD timestep of size `getMDTimeStepSize()`.
55  */
56  virtual void performMDTimestep() = 0;
57 
58  /**
59  * Returns the number of MPC solute particles.
60  */
61  virtual std::size_t getParticleCount() const = 0;
62 
63  /**
64  * Returns the number of logical entities in the solute.
65  */
66  virtual std::size_t getNumberOfLogicalEntities() const = 0;
67 
68  /**
69  * Copies the MPC solute particles from the CUDA Device to the Host.
70  */
71  void fetchFromDevice() const;
72 
73  /**
74  * Returns a MPC solute particle's position vector.
75  *
76  * @warning
77  * This function only returns the position that was current the last time
78  * `fetchFromDevice` was called.
79  *
80  * @throw OpenMPCD::OutOfBoundsException
81  * If `OPENMPCD_DEBUG` is defined, throws if
82  * `particleID >= getParticleCount()`.
83  *
84  * @param[in] particleID The particle ID.
85  */
87  getPosition(const std::size_t particleID) const;
88 
89  /**
90  * Returns a MPC solute particle's velocity vector.
91  *
92  * @warning
93  * This function only returns the velocity that was current the last time
94  * `fetchFromDevice` was called.
95  *
96  * @throw OpenMPCD::OutOfBoundsException
97  * If `OPENMPCD_DEBUG` is defined, throws if
98  * `particleID >= getParticleCount()`.
99  *
100  * @param[in] particleID The particle ID.
101  */
103  getVelocity(const std::size_t particleID) const;
104 
105  /**
106  * Returns a const pointer to the MPC solute positions on the Device.
107  */
108  const PositionCoordinate* getDevicePositions() const
109  {
110  return d_positions;
111  }
112 
113  /**
114  * Returns a pointer to the MPC solute positions on the Device.
115  */
116  PositionCoordinate* getDevicePositions()
117  {
118  return d_positions;
119  }
120 
121  /**
122  * Returns a pointer to the MPC solute positions on the Host.
123  */
124  PositionCoordinate* getHostPositions()
125  {
126  return h_positions.get();
127  }
128 
129  /**
130  * Returns a const pointer to the MPC solute velocities on the Device.
131  */
132  const VelocityCoordinate* getDeviceVelocities() const
133  {
134  return d_velocities;
135  }
136 
137  /**
138  * Returns a pointer to the MPC solute velocities on the Device.
139  */
140  VelocityCoordinate* getDeviceVelocities()
141  {
142  return d_velocities;
143  }
144 
145  /**
146  * Returns a pointer to the MPC solute velocities on the Host.
147  */
148  VelocityCoordinate* getHostVelocities()
149  {
150  return h_velocities.get();
151  }
152 
153  /**
154  * Returns the number of time units advanced per MD step.
155  */
157  {
158  return mdTimeStepSize;
159  }
160 
161  /**
162  * Returns whether the solute has instrumentation configured.
163  */
164  bool hasInstrumentation() const
165  {
166  return instrumentation != NULL;
167  }
168 
169  /**
170  * Returns the solute instrumentation.
171  *
172  * @throw OpenMPCD::NULLPointerException
173  * If `OPENMPCD_DEBUG` is defined, throws if `!hasInstrumentation()`.
174  */
176  {
179 
180  return *const_cast<Instrumentation::Base*>(instrumentation);
181  }
182 
183  /**
184  * Returns the mass of a particle, which is assumed to be equal for all
185  * particles in this instance.
186  */
187  virtual FP getParticleMass() const = 0;
188 
189 protected:
190  /**
191  * Copies the MPC solute particles from the Host to the CUDA Device.
192  */
193  void pushToDevice();
194 
195 private:
196  const Base& operator=(const Base&); ///< The assignment operator.
197 
198 protected:
199  DeviceMemoryManager deviceMemoryManager; ///< The Device memory manager.
200 
201  FP mdTimeStepSize; ///< The number of time units to advance per MD step.
202 
203  Instrumentation::Base* instrumentation; ///< The solute instrumentation.
204 
205  mutable boost::scoped_array<PositionCoordinate> h_positions;
206  ///< Host buffer for particle positions.
207  mutable boost::scoped_array<VelocityCoordinate> h_velocities;
208  ///< Host buffer for particle velocities.
209 
210  PositionCoordinate* d_positions; ///< Particle positions on the Device.
211  VelocityCoordinate* d_velocities; ///< Particle velocities on the Device.
212 }; //class Base
213 
214 } //namespace MPCSolute
215 } //namespace CUDA
216 } //namespace OpenMPCD
217 
218 #endif
OpenMPCD::RemotelyStoredVector
Represents a vector whose data is stored elsewhere.
Definition: RemotelyStoredVector.hpp:26
Base.hpp
OpenMPCD::CUDA::MPCSolute::Base::h_velocities
boost::scoped_array< VelocityCoordinate > h_velocities
Host buffer for particle velocities.
Definition: CUDA/MPCSolute/Base.hpp:207
Exceptions.hpp
OpenMPCD::CUDA::MPCSolute::Base::Base
Base()
The constructor.
OpenMPCD::CUDA::MPCSolute::Base::h_positions
boost::scoped_array< PositionCoordinate > h_positions
Host buffer for particle positions.
Definition: CUDA/MPCSolute/Base.hpp:205
OpenMPCD::CUDA::DeviceMemoryManager
Class for managing memory on the CUDA Device.
Definition: DeviceMemoryManager.hpp:21
OpenMPCD::CUDA::MPCSolute::Base::getDevicePositions
PositionCoordinate * getDevicePositions()
Returns a pointer to the MPC solute positions on the Device.
Definition: CUDA/MPCSolute/Base.hpp:116
RemotelyStoredVector.hpp
OpenMPCD::CUDA::MPCSolute::Base::fetchFromDevice
void fetchFromDevice() const
Copies the MPC solute particles from the CUDA Device to the Host.
OpenMPCD::CUDA::MPCSolute::Base::d_velocities
VelocityCoordinate * d_velocities
Particle velocities on the Device.
Definition: CUDA/MPCSolute/Base.hpp:211
OpenMPCD::CUDA::MPCSolute::Base::getInstrumentation
Instrumentation::Base & getInstrumentation() const
Returns the solute instrumentation.
Definition: CUDA/MPCSolute/Base.hpp:175
OpenMPCD::CUDA::MPCSolute::Base::getNumberOfLogicalEntities
virtual std::size_t getNumberOfLogicalEntities() const =0
Returns the number of logical entities in the solute.
OpenMPCD::CUDA::MPCSolute::Base
Base class for MPC solutes.
Definition: CUDA/MPCSolute/Base.hpp:35
OpenMPCD::CUDA::MPCSolute::Base::~Base
virtual ~Base()
The destructor.
OpenMPCD::CUDA::MPCSolute::Instrumentation::Base
Base class for MPC solutes instrumentation.
Definition: CUDA/MPCSolute/Instrumentation/Base.hpp:25
OpenMPCD::CUDA::MPCSolute::Base::performMDTimestep
virtual void performMDTimestep()=0
Performs, on the Device, an MD timestep of size getMDTimeStepSize().
OpenMPCD::CUDA::MPCSolute::Base::getParticleMass
virtual FP getParticleMass() const =0
Returns the mass of a particle, which is assumed to be equal for all particles in this instance.
OpenMPCD::CUDA::MPCSolute::Base::getPosition
const RemotelyStoredVector< const PositionCoordinate > getPosition(const std::size_t particleID) const
Returns a MPC solute particle's position vector.
DeviceMemoryManager.hpp
Vector3D.hpp
OPENMPCD_DEBUG_ASSERT.hpp
OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE
#define OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE(assertion, ExceptionType)
Definition: OPENMPCD_DEBUG_ASSERT.hpp:76
OpenMPCD::CUDA::MPCSolute::Base::mdTimeStepSize
FP mdTimeStepSize
The number of time units to advance per MD step.
Definition: CUDA/MPCSolute/Base.hpp:201
OpenMPCD::CUDA::MPCSolute::Base::pushToDevice
void pushToDevice()
Copies the MPC solute particles from the Host to the CUDA Device.
OpenMPCD::CUDA::MPCSolute::Base::d_positions
PositionCoordinate * d_positions
Particle positions on the Device.
Definition: CUDA/MPCSolute/Base.hpp:210
OpenMPCD::CUDA::MPCSolute::Base::getVelocity
const RemotelyStoredVector< const VelocityCoordinate > getVelocity(const std::size_t particleID) const
Returns a MPC solute particle's velocity vector.
OpenMPCD::FP
double FP
Default floating point type.
Definition: Types.hpp:13
OpenMPCD::CUDA::MPCSolute::Base::getMDTimeStepSize
FP getMDTimeStepSize() const
Returns the number of time units advanced per MD step.
Definition: CUDA/MPCSolute/Base.hpp:156
OpenMPCD::CUDA::MPCSolute::Base::hasInstrumentation
bool hasInstrumentation() const
Returns whether the solute has instrumentation configured.
Definition: CUDA/MPCSolute/Base.hpp:164
OpenMPCD::CUDA::MPCSolute::Base::getDeviceVelocities
VelocityCoordinate * getDeviceVelocities()
Returns a pointer to the MPC solute velocities on the Device.
Definition: CUDA/MPCSolute/Base.hpp:140
OpenMPCD::CUDA::MPCSolute::Base::getDevicePositions
const PositionCoordinate * getDevicePositions() const
Returns a const pointer to the MPC solute positions on the Device.
Definition: CUDA/MPCSolute/Base.hpp:108
OpenMPCD::CUDA::MPCSolute::Base::getHostPositions
PositionCoordinate * getHostPositions()
Returns a pointer to the MPC solute positions on the Host.
Definition: CUDA/MPCSolute/Base.hpp:124
OpenMPCD::CUDA::MPCSolute::Base::getDeviceVelocities
const VelocityCoordinate * getDeviceVelocities() const
Returns a const pointer to the MPC solute velocities on the Device.
Definition: CUDA/MPCSolute/Base.hpp:132
OpenMPCD::CUDA::MPCSolute::Base::instrumentation
Instrumentation::Base * instrumentation
The solute instrumentation.
Definition: CUDA/MPCSolute/Base.hpp:203
OpenMPCD::CUDA::MPCSolute::Base::getParticleCount
virtual std::size_t getParticleCount() const =0
Returns the number of MPC solute particles.
OpenMPCD::CUDA::MPCSolute::Base::getHostVelocities
VelocityCoordinate * getHostVelocities()
Returns a pointer to the MPC solute velocities on the Host.
Definition: CUDA/MPCSolute/Base.hpp:148
OpenMPCD::CUDA::MPCSolute::Base::deviceMemoryManager
DeviceMemoryManager deviceMemoryManager
The Device memory manager.
Definition: CUDA/MPCSolute/Base.hpp:199
OpenMPCD::NULLPointerException
NULL-pointer exception.
Definition: Exceptions.hpp:96