48T get_mi_coord(T a, T b, T box_length, T box_length_inv, T box_length_half,
50 auto const dx = a - b;
52 if (periodic && (std::abs(dx) > box_length_half)) {
53 return dx - std::round(dx * box_length_inv) * box_length;
68template <
typename T> T get_mi_coord(T a, T b, T box_length,
bool periodic) {
69 return get_mi_coord(a, b, box_length, 1. / box_length, 0.5 * box_length,
92 return pos + image_shift(image_box, box);
113 m_lees_edwards_bc = rhs.m_lees_edwards_bc;
119 std::bitset<3> m_periodic = 0b111;
147 return m_periodic[
coord];
174 m_length_inv = {1. / box_l[0], 1. / box_l[1], 1. / box_l[2]};
175 m_length_half = 0.5 * box_l;
195 return detail::get_mi_coord(a, b, m_length[
coord], m_length_inv[
coord],
209 template <
typename T>
217 a_tmp[shear_plane_normal], m_length[shear_plane_normal]);
219 b_tmp[shear_plane_normal], m_length[shear_plane_normal]);
221 m_length_inv, m_periodic);
251 auto const &le = m_lees_edwards_bc;
253 auto const shear_direction = le.shear_direction;
254 auto const dy = x[shear_plane_normal] - y[shear_plane_normal];
255 if (fabs(dy) > 0.5 *
length_half()[shear_plane_normal]) {
256 ret[shear_direction] -=
Utils::sgn(dy) * le.shear_velocity;
268 for (
auto i = 0u; i < 3u; i++) {
272 if (result.second == std::numeric_limits<int>::min() or
273 result.second == std::numeric_limits<int>::max()) {
274 throw std::runtime_error(
275 "Overflow in the image box count while folding a particle "
276 "coordinate into the primary simulation box. Maybe a particle "
277 "experienced a huge force.");
279 std::tie(pos[i], image_box[i]) = result;
290 auto pos_folded = pos;
291 for (
unsigned int i = 0u; i < 3u; i++) {
308 auto image_box_folded = image_box;
309 for (
auto i = 0u; i < 3u; i++) {
311 image_box_folded[i] =
316 return image_box_folded;
321 return detail::image_shift(image_box, m_length);
327 return detail::unfolded_position(pos, image_box, m_length);
static int coord(std::string const &s)
Vector implementation and trait types for boost qvm interoperability.
auto unfolded_position(Utils::Vector3d const &pos, Utils::Vector3i const &image_box) const
Unfold particle coordinates to image box.
T get_mi_coord(T a, T b, unsigned coord) const
Get the minimum-image distance between two coordinates.
void lees_edwards_update(double pos_offset, double shear_velocity)
Update the Lees-Edwards parameters of the box geometry for the current simulation time.
auto folded_position(Utils::Vector3d const &pos) const
Calculate coordinates folded to primary simulation box.
Utils::Vector3d const & length() const
Box length.
LeesEdwardsBC const & lees_edwards_bc() const
BoxGeometry(BoxGeometry const &rhs)
constexpr bool periodic(unsigned coord) const
Check periodicity in direction.
double volume() const
Box volume.
auto image_shift(Utils::Vector3i const &image_box) const
Calculate image box shift vector.
Utils::Vector< T, 3 > get_mi_vector(const Utils::Vector< T, 3 > &a, const Utils::Vector< T, 3 > &b) const
Get the minimum-image vector between two coordinates.
Utils::Vector3d const & length_half() const
Half box length.
Utils::Vector3d const & length_inv() const
Inverse box length.
void set_periodic(unsigned coord, bool val)
Set periodicity for direction.
void set_length(Utils::Vector3d const &box_l)
Set box side lengths.
auto folded_image_box(Utils::Vector3d const &pos, Utils::Vector3i const &image_box) const
Calculate image box of coordinates folded to primary simulation box.
void set_lees_edwards_bc(LeesEdwardsBC bc)
void fold_position(Utils::Vector3d &pos, Utils::Vector3i &image_box) const
Fold coordinates to primary simulation box in-place.
Utils::Vector3d velocity_difference(Utils::Vector3d const &x, Utils::Vector3d const &y, Utils::Vector3d const &u, Utils::Vector3d const &v) const
Calculate the velocity difference including the Lees-Edwards velocity.
void set_type(BoxType type)
std::pair< T, I > periodic_fold(T x, I i, T const l)
Fold value into primary interval.
T product(Vector< T, N > const &v)
constexpr int sgn(T val)
Calculate signum of val.
auto hadamard_product(Vector< T, N > const &a, Vector< U, N > const &b)
unsigned int shear_plane_normal
Utils::Vector3d distance(Utils::Vector3d const &d, Utils::Vector3d const &l, Utils::Vector3d const &, Utils::Vector3d const &l_inv, std::bitset< 3 > const periodic) const