|
| 1 | +// Copyright (c) 2018-2020, Michael P. Howard |
| 2 | +// Copyright (c) 2021-2024, Auburn University |
| 3 | +// Part of azplugins, released under the BSD 3-Clause License. |
| 4 | + |
| 5 | +#ifndef AZPLUGINS_PARTICLE_DATA_LOADER_H_ |
| 6 | +#define AZPLUGINS_PARTICLE_DATA_LOADER_H_ |
| 7 | + |
| 8 | +#include "hoomd/HOOMDMath.h" |
| 9 | + |
| 10 | +#ifdef __HIPCC__ |
| 11 | +#define HOSTDEVICE __host__ __device__ |
| 12 | +#else |
| 13 | +#define HOSTDEVICE |
| 14 | +#endif // __HIPCC__ |
| 15 | + |
| 16 | +namespace hoomd |
| 17 | + { |
| 18 | +namespace azplugins |
| 19 | + { |
| 20 | +namespace detail |
| 21 | + { |
| 22 | + |
| 23 | +//! Load HOOMD particle in a group from an index |
| 24 | +class LoadHOOMDGroupPositionVelocityMass |
| 25 | + { |
| 26 | + public: |
| 27 | + HOSTDEVICE |
| 28 | + LoadHOOMDGroupPositionVelocityMass(const Scalar4* positions, |
| 29 | + const Scalar4* velocities, |
| 30 | + const unsigned int* indexes) |
| 31 | + : m_positions(positions), m_velocities(velocities), m_indexes(indexes) |
| 32 | + { |
| 33 | + } |
| 34 | + |
| 35 | + HOSTDEVICE void |
| 36 | + operator()(Scalar3& position, Scalar3& velocity, Scalar& mass, unsigned int idx) const |
| 37 | + { |
| 38 | + const unsigned int pidx = m_indexes[idx]; |
| 39 | + const Scalar4 postype = m_positions[pidx]; |
| 40 | + position = make_scalar3(postype.x, postype.y, postype.z); |
| 41 | + |
| 42 | + const Scalar4 velmass = m_velocities[pidx]; |
| 43 | + velocity = make_scalar3(velmass.x, velmass.y, velmass.z); |
| 44 | + mass = velmass.w; |
| 45 | + } |
| 46 | + |
| 47 | + private: |
| 48 | + const Scalar4* const m_positions; |
| 49 | + const Scalar4* const m_velocities; |
| 50 | + const unsigned int* const m_indexes; |
| 51 | + }; |
| 52 | + |
| 53 | +//! Load MPCD particle from an index |
| 54 | +class LoadMPCDPositionVelocityMass |
| 55 | + { |
| 56 | + public: |
| 57 | + HOSTDEVICE |
| 58 | + LoadMPCDPositionVelocityMass(const Scalar4* positions, |
| 59 | + const Scalar4* velocities, |
| 60 | + const Scalar mass) |
| 61 | + : m_positions(positions), m_velocities(velocities), m_mass(mass) |
| 62 | + { |
| 63 | + } |
| 64 | + |
| 65 | + HOSTDEVICE void |
| 66 | + operator()(Scalar3& position, Scalar3& velocity, Scalar& mass, unsigned int idx) const |
| 67 | + { |
| 68 | + const Scalar4 postype = m_positions[idx]; |
| 69 | + position = make_scalar3(postype.x, postype.y, postype.z); |
| 70 | + |
| 71 | + const Scalar4 velcell = m_velocities[idx]; |
| 72 | + velocity = make_scalar3(velcell.x, velcell.y, velcell.z); |
| 73 | + mass = m_mass; |
| 74 | + } |
| 75 | + |
| 76 | + private: |
| 77 | + const Scalar4* const m_positions; |
| 78 | + const Scalar4* const m_velocities; |
| 79 | + const Scalar m_mass; |
| 80 | + }; |
| 81 | + |
| 82 | + } // end namespace detail |
| 83 | + } // end namespace azplugins |
| 84 | + } // end namespace hoomd |
| 85 | + |
| 86 | +#undef HOSTDEVICE |
| 87 | + |
| 88 | +#endif // AZPLUGINS_PARTICLE_DATA_LOADER_H_ |
0 commit comments