Unverified Commit 87fd43c8 authored by Florian Weik's avatar Florian Weik Committed by GitHub

Merge pull request #2422 from RudolfWeeber/fold2

Fold
parents 4a7cafd1 bf850638
Pipeline #4547 passed with stages
in 48 minutes and 6 seconds
......@@ -214,14 +214,20 @@ Vector3d get_mi_vector(T const &a, U const &b) {
template <typename T1, typename T2, typename T3>
void fold_coordinate(T1 &pos, T2 &vel, T3 &image_box, int dir) {
if (PERIODIC(dir)) {
while (pos[dir] < 0) {
while ((pos[dir] < 0) && (image_box[dir] > INT_MIN)) {
pos[dir] += box_l[dir];
image_box[dir] -= 1;
}
while (pos[dir] >= box_l[dir]) {
while ((pos[dir] >= box_l[dir]) && (image_box[dir] < INT_MAX)) {
pos[dir] -= box_l[dir];
image_box[dir] += 1;
}
if ((image_box[dir] == INT_MIN) || (image_box[dir] == INT_MAX)) {
throw std::runtime_error(
"Overflow in the image box count while folding a particle coordinate "
"into the primary simulation box. Maybe a particle experienced a "
"huge force.");
}
}
}
......@@ -271,14 +277,9 @@ template <typename T1, typename T2> void fold_position(T1 &pos, T2 &image_box) {
*/
inline Vector3d folded_position(Particle const &p) {
Vector3d pos{p.r.p};
int tmp[3] = {0, 0, 0};
for (int dir = 0; dir < 3; dir++) {
if (PERIODIC(dir)) {
const int img_count =
static_cast<int>(std::floor(pos[dir] * box_l_i[dir]));
pos[dir] -= img_count * box_l[dir];
}
fold_coordinate(pos, tmp, dir);
}
return pos;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment