OpenMPCD
Simulation.cpp
2 
6 
7 namespace OpenMPCD
8 {
9 namespace ImplementationDetails
10 {
11 
12 unsigned int getCollisionCellIndex(
13  const Vector3D<MPCParticlePositionType>& position,
14  const unsigned int boxSizeX,
15  const unsigned int boxSizeY,
16  const unsigned int boxSizeZ)
17 {
18  const FP x = position.getX();
19  const FP y = position.getY();
20  const FP z = position.getZ();
21 
22  const unsigned int cellX = static_cast<unsigned int>(x);
23  const unsigned int cellY = static_cast<unsigned int>(y);
24  const unsigned int cellZ = static_cast<unsigned int>(z);
25 
26  const unsigned int index =
27  cellZ * boxSizeX * boxSizeY +
28  cellY * boxSizeX +
29  cellX;
30 
31  OPENMPCD_DEBUG_ASSERT(index < boxSizeX * boxSizeY * boxSizeZ);
32 
33  return index;
34 }
35 
37  const unsigned int particleID,
38  const MPCParticlePositionType* const gridShift_,
39  const FP shearRate,
40  const FP mpcTime,
41  const MPCParticlePositionType* const positions,
42  MPCParticleVelocityType* const velocities,
43  MPCParticleVelocityType* const velocityCorrections,
44  unsigned int* const collisionCellIndices,
45  const unsigned int boxSizeX,
46  const unsigned int boxSizeY,
47  const unsigned int boxSizeZ)
48 {
50  gridShift_);
51 
53  positions, particleID);
54 
55  OPENMPCD_DEBUG_ASSERT(gridShift.isFinite());
56  OPENMPCD_DEBUG_ASSERT(position.isFinite());
57 
58  MPCParticleVelocityType velocityCorrection;
61  position + gridShift,
62  mpcTime,
63  shearRate,
64  boxSizeX, boxSizeY, boxSizeZ,
65  &velocityCorrection);
66 
67  velocities[3 * particleID + 0] += velocityCorrection;
68  velocityCorrections[particleID] = velocityCorrection;
69 
70  collisionCellIndices[particleID] =
71  getCollisionCellIndex(image, boxSizeX, boxSizeY, boxSizeZ);
72 }
73 
75  const unsigned int particleCount,
76  const MPCParticleVelocityType* const velocities,
77  const unsigned int* const collisionCellIndices,
78  MPCParticleVelocityType* const collisionCellMomenta,
79  FP* const collisionCellMasses,
80  const FP particleMass)
81 {
82  for(unsigned int particleID = 0; particleID < particleCount; ++particleID)
83  {
84  const unsigned int collisionCellIndex = collisionCellIndices[particleID];
85 
87  particleVelocity(velocities, particleID);
89  cellMomentum(collisionCellMomenta, collisionCellIndex);
90 
91  OPENMPCD_DEBUG_ASSERT(particleVelocity.isFinite());
92  OPENMPCD_DEBUG_ASSERT(cellMomentum.isFinite());
93 
94  cellMomentum += particleVelocity * particleMass;
95  collisionCellMasses[collisionCellIndex] += particleMass;
96 
97  OPENMPCD_DEBUG_ASSERT(cellMomentum.isFinite());
98  }
99 }
100 
103  const unsigned int collisionCellIndex,
104  const MPCParticleVelocityType* const collisionCellMomenta)
105 {
107  collisionCellMomentum(collisionCellMomenta, collisionCellIndex);
108 
109  return collisionCellMomentum;
110 }
111 
114  const unsigned int collisionCellIndex,
115  const MPCParticleVelocityType* const collisionCellMomenta,
116  const FP* const collisionCellMasses)
117 {
119  collisionCellMomentum(collisionCellMomenta, collisionCellIndex);
120 
121  const FP collisionCellMass = collisionCellMasses[collisionCellIndex];
122 
124  collisionCellMomentum / collisionCellMass;
125 
127 
128  return ret;
129 }
130 
132  const unsigned int particleCount,
133  MPCParticleVelocityType* const velocities,
134  const FP particleMass,
135  const unsigned int* const collisionCellIndices,
136  const MPCParticleVelocityType* const collisionCellMomenta,
137  const FP* const collisionCellMasses,
138  const MPCParticlePositionType* const collisionCellRotationAxes,
139  const FP collisionAngle,
140  FP* const collisionCellFrameInternalKineticEnergies,
141  unsigned int* const collisionCellParticleCounts)
142 {
143  for(unsigned int particleID = 0; particleID < particleCount; ++particleID)
144  {
145  const unsigned int collisionCellIndex =
146  collisionCellIndices[particleID];
147 
149  particleVelocity(velocities, particleID);
150 
151  const Vector3D<MPCParticleVelocityType> collisionCellVelocity =
153  collisionCellIndex, collisionCellMomenta, collisionCellMasses);
154 
155  Vector3D<MPCParticleVelocityType> relativeVelocity =
156  particleVelocity - collisionCellVelocity;
157 
159  rotationAxis(collisionCellRotationAxes, collisionCellIndex);
160 
161  particleVelocity =
162  relativeVelocity.getRotatedAroundNormalizedAxis(
163  rotationAxis, collisionAngle);
164 
165  //particleVelocity now contains the velocity *relative* to the
166  //center-of-mass frame of the collision cell!
167 
168  OPENMPCD_DEBUG_ASSERT(particleVelocity.isFinite());
169 
170  collisionCellFrameInternalKineticEnergies[collisionCellIndex] +=
171  particleMass * relativeVelocity.getMagnitudeSquared() / 2.0;
172  collisionCellParticleCounts[collisionCellIndex] += 1;
173  }
174 }
175 
177  const unsigned int particleCount,
178  MPCParticleVelocityType* const velocities,
179  const unsigned int* const collisionCellIndices,
180  const MPCParticleVelocityType* const collisionCellMomenta,
181  const FP* const collisionCellMasses,
182  const FP* const collisionCellVelocityScalings)
183 {
184  for(unsigned int particleID = 0; particleID < particleCount; ++particleID)
185  {
186  const unsigned int collisionCellIndex = collisionCellIndices[particleID];
187 
189  particleVelocity(velocities, particleID);
190 
191  OPENMPCD_DEBUG_ASSERT(particleVelocity.isFinite());
193  std::isfinite(collisionCellVelocityScalings[collisionCellIndex]));
194 
195  particleVelocity *=
196  collisionCellVelocityScalings[collisionCellIndex];
197 
198  particleVelocity +=
200  collisionCellIndex, collisionCellMomenta, collisionCellMasses);
201 
202  OPENMPCD_DEBUG_ASSERT(particleVelocity.isFinite());
203  }
204 }
205 
207  const unsigned int particleCount,
208  MPCParticleVelocityType* const velocities,
209  const MPCParticleVelocityType* const velocityCorrections)
210 {
211  for(unsigned int particleID = 0; particleID < particleCount; ++particleID)
212  {
213  OPENMPCD_DEBUG_ASSERT(std::isfinite(velocities[3 * particleID + 0]));
214  OPENMPCD_DEBUG_ASSERT(std::isfinite(velocityCorrections[particleID]));
215 
216  velocities[3 * particleID + 0] -= velocityCorrections[particleID];
217 
218  OPENMPCD_DEBUG_ASSERT(std::isfinite(velocities[3 * particleID + 0]));
219  }
220 }
221 
222 } //namespace ImplementationDetails
223 } //namespace OpenMPCD
OpenMPCD::Vector3D::isFinite
OPENMPCD_CUDA_HOST_AND_DEVICE bool isFinite() const
Returns whether all components are finite, i.e.
Definition: Vector3D.hpp:341
OpenMPCD::RemotelyStoredVector
Represents a vector whose data is stored elsewhere.
Definition: RemotelyStoredVector.hpp:26
OpenMPCD::Vector3D::getRotatedAroundNormalizedAxis
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D getRotatedAroundNormalizedAxis(const Vector3D &axis, const T angle) const
Returns this vector, but rotated about the given axis by the given angle.
Definition: Vector3D.hpp:322
OpenMPCD::Vector3D::getZ
OPENMPCD_CUDA_HOST_AND_DEVICE T getZ() const
Returns the z coordinate.
Definition: Vector3D.hpp:119
OpenMPCD::Vector3D
3-dimensional vector.
Definition: Vector3D.hpp:38
Simulation.hpp
OpenMPCD::Vector3D::getX
OPENMPCD_CUDA_HOST_AND_DEVICE T getX() const
Returns the x coordinate.
Definition: Vector3D.hpp:61
RemotelyStoredVector.hpp
OPENMPCD_DEBUG_ASSERT
#define OPENMPCD_DEBUG_ASSERT(assertion)
Asserts that the given expression evaluates to true, but only if OPENMPCD_DEBUG is defined.
Definition: OPENMPCD_DEBUG_ASSERT.hpp:88
OpenMPCD::MPCParticlePositionType
FP MPCParticlePositionType
The data type for the positions of MPC particles.
Definition: Types.hpp:15
OpenMPCD::Vector3D::getY
OPENMPCD_CUDA_HOST_AND_DEVICE T getY() const
Returns the y coordinate.
Definition: Vector3D.hpp:90
OpenMPCD::ImplementationDetails::getCollisionCellCenterOfMassMomentum
Vector3D< MPCParticleVelocityType > getCollisionCellCenterOfMassMomentum(const unsigned int collisionCellIndex, const MPCParticleVelocityType *const collisionCellMomenta)
Returns the center-of-mass momentum of a collision cell.
Definition: Simulation.cpp:102
OPENMPCD_DEBUG_ASSERT.hpp
OpenMPCD::ImplementationDetails::getCollisionCellIndex
unsigned int getCollisionCellIndex(const Vector3D< MPCParticlePositionType > &position, const unsigned int boxSizeX, const unsigned int boxSizeY, const unsigned int boxSizeZ)
Returns the collision cell index for the given position.
Definition: Simulation.cpp:12
OpenMPCD::ImplementationDetails::collisionCellStochasticRotationStep1
void collisionCellStochasticRotationStep1(const unsigned int particleCount, MPCParticleVelocityType *const velocities, const FP particleMass, const unsigned int *const collisionCellIndices, const MPCParticleVelocityType *const collisionCellMomenta, const FP *const collisionCellMasses, const MPCParticlePositionType *const collisionCellRotationAxes, const FP collisionAngle, FP *const collisionCellFrameInternalKineticEnergies, unsigned int *const collisionCellParticleCounts)
Applies the first step of the SRD rotation to the given particles.
Definition: Simulation.cpp:131
OpenMPCD::FP
double FP
Default floating point type.
Definition: Types.hpp:13
OpenMPCD::MPCParticleVelocityType
FP MPCParticleVelocityType
The data type for the velocities of MPC particles.
Definition: Types.hpp:16
OpenMPCD::ImplementationDetails::undoLeesEdwardsVelocityCorrections
void undoLeesEdwardsVelocityCorrections(const unsigned int particleCount, MPCParticleVelocityType *const velocities, const MPCParticleVelocityType *const velocityCorrections)
Undoes the velocity corrections applied by sortIntoCollisionCellsLeesEdwards.
Definition: Simulation.cpp:206
OpenMPCD::ImplementationDetails::collisionCellContributions
void collisionCellContributions(const unsigned int particleCount, const MPCParticleVelocityType *const velocities, const unsigned int *const collisionCellIndices, MPCParticleVelocityType *const collisionCellMomenta, FP *const collisionCellMasses, const FP particleMass)
Computes the collision cell mass and momentum contributions by the given particles.
Definition: Simulation.cpp:74
OpenMPCD::CUDA::DeviceCode::getImageUnderLeesEdwardsBoundaryConditions
const __device__ Vector3D< MPCParticlePositionType > getImageUnderLeesEdwardsBoundaryConditions(const FP mpcTime, const Vector3D< MPCParticlePositionType > &position, MPCParticleVelocityType &velocityCorrection)
Returns the image of the given particle position under Lees-Edwards boundary conditions.
OpenMPCD::ImplementationDetails::sortIntoCollisionCellsLeesEdwards
void sortIntoCollisionCellsLeesEdwards(const unsigned int particleID, const MPCParticlePositionType *const gridShift_, const FP shearRate, const FP mpcTime, const MPCParticlePositionType *const positions, MPCParticleVelocityType *const velocities, MPCParticleVelocityType *const velocityCorrections, unsigned int *const collisionCellIndices, const unsigned int boxSizeX, const unsigned int boxSizeY, const unsigned int boxSizeZ)
Sorts the given particle into the collision cells, temporarily applying Lees-Edwards boundary conditi...
Definition: Simulation.cpp:36
OpenMPCD::ImplementationDetails::getCollisionCellCenterOfMassVelocity
Vector3D< MPCParticleVelocityType > getCollisionCellCenterOfMassVelocity(const unsigned int collisionCellIndex, const MPCParticleVelocityType *const collisionCellMomenta, const FP *const collisionCellMasses)
Returns the center-of-mass velocity of a collision cell.
Definition: Simulation.cpp:113
LeesEdwardsBoundaryConditions.hpp
OpenMPCD::ImplementationDetails::collisionCellStochasticRotationStep2
void collisionCellStochasticRotationStep2(const unsigned int particleCount, MPCParticleVelocityType *const velocities, const unsigned int *const collisionCellIndices, const MPCParticleVelocityType *const collisionCellMomenta, const FP *const collisionCellMasses, const FP *const collisionCellVelocityScalings)
Applies the first step of the SRD rotation to the given particles.
Definition: Simulation.cpp:176
OpenMPCD::RemotelyStoredVector::isFinite
OPENMPCD_CUDA_HOST_AND_DEVICE bool isFinite() const
Returns whether all components are finite, i.e.
Definition: RemotelyStoredVector.hpp:200
OpenMPCD::Vector3D::getMagnitudeSquared
OPENMPCD_CUDA_HOST_AND_DEVICE RealType getMagnitudeSquared() const
Returns the square of the magnitude of this vector.
Definition: Vector3D.hpp:209