OpenMPCD
ImplementationDetails/StarPolymers.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Contains implementation details used in
4  * `OpenMPCD::CUDA::MPCSolute::StarPolymers`.
5  */
6 
7 #ifndef OPENMPCD_CUDA_MPCSOLUTE_IMPLEMENTATIONDETAILS_STARPOLYMERS_HPP
8 #define OPENMPCD_CUDA_MPCSOLUTE_IMPLEMENTATIONDETAILS_STARPOLYMERS_HPP
9 
11 
12 #include <OpenMPCD/CUDA/Macros.hpp>
14 
15 namespace OpenMPCD
16 {
17 namespace CUDA
18 {
19 namespace MPCSolute
20 {
21 
22 /**
23  * Contains implementation details used in `OpenMPCD::CUDA::MPCSolute`.
24  */
25 namespace ImplementationDetails
26 {
27 
28 /**
29  * Contains implementation details used in
30  * `OpenMPCD::CUDA::MPCSolute::StarPolymers`.
31  */
32 namespace StarPolymers
33 {
34 
35 /**
36  * Returns the total number of particles per star.
37  *
38  * @param[in] armCountPerStar
39  * The number of polymer arms per star.
40  * @param[in] particleCountPerArm
41  * The number of non-magnetic particles per arm.
42  * @param[in] hasMagneticParticles
43  * Whether each arm has an additional, magnetic particle attached.
44  */
46 std::size_t getParticleCountPerStar(
47  const std::size_t armCountPerStar,
48  const std::size_t particleCountPerArm,
49  const bool hasMagneticParticles);
50 
51 /**
52  * Returns the total number of particles in a `StarPolymers` instance.
53  *
54  * @param[in] starCount
55  * The number of stars in the `StarPolymers` instance.
56  * @param[in] armCountPerStar
57  * The number of polymer arms per star.
58  * @param[in] particleCountPerArm
59  * The number of non-magnetic particles per arm.
60  * @param[in] hasMagneticParticles
61  * Whether each arm has an additional, magnetic particle attached.
62  */
64 std::size_t getParticleCount(
65  const std::size_t starCount,
66  const std::size_t armCountPerStar,
67  const std::size_t particleCountPerArm,
68  const bool hasMagneticParticles);
69 
70 /**
71  * Computes the structure indices of the particle ID given.
72  *
73  * The pointers given must not correspond to overlapping regions of memory.
74  *
75  * @throw OpenMPCD::NULLPointerException
76  * If `OPENMPCD_DEBUG` is defined, throws if either `starID`,
77  * `isCoreParticle`, `armID`, `isMagneticParticl`, or `particleIDInArm`
78  * is `nullptr`.
79  *
80  * @throw OpenMPCD::InvalidArgumentException
81  * If `OPENMPCD_DEBUG` is defined, throws if `particleID` is greater than
82  * or equal to the number of particles, as returned by
83  * `getParticleCount`.
84  *
85  * @param[in] particleID
86  * The particle ID to query.
87  * @param[in] starCount
88  * The number of stars in the `StarPolymers` instance.
89  * @param[in] armCountPerStar
90  * The number of polymer arms per star.
91  * @param[in] particleCountPerArm
92  * The number of non-magnetic particles per arm.
93  * @param[in] hasMagneticParticles
94  * Whether each arm has an additional, magnetic particle attached.
95  * @param[out] starID
96  * The ID of the star the particle is in, running from `0` to
97  * `starCount - 1`, inclusive.
98  * @param[out] isCoreParticle
99  * Whether the `particleID` corresponds to the star's core particle.
100  * @param[out] armID
101  * If the particle is not a core particle, this is set the
102  * particle's arm's ID within the star, running from `0` to
103  * `armCountPerStar - 1`, inclusive. Otherwise, the value is left
104  * unchanged.
105  * @param[out] isMagneticParticle
106  * Whether the `particleID` corresponds to a magnetic particle.
107  * @param[out] particleIDInArm
108  * If `isCoreParticle`, the value is left unchanged. Otherwise, if
109  * the `particleID` corresponds to a magnetic particle, this is set
110  * to `particleCountPerArm`. Otherwise, the `particleID` corresponds
111  * to an arm particle, and this value is set to the particle's ID
112  * within the arm, running from `0` to `particleCountPerArm - 1`,
113  * inclusive.
114  */
117  const std::size_t particleID,
118  const std::size_t starCount,
119  const std::size_t armCountPerStar,
120  const std::size_t particleCountPerArm,
121  const bool hasMagneticParticles,
122  std::size_t* const starID,
123  bool* const isCoreParticle,
124  std::size_t* const armID,
125  bool* const isMagneticParticle,
126  std::size_t* const particleIDInArm);
127 
128 /**
129  * Returns the particle type that corresponds to the given ID.
130  *
131  * @throw OpenMPCD::InvalidArgumentException
132  * If `OPENMPCD_DEBUG` is defined, throws if `particleID` is greater than
133  * or equal to the number of particles, as returned by
134  * `getParticleCount`.
135  *
136  * @param[in] particleID
137  * The particle ID to query.
138  * @param[in] starCount
139  * The number of stars in the `StarPolymers` instance.
140  * @param[in] armCountPerStar
141  * The number of polymer arms per star.
142  * @param[in] particleCountPerArm
143  * The number of non-magnetic particles per arm.
144  * @param[in] hasMagneticParticles
145  * Whether each arm has an additional, magnetic particle attached.
146  */
149  const std::size_t particleID,
150  const std::size_t starCount,
151  const std::size_t armCountPerStar,
152  const std::size_t particleCountPerArm,
153  const bool hasMagneticParticles);
154 
155 /**
156  * Returns whether the two given particles are bonded.
157  *
158  * @throw OpenMPCD::InvalidArgumentException
159  * If `OPENMPCD_DEBUG` is defined, throws if either `particleID1` or
160  * `particleID2` is greater than or equal to the number of particles, as
161  * returned by `getParticleCount`, or if `particleID1 == particleID2`.
162  *
163  * @param[in] particleID1
164  * The ID of the first particle.
165  * @param[in] particleID2
166  * The ID of the second particle, which must not be equal to
167  * `particleID1`.
168  * @param[in] starCount
169  * The number of stars in the `StarPolymers` instance.
170  * @param[in] armCountPerStar
171  * The number of polymer arms per star.
172  * @param[in] particleCountPerArm
173  * The number of non-magnetic particles per arm.
174  * @param[in] hasMagneticParticles
175  * Whether each arm has an additional, magnetic particle attached.
176  */
178 bool particlesAreBonded(
179  const std::size_t particleID1,
180  const std::size_t particleID2,
181  const std::size_t starCount,
182  const std::size_t armCountPerStar,
183  const std::size_t particleCountPerArm,
184  const bool hasMagneticParticles);
185 
186 /**
187  * Returns a different integer, in a consecutive range starting from `0`, for
188  * every combination of particle types, except that the result is invariant
189  * under exchange of the two arguments.
190  *
191  * @param[in] type1 The particle type of the first particle.
192  * @param[in] type2 The particle type of the second particle.
193  */
196  const ParticleType::Enum type1, const ParticleType::Enum type2);
197 
198 /**
199  * Constructs the necessary interaction potentials in memory.
200  *
201  * The interaction parameters are described in the documentation of
202  * `OpenMPCD::CUDA::MPCSolute::StarPolymers`.
203  *
204  * The arrays returned in the output parameters `WCAPotentials` and
205  * `FENEPotentials` contain the interactions of particles of type `type1` and
206  * `type2` at the array index `getParticleTypeCombinationIndex(type1, type2)`.
207  *
208  * @throw OpenMPCD::NULLPointerException
209  * If `OPENMPCD_DEBUG` is defined, throws if either of the output
210  * arguments is `nullptr`.
211  *
212  * @tparam T The underlying data type.
213  *
214  * @param[in] epsilon_core The \f$ \varepsilon_C \f$ parameter.
215  * @param[in] epsilon_arm The \f$ \varepsilon_A \f$ parameter.
216  * @param[in] epsilon_magnetic The \f$ \varepsilon_M \f$ parameter.
217  * @param[in] sigma_core The \f$ \sigma_C \f$ parameter.
218  * @param[in] sigma_arm The \f$ \sigma_A \f$ parameter.
219  * @param[in] sigma_magnetic The \f$ \sigma_M \f$ parameter.
220  * @param[in] D_core The \f$ D_C \f$ parameter.
221  * @param[in] D_arm The \f$ D_A \f$ parameter.
222  * @param[in] D_magnetic The \f$ D_M \f$ parameter.
223  * @param[in] magneticPrefactor The `prefactor` argument to the magnetic
224  * interaction.
225  * @param[in] dipoleOrientation Normalized vector that defines the orientation
226  * of the magnetic dipoles.
227  * @param[out] WCAPotentials Returns an array of WCA potential instance
228  * pointers on the CUDA Device.
229  * The memory allocated this way has to be freed
230  * by `destroyInteractionOnDevice`.
231  * @param[out] FENEPotentials Returns an array of FENE potential instance
232  * pointers on the CUDA Device.
233  * The memory allocated this way has to be freed
234  * by `destroyInteractionOnDevice`.
235  * @param[out] magneticPotential Returns a pointer to an instance pointer for
236  * the magnetic potential on the CUDA Device.
237  * The memory allocated this way has to be freed
238  * by `destroyInteractionOnDevice`.
239  */
240 template<typename T>
242  const T epsilon_core, const T epsilon_arm, const T epsilon_magnetic,
243  const T sigma_core, const T sigma_arm, const T sigma_magnetic,
244  const T D_core, const T D_arm, const T D_magnetic,
245  const T magneticPrefactor, const Vector3D<T> dipoleOrientation,
247  WCAPotentials,
248  PairPotentials::FENE<T>*** const FENEPotentials,
249  PairPotentials::
250  MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles<T>*** const
251  magneticPotential
252  );
253 
254 /**
255  * Frees the memory allocated through `createInteractionsOnDevice`.
256  *
257  * @throw OpenMPCD::NULLPointerException
258  * If `OPENMPCD_DEBUG` is defined, throws if either of the arguments is
259  * `nullptr`, or if `WCAPotentials` or `FENEPotentials` are not arrays
260  * with non-`nullptr` entries at the indices returned by
261  * `getParticleTypeCombinationIndex` for the appropriate type
262  * combinations (all possible combinations for `WCAPotentials`, and
263  * Core-Arm, Arm-Arm, or Arm-Magnetic combinations for `FENEPotentials`),
264  * or if the entries are non-`nullptr` for invalid type combination
265  * indices.
266  *
267  * @param[in] WCAPotentials The array of allocated WCA potentials on the
268  * CUDA Device.
269  * @param[in] FENEPotentials The array of allocated FENE potentials on the
270  * CUDA Device.
271  * @param[in] magneticPotential The allocated magnetic potential on the CUDA
272  * Device.
273  */
274 template<typename T>
277  WCAPotentials,
278  PairPotentials::FENE<T>** const FENEPotentials,
279  PairPotentials::
280  MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles<T>** const
281  magneticPotential
282  );
283 
284 /**
285  * Returns the force that is exerted on `particleID1` due to `particleID2`.
286  *
287  * The interactions passed in this function are additive, i.e. if the two
288  * particles match the criteria of multiple interactions, these matching
289  * interactions will all be applied.
290  *
291  * @tparam T The underlying numeric type.
292  *
293  * @param[in] particleID1
294  * The ID of the first particle.
295  * @param[in] particleID2
296  * The ID of the second particle, which must not be equal to
297  * `particleID1`.
298  * @param[in] position1
299  * The position of the first particle.
300  * @param[in] position2
301  * The position of the second particle.
302  * @param[in] starCount
303  * The number of stars in the `StarPolymers` instance.
304  * @param[in] armCountPerStar
305  * The number of polymer arms per star.
306  * @param[in] particleCountPerArm
307  * The number of non-magnetic particles per arm.
308  * @param[in] hasMagneticParticles
309  * Whether each arm has an additional, magnetic particle attached.
310  * @param[in] WCAPotentials
311  * The array of allocated WCA potentials.
312  * @param[in] FENEPotentials
313  * The array of allocated FENE potentials.
314  * @param[in] magneticPotential
315  * The allocated magnetic potential.
316  */
317 template<typename T>
319 const Vector3D<T>
321  const std::size_t particleID1,
322  const std::size_t particleID2,
323  const RemotelyStoredVector<const T>& position1,
324  const RemotelyStoredVector<const T>& position2,
325  const std::size_t starCount,
326  const std::size_t armCountPerStar,
327  const std::size_t particleCountPerArm,
328  const bool hasMagneticParticles,
330  WCAPotentials,
331  PairPotentials::FENE<T>** const FENEPotentials,
332  PairPotentials::
333  MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles<T>** const
334  magneticPotential);
335 
336 } //namespace StarPolymers
337 } //namespace ImplementationDetails
338 } //namespace MPCSolute
339 } //namespace CUDA
340 } //namespace OpenMPCD
341 
343 
344 #endif //OPENMPCD_CUDA_MPCSOLUTE_IMPLEMENTATIONDETAILS_STARPOLYMERS_HPP
OpenMPCD::CUDA::MPCSolute::ImplementationDetails::StarPolymers::getParticleType
OPENMPCD_CUDA_HOST_AND_DEVICE ParticleType::Enum getParticleType(const std::size_t particleID, const std::size_t starCount, const std::size_t armCountPerStar, const std::size_t particleCountPerArm, const bool hasMagneticParticles)
Returns the particle type that corresponds to the given ID.
Definition: StarPolymers_Implementation.hpp:112
OpenMPCD::PairPotentials::WeeksChandlerAndersen_DistanceOffset
A generalization of the Weeks-Chandler-Andersen (WCA) potential.
Definition: WeeksChandlerAndersen_DistanceOffset.hpp:39
OpenMPCD::RemotelyStoredVector
Represents a vector whose data is stored elsewhere.
Definition: RemotelyStoredVector.hpp:26
OpenMPCD::Vector3D
3-dimensional vector.
Definition: Vector3D.hpp:38
OpenMPCD::CUDA::MPCSolute::ImplementationDetails::StarPolymers::getParticleCountPerStar
OPENMPCD_CUDA_HOST_AND_DEVICE std::size_t getParticleCountPerStar(const std::size_t armCountPerStar, const std::size_t particleCountPerArm, const bool hasMagneticParticles)
Returns the total number of particles per star.
Definition: StarPolymers_Implementation.hpp:29
OpenMPCD::CUDA::MPCSolute::ImplementationDetails::StarPolymers::createInteractionsOnDevice
void createInteractionsOnDevice(const T epsilon_core, const T epsilon_arm, const T epsilon_magnetic, const T sigma_core, const T sigma_arm, const T sigma_magnetic, const T D_core, const T D_arm, const T D_magnetic, const T magneticPrefactor, const Vector3D< T > dipoleOrientation, PairPotentials::WeeksChandlerAndersen_DistanceOffset< T > ***const WCAPotentials, PairPotentials::FENE< T > ***const FENEPotentials, PairPotentials::MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles< T > ***const magneticPotential)
Constructs the necessary interaction potentials in memory.
Definition: StarPolymers_Implementation.hpp:349
OpenMPCD::CUDA::MPCSolute::ImplementationDetails::StarPolymers::ParticleType::Enum
Enum
Enumerates particle types.
Definition: StarPolymers_ParticleType.hpp:30
OPENMPCD_CUDA_HOST_AND_DEVICE
#define OPENMPCD_CUDA_HOST_AND_DEVICE
Denotes a function to be callable both from the Host and from a CUDA Device.
Definition: Macros.hpp:15
OpenMPCD::CUDA::MPCSolute::ImplementationDetails::StarPolymers::getParticleCount
OPENMPCD_CUDA_HOST_AND_DEVICE std::size_t getParticleCount(const std::size_t starCount, const std::size_t armCountPerStar, const std::size_t particleCountPerArm, const bool hasMagneticParticles)
Returns the total number of particles in a StarPolymers instance.
Definition: StarPolymers_Implementation.hpp:42
StarPolymers_Implementation.hpp
OpenMPCD::CUDA::MPCSolute::ImplementationDetails::StarPolymers::getParticleTypeCombinationIndex
OPENMPCD_CUDA_HOST_AND_DEVICE std::size_t getParticleTypeCombinationIndex(const ParticleType::Enum type1, const ParticleType::Enum type2)
Returns a different integer, in a consecutive range starting from 0, for every combination of particl...
Definition: StarPolymers_Implementation.hpp:197
OPENMPCD_DEBUG_ASSERT.hpp
OpenMPCD::CUDA::MPCSolute::ImplementationDetails::StarPolymers::getParticleStructureIndices
OPENMPCD_CUDA_HOST_AND_DEVICE void getParticleStructureIndices(const std::size_t particleID, const std::size_t starCount, const std::size_t armCountPerStar, const std::size_t particleCountPerArm, const bool hasMagneticParticles, std::size_t *const starID, bool *const isCoreParticle, std::size_t *const armID, bool *const isMagneticParticle, std::size_t *const particleIDInArm)
Computes the structure indices of the particle ID given.
Definition: StarPolymers_Implementation.hpp:56
OpenMPCD::PairPotentials::FENE
FENE Interaction .
Definition: FENE.hpp:18
StarPolymers.hpp
Macros.hpp
OpenMPCD::CUDA::MPCSolute::ImplementationDetails::StarPolymers::particlesAreBonded
OPENMPCD_CUDA_HOST_AND_DEVICE bool particlesAreBonded(const std::size_t particleID1, const std::size_t particleID2, const std::size_t starCount, const std::size_t armCountPerStar, const std::size_t particleCountPerArm, const bool hasMagneticParticles)
Returns whether the two given particles are bonded.
Definition: StarPolymers_Implementation.hpp:139
OpenMPCD::CUDA::MPCSolute::StarPolymers
Class representing star polymers.
Definition: StarPolymers.hpp:123
OpenMPCD::CUDA::MPCSolute::ImplementationDetails::StarPolymers::computeForceOnParticle1DueToParticle2
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D< T > computeForceOnParticle1DueToParticle2(const std::size_t particleID1, const std::size_t particleID2, const RemotelyStoredVector< const T > &position1, const RemotelyStoredVector< const T > &position2, const std::size_t starCount, const std::size_t armCountPerStar, const std::size_t particleCountPerArm, const bool hasMagneticParticles, PairPotentials::WeeksChandlerAndersen_DistanceOffset< T > **const WCAPotentials, PairPotentials::FENE< T > **const FENEPotentials, PairPotentials::MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles< T > **const magneticPotential)
Returns the force that is exerted on particleID1 due to particleID2.
Definition: StarPolymers_Implementation.hpp:471
OpenMPCD::CUDA::MPCSolute::ImplementationDetails::StarPolymers::destroyInteractionsOnDevice
void destroyInteractionsOnDevice(PairPotentials::WeeksChandlerAndersen_DistanceOffset< T > **const WCAPotentials, PairPotentials::FENE< T > **const FENEPotentials, PairPotentials::MagneticDipoleDipoleInteraction_ConstantIdenticalDipoles< T > **const magneticPotential)
Frees the memory allocated through createInteractionsOnDevice.
Definition: StarPolymers_Implementation.hpp:450