|
| 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_BINNING_OPERATION_H_ |
| 6 | +#define AZPLUGINS_BINNING_OPERATION_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 | + |
| 21 | +//! Interface for binning operations in different 3D coordinate systems. |
| 22 | +class BinningOperation |
| 23 | + { |
| 24 | + public: |
| 25 | + HOSTDEVICE BinningOperation(const uint3& num_bins, |
| 26 | + const Scalar3& lower_bounds, |
| 27 | + const Scalar3& upper_bounds) |
| 28 | + : m_lower_bounds {lower_bounds.x, lower_bounds.y, lower_bounds.z}, |
| 29 | + m_upper_bounds {upper_bounds.x, upper_bounds.y, upper_bounds.z}, m_num_bins {1, 1, 1}, |
| 30 | + m_should_bin {false, false, false} |
| 31 | + { |
| 32 | + if (num_bins.x > 0) |
| 33 | + { |
| 34 | + m_num_bins[0] = num_bins.x; |
| 35 | + m_should_bin[0] = true; |
| 36 | + } |
| 37 | + if (num_bins.y > 0) |
| 38 | + { |
| 39 | + m_num_bins[1] = num_bins.y; |
| 40 | + m_should_bin[1] = true; |
| 41 | + } |
| 42 | + if (num_bins.z > 0) |
| 43 | + { |
| 44 | + m_num_bins[2] = num_bins.z; |
| 45 | + m_should_bin[2] = true; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + HOSTDEVICE bool bin(uint3& bin, |
| 50 | + Scalar3& transformed_vector, |
| 51 | + const Scalar3& coordinates, |
| 52 | + const Scalar3& vector) const |
| 53 | + { |
| 54 | + return false; |
| 55 | + } |
| 56 | + |
| 57 | + HOSTDEVICE size_t getTotalNumBins() const |
| 58 | + { |
| 59 | + return static_cast<size_t>(m_num_bins[0]) * m_num_bins[1] * m_num_bins[2]; |
| 60 | + } |
| 61 | + |
| 62 | + HOSTDEVICE size_t ravelBin(const uint3& bin) const |
| 63 | + { |
| 64 | + return static_cast<size_t>(bin.z) + m_num_bins[2] * (bin.y + m_num_bins[1] * bin.x); |
| 65 | + } |
| 66 | + |
| 67 | + protected: |
| 68 | + Scalar m_lower_bounds[3]; |
| 69 | + Scalar m_upper_bounds[3]; |
| 70 | + unsigned int m_num_bins[3]; |
| 71 | + bool m_should_bin[3]; |
| 72 | + |
| 73 | + HOSTDEVICE bool bin1D(unsigned int& bin_1d, const Scalar x, unsigned int dim) const |
| 74 | + { |
| 75 | + int bin_ = static_cast<int>( |
| 76 | + slow::floor(((x - m_lower_bounds[dim]) / (m_upper_bounds[dim] - m_lower_bounds[dim])) |
| 77 | + * m_num_bins[dim])); |
| 78 | + if (bin_ >= 0 && bin_ < static_cast<int>(m_num_bins[dim])) |
| 79 | + { |
| 80 | + bin_1d = bin_; |
| 81 | + return true; |
| 82 | + } |
| 83 | + else |
| 84 | + { |
| 85 | + return false; |
| 86 | + } |
| 87 | + } |
| 88 | + }; |
| 89 | + |
| 90 | + } // end namespace azplugins |
| 91 | + } // end namespace hoomd |
| 92 | + |
| 93 | +#undef HOSTDEVICE |
| 94 | + |
| 95 | +#endif // AZPLUGINS_BINNING_OPERATION_H_ |
0 commit comments